Fix GNU C++ version check
[LibreOffice.git] / hwpfilter / source / hpara.cxx
blob4cddf7d76ad78ef0ebbf129befd943d17e351961
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 <memory>
21 #include "precompile.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 void LineInfo::Read(HWPFile & hwpf, HWPPara const *pPara)
34 unsigned short tmp16;
35 if (!hwpf.Read2b(tmp16))
36 return;
37 // unused field is "pos" "Starting character position"
38 if (!hwpf.Read2b(tmp16))
39 return;
40 // unused field is "space_width"
41 if (!hwpf.Read2b(tmp16))
42 return;
43 // unused field is "height"
44 // internal information
45 if (!hwpf.Read2b(tmp16))
46 return;
47 pgy = tmp16;
48 if (!hwpf.Read2b(tmp16))
49 return;
50 // unused field is "sx"
51 if (!hwpf.Read2b(tmp16))
52 return;
53 // unused field is "psx"
54 if (!hwpf.Read2b(tmp16))
55 return;
57 hunit pex = tmp16;
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);
67 HWPPara::HWPPara()
68 : _next(nullptr)
69 , reuse_shape(0)
70 , nch(0)
71 , nline(0)
72 , begin_ypos(0)
73 , scflag(0)
74 , contain_cshape(0)
75 , etcflag(0)
76 , ctrlflag(0)
77 , pstyno(0)
78 , cshape(std::make_shared<CharShape>())
79 , pshape(std::make_shared<ParaShape>())
83 HWPPara::~HWPPara()
87 bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
89 DepthGuard aGuard(hwpf);
90 if (aGuard.toodeep())
91 return false;
92 int ii;
93 scflag = flag;
94 // Paragraph Information
95 hwpf.Read1b(reuse_shape);
96 hwpf.Read2b(&nch, 1);
97 hwpf.Read2b(&nline, 1);
98 hwpf.Read1b(contain_cshape);
99 hwpf.Read1b(etcflag);
100 hwpf.Read4b(ctrlflag);
101 hwpf.Read1b(pstyno);
103 /* Paragraph representative character */
104 cshape->Read(hwpf);
105 if (nch > 0)
106 hwpf.AddCharShape(cshape);
108 /* Paragraph paragraphs shape */
109 if (nch && !reuse_shape)
111 pshape->Read(hwpf);
112 pshape->cshape = cshape;
113 pshape->pagebreak = etcflag;
116 linfo.reset(::comphelper::newArray_null<LineInfo>(nline));
117 for (ii = 0; ii < nline; ii++)
119 linfo[ii].Read(hwpf, this);
121 if( etcflag & 0x04 ){
122 hwpf.AddColumnInfo();
125 if (nch && !reuse_shape){
126 if( pshape->xColdef->ncols > 1 ) {
127 hwpf.SetColumnDef(pshape->xColdef);
131 if( nline > 0 )
133 begin_ypos = linfo[0].pgy;
135 else
137 begin_ypos = 0;
140 if (contain_cshape)
142 cshapep.resize(nch);
144 for (ii = 0; ii < nch; ii++)
146 cshapep[ii] = std::make_shared<CharShape>();
148 unsigned char same_cshape(0);
149 hwpf.Read1b(same_cshape);
150 if (!same_cshape)
152 cshapep[ii]->Read(hwpf);
153 if (nch > 1)
154 hwpf.AddCharShape(cshapep[ii]);
156 else if (ii == 0)
157 cshapep[ii] = cshape;
158 else
159 cshapep[ii] = cshapep[ii - 1];
162 // read string
163 ii = 0;
164 while (ii < nch)
166 auto hBox = readHBox(hwpf);
167 if (!hBox)
168 return false;
169 hhstr.emplace_back(std::move(hBox));
170 if (hhstr.back()->hh == CH_END_PARA)
171 break;
172 if( hhstr.back()->hh < CH_END_PARA )
173 pshape->reserved[0] = 0;
174 ii += hhstr.back()->WSize();
176 return nch && !hwpf.State();
179 CharShape *HWPPara::GetCharShape(int pos)
181 if (contain_cshape == 0)
182 return cshape.get();
183 return cshapep[pos].get();
186 std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
188 std::unique_ptr<HBox> hbox;
190 hchar hh;
191 if (!hwpf.Read2b(hh))
192 return hbox;
194 if (hwpf.State() != HWP_NoError)
195 return hbox;
197 if (hh > 31 || hh == CH_END_PARA)
198 hbox.reset(new HBox(hh));
199 else if (IS_SP_SKIP_BLOCK(hh))
200 hbox.reset(new SkipData(hh));
201 else
203 switch (hh)
205 case CH_FIELD: // 5
206 hbox.reset(new FieldCode);
207 break;
208 case CH_BOOKMARK: // 6
209 hbox.reset(new Bookmark);
210 break;
211 case CH_DATE_FORM: // 7
212 hbox.reset(new DateFormat);
213 break;
214 case CH_DATE_CODE: // 8
215 hbox.reset(new DateCode);
216 break;
217 case CH_TAB: // 9
218 hbox.reset(new Tab);
219 break;
220 case CH_TEXT_BOX: // 10
221 hbox.reset(new TxtBox);
222 break;
223 case CH_PICTURE: // 11
224 hbox.reset(new Picture);
225 break;
226 case CH_LINE: // 14
227 hbox.reset(new Line);
228 break;
229 case CH_HIDDEN: // 15
230 hbox.reset(new Hidden);
231 break;
232 case CH_HEADER_FOOTER: // 16
233 if (!hwpf.already_importing_type(CH_HEADER_FOOTER))
234 hbox.reset(new HeaderFooter);
235 break;
236 case CH_FOOTNOTE: // 17
237 hbox.reset(new Footnote);
238 break;
239 case CH_AUTO_NUM: // 18
240 hbox.reset(new AutoNum);
241 break;
242 case CH_NEW_NUM: // 19
243 hbox.reset(new NewNum);
244 break;
245 case CH_SHOW_PAGE_NUM: // 20
246 hbox.reset(new ShowPageNum);
247 break;
248 case CH_PAGE_NUM_CTRL: // 21
249 hbox.reset(new PageNumCtrl);
250 break;
251 case CH_MAIL_MERGE: // 22
252 hbox.reset(new MailMerge);
253 break;
254 case CH_COMPOSE: // 23
255 hbox.reset(new Compose);
256 break;
257 case CH_HYPHEN: // 24
258 hbox.reset(new Hyphen);
259 break;
260 case CH_TOC_MARK: // 25
261 hbox.reset(new TocMark);
262 break;
263 case CH_INDEX_MARK: // 26
264 hbox.reset(new IndexMark);
265 break;
266 case CH_OUTLINE: // 28
267 hbox.reset(new Outline);
268 break;
269 case CH_KEEP_SPACE: // 30
270 hbox.reset(new KeepSpace);
271 break;
272 case CH_FIXED_SPACE: // 31
273 hbox.reset(new FixedSpace);
274 break;
275 default:
276 break;
280 if (!hbox)
281 return nullptr;
283 hwpf.push_hpara_type(scflag);
284 bool bRead = hbox->Read(hwpf);
285 hwpf.pop_hpara_type();
286 if (!bRead)
288 hbox.reset();
289 return nullptr;
292 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
294 FBox *fbox = static_cast<FBox *>(hbox.get());
295 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
297 //strange construct to compile without warning
298 int nTemp = fbox->pgy;
299 nTemp -= begin_ypos;
300 fbox->pgy = sal::static_int_cast<short>(nTemp);
303 return hbox;
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */