Update ooo320-m1
[ooovba.git] / hwpfilter / source / hpara.cpp
blobe1c1140703726e04b07e91043cf2df85f96a890a
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: hpara.cpp,v $
10 * $Revision: 1.6 $
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: hpara.cpp,v 1.6 2008-06-04 09:59:35 vg Exp $ */
33 #include "precompile.h"
35 #include "hwplib.h"
36 #include "hwpfile.h"
37 #include "hpara.h"
38 #include "hbox.h"
39 #include "hutil.h"
40 #include "hutil.h"
42 bool LineInfo::Read(HWPFile & hwpf, HWPPara *pPara)
44 pos = sal::static_int_cast<unsigned short>(hwpf.Read2b());
45 space_width = (short) hwpf.Read2b();
46 height = (short) hwpf.Read2b();
47 // internal informations
48 pgy = (short) hwpf.Read2b();
49 sx = (short) hwpf.Read2b();
50 psx = (short) hwpf.Read2b();
51 pex = (short) hwpf.Read2b();
52 height_sp = 0;
54 if( pex >> 15 & 0x01 )
56 if( pex & 0x01 )
57 hwpf.AddPage();
58 pPara->pshape.reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
59 pPara->pshape.reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
62 return (!hwpf.State());
66 HWPPara::HWPPara(void)
68 _next = NULL;
69 linfo = NULL;
70 cshapep = NULL;
71 hhstr = NULL;
72 pno = 0;
77 HWPPara::~HWPPara(void)
79 int ii;
81 if (linfo)
82 delete[]linfo;
83 if (cshapep)
84 delete[]cshapep;
85 if (hhstr)
87 // virtual destructor
88 /* C++?? null?? ???????? ????????. */
89 for (ii = 0; ii < nch; ++ii)
90 delete hhstr[ii];
92 delete[]hhstr;
98 int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
100 unsigned char same_cshape;
101 register int ii;
102 scflag = flag;
103 // Paragraph Infomation
104 hwpf.Read1b(&reuse_shape, 1);
105 hwpf.Read2b(&nch, 1);
106 hwpf.Read2b(&nline, 1);
107 hwpf.Read1b(&contain_cshape, 1);
108 hwpf.Read1b(&etcflag, 1);
109 hwpf.Read4b(&ctrlflag, 1);
110 hwpf.Read1b(&pstyno, 1);
113 /* Paragraph ???? ???? */
114 cshape.Read(hwpf);
115 if (nch > 0)
116 hwpf.AddCharShape(&cshape);
118 /* Paragraph ???? ???? */
119 if (nch && !reuse_shape)
121 pshape.Read(hwpf);
122 pshape.cshape = &cshape;
123 pshape.pagebreak = etcflag;
126 linfo = new LineInfo[nline];
127 for (ii = 0; ii < nline; ii++)
129 linfo[ii].Read(hwpf, this);
131 if( etcflag & 0x04 ){
132 hwpf.AddColumnInfo();
135 if (nch && !reuse_shape){
136 if( pshape.coldef.ncols > 1 ){
137 hwpf.SetColumnDef( &pshape.coldef );
142 if( nline > 0 )
144 begin_ypos = linfo[0].pgy;
146 else
148 begin_ypos = 0;
151 if (contain_cshape)
153 cshapep = new CharShape[nch];
154 if (!cshapep)
156 perror("Memory Allocation: cshape\n");
157 return false;
160 for (ii = 0; ii < nch; ii++)
163 hwpf.Read1b(&same_cshape, 1);
164 if (!same_cshape)
166 cshapep[ii].Read(hwpf);
167 if (nch > 1)
168 hwpf.AddCharShape(&cshapep[ii]);
170 else if (ii == 0)
171 cshapep[ii] = cshape;
172 else
173 cshapep[ii] = cshapep[ii - 1];
176 // read string
177 hhstr = new HBox *[nch];
178 for (ii = 0; ii < nch; ii++)
179 hhstr[ii] = 0;
180 ii = 0;
181 while (ii < nch)
183 if (0 == (hhstr[ii] = readHBox(hwpf)))
184 return false;
185 if (hhstr[ii]->hh == CH_END_PARA)
186 break;
187 if( hhstr[ii]->hh < CH_END_PARA )
188 pshape.reserved[0] = 0;
189 ii += hhstr[ii]->WSize();
191 return nch && !hwpf.State();
195 HWPPara *HWPPara::Next(void)
197 return _next;
201 CharShape *HWPPara::GetCharShape(int pos)
203 if (contain_cshape == 0)
204 return &cshape;
205 return cshapep + pos;
209 ParaShape *HWPPara::GetParaShape(void)
211 return &pshape;
215 HBox *HWPPara::readHBox(HWPFile & hwpf)
217 hchar hh = sal::static_int_cast<hchar>(hwpf.Read2b());
218 HBox *hbox = 0;
220 if (hwpf.State() != HWP_NoError)
221 return 0;
222 //hbox = new HBox(hh);
223 if (hh > 31 || hh == CH_END_PARA)
224 hbox = new HBox(hh);
225 else if (IS_SP_SKIP_BLOCK(hh))
226 hbox = new SkipBlock(hh);
227 else
229 switch (hh)
231 case CH_FIELD: // 5
232 hbox = new FieldCode;
233 break;
234 case CH_BOOKMARK: // 6
235 hbox = new Bookmark;
236 break;
237 case CH_DATE_FORM: // 7
238 hbox = new DateFormat;
239 break;
240 case CH_DATE_CODE: // 8
241 hbox = new DateCode;
242 break;
243 case CH_TAB: // 9
244 hbox = new Tab;
245 break;
246 case CH_TEXT_BOX: // 10
247 hbox = new TxtBox;
248 break;
249 case CH_PICTURE: // 11
250 hbox = new Picture;
251 break;
252 case CH_LINE: // 14
253 hbox = new Line;
254 break;
255 case CH_HIDDEN: // 15
256 hbox = new Hidden;
257 break;
258 case CH_HEADER_FOOTER: // 16
259 hbox = new HeaderFooter;
260 break;
261 case CH_FOOTNOTE: // 17
262 hbox = new Footnote;
263 break;
264 case CH_AUTO_NUM: // 18
265 hbox = new AutoNum;
266 break;
267 case CH_NEW_NUM: // 19
268 hbox = new NewNum;
269 break;
270 case CH_SHOW_PAGE_NUM: // 20
271 hbox = new ShowPageNum;
272 break;
273 case CH_PAGE_NUM_CTRL: // 21
274 hbox = new PageNumCtrl;
275 break;
276 case CH_MAIL_MERGE: // 22
277 hbox = new MailMerge;
278 break;
279 case CH_COMPOSE: // 23
280 hbox = new Compose;
281 break;
282 case CH_HYPHEN: // 24
283 hbox = new Hyphen;
284 break;
285 case CH_TOC_MARK: // 25
286 hbox = new TocMark;
287 break;
288 case CH_INDEX_MARK: // 26
289 hbox = new IndexMark;
290 break;
291 case CH_OUTLINE: // 28
292 hbox = new Outline;
293 break;
294 case CH_KEEP_SPACE: // 30
295 hbox = new KeepSpace;
296 break;
297 case CH_FIXED_SPACE: // 31
298 hbox = new FixedSpace;
299 break;
300 default:
301 break;
304 if (!hbox || !hbox->Read(hwpf))
306 delete hbox;
308 return 0;
310 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
312 FBox *fbox = static_cast<FBox *>(hbox);
313 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
315 //strange construct to compile without warning
316 int nTemp = fbox->pgy;
317 nTemp -= begin_ypos;
318 fbox->pgy = sal::static_int_cast<short>(nTemp);
321 return hbox;
322 //return 0;