fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / hwpfilter / source / hpara.cxx
blobe26fb6f65cfdb4bb3e06b33cc4779089272fd0fc
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 if (!hwpf.Read2b(pos))
35 return false;
36 unsigned short tmp16;
37 if (!hwpf.Read2b(tmp16))
38 return false;
39 space_width = tmp16;
40 if (!hwpf.Read2b(tmp16))
41 return false;
42 height = tmp16;
43 // internal information
44 if (!hwpf.Read2b(tmp16))
45 return false;
46 pgy = tmp16;
47 if (!hwpf.Read2b(tmp16))
48 return false;
49 sx = tmp16;
50 if (!hwpf.Read2b(tmp16))
51 return false;
52 psx = tmp16;
53 if (!hwpf.Read2b(tmp16))
54 return false;
55 pex = tmp16;
56 height_sp = 0;
58 if( pex >> 15 & 0x01 )
60 if( pex & 0x01 )
61 hwpf.AddPage();
62 pPara->pshape.reserved[0] = sal::static_int_cast<unsigned char>(pex & 0x01);
63 pPara->pshape.reserved[1] = sal::static_int_cast<unsigned char>(pex & 0x02);
66 return (!hwpf.State());
69 HWPPara::HWPPara()
70 : _next(NULL)
71 , reuse_shape(0)
72 , nch(0)
73 , nline(0)
74 , begin_ypos(0)
75 , scflag(0)
76 , contain_cshape(0)
77 , etcflag(0)
78 , ctrlflag(0)
79 , pstyno(0)
80 , pno(0)
81 , linfo(NULL)
82 , cshapep(NULL)
83 , hhstr(NULL)
85 memset(&cshape, 0, sizeof(cshape));
86 memset(&pshape, 0, sizeof(pshape));
89 HWPPara::~HWPPara()
91 delete[] linfo;
92 delete[] cshapep;
93 if (hhstr)
95 // virtual destructor
96 /* C++은 null에 대해서도 동작한다. */
97 for (int ii = 0; ii < nch; ++ii)
98 delete hhstr[ii];
100 delete[]hhstr;
106 bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
108 unsigned char same_cshape;
109 int ii;
110 scflag = flag;
111 // Paragraph Information
112 hwpf.Read1b(&reuse_shape, 1);
113 hwpf.Read2b(&nch, 1);
114 hwpf.Read2b(&nline, 1);
115 hwpf.Read1b(&contain_cshape, 1);
116 hwpf.Read1b(&etcflag, 1);
117 hwpf.Read4b(&ctrlflag, 1);
118 hwpf.Read1b(&pstyno, 1);
121 /* Paragraph 대표 글자 */
122 cshape.Read(hwpf);
123 if (nch > 0)
124 hwpf.AddCharShape(&cshape);
126 /* Paragraph 문단 모양 */
127 if (nch && !reuse_shape)
129 pshape.Read(hwpf);
130 pshape.cshape = &cshape;
131 pshape.pagebreak = etcflag;
134 linfo = ::comphelper::newArray_null<LineInfo>(nline);
135 if (!linfo) { return false; }
136 for (ii = 0; ii < nline; ii++)
138 linfo[ii].Read(hwpf, this);
140 if( etcflag & 0x04 ){
141 hwpf.AddColumnInfo();
144 if (nch && !reuse_shape){
145 if( pshape.coldef.ncols > 1 ){
146 hwpf.SetColumnDef( &pshape.coldef );
151 if( nline > 0 )
153 begin_ypos = linfo[0].pgy;
155 else
157 begin_ypos = 0;
160 if (contain_cshape)
162 cshapep = ::comphelper::newArray_null<CharShape>(nch);
163 if (!cshapep)
165 perror("Memory Allocation: cshape\n");
166 return false;
169 for (ii = 0; ii < nch; ii++)
172 hwpf.Read1b(&same_cshape, 1);
173 if (!same_cshape)
175 cshapep[ii].Read(hwpf);
176 if (nch > 1)
177 hwpf.AddCharShape(&cshapep[ii]);
179 else if (ii == 0)
180 cshapep[ii] = cshape;
181 else
182 cshapep[ii] = cshapep[ii - 1];
185 // read string
186 hhstr = ::comphelper::newArray_null<HBox *>(nch);
187 if (!hhstr) { return false; }
188 for (ii = 0; ii < nch; ii++)
189 hhstr[ii] = 0;
190 ii = 0;
191 while (ii < nch)
193 if (0 == (hhstr[ii] = readHBox(hwpf)))
194 return false;
195 if (hhstr[ii]->hh == CH_END_PARA)
196 break;
197 if( hhstr[ii]->hh < CH_END_PARA )
198 pshape.reserved[0] = 0;
199 ii += hhstr[ii]->WSize();
201 return nch && !hwpf.State();
207 CharShape *HWPPara::GetCharShape(int pos)
209 if (contain_cshape == 0)
210 return &cshape;
211 return cshapep + pos;
217 HBox *HWPPara::readHBox(HWPFile & hwpf)
219 hchar hh;
220 if (!hwpf.Read2b(hh))
221 return 0;
223 HBox *hbox = 0;
225 if (hwpf.State() != HWP_NoError)
226 return 0;
228 if (hh > 31 || hh == CH_END_PARA)
229 hbox = new HBox(hh);
230 else if (IS_SP_SKIP_BLOCK(hh))
231 hbox = new SkipData(hh);
232 else
234 switch (hh)
236 case CH_FIELD: // 5
237 hbox = new FieldCode;
238 break;
239 case CH_BOOKMARK: // 6
240 hbox = new Bookmark;
241 break;
242 case CH_DATE_FORM: // 7
243 hbox = new DateFormat;
244 break;
245 case CH_DATE_CODE: // 8
246 hbox = new DateCode;
247 break;
248 case CH_TAB: // 9
249 hbox = new Tab;
250 break;
251 case CH_TEXT_BOX: // 10
252 hbox = new TxtBox;
253 break;
254 case CH_PICTURE: // 11
255 hbox = new Picture;
256 break;
257 case CH_LINE: // 14
258 hbox = new Line;
259 break;
260 case CH_HIDDEN: // 15
261 hbox = new Hidden;
262 break;
263 case CH_HEADER_FOOTER: // 16
264 hbox = new HeaderFooter;
265 break;
266 case CH_FOOTNOTE: // 17
267 hbox = new Footnote;
268 break;
269 case CH_AUTO_NUM: // 18
270 hbox = new AutoNum;
271 break;
272 case CH_NEW_NUM: // 19
273 hbox = new NewNum;
274 break;
275 case CH_SHOW_PAGE_NUM: // 20
276 hbox = new ShowPageNum;
277 break;
278 case CH_PAGE_NUM_CTRL: // 21
279 hbox = new PageNumCtrl;
280 break;
281 case CH_MAIL_MERGE: // 22
282 hbox = new MailMerge;
283 break;
284 case CH_COMPOSE: // 23
285 hbox = new Compose;
286 break;
287 case CH_HYPHEN: // 24
288 hbox = new Hyphen;
289 break;
290 case CH_TOC_MARK: // 25
291 hbox = new TocMark;
292 break;
293 case CH_INDEX_MARK: // 26
294 hbox = new IndexMark;
295 break;
296 case CH_OUTLINE: // 28
297 hbox = new Outline;
298 break;
299 case CH_KEEP_SPACE: // 30
300 hbox = new KeepSpace;
301 break;
302 case CH_FIXED_SPACE: // 31
303 hbox = new FixedSpace;
304 break;
305 default:
306 break;
309 if (!hbox || !hbox->Read(hwpf))
311 delete hbox;
313 return 0;
315 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
317 FBox *fbox = static_cast<FBox *>(hbox);
318 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
320 //strange construct to compile without warning
321 int nTemp = fbox->pgy;
322 nTemp -= begin_ypos;
323 fbox->pgy = sal::static_int_cast<short>(nTemp);
326 return hbox;
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */