Bump for 3.6-28
[LibreOffice.git] / hwpfilter / source / hstyle.cxx
blobfef92998ccc3a1ab04f4715fc4612b551864096c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "precompile.h"
31 #include <comphelper/newarray.hxx>
33 #include "hwplib.h"
34 #include "hwpfile.h"
35 #include "hstyle.h"
37 enum
38 { MAXSTYLENAME = 20 };
40 #define DATA ((StyleData *)style)
42 struct StyleData
44 char name[MAXSTYLENAME + 1];
45 CharShape cshape;
46 ParaShape pshape;
49 static char buffer[MAXSTYLENAME + 1];
51 HWPStyle::HWPStyle(void)
53 nstyles = 0;
54 style = 0;
58 HWPStyle::~HWPStyle(void)
60 delete[]DATA;
61 nstyles = 0;
65 int HWPStyle::Num(void) const
67 return nstyles;
71 char *HWPStyle::GetName(int n) const
73 if (!(n >= 0 && n < nstyles))
74 return 0;
75 return DATA[n].name;
79 void HWPStyle::SetName(int n, char *name)
81 if (n >= 0 && n < nstyles)
83 if (name)
84 strncpy(DATA[n].name, name, MAXSTYLENAME);
85 else
86 DATA[n].name[0] = 0;
91 CharShape *HWPStyle::GetCharShape(int n) const
93 if (!(n >= 0 && n < nstyles))
94 return 0;
95 return &DATA[n].cshape;
99 void HWPStyle::SetCharShape(int n, CharShape * cshapep)
101 if (n >= 0 && n < nstyles)
103 if (cshapep)
104 DATA[n].cshape = *cshapep;
105 else
106 memset(&DATA[n].cshape, 0, sizeof(CharShape));
111 ParaShape *HWPStyle::GetParaShape(int n) const
113 if (!(n >= 0 && n < nstyles))
114 return 0;
115 return &DATA[n].pshape;
119 void HWPStyle::SetParaShape(int n, ParaShape * pshapep)
121 if (n >= 0 && n < nstyles)
123 if (pshapep)
124 DATA[n].pshape = *pshapep;
125 else
126 memset(&DATA[n].pshape, 0, sizeof(ParaShape));
131 bool HWPStyle::Read(HWPFile & hwpf)
133 CharShape cshape;
134 ParaShape pshape;
136 hwpf.Read2b(&nstyles, 1);
137 style = ::comphelper::newArray_null<StyleData>(nstyles);
138 if (!style)
139 return false;
141 for (int ii = 0; ii < nstyles; ii++)
143 hwpf.ReadBlock(buffer, MAXSTYLENAME);
144 cshape.Read(hwpf);
145 pshape.Read(hwpf);
147 SetName(ii, buffer);
148 SetCharShape(ii, &cshape);
149 SetParaShape(ii, &pshape);
150 if (hwpf.State())
151 return false;
153 return true;
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */