nss: upgrade to release 3.73
[LibreOffice.git] / hwpfilter / source / hwpfile.h
blob9cc3b72a7c654f318ded37f0f8d684a9c9e005b0
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 <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"
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"
45 #define HWP_V20 20
46 #define HWP_V21 21
47 #define HWP_V30 30
49 int detect_hwp_version(const char *str);
51 struct FBox;
52 struct EmPicture;
53 struct HyperText;
54 struct FBoxStyle;
55 struct CellLine;
56 struct Cell;
57 struct OlePicture;
58 struct Picture;
59 struct HeaderFooter;
60 struct ShowPageNum;
61 struct DateCode;
62 struct Table;
64 class HIODev;
65 class HWPInfo;
66 class HWPFont;
67 class HWPStyle;
68 class HWPPara;
69 class HStream;
71 struct 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;
81 /**
82 * The HWPFile class is the main class of hwp for reading file
83 * information from stream
85 * The example is as below:
86 * <pre>
87 * HWPFile f;
88 * f.ReadHwpFile( stream );
89 * </pre>
91 * There are two way to read hwp information from stream, one is to read all at a time
92 * to use @ref ReadhwpFile() method like above example, other is to read partial information
93 * to use @ref Open(), @ref InfoRead(), @ref FontRead(), @ref StyleRead(), @ref ParaListRead(), @ref TagsRead(),
95 * @short HWP file management object
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( std::unique_ptr<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(unsigned char &out);
128 bool Read1b(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 short type array from HIODev
141 size_t Read2b(void *ptr, size_t nmemb);
143 * Reads nmemb long type array from HIODev
145 void Read4b( void *ptr, size_t nmemb );
147 * Reads some bytes from HIODev not regarding endian's way
148 * @param size Amount for reading
150 size_t ReadBlock( void *ptr, size_t size );
152 * Skips some bytes from HIODev
154 size_t SkipBlock( size_t size );
156 * Reads main paragraph list
158 void ReadParaList(std::vector<std::unique_ptr<HWPPara>> &aplist, unsigned char flag = 0);
159 void ReadParaList(std::vector<HWPPara*> &aplist);
161 * Sets if the stream is compressed
163 void SetCompressed( bool );
165 * Sets current HIODev
167 std::unique_ptr<HIODev> SetIODevice( std::unique_ptr<HIODev> hiodev );
170 * Reads all information of hwp file from stream
172 int ReadHwpFile( std::unique_ptr<HStream> );
174 * Reads document information of hwp file from HIODev
176 void InfoRead(void);
178 * Reads font list of hwp file from HIODev
180 void FontRead(void);
182 * Reads style list of hwp file from HIODev
184 void StyleRead(void);
186 * Reads paragraph list of hwp file from HIODev
188 void ParaListRead();
189 /* 그림 등의 추가 정보를 읽는다. */
191 * Reads additional information like embedded image of hwp file from HIODev
193 void TagsRead();
195 enum Paper
197 UserPaper = 0,
198 Col80Paper = 1,
199 Col132Paper = 2,
200 A4Paper = 3,
201 LetterPaper = 4,
202 B5Paper = 5,
203 B4Paper = 6,
204 LegalPaper = 7,
205 A3Paper = 8
208 void AddBox(FBox *);
209 void AddPage(){ m_nCurrentPage++;}
210 void AddColumnInfo();
211 void SetColumnDef(std::shared_ptr<ColumnDef> const &);
212 void AddParaShape(std::shared_ptr<ParaShape> const &);
213 void AddCharShape(std::shared_ptr<CharShape> const &);
214 void AddFBoxStyle(FBoxStyle *);
215 void AddDateFormat(DateCode *);
216 void AddHeaderFooter(HeaderFooter *);
217 void AddPageNumber(ShowPageNum *);
218 void AddTable(std::unique_ptr<Table>);
220 ColumnDef* GetColumnDef(int);
221 int GetPageMasterNum(int page);
223 int getCurrentPage() const{ return m_nCurrentPage;}
224 HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
225 HWPFont& GetHWPFont(void) { return _hwpFont; }
226 HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
227 HWPPara *GetFirstPara(void) { return !plist.empty() ? plist.front().get() : nullptr; }
229 EmPicture *GetEmPicture(Picture *pic);
230 EmPicture *GetEmPictureByName(char * name);
231 HyperText *GetHyperText();
232 ParaShape *getParaShape(int);
233 CharShape *getCharShape(int);
234 FBoxStyle *getFBoxStyle(int);
235 DateCode *getDateCode(int);
236 HeaderFooter *getHeaderFooter(int);
237 ShowPageNum *getPageNumber(int);
238 Table *getTable(int);
240 int getParaShapeCount() const{ return pslist.size(); }
241 int getCharShapeCount() const{ return cslist.size(); }
242 int getFBoxStyleCount() const{ return fbslist.size(); }
243 int getDateFormatCount() const{ return datecodes.size(); }
244 int getHeaderFooterCount() const{ return headerfooters.size(); }
245 int getPageNumberCount() const{ return pagenumbers.size(); }
246 int getTableCount() const{ return tables.size(); }
247 int getColumnCount() const{ return columnlist.size(); }
249 int getMaxSettedPage() const{ return m_nMaxSettedPage; }
250 void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
252 void push_hpara_type(unsigned char scflag) { element_import_stack.push_back(scflag); }
253 bool already_importing_type(unsigned char scflag) const
255 return std::find(element_import_stack.begin(), element_import_stack.end(), scflag) != element_import_stack.end();
257 void pop_hpara_type() { element_import_stack.pop_back(); }
259 private:
260 int compareCharShape(CharShape const *shape);
261 int compareParaShape(ParaShape const *shape);
263 public:
264 int version;
265 bool compressed;
266 bool encrypted;
267 unsigned char linenumber;
268 int info_block_len;
269 int error_code;
270 std::unique_ptr<OlePicture> oledata;
271 unsigned char scratch[SAL_MAX_UINT16];
272 int readdepth;
274 private:
275 /* hwp 파일 이름 */
276 int m_nCurrentPage;
277 int m_nMaxSettedPage;
278 std::unique_ptr<HIODev> hiodev;
279 // read hwp contents
280 HWPInfo _hwpInfo;
281 HWPFont _hwpFont;
282 HWPStyle _hwpStyle;
283 std::vector<std::unique_ptr<ColumnInfo>> columnlist;
284 // paragraph list
285 std::vector<std::unique_ptr<HWPPara>> plist;
286 // floating box list
287 std::vector<FBox*> blist;
288 // embedded picture list(tag data)
289 std::vector<std::unique_ptr<EmPicture>> emblist;
290 std::vector<std::unique_ptr<HyperText>> hyperlist;
291 int currenthyper;
292 std::vector<std::shared_ptr<ParaShape>> pslist;
293 std::vector<std::shared_ptr<CharShape>> cslist;
294 std::vector<FBoxStyle*> fbslist;
295 std::vector<DateCode*> datecodes;
296 std::vector<HeaderFooter*> headerfooters;
297 std::vector<ShowPageNum*> pagenumbers;
298 std::vector<std::unique_ptr<Table>> tables;
299 //track the stack of HParas types we're currently importing
300 std::vector<unsigned char> element_import_stack;
302 // for global document handling
303 static HWPFile *cur_doc;
304 friend HWPFile *GetCurrentDoc(void);
305 friend HWPFile *SetCurrentDoc(HWPFile *);
308 class DLLEXPORT DepthGuard
310 private:
311 HWPFile& m_rFile;
312 public:
313 DepthGuard(HWPFile &rFile)
314 : m_rFile(rFile)
316 ++m_rFile.readdepth;
318 bool toodeep() const
320 return m_rFile.readdepth == 512;
322 ~DepthGuard()
324 --m_rFile.readdepth;
328 HWPFile *GetCurrentDoc(void);
329 HWPFile *SetCurrentDoc(HWPFile *hwpfp);
330 #endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */