Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / hwpfilter / source / hpara.cxx
blob36268f63b633d26a38a8723677204deea85de4a5
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 <osl/diagnose.h>
33 #include <comphelper/newarray.hxx>
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 if (linfo)
80 delete[]linfo;
81 if (cshapep)
82 delete[]cshapep;
83 if (hhstr)
85 // virtual destructor
86 /* C++은 null에 대해서도 동작한다. */
87 for (int ii = 0; ii < nch; ++ii)
88 delete hhstr[ii];
90 delete[]hhstr;
96 int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
98 unsigned char same_cshape;
99 register int ii;
100 scflag = flag;
101 // Paragraph Information
102 hwpf.Read1b(&reuse_shape, 1);
103 hwpf.Read2b(&nch, 1);
104 hwpf.Read2b(&nline, 1);
105 hwpf.Read1b(&contain_cshape, 1);
106 hwpf.Read1b(&etcflag, 1);
107 hwpf.Read4b(&ctrlflag, 1);
108 hwpf.Read1b(&pstyno, 1);
111 /* Paragraph 대표 글자 */
112 cshape.Read(hwpf);
113 if (nch > 0)
114 hwpf.AddCharShape(&cshape);
116 /* Paragraph 문단 모양 */
117 if (nch && !reuse_shape)
119 pshape.Read(hwpf);
120 pshape.cshape = &cshape;
121 pshape.pagebreak = etcflag;
124 linfo = ::comphelper::newArray_null<LineInfo>(nline);
125 if (!linfo) { return false; }
126 for (ii = 0; ii < nline; ii++)
128 linfo[ii].Read(hwpf, this);
130 if( etcflag & 0x04 ){
131 hwpf.AddColumnInfo();
134 if (nch && !reuse_shape){
135 if( pshape.coldef.ncols > 1 ){
136 hwpf.SetColumnDef( &pshape.coldef );
141 if( nline > 0 )
143 begin_ypos = linfo[0].pgy;
145 else
147 begin_ypos = 0;
150 if (contain_cshape)
152 cshapep = ::comphelper::newArray_null<CharShape>(nch);
153 if (!cshapep)
155 perror("Memory Allocation: cshape\n");
156 return false;
159 for (ii = 0; ii < nch; ii++)
162 hwpf.Read1b(&same_cshape, 1);
163 if (!same_cshape)
165 cshapep[ii].Read(hwpf);
166 if (nch > 1)
167 hwpf.AddCharShape(&cshapep[ii]);
169 else if (ii == 0)
170 cshapep[ii] = cshape;
171 else
172 cshapep[ii] = cshapep[ii - 1];
175 // read string
176 hhstr = ::comphelper::newArray_null<HBox *>(nch);
177 if (!hhstr) { return false; }
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;
223 if (hh > 31 || hh == CH_END_PARA)
224 hbox = new HBox(hh);
225 else if (IS_SP_SKIP_BLOCK(hh))
226 hbox = new SkipData(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;
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */