Line data Source code
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 <comphelper/newarray.hxx>
23 :
24 : #include <list>
25 :
26 : #include "hwpfile.h"
27 : #include "hbox.h"
28 : #include "hpara.h"
29 : #include "drawing.h"
30 : #include "htags.h"
31 : #include "hcode.h"
32 :
33 : static short fboxnum = 1;
34 : static int zindex = 1;
35 : static int lnnumber = 0;
36 :
37 70 : int HBox::Read(HWPFile & )
38 : {
39 : // already read
40 70 : return 1;
41 : }
42 :
43 :
44 : // skip block
45 :
46 0 : int SkipData::Read(HWPFile & hwpf)
47 : {
48 0 : hwpf.Read4b(&data_block_len, 1);
49 0 : hwpf.Read2b(&dummy, 1);
50 :
51 0 : if (!(IS_SP_SKIP_BLOCK(hh) && (hh == dummy))){
52 0 : return hwpf.SetState(HWP_InvalidFileFormat);
53 : }
54 :
55 0 : data_block = new char[data_block_len];
56 :
57 0 : return hwpf.Read1b(data_block, data_block_len);
58 : }
59 :
60 :
61 : // Field code(5)
62 0 : int FieldCode::Read(HWPFile & hwpf)
63 : {
64 : ulong size;
65 : hchar dummy;
66 : ulong len1; /* hcharŸÀÔÀÇ ¹®ÀÚ¿ Å×ÀÌÅÍ #1ÀÇ ±æÀÌ */
67 : ulong len2; /* hcharŸÀÔÀÇ ¹®ÀÚ¿ Å×ÀÌÅÍ #2ÀÇ ±æÀÌ */
68 : ulong len3; /* hcharŸÀÔÀÇ ¹®ÀÚ¿ Å×ÀÌÅÍ #3ÀÇ ±æÀÌ */
69 : ulong binlen; /* ÀÓÀÇ Çü½ÄÀÇ ¹ÙÀ̳ʸ® µ¥ÀÌŸ ±æÀÌ */
70 :
71 0 : hwpf.Read4b(&size, 1);
72 0 : hwpf.Read2b(&dummy, 1);
73 0 : hwpf.Read1b(&type, 2);
74 0 : hwpf.Read4b(reserved1, 1);
75 0 : hwpf.Read2b(&location_info, 1);
76 0 : hwpf.Read1b(reserved2, 22);
77 0 : hwpf.Read4b(&len1, 1);
78 0 : hwpf.Read4b(&len2, 1);
79 0 : hwpf.Read4b(&len3, 1);
80 0 : hwpf.Read4b(&binlen, 1);
81 :
82 0 : ulong const len1_ = ((len1 > 1024) ? 1024 : len1) / sizeof(hchar);
83 0 : ulong const len2_ = ((len2 > 1024) ? 1024 : len2) / sizeof(hchar);
84 0 : ulong const len3_ = ((len3 > 1024) ? 1024 : len3) / sizeof(hchar);
85 :
86 0 : str1 = new hchar[len1_ ? len1_ : 1];
87 0 : str2 = new hchar[len2_ ? len2_ : 1];
88 0 : str3 = new hchar[len3_ ? len3_ : 1];
89 0 : bin = new char[binlen];
90 :
91 0 : hwpf.Read2b(str1, len1_);
92 0 : hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
93 0 : str1[len1_ ? (len1_ - 1) : 0] = 0;
94 0 : hwpf.Read2b(str2, len2_);
95 0 : hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
96 0 : str2[len2_ ? (len2_ - 1) : 0] = 0;
97 0 : hwpf.Read2b(str3, len3_);
98 0 : hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
99 0 : str3[len3_ ? (len3_ - 1) : 0] = 0;
100 :
101 0 : hwpf.ReadBlock(bin, binlen);
102 :
103 0 : if( type[0] == 3 && type[1] == 2 ){ /* ¸¸µç³¯Â¥·Î¼ Æ÷¸ËÀ» »ý¼ºÇØ¾ß ÇÑ´Ù. */
104 0 : DateCode *pDate = new DateCode;
105 0 : for (int i = 0 ; i < static_cast<int>(len3_); i++) {
106 0 : if(str3[i] == 0 ) break;
107 0 : if( i >= DATE_SIZE ) break;
108 0 : pDate->format[i] = str3[i];
109 : }
110 0 : hwpf.AddDateFormat(pDate);
111 0 : m_pDate = pDate;
112 : }
113 :
114 0 : return true;
115 : }
116 :
117 :
118 : // book mark(6)
119 0 : int Bookmark::Read(HWPFile & hwpf)
120 : {
121 : long len;
122 :
123 0 : hwpf.Read4b(&len, 1);
124 0 : dummy = sal::static_int_cast<hchar>(hwpf.Read2b());
125 :
126 0 : if (!(len == 34))// 2 * (BMK_COMMENT_LEN + 1) + 2
127 : {
128 0 : return hwpf.SetState(HWP_InvalidFileFormat);
129 : }
130 0 : if (!(hh == dummy && dummy == CH_BOOKMARK)){
131 0 : return hwpf.SetState(HWP_InvalidFileFormat);
132 : }
133 :
134 0 : hwpf.Read2b(id, BMK_COMMENT_LEN + 1);
135 0 : hwpf.Read2b(&type, 1);
136 : //return hwpf.Read2b(&type, 1);
137 0 : return 1;
138 : }
139 :
140 :
141 : // date format(7)
142 :
143 0 : int DateFormat::Read(HWPFile & hwpf)
144 : {
145 0 : hwpf.Read2b(format, DATE_SIZE);
146 0 : dummy = sal::static_int_cast<hchar>(hwpf.Read2b());
147 0 : if (!(hh == dummy && CH_DATE_FORM == dummy)){
148 0 : return hwpf.SetState(HWP_InvalidFileFormat);
149 : }
150 0 : return true;
151 : }
152 :
153 :
154 : // date code(8)
155 :
156 0 : int DateCode::Read(HWPFile & hwpf)
157 : {
158 0 : hwpf.Read2b(format, DATE_SIZE);
159 0 : hwpf.Read2b(date, 6);
160 0 : dummy = sal::static_int_cast<hchar>(hwpf.Read2b());
161 0 : if (!(hh == dummy && CH_DATE_CODE == dummy)){
162 0 : return hwpf.SetState(HWP_InvalidFileFormat);
163 : }
164 0 : hwpf.AddDateFormat(this);
165 0 : return true;
166 : }
167 :
168 :
169 : // tab(9)
170 :
171 0 : int Tab::Read(HWPFile & hwpf)
172 : {
173 0 : width = hwpf.Read2b();
174 0 : leader = sal::static_int_cast<unsigned short>(hwpf.Read2b());
175 0 : dummy = sal::static_int_cast<hchar>(hwpf.Read2b());
176 0 : if (!(hh == dummy && CH_TAB == dummy)){
177 0 : return hwpf.SetState(HWP_InvalidFileFormat);
178 : }
179 0 : return true;
180 : }
181 :
182 :
183 : // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
184 :
185 0 : static void UpdateBBox(FBox * fbox)
186 : {
187 0 : fbox->boundsy = fbox->pgy;
188 0 : fbox->boundey = fbox->pgy + fbox->ys - 1;
189 0 : }
190 :
191 :
192 0 : void Cell::Read(HWPFile & hwpf)
193 : {
194 0 : hwpf.Read2b(&p, 1);
195 0 : hwpf.Read2b(&color, 1);
196 0 : hwpf.Read2b(&x, 1);
197 0 : hwpf.Read2b(&y, 1);
198 0 : hwpf.Read2b(&w, 1);
199 0 : hwpf.Read2b(&h, 1);
200 0 : hwpf.Read2b(&txthigh, 1);
201 0 : hwpf.Read2b(&cellhigh, 1);
202 :
203 0 : hwpf.Read1b(&flag, 1);
204 0 : hwpf.Read1b(&changed, 1);
205 0 : hwpf.Read1b(&used, 1);
206 0 : hwpf.Read1b(&ver_align, 1);
207 0 : hwpf.Read1b(linetype, 4);
208 0 : hwpf.Read1b(&shade, 1);
209 0 : hwpf.Read1b(&diagonal, 1);
210 0 : hwpf.Read1b(&protect, 1);
211 0 : }
212 :
213 :
214 0 : int TxtBox::Read(HWPFile & hwpf)
215 : {
216 : int ii, ncell;
217 :
218 0 : hwpf.Read2b(reserved, 2);
219 0 : hwpf.Read2b(&dummy, 1);
220 :
221 0 : if (!(hh == dummy && CH_TEXT_BOX == dummy)){
222 0 : return hwpf.SetState(HWP_InvalidFileFormat);
223 : }
224 0 : hwpf.AddBox(this);
225 0 : hwpf.Read2b(&style.cap_len, 1);
226 0 : hwpf.Read2b(&dummy1, 1);
227 0 : hwpf.Read2b(&next, 1);
228 0 : hwpf.Read2b(&dummy2, 1);
229 :
230 0 : style.boxnum = fboxnum++;
231 0 : zorder = zindex++;
232 0 : hwpf.Read1b(&style.anchor_type, 1);
233 0 : hwpf.Read1b(&style.txtflow, 1);
234 0 : hwpf.Read2b(&style.xpos, 1);
235 0 : hwpf.Read2b(&style.ypos, 1);
236 0 : hwpf.Read2b(&option, 1);
237 0 : hwpf.Read2b(&ctrl_ch, 1);
238 0 : hwpf.Read2b(style.margin, 12);
239 0 : hwpf.AddFBoxStyle(&style);
240 0 : hwpf.Read2b(&box_xs, 1);
241 0 : hwpf.Read2b(&box_ys, 1);
242 0 : hwpf.Read2b(&cap_xs, 1);
243 0 : hwpf.Read2b(&cap_ys, 1);
244 0 : hwpf.Read2b(&style.cap_len, 1);
245 0 : hwpf.Read2b(&xs, 1);
246 0 : hwpf.Read2b(&ys, 1);
247 0 : hwpf.Read2b(&cap_margin, 1);
248 0 : hwpf.Read1b(&xpos_type, 1);
249 0 : hwpf.Read1b(&ypos_type, 1);
250 0 : hwpf.Read1b(&smart_linesp, 1);
251 0 : hwpf.Read1b(&reserved1, 1);
252 0 : hwpf.Read2b(&pgx, 1);
253 0 : hwpf.Read2b(&pgy, 1);
254 0 : hwpf.Read2b(&pgno, 1);
255 0 : if( ( pgno +1 ) != hwpf.getCurrentPage() )
256 0 : pgno = sal::static_int_cast<short>(hwpf.getCurrentPage() -1) ;
257 :
258 0 : hwpf.Read2b(&showpg, 1);
259 0 : hwpf.Read2b(&cap_pos, 1);
260 0 : hwpf.Read2b(&num, 1);
261 0 : hwpf.Read2b(&dummy3, 1);
262 0 : hwpf.Read2b(&baseline, 1);
263 0 : hwpf.Read2b(&type, 1);
264 0 : hwpf.Read2b(&nCell, 1);
265 0 : hwpf.Read2b(&protect, 1);
266 0 : switch (type)
267 : {
268 : case 0: //table
269 0 : style.boxtype = 'T';
270 0 : break;
271 : case 1: // text-box
272 0 : style.boxtype = 'X';
273 0 : break;
274 : case 2: // equation
275 0 : style.boxtype = 'E';
276 0 : break;
277 : case 3: // button
278 0 : style.boxtype = 'B';
279 0 : break;
280 : default: // other
281 0 : style.boxtype = 'O';
282 0 : break;
283 : }
284 :
285 0 : UpdateBBox(this);
286 :
287 0 : ncell = NCell();
288 0 : if (!(ncell > 0)){
289 0 : return hwpf.SetState(HWP_InvalidFileFormat);
290 : }
291 :
292 0 : cell = ::comphelper::newArray_null<Cell>(ncell);
293 0 : if (!cell) {
294 0 : return hwpf.SetState(HWP_InvalidFileFormat);
295 : }
296 0 : for (ii = 0; ii < ncell; ii++)
297 : {
298 0 : cell[ii].Read(hwpf);
299 0 : cell[ii].key = sal::static_int_cast<unsigned char>(ii);
300 : }
301 0 : if (ncell == 1)
302 0 : style.cell = &cell[0];
303 0 : plists = ::comphelper::newArray_null< std::list< HWPPara* > >(ncell);
304 0 : if (!plists) {
305 0 : return hwpf.SetState(HWP_InvalidFileFormat);
306 : }
307 0 : for (ii = 0; ii < ncell; ii++)
308 0 : hwpf.ReadParaList(plists[ii]);
309 : // caption
310 0 : hwpf.ReadParaList(caption);
311 :
312 0 : if( type == 0 ){ // if table?
313 0 : Table *tbl = new Table;
314 0 : for( ii = 0 ; ii < ncell; ii++)
315 : {
316 0 : tbl->columns.insert(cell[ii].x);
317 0 : tbl->columns.insert(cell[ii].x + cell[ii].w);
318 0 : tbl->rows.insert(cell[ii].y);
319 0 : tbl->rows.insert(cell[ii].y + cell[ii].h);
320 : }
321 0 : TCell* *pArr = ::comphelper::newArray_null<TCell *>(ncell);
322 0 : if (!pArr) {
323 0 : return hwpf.SetState(HWP_InvalidFileFormat);
324 : }
325 0 : for( ii = 0 ; ii < ncell; ii++)
326 : {
327 0 : TCell *tcell = new TCell;
328 0 : tcell->nColumnIndex = tbl->columns.getIndex(cell[ii].x);
329 0 : tcell->nColumnSpan = tbl->columns.getIndex(cell[ii].x + cell[ii].w) -
330 0 : tcell->nColumnIndex;
331 0 : tcell->nRowIndex = tbl->rows.getIndex(cell[ii].y);
332 0 : tcell->nRowSpan = tbl->rows.getIndex(cell[ii].y + cell[ii].h) -
333 0 : tcell->nRowIndex;
334 0 : tcell->pCell = &cell[ii];
335 0 : pArr[ii] = tcell;
336 : }
337 : TCell *tmp;
338 : // Sort by row and column
339 0 : for( ii = 0 ; ii < ncell - 1; ii++ ){
340 0 : for( int jj = ii ; jj < ncell ; jj++){
341 0 : if( pArr[ii]->nRowIndex > pArr[jj]->nRowIndex ){
342 0 : tmp = pArr[ii];
343 0 : pArr[ii] = pArr[jj];
344 0 : pArr[jj] = tmp;
345 : }
346 : }
347 0 : for( int kk = ii ; kk > 0 ; kk--){
348 0 : if( ( pArr[kk]->nRowIndex == pArr[kk-1]->nRowIndex ) &&
349 0 : (pArr[kk]->nColumnIndex < pArr[kk-1]->nColumnIndex )){
350 0 : tmp = pArr[kk];
351 0 : pArr[kk] = pArr[kk-1];
352 0 : pArr[kk-1] = tmp;
353 : }
354 : }
355 : }
356 0 : for( ii = 0 ; ii < ncell ; ii++ ){
357 0 : tbl->cells.push_back(pArr[ii]);
358 : }
359 0 : tbl->box = this;
360 0 : hwpf.AddTable(tbl);
361 0 : m_pTable = tbl;
362 0 : delete[] pArr;
363 : }
364 : else
365 0 : m_pTable = 0L;
366 :
367 0 : return !hwpf.State();
368 : }
369 :
370 :
371 : // picture(11)
372 0 : int Picture::Read(HWPFile & hwpf)
373 : {
374 0 : hwpf.Read2b(reserved, 2);
375 0 : hwpf.Read2b(&dummy, 1);
376 :
377 0 : if (!(hh == dummy && CH_PICTURE == dummy)){
378 0 : return hwpf.SetState(HWP_InvalidFileFormat);
379 : }
380 0 : hwpf.AddBox(this);
381 :
382 0 : hwpf.Read4b(&follow_block_size, 1);
383 0 : hwpf.Read2b(&dummy1, 1); /* ¿¹¾à 4¹ÙÀÌÆ® */
384 0 : hwpf.Read2b(&dummy2, 1);
385 :
386 0 : style.boxnum = fboxnum++;
387 0 : zorder = zindex++;
388 0 : hwpf.Read1b(&style.anchor_type, 1); /* ±âÁØÀ§Ä¡ */
389 0 : hwpf.Read1b(&style.txtflow, 1); /* ±×¸²ÇÇÇÔ. 0-2(ÀÚ¸®Â÷Áö,Åõ¸í,¾î¿ï¸²) */
390 0 : hwpf.Read2b(&style.xpos, 1); /* °¡·ÎÀ§Ä¡ : 1 ¿ÞÂÊ, 2¿À¸¥ÂÊ, 3 °¡¿îµ¥, ÀÌ¿Ü = ÀÓÀÇ */
391 0 : hwpf.Read2b(&style.ypos, 1); /* ¼¼·ÎÀ§Ä¡ : 1 À§, 2 ¾Æ·¡, 3 °¡¿îµ¥, ÀÌ¿Ü ÀÓÀÇ */
392 0 : hwpf.Read2b(&option, 1); /* ±âŸ¿É¼Ç : Å׵θ®,±×¸²¹ÝÀü,µî. bit·Î ÀúÀå. */
393 0 : hwpf.Read2b(&ctrl_ch, 1); /* Ç×»ó 11 */
394 0 : hwpf.Read2b(style.margin, 12); /* ¿©¹é : [0-2][] out/in/¼¿,[][0-3] ¿Þ/¿À¸¥/À§/¾Æ·¡ ¿©¹é */
395 0 : hwpf.Read2b(&box_xs, 1); /* ¹Ú½ºÅ©±â °¡·Î */
396 0 : hwpf.Read2b(&box_ys, 1); /* ¼¼·Î */
397 0 : hwpf.Read2b(&cap_xs, 1); /* ĸ¼Ç Å©±â °¡·Î */
398 0 : hwpf.Read2b(&cap_ys, 1); /* ¼¼·Î */
399 0 : hwpf.Read2b(&style.cap_len, 1); /* ±æÀÌ */
400 0 : hwpf.Read2b(&xs, 1); /* Àüü Å©±â(¹Ú½º Å©±â + ĸ¼Ç + ¿©¹é) °¡·Î */
401 0 : hwpf.Read2b(&ys, 1); /* ¼¼·Î */
402 0 : hwpf.Read2b(&cap_margin, 1); /* ĸ¼Ç ¿©¹é */
403 0 : hwpf.Read1b(&xpos_type, 1);
404 0 : hwpf.Read1b(&ypos_type, 1);
405 0 : hwpf.Read1b(&smart_linesp, 1); /* ÁÙ°£°Ý º¸È£ : 0 ¹Ìº¸È£, 1 º¸È£ */
406 0 : hwpf.Read1b(&reserved1, 1);
407 0 : hwpf.Read2b(&pgx, 1); /* ½ÇÁ¦ °è»êµÈ ¹Ú½º °¡·Î */
408 0 : hwpf.Read2b(&pgy, 1); /* ¼¼·Î */
409 0 : hwpf.Read2b(&pgno, 1); /* ÆäÀÌÁö ¼ýÀÚ : 0ºÎÅÍ ½ÃÀÛ */
410 0 : hwpf.Read2b(&showpg, 1); /* ¹Ú½ºº¸¿©ÁÜ */
411 0 : hwpf.Read2b(&cap_pos, 1); /* ĸ¼ÇÀ§Ä¡ 0 - 7 ¸Þ´º¼ø¼. */
412 0 : hwpf.Read2b(&num, 1); /* ¹Ú½º¹øÈ£ 0ºÎÅÍ ½ÃÀÛÇؼ ¸Å±äÀϷùøÈ£ */
413 :
414 0 : hwpf.Read1b(&pictype, 1); /* ±×¸²Á¾·ù */
415 :
416 0 : skip[0] = (short) hwpf.Read2b(); /* ±×¸²¿¡¼ ½ÇÁ¦ Ç¥½Ã¸¦ ½ÃÀÛÇÒ À§Ä¡ °¡·Î */
417 0 : skip[1] = (short) hwpf.Read2b(); /* ¼¼·Î */
418 0 : scale[0] = (short) hwpf.Read2b(); /* È®´ëºñÀ² : 0 °íÁ¤, ÀÌ¿Ü ÆÛ¼¾Æ® ´ÜÀ§ °¡·Î */
419 0 : scale[1] = (short) hwpf.Read2b(); /* ¼¼·Î */
420 :
421 0 : hwpf.Read1b(picinfo.picun.path, 256); /* ±×¸²ÆÄÀÏ À̸§ : Á¾·ù°¡ DrawingÀÌ ¾Æ´Ò¶§. */
422 0 : hwpf.Read1b(reserved3, 9); /* ¹à±â/¸í¾Ï/±×¸²È¿°ú µî */
423 :
424 0 : UpdateBBox(this);
425 0 : if( pictype != PICTYPE_DRAW )
426 0 : style.cell = reserved3;
427 :
428 0 : if (follow_block_size != 0)
429 : {
430 0 : follow = new unsigned char[follow_block_size];
431 :
432 0 : hwpf.Read1b(follow, follow_block_size);
433 0 : if (pictype == PICTYPE_DRAW)
434 : {
435 0 : hmem = new HMemIODev((char *) follow, follow_block_size);
436 0 : LoadDrawingObjectBlock(this);
437 0 : style.cell = picinfo.picdraw.hdo;
438 0 : delete hmem;
439 :
440 0 : hmem = 0;
441 : }
442 : else
443 : {
444 0 : if ((follow[3] << 24 | follow[2] << 16 | follow[1] << 8 | follow[0]) == 0x269)
445 : {
446 0 : ishyper = true;
447 : }
448 : }
449 : }
450 :
451 0 : if( pictype != 3 )
452 0 : style.boxtype = 'G';
453 : else
454 0 : style.boxtype = 'D';
455 0 : hwpf.AddFBoxStyle(&style);
456 :
457 : // cation
458 0 : hwpf.ReadParaList(caption);
459 :
460 0 : return !hwpf.State();
461 : }
462 :
463 :
464 : // line(15)
465 :
466 0 : Line::Line():FBox(CH_LINE)
467 : {
468 0 : }
469 :
470 :
471 0 : int Line::Read(HWPFile & hwpf)
472 : {
473 0 : hwpf.Read2b(reserved, 2);
474 0 : hwpf.Read2b(&dummy, 1);
475 :
476 0 : if (!(hh == dummy && CH_LINE == dummy)){
477 0 : return hwpf.SetState(HWP_InvalidFileFormat);
478 : }
479 0 : hwpf.AddBox(this);
480 :
481 0 : style.boxnum = fboxnum++;
482 0 : zorder = zindex++;
483 0 : style.boxtype = 'L';
484 0 : hwpf.Read1b(&reserved2, 8);
485 0 : hwpf.Read1b(&style.anchor_type, 1);
486 0 : hwpf.Read1b(&style.txtflow, 1);
487 0 : hwpf.Read2b(&style.xpos, 1);
488 0 : hwpf.Read2b(&style.ypos, 1);
489 0 : hwpf.Read2b(&option, 1);
490 0 : hwpf.Read2b(&ctrl_ch, 1);
491 0 : hwpf.Read2b(style.margin, 12);
492 0 : hwpf.AddFBoxStyle(&style);
493 0 : hwpf.Read2b(&box_xs, 1);
494 0 : hwpf.Read2b(&box_ys, 1);
495 0 : hwpf.Read2b(&cap_xs, 1);
496 0 : hwpf.Read2b(&cap_ys, 1);
497 0 : hwpf.Read2b(&style.cap_len, 1);
498 0 : hwpf.Read2b(&xs, 1);
499 0 : hwpf.Read2b(&ys, 1);
500 0 : lnnumber = style.boxnum;
501 0 : hwpf.linenumber = 1;
502 0 : hwpf.Read2b(&boundsy, 1);
503 0 : hwpf.Read2b(&boundey, 1);
504 0 : hwpf.Read1b(&boundx, 1);
505 0 : hwpf.Read1b(&draw, 1);
506 :
507 0 : hwpf.Read2b(&pgx, 1);
508 0 : hwpf.Read2b(&pgy, 1);
509 0 : hwpf.Read2b(&pgno, 1);
510 0 : hwpf.Read2b(&showpg, 1);
511 :
512 0 : hwpf.Read2b(&sx, 1);
513 0 : hwpf.Read2b(&sy, 1);
514 0 : hwpf.Read2b(&ex, 1);
515 0 : hwpf.Read2b(&sy, 1);
516 0 : hwpf.Read2b(&width, 1);
517 0 : hwpf.Read2b(&shade, 1);
518 0 : hwpf.Read2b(&color, 1);
519 0 : style.xpos = width;
520 :
521 0 : return !hwpf.State();
522 : }
523 :
524 :
525 : // hidden(15)
526 0 : Hidden::Hidden():HBox(CH_HIDDEN)
527 : {
528 0 : }
529 :
530 :
531 0 : int Hidden::Read(HWPFile & hwpf)
532 : {
533 0 : hwpf.Read2b(reserved, 2);
534 0 : hwpf.Read2b(&dummy, 1);
535 0 : if (!(hh == dummy && CH_HIDDEN == dummy)){
536 0 : return hwpf.SetState(HWP_InvalidFileFormat);
537 : }
538 :
539 0 : hwpf.Read1b(info, 8);
540 0 : hwpf.ReadParaList(plist);
541 :
542 0 : return !hwpf.State();
543 : }
544 :
545 :
546 : // header/footer(16)
547 0 : HeaderFooter::HeaderFooter():HBox(CH_HEADER_FOOTER)
548 : {
549 0 : linenumber = 0;
550 0 : }
551 :
552 :
553 0 : int HeaderFooter::Read(HWPFile & hwpf)
554 : {
555 0 : hwpf.Read2b(reserved, 2);
556 0 : hwpf.Read2b(&dummy, 1);
557 0 : if (!(hh == dummy && CH_HEADER_FOOTER == dummy)){
558 0 : return hwpf.SetState(HWP_InvalidFileFormat);
559 : }
560 :
561 0 : hwpf.Read1b(info, 8);
562 0 : hwpf.Read1b(&type, 1);
563 0 : hwpf.Read1b(&where, 1);
564 0 : lnnumber = 0;
565 0 : hwpf.ReadParaList(plist, CH_HEADER_FOOTER);
566 0 : linenumber = sal::static_int_cast<unsigned char>(lnnumber);
567 0 : m_nPageNumber = hwpf.getCurrentPage();
568 0 : hwpf.setMaxSettedPage();
569 0 : hwpf.AddHeaderFooter(this);
570 :
571 0 : return !hwpf.State();
572 : }
573 :
574 :
575 : // footnote(17)
576 0 : Footnote::Footnote():HBox(CH_FOOTNOTE)
577 : {
578 0 : }
579 :
580 :
581 0 : int Footnote::Read(HWPFile & hwpf)
582 : {
583 0 : hwpf.Read2b(reserved, 2);
584 0 : hwpf.Read2b(&dummy, 1);
585 0 : if (!(hh == dummy && CH_FOOTNOTE == dummy)){
586 0 : return hwpf.SetState(HWP_InvalidFileFormat);
587 : }
588 :
589 0 : hwpf.Read1b(info, 8);
590 0 : hwpf.Read2b(&number, 1);
591 0 : hwpf.Read2b(&type, 1);
592 0 : width = (short) hwpf.Read2b();
593 0 : hwpf.ReadParaList(plist, CH_FOOTNOTE);
594 :
595 0 : return !hwpf.State();
596 : }
597 :
598 :
599 : // auto number(18)
600 0 : AutoNum::AutoNum():HBox(CH_AUTO_NUM)
601 : {
602 0 : }
603 :
604 :
605 0 : int AutoNum::Read(HWPFile & hwpf)
606 : {
607 0 : hwpf.Read2b(&type, 1);
608 0 : hwpf.Read2b(&number, 1);
609 0 : hwpf.Read2b(&dummy, 1);
610 :
611 0 : if (!(hh == dummy)){
612 0 : return hwpf.SetState(HWP_InvalidFileFormat);
613 : }
614 0 : return !hwpf.State();
615 : }
616 :
617 :
618 : // new number(19)
619 0 : NewNum::NewNum():HBox(CH_NEW_NUM)
620 : {
621 0 : }
622 :
623 :
624 0 : int NewNum::Read(HWPFile & hwpf)
625 : {
626 0 : hwpf.Read2b(&type, 1);
627 0 : hwpf.Read2b(&number, 1);
628 0 : hwpf.Read2b(&dummy, 1);
629 :
630 0 : if (!(hh == dummy)){
631 0 : return hwpf.SetState(HWP_InvalidFileFormat);
632 : }
633 0 : return !hwpf.State();
634 : }
635 :
636 :
637 : // show page number (20)
638 0 : ShowPageNum::ShowPageNum():HBox(CH_SHOW_PAGE_NUM)
639 : {
640 0 : }
641 :
642 :
643 0 : int ShowPageNum::Read(HWPFile & hwpf)
644 : {
645 0 : hwpf.Read2b(&where, 1);
646 0 : hwpf.Read2b(&shape, 1);
647 0 : hwpf.Read2b(&dummy, 1);
648 :
649 0 : if (!(hh == dummy)){
650 0 : return hwpf.SetState(HWP_InvalidFileFormat);
651 : }
652 0 : m_nPageNumber = hwpf.getCurrentPage();
653 0 : hwpf.setMaxSettedPage();
654 0 : hwpf.AddPageNumber(this);
655 0 : return !hwpf.State();
656 : }
657 :
658 :
659 : /* Ȧ¼öÂʽÃÀÛ/°¨Ãß±â (21) */
660 0 : PageNumCtrl::PageNumCtrl():HBox(CH_PAGE_NUM_CTRL)
661 : {
662 0 : }
663 :
664 :
665 0 : int PageNumCtrl::Read(HWPFile & hwpf)
666 : {
667 0 : hwpf.Read2b(&kind, 1);
668 0 : hwpf.Read2b(&what, 1);
669 0 : hwpf.Read2b(&dummy, 1);
670 :
671 0 : if (!(hh == dummy)){
672 0 : return hwpf.SetState(HWP_InvalidFileFormat);
673 : }
674 0 : return !hwpf.State();
675 : }
676 :
677 :
678 : // mail merge(22)
679 0 : MailMerge::MailMerge():HBox(CH_MAIL_MERGE)
680 : {
681 0 : }
682 :
683 :
684 0 : int MailMerge::Read(HWPFile & hwpf)
685 : {
686 0 : hwpf.Read1b(field_name, 20);
687 0 : hwpf.Read2b(&dummy, 1);
688 :
689 0 : if (!(hh == dummy)){
690 0 : return hwpf.SetState(HWP_InvalidFileFormat);
691 : }
692 0 : return !hwpf.State();
693 : }
694 :
695 :
696 : // char compositon(23)
697 0 : Compose::Compose():HBox(CH_COMPOSE)
698 : {
699 0 : }
700 :
701 :
702 0 : int Compose::Read(HWPFile & hwpf)
703 : {
704 0 : hwpf.Read2b(compose, 3);
705 0 : hwpf.Read2b(&dummy, 1);
706 :
707 0 : if (!(hh == dummy)){
708 0 : return hwpf.SetState(HWP_InvalidFileFormat);
709 : }
710 0 : return !hwpf.State();
711 : }
712 :
713 :
714 : // hyphen(24)
715 0 : Hyphen::Hyphen():HBox(CH_HYPHEN)
716 : {
717 0 : }
718 :
719 :
720 0 : int Hyphen::Read(HWPFile & hwpf)
721 : {
722 0 : hwpf.Read2b(&width, 1);
723 0 : hwpf.Read2b(&dummy, 1);
724 :
725 0 : if (!(hh == dummy)){
726 0 : return hwpf.SetState(HWP_InvalidFileFormat);
727 : }
728 0 : return !hwpf.State();
729 : }
730 :
731 :
732 : // toc mark(25)
733 0 : TocMark::TocMark():HBox(CH_TOC_MARK)
734 : {
735 0 : }
736 :
737 :
738 0 : int TocMark::Read(HWPFile & hwpf)
739 : {
740 0 : hwpf.Read2b(&kind, 1);
741 0 : hwpf.Read2b(&dummy, 1);
742 :
743 0 : if (!(hh == dummy)){
744 0 : return hwpf.SetState(HWP_InvalidFileFormat);
745 : }
746 0 : return !hwpf.State();
747 : }
748 :
749 :
750 : // index mark(26)
751 0 : IndexMark::IndexMark():HBox(CH_INDEX_MARK)
752 : {
753 0 : }
754 :
755 :
756 0 : int IndexMark::Read(HWPFile & hwpf)
757 : {
758 0 : hwpf.Read2b(&keyword1, 60);
759 0 : hwpf.Read2b(&keyword2, 60);
760 0 : hwpf.Read2b(&pgno, 1);
761 0 : hwpf.Read2b(&dummy, 1);
762 :
763 0 : if (!(hh == dummy)){
764 0 : return hwpf.SetState(HWP_InvalidFileFormat);
765 : }
766 0 : return !hwpf.State();
767 : }
768 :
769 :
770 : // outline(28)
771 0 : Outline::Outline():HBox(CH_OUTLINE)
772 : {
773 0 : }
774 :
775 :
776 0 : int Outline::Read(HWPFile & hwpf)
777 : {
778 0 : hwpf.Read2b(&kind, 1);
779 0 : hwpf.Read1b(&shape, 1);
780 0 : hwpf.Read1b(&level, 1);
781 0 : hwpf.Read2b(number, 7);
782 0 : hwpf.Read2b(user_shape, 7);
783 0 : hwpf.Read2b(deco, 14);
784 0 : hwpf.Read2b(&dummy, 1);
785 :
786 0 : if (!(hh == dummy)){
787 0 : return hwpf.SetState(HWP_InvalidFileFormat);
788 : }
789 0 : return !hwpf.State();
790 : }
791 :
792 :
793 : /* ¹À½ ºóÄ(30) */
794 0 : KeepSpace::KeepSpace():HBox(CH_KEEP_SPACE)
795 : {
796 0 : }
797 :
798 :
799 0 : int KeepSpace::Read(HWPFile & hwpf)
800 : {
801 0 : hwpf.Read2b(&dummy, 1);
802 :
803 0 : if (!(hh == dummy)){
804 0 : return hwpf.SetState(HWP_InvalidFileFormat);
805 : }
806 0 : return !hwpf.State();
807 : }
808 :
809 :
810 : /* °íÁ¤Æø ºóÄ(31) */
811 0 : FixedSpace::FixedSpace():HBox(CH_FIXED_SPACE)
812 : {
813 0 : }
814 :
815 :
816 0 : int FixedSpace::Read(HWPFile & hwpf)
817 : {
818 0 : hwpf.Read2b(&dummy, 1);
819 :
820 0 : if (!(hh == dummy)){
821 0 : return hwpf.SetState(HWP_InvalidFileFormat);
822 : }
823 0 : return !hwpf.State();
824 : }
825 :
826 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|