LOK: custom widgets: check size of API structures
[LibreOffice.git] / hwpfilter / source / hwpfile.h
blob88e2151a5c9a975c980833c76271c8b6cbe3aab8
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 <list>
30 #include <memory>
31 #include <vector>
32 #include <stdio.h>
33 #include <string.h>
34 #include <fcntl.h>
35 #include <sal/types.h>
36 #include "hwplib.h"
37 #include "hfont.h"
38 #include "hstyle.h"
39 #include "hpara.h"
41 #define HWPIDLen 30
42 #define V20SIGNATURE "HWP Document File V2.00 \032\1\2\3\4\5"
43 #define V21SIGNATURE "HWP Document File V2.10 \032\1\2\3\4\5"
44 #define V30SIGNATURE "HWP Document File V3.00 \032\1\2\3\4\5"
46 #define HWP_V20 20
47 #define HWP_V21 21
48 #define HWP_V30 30
50 int detect_hwp_version(const char *str);
52 struct FBox;
53 struct EmPicture;
54 struct HyperText;
55 struct FBoxStyle;
56 struct CellLine;
57 struct Cell;
58 struct OlePicture;
59 struct Picture;
60 struct HeaderFooter;
61 struct ShowPageNum;
62 struct DateCode;
63 struct Table;
65 class HIODev;
66 class HWPInfo;
67 class HWPFont;
68 class HWPStyle;
69 class HWPPara;
70 class HStream;
72 struct ColumnInfo{
73 int start_page;
74 bool bIsSet;
75 std::shared_ptr<ColumnDef> xColdef;
76 explicit ColumnInfo(int num){
77 start_page = num;
78 bIsSet = false;
82 /**
83 * The HWPFile class is the main class of hwp for reading file
84 * information from stream
86 * The example is as below:
87 * <pre>
88 * HWPFile f;
89 * f.ReadHwpFile( stream );
90 * </pre>
92 * There are two way to read hwp information from stream, one is to read all at a time
93 * to use @ref ReadhwpFile() method like above example, other is to read partial information
94 * to use @ref Open(), @ref InfoRead(), @ref FontRead(), @ref StyleRead(), @ref ParaListRead(), @ref TagsRead(),
96 * @short HWP file management object
98 class DLLEXPORT HWPFile
100 public:
102 * Default constructor
104 HWPFile();
105 ~HWPFile();
107 public:
110 * Opens HStream to use it.
111 * @returns 0 if success, otherwise error code
112 * @see State()
114 int Open( std::unique_ptr<HStream> );
117 * Say current state
118 * @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.
120 int State( void ) const { return error_code;}
122 * Sets the current state
124 int SetState(int errcode);
126 * Reads one byte from HIODev
128 bool Read1b(unsigned char &out);
129 bool Read1b(char &out);
131 * Reads two byte from HIODev
133 bool Read2b(unsigned short &out);
135 * Reads four byte from HIODev
137 bool Read4b(unsigned int &out);
138 bool Read4b(int &out);
140 * Reads nmemb short type array from HIODev
142 size_t Read2b(void *ptr, size_t nmemb);
144 * Reads nmemb long type array from HIODev
146 void Read4b( void *ptr, size_t nmemb );
148 * Reads some bytes from HIODev not regarding endian's way
149 * @param size Amount for reading
151 size_t ReadBlock( void *ptr, size_t size );
153 * Skips some bytes from HIODev
155 size_t SkipBlock( size_t size );
157 * Reads main paragraph list
159 void ReadParaList(std::vector<std::unique_ptr<HWPPara>> &aplist, unsigned char flag = 0);
160 void ReadParaList(std::vector<HWPPara*> &aplist);
162 * Sets if the stream is compressed
164 void SetCompressed( bool );
166 * Sets current HIODev
168 std::unique_ptr<HIODev> SetIODevice( std::unique_ptr<HIODev> hiodev );
171 * Reads all information of hwp file from stream
173 int ReadHwpFile( std::unique_ptr<HStream> );
175 * Reads document information of hwp file from HIODev
177 void InfoRead(void);
179 * Reads font list of hwp file from HIODev
181 void FontRead(void);
183 * Reads style list of hwp file from HIODev
185 void StyleRead(void);
187 * Reads paragraph list of hwp file from HIODev
189 void ParaListRead();
190 /* 그림 등의 추가 정보를 읽는다. */
192 * Reads additional information like embedded image of hwp file from HIODev
194 void TagsRead();
196 enum Paper
198 UserPaper = 0,
199 Col80Paper = 1,
200 Col132Paper = 2,
201 A4Paper = 3,
202 LetterPaper = 4,
203 B5Paper = 5,
204 B4Paper = 6,
205 LegalPaper = 7,
206 A3Paper = 8
209 void AddBox(FBox *);
210 void AddPage(){ m_nCurrentPage++;}
211 void AddColumnInfo();
212 void SetColumnDef(std::shared_ptr<ColumnDef> const &);
213 void AddParaShape(std::shared_ptr<ParaShape> const &);
214 void AddCharShape(std::shared_ptr<CharShape> const &);
215 void AddFBoxStyle(FBoxStyle *);
216 void AddDateFormat(DateCode *);
217 void AddHeaderFooter(HeaderFooter *);
218 void AddPageNumber(ShowPageNum *);
219 void AddTable(std::unique_ptr<Table>);
221 ColumnDef* GetColumnDef(int);
222 int GetPageMasterNum(int page);
224 int getCurrentPage(){ return m_nCurrentPage;}
225 HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
226 HWPFont& GetHWPFont(void) { return _hwpFont; }
227 HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
228 HWPPara *GetFirstPara(void) { return !plist.empty() ? plist.front().get() : nullptr; }
230 EmPicture *GetEmPicture(Picture *pic);
231 EmPicture *GetEmPictureByName(char * name);
232 HyperText *GetHyperText();
233 ParaShape *getParaShape(int);
234 CharShape *getCharShape(int);
235 FBoxStyle *getFBoxStyle(int);
236 DateCode *getDateCode(int);
237 HeaderFooter *getHeaderFooter(int);
238 ShowPageNum *getPageNumber(int);
239 Table *getTable(int);
241 int getParaShapeCount(){ return pslist.size(); }
242 int getCharShapeCount(){ return cslist.size(); }
243 int getFBoxStyleCount(){ return fbslist.size(); }
244 int getDateFormatCount(){ return datecodes.size(); }
245 int getHeaderFooterCount(){ return headerfooters.size(); }
246 int getPageNumberCount(){ return pagenumbers.size(); }
247 int getTableCount(){ return tables.size(); }
248 int getColumnCount(){ return columnlist.size(); }
250 int getMaxSettedPage(){ return m_nMaxSettedPage; }
251 void setMaxSettedPage(){ m_nMaxSettedPage = m_nCurrentPage; }
253 void push_hpara_type(unsigned char scflag) { element_import_stack.push_back(scflag); }
254 bool already_importing_type(unsigned char scflag) const
256 return std::find(element_import_stack.begin(), element_import_stack.end(), scflag) != element_import_stack.end();
258 void pop_hpara_type() { element_import_stack.pop_back(); }
260 private:
261 int compareCharShape(CharShape const *shape);
262 int compareParaShape(ParaShape const *shape);
264 public:
265 int version;
266 bool compressed;
267 bool encrypted;
268 unsigned char linenumber;
269 int info_block_len;
270 int error_code;
271 std::unique_ptr<OlePicture> oledata;
272 unsigned char scratch[SAL_MAX_UINT16];
273 int readdepth;
275 private:
276 /* hwp 파일 이름 */
277 int m_nCurrentPage;
278 int m_nMaxSettedPage;
279 std::unique_ptr<HIODev> hiodev;
280 // read hwp contents
281 HWPInfo _hwpInfo;
282 HWPFont _hwpFont;
283 HWPStyle _hwpStyle;
284 std::vector<std::unique_ptr<ColumnInfo>> columnlist;
285 // paragraph list
286 std::vector<std::unique_ptr<HWPPara>> plist;
287 // floating box list
288 std::vector<FBox*> blist;
289 // embedded picture list(tag datas)
290 std::vector<std::unique_ptr<EmPicture>> emblist;
291 std::vector<std::unique_ptr<HyperText>> hyperlist;
292 int currenthyper;
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;
303 // for global document handling
304 static HWPFile *cur_doc;
305 friend HWPFile *GetCurrentDoc(void);
306 friend HWPFile *SetCurrentDoc(HWPFile *);
309 class DLLEXPORT DepthGuard
311 private:
312 HWPFile& m_rFile;
313 public:
314 DepthGuard(HWPFile &rFile)
315 : m_rFile(rFile)
317 ++m_rFile.readdepth;
319 bool toodeep() const
321 return m_rFile.readdepth == 512;
323 ~DepthGuard()
325 --m_rFile.readdepth;
329 HWPFile *GetCurrentDoc(void);
330 HWPFile *SetCurrentDoc(HWPFile *hwpfp);
331 #endif // INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */