LibreOffice Module hwpfilter (master) 1
hinfo.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 "precompile.h"
21
22#include "hwplib.h"
23#include "hinfo.h"
24#include "hwpfile.h"
25
26// Info Block
27
28
29static bool HWPReadInfoBlock(void *ptr, int len, HWPFile & hwpf)
30{
31 hwpf.info_block_len = len;
32 if (0 == len)
33 return true;
34 else
35 return hwpf.ReadBlock(ptr, len) != 0;
36}
37
38
39// Document Information
41 : cur_col(0)
42 , cur_row(0)
43 , readonly(0)
44 , encrypted(0)
45 , beginpagenum(0)
46 , beginfnnum(0)
47 , countfn(0)
48 , splinetext(0)
49 , splinefn(0)
50 , spfnfn(0)
51 , fnchar(0)
52 , fnlinetype(0)
53 , borderline(0)
54 , empty_line_hide(0)
55 , table_move(0)
56 , compressed(0)
57 , reserved3(0)
58 , info_block_len(0)
59{
60 back_info.isset = false;
61}
62
64{
65}
66
67
73{
74 hwpf.Read2b(&cur_col, 1); /* When a document is saving, the paragraph number where the coursor is */
75 hwpf.Read2b(&cur_row, 1); /* Paragraphs rows */
76
77 hwpf.Read1b(paper.paper_kind); /* Paper Type */
78 hwpf.Read1b(paper.paper_direction); /* Paper orientation */
79
80// paper geometry information
81 unsigned short tmp16;
82 if (!hwpf.Read2b(tmp16))
83 return;
84 paper.paper_height = tmp16; /* Paper length */
85 if (!hwpf.Read2b(tmp16))
86 return;
87 paper.paper_width = tmp16; /* Sheet width */
88 if (!hwpf.Read2b(tmp16))
89 return;
90 paper.top_margin = tmp16; /* Top margin */
91 if (!hwpf.Read2b(tmp16))
92 return;
93 paper.bottom_margin = tmp16; /* The bottom margin */
94 if (!hwpf.Read2b(tmp16))
95 return;
96 paper.left_margin = tmp16; /* Left Margin */
97 if (!hwpf.Read2b(tmp16))
98 return;
99 paper.right_margin = tmp16; /* Right margins */
100 if (!hwpf.Read2b(tmp16))
101 return;
102 paper.header_length = tmp16; /* Header length */
103 if (!hwpf.Read2b(tmp16))
104 return;
105 paper.footer_length = tmp16; /* Footer length */
106 if (!hwpf.Read2b(tmp16))
107 return;
108 paper.gutter_length = tmp16; /* The binding margin */
109 hwpf.Read2b(&readonly, 1); /* Reserve */
110 hwpf.ReadBlock(reserved1, 4); /* Reserve */
111 hwpf.Read1b(chain_info.chain_page_no); /* Connect page number: 1-Connect, 0-newly started (used in connection printing) */
112 hwpf.Read1b(chain_info.chain_footnote_no); /* Connect footnote number: 1-connect, 0-newly started*/
113 /* the file name to be printed with connection */
115
116 hwpf.ReadBlock(annotation, ANNOTATION_LEN); /* Annotation (additional information when a file is saving.) */
117 hwpf.Read2b(&encrypted, 1); /* encrypt: 0-normal file(without password), 1-protected by password */
118 hwpf.Read2b(&beginpagenum,1); /* Page starting number */
119
120// footnote
121 hwpf.Read2b(&beginfnnum,1); /* Footnote start number */
122 hwpf.Read2b(&countfn,1); /* Number of footnote */
123
124 if (!hwpf.Read2b(tmp16))
125 return;
126 splinetext = tmp16;
127 if (!hwpf.Read2b(tmp16))
128 return;
129 splinefn = tmp16;
130 if (!hwpf.Read2b(tmp16))
131 return;
132 spfnfn = tmp16;
133 hwpf.Read1b(fnchar);
134 hwpf.Read1b(fnlinetype);
135// border layout
136 for (int & ii : bordermargin)
137 {
138 if (!hwpf.Read2b(tmp16))
139 return;
140 ii = tmp16;
141 }
142 hwpf.Read2b(&borderline, 1);
143
145 hwpf.Read1b(table_move);
146 hwpf.Read1b(compressed);
147
148 hwpf.Read1b(reserved3);
149
150 hwpf.Read2b(&info_block_len, 1);
151 if (hwpf.State())
152 return;
153
154/* Read the article summary. */
155 if (!summary.Read(hwpf))
156 return;
157 if (info_block_len > 0)
158 {
159 info_block.reset( new unsigned char[info_block_len + 1] );
160
161 if (!HWPReadInfoBlock(info_block.get(), info_block_len, hwpf))
162 return;
163 }
164
165/* reset the value of hwpf. */
166 hwpf.compressed = compressed != 0;
167 hwpf.encrypted = encrypted != 0;
169 hwpf.SetCompressed(hwpf.compressed);
170}
171
172
173// Document Summary
174
176{
177 hwpf.Read2b(title, 56);
178 hwpf.Read2b(subject, 56);
179 hwpf.Read2b(author, 56);
180 hwpf.Read2b(date, 56);
181 hwpf.Read2b(keyword[0], 56);
182 hwpf.Read2b(keyword[1], 56);
183 hwpf.Read2b(etc[0], 56);
184 hwpf.Read2b(etc[1], 56);
185 hwpf.Read2b(etc[2], 56);
186
187 return (!hwpf.State());
188}
189
191 : index(0)
192 , left_margin(0)
193 , right_margin(0)
194 , indent(0)
195 , lspacing(0)
196 , pspacing_prev(0)
197 , pspacing_next(0)
198 , condense(0)
199 , arrange_type(0)
200 , xColdef(std::make_shared<ColumnDef>())
201 , shade(0)
202 , outline(0)
203 , outline_continue(0)
204 , pagebreak(0)
205{
206 reserved[0] = 0;
207 reserved[1] = 0;
208}
209
211{
212 pagebreak = 0;
213 unsigned short tmp16;
214 if (!hwpf.Read2b(tmp16))
215 return;
216 left_margin = tmp16;
217 if (!hwpf.Read2b(tmp16))
218 return;
219 right_margin = tmp16;
220 if (!hwpf.Read2b(tmp16))
221 return;
222 indent = tmp16;
223 if (!hwpf.Read2b(tmp16))
224 return;
225 lspacing = tmp16;
226 if (!hwpf.Read2b(tmp16))
227 return;
228 pspacing_next = tmp16;
229
230 hwpf.Read1b(condense);
231 hwpf.Read1b(arrange_type);
232 for (TabSet & tab : tabs)
233 {
234 hwpf.Read1b(tab.type);
235 hwpf.Read1b(tab.dot_continue);
236 if (!hwpf.Read2b(tmp16))
237 return;
238 tab.position = tmp16;
239 }
240 hwpf.Read1b(xColdef->ncols);
241 hwpf.Read1b(xColdef->separator);
242 if (!hwpf.Read2b(tmp16))
243 return;
244 xColdef->spacing = tmp16;
245 if (!hwpf.Read2b(tmp16))
246 return;
247 xColdef->columnlen = tmp16;
248 if (!hwpf.Read2b(tmp16))
249 return;
250 xColdef->columnlen0 = tmp16;
251 hwpf.Read1b(shade);
252 hwpf.Read1b(outline);
254 if (!hwpf.Read2b(tmp16))
255 return;
256 pspacing_prev = tmp16;
257
258 hwpf.ReadBlock(reserved, 2);
259}
260
262 : index(0)
263 , size(0)
264 , color{0}
265 , font(0)
266 , space(0)
267 , ratio(0)
268 , shade(0)
269 , attr(0)
270{
271}
272
274{
275 unsigned short tmp16;
276 if (!hwpf.Read2b(tmp16))
277 return;
278 size = tmp16;
279
280 hwpf.Read1b(font);
281 hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining font field
282
283 hwpf.Read1b(ratio);
284 hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining ratio field
285
286 hwpf.Read1b(space);
287 hwpf.SkipBlock(NLanguage - 1); //skip unused part of remaining space field
288
289 hwpf.ReadBlock(color, 2);
290 hwpf.Read1b(shade);
291 hwpf.Read1b(attr);
292 hwpf.SkipBlock(4);
293}
294
295/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
bool compressed
Definition: hwpfile.h:264
size_t SkipBlock(size_t size)
Skips some bytes from HIODev.
Definition: hwpfile.cxx:176
bool encrypted
Definition: hwpfile.h:265
int info_block_len
Definition: hwpfile.h:267
int State(void) const
Say current state.
Definition: hwpfile.h:119
void SetCompressed(bool)
Sets if the stream is compressed.
Definition: hwpfile.cxx:181
bool Read1b(unsigned char &out)
Reads one byte from HIODev.
Definition: hwpfile.cxx:123
bool Read2b(unsigned short &out)
Reads two byte from HIODev.
Definition: hwpfile.cxx:137
size_t ReadBlock(void *ptr, size_t size)
Reads some bytes from HIODev not regarding endian's way.
Definition: hwpfile.cxx:171
std::unique_ptr< unsigned char[]> info_block
Definition: hinfo.h:199
short countfn
Definition: hinfo.h:177
unsigned char compressed
Definition: hinfo.h:191
short cur_row
The row index of a document that is saved at last.
Definition: hinfo.h:153
short encrypted
Definition: hinfo.h:170
~HWPInfo(void)
Definition: hinfo.cxx:63
short beginpagenum
Definition: hinfo.h:172
short info_block_len
Definition: hinfo.h:193
hunit splinetext
Definition: hinfo.h:178
HWPInfo(void)
Definition: hinfo.cxx:40
unsigned char empty_line_hide
Definition: hinfo.h:189
PaperBackInfo back_info
Definition: hinfo.h:159
unsigned char table_move
Definition: hinfo.h:190
hunit splinefn
Definition: hinfo.h:178
hunit spfnfn
Definition: hinfo.h:179
unsigned char reserved1[4]
Definition: hinfo.h:164
hunit bordermargin[4]
Information about page layout.
Definition: hinfo.h:186
short readonly
Sets the attribute of read-only or read/write.
Definition: hinfo.h:163
short beginfnnum
Information about footnote.
Definition: hinfo.h:176
HWPSummary summary
Summary of document.
Definition: hinfo.h:198
DocChainInfo chain_info
Information about document chain.
Definition: hinfo.h:168
PaperInfo paper
Paper Information.
Definition: hinfo.h:157
short cur_col
The column index of a document that is saved at last.
Definition: hinfo.h:149
unsigned char annotation[ANNOTATION_LEN]
Definition: hinfo.h:169
unsigned char fnchar
Definition: hinfo.h:180
unsigned char fnlinetype
Definition: hinfo.h:181
void Read(HWPFile &hwpf)
Function for reading document information (128 bytes) Document information is the information after t...
Definition: hinfo.cxx:72
short borderline
Definition: hinfo.h:187
unsigned char reserved3
Definition: hinfo.h:192
static int indent
Definition: formula.cxx:39
static bool HWPReadInfoBlock(void *ptr, int len, HWPFile &hwpf)
Definition: hinfo.cxx:29
#define CHAIN_MAX_PATH
Definition: hinfo.h:29
#define ANNOTATION_LEN
Definition: hinfo.h:30
#define NLanguage
Definition: hwplib.h:115
size
index
std::shared_ptr< T > make_shared(Args &&... args)
unsigned char font
Definition: hinfo.h:223
char space
Definition: hinfo.h:224
unsigned char attr
Definition: hinfo.h:227
void Read(HWPFile &)
Definition: hinfo.cxx:273
unsigned char ratio
Definition: hinfo.h:225
unsigned char shade
Definition: hinfo.h:226
hunit size
Font size.
Definition: hinfo.h:221
CharShape()
Definition: hinfo.cxx:261
Column properties.
Definition: hinfo.h:257
unsigned char chain_filename[CHAIN_MAX_PATH]
Definition: hinfo.h:106
unsigned char chain_footnote_no
Definition: hinfo.h:105
unsigned char chain_page_no
Definition: hinfo.h:104
unsigned short title[56]
Definition: hinfo.h:120
unsigned short subject[56]
Definition: hinfo.h:121
unsigned short date[56]
Definition: hinfo.h:123
unsigned short keyword[2][56]
Definition: hinfo.h:124
bool Read(HWPFile &)
Definition: hinfo.cxx:175
unsigned short etc[3][56]
Definition: hinfo.h:125
unsigned short author[56]
Definition: hinfo.h:122
bool isset
Definition: hinfo.h:84
hunit right_margin
Definition: hinfo.h:282
ParaShape()
Definition: hinfo.cxx:190
void Read(HWPFile &)
Definition: hinfo.cxx:210
unsigned char condense
Definition: hinfo.h:287
hunit pspacing_next
Definition: hinfo.h:286
hunit left_margin
Definition: hinfo.h:281
unsigned char outline
Definition: hinfo.h:292
TabSet tabs[MAXTABS]
Definition: hinfo.h:289
unsigned char pagebreak
Definition: hinfo.h:296
unsigned char arrange_type
Definition: hinfo.h:288
hunit indent
Definition: hinfo.h:283
unsigned char outline_continue
Definition: hinfo.h:293
unsigned char reserved[2]
Definition: hinfo.h:294
hunit lspacing
Definition: hinfo.h:284
hunit pspacing_prev
Definition: hinfo.h:285
std::shared_ptr< ColumnDef > xColdef
Definition: hinfo.h:290
unsigned char shade
Definition: hinfo.h:291
Tab properties.
Definition: hinfo.h:241