bump product version to 4.1.6.2
[LibreOffice.git] / hwpfilter / source / hpara.cxx
blobb1d6f544fc149b9bb72e371452b5018f311c4211
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "precompile.h"
22 #include <osl/diagnose.h>
24 #include <comphelper/newarray.hxx>
26 #include "hwplib.h"
27 #include "hwpfile.h"
28 #include "hpara.h"
29 #include "hbox.h"
30 #include "hutil.h"
32 bool LineInfo::Read(HWPFile & hwpf, HWPPara *pPara)
34 pos = sal::static_int_cast<unsigned short>(hwpf.Read2b());
35 space_width = (short) hwpf.Read2b();
36 height = (short) hwpf.Read2b();
37 // internal information
38 pgy = (short) hwpf.Read2b();
39 sx = (short) hwpf.Read2b();
40 psx = (short) hwpf.Read2b();
41 pex = (short) hwpf.Read2b();
42 height_sp = 0;
44 if( pex >> 15 & 0x01 )
46 if( pex & 0x01 )
47 hwpf.AddPage();
48 pPara->pshape.reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
49 pPara->pshape.reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
52 return (!hwpf.State());
56 HWPPara::HWPPara(void)
58 _next = NULL;
59 linfo = NULL;
60 cshapep = NULL;
61 hhstr = NULL;
62 pno = 0;
67 HWPPara::~HWPPara(void)
69 if (linfo)
70 delete[]linfo;
71 if (cshapep)
72 delete[]cshapep;
73 if (hhstr)
75 // virtual destructor
76 /* C++은 null에 대해서도 동작한다. */
77 for (int ii = 0; ii < nch; ++ii)
78 delete hhstr[ii];
80 delete[]hhstr;
86 int HWPPara::Read(HWPFile & hwpf, unsigned char flag)
88 unsigned char same_cshape;
89 register int ii;
90 scflag = flag;
91 // Paragraph Information
92 hwpf.Read1b(&reuse_shape, 1);
93 hwpf.Read2b(&nch, 1);
94 hwpf.Read2b(&nline, 1);
95 hwpf.Read1b(&contain_cshape, 1);
96 hwpf.Read1b(&etcflag, 1);
97 hwpf.Read4b(&ctrlflag, 1);
98 hwpf.Read1b(&pstyno, 1);
101 /* Paragraph 대표 글자 */
102 cshape.Read(hwpf);
103 if (nch > 0)
104 hwpf.AddCharShape(&cshape);
106 /* Paragraph 문단 모양 */
107 if (nch && !reuse_shape)
109 pshape.Read(hwpf);
110 pshape.cshape = &cshape;
111 pshape.pagebreak = etcflag;
114 linfo = ::comphelper::newArray_null<LineInfo>(nline);
115 if (!linfo) { return false; }
116 for (ii = 0; ii < nline; ii++)
118 linfo[ii].Read(hwpf, this);
120 if( etcflag & 0x04 ){
121 hwpf.AddColumnInfo();
124 if (nch && !reuse_shape){
125 if( pshape.coldef.ncols > 1 ){
126 hwpf.SetColumnDef( &pshape.coldef );
131 if( nline > 0 )
133 begin_ypos = linfo[0].pgy;
135 else
137 begin_ypos = 0;
140 if (contain_cshape)
142 cshapep = ::comphelper::newArray_null<CharShape>(nch);
143 if (!cshapep)
145 perror("Memory Allocation: cshape\n");
146 return false;
149 for (ii = 0; ii < nch; ii++)
152 hwpf.Read1b(&same_cshape, 1);
153 if (!same_cshape)
155 cshapep[ii].Read(hwpf);
156 if (nch > 1)
157 hwpf.AddCharShape(&cshapep[ii]);
159 else if (ii == 0)
160 cshapep[ii] = cshape;
161 else
162 cshapep[ii] = cshapep[ii - 1];
165 // read string
166 hhstr = ::comphelper::newArray_null<HBox *>(nch);
167 if (!hhstr) { return false; }
168 for (ii = 0; ii < nch; ii++)
169 hhstr[ii] = 0;
170 ii = 0;
171 while (ii < nch)
173 if (0 == (hhstr[ii] = readHBox(hwpf)))
174 return false;
175 if (hhstr[ii]->hh == CH_END_PARA)
176 break;
177 if( hhstr[ii]->hh < CH_END_PARA )
178 pshape.reserved[0] = 0;
179 ii += hhstr[ii]->WSize();
181 return nch && !hwpf.State();
185 HWPPara *HWPPara::Next(void)
187 return _next;
191 CharShape *HWPPara::GetCharShape(int pos)
193 if (contain_cshape == 0)
194 return &cshape;
195 return cshapep + pos;
199 ParaShape *HWPPara::GetParaShape(void)
201 return &pshape;
205 HBox *HWPPara::readHBox(HWPFile & hwpf)
207 hchar hh = sal::static_int_cast<hchar>(hwpf.Read2b());
208 HBox *hbox = 0;
210 if (hwpf.State() != HWP_NoError)
211 return 0;
213 if (hh > 31 || hh == CH_END_PARA)
214 hbox = new HBox(hh);
215 else if (IS_SP_SKIP_BLOCK(hh))
216 hbox = new SkipData(hh);
217 else
219 switch (hh)
221 case CH_FIELD: // 5
222 hbox = new FieldCode;
223 break;
224 case CH_BOOKMARK: // 6
225 hbox = new Bookmark;
226 break;
227 case CH_DATE_FORM: // 7
228 hbox = new DateFormat;
229 break;
230 case CH_DATE_CODE: // 8
231 hbox = new DateCode;
232 break;
233 case CH_TAB: // 9
234 hbox = new Tab;
235 break;
236 case CH_TEXT_BOX: // 10
237 hbox = new TxtBox;
238 break;
239 case CH_PICTURE: // 11
240 hbox = new Picture;
241 break;
242 case CH_LINE: // 14
243 hbox = new Line;
244 break;
245 case CH_HIDDEN: // 15
246 hbox = new Hidden;
247 break;
248 case CH_HEADER_FOOTER: // 16
249 hbox = new HeaderFooter;
250 break;
251 case CH_FOOTNOTE: // 17
252 hbox = new Footnote;
253 break;
254 case CH_AUTO_NUM: // 18
255 hbox = new AutoNum;
256 break;
257 case CH_NEW_NUM: // 19
258 hbox = new NewNum;
259 break;
260 case CH_SHOW_PAGE_NUM: // 20
261 hbox = new ShowPageNum;
262 break;
263 case CH_PAGE_NUM_CTRL: // 21
264 hbox = new PageNumCtrl;
265 break;
266 case CH_MAIL_MERGE: // 22
267 hbox = new MailMerge;
268 break;
269 case CH_COMPOSE: // 23
270 hbox = new Compose;
271 break;
272 case CH_HYPHEN: // 24
273 hbox = new Hyphen;
274 break;
275 case CH_TOC_MARK: // 25
276 hbox = new TocMark;
277 break;
278 case CH_INDEX_MARK: // 26
279 hbox = new IndexMark;
280 break;
281 case CH_OUTLINE: // 28
282 hbox = new Outline;
283 break;
284 case CH_KEEP_SPACE: // 30
285 hbox = new KeepSpace;
286 break;
287 case CH_FIXED_SPACE: // 31
288 hbox = new FixedSpace;
289 break;
290 default:
291 break;
294 if (!hbox || !hbox->Read(hwpf))
296 delete hbox;
298 return 0;
300 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
302 FBox *fbox = static_cast<FBox *>(hbox);
303 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
305 //strange construct to compile without warning
306 int nTemp = fbox->pgy;
307 nTemp -= begin_ypos;
308 fbox->pgy = sal::static_int_cast<short>(nTemp);
311 return hbox;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */