~ubuntu-branches/ubuntu/trusty/scribus-ng/trusty

« back to all changes in this revision

Viewing changes to scribus/plugins/gettext/pdbim/pdbim.h

  • Committer: Package Import Robot
  • Author(s): Oleksandr Moskalenko
  • Date: 2012-02-15 15:57:12 UTC
  • mfrom: (4.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20120215155712-biimoc8o875jht80
Tags: 1.4.0.dfsg+r17300-1
* Prepare a dummy transitional package to converge on the 1.4.0 release.
* debian/NEWS: update the news.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
 
to the COPYING file provided with the program. Following this notice may exist
4
 
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
 
for which a new license (GPL+exception) is in place.
6
 
*/
7
 
#ifndef PDBIM_H
8
 
#define PDBIM_H
9
 
 
10
 
#include "pluginapi.h"
11
 
 
12
 
class gtWriter;
13
 
class gtParagraphStyle;
14
 
class QString;
15
 
class QStringList;
16
 
 
17
 
extern "C" PLUGIN_API void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer);
18
 
 
19
 
extern "C" PLUGIN_API QString FileFormatName();
20
 
 
21
 
extern "C" PLUGIN_API QStringList FileExtensions();
22
 
 
23
 
 
24
 
 
25
 
 
26
 
/*! \brief Abiword's internal data types */
27
 
typedef unsigned int UT_uint32;
28
 
typedef unsigned short UT_uint16;
29
 
 
30
 
/*! \brief Define integral type Byte, Word, and DWord to match those on the
31
 
Pilot being 8, 16, and 32 bits, respectively. Max  8-bit unsigned */
32
 
typedef unsigned char Byte;
33
 
typedef UT_uint16 Word;
34
 
typedef UT_uint32 DWord;
35
 
 
36
 
/*! \brief Pilots have a fixed 4K record size */
37
 
#define RECORD_SIZE_MAX 4096
38
 
#define BUFFER_SIZE 4096
39
 
#define COUNT_BITS 3
40
 
#define DISP_BITS 11
41
 
#define DOC_CREATOR "REAd"
42
 
#define DOC_TYPE "TEXt"
43
 
/*! \brief 31 chars + 1 null terminator */
44
 
#define dmDBNameLength 32
45
 
 
46
 
/*! \brief PDB document header
47
 
http://www.pyrite.org/doc_format.html
48
 
version  2 bytes  0x0002 if data is compressed, 0x0001 if uncompressed
49
 
spare  2 bytes  purpose unknown (set to 0 on creation)
50
 
length  4 bytes  total length of text before compression
51
 
records  2 bytes  number of text records
52
 
record_size  2 bytes  maximum size of each record (usually 4096; see below)
53
 
position  4 bytes  currently viewed position in the document
54
 
sizes  2*records bytes  record size array
55
 
78 bytes total
56
 
*/
57
 
typedef struct
58
 
{
59
 
        char    name[ dmDBNameLength ];
60
 
        Word    attributes;
61
 
        Word    version;
62
 
        DWord   create_time;
63
 
        DWord   modify_time;
64
 
        DWord   backup_time;
65
 
        DWord   modificationNumber;
66
 
        DWord   appInfoID;
67
 
        DWord   sortInfoID;
68
 
        char    type[4];
69
 
        char    creator[4];
70
 
        DWord   id_seed;
71
 
        DWord   nextRecordList;
72
 
        Word    numRecords;
73
 
} pdb_header;
74
 
 
75
 
/*! \brief Some compilers pad structures out to DWord boundaries so using 
76
 
sizeof() doesn't give the intended result.
77
 
*/
78
 
#define PDB_HEADER_SIZE 78
79
 
#define PDB_RECORD_HEADER_SIZE 8
80
 
 
81
 
/*! \brief PDB Document record.
82
 
16 bytes total. */
83
 
typedef struct {
84
 
        Word    version; /* 1 = plain text, 2 = compressed */
85
 
        Word    reserved1;
86
 
        DWord   doc_size; /* in bytes, when uncompressed */
87
 
        Word    numRecords; /* text rec's only; = pdb_header.numRecords-1 */
88
 
        Word    rec_size; /* usually RECORD_SIZE_MAX */
89
 
        DWord   reserved2;
90
 
} doc_record0;
91
 
 
92
 
/*! \brief Binary buffer */
93
 
typedef struct {
94
 
        Byte buf[BUFFER_SIZE];
95
 
        UT_uint32   len;
96
 
        UT_uint32   position;
97
 
} buffer;
98
 
 
99
 
#define GET_Word(f,n)   { fread( &n, 2, 1, f ); n = swap_Word ( n ); }
100
 
#define GET_DWord(f,n)  { fread( &n, 4, 1, f ); n = swap_DWord( n ); }
101
 
 
102
 
/*! \brief An import filter for Palm Documents (PDB files).
103
 
PDB documents are simple non-formatted texts in binary forms used
104
 
mainly for e-books distribution.
105
 
It's taken from Abiword's PDB import/export plugin http://www.abisource.com
106
 
I've simplified the importer guts to fit special Scribus needs.
107
 
\warning This plugin uses a very special low-level IO and memory operations.
108
 
It uses big/little endian handling for bit related operations.
109
 
Welcome in the "macro and gtk hell" ;)
110
 
\note User should specify file encoding correctly.
111
 
\author Copyright (C) 2001 AbiSource, Inc.
112
 
\author Petr Vanek <petr@scribus.info>
113
 
*/
114
 
class PdbIm
115
 
{
116
 
public:
117
 
        /*! \brief Parse and decode the PDB file
118
 
        \param fname a file name of the document
119
 
        \param enc user selected text encoding. See encoding attr.
120
 
        \param w a reference to the gtWriter instance */
121
 
        PdbIm(const QString& fname, const QString& enc, gtWriter *w);
122
 
        ~PdbIm(){};
123
 
        /*! \brief Write data into Scribus text frame.
124
 
        User should specify encoding of the imported text - it's recoded here. */
125
 
        void write();
126
 
private:
127
 
        //! \brief Binary buffer for extraction tasks
128
 
        buffer *m_buf;
129
 
        //! \brief Store the extracted text here
130
 
        QString data;
131
 
        //! \brief Name of the codec/encoding to recode
132
 
        QString encoding;
133
 
        //! \brief Imp plugin handler
134
 
        gtWriter *writer;
135
 
        //! \brief A "bit order" flag. True on little endian systems.
136
 
        bool m_littlendian;
137
 
        //! \brief A "document uses that strange compress algorithm" flag.
138
 
        bool bCompressed;
139
 
        
140
 
        /*! \brief Parse the PDB file.
141
 
        \param fname a filename to open */
142
 
        void loadFile(QString fname);
143
 
        /*! \brief Learn which endian to use.
144
 
        It fills the m_littlendian flag */
145
 
        void selectSwap();
146
 
        /*! \brief Recompute the binary value for given endian
147
 
        \param r a binary Word
148
 
        \retval Word a correct endian Word */
149
 
        Word swap_Word(Word r);
150
 
        /*! \brief Recompute the binary value for given endian
151
 
        \param r a binary DWord
152
 
        \retval DWord a correct endian Word */
153
 
        DWord swap_DWord(DWord r);
154
 
        /*! \brief PDB strange decompress algorithm implementation.
155
 
        \param m_buf a reference to the current buffer */
156
 
        void uncompress(buffer *m_buf);
157
 
};
158
 
 
159
 
#endif