LibreOffice Module hwpfilter (master) 1
hwpfile.h
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
21// hwpfile.h
22// (C) 1998 Mizi Research, All rights are reserved
23
24
25#ifndef INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
26#define INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
27
28#include <algorithm>
29#include <memory>
30#include <vector>
31#include <stdio.h>
32#include <string.h>
33#include <fcntl.h>
34#include <sal/types.h>
35#include "hwplib.h"
36#include "hfont.h"
37#include "hstyle.h"
38#include "hpara.h"
39
40#define HWPIDLen 30
41#define V20SIGNATURE "HWP Document File V2.00 \032\1\2\3\4\5"
42#define V21SIGNATURE "HWP Document File V2.10 \032\1\2\3\4\5"
43#define V30SIGNATURE "HWP Document File V3.00 \032\1\2\3\4\5"
44
45#define HWP_V20 20
46#define HWP_V21 21
47#define HWP_V30 30
48
49int detect_hwp_version(const char *str);
50
51struct FBox;
52struct EmPicture;
53struct HyperText;
54struct FBoxStyle;
55struct CellLine;
56struct Cell;
57struct OlePicture;
58struct Picture;
59struct HeaderFooter;
60struct ShowPageNum;
61struct DateCode;
62struct Table;
63
64class HIODev;
65class HWPInfo;
66class HWPFont;
67class HWPStyle;
68class HWPPara;
69class HStream;
70
71struct ColumnInfo{
72 int start_page;
73 bool bIsSet;
74 std::shared_ptr<ColumnDef> xColdef;
75 explicit ColumnInfo(int num){
76 start_page = num;
77 bIsSet = false;
78 }
79};
80
98{
99 public:
103 HWPFile();
104 ~HWPFile();
105
106 public:
107
113 int Open( std::unique_ptr<HStream> );
114
119 int State( void ) const { return error_code;}
123 int SetState(int errcode);
127 bool Read1b(unsigned char &out);
128 bool Read1b(char &out);
132 bool Read2b(unsigned short &out);
133 bool Read2b(char16_t &out);
137 bool Read4b(unsigned int &out);
138 bool Read4b(int &out);
142 size_t Read2b(void *ptr, size_t nmemb);
143
148 size_t ReadBlock( void *ptr, size_t size );
152 size_t SkipBlock( size_t size );
156 void ReadParaList(std::vector<std::unique_ptr<HWPPara>> &aplist, unsigned char flag = 0);
157 void ReadParaList(std::vector<HWPPara*> &aplist);
161 void SetCompressed( bool );
165 std::unique_ptr<HIODev> SetIODevice( std::unique_ptr<HIODev> hiodev );
166
170 int ReadHwpFile( std::unique_ptr<HStream> );
174 void InfoRead(void);
178 void FontRead(void);
182 void StyleRead(void);
186 void ParaListRead();
187/* 그림 등의 추가 정보를 읽는다. */
191 void TagsRead();
192
193 enum Paper
194 {
195 UserPaper = 0,
196 Col80Paper = 1,
197 Col132Paper = 2,
198 A4Paper = 3,
199 LetterPaper = 4,
200 B5Paper = 5,
201 B4Paper = 6,
202 LegalPaper = 7,
203 A3Paper = 8
204 };
205
206 void AddPage(){ m_nCurrentPage++;}
207 void AddColumnInfo();
208 void SetColumnDef(std::shared_ptr<ColumnDef> const &);
209 void AddParaShape(std::shared_ptr<ParaShape> const &);
210 void AddCharShape(std::shared_ptr<CharShape> const &);
211 void AddFBoxStyle(FBoxStyle *);
212 void AddDateFormat(DateCode *);
213 void AddHeaderFooter(HeaderFooter *);
214 void AddPageNumber(ShowPageNum *);
215 void AddTable(std::unique_ptr<Table>);
216
217 ColumnDef* GetColumnDef(int);
218 int GetPageMasterNum(int page);
219
220 int getCurrentPage() const{ return m_nCurrentPage;}
221 HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
222 HWPFont& GetHWPFont(void) { return _hwpFont; }
223 HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
224 HWPPara *GetFirstPara(void) { return !plist.empty() ? plist.front().get() : nullptr; }
225
226 EmPicture *GetEmPicture(Picture *pic);
227 EmPicture *GetEmPictureByName(char * name);
228 HyperText *GetHyperText();
229 ParaShape *getParaShape(int);
230 CharShape *getCharShape(int);
231 FBoxStyle *getFBoxStyle(int);
232 DateCode *getDateCode(int);
233 HeaderFooter *getHeaderFooter(int);
234 ShowPageNum *getPageNumber(int);
235 Table *getTable(int);
236
237 int getParaShapeCount() const{ return pslist.size(); }
238 int getCharShapeCount() const{ return cslist.size(); }
239 int getFBoxStyleCount() const{ return fbslist.size(); }
240 int getDateFormatCount() const{ return datecodes.size(); }
241 int getHeaderFooterCount() const{ return headerfooters.size(); }
242 int getPageNumberCount() const{ return pagenumbers.size(); }
243 int getTableCount() const{ return tables.size(); }
244 int getColumnCount() const{ return columnlist.size(); }
245
246 int getMaxSettedPage() const{ return m_nMaxSettedPage; }
247 void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
248
249 void push_hpara_type(unsigned char scflag) { element_import_stack.push_back(scflag); }
250 bool already_importing_type(unsigned char scflag) const
251 {
252 return std::find(element_import_stack.begin(), element_import_stack.end(), scflag) != element_import_stack.end();
253 }
254 void pop_hpara_type() { element_import_stack.pop_back(); }
255
256 void move_to_failed(std::unique_ptr<HWPPara> rPara);
257
258 private:
259 int compareCharShape(CharShape const *shape);
260 int compareParaShape(ParaShape const *shape);
261
262 public:
266 unsigned char linenumber;
269 std::unique_ptr<OlePicture> oledata;
270 unsigned char scratch[SAL_MAX_UINT16];
272
273 private:
274/* hwp 파일 이름 */
277 std::unique_ptr<HIODev> hiodev;
278// read hwp contents
282 std::vector<std::unique_ptr<ColumnInfo>> columnlist;
283 // paragraph list
284 std::vector<std::unique_ptr<HWPPara>> plist;
285 // keep paragraph's that failed to load until
286 // import is complete to avoid dangling references
287 // elsewhere
288 std::vector<std::unique_ptr<HWPPara>> pfailedlist;
289 // embedded picture list(tag data)
290 std::vector<std::unique_ptr<EmPicture>> emblist;
291 std::vector<std::unique_ptr<HyperText>> hyperlist;
293 std::vector<std::shared_ptr<ParaShape>> pslist;
294 std::vector<std::shared_ptr<CharShape>> cslist;
295 std::vector<FBoxStyle*> fbslist;
296 std::vector<DateCode*> datecodes;
297 std::vector<HeaderFooter*> headerfooters;
298 std::vector<ShowPageNum*> pagenumbers;
299 std::vector<std::unique_ptr<Table>> tables;
300 //track the stack of HParas types we're currently importing
301 std::vector<unsigned char> element_import_stack;
302
303// for global document handling
305 friend HWPFile *GetCurrentDoc(void);
306 friend HWPFile *SetCurrentDoc(HWPFile *);
307};
308
310{
311private:
313public:
315 : m_rFile(rFile)
316 {
317 ++m_rFile.readdepth;
318 }
319 bool toodeep() const
320 {
321 return m_rFile.readdepth == 512;
322 }
324 {
325 --m_rFile.readdepth;
326 }
327};
328
331#endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
332
333/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DepthGuard(HWPFile &rFile)
Definition: hwpfile.h:314
HWPFile & m_rFile
Definition: hwpfile.h:312
bool toodeep() const
Definition: hwpfile.h:319
~DepthGuard()
Definition: hwpfile.h:323
hwpio.h (C) 1999 Mizi Research, All rights are reserved
Definition: hiodev.h:40
The HWPFile class is the main class of hwp for reading file information from stream.
Definition: hwpfile.h:98
std::vector< HeaderFooter * > headerfooters
Definition: hwpfile.h:297
std::vector< std::unique_ptr< ColumnInfo > > columnlist
Definition: hwpfile.h:282
std::vector< std::unique_ptr< HWPPara > > pfailedlist
Definition: hwpfile.h:288
bool compressed
Definition: hwpfile.h:264
static HWPFile * cur_doc
Definition: hwpfile.h:304
unsigned char linenumber
Definition: hwpfile.h:266
std::vector< FBoxStyle * > fbslist
Definition: hwpfile.h:295
int m_nCurrentPage
Definition: hwpfile.h:275
int getParaShapeCount() const
Definition: hwpfile.h:237
int getCurrentPage() const
Definition: hwpfile.h:220
int error_code
Definition: hwpfile.h:268
std::unique_ptr< HIODev > hiodev
Definition: hwpfile.h:277
HWPFont _hwpFont
Definition: hwpfile.h:280
std::vector< unsigned char > element_import_stack
Definition: hwpfile.h:301
HWPFont & GetHWPFont(void)
Definition: hwpfile.h:222
int m_nMaxSettedPage
Definition: hwpfile.h:276
int version
Definition: hwpfile.h:263
HWPInfo _hwpInfo
Definition: hwpfile.h:279
HWPInfo & GetHWPInfo(void)
Definition: hwpfile.h:221
HWPStyle _hwpStyle
Definition: hwpfile.h:281
HWPPara * GetFirstPara(void)
Definition: hwpfile.h:224
int getHeaderFooterCount() const
Definition: hwpfile.h:241
int getTableCount() const
Definition: hwpfile.h:243
bool encrypted
Definition: hwpfile.h:265
int getPageNumberCount() const
Definition: hwpfile.h:242
int getCharShapeCount() const
Definition: hwpfile.h:238
int info_block_len
Definition: hwpfile.h:267
int State(void) const
Say current state.
Definition: hwpfile.h:119
std::vector< DateCode * > datecodes
Definition: hwpfile.h:296
int getMaxSettedPage() const
Definition: hwpfile.h:246
int getColumnCount() const
Definition: hwpfile.h:244
std::vector< std::unique_ptr< EmPicture > > emblist
Definition: hwpfile.h:290
std::vector< std::shared_ptr< CharShape > > cslist
Definition: hwpfile.h:294
std::unique_ptr< OlePicture > oledata
Definition: hwpfile.h:269
int readdepth
Definition: hwpfile.h:271
HWPStyle & GetHWPStyle(void)
Definition: hwpfile.h:223
int getDateFormatCount() const
Definition: hwpfile.h:240
void AddPage()
Definition: hwpfile.h:206
void pop_hpara_type()
Definition: hwpfile.h:254
void setMaxSettedPage()
Definition: hwpfile.h:247
std::vector< std::shared_ptr< ParaShape > > pslist
Definition: hwpfile.h:293
std::vector< std::unique_ptr< HyperText > > hyperlist
Definition: hwpfile.h:291
bool already_importing_type(unsigned char scflag) const
Definition: hwpfile.h:250
std::vector< std::unique_ptr< Table > > tables
Definition: hwpfile.h:299
void push_hpara_type(unsigned char scflag)
Definition: hwpfile.h:249
int getFBoxStyleCount() const
Definition: hwpfile.h:239
int currenthyper
Definition: hwpfile.h:292
std::vector< ShowPageNum * > pagenumbers
Definition: hwpfile.h:298
std::vector< std::unique_ptr< HWPPara > > plist
Definition: hwpfile.h:284
The HWPFont class has the font list for the document when it's saved.
Definition: hfont.h:37
HWPInfo class는 HWPFile에 대한 정보를 담고 있는 클래스이다.
Definition: hinfo.h:144
It represents the paragraph.
Definition: hpara.h:69
Using for global style object like "Standard".
Definition: hstyle.h:35
HWPFile * GetCurrentDoc(void)
Definition: hwpfile.cxx:667
HWPFile * SetCurrentDoc(HWPFile *hwpfp)
Definition: hwpfile.cxx:673
int detect_hwp_version(const char *str)
Definition: hwpfile.cxx:83
#define DLLEXPORT
Definition: hwplib.h:201
const char * name
Definition: hwpreader.cxx:365
Definition: hbox.h:196
A cell has four properties to specify the position for itself in hwp.
Definition: hbox.h:217
Style of character.
Definition: hinfo.h:213
Column properties.
Definition: hinfo.h:257
ColumnInfo(OUString i_sColumnName)
Class for current date and time with specified format.
Definition: hbox.h:142
Embedded image.
Definition: htags.h:34
Style for floating object.
Definition: hbox.h:238
This object is for floating object like table, image, line and so on.
Definition: hbox.h:292
Header or footer.
Definition: hbox.h:681
HyperText.
Definition: htags.h:49
Win32 OLE object.
Definition: htags.h:61
Style of paragraph.
Definition: hinfo.h:276
There are four kinds of image.
Definition: hbox.h:593
Input page index in footer or header.
Definition: hbox.h:786
Definition: hbox.h:511
#define SAL_MAX_UINT16