Typo: cirle->circle
[LibreOffice.git] / hwpfilter / source / hstyle.cxx
blob6be9bd85f343e40656a321f89b5a234b1af36a5a
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;
58 char *HWPStyle::GetName(int n) const
60 if (!(n >= 0 && n < nstyles))
61 return 0;
62 return DATA[n].name;
66 void HWPStyle::SetName(int n, char *name)
68 if (n >= 0 && n < nstyles)
70 if (name)
71 strncpy(DATA[n].name, name, MAXSTYLENAME);
72 else
73 DATA[n].name[0] = 0;
78 CharShape *HWPStyle::GetCharShape(int n) const
80 if (!(n >= 0 && n < nstyles))
81 return 0;
82 return &DATA[n].cshape;
86 void HWPStyle::SetCharShape(int n, CharShape * cshapep)
88 if (n >= 0 && n < nstyles)
90 if (cshapep)
91 DATA[n].cshape = *cshapep;
92 else
93 memset(&DATA[n].cshape, 0, sizeof(CharShape));
98 ParaShape *HWPStyle::GetParaShape(int n) const
100 if (!(n >= 0 && n < nstyles))
101 return 0;
102 return &DATA[n].pshape;
106 void HWPStyle::SetParaShape(int n, ParaShape * pshapep)
108 if (n >= 0 && n < nstyles)
110 if (pshapep)
111 DATA[n].pshape = *pshapep;
112 else
113 memset(&DATA[n].pshape, 0, sizeof(ParaShape));
118 bool HWPStyle::Read(HWPFile & hwpf)
120 CharShape cshape;
121 ParaShape pshape;
123 hwpf.Read2b(&nstyles, 1);
124 style = ::comphelper::newArray_null<StyleData>(nstyles);
125 if (!style)
126 return false;
128 for (int ii = 0; ii < nstyles; ii++)
130 hwpf.ReadBlock(buffer, MAXSTYLENAME);
131 cshape.Read(hwpf);
132 pshape.Read(hwpf);
134 SetName(ii, buffer);
135 SetCharShape(ii, &cshape);
136 SetParaShape(ii, &pshape);
137 if (hwpf.State())
138 return false;
140 return true;
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */