LibreOffice Module hwpfilter (master) 1
hpara.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include "precompile.h"
22
23
25
26#include "hwplib.h"
27#include "hwpfile.h"
28#include "hpara.h"
29#include "hbox.h"
30#include "hutil.h"
31
32void LineInfo::Read(HWPFile & hwpf, HWPPara const *pPara)
33{
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;
56
57 hunit pex = tmp16;
58 if( pex >> 15 & 0x01 )
59 {
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);
64 }
65}
66
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>())
80{
81}
82
84{
85}
86
87bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
88{
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);
99 hwpf.Read1b(etcflag);
100 hwpf.Read4b(ctrlflag);
101 hwpf.Read1b(pstyno);
102
103/* Paragraph representative character */
104 cshape->Read(hwpf);
105 if (nch > 0)
106 hwpf.AddCharShape(cshape);
107
108/* Paragraph paragraphs shape */
109 if (nch && !reuse_shape)
110 {
111 pshape->Read(hwpf);
112 pshape->cshape = cshape;
113 pshape->pagebreak = etcflag;
114 }
115
116 linfo.reset(::comphelper::newArray_null<LineInfo>(nline));
117 for (ii = 0; ii < nline; ii++)
118 {
119 linfo[ii].Read(hwpf, this);
120 }
121 if( etcflag & 0x04 ){
122 hwpf.AddColumnInfo();
123 }
124
125 if (nch && !reuse_shape){
126 if( pshape->xColdef->ncols > 1 ) {
127 hwpf.SetColumnDef(pshape->xColdef);
128 }
129 }
130
131 if( nline > 0 )
132 {
133 begin_ypos = linfo[0].pgy;
134 }
135 else
136 {
137 begin_ypos = 0;
138 }
139
140 if (contain_cshape)
141 {
142 cshapep.resize(nch);
143
144 for (ii = 0; ii < nch; ii++)
145 {
146 cshapep[ii] = std::make_shared<CharShape>();
147
148 unsigned char same_cshape(0);
149 hwpf.Read1b(same_cshape);
150 if (!same_cshape)
151 {
152 cshapep[ii]->Read(hwpf);
153 if (nch > 1)
154 hwpf.AddCharShape(cshapep[ii]);
155 }
156 else if (ii == 0)
157 cshapep[ii] = cshape;
158 else
159 cshapep[ii] = cshapep[ii - 1];
160 }
161 }
162// read string
163 ii = 0;
164 while (ii < nch)
165 {
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();
175 }
176 return nch && !hwpf.State();
177}
178
180{
181 if (contain_cshape == 0)
182 return cshape.get();
183 return cshapep[pos].get();
184}
185
186std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
187{
188 std::unique_ptr<HBox> hbox;
189
190 hchar hh;
191 if (!hwpf.Read2b(hh))
192 return hbox;
193
194 if (hwpf.State() != HWP_NoError)
195 return hbox;
196
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
202 {
203 switch (hh)
204 {
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
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;
277 }
278 }
279
280 if (!hbox)
281 return nullptr;
282
284 bool bRead = hbox->Read(hwpf);
285 hwpf.pop_hpara_type();
286 if (!bRead)
287 {
288 hbox.reset();
289 return nullptr;
290 }
291
292 if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
293 {
294 FBox *fbox = static_cast<FBox *>(hbox.get());
295 if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
296 {
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);
301 }
302 }
303 return hbox;
304}
305
306/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool toodeep() const
Definition: hwpfile.h:319
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
void SetColumnDef(std::shared_ptr< ColumnDef > const &)
Definition: hwpfile.cxx:573
void AddColumnInfo()
Definition: hwpfile.cxx:567
int State(void) const
Say current state.
Definition: hwpfile.h:119
void AddCharShape(std::shared_ptr< CharShape > const &)
Definition: hwpfile.cxx:555
void AddPage()
Definition: hwpfile.h:206
bool Read1b(unsigned char &out)
Reads one byte from HIODev.
Definition: hwpfile.cxx:123
void pop_hpara_type()
Definition: hwpfile.h:254
bool already_importing_type(unsigned char scflag) const
Definition: hwpfile.h:250
void push_hpara_type(unsigned char scflag)
Definition: hwpfile.h:249
bool Read2b(unsigned short &out)
Reads two byte from HIODev.
Definition: hwpfile.cxx:137
bool Read4b(unsigned int &out)
Reads four byte from HIODev.
Definition: hwpfile.cxx:152
It represents the paragraph.
Definition: hpara.h:69
unsigned short nline
Definition: hpara.h:80
hunit begin_ypos
Definition: hpara.h:83
std::unique_ptr< HBox > readHBox(HWPFile &)
Definition: hpara.cxx:186
~HWPPara(void)
Definition: hpara.cxx:83
std::vector< std::unique_ptr< HBox > > hhstr
Box object list.
Definition: hpara.h:104
CharShape * GetCharShape(int pos)
Returns the character style of paragraph.
Definition: hpara.cxx:179
std::unique_ptr< LineInfo[]> linfo
Definition: hpara.h:99
unsigned char contain_cshape
If the value is 0, all character of paragraph have same style given cshape.
Definition: hpara.h:89
bool Read(HWPFile &hwpf, unsigned char flag)
Definition: hpara.cxx:87
uint ctrlflag
Checks the special characters in the paragraph.
Definition: hpara.h:94
unsigned char reuse_shape
Zero is for the new paragraph style.
Definition: hpara.h:78
unsigned char scflag
Definition: hpara.h:84
std::shared_ptr< ParaShape > pshape
Definition: hpara.h:97
unsigned char pstyno
Definition: hpara.h:95
std::vector< std::shared_ptr< CharShape > > cshapep
Definition: hpara.h:100
unsigned short nch
Definition: hpara.h:79
HWPPara(void)
Definition: hpara.cxx:67
unsigned char etcflag
Definition: hpara.h:90
std::shared_ptr< CharShape > cshape
Definition: hpara.h:96
Number and format of title.
Definition: hbox.h:947
#define CH_DATE_CODE
Definition: hwplib.h:126
#define CH_MAIL_MERGE
Definition: hwplib.h:141
#define CH_HYPHEN
Definition: hwplib.h:143
char16_t hchar
size of hunit is 4 since hwp96 version
Definition: hwplib.h:36
#define CH_COMPOSE
Definition: hwplib.h:142
int hunit
Definition: hwplib.h:37
#define CH_KEEP_SPACE
Definition: hwplib.h:152
#define IS_SP_SKIP_BLOCK(hch)
Definition: hwplib.h:158
@ HWP_NoError
Definition: hwplib.h:175
#define CH_END_PARA
Definition: hwplib.h:131
#define CH_TEXT_BOX
Definition: hwplib.h:128
#define CH_AUTO_NUM
Definition: hwplib.h:136
#define CH_TOC_MARK
Definition: hwplib.h:145
#define CH_TAB
Definition: hwplib.h:127
#define CH_FIELD
Definition: hwplib.h:122
#define CH_PICTURE
Definition: hwplib.h:129
#define CH_FOOTNOTE
Definition: hwplib.h:135
#define CH_NEW_NUM
Definition: hwplib.h:137
#define CH_DATE_FORM
Definition: hwplib.h:125
#define CH_SHOW_PAGE_NUM
Definition: hwplib.h:139
#define CH_OUTLINE
Definition: hwplib.h:149
#define CH_HEADER_FOOTER
Definition: hwplib.h:134
#define CH_FIXED_SPACE
Definition: hwplib.h:153
#define CH_PAGE_NUM_CTRL
Definition: hwplib.h:140
#define CH_BOOKMARK
Definition: hwplib.h:123
#define CH_HIDDEN
Definition: hwplib.h:133
#define CH_LINE
Definition: hwplib.h:132
#define CH_INDEX_MARK
Definition: hwplib.h:146
std::shared_ptr< T > make_shared(Args &&... args)
Input current index of page,comment,table and picture.
Definition: hbox.h:757
Class for BOOKMARK.
Definition: hbox.h:113
Style of character.
Definition: hinfo.h:213
The compose struct displays characters at position.
Definition: hbox.h:846
Class for current date and time with specified format.
Definition: hbox.h:142
Class for saving date format made by user.
Definition: hbox.h:130
unsigned char anchor_type
Anchor type : paragraph , page, char.
Definition: hbox.h:242
This object is for floating object like table, image, line and so on.
Definition: hbox.h:292
FBoxStyle style
Definition: hbox.h:296
short pgy
Definition: hbox.h:315
Definition: hbox.h:82
Space with always same width not relation with fonts.
Definition: hbox.h:998
Both footnote and endnote are comment.
Definition: hbox.h:711
The HBox class is the base class for all date classes in hwp document.
Definition: hbox.h:44
Header or footer.
Definition: hbox.h:681
Hidden section.
Definition: hbox.h:664
Hyphen.
Definition: hbox.h:860
IndexMark marks the table of search.
Definition: hbox.h:895
The Special space to be treated non-space when a string is cut at the end of line.
Definition: hbox.h:985
Line.
Definition: hbox.h:645
Generates the mailing list automatically using address book and mail body format.
Definition: hbox.h:830
Input new number as current index of page,comment,table and picture.
Definition: hbox.h:771
Controls the display of page number, header, footer and border.
Definition: hbox.h:808
Style of paragraph.
Definition: hinfo.h:276
There are four kinds of image.
Definition: hbox.h:593
Input page index in footer or header.
Definition: hbox.h:786
Class for skipping data.
Definition: hbox.h:74
Tab object.
Definition: hbox.h:166
The TocMark class is for making the content of a table.
Definition: hbox.h:879
The TxtBox class saves object properties about table, textbox, equalizer or button.
Definition: hbox.h:327
size_t pos