author | sandman <sandman> | 2002-04-16 22:22:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-16 22:22:14 (UTC) |
commit | f27ad352830a751937dc427f2677753545f38b16 (patch) (unidiff) | |
tree | 654858e6708eaaf09dd146a72f5fe1dbbf99a536 | |
parent | ece373988ee95e4dc3c22eeb012a077595740057 (diff) | |
download | opie-f27ad352830a751937dc427f2677753545f38b16.zip opie-f27ad352830a751937dc427f2677753545f38b16.tar.gz opie-f27ad352830a751937dc427f2677753545f38b16.tar.bz2 |
Fix (previous commit was an experimental version)
-rw-r--r-- | noncore/unsupported/qpdf/QOutputDev.cpp | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/noncore/unsupported/qpdf/QOutputDev.cpp b/noncore/unsupported/qpdf/QOutputDev.cpp index 15a58b1..f587a33 100644 --- a/noncore/unsupported/qpdf/QOutputDev.cpp +++ b/noncore/unsupported/qpdf/QOutputDev.cpp | |||
@@ -1,569 +1,567 @@ | |||
1 | ///======================================================================== | 1 | ///======================================================================== |
2 | // | 2 | // |
3 | // QOutputDev.cc | 3 | // QOutputDev.cc |
4 | // | 4 | // |
5 | // Copyright 1996 Derek B. Noonburg | 5 | // Copyright 1996 Derek B. Noonburg |
6 | // CopyRight 2002 Robert Griebl | 6 | // CopyRight 2002 Robert Griebl |
7 | // | 7 | // |
8 | //======================================================================== | 8 | //======================================================================== |
9 | 9 | ||
10 | #ifdef __GNUC__ | 10 | #ifdef __GNUC__ |
11 | #pragma implementation | 11 | #pragma implementation |
12 | #endif | 12 | #endif |
13 | 13 | ||
14 | #include <aconf.h> | 14 | #include <aconf.h> |
15 | #include <stdio.h> | 15 | #include <stdio.h> |
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | #include <stddef.h> | 17 | #include <stddef.h> |
18 | #include <unistd.h> | 18 | #include <unistd.h> |
19 | #include <string.h> | 19 | #include <string.h> |
20 | #include <ctype.h> | 20 | #include <ctype.h> |
21 | #include <math.h> | 21 | #include <math.h> |
22 | #include "GString.h" | 22 | #include "GString.h" |
23 | #include "Object.h" | 23 | #include "Object.h" |
24 | #include "Stream.h" | 24 | #include "Stream.h" |
25 | #include "Link.h" | 25 | #include "Link.h" |
26 | #include "GfxState.h" | 26 | #include "GfxState.h" |
27 | #include "GfxFont.h" | 27 | #include "GfxFont.h" |
28 | #include "UnicodeMap.h" | 28 | #include "UnicodeMap.h" |
29 | #include "CharCodeToUnicode.h" | 29 | #include "CharCodeToUnicode.h" |
30 | #include "FontFile.h" | 30 | #include "FontFile.h" |
31 | #include "Error.h" | 31 | #include "Error.h" |
32 | #include "TextOutputDev.h" | 32 | #include "TextOutputDev.h" |
33 | #include "QOutputDev.h" | 33 | #include "QOutputDev.h" |
34 | 34 | ||
35 | 35 | ||
36 | #include <qpixmap.h> | 36 | #include <qpixmap.h> |
37 | #include <qimage.h> | 37 | #include <qimage.h> |
38 | #include <qpainter.h> | 38 | #include <qpainter.h> |
39 | #include <qdict.h> | 39 | #include <qdict.h> |
40 | #include <qtimer.h> | 40 | #include <qtimer.h> |
41 | #include <qapplication.h> | 41 | #include <qapplication.h> |
42 | #include <qclipboard.h> | 42 | #include <qclipboard.h> |
43 | 43 | ||
44 | //#define QPDFDBG(x) x // special debug mode | 44 | //#define QPDFDBG(x) x // special debug mode |
45 | #define QPDFDBG(x) // normal compilation | 45 | #define QPDFDBG(x) // normal compilation |
46 | 46 | ||
47 | 47 | ||
48 | //------------------------------------------------------------------------ | 48 | //------------------------------------------------------------------------ |
49 | // Constants and macros | 49 | // Constants and macros |
50 | //------------------------------------------------------------------------ | 50 | //------------------------------------------------------------------------ |
51 | 51 | ||
52 | 52 | ||
53 | static inline QColor q_col ( const GfxRGB &rgb ) | 53 | static inline QColor q_col ( const GfxRGB &rgb ) |
54 | { | 54 | { |
55 | return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); | 55 | return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | //------------------------------------------------------------------------ | 59 | //------------------------------------------------------------------------ |
60 | // Font substitutions | 60 | // Font substitutions |
61 | //------------------------------------------------------------------------ | 61 | //------------------------------------------------------------------------ |
62 | 62 | ||
63 | struct QOutFontSubst { | 63 | struct QOutFontSubst { |
64 | char * m_name; | 64 | char * m_name; |
65 | char * m_sname; | 65 | char * m_sname; |
66 | bool m_bold; | 66 | bool m_bold; |
67 | bool m_italic; | 67 | bool m_italic; |
68 | QFont::StyleHint m_hint; | 68 | QFont::StyleHint m_hint; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | static QOutFontSubst qStdFonts [] = { | 71 | static QOutFontSubst qStdFonts [] = { |
72 | { "Helvetica", "Helvetica", false, false, QFont::Helvetica }, | 72 | { "Helvetica", "Helvetica", false, false, QFont::Helvetica }, |
73 | { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica }, | 73 | { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica }, |
74 | { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica }, | 74 | { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica }, |
75 | { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica }, | 75 | { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica }, |
76 | { "Times-Roman", "Times", false, false, QFont::Times }, | 76 | { "Times-Roman", "Times", false, false, QFont::Times }, |
77 | { "Times-Italic", "Times", false, true, QFont::Times }, | 77 | { "Times-Italic", "Times", false, true, QFont::Times }, |
78 | { "Times-Bold", "Times", true, false, QFont::Times }, | 78 | { "Times-Bold", "Times", true, false, QFont::Times }, |
79 | { "Times-BoldItalic", "Times", true, true, QFont::Times }, | 79 | { "Times-BoldItalic", "Times", true, true, QFont::Times }, |
80 | { "Courier", "Courier", false, false, QFont::Courier }, | 80 | { "Courier", "Courier", false, false, QFont::Courier }, |
81 | { "Courier-Oblique", "Courier", false, true, QFont::Courier }, | 81 | { "Courier-Oblique", "Courier", false, true, QFont::Courier }, |
82 | { "Courier-Bold", "Courier", true, false, QFont::Courier }, | 82 | { "Courier-Bold", "Courier", true, false, QFont::Courier }, |
83 | { "Courier-BoldOblique", "Courier", true, true, QFont::Courier }, | 83 | { "Courier-BoldOblique", "Courier", true, true, QFont::Courier }, |
84 | 84 | ||
85 | { "Symbol", 0, false, false, QFont::AnyStyle }, | 85 | { "Symbol", 0, false, false, QFont::AnyStyle }, |
86 | { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle }, | 86 | { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle }, |
87 | 87 | ||
88 | { 0, 0, false, false, QFont::AnyStyle } | 88 | { 0, 0, false, false, QFont::AnyStyle } |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | 96 | ||
97 | QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) | 97 | QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) |
98 | { | 98 | { |
99 | static QDict<QOutFontSubst> stdfonts; | 99 | static QDict<QOutFontSubst> stdfonts; |
100 | 100 | ||
101 | // build dict for std. fonts on first invocation | 101 | // build dict for std. fonts on first invocation |
102 | if ( stdfonts. isEmpty ( )) { | 102 | if ( stdfonts. isEmpty ( )) { |
103 | for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { | 103 | for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { |
104 | stdfonts. insert ( QString ( ptr-> m_name ), ptr ); | 104 | stdfonts. insert ( QString ( ptr-> m_name ), ptr ); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | // compute size and normalized transform matrix | 108 | // compute size and normalized transform matrix |
109 | int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); | 109 | int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); |
110 | 110 | ||
111 | QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n", | 111 | QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n", |
112 | (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ), | 112 | (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ), |
113 | size, | 113 | size, |
114 | gfxFont-> isBold ( ), | 114 | gfxFont-> isBold ( ), |
115 | gfxFont-> isItalic ( ), | 115 | gfxFont-> isItalic ( ), |
116 | gfxFont-> isFixedWidth ( ), | 116 | gfxFont-> isFixedWidth ( ), |
117 | gfxFont-> isSerif ( ), | 117 | gfxFont-> isSerif ( ), |
118 | gfxFont-> isSymbolic ( ), | 118 | gfxFont-> isSymbolic ( ), |
119 | gfxFont-> isCIDFont ( ), | 119 | gfxFont-> isCIDFont ( ), |
120 | ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), | 120 | ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), |
121 | (double) m11, (double) m12, (double) m21, (double) m22 )); | 121 | (double) m11, (double) m12, (double) m21, (double) m22 )); |
122 | 122 | ||
123 | 123 | ||
124 | QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); | 124 | QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); |
125 | 125 | ||
126 | QFont f; | 126 | QFont f; |
127 | f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes | 127 | f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes |
128 | 128 | ||
129 | // fast lookup for std. fonts | 129 | // fast lookup for std. fonts |
130 | QOutFontSubst *subst = stdfonts [fname]; | 130 | QOutFontSubst *subst = stdfonts [fname]; |
131 | 131 | ||
132 | if ( subst ) { | 132 | if ( subst ) { |
133 | if ( subst-> m_sname ) | 133 | if ( subst-> m_sname ) |
134 | f. setFamily ( subst-> m_sname ); | 134 | f. setFamily ( subst-> m_sname ); |
135 | f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); | 135 | f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); |
136 | f. setBold ( subst-> m_bold ); | 136 | f. setBold ( subst-> m_bold ); |
137 | f. setItalic ( subst-> m_italic ); | 137 | f. setItalic ( subst-> m_italic ); |
138 | } | 138 | } |
139 | else { | 139 | else { |
140 | QFont::StyleHint sty; | 140 | QFont::StyleHint sty; |
141 | 141 | ||
142 | if ( gfxFont-> isSerif ( )) | 142 | if ( gfxFont-> isSerif ( )) |
143 | sty = QFont::Serif; | 143 | sty = QFont::Serif; |
144 | else if ( gfxFont-> isFixedWidth ( )) | 144 | else if ( gfxFont-> isFixedWidth ( )) |
145 | sty = QFont::TypeWriter; | 145 | sty = QFont::TypeWriter; |
146 | else | 146 | else |
147 | sty = QFont::Helvetica; | 147 | sty = QFont::Helvetica; |
148 | 148 | ||
149 | f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); | 149 | f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); |
150 | f. setBold ( gfxFont-> isBold ( ) > 0 ); | 150 | f. setBold ( gfxFont-> isBold ( ) > 0 ); |
151 | f. setItalic ( gfxFont-> isItalic ( ) > 0 ); | 151 | f. setItalic ( gfxFont-> isItalic ( ) > 0 ); |
152 | f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 ); | 152 | f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 ); |
153 | 153 | ||
154 | // common specifiers in font names | 154 | // common specifiers in font names |
155 | if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" )) | 155 | if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" )) |
156 | f. setItalic ( true ); | 156 | f. setItalic ( true ); |
157 | if ( fname. contains ( "Bold" )) | 157 | if ( fname. contains ( "Bold" )) |
158 | f. setWeight ( QFont::Bold ); | 158 | f. setWeight ( QFont::Bold ); |
159 | if ( fname. contains ( "Demi" )) | 159 | if ( fname. contains ( "Demi" )) |
160 | f. setWeight ( QFont::DemiBold ); | 160 | f. setWeight ( QFont::DemiBold ); |
161 | if ( fname. contains ( "Light" )) | 161 | if ( fname. contains ( "Light" )) |
162 | f. setWeight ( QFont::Light ); | 162 | f. setWeight ( QFont::Light ); |
163 | if ( fname. contains ( "Black" )) | 163 | if ( fname. contains ( "Black" )) |
164 | f. setWeight ( QFont::Black ); | 164 | f. setWeight ( QFont::Black ); |
165 | } | 165 | } |
166 | // Treat x-sheared fonts as italic | 166 | // Treat x-sheared fonts as italic |
167 | if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) { | 167 | if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) { |
168 | f. setItalic ( true ); | 168 | f. setItalic ( true ); |
169 | } | 169 | } |
170 | return f; | 170 | return f; |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | //------------------------------------------------------------------------ | 175 | //------------------------------------------------------------------------ |
176 | // QOutputDev | 176 | // QOutputDev |
177 | //------------------------------------------------------------------------ | 177 | //------------------------------------------------------------------------ |
178 | 178 | ||
179 | QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) | 179 | QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) |
180 | { | 180 | { |
181 | m_pixmap = 0; | 181 | m_pixmap = 0; |
182 | m_painter = 0; | 182 | m_painter = 0; |
183 | 183 | ||
184 | m_use_string = true; | ||
185 | |||
186 | // create text object | 184 | // create text object |
187 | m_text = new TextPage ( gFalse ); | 185 | m_text = new TextPage ( gFalse ); |
188 | } | 186 | } |
189 | 187 | ||
190 | QOutputDev::~QOutputDev ( ) | 188 | QOutputDev::~QOutputDev ( ) |
191 | { | 189 | { |
192 | delete m_painter; | 190 | delete m_painter; |
193 | delete m_pixmap; | 191 | delete m_pixmap; |
194 | delete m_text; | 192 | delete m_text; |
195 | } | 193 | } |
196 | 194 | ||
197 | 195 | ||
198 | void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) | 196 | void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) |
199 | { | 197 | { |
200 | delete m_pixmap; | 198 | delete m_pixmap; |
201 | delete m_painter; | 199 | delete m_painter; |
202 | 200 | ||
203 | m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); | 201 | m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); |
204 | m_painter = new QPainter ( m_pixmap ); | 202 | m_painter = new QPainter ( m_pixmap ); |
205 | 203 | ||
206 | QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); | 204 | QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); |
207 | 205 | ||
208 | resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); | 206 | resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); |
209 | setContentsPos ( 0, 0 ); | 207 | setContentsPos ( 0, 0 ); |
210 | 208 | ||
211 | m_pixmap-> fill ( white ); // clear window | 209 | m_pixmap-> fill ( white ); // clear window |
212 | m_text-> clear ( ); // cleat text object | 210 | m_text-> clear ( ); // cleat text object |
213 | viewport ( )-> repaint ( ); | 211 | viewport ( )-> repaint ( ); |
214 | } | 212 | } |
215 | 213 | ||
216 | void QOutputDev::endPage ( ) | 214 | void QOutputDev::endPage ( ) |
217 | { | 215 | { |
218 | m_text-> coalesce ( ); | 216 | m_text-> coalesce ( ); |
219 | 217 | ||
220 | delete m_painter; | 218 | delete m_painter; |
221 | m_painter = 0; | 219 | m_painter = 0; |
222 | 220 | ||
223 | updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( )); | 221 | updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( )); |
224 | } | 222 | } |
225 | 223 | ||
226 | void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ ) | 224 | void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ ) |
227 | { | 225 | { |
228 | fp_t x1, y1, x2, y2, w; | 226 | fp_t x1, y1, x2, y2, w; |
229 | 227 | ||
230 | link-> getBorder ( &x1, &y1, &x2, &y2, &w ); | 228 | link-> getBorder ( &x1, &y1, &x2, &y2, &w ); |
231 | 229 | ||
232 | if ( w > 0 ) { | 230 | if ( w > 0 ) { |
233 | int x, y, dx, dy; | 231 | int x, y, dx, dy; |
234 | 232 | ||
235 | cvtUserToDev ( x1, y1, &x, &y ); | 233 | cvtUserToDev ( x1, y1, &x, &y ); |
236 | cvtUserToDev ( x2, y2, &dx, &dy ); | 234 | cvtUserToDev ( x2, y2, &dx, &dy ); |
237 | 235 | ||
238 | QPen oldpen = m_painter-> pen ( ); | 236 | QPen oldpen = m_painter-> pen ( ); |
239 | m_painter-> setPen ( blue ); | 237 | m_painter-> setPen ( blue ); |
240 | m_painter-> drawRect ( x, y, dx, dy ); | 238 | m_painter-> drawRect ( x, y, dx, dy ); |
241 | m_painter-> setPen ( oldpen ); | 239 | m_painter-> setPen ( oldpen ); |
242 | } | 240 | } |
243 | } | 241 | } |
244 | 242 | ||
245 | void QOutputDev::saveState ( GfxState */*state*/ ) | 243 | void QOutputDev::saveState ( GfxState */*state*/ ) |
246 | { | 244 | { |
247 | QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); | 245 | QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); |
248 | 246 | ||
249 | m_painter-> save ( ); | 247 | m_painter-> save ( ); |
250 | } | 248 | } |
251 | 249 | ||
252 | void QOutputDev::restoreState ( GfxState */*state*/ ) | 250 | void QOutputDev::restoreState ( GfxState */*state*/ ) |
253 | { | 251 | { |
254 | m_painter-> restore ( ); | 252 | m_painter-> restore ( ); |
255 | 253 | ||
256 | //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ))); | 254 | //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ))); |
257 | //m_painter-> setClipping ( false ); | 255 | //m_painter-> setClipping ( false ); |
258 | QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); | 256 | QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); |
259 | } | 257 | } |
260 | 258 | ||
261 | void QOutputDev::updateAll ( GfxState *state ) | 259 | void QOutputDev::updateAll ( GfxState *state ) |
262 | { | 260 | { |
263 | updateLineAttrs ( state, gTrue ); | 261 | updateLineAttrs ( state, gTrue ); |
264 | //updateFlatness ( state ); | 262 | //updateFlatness ( state ); |
265 | //updateMiterLimit ( state ); | 263 | //updateMiterLimit ( state ); |
266 | updateFillColor ( state ); | 264 | updateFillColor ( state ); |
267 | updateStrokeColor ( state ); | 265 | updateStrokeColor ( state ); |
268 | updateFont ( state ); | 266 | updateFont ( state ); |
269 | } | 267 | } |
270 | 268 | ||
271 | void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ ) | 269 | void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ ) |
272 | { | 270 | { |
273 | updateLineAttrs ( state, gTrue ); | 271 | updateLineAttrs ( state, gTrue ); |
274 | } | 272 | } |
275 | 273 | ||
276 | void QOutputDev::updateLineDash ( GfxState *state ) | 274 | void QOutputDev::updateLineDash ( GfxState *state ) |
277 | { | 275 | { |
278 | updateLineAttrs ( state, gTrue ); | 276 | updateLineAttrs ( state, gTrue ); |
279 | } | 277 | } |
280 | 278 | ||
281 | void QOutputDev::updateFlatness ( GfxState */*state*/ ) | 279 | void QOutputDev::updateFlatness ( GfxState */*state*/ ) |
282 | { | 280 | { |
283 | // not supported | 281 | // not supported |
284 | QPDFDBG( printf ( "updateFlatness not supported !\n" )); | 282 | QPDFDBG( printf ( "updateFlatness not supported !\n" )); |
285 | } | 283 | } |
286 | 284 | ||
287 | void QOutputDev::updateLineJoin ( GfxState *state ) | 285 | void QOutputDev::updateLineJoin ( GfxState *state ) |
288 | { | 286 | { |
289 | updateLineAttrs ( state, gFalse ); | 287 | updateLineAttrs ( state, gFalse ); |
290 | } | 288 | } |
291 | 289 | ||
292 | void QOutputDev::updateLineCap ( GfxState *state ) | 290 | void QOutputDev::updateLineCap ( GfxState *state ) |
293 | { | 291 | { |
294 | updateLineAttrs ( state, gFalse ); | 292 | updateLineAttrs ( state, gFalse ); |
295 | } | 293 | } |
296 | 294 | ||
297 | // unimplemented | 295 | // unimplemented |
298 | void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) | 296 | void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) |
299 | { | 297 | { |
300 | QPDFDBG( printf ( "updateMiterLimit not supported !\n" )); | 298 | QPDFDBG( printf ( "updateMiterLimit not supported !\n" )); |
301 | } | 299 | } |
302 | 300 | ||
303 | void QOutputDev::updateLineWidth ( GfxState *state ) | 301 | void QOutputDev::updateLineWidth ( GfxState *state ) |
304 | { | 302 | { |
305 | updateLineAttrs ( state, gFalse ); | 303 | updateLineAttrs ( state, gFalse ); |
306 | } | 304 | } |
307 | 305 | ||
308 | void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) | 306 | void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) |
309 | { | 307 | { |
310 | fp_t *dashPattern; | 308 | fp_t *dashPattern; |
311 | int dashLength; | 309 | int dashLength; |
312 | fp_t dashStart; | 310 | fp_t dashStart; |
313 | 311 | ||
314 | Qt::PenCapStyle cap; | 312 | Qt::PenCapStyle cap; |
315 | Qt::PenJoinStyle join; | 313 | Qt::PenJoinStyle join; |
316 | int width; | 314 | int width; |
317 | 315 | ||
318 | width = lrint ( state-> getTransformedLineWidth ( )); | 316 | width = lrint ( state-> getTransformedLineWidth ( )); |
319 | 317 | ||
320 | switch ( state-> getLineCap ( )) { | 318 | switch ( state-> getLineCap ( )) { |
321 | case 0: cap = FlatCap; break; | 319 | case 0: cap = FlatCap; break; |
322 | case 1: cap = RoundCap; break; | 320 | case 1: cap = RoundCap; break; |
323 | case 2: cap = SquareCap; break; | 321 | case 2: cap = SquareCap; break; |
324 | default: | 322 | default: |
325 | qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( )); | 323 | qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( )); |
326 | cap = FlatCap; | 324 | cap = FlatCap; |
327 | break; | 325 | break; |
328 | } | 326 | } |
329 | 327 | ||
330 | switch (state->getLineJoin()) { | 328 | switch (state->getLineJoin()) { |
331 | case 0: join = MiterJoin; break; | 329 | case 0: join = MiterJoin; break; |
332 | case 1: join = RoundJoin; break; | 330 | case 1: join = RoundJoin; break; |
333 | case 2: join = BevelJoin; break; | 331 | case 2: join = BevelJoin; break; |
334 | default: | 332 | default: |
335 | qWarning ( "Bad line join style (%d)\n", state->getLineJoin ( )); | 333 | qWarning ( "Bad line join style (%d)\n", state->getLineJoin ( )); |
336 | join = MiterJoin; | 334 | join = MiterJoin; |
337 | break; | 335 | break; |
338 | } | 336 | } |
339 | 337 | ||
340 | state-> getLineDash ( &dashPattern, &dashLength, &dashStart ); | 338 | state-> getLineDash ( &dashPattern, &dashLength, &dashStart ); |
341 | 339 | ||
342 | QColor oldcol = m_painter-> pen ( ). color ( ); | 340 | QColor oldcol = m_painter-> pen ( ). color ( ); |
343 | GfxRGB rgb; | 341 | GfxRGB rgb; |
344 | 342 | ||
345 | state-> getStrokeRGB ( &rgb ); | 343 | state-> getStrokeRGB ( &rgb ); |
346 | oldcol = q_col ( rgb ); | 344 | oldcol = q_col ( rgb ); |
347 | 345 | ||
348 | m_painter-> setPen ( QPen ( oldcol, width, dashLength > 0 ? DashLine : SolidLine, cap, join )); | 346 | m_painter-> setPen ( QPen ( oldcol, width, dashLength > 0 ? DashLine : SolidLine, cap, join )); |
349 | 347 | ||
350 | if ( updateDash && ( dashLength > 0 )) { | 348 | if ( updateDash && ( dashLength > 0 )) { |
351 | // Not supported by QT | 349 | // Not supported by QT |
352 | /* | 350 | /* |
353 | char dashList[20]; | 351 | char dashList[20]; |
354 | if (dashLength > 20) | 352 | if (dashLength > 20) |
355 | dashLength = 20; | 353 | dashLength = 20; |
356 | for ( int i = 0; i < dashLength; ++i ) { | 354 | for ( int i = 0; i < dashLength; ++i ) { |
357 | dashList[i] = xoutRound(state->transformWidth(dashPattern[i])); | 355 | dashList[i] = xoutRound(state->transformWidth(dashPattern[i])); |
358 | if (dashList[i] == 0) | 356 | if (dashList[i] == 0) |
359 | dashList[i] = 1; | 357 | dashList[i] = 1; |
360 | } | 358 | } |
361 | XSetDashes(display, strokeGC, xoutRound(dashStart), dashList, dashLength); | 359 | XSetDashes(display, strokeGC, xoutRound(dashStart), dashList, dashLength); |
362 | */ | 360 | */ |
363 | } | 361 | } |
364 | } | 362 | } |
365 | 363 | ||
366 | void QOutputDev::updateFillColor ( GfxState *state ) | 364 | void QOutputDev::updateFillColor ( GfxState *state ) |
367 | { | 365 | { |
368 | GfxRGB rgb; | 366 | GfxRGB rgb; |
369 | state-> getFillRGB ( &rgb ); | 367 | state-> getFillRGB ( &rgb ); |
370 | 368 | ||
371 | m_painter-> setBrush ( q_col ( rgb )); | 369 | m_painter-> setBrush ( q_col ( rgb )); |
372 | } | 370 | } |
373 | 371 | ||
374 | void QOutputDev::updateStrokeColor ( GfxState *state ) | 372 | void QOutputDev::updateStrokeColor ( GfxState *state ) |
375 | { | 373 | { |
376 | GfxRGB rgb; | 374 | GfxRGB rgb; |
377 | state-> getStrokeRGB ( &rgb ); | 375 | state-> getStrokeRGB ( &rgb ); |
378 | 376 | ||
379 | QPen pen = m_painter-> pen ( ); | 377 | QPen pen = m_painter-> pen ( ); |
380 | pen. setColor ( q_col ( rgb )); | 378 | pen. setColor ( q_col ( rgb )); |
381 | m_painter-> setPen ( pen ); | 379 | m_painter-> setPen ( pen ); |
382 | } | 380 | } |
383 | 381 | ||
384 | void QOutputDev::updateFont ( GfxState *state ) | 382 | void QOutputDev::updateFont ( GfxState *state ) |
385 | { | 383 | { |
386 | fp_t m11, m12, m21, m22; | 384 | fp_t m11, m12, m21, m22; |
387 | GfxFont *gfxFont = state-> getFont ( ); | 385 | GfxFont *gfxFont = state-> getFont ( ); |
388 | 386 | ||
389 | if ( !gfxFont ) | 387 | if ( !gfxFont ) |
390 | return; | 388 | return; |
391 | 389 | ||
392 | state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); | 390 | state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); |
393 | m11 *= state-> getHorizScaling ( ); | 391 | m11 *= state-> getHorizScaling ( ); |
394 | m12 *= state-> getHorizScaling ( ); | 392 | m12 *= state-> getHorizScaling ( ); |
395 | 393 | ||
396 | QFont font = matchFont ( gfxFont, m11, m12, m21, m22 ); | 394 | QFont font = matchFont ( gfxFont, m11, m12, m21, m22 ); |
397 | 395 | ||
398 | m_painter-> setFont ( font ); | 396 | m_painter-> setFont ( font ); |
399 | m_text-> updateFont ( state ); | 397 | m_text-> updateFont ( state ); |
400 | } | 398 | } |
401 | 399 | ||
402 | void QOutputDev::stroke ( GfxState *state ) | 400 | void QOutputDev::stroke ( GfxState *state ) |
403 | { | 401 | { |
404 | QPointArray points; | 402 | QPointArray points; |
405 | QArray<int> lengths; | 403 | QArray<int> lengths; |
406 | 404 | ||
407 | // transform points | 405 | // transform points |
408 | int n = convertPath ( state, points, lengths ); | 406 | int n = convertPath ( state, points, lengths ); |
409 | 407 | ||
410 | QPDFDBG( printf ( "DRAWING: %d POLYS\n", n )); | 408 | QPDFDBG( printf ( "DRAWING: %d POLYS\n", n )); |
411 | 409 | ||
412 | // draw each subpath | 410 | // draw each subpath |
413 | int j = 0; | 411 | int j = 0; |
414 | for ( int i = 0; i < n; i++ ) { | 412 | for ( int i = 0; i < n; i++ ) { |
415 | int len = lengths [i]; | 413 | int len = lengths [i]; |
416 | 414 | ||
417 | if ( len >= 2 ) { | 415 | if ( len >= 2 ) { |
418 | QPDFDBG( printf ( " - POLY %d: ", i )); | 416 | QPDFDBG( printf ( " - POLY %d: ", i )); |
419 | QPDFDBG( for ( int ii = 0; ii < len; ii++ )) | 417 | QPDFDBG( for ( int ii = 0; ii < len; ii++ )) |
420 | QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); | 418 | QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); |
421 | QPDFDBG( printf ( "\n" )); | 419 | QPDFDBG( printf ( "\n" )); |
422 | 420 | ||
423 | m_painter-> drawPolyline ( points, j, len ); | 421 | m_painter-> drawPolyline ( points, j, len ); |
424 | } | 422 | } |
425 | j += len; | 423 | j += len; |
426 | } | 424 | } |
427 | qApp-> processEvents ( ); | 425 | qApp-> processEvents ( ); |
428 | } | 426 | } |
429 | 427 | ||
430 | void QOutputDev::fill ( GfxState *state ) | 428 | void QOutputDev::fill ( GfxState *state ) |
431 | { | 429 | { |
432 | doFill ( state, true ); | 430 | doFill ( state, true ); |
433 | } | 431 | } |
434 | 432 | ||
435 | void QOutputDev::eoFill ( GfxState *state ) | 433 | void QOutputDev::eoFill ( GfxState *state ) |
436 | { | 434 | { |
437 | doFill ( state, false ); | 435 | doFill ( state, false ); |
438 | } | 436 | } |
439 | 437 | ||
440 | // | 438 | // |
441 | // X doesn't color the pixels on the right-most and bottom-most | 439 | // X doesn't color the pixels on the right-most and bottom-most |
442 | // borders of a polygon. This means that one-pixel-thick polygons | 440 | // borders of a polygon. This means that one-pixel-thick polygons |
443 | // are not colored at all. I think this is supposed to be a | 441 | // are not colored at all. I think this is supposed to be a |
444 | // feature, but I can't figure out why. So after it fills a | 442 | // feature, but I can't figure out why. So after it fills a |
445 | // polygon, it also draws lines around the border. This is done | 443 | // polygon, it also draws lines around the border. This is done |
446 | // only for single-component polygons, since it's not very | 444 | // only for single-component polygons, since it's not very |
447 | // compatible with the compound polygon kludge (see convertPath()). | 445 | // compatible with the compound polygon kludge (see convertPath()). |
448 | // | 446 | // |
449 | void QOutputDev::doFill ( GfxState *state, bool winding ) | 447 | void QOutputDev::doFill ( GfxState *state, bool winding ) |
450 | { | 448 | { |
451 | QPointArray points; | 449 | QPointArray points; |
452 | QArray<int> lengths; | 450 | QArray<int> lengths; |
453 | 451 | ||
454 | // transform points | 452 | // transform points |
455 | int n = convertPath ( state, points, lengths ); | 453 | int n = convertPath ( state, points, lengths ); |
456 | 454 | ||
457 | QPDFDBG( printf ( "FILLING: %d POLYS\n", n )); | 455 | QPDFDBG( printf ( "FILLING: %d POLYS\n", n )); |
458 | 456 | ||
459 | QPen oldpen = m_painter-> pen ( ); | 457 | QPen oldpen = m_painter-> pen ( ); |
460 | m_painter-> setPen ( QPen ( NoPen )); | 458 | m_painter-> setPen ( QPen ( NoPen )); |
461 | 459 | ||
462 | // draw each subpath | 460 | // draw each subpath |
463 | int j = 0; | 461 | int j = 0; |
464 | for ( int i = 0; i < n; i++ ) { | 462 | for ( int i = 0; i < n; i++ ) { |
465 | int len = lengths [i]; | 463 | int len = lengths [i]; |
466 | 464 | ||
467 | if ( len >= 3 ) { | 465 | if ( len >= 3 ) { |
468 | QPDFDBG( printf ( " - POLY %d: ", i )); | 466 | QPDFDBG( printf ( " - POLY %d: ", i )); |
469 | QPDFDBG( for ( int ii = 0; ii < len; ii++ )) | 467 | QPDFDBG( for ( int ii = 0; ii < len; ii++ )) |
470 | QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); | 468 | QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); |
471 | QPDFDBG( printf ( "\n" )); | 469 | QPDFDBG( printf ( "\n" )); |
472 | 470 | ||
473 | m_painter-> drawPolygon ( points, winding, j, len ); | 471 | m_painter-> drawPolygon ( points, winding, j, len ); |
474 | } | 472 | } |
475 | j += len; | 473 | j += len; |
476 | } | 474 | } |
477 | m_painter-> setPen ( oldpen ); | 475 | m_painter-> setPen ( oldpen ); |
478 | 476 | ||
479 | qApp-> processEvents ( ); | 477 | qApp-> processEvents ( ); |
480 | } | 478 | } |
481 | 479 | ||
482 | void QOutputDev::clip ( GfxState *state ) | 480 | void QOutputDev::clip ( GfxState *state ) |
483 | { | 481 | { |
484 | doClip ( state, true ); | 482 | doClip ( state, true ); |
485 | } | 483 | } |
486 | 484 | ||
487 | void QOutputDev::eoClip ( GfxState *state ) | 485 | void QOutputDev::eoClip ( GfxState *state ) |
488 | { | 486 | { |
489 | doClip ( state, false ); | 487 | doClip ( state, false ); |
490 | } | 488 | } |
491 | 489 | ||
492 | void QOutputDev::doClip ( GfxState *state, bool winding ) | 490 | void QOutputDev::doClip ( GfxState *state, bool winding ) |
493 | { | 491 | { |
494 | QPointArray points; | 492 | QPointArray points; |
495 | QArray<int> lengths; | 493 | QArray<int> lengths; |
496 | 494 | ||
497 | // transform points | 495 | // transform points |
498 | int n = convertPath ( state, points, lengths ); | 496 | int n = convertPath ( state, points, lengths ); |
499 | 497 | ||
500 | QRegion region; | 498 | QRegion region; |
501 | 499 | ||
502 | QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); | 500 | QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); |
503 | 501 | ||
504 | // draw each subpath | 502 | // draw each subpath |
505 | int j = 0; | 503 | int j = 0; |
506 | for ( int i = 0; i < n; i++ ) { | 504 | for ( int i = 0; i < n; i++ ) { |
507 | int len = lengths [i]; | 505 | int len = lengths [i]; |
508 | 506 | ||
509 | if ( len >= 3 ) { | 507 | if ( len >= 3 ) { |
510 | QPointArray dummy; | 508 | QPointArray dummy; |
511 | dummy. setRawData ( points. data ( ) + j, len ); | 509 | dummy. setRawData ( points. data ( ) + j, len ); |
512 | 510 | ||
513 | QPDFDBG( printf ( " - POLY %d: ", i )); | 511 | QPDFDBG( printf ( " - POLY %d: ", i )); |
514 | QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); | 512 | QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); |
515 | QPDFDBG( printf ( "\n" )); | 513 | QPDFDBG( printf ( "\n" )); |
516 | 514 | ||
517 | region |= QRegion ( dummy, winding ); | 515 | region |= QRegion ( dummy, winding ); |
518 | 516 | ||
519 | dummy. resetRawData ( points. data ( ) + j, len ); | 517 | dummy. resetRawData ( points. data ( ) + j, len ); |
520 | } | 518 | } |
521 | j += len; | 519 | j += len; |
522 | } | 520 | } |
523 | 521 | ||
524 | if ( m_painter-> hasClipping ( )) | 522 | if ( m_painter-> hasClipping ( )) |
525 | region &= m_painter-> clipRegion ( ); | 523 | region &= m_painter-> clipRegion ( ); |
526 | 524 | ||
527 | //m_painter-> setClipRegion ( region ); | 525 | //m_painter-> setClipRegion ( region ); |
528 | //m_painter-> setClipping ( true ); | 526 | //m_painter-> setClipping ( true ); |
529 | 527 | ||
530 | //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red ); | 528 | //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red ); |
531 | //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" ); | 529 | //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" ); |
532 | qApp-> processEvents ( ); | 530 | qApp-> processEvents ( ); |
533 | } | 531 | } |
534 | 532 | ||
535 | // | 533 | // |
536 | // Transform points in the path and convert curves to line segments. | 534 | // Transform points in the path and convert curves to line segments. |
537 | // Builds a set of subpaths and returns the number of subpaths. | 535 | // Builds a set of subpaths and returns the number of subpaths. |
538 | // If <fillHack> is set, close any unclosed subpaths and activate a | 536 | // If <fillHack> is set, close any unclosed subpaths and activate a |
539 | // kludge for polygon fills: First, it divides up the subpaths into | 537 | // kludge for polygon fills: First, it divides up the subpaths into |
540 | // non-overlapping polygons by simply comparing bounding rectangles. | 538 | // non-overlapping polygons by simply comparing bounding rectangles. |
541 | // Then it connects subaths within a single compound polygon to a single | 539 | // Then it connects subaths within a single compound polygon to a single |
542 | // point so that X can fill the polygon (sort of). | 540 | // point so that X can fill the polygon (sort of). |
543 | // | 541 | // |
544 | int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths ) | 542 | int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths ) |
545 | { | 543 | { |
546 | GfxPath *path = state-> getPath ( ); | 544 | GfxPath *path = state-> getPath ( ); |
547 | int n = path-> getNumSubpaths ( ); | 545 | int n = path-> getNumSubpaths ( ); |
548 | 546 | ||
549 | lengths. resize ( n ); | 547 | lengths. resize ( n ); |
550 | 548 | ||
551 | // do each subpath | 549 | // do each subpath |
552 | for ( int i = 0; i < n; i++ ) { | 550 | for ( int i = 0; i < n; i++ ) { |
553 | // transform the points | 551 | // transform the points |
554 | lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points ); | 552 | lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points ); |
555 | } | 553 | } |
556 | 554 | ||
557 | return n; | 555 | return n; |
558 | } | 556 | } |
559 | 557 | ||
560 | // | 558 | // |
561 | // Transform points in a single subpath and convert curves to line | 559 | // Transform points in a single subpath and convert curves to line |
562 | // segments. | 560 | // segments. |
563 | // | 561 | // |
564 | int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points ) | 562 | int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points ) |
565 | { | 563 | { |
566 | int oldcnt = points. count ( ); | 564 | int oldcnt = points. count ( ); |
567 | 565 | ||
568 | fp_t x0, y0, x1, y1, x2, y2, x3, y3; | 566 | fp_t x0, y0, x1, y1, x2, y2, x3, y3; |
569 | 567 | ||