merged tag ooo/DEV300_m102
[LibreOffice.git] / hwpfilter / source / hpara.cpp
blob885fa53799ae1cb163f3cd56a3d6ef4ba30ba1ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 /* $Id: hpara.cpp,v 1.6 2008-06-04 09:59:35 vg Exp $ */
30 #include "precompile.h"
32 #include "hwplib.h"
33 #include "hwpfile.h"
34 #include "hpara.h"
35 #include "hbox.h"
36 #include "hutil.h"
37 #include "hutil.h"
39 bool LineInfo::Read(HWPFile & hwpf, HWPPara *pPara)
41 pos = sal::static_int_cast<unsigned short>(hwpf.Read2b());
42 space_width = (short) hwpf.Read2b();
43 height = (short) hwpf.Read2b();
44 // internal informations
45 pgy = (short) hwpf.Read2b();
46 sx = (short) hwpf.Read2b();
47 psx = (short) hwpf.Read2b();
48 pex = (short) hwpf.Read2b();
49 height_sp = 0;
51 if( pex >> 15 & 0x01 )
53 if( pex & 0x01 )
54 hwpf.AddPage();
55 pPara->pshape.reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
56 pPara->pshape.reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
59 return (!hwpf.State());
63 HWPPara::HWPPara(void)
65 _next = NULL;
66 linfo = NULL;
67 cshapep = NULL;
68 hhstr = NULL;
69 pno = 0;
74 HWPPara::~HWPPara(void)
76 int ii;
78 if (linfo)
79 delete[]linfo;
80 if (cshapep)
81 delete[]cshapep;
82 if (hhstr)
84 // virtual destructor
85 /* C++?? null?? ???????? ????????. */
86 for (ii = 0; ii < nch; ++ii)
87 delete hhstr[ii];
89 delete[]hhstr;
95 int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
97 unsigned char same_cshape;
98 register int ii;
99 scflag = flag;
100 // Paragraph Infomation
101 hwpf.Read1b(&reuse_shape, 1);
102 hwpf.Read2b(&nch, 1);
103 hwpf.Read2b(&nline, 1);
104 hwpf.Read1b(&contain_cshape, 1);
105 hwpf.Read1b(&etcflag, 1);
106 hwpf.Read4b(&ctrlflag, 1);
107 hwpf.Read1b(&pstyno, 1);
110 /* Paragraph ???? ???? */
111 cshape.Read(hwpf);
112 if (nch > 0)
113 hwpf.AddCharShape(&cshape);
115 /* Paragraph ???? ???? */
116 if (nch && !reuse_shape)
118 pshape.Read(hwpf);
119 pshape.cshape = &cshape;
120 pshape.pagebreak = etcflag;
123 linfo = new LineInfo[nline];
124 for (ii = 0; ii < nline; ii++)
126 linfo[ii].Read(hwpf, this);
128 if( etcflag & 0x04 ){
129 hwpf.AddColumnInfo();
132 if (nch && !reuse_shape){
133 if( pshape.coldef.ncols > 1 ){
134 hwpf.SetColumnDef( &pshape.coldef );
139 if( nline > 0 )
141 begin_ypos = linfo[0].pgy;
143 else
145 begin_ypos = 0;
148 if (contain_cshape)
150 cshapep = new CharShape[nch];
151 if (!cshapep)
153 perror("Memory Allocation: cshape\n");
154 return false;
157 for (ii = 0; ii < nch; ii++)
160 hwpf.Read1b(&same_cshape, 1);
161 if (!same_cshape)
163 cshapep[ii].Read(hwpf);
164 if (nch > 1)
165 hwpf.AddCharShape(&cshapep[ii]);
167 else if (ii == 0)
168 cshapep[ii] = cshape;
169 else
170 cshapep[ii] = cshapep[ii - 1];
173 // read string
174 hhstr = new HBox *[nch];
175 for (ii = 0; ii < nch; ii++)
176 hhstr[ii] = 0;
177 ii = 0;
178 while (ii < nch)
180 if (0 == (hhstr[ii] = readHBox(hwpf)))
181 return false;
182 if (hhstr[ii]->hh == CH_END_PARA)
183 break;
184 if( hhstr[ii]->hh < CH_END_PARA )
185 pshape.reserved[0] = 0;
186 ii += hhstr[ii]->WSize();
188 return nch && !hwpf.State();
192 HWPPara *HWPPara::Next(void)
194 return _next;
198 CharShape *HWPPara::GetCharShape(int pos)
200 if (contain_cshape == 0)
201 return &cshape;
202 return cshapep + pos;
206 ParaShape *HWPPara::GetParaShape(void)
208 return &pshape;
212 HBox *HWPPara::readHBox(HWPFile & hwpf)
214 hchar hh = sal::static_int_cast<hchar>(hwpf.Read2b());
215 HBox *hbox = 0;
217 if (hwpf.State() != HWP_NoError)
218 return 0;
219 //hbox = new HBox(hh);
220 if (hh > 31 || hh == CH_END_PARA)
221 hbox = new HBox(hh);
222 else if (IS_SP_SKIP_BLOCK(hh))
223 hbox = new SkipBlock(hh);
224 else
226 switch (hh)
228 case CH_FIELD: // 5
229 hbox = new FieldCode;
230 break;
231 case CH_BOOKMARK: // 6
232 hbox = new Bookmark;
233 break;
234 case CH_DATE_FORM: // 7
235 hbox = new DateFormat;
236 break;
237 case CH_DATE_CODE: // 8
238 hbox = new DateCode;
239 break;
240 case CH_TAB: // 9
241 hbox = new Tab;
242 break;
243 case CH_TEXT_BOX: // 10
244 hbox = new TxtBox;
245 break;
246 case CH_PICTURE: // 11
247 hbox = new Picture;
248 break;
249 case CH_LINE: // 14
250 hbox = new Line;
251 break;
252 case CH_HIDDEN: // 15
253 hbox = new Hidden;
254 break;
255 case CH_HEADER_FOOTER: // 16
256 hbox = new HeaderFooter;
257 break;
258 case CH_FOOTNOTE: // 17
259 hbox = new Footnote;
260 break;
261 case CH_AUTO_NUM: // 18
262 hbox = new AutoNum;
263 break;
264 case CH_NEW_NUM: // 19
265 hbox = new NewNum;
266 break;
267 case CH_SHOW_PAGE_NUM: // 20
268 hbox = new ShowPageNum;
269 break;
270 case CH_PAGE_NUM_CTRL: // 21
271 hbox = new PageNumCtrl;
272 break;
273 case CH_MAIL_MERGE: // 22
274 hbox = new MailMerge;
275 break;
276 case CH_COMPOSE: // 23
277 hbox = new Compose;
278 break;
279 case CH_HYPHEN: // 24
280 hbox = new Hyphen;
281 break;
282 case CH_TOC_MARK: // 25
283 hbox = new TocMark;
284 break;
285 case CH_INDEX_MARK: // 26
286 hbox = new IndexMark;
287 break;
288 case CH_OUTLINE: // 28
289 hbox = new Outline;
290 break;
291 case CH_KEEP_SPACE: // 30
292 hbox = new KeepSpace;
293 break;
294 case CH_FIXED_SPACE: // 31
295 hbox = new FixedSpace;
296 break;
297 default:
298 break;
301 if (!hbox || !hbox->Read(hwpf))
303 delete hbox;
305 return 0;
307 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
309 FBox *fbox = static_cast<FBox *>(hbox);
310 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
312 //strange construct to compile without warning
313 int nTemp = fbox->pgy;
314 nTemp -= begin_ypos;
315 fbox->pgy = sal::static_int_cast<short>(nTemp);
318 return hbox;
319 //return 0;