1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "precompile.h"
24 #include <comphelper/newarray.hxx>
32 void LineInfo::Read(HWPFile
& hwpf
, HWPPara
const *pPara
)
35 if (!hwpf
.Read2b(tmp16
))
37 // unused field is "pos" "Starting character position"
38 if (!hwpf
.Read2b(tmp16
))
40 // unused field is "space_width"
41 if (!hwpf
.Read2b(tmp16
))
43 // unused field is "height"
44 // internal information
45 if (!hwpf
.Read2b(tmp16
))
48 if (!hwpf
.Read2b(tmp16
))
50 // unused field is "sx"
51 if (!hwpf
.Read2b(tmp16
))
53 // unused field is "psx"
54 if (!hwpf
.Read2b(tmp16
))
58 if( pex
>> 15 & 0x01 )
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);
78 , cshape(std::make_shared
<CharShape
>())
79 , pshape(std::make_shared
<ParaShape
>())
87 bool HWPPara::Read(HWPFile
& hwpf
, unsigned char flag
)
89 DepthGuard
aGuard(hwpf
);
94 // Paragraph Information
95 hwpf
.Read1b(reuse_shape
);
97 hwpf
.Read2b(&nline
, 1);
98 hwpf
.Read1b(contain_cshape
);
100 hwpf
.Read4b(ctrlflag
);
103 /* Paragraph representative character */
106 hwpf
.AddCharShape(cshape
);
108 /* Paragraph paragraphs shape */
109 if (nch
&& !reuse_shape
)
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
);
133 begin_ypos
= linfo
[0].pgy
;
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
);
152 cshapep
[ii
]->Read(hwpf
);
154 hwpf
.AddCharShape(cshapep
[ii
]);
157 cshapep
[ii
] = cshape
;
159 cshapep
[ii
] = cshapep
[ii
- 1];
166 auto hBox
= readHBox(hwpf
);
169 hhstr
.emplace_back(std::move(hBox
));
170 if (hhstr
.back()->hh
== CH_END_PARA
)
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)
183 return cshapep
[pos
].get();
186 std::unique_ptr
<HBox
> HWPPara::readHBox(HWPFile
& hwpf
)
188 std::unique_ptr
<HBox
> hbox
;
191 if (!hwpf
.Read2b(hh
))
194 if (hwpf
.State() != HWP_NoError
)
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
));
206 hbox
.reset(new FieldCode
);
208 case CH_BOOKMARK
: // 6
209 hbox
.reset(new Bookmark
);
211 case CH_DATE_FORM
: // 7
212 hbox
.reset(new DateFormat
);
214 case CH_DATE_CODE
: // 8
215 hbox
.reset(new DateCode
);
220 case CH_TEXT_BOX
: // 10
221 hbox
.reset(new TxtBox
);
223 case CH_PICTURE
: // 11
224 hbox
.reset(new Picture
);
227 hbox
.reset(new Line
);
229 case CH_HIDDEN
: // 15
230 hbox
.reset(new Hidden
);
232 case CH_HEADER_FOOTER
: // 16
233 if (!hwpf
.already_importing_type(CH_HEADER_FOOTER
))
234 hbox
.reset(new HeaderFooter
);
236 case CH_FOOTNOTE
: // 17
237 hbox
.reset(new Footnote
);
239 case CH_AUTO_NUM
: // 18
240 hbox
.reset(new AutoNum
);
242 case CH_NEW_NUM
: // 19
243 hbox
.reset(new NewNum
);
245 case CH_SHOW_PAGE_NUM
: // 20
246 hbox
.reset(new ShowPageNum
);
248 case CH_PAGE_NUM_CTRL
: // 21
249 hbox
.reset(new PageNumCtrl
);
251 case CH_MAIL_MERGE
: // 22
252 hbox
.reset(new MailMerge
);
254 case CH_COMPOSE
: // 23
255 hbox
.reset(new Compose
);
257 case CH_HYPHEN
: // 24
258 hbox
.reset(new Hyphen
);
260 case CH_TOC_MARK
: // 25
261 hbox
.reset(new TocMark
);
263 case CH_INDEX_MARK
: // 26
264 hbox
.reset(new IndexMark
);
266 case CH_OUTLINE
: // 28
267 hbox
.reset(new Outline
);
269 case CH_KEEP_SPACE
: // 30
270 hbox
.reset(new KeepSpace
);
272 case CH_FIXED_SPACE
: // 31
273 hbox
.reset(new FixedSpace
);
283 hwpf
.push_hpara_type(scflag
);
284 bool bRead
= hbox
->Read(hwpf
);
285 hwpf
.pop_hpara_type();
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
;
300 fbox
->pgy
= sal::static_int_cast
<short>(nTemp
);
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */