filters

misc.h
1/*
2 * Copyright (c) 2002-2003 Nicolas HADACEK (hadacek@kde.org)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#ifndef MISC_H
21#define MISC_H
22
23#include <math.h>
24
25#include <tqcolor.h>
26#include <tqdom.h>
27#include <tqsize.h>
28#include <tqvaluevector.h>
29#include <tqdict.h>
30#include <tqmap.h>
31
32class LinkAction;
33class Catalog;
34class GfxRGB;
35class GfxState;
36
37namespace PDFImport
38{
39
40// FIX for TQt 3.0
41// qvaluevector bug - qheapsort uses 'count' but qvaluevector has only 'size'
42template <class Container>
43inline void qHeapSort2( Container &c )
44{
45 if ( c.begin() == c.end() )
46 return;
47
48 // The second last parameter is a hack to retrieve the value type
49 // Do the real sorting here
50 qHeapSortHelper( c.begin(), c.end(), *(c.begin()), (uint)c.size() );
51}
52
53enum ParagraphType { Body = 0, Header, Footer, Nb_ParagraphTypes };
54
55//-----------------------------------------------------------------------------
56enum FontFamily { Times = 0, Helvetica, Courier, Symbol, Nb_Family };
57enum FontStyle { Regular, Bold, Italic, BoldItalic };
58
59inline FontStyle toStyle(bool bold, bool italic) {
60 return (bold ? (italic ? BoldItalic : Bold)
61 : (italic ? Italic : Regular) );
62}
63inline bool isItalic(FontStyle style) {
64 return (style==Italic || style==BoldItalic);
65}
66inline bool isBold(FontStyle style) {
67 return (style==Bold || style==BoldItalic);
68}
69
70//-----------------------------------------------------------------------------
71inline double mmToPoint(double mm) { return mm * 72 / 25.4; }
72
73inline bool equal(double d1, double d2, double percent = 0.01) {
74 double delta = percent * (fabs(d1)+fabs(d2)) / 2;
75 return ( fabs(d1 - d2)<delta );
76}
77inline bool more(double d1, double d2, double percent = 0.01) {
78 double delta = percent * (fabs(d1)+fabs(d2)) / 2;
79 return ( (d2-d1)<delta );
80}
81inline bool less(double d1, double d2, double percent = 0.01) {
82 double delta = percent * (fabs(d1)+fabs(d2)) / 2;
83 return ( (d1-d2)<delta );
84}
85
86TQColor toColor(GfxRGB &);
87
88//-----------------------------------------------------------------------------
89class DRect {
90public:
91 DRect() : _left(0), _right(0), _top(0), _bottom(0) {}
92 DRect(double left, double right, double top, double bottom)
93 : _left(left), _right(right), _top(top), _bottom(bottom) {}
94
95 bool isValid() const { return ( _right>_left && _bottom>_top ); }
96
97 void setTop(double top) { _top = top; }
98 void setBottom(double bottom) { _bottom = bottom; }
99 void setRight(double right) { _right = right; }
100 void setLeft(double left) { _left = left; }
101
102 double top() const { return _top; }
103 double bottom() const { return _bottom; }
104 double left() const { return _left; }
105 double right() const { return _right; }
106
107 double width() const { return _right - _left; }
108 double height() const { return _bottom - _top; }
109
110 bool operator ==(const DRect &) const;
111 bool isInside(const DRect &, double percent = 0.01) const;
112 void unite(const DRect &);
113 TQString toString() const;
114
115private:
116 double _left, _right, _top, _bottom;
117};
118
119struct DPoint {
120 double x, y;
121};
122
123class DPath : public TQValueVector<DPoint>
124{
125public:
126 DPath() {}
127
128 bool isSegment() const { return size()==2; }
129 bool isHorizontalSegment() const {
130 return isSegment() && equal(at(0).y, at(1).y);
131 }
132 bool isVerticalSegment() const {
133 return isSegment() && equal(at(0).x, at(1).y);
134 }
135 bool isRectangle() const;
136 DRect boundingRect() const;
137};
138
139typedef TQValueVector<DPath> DPathVector;
140
141//-----------------------------------------------------------------------------
142class Font
143{
144public:
145 Font();
146 Font(const GfxState *, double size);
147
148 bool operator ==(const Font &) const;
149 bool format(TQDomDocument &, TQDomElement &format, uint pos, uint len,
150 bool all = false) const;
151 int height() const { return _data->height[_pointSize]; }
152 const TQColor &color() const { return _color; }
153 bool isLatex() const { return _data->latex; }
154
155 void setFamily(FontFamily);
156
157 static void init();
158 static void cleanup();
159
160private:
161 void init(const TQString &name);
162
163private:
164 uint _pointSize;
165 TQColor _color;
166
167 class Data {
168 public:
169 TQString family;
170 FontStyle style;
171 bool latex;
172 TQMap<int, int> height;
173 };
174 Data *_data;
175
176 static TQDict<Data> *_dict;
177 static const char *FAMILY_DATA[PDFImport::Nb_Family];
178};
179
180//-----------------------------------------------------------------------------
181class Link
182{
183public:
184 Link(const DRect &, LinkAction &, Catalog &);
185
186 const DRect &rect() const { return _rect; }
187 void format(TQDomDocument &, TQDomElement &format,
188 uint pos, const TQString &text) const;
189
190 static TQString pageLinkName(uint i);
191
192private:
193 DRect _rect;
194 TQString _href;
195};
196
197} // namespace
198
199#endif
The body is a frameset.
Definition body.h:38