bump product version to 4.1.6.2
[LibreOffice.git] / hwpfilter / source / hstyle.cxx
blob5b91dc4a5e4d608dffe4c4791145363713cc45cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "precompile.h"
22 #include <comphelper/newarray.hxx>
24 #include "hwplib.h"
25 #include "hwpfile.h"
26 #include "hstyle.h"
28 enum
29 { MAXSTYLENAME = 20 };
31 #define DATA ((StyleData *)style)
33 struct StyleData
35 char name[MAXSTYLENAME + 1];
36 CharShape cshape;
37 ParaShape pshape;
40 static char buffer[MAXSTYLENAME + 1];
42 HWPStyle::HWPStyle(void)
44 nstyles = 0;
45 style = 0;
49 HWPStyle::~HWPStyle(void)
51 delete[]DATA;
52 nstyles = 0;
56 int HWPStyle::Num(void) const
58 return nstyles;
62 char *HWPStyle::GetName(int n) const
64 if (!(n >= 0 && n < nstyles))
65 return 0;
66 return DATA[n].name;
70 void HWPStyle::SetName(int n, char *name)
72 if (n >= 0 && n < nstyles)
74 if (name)
75 strncpy(DATA[n].name, name, MAXSTYLENAME);
76 else
77 DATA[n].name[0] = 0;
82 CharShape *HWPStyle::GetCharShape(int n) const
84 if (!(n >= 0 && n < nstyles))
85 return 0;
86 return &DATA[n].cshape;
90 void HWPStyle::SetCharShape(int n, CharShape * cshapep)
92 if (n >= 0 && n < nstyles)
94 if (cshapep)
95 DATA[n].cshape = *cshapep;
96 else
97 memset(&DATA[n].cshape, 0, sizeof(CharShape));
102 ParaShape *HWPStyle::GetParaShape(int n) const
104 if (!(n >= 0 && n < nstyles))
105 return 0;
106 return &DATA[n].pshape;
110 void HWPStyle::SetParaShape(int n, ParaShape * pshapep)
112 if (n >= 0 && n < nstyles)
114 if (pshapep)
115 DATA[n].pshape = *pshapep;
116 else
117 memset(&DATA[n].pshape, 0, sizeof(ParaShape));
122 bool HWPStyle::Read(HWPFile & hwpf)
124 CharShape cshape;
125 ParaShape pshape;
127 hwpf.Read2b(&nstyles, 1);
128 style = ::comphelper::newArray_null<StyleData>(nstyles);
129 if (!style)
130 return false;
132 for (int ii = 0; ii < nstyles; ii++)
134 hwpf.ReadBlock(buffer, MAXSTYLENAME);
135 cshape.Read(hwpf);
136 pshape.Read(hwpf);
138 SetName(ii, buffer);
139 SetCharShape(ii, &cshape);
140 SetParaShape(ii, &pshape);
141 if (hwpf.State())
142 return false;
144 return true;
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */