Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / hwpfilter / source / hinfo.cxx
blob025e54b7a6de727fe1697ab8acbbab21288fd06d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "hwplib.h"
23 #include "hinfo.h"
24 #include "hwpfile.h"
26 // Info Block
29 static bool HWPReadInfoBlock(void *ptr, int len, HWPFile & hwpf)
31 hwpf.info_block_len = len;
32 if (0 == len)
33 return true;
34 else
35 return hwpf.ReadBlock(ptr, len) != 0;
39 // Document Information
40 HWPInfo::HWPInfo()
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)
60 back_info.isset = false;
63 HWPInfo::~HWPInfo()
68 /**
69 * Function for reading document information (128 bytes)
70 * Document information is the information after the file identification information (30 bytes).
72 void HWPInfo::Read(HWPFile & hwpf)
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 */
77 hwpf.Read1b(paper.paper_kind); /* Paper Type */
78 hwpf.Read1b(paper.paper_direction); /* Paper orientation */
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 */
114 hwpf.ReadBlock(chain_info.chain_filename, CHAIN_MAX_PATH);
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 */
120 // footnote
121 hwpf.Read2b(&beginfnnum,1); /* Footnote start number */
122 hwpf.Read2b(&countfn,1); /* Number of footnote */
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)
138 if (!hwpf.Read2b(tmp16))
139 return;
140 ii = tmp16;
142 hwpf.Read2b(&borderline, 1);
144 hwpf.Read1b(empty_line_hide);
145 hwpf.Read1b(table_move);
146 hwpf.Read1b(compressed);
148 hwpf.Read1b(reserved3);
150 hwpf.Read2b(&info_block_len, 1);
151 if (hwpf.State())
152 return;
154 /* Read the article summary. */
155 if (!summary.Read(hwpf))
156 return;
157 if (info_block_len > 0)
159 info_block.reset( new unsigned char[info_block_len + 1] );
161 if (!HWPReadInfoBlock(info_block.get(), info_block_len, hwpf))
162 return;
165 /* reset the value of hwpf. */
166 hwpf.compressed = compressed != 0;
167 hwpf.encrypted = encrypted != 0;
168 hwpf.info_block_len = info_block_len;
169 hwpf.SetCompressed(hwpf.compressed);
173 // Document Summary
175 bool HWPSummary::Read(HWPFile & hwpf)
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);
187 return (!hwpf.State());
190 ParaShape::ParaShape()
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(new ColumnDef)
201 , shade(0)
202 , outline(0)
203 , outline_continue(0)
204 , pagebreak(0)
206 reserved[0] = 0;
207 reserved[1] = 0;
210 void ParaShape::Read(HWPFile & hwpf)
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;
230 hwpf.Read1b(condense);
231 hwpf.Read1b(arrange_type);
232 for (TabSet & tab : tabs)
234 hwpf.Read1b(tab.type);
235 hwpf.Read1b(tab.dot_continue);
236 if (!hwpf.Read2b(tmp16))
237 return;
238 tab.position = tmp16;
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);
253 hwpf.Read1b(outline_continue);
254 if (!hwpf.Read2b(tmp16))
255 return;
256 pspacing_prev = tmp16;
258 hwpf.ReadBlock(reserved, 2);
262 void CharShape::Read(HWPFile & hwpf)
264 unsigned short tmp16;
265 if (!hwpf.Read2b(tmp16))
266 return;
267 size = tmp16;
268 hwpf.ReadBlock(font, NLanguage);
269 hwpf.ReadBlock(ratio, NLanguage);
270 hwpf.ReadBlock(space, NLanguage);
271 hwpf.ReadBlock(color, 2);
272 hwpf.Read1b(shade);
273 hwpf.Read1b(attr);
274 hwpf.ReadBlock(reserved, 4);
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */