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 :
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 <list>
29 : #include <stdio.h>
30 : #include <string.h>
31 : #include <fcntl.h>
32 :
33 : #include "hwplib.h"
34 : #include "hfont.h"
35 : #include "hstyle.h"
36 : #include "hpara.h"
37 :
38 : #define HWPIDLen 30
39 : #define V20SIGNATURE "HWP Document File V2.00 \032\1\2\3\4\5"
40 : #define V21SIGNATURE "HWP Document File V2.10 \032\1\2\3\4\5"
41 : #define V30SIGNATURE "HWP Document File V3.00 \032\1\2\3\4\5"
42 :
43 : #define HWP_V20 20
44 : #define HWP_V21 21
45 : #define HWP_V30 30
46 :
47 : int detect_hwp_version(const char *str);
48 :
49 : struct FBox;
50 : struct EmPicture;
51 : struct HyperText;
52 : struct FBoxStyle;
53 : struct CellLine;
54 : struct Cell;
55 : struct OlePicture;
56 : struct Picture;
57 : struct HeaderFooter;
58 : struct ShowPageNum;
59 : struct DateCode;
60 : struct Table;
61 :
62 : class HIODev;
63 : class HWPInfo;
64 : class HWPFont;
65 : class HWPStyle;
66 : class HWPPara;
67 : class HStream;
68 :
69 : struct ColumnInfo{
70 : int start_page;
71 : bool bIsSet;
72 : ColumnDef *coldef;
73 1 : ColumnInfo(int num){
74 1 : start_page = num;
75 1 : bIsSet = false;
76 1 : coldef = 0;
77 1 : }
78 : };
79 :
80 : /**
81 : * The HWPFile class is the main class of hwp for reading file
82 : * information from stream
83 : *
84 : * The example is as below:
85 : * <pre>
86 : * HWPFile f;
87 : * f.ReadHwpFile( stream );
88 : * </pre>
89 : *
90 : * There are two way to read hwp information from stream, one is to read all at a time
91 : * to use @ref ReadhwpFile() method like above example, other is to read partial information
92 : * to use @ref Open(), @ref InfoRead(), @ref FontRead(), @ref StyleRead(), @ref ParaListRead(), @ref TagsRead(),
93 : *
94 : * @short HWP file management object
95 : * @author Mizi Reserach
96 : */
97 : class DLLEXPORT HWPFile
98 : {
99 : public:
100 : /**
101 : * Default constructor
102 : */
103 : HWPFile();
104 : ~HWPFile();
105 :
106 : public:
107 :
108 : /**
109 : * Opens HStream to use it.
110 : * @returns 0 if success, otherwise error code
111 : * @see State()
112 : */
113 : int Open( HStream * );
114 :
115 : /**
116 : * Say current state
117 : * @returns 0 if normal, otherwise error code. If it's bigger than USER_ERROR_BIT, it is internally using error, otherwise it's system error which is able to get the message @ref strerror() method.
118 : */
119 88 : int State( void ) const { return error_code;}
120 : /**
121 : * Sets the current state
122 : */
123 : int SetState(int errcode);
124 : /**
125 : * Reads one byte from HIODev
126 : */
127 : bool Read1b(char &out);
128 : bool Read1b(unsigned char &out);
129 : /**
130 : * Reads two byte from HIODev
131 : */
132 : bool Read2b(unsigned short &out);
133 : /**
134 : * Reads four byte from HIODev
135 : */
136 : bool Read4b(unsigned int &out);
137 : bool Read4b(int &out);
138 : /**
139 : * Reads nmemb byte array from HIODev
140 : */
141 : int Read1b( void *ptr, size_t nmemb );
142 : /**
143 : * Reads nmemb short type array from HIODev
144 : */
145 : int Read2b( void *ptr, size_t nmemb );
146 : /**
147 : * Reads nmemb long type array from HIODev
148 : */
149 : int Read4b( void *ptr, size_t nmemb );
150 : /**
151 : * Reads some bytes from HIODev not regarding endian's way
152 : * @param size Amount for reading
153 : */
154 : size_t ReadBlock( void *ptr, size_t size );
155 : /**
156 : * Skips some bytes from HIODev
157 : */
158 : size_t SkipBlock( size_t size );
159 : /**
160 : * Reads main paragraph list
161 : */
162 : bool ReadParaList(std::list<HWPPara*> &aplist, unsigned char flag = 0);
163 : /**
164 : * Sets if the stream is compressed
165 : */
166 : bool SetCompressed( bool );
167 : /**
168 : * Sets current HIODev
169 : */
170 : HIODev *SetIODevice( HIODev *hiodev );
171 :
172 : /**
173 : * Reads all information of hwp file from stream
174 : */
175 : int ReadHwpFile( HStream *);
176 : /**
177 : * Reads document information of hwp file from HIODev
178 : */
179 : bool InfoRead(void);
180 : /**
181 : * Reads font list of hwp file from HIODev
182 : */
183 : bool FontRead(void);
184 : /**
185 : * Reads style list of hwp file from HIODev
186 : */
187 : bool StyleRead(void);
188 : /**
189 : * Reads paragraph list of hwp file from HIODev
190 : */
191 : bool ParaListRead();
192 : /* 그림 등의 추가 정보를 읽는다. */
193 : /**
194 : * Reads additional information like embedded image of hwp file from HIODev
195 : */
196 : void TagsRead();
197 :
198 : enum Paper
199 : {
200 : UserPaper = 0,
201 : Col80Paper = 1,
202 : Col132Paper = 2,
203 : A4Paper = 3,
204 : LetterPaper = 4,
205 : B5Paper = 5,
206 : B4Paper = 6,
207 : LegalPaper = 7,
208 : A3Paper = 8
209 : };
210 :
211 : void AddBox(FBox *);
212 0 : void AddPage(){ m_nCurrentPage++;}
213 : void AddColumnInfo();
214 : void SetColumnDef(ColumnDef *coldef);
215 : void AddParaShape(ParaShape *);
216 : void AddCharShape(CharShape *);
217 : void AddFBoxStyle(FBoxStyle *);
218 : void AddDateFormat(DateCode *);
219 : void AddHeaderFooter(HeaderFooter *);
220 : void AddPageNumber(ShowPageNum *);
221 : void AddTable(Table *);
222 :
223 : ColumnDef* GetColumnDef(int);
224 : int GetPageMasterNum(int page);
225 :
226 0 : int getCurrentPage(){ return m_nCurrentPage;}
227 3 : HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
228 14 : HWPFont& GetHWPFont(void) { return _hwpFont; }
229 1 : HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
230 1 : HWPPara *GetFirstPara(void) { return plist.front(); }
231 : HWPPara *GetLastPara(void) { return plist.back(); }
232 :
233 : EmPicture *GetEmPicture(Picture *pic);
234 : EmPicture *GetEmPictureByName(char * name);
235 : HyperText *GetHyperText();
236 : FBox *GetBoxHead (void) { return blist.size()?blist.front():0; }
237 : ParaShape *getParaShape(int);
238 : CharShape *getCharShape(int);
239 : FBoxStyle *getFBoxStyle(int);
240 : DateCode *getDateCode(int);
241 : HeaderFooter *getHeaderFooter(int);
242 : ShowPageNum *getPageNumber(int);
243 : Table *getTable(int);
244 :
245 2 : int getParaShapeCount(){ return pslist.size(); }
246 2 : int getCharShapeCount(){ return cslist.size(); }
247 2 : int getFBoxStyleCount(){ return fbslist.size(); }
248 1 : int getDateFormatCount(){ return datecodes.size(); }
249 1 : int getHeaderFooterCount(){ return headerfooters.size(); }
250 2 : int getPageNumberCount(){ return pagenumbers.size(); }
251 1 : int getTableCount(){ return tables.size(); }
252 1 : int getColumnCount(){ return columnlist.size(); }
253 :
254 1 : int getMaxSettedPage(){ return m_nMaxSettedPage; }
255 1 : void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
256 :
257 : private :
258 : int compareCharShape(CharShape *shape);
259 : int compareParaShape(ParaShape *shape);
260 :
261 : public:
262 : int version;
263 : bool compressed;
264 : bool encrypted;
265 : unsigned char linenumber;
266 : int info_block_len;
267 : int error_code;
268 : OlePicture *oledata;
269 :
270 : private:
271 : /* hwp 파일 이름 */
272 : int m_nCurrentPage;
273 : int m_nMaxSettedPage;
274 : HIODev *hiodev;
275 : // read hwp contents
276 : HWPInfo _hwpInfo;
277 : HWPFont _hwpFont;
278 : HWPStyle _hwpStyle;
279 : std::list<ColumnInfo*> columnlist;
280 : // paragraph linked list
281 : std::list<HWPPara*> plist;
282 : // floating box linked list
283 : std::list<FBox*> blist;
284 : // embedded picture list(tag datas)
285 : std::list<EmPicture*> emblist;
286 : std::list<HyperText*> hyperlist;
287 : int currenthyper;
288 : std::list<ParaShape*> pslist; /* 스타오피스의 구조상 필요 */
289 : std::list<CharShape*> cslist;
290 : std::list<FBoxStyle*> fbslist;
291 : std::list<DateCode*> datecodes;
292 : std::list<HeaderFooter*> headerfooters;
293 : std::list<ShowPageNum*> pagenumbers;
294 : std::list<Table*> tables;
295 :
296 : // for global document handling
297 : static HWPFile *cur_doc;
298 : friend HWPFile *GetCurrentDoc(void);
299 : friend HWPFile *SetCurrentDoc(HWPFile *);
300 : };
301 :
302 : HWPFile *GetCurrentDoc(void);
303 : HWPFile *SetCurrentDoc(HWPFile *hwpfp);
304 : #endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|