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
)
34 if (!hwpf
.Read2b(pos
))
37 if (!hwpf
.Read2b(tmp16
))
40 if (!hwpf
.Read2b(tmp16
))
43 // internal information
44 if (!hwpf
.Read2b(tmp16
))
47 if (!hwpf
.Read2b(tmp16
))
50 if (!hwpf
.Read2b(tmp16
))
53 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
>())
81 memset(cshape
.get(), 0, sizeof(CharShape
));
88 bool HWPPara::Read(HWPFile
& hwpf
, unsigned char flag
)
90 DepthGuard
aGuard(hwpf
);
95 // Paragraph Information
96 hwpf
.Read1b(reuse_shape
);
98 hwpf
.Read2b(&nline
, 1);
99 hwpf
.Read1b(contain_cshape
);
100 hwpf
.Read1b(etcflag
);
101 hwpf
.Read4b(&ctrlflag
, 1);
104 /* Paragraph representative character */
107 hwpf
.AddCharShape(cshape
);
109 /* Paragraph paragraphs shape */
110 if (nch
&& !reuse_shape
)
113 pshape
->cshape
= cshape
;
114 pshape
->pagebreak
= etcflag
;
117 linfo
.reset(::comphelper::newArray_null
<LineInfo
>(nline
));
118 for (ii
= 0; ii
< nline
; ii
++)
120 linfo
[ii
].Read(hwpf
, this);
122 if( etcflag
& 0x04 ){
123 hwpf
.AddColumnInfo();
126 if (nch
&& !reuse_shape
){
127 if( pshape
->xColdef
->ncols
> 1 ) {
128 hwpf
.SetColumnDef(pshape
->xColdef
);
134 begin_ypos
= linfo
[0].pgy
;
145 for (ii
= 0; ii
< nch
; ii
++)
147 cshapep
[ii
] = std::make_shared
<CharShape
>();
148 memset(cshapep
[ii
].get(), 0, sizeof(CharShape
));
150 unsigned char same_cshape(0);
151 hwpf
.Read1b(same_cshape
);
154 cshapep
[ii
]->Read(hwpf
);
156 hwpf
.AddCharShape(cshapep
[ii
]);
159 cshapep
[ii
] = cshape
;
161 cshapep
[ii
] = cshapep
[ii
- 1];
168 auto hBox
= readHBox(hwpf
);
171 hhstr
[ii
] = std::move(hBox
);
172 if (hhstr
[ii
]->hh
== CH_END_PARA
)
174 if( hhstr
[ii
]->hh
< CH_END_PARA
)
175 pshape
->reserved
[0] = 0;
176 ii
+= hhstr
[ii
]->WSize();
178 return nch
&& !hwpf
.State();
181 CharShape
*HWPPara::GetCharShape(int pos
)
183 if (contain_cshape
== 0)
185 return cshapep
[pos
].get();
188 std::unique_ptr
<HBox
> HWPPara::readHBox(HWPFile
& hwpf
)
190 std::unique_ptr
<HBox
> hbox
;
193 if (!hwpf
.Read2b(hh
))
196 if (hwpf
.State() != HWP_NoError
)
199 if (hh
> 31 || hh
== CH_END_PARA
)
200 hbox
.reset(new HBox(hh
));
201 else if (IS_SP_SKIP_BLOCK(hh
))
202 hbox
.reset(new SkipData(hh
));
208 hbox
.reset(new FieldCode
);
210 case CH_BOOKMARK
: // 6
211 hbox
.reset(new Bookmark
);
213 case CH_DATE_FORM
: // 7
214 hbox
.reset(new DateFormat
);
216 case CH_DATE_CODE
: // 8
217 hbox
.reset(new DateCode
);
222 case CH_TEXT_BOX
: // 10
223 hbox
.reset(new TxtBox
);
225 case CH_PICTURE
: // 11
226 hbox
.reset(new Picture
);
229 hbox
.reset(new Line
);
231 case CH_HIDDEN
: // 15
232 hbox
.reset(new Hidden
);
234 case CH_HEADER_FOOTER
: // 16
235 if (!hwpf
.already_importing_type(CH_HEADER_FOOTER
))
236 hbox
.reset(new HeaderFooter
);
238 case CH_FOOTNOTE
: // 17
239 hbox
.reset(new Footnote
);
241 case CH_AUTO_NUM
: // 18
242 hbox
.reset(new AutoNum
);
244 case CH_NEW_NUM
: // 19
245 hbox
.reset(new NewNum
);
247 case CH_SHOW_PAGE_NUM
: // 20
248 hbox
.reset(new ShowPageNum
);
250 case CH_PAGE_NUM_CTRL
: // 21
251 hbox
.reset(new PageNumCtrl
);
253 case CH_MAIL_MERGE
: // 22
254 hbox
.reset(new MailMerge
);
256 case CH_COMPOSE
: // 23
257 hbox
.reset(new Compose
);
259 case CH_HYPHEN
: // 24
260 hbox
.reset(new Hyphen
);
262 case CH_TOC_MARK
: // 25
263 hbox
.reset(new TocMark
);
265 case CH_INDEX_MARK
: // 26
266 hbox
.reset(new IndexMark
);
268 case CH_OUTLINE
: // 28
269 hbox
.reset(new Outline
);
271 case CH_KEEP_SPACE
: // 30
272 hbox
.reset(new KeepSpace
);
274 case CH_FIXED_SPACE
: // 31
275 hbox
.reset(new FixedSpace
);
285 hwpf
.push_hpara_type(scflag
);
286 bool bRead
= hbox
->Read(hwpf
);
287 hwpf
.pop_hpara_type();
294 if( hh
== CH_TEXT_BOX
|| hh
== CH_PICTURE
|| hh
== CH_LINE
)
296 FBox
*fbox
= static_cast<FBox
*>(hbox
.get());
297 if( ( fbox
->style
.anchor_type
== 1) && ( fbox
->pgy
>= begin_ypos
) )
299 //strange construct to compile without warning
300 int nTemp
= fbox
->pgy
;
302 fbox
->pgy
= sal::static_int_cast
<short>(nTemp
);
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */