LibreOffice Module hwpfilter (master) 1
hwpread.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
24#include <sal/log.hxx>
25#include <tools/long.hxx>
26
27#include <assert.h>
28
29#include "hwpfile.h"
30#include "hbox.h"
31#include "hpara.h"
32#include "drawing.h"
33#include "htags.h"
34#include "hcode.h"
35
36static short fboxnum = 1;
37static int zindex = 1;
38static int lnnumber = 0;
39
41{
42 // already read
43 return true;
44}
45
46// skip block
48{
49 uint data_block_len;
50 hwpf.Read4b(data_block_len);
51
52 hchar dummy;
53 if (!hwpf.Read2b(dummy))
55
56 if (!(IS_SP_SKIP_BLOCK(hh) && (hh == dummy))){
58 }
59
60 return hwpf.SkipBlock(data_block_len);
61}
62
63// Field code(5)
65{
66 uint size;
67 hchar dummy;
68 uint len1; /* Length of hchar type string DATA #1 */
69 uint len2; /* Length of hchar type string DATA #2 */
70 uint len3; /* Length of hchar type string DATA #3 */
71 uint binlen; /* Length of any binary data format */
72
73 hwpf.Read4b(size);
74 if (!hwpf.Read2b(dummy))
75 return false;
76 hwpf.ReadBlock(&type, 2);
77 hwpf.ReadBlock(reserved1.data(), 4);
78 if (!hwpf.Read2b(location_info))
79 return false;
80 hwpf.ReadBlock(reserved2.data(), 22);
81 hwpf.Read4b(len1);
82 hwpf.Read4b(len2);
83 hwpf.Read4b(len3);
84 if (!hwpf.Read4b(binlen))
85 return false;
86
87 uint const len1_ = std::min<uint>(len1, 1024) / sizeof(hchar);
88 uint const len2_ = std::min<uint>(len2, 1024) / sizeof(hchar);
89 uint const len3_ = std::min<uint>(len3, 1024) / sizeof(hchar);
90
91 str1.reset( new hchar[len1_ ? len1_ : 1] );
92 str2.reset( new hchar[len2_ ? len2_ : 1] );
93 str3.reset( new hchar[len3_ ? len3_ : 1] );
94
95 if (hwpf.Read2b(str1.get(), len1_) != len1_)
96 return false;
97 hwpf.SkipBlock(len1 - (len1_ * sizeof(hchar)));
98 str1[len1_ ? (len1_ - 1) : 0] = 0;
99 if (hwpf.Read2b(str2.get(), len2_) != len2_)
100 return false;
101 hwpf.SkipBlock(len2 - (len2_ * sizeof(hchar)));
102 str2[len2_ ? (len2_ - 1) : 0] = 0;
103 if (hwpf.Read2b(str3.get(), len3_) != len3_)
104 return false;
105 hwpf.SkipBlock(len3 - (len3_ * sizeof(hchar)));
106 str3[len3_ ? (len3_ - 1) : 0] = 0;
107
108 hwpf.SkipBlock(binlen);
109
110 if( type[0] == 3 && type[1] == 2 ){ /* It must create a format as created date. */
111 DateCode *pDate = new DateCode;
112 for (uint i = 0 ; i < len3_; i++) {
113 if(str3[i] == 0 ) break;
114 if( i >= DATE_SIZE ) break;
115 pDate->format[i] = str3[i];
116 }
117 hwpf.AddDateFormat(pDate);
118 m_pDate.reset( pDate );
119 }
120
121 return true;
122}
123
124// book mark(6)
126{
127 uint len;
128
129 hwpf.Read4b(len);
130 if (!hwpf.Read2b(dummy))
131 return false;
132
133 if (len != 34)// 2 * (BMK_COMMENT_LEN + 1) + 2
134 {
135 return hwpf.SetState(HWP_InvalidFileFormat);
136 }
137 if (hh != dummy || dummy != CH_BOOKMARK) {
138 return hwpf.SetState(HWP_InvalidFileFormat);
139 }
140
141 hwpf.Read2b(id, BMK_COMMENT_LEN + 1);
142 hwpf.Read2b(&type, 1);
143 return true;
144}
145
146// date format(7)
148{
149 hwpf.Read2b(format, DATE_SIZE);
150 if (!hwpf.Read2b(dummy))
151 return false;
152 if (hh != dummy || CH_DATE_FORM != dummy) {
153 return hwpf.SetState(HWP_InvalidFileFormat);
154 }
155 return true;
156}
157
158// date code(8)
160{
161 hwpf.Read2b(format, DATE_SIZE);
162 hwpf.Read2b(date, 6);
163 if (!hwpf.Read2b(dummy))
164 return false;
165 if (hh != dummy || CH_DATE_CODE != dummy) {
166 return hwpf.SetState(HWP_InvalidFileFormat);
167 }
168 hwpf.AddDateFormat(this);
169 return true;
170}
171
172// tab(9)
173bool Tab::Read(HWPFile & hwpf)
174{
175 unsigned short tmp16;
176 if (!hwpf.Read2b(tmp16))
177 return false;
178 width = tmp16;
179 if (!hwpf.Read2b(leader))
180 return false;
181 if (!hwpf.Read2b(dummy))
182 return false;
183 if (hh != dummy || CH_TAB != dummy) {
184 return hwpf.SetState(HWP_InvalidFileFormat);
185 }
186 return true;
187}
188
189// tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
190static void UpdateBBox(FBox * fbox)
191{
192 fbox->boundsy = fbox->pgy;
193 fbox->boundey = fbox->pgy + fbox->ys - 1;
194}
195
196bool Cell::Read(HWPFile & hwpf)
197{
198 hwpf.Read2b(&p, 1);
199 hwpf.Read2b(&color, 1);
200 hwpf.Read2b(&x, 1);
201 hwpf.Read2b(&y, 1);
202 hwpf.Read2b(&w, 1);
203 hwpf.Read2b(&h, 1);
204 hwpf.Read2b(&txthigh, 1);
205 hwpf.Read2b(&cellhigh, 1);
206
207 hwpf.Read1b(flag);
208 hwpf.Read1b(changed);
209 hwpf.Read1b(used);
210 hwpf.Read1b(ver_align);
211 hwpf.ReadBlock(linetype, 4);
212 hwpf.Read1b(shade);
213 hwpf.Read1b(diagonal);
214 return hwpf.Read1b(protect);
215}
216
218{
219 int ii, ncell;
220
221 hwpf.Read2b(reserved, 2);
222 hwpf.Read2b(&dummy, 1);
223
224 if (hh != dummy || CH_TEXT_BOX != dummy) {
225 return hwpf.SetState(HWP_InvalidFileFormat);
226 }
227 hwpf.Read2b(&style.cap_len, 1);
228 hwpf.Read2b(&dummy1, 1);
229 unsigned short next;
230 hwpf.Read2b(&next, 1);
231 hwpf.Read2b(&dummy2, 1);
232
233 style.boxnum = fboxnum++;
234 zorder = zindex++;
236 hwpf.Read1b(style.txtflow);
237 hwpf.Read2b(&style.xpos, 1);
238 hwpf.Read2b(&style.ypos, 1);
239 hwpf.Read2b(&option, 1);
240 hwpf.Read2b(&ctrl_ch, 1);
241 hwpf.Read2b(style.margin, 12);
242 hwpf.Read2b(&box_xs, 1);
243 hwpf.Read2b(&box_ys, 1);
244 hwpf.Read2b(&cap_xs, 1);
245 hwpf.Read2b(&cap_ys, 1);
246 hwpf.Read2b(&style.cap_len, 1);
247 hwpf.Read2b(&xs, 1);
248 hwpf.Read2b(&ys, 1);
249 hwpf.Read2b(&cap_margin, 1);
250 hwpf.Read1b(xpos_type);
251 hwpf.Read1b(ypos_type);
252 hwpf.Read1b(smart_linesp);
253 hwpf.Read1b(reserved1);
254 hwpf.Read2b(&pgx, 1);
255 hwpf.Read2b(&pgy, 1);
256 hwpf.Read2b(&pgno, 1);
257 if( ( pgno +1 ) != hwpf.getCurrentPage() )
258 pgno = sal::static_int_cast<short>(hwpf.getCurrentPage() -1) ;
259
260 hwpf.Read2b(&showpg, 1);
261 hwpf.Read2b(&cap_pos, 1);
262 hwpf.Read2b(&num, 1);
263 hwpf.Read2b(&dummy3, 1);
264 hwpf.Read2b(&baseline, 1);
265 hwpf.Read2b(&type, 1);
266 hwpf.Read2b(&nCell, 1);
267 hwpf.Read2b(&protect, 1);
268 switch (type)
269 {
270 case 0: //table
271 style.boxtype = 'T';
272 break;
273 case 1: // text-box
274 style.boxtype = 'X';
275 break;
276 case 2: // equation
277 style.boxtype = 'E';
278 break;
279 case 3: // button
280 style.boxtype = 'B';
281 break;
282 default: // other
283 style.boxtype = 'O';
284 break;
285 }
286
287 UpdateBBox(this);
288
289 ncell = nCell;
290 if (ncell <= 0) {
291 return hwpf.SetState(HWP_InvalidFileFormat);
292 }
293
294 if (ncell > 4096 && utl::ConfigManager::IsFuzzing()) {
295 // cut off at an arbitrary size to speed up fuzzing
296 return hwpf.SetState(HWP_InvalidFileFormat);
297 }
298
299 cell.reset( ::comphelper::newArray_null<Cell>(ncell) );
300 if (!cell) {
301 return hwpf.SetState(HWP_InvalidFileFormat);
302 }
303 bool bSuccess = true;
304 for (ii = 0; ii < ncell && bSuccess; ii++)
305 {
306 bSuccess = cell[ii].Read(hwpf);
307 cell[ii].key = sal::static_int_cast<unsigned char>(ii);
308 }
309 if (!bSuccess)
310 return false;
311 if (ncell == 1)
312 style.cell = &cell[0];
313 plists.resize(ncell);
314 for (ii = 0; ii < ncell; ii++)
315 hwpf.ReadParaList(plists[ii]);
316 // caption
317 hwpf.ReadParaList(caption);
318
319 if( type == 0 ){ // if table?
320 std::unique_ptr<TCell*[]> pArr(new TCell*[ncell]);
321 std::fill(pArr.get(), pArr.get() + ncell, nullptr);
322 if (!pArr) {
323 return hwpf.SetState(HWP_InvalidFileFormat);
324 }
325 std::unique_ptr<Table> tbl(new Table);
326 for( ii = 0 ; ii < ncell; ii++)
327 {
328 tbl->columns.insert(cell[ii].x);
329 tbl->columns.insert(cell[ii].x + cell[ii].w);
330 tbl->rows.insert(cell[ii].y);
331 tbl->rows.insert(cell[ii].y + cell[ii].h);
332 }
333 for( ii = 0 ; ii < ncell; ii++)
334 {
335 TCell *tcell = new TCell;
336 tcell->nColumnIndex = tbl->columns.getIndex(cell[ii].x);
337 tcell->nColumnSpan = tbl->columns.getIndex(cell[ii].x + cell[ii].w) -
338 tcell->nColumnIndex;
339 tcell->nRowIndex = tbl->rows.getIndex(cell[ii].y);
340 tcell->nRowSpan = tbl->rows.getIndex(cell[ii].y + cell[ii].h) -
341 tcell->nRowIndex;
342 tcell->pCell = &cell[ii];
343 pArr[ii] = tcell;
344 }
345
346 // Sort by row and column
347 for( ii = 0 ; ii < ncell - 1; ii++ ){
348 for( int jj = ii ; jj < ncell ; jj++){
349 if( pArr[ii]->nRowIndex > pArr[jj]->nRowIndex ){
350 std::swap(pArr[ii], pArr[jj]);
351 }
352 }
353 for( int kk = ii ; kk > 0 ; kk--){
354 if( ( pArr[kk]->nRowIndex == pArr[kk-1]->nRowIndex ) &&
355 (pArr[kk]->nColumnIndex < pArr[kk-1]->nColumnIndex )){
356 std::swap(pArr[kk], pArr[kk-1]);
357 }
358 }
359 }
360 for( ii = 0 ; ii < ncell ; ii++ ){
361 tbl->cells.emplace_back(pArr[ii]);
362 }
363 tbl->box = this;
364 m_pTable = tbl.get();
365 hwpf.AddTable(std::move(tbl));
366 }
367 else
368 m_pTable = nullptr;
369
370 bSuccess = !hwpf.State();
371 if (bSuccess)
372 hwpf.AddFBoxStyle(&style);
373 return bSuccess;
374}
375
376namespace
377{
378 class ChangeMemGuard
379 {
380 private:
381 HIODev* m_pOldMem;
382 std::unique_ptr<HMemIODev> m_xNewMem;
383 public:
384 ChangeMemGuard(unsigned char* data, size_t nLen)
385 : m_pOldMem(hmem)
386 , m_xNewMem(std::make_unique<HMemIODev>(reinterpret_cast<char*>(data), nLen))
387 {
388 hmem = m_xNewMem.get();
389 }
390 ~ChangeMemGuard()
391 {
392 assert(hmem == m_xNewMem.get());
393 hmem = m_pOldMem;
394 }
395 };
396}
397
398// picture(11)
400{
401 hwpf.Read2b(reserved, 2);
402 hwpf.Read2b(&dummy, 1);
403
404 if (hh != dummy || CH_PICTURE != dummy) {
405 return hwpf.SetState(HWP_InvalidFileFormat);
406 }
407
409
410 //when fuzzing with a max len set, max decompress to 10 times that limit
411 static size_t nMaxAllowedDecompression = [](const char* pEnv) { size_t nRet = pEnv ? std::atoi(pEnv) : 0; return nRet * 10; }(std::getenv("FUZZ_MAX_INPUT_LEN"));
412
413 hwpf.Read2b(&dummy1, 1); /* Reserved 4 bytes */
414 hwpf.Read2b(&dummy2, 1);
415
416 style.boxnum = fboxnum++;
417 zorder = zindex++;
418 hwpf.Read1b(style.anchor_type); /* Reference position */
419 hwpf.Read1b(style.txtflow); /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
420 hwpf.Read2b(&style.xpos, 1); /* Horizontal position: 1=left, 2=right, 3=center, and others=any */
421 hwpf.Read2b(&style.ypos, 1); /* Vertical position: 1=top, 2=down, 3=middle, and others=any */
422 hwpf.Read2b(&option, 1); /* Other options: Borders, reverse picture, and so on. Save as bit. */
423 hwpf.Read2b(&ctrl_ch, 1); /* Always 11 */
424 hwpf.Read2b(style.margin, 12); /* Margin: [0-2] [] out / in / cell, [], [0-3] left / right / top / bottom margins */
425 hwpf.Read2b(&box_xs, 1); /* Box Size Width */
426 hwpf.Read2b(&box_ys, 1); /* Vertical */
427 hwpf.Read2b(&cap_xs, 1); /* Caption Size Width */
428 hwpf.Read2b(&cap_ys, 1); /* Vertical */
429 hwpf.Read2b(&style.cap_len, 1); /* Length */
430 hwpf.Read2b(&xs, 1); /* The total size (box size + caption + margin) Horizontal */
431 hwpf.Read2b(&ys, 1); /* Vertical */
432 hwpf.Read2b(&cap_margin, 1); /* Caption margins */
433 hwpf.Read1b(xpos_type);
434 hwpf.Read1b(ypos_type);
435 hwpf.Read1b(smart_linesp); /* Line Spacing protection: 0 unprotected 1 protected */
436 hwpf.Read1b(reserved1);
437 hwpf.Read2b(&pgx, 1); /* Real Calculated box width */
438 hwpf.Read2b(&pgy, 1); /* Height */
439 hwpf.Read2b(&pgno, 1); /* Page number: starts from 0 */
440 hwpf.Read2b(&showpg, 1); /* Show the Box */
441 hwpf.Read2b(&cap_pos, 1); /* Caption positions 0-7 Menu Order. */
442 hwpf.Read2b(&num, 1); /* Box number, serial number which starts from 0 */
443
444 hwpf.Read1b(pictype); /* Picture type */
445
446 unsigned short tmp16;
447 if (!hwpf.Read2b(tmp16)) /* the real horizontal starting point where shows the picture */
448 return false;
449 skip[0] = tmp16;
450 if (!hwpf.Read2b(tmp16)) /* Vertical */
451 return false;
452 skip[1] = tmp16;
453 if (!hwpf.Read2b(tmp16)) /* Zoom Ratio: 0:fixed, others are percentage for horizontal */
454 return false;
455 scale[0] = tmp16;
456 if (!hwpf.Read2b(tmp16)) /* Vertical */
457 return false;
458 scale[1] = tmp16;
459
460 hwpf.ReadBlock(picinfo.picun.path, 256); /* Picture File Name: when type is not a Drawing. */
461 picinfo.picun.path[255] = 0; // ensure null terminated
462 hwpf.ReadBlock(reserved3, 9); /* Brightness / Contrast / Picture Effect, etc. */
463
464 UpdateBBox(this);
465 if( pictype != PICTYPE_DRAW )
467 else
468 {
469 //picinfo.picun read above is unioned with
470 //picinfo.picdraw and so wrote to the hdo pointer
471 //value, which is definitely not useful to us
472 picinfo.picdraw.hdo = nullptr;
473 }
474
475 if (follow_block_size != 0)
476 {
477 follow.clear();
478
479 //read potentially compressed data in blocks as it's more
480 //likely large values are simply broken and we'll run out
481 //of data before we need to realloc
482 for (size_t i = 0; i < follow_block_size; i+= SAL_N_ELEMENTS(hwpf.scratch))
483 {
484 size_t nOldSize = follow.size();
485 size_t nBlock = std::min(SAL_N_ELEMENTS(hwpf.scratch), follow_block_size - nOldSize);
486 size_t nReadBlock = hwpf.ReadBlock(hwpf.scratch, nBlock);
487 if (nReadBlock)
488 {
489 follow.insert(follow.end(), hwpf.scratch, hwpf.scratch + nReadBlock);
490 }
491 if (nBlock != nReadBlock)
492 break;
493 if (nMaxAllowedDecompression && follow.size() > nMaxAllowedDecompression)
494 {
495 SAL_WARN("filter.hwp", "too much decompression, abandoning");
496 follow.clear();
497 return false;
498 }
499 }
500 follow_block_size = follow.size();
501
502 if (pictype == PICTYPE_DRAW)
503 {
504 auto xGuard(std::make_unique<ChangeMemGuard>(follow.data(), follow_block_size));
505 LoadDrawingObjectBlock(this, hwpf);
507 xGuard.reset();
508 }
509 else if (follow_block_size >= 4)
510 {
511 if ((follow[3] << 24 | follow[2] << 16 | follow[1] << 8 | follow[0]) == 0x269)
512 {
513 ishyper = true;
514 }
515 }
516 }
517
518 if( pictype != 3 )
519 style.boxtype = 'G';
520 else
521 style.boxtype = 'D';
522
523// caption
524 hwpf.ReadParaList(caption);
525
526 bool bSuccess = !hwpf.State();
527 if (bSuccess)
528 hwpf.AddFBoxStyle(&style);
529 return bSuccess;
530}
531
532// line(15)
534 : FBox(CH_LINE)
535 , dummy(0)
536 , sx(0)
537 , sy(0)
538 , ex(0)
539 , ey(0)
540 , width(0)
541 , shade(0)
542 , color(0)
543{
544}
545
546bool Line::Read(HWPFile & hwpf)
547{
548 hwpf.Read2b(reserved, 2);
549 hwpf.Read2b(&dummy, 1);
550
551 if (hh != dummy || CH_LINE != dummy) {
552 return hwpf.SetState(HWP_InvalidFileFormat);
553 }
554
555 style.boxnum = fboxnum++;
556 zorder = zindex++;
557 style.boxtype = 'L';
558 hwpf.ReadBlock(&reserved2, 8);
560 hwpf.Read1b(style.txtflow);
561 hwpf.Read2b(&style.xpos, 1);
562 hwpf.Read2b(&style.ypos, 1);
563 hwpf.Read2b(&option, 1);
564 hwpf.Read2b(&ctrl_ch, 1);
565 hwpf.Read2b(style.margin, 12);
566 hwpf.Read2b(&box_xs, 1);
567 hwpf.Read2b(&box_ys, 1);
568 hwpf.Read2b(&cap_xs, 1);
569 hwpf.Read2b(&cap_ys, 1);
570 hwpf.Read2b(&style.cap_len, 1);
571 hwpf.Read2b(&xs, 1);
572 hwpf.Read2b(&ys, 1);
574 hwpf.linenumber = 1;
575 hwpf.Read2b(&boundsy, 1);
576 hwpf.Read2b(&boundey, 1);
577 hwpf.Read1b(boundx);
578 hwpf.Read1b(draw);
579
580 hwpf.Read2b(&pgx, 1);
581 hwpf.Read2b(&pgy, 1);
582 hwpf.Read2b(&pgno, 1);
583 hwpf.Read2b(&showpg, 1);
584
585 hwpf.Read2b(&sx, 1);
586 hwpf.Read2b(&sy, 1);
587 hwpf.Read2b(&ex, 1);
588 hwpf.Read2b(&sy, 1);
589 hwpf.Read2b(&width, 1);
590 hwpf.Read2b(&shade, 1);
591 hwpf.Read2b(&color, 1);
592 style.xpos = width;
593
594 bool bSuccess = !hwpf.State();
595 if (bSuccess)
596 hwpf.AddFBoxStyle(&style);
597 return bSuccess;
598}
599
600// hidden(15)
602 : HBox(CH_HIDDEN)
603 , dummy(0)
604{
605}
606
608{
609 hwpf.Read2b(reserved, 2);
610 hwpf.Read2b(&dummy, 1);
611 if (hh != dummy || CH_HIDDEN != dummy) {
612 return hwpf.SetState(HWP_InvalidFileFormat);
613 }
614
615 hwpf.ReadBlock(info, 8);
616 hwpf.ReadParaList(plist);
617
618 return !hwpf.State();
619}
620
621// header/footer(16)
624 , dummy(0)
625 , type(0)
626 , where(0)
627 , linenumber(0)
628 , m_nPageNumber(0)
629{
630}
631
633{
634 hwpf.Read2b(reserved, 2);
635 hwpf.Read2b(&dummy, 1);
636 if (hh != dummy || CH_HEADER_FOOTER != dummy) {
637 return hwpf.SetState(HWP_InvalidFileFormat);
638 }
639
640 hwpf.ReadBlock(info, 8);
641 hwpf.Read1b(type);
642 hwpf.Read1b(where);
643 lnnumber = 0;
645 linenumber = sal::static_int_cast<unsigned char>(lnnumber);
647 hwpf.setMaxSettedPage();
648 hwpf.AddHeaderFooter(this);
649
650 return !hwpf.State();
651}
652
653
654// footnote(17)
657 , dummy(0)
658 , number(0)
659 , type(0)
660 , width(0)
661{
662}
663
665{
666 hwpf.Read2b(reserved, 2);
667 hwpf.Read2b(&dummy, 1);
668 if (hh != dummy || CH_FOOTNOTE != dummy) {
669 return hwpf.SetState(HWP_InvalidFileFormat);
670 }
671
672 hwpf.ReadBlock(info, 8);
673 hwpf.Read2b(&number, 1);
674 hwpf.Read2b(&type, 1);
675 unsigned short tmp16;
676 if (!hwpf.Read2b(tmp16))
677 return false;
678 width = tmp16;
680
681 return !hwpf.State();
682}
683
684// auto number(18)
687 , type(0)
688 , number(0)
689 , dummy(0)
690{
691}
692
694{
695 hwpf.Read2b(&type, 1);
696 hwpf.Read2b(&number, 1);
697 hwpf.Read2b(&dummy, 1);
698
699 if (hh != dummy){
700 return hwpf.SetState(HWP_InvalidFileFormat);
701 }
702 return !hwpf.State();
703}
704
705
706// new number(19)
709 , type(0)
710 , number(0)
711 , dummy(0)
712{
713}
714
715
717{
718 hwpf.Read2b(&type, 1);
719 hwpf.Read2b(&number, 1);
720 hwpf.Read2b(&dummy, 1);
721
722 if (hh != dummy){
723 return hwpf.SetState(HWP_InvalidFileFormat);
724 }
725 return !hwpf.State();
726}
727
728// show page number (20)
731 , where(0)
732 , m_nPageNumber(0)
733 , shape(0)
734 , dummy(0)
735{
736}
737
739{
740 hwpf.Read2b(&where, 1);
741 hwpf.Read2b(&shape, 1);
742 hwpf.Read2b(&dummy, 1);
743
744 if (hh != dummy){
745 return hwpf.SetState(HWP_InvalidFileFormat);
746 }
748 hwpf.setMaxSettedPage();
749 hwpf.AddPageNumber(this);
750 return !hwpf.State();
751}
752
753/* 홀수쪽시작/감추기 (21) */
756 , kind(0)
757 , what(0)
758 , dummy(0)
759{
760}
761
763{
764 hwpf.Read2b(&kind, 1);
765 hwpf.Read2b(&what, 1);
766 hwpf.Read2b(&dummy, 1);
767
768 if (hh != dummy){
769 return hwpf.SetState(HWP_InvalidFileFormat);
770 }
771 return !hwpf.State();
772}
773
774// mail merge(22)
777 , dummy(0)
778{
779}
780
782{
783 hwpf.ReadBlock(field_name, 20);
784 hwpf.Read2b(&dummy, 1);
785
786 if (hh != dummy){
787 return hwpf.SetState(HWP_InvalidFileFormat);
788 }
789 return !hwpf.State();
790}
791
792// char composition(23)
795 , dummy(0)
796{
797}
798
800{
801 hwpf.Read2b(compose, 3);
802 hwpf.Read2b(&dummy, 1);
803
804 if (hh != dummy){
805 return hwpf.SetState(HWP_InvalidFileFormat);
806 }
807 return !hwpf.State();
808}
809
810// hyphen(24)
812 : HBox(CH_HYPHEN)
813 , width(0)
814 , dummy(0)
815{
816}
817
819{
820 hwpf.Read2b(&width, 1);
821 hwpf.Read2b(&dummy, 1);
822
823 if (hh != dummy){
824 return hwpf.SetState(HWP_InvalidFileFormat);
825 }
826 return !hwpf.State();
827}
828
829
830// toc mark(25)
833 , kind(0)
834 , dummy(0)
835{
836}
837
838
840{
841 hwpf.Read2b(&kind, 1);
842 hwpf.Read2b(&dummy, 1);
843
844 if (hh != dummy){
845 return hwpf.SetState(HWP_InvalidFileFormat);
846 }
847 return !hwpf.State();
848}
849
850// index mark(26)
853 , pgno(0)
854 , dummy(0)
855{
856}
857
859{
860 hwpf.Read2b(&keyword1, 60);
861 hwpf.Read2b(&keyword2, 60);
862 hwpf.Read2b(&pgno, 1);
863 hwpf.Read2b(&dummy, 1);
864
865 if (hh != dummy){
866 return hwpf.SetState(HWP_InvalidFileFormat);
867 }
868 return !hwpf.State();
869}
870
871// outline(28)
874 , kind(0)
875 , shape(0)
876 , level(0)
877 , dummy(0)
878{
879}
880
882{
883 hwpf.Read2b(&kind, 1);
884 hwpf.Read1b(shape);
885 hwpf.Read1b(level);
886 hwpf.Read2b(number, 7);
887 hwpf.Read2b(user_shape, 7);
888 hwpf.Read2b(deco, 14);
889 hwpf.Read2b(&dummy, 1);
890
891 if (hh != dummy){
892 return hwpf.SetState(HWP_InvalidFileFormat);
893 }
894 return !hwpf.State();
895}
896
897
898/* Bundle of spaces (30)*/
901 , dummy(0)
902{
903}
904
905
907{
908 hwpf.Read2b(&dummy, 1);
909
910 if (hh != dummy){
911 return hwpf.SetState(HWP_InvalidFileFormat);
912 }
913 return !hwpf.State();
914}
915
916
917/* Fixed-width spaces (31) */
920 , dummy(0)
921{
922}
923
924
926{
927 hwpf.Read2b(&dummy, 1);
928
929 if (hh != dummy){
930 return hwpf.SetState(HWP_InvalidFileFormat);
931 }
932 return !hwpf.State();
933}
934
935/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unsigned int uint
hwpio.h (C) 1999 Mizi Research, All rights are reserved
Definition: hiodev.h:40
The HMemIODev class controls the Input/Output device.
Definition: hiodev.h:136
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
void AddPageNumber(ShowPageNum *)
Definition: hwpfile.cxx:588
void AddHeaderFooter(HeaderFooter *)
Definition: hwpfile.cxx:593
unsigned char linenumber
Definition: hwpfile.h:266
int getCurrentPage() const
Definition: hwpfile.h:220
void AddFBoxStyle(FBoxStyle *)
Definition: hwpfile.cxx:603
void AddTable(std::unique_ptr< Table >)
Definition: hwpfile.cxx:598
size_t SkipBlock(size_t size)
Skips some bytes from HIODev.
Definition: hwpfile.cxx:176
int State(void) const
Say current state.
Definition: hwpfile.h:119
int SetState(int errcode)
Sets the current state.
Definition: hwpfile.cxx:117
void AddDateFormat(DateCode *)
Definition: hwpfile.cxx:582
unsigned char scratch[SAL_MAX_UINT16]
Definition: hwpfile.h:270
bool Read1b(unsigned char &out)
Reads one byte from HIODev.
Definition: hwpfile.cxx:123
void setMaxSettedPage()
Definition: hwpfile.h:247
void ReadParaList(std::vector< std::unique_ptr< HWPPara > > &aplist, unsigned char flag=0)
Reads main paragraph list.
Definition: hwpfile.cxx:254
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
bool Read4b(unsigned int &out)
Reads four byte from HIODev.
Definition: hwpfile.cxx:152
hchar user_shape[MAX_OUTLINE_LEVEL]
shape of level
Definition: hbox.h:965
unsigned short kind
kind of numbering format
Definition: hbox.h:952
unsigned char level
level of number, Ex) The level of 1.3.2.4 is four
Definition: hbox.h:957
hchar dummy
Definition: hbox.h:970
unsigned short number[MAX_OUTLINE_LEVEL]
value of level
Definition: hbox.h:961
hchar deco[MAX_OUTLINE_LEVEL][2]
decoration character for the level type
Definition: hbox.h:969
Outline()
Definition: hwpread.cxx:872
unsigned char shape
Definition: hbox.h:953
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:881
static bool IsFuzzing()
static HIODev * hmem
Definition: drawing.h:87
static bool LoadDrawingObjectBlock(Picture *pic, HWPFile &hwpf)
Definition: drawing.h:410
float y
float x
pictype
Definition: hbox.h:522
@ PICTYPE_DRAW
Definition: hbox.h:524
#define BMK_COMMENT_LEN
Definition: hbox.h:107
const int DATE_SIZE
Definition: hbox.h:124
#define CH_DATE_CODE
Definition: hwplib.h:126
#define CH_MAIL_MERGE
Definition: hwplib.h:141
#define CH_HYPHEN
Definition: hwplib.h:143
char16_t hchar
size of hunit is 4 since hwp96 version
Definition: hwplib.h:36
#define CH_COMPOSE
Definition: hwplib.h:142
#define CH_KEEP_SPACE
Definition: hwplib.h:152
#define IS_SP_SKIP_BLOCK(hch)
Definition: hwplib.h:158
@ HWP_InvalidFileFormat
Definition: hwplib.h:179
#define CH_TEXT_BOX
Definition: hwplib.h:128
#define CH_AUTO_NUM
Definition: hwplib.h:136
#define CH_TOC_MARK
Definition: hwplib.h:145
#define CH_TAB
Definition: hwplib.h:127
#define CH_PICTURE
Definition: hwplib.h:129
#define CH_FOOTNOTE
Definition: hwplib.h:135
#define CH_NEW_NUM
Definition: hwplib.h:137
#define CH_DATE_FORM
Definition: hwplib.h:125
#define CH_SHOW_PAGE_NUM
Definition: hwplib.h:139
#define CH_OUTLINE
Definition: hwplib.h:149
#define CH_HEADER_FOOTER
Definition: hwplib.h:134
#define CH_FIXED_SPACE
Definition: hwplib.h:153
#define CH_PAGE_NUM_CTRL
Definition: hwplib.h:140
#define CH_BOOKMARK
Definition: hwplib.h:123
#define CH_HIDDEN
Definition: hwplib.h:133
#define CH_LINE
Definition: hwplib.h:132
#define CH_INDEX_MARK
Definition: hwplib.h:146
static short fboxnum
Definition: hwpread.cxx:36
static int zindex
Definition: hwpread.cxx:37
static void UpdateBBox(FBox *fbox)
Definition: hwpread.cxx:190
static int lnnumber
Definition: hwpread.cxx:38
#define SAL_WARN(area, stream)
#define SAL_N_ELEMENTS(arr)
size
int i
sal_Int32 h
sal_Int32 w
unsigned short type
Definition: hbox.h:758
unsigned short number
Definition: hbox.h:759
AutoNum()
Definition: hwpread.cxx:685
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:693
hchar dummy
Definition: hbox.h:760
hchar dummy
Definition: hbox.h:114
unsigned short type
Definition: hbox.h:116
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:125
unsigned char protect
Definition: hbox.h:229
short x
Definition: hbox.h:221
unsigned char flag
Definition: hbox.h:224
unsigned char linetype[4]
Definition: hbox.h:226
unsigned char changed
Definition: hbox.h:224
short txthigh
Definition: hbox.h:223
unsigned char used
Definition: hbox.h:224
short h
Definition: hbox.h:222
short w
Definition: hbox.h:222
short p
Definition: hbox.h:219
unsigned char ver_align
Definition: hbox.h:225
short cellhigh
Definition: hbox.h:223
short y
Definition: hbox.h:221
unsigned char shade
Definition: hbox.h:227
bool Read(HWPFile &hwpf)
Definition: hwpread.cxx:196
unsigned char diagonal
Definition: hbox.h:228
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:799
hchar compose[3]
Definition: hbox.h:847
hchar dummy
Definition: hbox.h:848
Compose()
Definition: hwpread.cxx:793
Class for current date and time with specified format.
Definition: hbox.h:142
hchar dummy
Definition: hbox.h:153
hchar format[DATE_SIZE]
Definition: hbox.h:148
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:159
short date[6]
year/month/week/day/hour/minute
Definition: hbox.h:152
hchar format[DATE_SIZE]
Definition: hbox.h:131
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:147
hchar dummy
Definition: hbox.h:132
short ypos
Vertical alignment.
Definition: hbox.h:254
unsigned char boxtype
Type of floating object : line, txtbox, image, table, equalizer and button.
Definition: hbox.h:268
short margin[3][4]
Every margin of border [0-2][] : out/in/cell margin [][0-3] : left/right/top/bottom.
Definition: hbox.h:260
void * cell
Definition: hbox.h:271
unsigned char txtflow
Kind of wrap.
Definition: hbox.h:246
short boxnum
Index of floating object.
Definition: hbox.h:264
short xpos
Horizontal alignment.
Definition: hbox.h:250
short cap_len
Definition: hbox.h:269
unsigned char anchor_type
Anchor type : paragraph , page, char.
Definition: hbox.h:242
This object is for floating object like table, image, line and so on.
Definition: hbox.h:292
short pgno
Definition: hbox.h:316
short boundsy
Definition: hbox.h:309
short cap_ys
Definition: hbox.h:299
short box_ys
Definition: hbox.h:298
short ys
Definition: hbox.h:300
short cap_margin
Definition: hbox.h:302
char ypos_type
Definition: hbox.h:303
short boundey
Definition: hbox.h:309
char xpos_type
Definition: hbox.h:303
short showpg
Definition: hbox.h:316
int zorder
Definition: hbox.h:293
FBoxStyle style
Definition: hbox.h:296
short pgx
Physical x,y position.
Definition: hbox.h:315
unsigned char smart_linesp
Definition: hbox.h:304
short cap_xs
Definition: hbox.h:299
unsigned char draw
Definition: hbox.h:310
hchar ctrl_ch
Definition: hbox.h:295
short xs
Definition: hbox.h:300
short pgy
Definition: hbox.h:315
short option
Definition: hbox.h:294
short box_xs
Definition: hbox.h:298
unsigned char boundx
Definition: hbox.h:310
unsigned short location_info
Definition: hbox.h:85
std::unique_ptr< hchar[]> str2
Definition: hbox.h:88
std::unique_ptr< hchar[]> str1
Definition: hbox.h:87
std::unique_ptr< hchar[]> str3
Definition: hbox.h:89
std::array< char, 22 > reserved2
Definition: hbox.h:86
std::array< char, 4 > reserved1
Definition: hbox.h:84
std::unique_ptr< DateCode > m_pDate
Definition: hbox.h:91
uchar type[2]
Definition: hbox.h:83
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:64
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:925
hchar dummy
Definition: hbox.h:999
std::vector< std::unique_ptr< HWPPara > > plist
Paragraph list of Footnote objects.
Definition: hbox.h:731
hchar dummy
Definition: hbox.h:713
hunit width
The width of the Footnote object.
Definition: hbox.h:727
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:664
unsigned short number
The number of current footnote/endnote.
Definition: hbox.h:719
unsigned short type
Set the type of Footnote either footnote or endnote.
Definition: hbox.h:723
hchar reserved[2]
Definition: hbox.h:712
Footnote()
Definition: hwpread.cxx:655
unsigned char info[8]
Definition: hbox.h:715
The HBox class is the base class for all date classes in hwp document.
Definition: hbox.h:44
hchar hh
Definition: hbox.h:46
virtual bool Read(HWPFile &hwpf)
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:40
unsigned char info[8]
Definition: hbox.h:685
hchar reserved[2]
Definition: hbox.h:682
unsigned char where
Definition: hbox.h:690
hchar dummy
Definition: hbox.h:683
unsigned char type
Header or footer.
Definition: hbox.h:689
unsigned int m_nPageNumber
Definition: hbox.h:693
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:632
unsigned char linenumber
Definition: hbox.h:691
std::vector< std::unique_ptr< HWPPara > > plist
Paragraph list of header or footer.
Definition: hbox.h:698
hchar reserved[2]
Definition: hbox.h:665
hchar dummy
Definition: hbox.h:666
unsigned char info[8]
Definition: hbox.h:668
Hidden()
Definition: hwpread.cxx:601
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:607
std::vector< std::unique_ptr< HWPPara > > plist
Definition: hbox.h:669
hchar width
Width of hyphen.
Definition: hbox.h:864
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:818
Hyphen()
Definition: hwpread.cxx:811
hchar dummy
Definition: hbox.h:865
hchar dummy
Definition: hbox.h:899
unsigned short pgno
Definition: hbox.h:898
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:858
hchar keyword1[60]
Definition: hbox.h:896
hchar keyword2[60]
Definition: hbox.h:897
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:906
hchar dummy
Definition: hbox.h:986
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:546
char reserved2[8]
Definition: hbox.h:649
short width
Definition: hbox.h:652
hchar reserved[2]
Definition: hbox.h:646
hchar dummy
Definition: hbox.h:647
short ex
Definition: hbox.h:651
short shade
Definition: hbox.h:652
short sx
Definition: hbox.h:651
Line()
Definition: hwpread.cxx:533
short sy
Definition: hbox.h:651
unsigned char field_name[20]
Definition: hbox.h:831
hchar dummy
Definition: hbox.h:832
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:781
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:716
unsigned short type
Definition: hbox.h:772
NewNum()
Definition: hwpread.cxx:707
hchar dummy
Definition: hbox.h:774
unsigned short number
Definition: hbox.h:773
hchar dummy
Definition: hbox.h:817
unsigned short kind
object type
Definition: hbox.h:812
unsigned short what
control command.
Definition: hbox.h:816
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:762
HWPDrawingObject * hdo
Definition: hbox.h:560
char path[256]
Definition: hbox.h:571
std::vector< unsigned char > follow
It's for the Drawing object.
Definition: hbox.h:630
hchar reserved[2]
Definition: hbox.h:594
bool ishyper
Definition: hbox.h:632
std::vector< std::unique_ptr< HWPPara > > caption
Definition: hbox.h:626
short num
Index of current Picture object.
Definition: hbox.h:611
char reserved3[9]
Definition: hbox.h:624
PicDef picinfo
Definition: hbox.h:623
uchar reserved1
Definition: hbox.h:603
short dummy2
Definition: hbox.h:602
short cap_pos
Position of caption.
Definition: hbox.h:607
hunit scale[2]
Ratio of magnification or reduction.
Definition: hbox.h:622
hunit skip[2]
Definition: hbox.h:618
hchar dummy
Definition: hbox.h:595
short dummy1
Definition: hbox.h:601
uint follow_block_size
follow_block_size is the size information of the Drawing object of hwp.
Definition: hbox.h:600
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:399
unsigned int m_nPageNumber
Definition: hbox.h:791
hchar dummy
Definition: hbox.h:796
unsigned short where
Location of page number to be inserted.
Definition: hbox.h:790
unsigned short shape
Shape of page number to be inserted.
Definition: hbox.h:795
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:738
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:47
Definition: hbox.h:502
int nColumnIndex
Definition: hbox.h:503
Cell * pCell
Definition: hbox.h:507
int nRowSpan
Definition: hbox.h:506
int nColumnSpan
Definition: hbox.h:505
int nRowIndex
Definition: hbox.h:504
unsigned short leader
Definition: hbox.h:168
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:173
hchar dummy
Definition: hbox.h:169
hunit width
Definition: hbox.h:167
Definition: hbox.h:511
hchar kind
Definition: hbox.h:880
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:839
hchar dummy
Definition: hbox.h:881
TocMark()
Definition: hwpread.cxx:831
short dummy1
Definition: hbox.h:331
short nCell
nCell is greater than one only for table, otherwise it is 1.
Definition: hbox.h:353
std::vector< std::unique_ptr< HWPPara > > caption
Caption.
Definition: hbox.h:371
short protect
If value of protect is 1, size of cell can't change.
Definition: hbox.h:357
plists_t plists
Definition: hbox.h:366
std::unique_ptr< Cell[]> cell
Definition: hbox.h:359
hchar dummy
Definition: hbox.h:329
short cap_pos
caption position
Definition: hbox.h:339
Table * m_pTable
Definition: hbox.h:360
short dummy2
Definition: hbox.h:334
short num
Definition: hbox.h:340
short baseline
Definition: hbox.h:343
unsigned char reserved1
Definition: hbox.h:335
short dummy3
Definition: hbox.h:342
short type
The value of type indicates as the below: zero is table, one is textbox, two is equalizer and three i...
Definition: hbox.h:349
virtual bool Read(HWPFile &hwpf) override
Read properties from HIODevice object like stream, file, memory.
Definition: hwpread.cxx:217
hchar reserved[2]
Definition: hbox.h:328
ResultType type
PicDefDraw picdraw
Definition: hbox.h:579
PicDefUnknown picun
Definition: hbox.h:580