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 .
20 #include "precompile.h"
22 #include <osl/diagnose.h>
24 #include <comphelper/newarray.hxx>
32 bool LineInfo::Read(HWPFile
& hwpf
, HWPPara
*pPara
)
34 pos
= sal::static_int_cast
<unsigned short>(hwpf
.Read2b());
35 space_width
= (short) hwpf
.Read2b();
36 height
= (short) hwpf
.Read2b();
37 // internal information
38 pgy
= (short) hwpf
.Read2b();
39 sx
= (short) hwpf
.Read2b();
40 psx
= (short) hwpf
.Read2b();
41 pex
= (short) hwpf
.Read2b();
44 if( pex
>> 15 & 0x01 )
48 pPara
->pshape
.reserved
[0] = sal::static_int_cast
<unsigned char>(pex
& 0x01);
49 pPara
->pshape
.reserved
[1] = sal::static_int_cast
<unsigned char>(pex
& 0x02);
52 return (!hwpf
.State());
56 HWPPara::HWPPara(void)
67 HWPPara::~HWPPara(void)
76 /* C++은 null에 대해서도 동작한다. */
77 for (int ii
= 0; ii
< nch
; ++ii
)
86 int HWPPara::Read(HWPFile
& hwpf
, unsigned char flag
)
88 unsigned char same_cshape
;
91 // Paragraph Information
92 hwpf
.Read1b(&reuse_shape
, 1);
94 hwpf
.Read2b(&nline
, 1);
95 hwpf
.Read1b(&contain_cshape
, 1);
96 hwpf
.Read1b(&etcflag
, 1);
97 hwpf
.Read4b(&ctrlflag
, 1);
98 hwpf
.Read1b(&pstyno
, 1);
101 /* Paragraph 대표 글자 */
104 hwpf
.AddCharShape(&cshape
);
106 /* Paragraph 문단 모양 */
107 if (nch
&& !reuse_shape
)
110 pshape
.cshape
= &cshape
;
111 pshape
.pagebreak
= etcflag
;
114 linfo
= ::comphelper::newArray_null
<LineInfo
>(nline
);
115 if (!linfo
) { return false; }
116 for (ii
= 0; ii
< nline
; ii
++)
118 linfo
[ii
].Read(hwpf
, this);
120 if( etcflag
& 0x04 ){
121 hwpf
.AddColumnInfo();
124 if (nch
&& !reuse_shape
){
125 if( pshape
.coldef
.ncols
> 1 ){
126 hwpf
.SetColumnDef( &pshape
.coldef
);
133 begin_ypos
= linfo
[0].pgy
;
142 cshapep
= ::comphelper::newArray_null
<CharShape
>(nch
);
145 perror("Memory Allocation: cshape\n");
149 for (ii
= 0; ii
< nch
; ii
++)
152 hwpf
.Read1b(&same_cshape
, 1);
155 cshapep
[ii
].Read(hwpf
);
157 hwpf
.AddCharShape(&cshapep
[ii
]);
160 cshapep
[ii
] = cshape
;
162 cshapep
[ii
] = cshapep
[ii
- 1];
166 hhstr
= ::comphelper::newArray_null
<HBox
*>(nch
);
167 if (!hhstr
) { return false; }
168 for (ii
= 0; ii
< nch
; ii
++)
173 if (0 == (hhstr
[ii
] = readHBox(hwpf
)))
175 if (hhstr
[ii
]->hh
== CH_END_PARA
)
177 if( hhstr
[ii
]->hh
< CH_END_PARA
)
178 pshape
.reserved
[0] = 0;
179 ii
+= hhstr
[ii
]->WSize();
181 return nch
&& !hwpf
.State();
185 HWPPara
*HWPPara::Next(void)
191 CharShape
*HWPPara::GetCharShape(int pos
)
193 if (contain_cshape
== 0)
195 return cshapep
+ pos
;
199 ParaShape
*HWPPara::GetParaShape(void)
205 HBox
*HWPPara::readHBox(HWPFile
& hwpf
)
207 hchar hh
= sal::static_int_cast
<hchar
>(hwpf
.Read2b());
210 if (hwpf
.State() != HWP_NoError
)
213 if (hh
> 31 || hh
== CH_END_PARA
)
215 else if (IS_SP_SKIP_BLOCK(hh
))
216 hbox
= new SkipData(hh
);
222 hbox
= new FieldCode
;
224 case CH_BOOKMARK
: // 6
227 case CH_DATE_FORM
: // 7
228 hbox
= new DateFormat
;
230 case CH_DATE_CODE
: // 8
236 case CH_TEXT_BOX
: // 10
239 case CH_PICTURE
: // 11
245 case CH_HIDDEN
: // 15
248 case CH_HEADER_FOOTER
: // 16
249 hbox
= new HeaderFooter
;
251 case CH_FOOTNOTE
: // 17
254 case CH_AUTO_NUM
: // 18
257 case CH_NEW_NUM
: // 19
260 case CH_SHOW_PAGE_NUM
: // 20
261 hbox
= new ShowPageNum
;
263 case CH_PAGE_NUM_CTRL
: // 21
264 hbox
= new PageNumCtrl
;
266 case CH_MAIL_MERGE
: // 22
267 hbox
= new MailMerge
;
269 case CH_COMPOSE
: // 23
272 case CH_HYPHEN
: // 24
275 case CH_TOC_MARK
: // 25
278 case CH_INDEX_MARK
: // 26
279 hbox
= new IndexMark
;
281 case CH_OUTLINE
: // 28
284 case CH_KEEP_SPACE
: // 30
285 hbox
= new KeepSpace
;
287 case CH_FIXED_SPACE
: // 31
288 hbox
= new FixedSpace
;
294 if (!hbox
|| !hbox
->Read(hwpf
))
300 if( hh
== CH_TEXT_BOX
|| hh
== CH_PICTURE
|| hh
== CH_LINE
)
302 FBox
*fbox
= static_cast<FBox
*>(hbox
);
303 if( ( fbox
->style
.anchor_type
== 1) && ( fbox
->pgy
>= begin_ypos
) )
305 //strange construct to compile without warning
306 int nTemp
= fbox
->pgy
;
308 fbox
->pgy
= sal::static_int_cast
<short>(nTemp
);
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */