update dev300-m58
[ooovba.git] / hwpfilter / source / hstyle.cpp
blob85bff7d66acc7c1ce85c7458c3325cfcd4e95b07
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hstyle.cpp,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 /* $Id: hstyle.cpp,v 1.3 2008-04-10 12:07:14 rt Exp $ */
33 #include "precompile.h"
35 #include "hwplib.h"
36 #include "hwpfile.h"
37 #include "hstyle.h"
39 enum
40 { MAXSTYLENAME = 20 };
42 #define DATA ((StyleData *)style)
44 struct StyleData
46 char name[MAXSTYLENAME + 1];
47 CharShape cshape;
48 ParaShape pshape;
51 static char buffer[MAXSTYLENAME + 1];
53 HWPStyle::HWPStyle(void)
55 nstyles = 0;
56 style = 0;
60 HWPStyle::~HWPStyle(void)
62 delete[]DATA;
63 nstyles = 0;
67 int HWPStyle::Num(void) const
69 return nstyles;
73 char *HWPStyle::GetName(int n) const
75 if (!(n >= 0 && n < nstyles))
76 return 0;
77 return DATA[n].name;
81 void HWPStyle::SetName(int n, char *name)
83 if (n >= 0 && n < nstyles)
85 if (name)
86 strncpy(DATA[n].name, name, MAXSTYLENAME);
87 else
88 DATA[n].name[0] = 0;
93 CharShape *HWPStyle::GetCharShape(int n) const
95 if (!(n >= 0 && n < nstyles))
96 return 0;
97 return &DATA[n].cshape;
101 void HWPStyle::SetCharShape(int n, CharShape * cshapep)
103 if (n >= 0 && n < nstyles)
105 if (cshapep)
106 DATA[n].cshape = *cshapep;
107 else
108 memset(&DATA[n].cshape, 0, sizeof(CharShape));
113 ParaShape *HWPStyle::GetParaShape(int n) const
115 if (!(n >= 0 && n < nstyles))
116 return 0;
117 return &DATA[n].pshape;
121 void HWPStyle::SetParaShape(int n, ParaShape * pshapep)
123 if (n >= 0 && n < nstyles)
125 if (pshapep)
126 DATA[n].pshape = *pshapep;
127 else
128 memset(&DATA[n].pshape, 0, sizeof(ParaShape));
133 bool HWPStyle::Read(HWPFile & hwpf)
135 CharShape cshape;
136 ParaShape pshape;
138 hwpf.Read2b(&nstyles, 1);
139 style = new StyleData[nstyles];
140 if (!style)
141 return false;
143 for (int ii = 0; ii < nstyles; ii++)
145 hwpf.ReadBlock(buffer, MAXSTYLENAME);
146 cshape.Read(hwpf);
147 pshape.Read(hwpf);
149 SetName(ii, buffer);
150 SetCharShape(ii, &cshape);
151 SetParaShape(ii, &pshape);
152 if (hwpf.State())
153 return false;
155 return true;