Typo: cirle->circle
[LibreOffice.git] / hwpfilter / source / hwpfile.h
blobb28c2a44074322ff1f6d8fa14e63ba4a7c902d94
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 .
21 // hwpfile.h
22 // (C) 1998 Mizi Research, All rights are reserved
25 #ifndef INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
26 #define INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
28 #include <list>
29 #include <stdio.h>
30 #include <string.h>
31 #include <fcntl.h>
33 #include "hwplib.h"
34 #include "hfont.h"
35 #include "hstyle.h"
36 #include "hpara.h"
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"
43 #define HWP_V20 20
44 #define HWP_V21 21
45 #define HWP_V30 30
47 int detect_hwp_version(const char *str);
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;
62 class HIODev;
63 class HWPInfo;
64 class HWPFont;
65 class HWPStyle;
66 class HWPPara;
67 class HStream;
69 struct ColumnInfo{
70 int start_page;
71 bool bIsSet;
72 ColumnDef *coldef;
73 ColumnInfo(int num){
74 start_page = num;
75 bIsSet = false;
76 coldef = 0;
80 /**
81 * The HWPFile class is the main class of hwp for reading file
82 * information from stream
84 * The example is as below:
85 * <pre>
86 * HWPFile f;
87 * f.ReadHwpFile( stream );
88 * </pre>
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(),
94 * @short HWP file management object
95 * @author Mizi Reserach
97 class DLLEXPORT HWPFile
99 public:
101 * Default constructor
103 HWPFile();
104 ~HWPFile();
106 public:
109 * Opens HStream to use it.
110 * @returns 0 if success, otherwise error code
111 * @see State()
113 int Open( HStream * );
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.
119 int State( void ) const { return error_code;}
121 * Sets the current state
123 int SetState(int errcode);
125 * Reads one byte from HIODev
127 bool Read1b(char &out);
128 bool Read1b(unsigned char &out);
130 * Reads two byte from HIODev
132 bool Read2b(unsigned short &out);
134 * Reads four byte from HIODev
136 bool Read4b(unsigned int &out);
137 bool Read4b(int &out);
139 * Reads nmemb byte array from HIODev
141 int Read1b( void *ptr, size_t nmemb );
143 * Reads nmemb short type array from HIODev
145 int Read2b( void *ptr, size_t nmemb );
147 * Reads nmemb long type array from HIODev
149 int Read4b( void *ptr, size_t nmemb );
151 * Reads some bytes from HIODev not regarding endian's way
152 * @param size Amount for reading
154 size_t ReadBlock( void *ptr, size_t size );
156 * Skips some bytes from HIODev
158 size_t SkipBlock( size_t size );
160 * Reads main paragraph list
162 bool ReadParaList(std::list<HWPPara*> &aplist, unsigned char flag = 0);
164 * Sets if the stream is compressed
166 bool SetCompressed( bool );
168 * Sets current HIODev
170 HIODev *SetIODevice( HIODev *hiodev );
173 * Reads all information of hwp file from stream
175 int ReadHwpFile( HStream *);
177 * Reads document information of hwp file from HIODev
179 bool InfoRead(void);
181 * Reads font list of hwp file from HIODev
183 bool FontRead(void);
185 * Reads style list of hwp file from HIODev
187 bool StyleRead(void);
189 * Reads paragraph list of hwp file from HIODev
191 bool ParaListRead();
192 /* 그림 등의 추가 정보를 읽는다. */
194 * Reads additional information like embedded image of hwp file from HIODev
196 void TagsRead();
198 enum Paper
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
211 void AddBox(FBox *);
212 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 *);
223 ColumnDef* GetColumnDef(int);
224 int GetPageMasterNum(int page);
226 int getCurrentPage(){ return m_nCurrentPage;}
227 HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
228 HWPFont& GetHWPFont(void) { return _hwpFont; }
229 HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
230 HWPPara *GetFirstPara(void) { return plist.front(); }
231 HWPPara *GetLastPara(void) { return plist.back(); }
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);
245 int getParaShapeCount(){ return pslist.size(); }
246 int getCharShapeCount(){ return cslist.size(); }
247 int getFBoxStyleCount(){ return fbslist.size(); }
248 int getDateFormatCount(){ return datecodes.size(); }
249 int getHeaderFooterCount(){ return headerfooters.size(); }
250 int getPageNumberCount(){ return pagenumbers.size(); }
251 int getTableCount(){ return tables.size(); }
252 int getColumnCount(){ return columnlist.size(); }
254 int getMaxSettedPage(){ return m_nMaxSettedPage; }
255 void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
257 private :
258 int compareCharShape(CharShape *shape);
259 int compareParaShape(ParaShape *shape);
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;
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;
296 // for global document handling
297 static HWPFile *cur_doc;
298 friend HWPFile *GetCurrentDoc(void);
299 friend HWPFile *SetCurrentDoc(HWPFile *);
302 HWPFile *GetCurrentDoc(void);
303 HWPFile *SetCurrentDoc(HWPFile *hwpfp);
304 #endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */