-rw-r--r-- | noncore/apps/oxygen/kmolcalc.cpp | 2 | ||||
-rw-r--r-- | noncore/games/kbill/MCursor.cc | 6 | ||||
-rw-r--r-- | noncore/games/kbill/Picture.cc | 6 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/QOutputDev.cpp | 12 |
4 files changed, 14 insertions, 12 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp index 33666b1..1d41b0f 100644 --- a/noncore/apps/oxygen/kmolcalc.cpp +++ b/noncore/apps/oxygen/kmolcalc.cpp | |||
@@ -1,200 +1,200 @@ | |||
1 | /* | 1 | /* |
2 | * kmolcalc.cpp | 2 | * kmolcalc.cpp |
3 | * | 3 | * |
4 | * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> | 4 | * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> |
5 | * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> | 5 | * Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org> |
6 | */ | 6 | */ |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic | 9 | * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic |
10 | * weights and group definitions ELSTABLE, and the currently processed formula, stored | 10 | * weights and group definitions ELSTABLE, and the currently processed formula, stored |
11 | * as a list of elements and their coefficients, ELEMENTS. | 11 | * as a list of elements and their coefficients, ELEMENTS. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "kmolcalc.h" | 14 | #include "kmolcalc.h" |
15 | #include <qdict.h> | 15 | #include <qdict.h> |
16 | #include <qdir.h> | 16 | #include <qdir.h> |
17 | #include <qfile.h> | 17 | #include <qfile.h> |
18 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #include <iostream.h> | 19 | #include <iostream> |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
23 | * Construct a new calculator object. | 23 | * Construct a new calculator object. |
24 | */ | 24 | */ |
25 | KMolCalc::KMolCalc() { | 25 | KMolCalc::KMolCalc() { |
26 | elements = new ElementList; | 26 | elements = new ElementList; |
27 | elstable = NULL; | 27 | elstable = NULL; |
28 | readElstable(); | 28 | readElstable(); |
29 | } | 29 | } |
30 | 30 | ||
31 | KMolCalc::~KMolCalc() { | 31 | KMolCalc::~KMolCalc() { |
32 | delete elements; | 32 | delete elements; |
33 | } | 33 | } |
34 | 34 | ||
35 | void KMolCalc::readElstable() { | 35 | void KMolCalc::readElstable() { |
36 | weight = -1; // not calculated yet | 36 | weight = -1; // not calculated yet |
37 | if (elstable) delete elstable; | 37 | if (elstable) delete elstable; |
38 | elstable = new QDict<SubUnit> (197, TRUE); | 38 | elstable = new QDict<SubUnit> (197, TRUE); |
39 | elstable->setAutoDelete(TRUE); | 39 | elstable->setAutoDelete(TRUE); |
40 | mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; | 40 | mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; |
41 | QFile f(mwfile); | 41 | QFile f(mwfile); |
42 | if (f.exists()) readMwfile(f); | 42 | if (f.exists()) readMwfile(f); |
43 | } | 43 | } |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Parse a string S and construct the ElementList this->ELEMENTS, representing the | 47 | * Parse a string S and construct the ElementList this->ELEMENTS, representing the |
48 | * composition of S. Returns 0 if successful, or an error code (currently -1) if | 48 | * composition of S. Returns 0 if successful, or an error code (currently -1) if |
49 | * parsing failed. | 49 | * parsing failed. |
50 | * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. | 50 | * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. |
51 | * See help files for correct formula syntax. | 51 | * See help files for correct formula syntax. |
52 | */ | 52 | */ |
53 | QString KMolCalc::readFormula(const QString& s) { | 53 | QString KMolCalc::readFormula(const QString& s) { |
54 | weight = -1; | 54 | weight = -1; |
55 | if (elements) delete elements; | 55 | if (elements) delete elements; |
56 | elements = new ElementList; | 56 | elements = new ElementList; |
57 | return KMolCalc::readGroup(s, elements); | 57 | return KMolCalc::readGroup(s, elements); |
58 | } | 58 | } |
59 | 59 | ||
60 | // read a formula group recursively. Called by readFormula. | 60 | // read a formula group recursively. Called by readFormula. |
61 | QString KMolCalc::readGroup(const QString& s, ElementList* els) { | 61 | QString KMolCalc::readGroup(const QString& s, ElementList* els) { |
62 | if (s.isEmpty()) return QString ("Enter a formula."); //ERROR | 62 | if (s.isEmpty()) return QString ("Enter a formula."); //ERROR |
63 | int sl = s.length(); | 63 | int sl = s.length(); |
64 | int i = 0; | 64 | int i = 0; |
65 | QString errors ("OK"); | 65 | QString errors ("OK"); |
66 | bool ok = TRUE; | 66 | bool ok = TRUE; |
67 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 67 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
68 | double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); | 68 | double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); |
69 | if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR | 69 | if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR |
70 | ElementList* elstemp = new ElementList; | 70 | ElementList* elstemp = new ElementList; |
71 | while (i < sl) { | 71 | while (i < sl) { |
72 | int j = i; | 72 | int j = i; |
73 | if (s[i] == '(') { | 73 | if (s[i] == '(') { |
74 | ElementList* inner = new ElementList; | 74 | ElementList* inner = new ElementList; |
75 | int level = 1; // count levels of nested ( ). | 75 | int level = 1; // count levels of nested ( ). |
76 | while (1) { | 76 | while (1) { |
77 | if (i++ == sl) { | 77 | if (i++ == sl) { |
78 | delete inner; | 78 | delete inner; |
79 | delete elstemp; | 79 | delete elstemp; |
80 | return QString ("Bad formula."); //ERROR | 80 | return QString ("Bad formula."); //ERROR |
81 | } | 81 | } |
82 | if (s[i] == '(') level++; | 82 | if (s[i] == '(') level++; |
83 | if (s[i] == ')') level--; | 83 | if (s[i] == ')') level--; |
84 | if (level == 0) break; | 84 | if (level == 0) break; |
85 | } | 85 | } |
86 | errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); | 86 | errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); |
87 | j = ++i; | 87 | j = ++i; |
88 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 88 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
89 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); | 89 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); |
90 | if (! ok || suffix == 0) { | 90 | if (! ok || suffix == 0) { |
91 | delete inner; | 91 | delete inner; |
92 | delete elstemp; | 92 | delete elstemp; |
93 | return QString ("Bad formula."); // ERROR | 93 | return QString ("Bad formula."); // ERROR |
94 | } | 94 | } |
95 | inner->addTo(*elstemp, suffix); | 95 | inner->addTo(*elstemp, suffix); |
96 | delete inner; | 96 | delete inner; |
97 | inner = NULL; | 97 | inner = NULL; |
98 | } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { | 98 | } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { |
99 | while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || | 99 | while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || |
100 | s[i] == '\'')); | 100 | s[i] == '\'')); |
101 | QString elname = s.mid(j, i-j); | 101 | QString elname = s.mid(j, i-j); |
102 | j = i; | 102 | j = i; |
103 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 103 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
104 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); | 104 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); |
105 | if (! ok || suffix == 0) { | 105 | if (! ok || suffix == 0) { |
106 | delete elstemp; | 106 | delete elstemp; |
107 | return QString ("Bad formula."); // ERROR | 107 | return QString ("Bad formula."); // ERROR |
108 | } | 108 | } |
109 | SubUnit* group = elstable->find(elname); | 109 | SubUnit* group = elstable->find(elname); |
110 | if (group == 0) { | 110 | if (group == 0) { |
111 | delete elstemp; | 111 | delete elstemp; |
112 | return QString ("Undefined symbol: ") + elname; //ERROR | 112 | return QString ("Undefined symbol: ") + elname; //ERROR |
113 | } | 113 | } |
114 | group->addTo(*elstemp, suffix); | 114 | group->addTo(*elstemp, suffix); |
115 | } else if (s[i] == '+') { | 115 | } else if (s[i] == '+') { |
116 | if (elstemp->isEmpty()) { | 116 | if (elstemp->isEmpty()) { |
117 | delete elstemp; | 117 | delete elstemp; |
118 | return QString ("Bad formula."); //ERROR | 118 | return QString ("Bad formula."); //ERROR |
119 | } | 119 | } |
120 | elstemp->addTo(*els, prefix); | 120 | elstemp->addTo(*els, prefix); |
121 | delete elstemp; | 121 | delete elstemp; |
122 | errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); | 122 | errors = KMolCalc::readGroup(s.mid(i+1, sl-i-1), els); |
123 | return errors; | 123 | return errors; |
124 | } else { | 124 | } else { |
125 | delete elstemp; | 125 | delete elstemp; |
126 | return QString ("Bad formula."); //ERROR | 126 | return QString ("Bad formula."); //ERROR |
127 | } | 127 | } |
128 | } | 128 | } |
129 | elstemp->addTo(*els, prefix); | 129 | elstemp->addTo(*els, prefix); |
130 | delete elstemp; | 130 | delete elstemp; |
131 | return errors; | 131 | return errors; |
132 | } | 132 | } |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Calculate and return the molecular weight of the current chemical formula. | 135 | * Calculate and return the molecular weight of the current chemical formula. |
136 | */ | 136 | */ |
137 | double KMolCalc::getWeight() { | 137 | double KMolCalc::getWeight() { |
138 | if (weight == -1) weight = elements->getWeight(elstable); | 138 | if (weight == -1) weight = elements->getWeight(elstable); |
139 | return weight; | 139 | return weight; |
140 | } | 140 | } |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Return the elemental composition of the current formula, as a string of tab-separated | 143 | * Return the elemental composition of the current formula, as a string of tab-separated |
144 | * element - percentage pairs, separated by newlines. | 144 | * element - percentage pairs, separated by newlines. |
145 | */ | 145 | */ |
146 | QString KMolCalc::getEA() { | 146 | QString KMolCalc::getEA() { |
147 | if (weight == -1) weight = elements->getWeight(elstable); | 147 | if (weight == -1) weight = elements->getWeight(elstable); |
148 | if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR | 148 | if (weight == -1) return QString("ERROR: Couldn't get Mw..."); // ERROR |
149 | return elements->getEA(elstable, weight); | 149 | return elements->getEA(elstable, weight); |
150 | } | 150 | } |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Return the empirical formula of the current compound as a QString. | 153 | * Return the empirical formula of the current compound as a QString. |
154 | */ | 154 | */ |
155 | QString KMolCalc::getEmpFormula() { | 155 | QString KMolCalc::getEmpFormula() { |
156 | return elements->getEmpFormula(); | 156 | return elements->getEmpFormula(); |
157 | } | 157 | } |
158 | 158 | ||
159 | // Read the element definition file. | 159 | // Read the element definition file. |
160 | void KMolCalc::readMwfile(QFile& f) { | 160 | void KMolCalc::readMwfile(QFile& f) { |
161 | if (! f.open(IO_ReadOnly)) return; //ERROR | 161 | if (! f.open(IO_ReadOnly)) return; //ERROR |
162 | QTextStream fs (&f); | 162 | QTextStream fs (&f); |
163 | QString line; | 163 | QString line; |
164 | while (! fs.eof()) { | 164 | while (! fs.eof()) { |
165 | line = fs.readLine(); | 165 | line = fs.readLine(); |
166 | SubUnit* s = SubUnit::makeSubUnit(line); | 166 | SubUnit* s = SubUnit::makeSubUnit(line); |
167 | elstable->replace(s->getName(), s); | 167 | elstable->replace(s->getName(), s); |
168 | } | 168 | } |
169 | f.close(); | 169 | f.close(); |
170 | } | 170 | } |
171 | 171 | ||
172 | /** | 172 | /** |
173 | * Remove a group or element definition from ELSTABLE. | 173 | * Remove a group or element definition from ELSTABLE. |
174 | */ | 174 | */ |
175 | void KMolCalc::undefineGroup (const QString& name) { | 175 | void KMolCalc::undefineGroup (const QString& name) { |
176 | elstable->remove (name); | 176 | elstable->remove (name); |
177 | } | 177 | } |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes | 180 | * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes |
181 | * NAME has valid syntax. | 181 | * NAME has valid syntax. |
182 | 182 | ||
183 | */ | 183 | */ |
184 | void KMolCalc::defineElement (const QString& name, double weight) { | 184 | void KMolCalc::defineElement (const QString& name, double weight) { |
185 | Element* el = new Element(name, weight); | 185 | Element* el = new Element(name, weight); |
186 | elstable->replace(name, el); | 186 | elstable->replace(name, el); |
187 | } | 187 | } |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA | 190 | * Add a new group definition to the ELSTABLE. Returns 0 if OK, -1 if parsing FORMULA |
191 | * fails. Assumes the syntax of grpname is correct. | 191 | * fails. Assumes the syntax of grpname is correct. |
192 | */ | 192 | */ |
193 | QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) { | 193 | QString KMolCalc::defineGroup (const QString& grpname, const QString& formula) { |
194 | ElementList* els = new ElementList(grpname); | 194 | ElementList* els = new ElementList(grpname); |
195 | QString error = readGroup(formula, els); | 195 | QString error = readGroup(formula, els); |
196 | if (error != "OK") return error; | 196 | if (error != "OK") return error; |
197 | if (els->contains(grpname)) return QString("Can't define a group recursively!\n"); | 197 | if (els->contains(grpname)) return QString("Can't define a group recursively!\n"); |
198 | elstable->replace(grpname, els); | 198 | elstable->replace(grpname, els); |
199 | return QString("OK"); | 199 | return QString("OK"); |
200 | } | 200 | } |
diff --git a/noncore/games/kbill/MCursor.cc b/noncore/games/kbill/MCursor.cc index 30f7577..a3cb340 100644 --- a/noncore/games/kbill/MCursor.cc +++ b/noncore/games/kbill/MCursor.cc | |||
@@ -1,69 +1,69 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | MCursor.cc - description | 2 | MCursor.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "MCursor.h" | 17 | #include "MCursor.h" |
18 | #include "objects.h" | 18 | #include "objects.h" |
19 | 19 | ||
20 | #include <qcursor.h> | 20 | #include <qcursor.h> |
21 | #include <qbitmap.h> | 21 | #include <qbitmap.h> |
22 | #include <qwidget.h> | 22 | #include <qwidget.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #ifdef KDEVER | 24 | #ifdef KDEVER |
25 | #include <kapp.h> | 25 | #include <kapp.h> |
26 | #include <kstandarddirs.h> | 26 | #include <kstandarddirs.h> |
27 | #endif | 27 | #endif |
28 | #include <iostream.h> | 28 | #include <iostream> |
29 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
30 | MCursor::~MCursor() { | 30 | MCursor::~MCursor() { |
31 | delete cursor; | 31 | delete cursor; |
32 | } | 32 | } |
33 | 33 | ||
34 | void MCursor::load(const char *name, int masked) { | 34 | void MCursor::load(const char *name, int masked) { |
35 | 35 | ||
36 | #ifdef KDEVER | 36 | #ifdef KDEVER |
37 | QString file, mfile; | 37 | QString file, mfile; |
38 | KStandardDirs dirs; | 38 | KStandardDirs dirs; |
39 | 39 | ||
40 | 40 | ||
41 | file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + ".xbm"); | 41 | file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + ".xbm"); |
42 | 42 | ||
43 | QBitmap bitmap, mask; | 43 | QBitmap bitmap, mask; |
44 | if (bitmap.load(file) == FALSE) { | 44 | if (bitmap.load(file) == FALSE) { |
45 | cerr << "cannot open " << file << endl; | 45 | std::cerr << "cannot open " << file << std::endl; |
46 | exit(1); | 46 | exit(1); |
47 | } | 47 | } |
48 | if (masked == SEP_MASK) { | 48 | if (masked == SEP_MASK) { |
49 | // mfile.sprintf ("%sbitmaps/%s_mask.xbm", (const char*)dir, name); | 49 | // mfile.sprintf ("%sbitmaps/%s_mask.xbm", (const char*)dir, name); |
50 | mfile = file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); | 50 | mfile = file = dirs.findResource("data","kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); |
51 | if (mask.load(mfile) == FALSE) { | 51 | if (mask.load(mfile) == FALSE) { |
52 | cerr << "cannot open " << file << endl; | 52 | std::cerr << "cannot open " << file << std::endl; |
53 | exit(1); | 53 | exit(1); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | else | 56 | else |
57 | mask = bitmap; | 57 | mask = bitmap; |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | QBitmap bitmap, mask; | 60 | QBitmap bitmap, mask; |
61 | bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name)); | 61 | bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name)); |
62 | 62 | ||
63 | if (masked == SEP_MASK) | 63 | if (masked == SEP_MASK) |
64 | mask = bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); | 64 | mask = bitmap = Resource::loadBitmap("kbill/bitmaps/" + QString::fromLocal8Bit(name) + "_mask.xbm"); |
65 | else | 65 | else |
66 | mask = bitmap; | 66 | mask = bitmap; |
67 | cursor = new QCursor(bitmap, mask, bitmap.width() / 2, bitmap.height() / 2); | 67 | cursor = new QCursor(bitmap, mask, bitmap.width() / 2, bitmap.height() / 2); |
68 | } | 68 | } |
69 | 69 | ||
diff --git a/noncore/games/kbill/Picture.cc b/noncore/games/kbill/Picture.cc index 79e19ba..fe0eff8 100644 --- a/noncore/games/kbill/Picture.cc +++ b/noncore/games/kbill/Picture.cc | |||
@@ -1,72 +1,72 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | Picture.cc - description | 2 | Picture.cc - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Dec 30 1999 | 4 | begin : Thu Dec 30 1999 |
5 | copyright : (C) 1999 by Jurrien Loonstra | 5 | copyright : (C) 1999 by Jurrien Loonstra |
6 | email : j.h.loonstra@st.hanze.nl | 6 | email : j.h.loonstra@st.hanze.nl |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include "Picture.h" | 17 | #include "Picture.h" |
18 | #include "objects.h" | 18 | #include "objects.h" |
19 | 19 | ||
20 | #include <iostream.h> | 20 | #include <iostream> |
21 | 21 | ||
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #ifdef KDEVER | 24 | #ifdef KDEVER |
25 | #include <kapp.h> | 25 | #include <kapp.h> |
26 | #include <kstandarddirs.h> | 26 | #include <kstandarddirs.h> |
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #endif | 28 | #endif |
29 | void Picture::load(const char *name, int index) { | 29 | void Picture::load(const char *name, int index) { |
30 | //QString dir = KApplication::kde_datadir(), file; | 30 | //QString dir = KApplication::kde_datadir(), file; |
31 | // QString dir = locate("data",""),file; | 31 | // QString dir = locate("data",""),file; |
32 | // dir += "/kbill/"; | 32 | // dir += "/kbill/"; |
33 | // if (index>=0) | 33 | // if (index>=0) |
34 | // file.sprintf ("%spixmaps/%s_%d.xpm", (const char *)dir, name, index); | 34 | // file.sprintf ("%spixmaps/%s_%d.xpm", (const char *)dir, name, index); |
35 | // else | 35 | // else |
36 | // file.sprintf("%spixmaps/%s.xpm", (const char *)dir, name); | 36 | // file.sprintf("%spixmaps/%s.xpm", (const char *)dir, name); |
37 | #ifdef KDEVER | 37 | #ifdef KDEVER |
38 | KStandardDirs dirs; | 38 | KStandardDirs dirs; |
39 | QString file; | 39 | QString file; |
40 | 40 | ||
41 | if (index>=0) { | 41 | if (index>=0) { |
42 | //kdDebug() << "Here"; | 42 | //kdDebug() << "Here"; |
43 | QString sindex; | 43 | QString sindex; |
44 | sindex.setNum(index); | 44 | sindex.setNum(index); |
45 | // kdDebug() << "kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"; | 45 | // kdDebug() << "kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"; |
46 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"); | 46 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + "_" + sindex + ".xpm"); |
47 | } else { | 47 | } else { |
48 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + ".xpm"); | 48 | file = dirs.findResource("data","kbill/pixmaps/" + QString::fromLocal8Bit(name) + ".xpm"); |
49 | } | 49 | } |
50 | kdDebug() << file << endl; | 50 | kdDebug() << file << std::endl; |
51 | pix = new QPixmap(); | 51 | pix = new QPixmap(); |
52 | if (pix->load(file) == FALSE) | 52 | if (pix->load(file) == FALSE) |
53 | cerr << "cannot open " << file << endl; | 53 | std::cerr << "cannot open " << file << std::endl; |
54 | width = pix->width(); | 54 | width = pix->width(); |
55 | height = pix->height(); | 55 | height = pix->height(); |
56 | #endif | 56 | #endif |
57 | QString sindex; | 57 | QString sindex; |
58 | pix = new QPixmap(); | 58 | pix = new QPixmap(); |
59 | sindex.setNum(index); | 59 | sindex.setNum(index); |
60 | if (index>=0) | 60 | if (index>=0) |
61 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name) +"_"+ sindex)); | 61 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name) +"_"+ sindex)); |
62 | else | 62 | else |
63 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name))); | 63 | pix->load(Resource::findPixmap("kbill/pixmaps/" + QString::fromLocal8Bit(name))); |
64 | 64 | ||
65 | width = pix->width(); | 65 | width = pix->width(); |
66 | height = pix->height(); | 66 | height = pix->height(); |
67 | 67 | ||
68 | } | 68 | } |
69 | 69 | ||
70 | QPixmap* Picture::getPixmap() { | 70 | QPixmap* Picture::getPixmap() { |
71 | return pix; | 71 | return pix; |
72 | } | 72 | } |
diff --git a/noncore/unsupported/qpdf/QOutputDev.cpp b/noncore/unsupported/qpdf/QOutputDev.cpp index f587a33..52237f5 100644 --- a/noncore/unsupported/qpdf/QOutputDev.cpp +++ b/noncore/unsupported/qpdf/QOutputDev.cpp | |||
@@ -1,213 +1,215 @@ | |||
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 <iostream> | ||
23 | |||
22 | #include "GString.h" | 24 | #include "GString.h" |
23 | #include "Object.h" | 25 | #include "Object.h" |
24 | #include "Stream.h" | 26 | #include "Stream.h" |
25 | #include "Link.h" | 27 | #include "Link.h" |
26 | #include "GfxState.h" | 28 | #include "GfxState.h" |
27 | #include "GfxFont.h" | 29 | #include "GfxFont.h" |
28 | #include "UnicodeMap.h" | 30 | #include "UnicodeMap.h" |
29 | #include "CharCodeToUnicode.h" | 31 | #include "CharCodeToUnicode.h" |
30 | #include "FontFile.h" | 32 | #include "FontFile.h" |
31 | #include "Error.h" | 33 | #include "Error.h" |
32 | #include "TextOutputDev.h" | 34 | #include "TextOutputDev.h" |
33 | #include "QOutputDev.h" | 35 | #include "QOutputDev.h" |
34 | 36 | ||
35 | 37 | ||
36 | #include <qpixmap.h> | 38 | #include <qpixmap.h> |
37 | #include <qimage.h> | 39 | #include <qimage.h> |
38 | #include <qpainter.h> | 40 | #include <qpainter.h> |
39 | #include <qdict.h> | 41 | #include <qdict.h> |
40 | #include <qtimer.h> | 42 | #include <qtimer.h> |
41 | #include <qapplication.h> | 43 | #include <qapplication.h> |
42 | #include <qclipboard.h> | 44 | #include <qclipboard.h> |
43 | 45 | ||
44 | //#define QPDFDBG(x) x // special debug mode | 46 | //#define QPDFDBG(x) x // special debug mode |
45 | #define QPDFDBG(x) // normal compilation | 47 | #define QPDFDBG(x) // normal compilation |
46 | 48 | ||
47 | 49 | ||
48 | //------------------------------------------------------------------------ | 50 | //------------------------------------------------------------------------ |
49 | // Constants and macros | 51 | // Constants and macros |
50 | //------------------------------------------------------------------------ | 52 | //------------------------------------------------------------------------ |
51 | 53 | ||
52 | 54 | ||
53 | static inline QColor q_col ( const GfxRGB &rgb ) | 55 | static inline QColor q_col ( const GfxRGB &rgb ) |
54 | { | 56 | { |
55 | return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); | 57 | return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); |
56 | } | 58 | } |
57 | 59 | ||
58 | 60 | ||
59 | //------------------------------------------------------------------------ | 61 | //------------------------------------------------------------------------ |
60 | // Font substitutions | 62 | // Font substitutions |
61 | //------------------------------------------------------------------------ | 63 | //------------------------------------------------------------------------ |
62 | 64 | ||
63 | struct QOutFontSubst { | 65 | struct QOutFontSubst { |
64 | char * m_name; | 66 | char * m_name; |
65 | char * m_sname; | 67 | char * m_sname; |
66 | bool m_bold; | 68 | bool m_bold; |
67 | bool m_italic; | 69 | bool m_italic; |
68 | QFont::StyleHint m_hint; | 70 | QFont::StyleHint m_hint; |
69 | }; | 71 | }; |
70 | 72 | ||
71 | static QOutFontSubst qStdFonts [] = { | 73 | static QOutFontSubst qStdFonts [] = { |
72 | { "Helvetica", "Helvetica", false, false, QFont::Helvetica }, | 74 | { "Helvetica", "Helvetica", false, false, QFont::Helvetica }, |
73 | { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica }, | 75 | { "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica }, |
74 | { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica }, | 76 | { "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica }, |
75 | { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica }, | 77 | { "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica }, |
76 | { "Times-Roman", "Times", false, false, QFont::Times }, | 78 | { "Times-Roman", "Times", false, false, QFont::Times }, |
77 | { "Times-Italic", "Times", false, true, QFont::Times }, | 79 | { "Times-Italic", "Times", false, true, QFont::Times }, |
78 | { "Times-Bold", "Times", true, false, QFont::Times }, | 80 | { "Times-Bold", "Times", true, false, QFont::Times }, |
79 | { "Times-BoldItalic", "Times", true, true, QFont::Times }, | 81 | { "Times-BoldItalic", "Times", true, true, QFont::Times }, |
80 | { "Courier", "Courier", false, false, QFont::Courier }, | 82 | { "Courier", "Courier", false, false, QFont::Courier }, |
81 | { "Courier-Oblique", "Courier", false, true, QFont::Courier }, | 83 | { "Courier-Oblique", "Courier", false, true, QFont::Courier }, |
82 | { "Courier-Bold", "Courier", true, false, QFont::Courier }, | 84 | { "Courier-Bold", "Courier", true, false, QFont::Courier }, |
83 | { "Courier-BoldOblique", "Courier", true, true, QFont::Courier }, | 85 | { "Courier-BoldOblique", "Courier", true, true, QFont::Courier }, |
84 | 86 | ||
85 | { "Symbol", 0, false, false, QFont::AnyStyle }, | 87 | { "Symbol", 0, false, false, QFont::AnyStyle }, |
86 | { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle }, | 88 | { "Zapf-Dingbats", 0, false, false, QFont::AnyStyle }, |
87 | 89 | ||
88 | { 0, 0, false, false, QFont::AnyStyle } | 90 | { 0, 0, false, false, QFont::AnyStyle } |
89 | }; | 91 | }; |
90 | 92 | ||
91 | 93 | ||
92 | 94 | ||
93 | 95 | ||
94 | 96 | ||
95 | 97 | ||
96 | 98 | ||
97 | QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) | 99 | QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) |
98 | { | 100 | { |
99 | static QDict<QOutFontSubst> stdfonts; | 101 | static QDict<QOutFontSubst> stdfonts; |
100 | 102 | ||
101 | // build dict for std. fonts on first invocation | 103 | // build dict for std. fonts on first invocation |
102 | if ( stdfonts. isEmpty ( )) { | 104 | if ( stdfonts. isEmpty ( )) { |
103 | for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { | 105 | for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { |
104 | stdfonts. insert ( QString ( ptr-> m_name ), ptr ); | 106 | stdfonts. insert ( QString ( ptr-> m_name ), ptr ); |
105 | } | 107 | } |
106 | } | 108 | } |
107 | 109 | ||
108 | // compute size and normalized transform matrix | 110 | // compute size and normalized transform matrix |
109 | int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); | 111 | int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); |
110 | 112 | ||
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", | 113 | 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>" ), | 114 | (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ), |
113 | size, | 115 | size, |
114 | gfxFont-> isBold ( ), | 116 | gfxFont-> isBold ( ), |
115 | gfxFont-> isItalic ( ), | 117 | gfxFont-> isItalic ( ), |
116 | gfxFont-> isFixedWidth ( ), | 118 | gfxFont-> isFixedWidth ( ), |
117 | gfxFont-> isSerif ( ), | 119 | gfxFont-> isSerif ( ), |
118 | gfxFont-> isSymbolic ( ), | 120 | gfxFont-> isSymbolic ( ), |
119 | gfxFont-> isCIDFont ( ), | 121 | gfxFont-> isCIDFont ( ), |
120 | ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), | 122 | ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), |
121 | (double) m11, (double) m12, (double) m21, (double) m22 )); | 123 | (double) m11, (double) m12, (double) m21, (double) m22 )); |
122 | 124 | ||
123 | 125 | ||
124 | QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); | 126 | QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); |
125 | 127 | ||
126 | QFont f; | 128 | QFont f; |
127 | f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes | 129 | f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes |
128 | 130 | ||
129 | // fast lookup for std. fonts | 131 | // fast lookup for std. fonts |
130 | QOutFontSubst *subst = stdfonts [fname]; | 132 | QOutFontSubst *subst = stdfonts [fname]; |
131 | 133 | ||
132 | if ( subst ) { | 134 | if ( subst ) { |
133 | if ( subst-> m_sname ) | 135 | if ( subst-> m_sname ) |
134 | f. setFamily ( subst-> m_sname ); | 136 | f. setFamily ( subst-> m_sname ); |
135 | f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); | 137 | f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); |
136 | f. setBold ( subst-> m_bold ); | 138 | f. setBold ( subst-> m_bold ); |
137 | f. setItalic ( subst-> m_italic ); | 139 | f. setItalic ( subst-> m_italic ); |
138 | } | 140 | } |
139 | else { | 141 | else { |
140 | QFont::StyleHint sty; | 142 | QFont::StyleHint sty; |
141 | 143 | ||
142 | if ( gfxFont-> isSerif ( )) | 144 | if ( gfxFont-> isSerif ( )) |
143 | sty = QFont::Serif; | 145 | sty = QFont::Serif; |
144 | else if ( gfxFont-> isFixedWidth ( )) | 146 | else if ( gfxFont-> isFixedWidth ( )) |
145 | sty = QFont::TypeWriter; | 147 | sty = QFont::TypeWriter; |
146 | else | 148 | else |
147 | sty = QFont::Helvetica; | 149 | sty = QFont::Helvetica; |
148 | 150 | ||
149 | f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); | 151 | f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality )); |
150 | f. setBold ( gfxFont-> isBold ( ) > 0 ); | 152 | f. setBold ( gfxFont-> isBold ( ) > 0 ); |
151 | f. setItalic ( gfxFont-> isItalic ( ) > 0 ); | 153 | f. setItalic ( gfxFont-> isItalic ( ) > 0 ); |
152 | f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 ); | 154 | f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 ); |
153 | 155 | ||
154 | // common specifiers in font names | 156 | // common specifiers in font names |
155 | if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" )) | 157 | if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" )) |
156 | f. setItalic ( true ); | 158 | f. setItalic ( true ); |
157 | if ( fname. contains ( "Bold" )) | 159 | if ( fname. contains ( "Bold" )) |
158 | f. setWeight ( QFont::Bold ); | 160 | f. setWeight ( QFont::Bold ); |
159 | if ( fname. contains ( "Demi" )) | 161 | if ( fname. contains ( "Demi" )) |
160 | f. setWeight ( QFont::DemiBold ); | 162 | f. setWeight ( QFont::DemiBold ); |
161 | if ( fname. contains ( "Light" )) | 163 | if ( fname. contains ( "Light" )) |
162 | f. setWeight ( QFont::Light ); | 164 | f. setWeight ( QFont::Light ); |
163 | if ( fname. contains ( "Black" )) | 165 | if ( fname. contains ( "Black" )) |
164 | f. setWeight ( QFont::Black ); | 166 | f. setWeight ( QFont::Black ); |
165 | } | 167 | } |
166 | // Treat x-sheared fonts as italic | 168 | // 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 )))) { | 169 | if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) { |
168 | f. setItalic ( true ); | 170 | f. setItalic ( true ); |
169 | } | 171 | } |
170 | return f; | 172 | return f; |
171 | } | 173 | } |
172 | 174 | ||
173 | 175 | ||
174 | 176 | ||
175 | //------------------------------------------------------------------------ | 177 | //------------------------------------------------------------------------ |
176 | // QOutputDev | 178 | // QOutputDev |
177 | //------------------------------------------------------------------------ | 179 | //------------------------------------------------------------------------ |
178 | 180 | ||
179 | QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) | 181 | QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) |
180 | { | 182 | { |
181 | m_pixmap = 0; | 183 | m_pixmap = 0; |
182 | m_painter = 0; | 184 | m_painter = 0; |
183 | 185 | ||
184 | // create text object | 186 | // create text object |
185 | m_text = new TextPage ( gFalse ); | 187 | m_text = new TextPage ( gFalse ); |
186 | } | 188 | } |
187 | 189 | ||
188 | QOutputDev::~QOutputDev ( ) | 190 | QOutputDev::~QOutputDev ( ) |
189 | { | 191 | { |
190 | delete m_painter; | 192 | delete m_painter; |
191 | delete m_pixmap; | 193 | delete m_pixmap; |
192 | delete m_text; | 194 | delete m_text; |
193 | } | 195 | } |
194 | 196 | ||
195 | 197 | ||
196 | void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) | 198 | void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) |
197 | { | 199 | { |
198 | delete m_pixmap; | 200 | delete m_pixmap; |
199 | delete m_painter; | 201 | delete m_painter; |
200 | 202 | ||
201 | m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); | 203 | m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); |
202 | m_painter = new QPainter ( m_pixmap ); | 204 | m_painter = new QPainter ( m_pixmap ); |
203 | 205 | ||
204 | QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); | 206 | QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); |
205 | 207 | ||
206 | resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); | 208 | resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); |
207 | setContentsPos ( 0, 0 ); | 209 | setContentsPos ( 0, 0 ); |
208 | 210 | ||
209 | m_pixmap-> fill ( white ); // clear window | 211 | m_pixmap-> fill ( white ); // clear window |
210 | m_text-> clear ( ); // cleat text object | 212 | m_text-> clear ( ); // cleat text object |
211 | viewport ( )-> repaint ( ); | 213 | viewport ( )-> repaint ( ); |
212 | } | 214 | } |
213 | 215 | ||
@@ -481,558 +483,558 @@ void QOutputDev::clip ( GfxState *state ) | |||
481 | { | 483 | { |
482 | doClip ( state, true ); | 484 | doClip ( state, true ); |
483 | } | 485 | } |
484 | 486 | ||
485 | void QOutputDev::eoClip ( GfxState *state ) | 487 | void QOutputDev::eoClip ( GfxState *state ) |
486 | { | 488 | { |
487 | doClip ( state, false ); | 489 | doClip ( state, false ); |
488 | } | 490 | } |
489 | 491 | ||
490 | void QOutputDev::doClip ( GfxState *state, bool winding ) | 492 | void QOutputDev::doClip ( GfxState *state, bool winding ) |
491 | { | 493 | { |
492 | QPointArray points; | 494 | QPointArray points; |
493 | QArray<int> lengths; | 495 | QArray<int> lengths; |
494 | 496 | ||
495 | // transform points | 497 | // transform points |
496 | int n = convertPath ( state, points, lengths ); | 498 | int n = convertPath ( state, points, lengths ); |
497 | 499 | ||
498 | QRegion region; | 500 | QRegion region; |
499 | 501 | ||
500 | QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); | 502 | QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); |
501 | 503 | ||
502 | // draw each subpath | 504 | // draw each subpath |
503 | int j = 0; | 505 | int j = 0; |
504 | for ( int i = 0; i < n; i++ ) { | 506 | for ( int i = 0; i < n; i++ ) { |
505 | int len = lengths [i]; | 507 | int len = lengths [i]; |
506 | 508 | ||
507 | if ( len >= 3 ) { | 509 | if ( len >= 3 ) { |
508 | QPointArray dummy; | 510 | QPointArray dummy; |
509 | dummy. setRawData ( points. data ( ) + j, len ); | 511 | dummy. setRawData ( points. data ( ) + j, len ); |
510 | 512 | ||
511 | QPDFDBG( printf ( " - POLY %d: ", i )); | 513 | QPDFDBG( printf ( " - POLY %d: ", i )); |
512 | QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); | 514 | QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); |
513 | QPDFDBG( printf ( "\n" )); | 515 | QPDFDBG( printf ( "\n" )); |
514 | 516 | ||
515 | region |= QRegion ( dummy, winding ); | 517 | region |= QRegion ( dummy, winding ); |
516 | 518 | ||
517 | dummy. resetRawData ( points. data ( ) + j, len ); | 519 | dummy. resetRawData ( points. data ( ) + j, len ); |
518 | } | 520 | } |
519 | j += len; | 521 | j += len; |
520 | } | 522 | } |
521 | 523 | ||
522 | if ( m_painter-> hasClipping ( )) | 524 | if ( m_painter-> hasClipping ( )) |
523 | region &= m_painter-> clipRegion ( ); | 525 | region &= m_painter-> clipRegion ( ); |
524 | 526 | ||
525 | //m_painter-> setClipRegion ( region ); | 527 | //m_painter-> setClipRegion ( region ); |
526 | //m_painter-> setClipping ( true ); | 528 | //m_painter-> setClipping ( true ); |
527 | 529 | ||
528 | //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red ); | 530 | //m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red ); |
529 | //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" ); | 531 | //m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" ); |
530 | qApp-> processEvents ( ); | 532 | qApp-> processEvents ( ); |
531 | } | 533 | } |
532 | 534 | ||
533 | // | 535 | // |
534 | // Transform points in the path and convert curves to line segments. | 536 | // Transform points in the path and convert curves to line segments. |
535 | // Builds a set of subpaths and returns the number of subpaths. | 537 | // Builds a set of subpaths and returns the number of subpaths. |
536 | // If <fillHack> is set, close any unclosed subpaths and activate a | 538 | // If <fillHack> is set, close any unclosed subpaths and activate a |
537 | // kludge for polygon fills: First, it divides up the subpaths into | 539 | // kludge for polygon fills: First, it divides up the subpaths into |
538 | // non-overlapping polygons by simply comparing bounding rectangles. | 540 | // non-overlapping polygons by simply comparing bounding rectangles. |
539 | // Then it connects subaths within a single compound polygon to a single | 541 | // Then it connects subaths within a single compound polygon to a single |
540 | // point so that X can fill the polygon (sort of). | 542 | // point so that X can fill the polygon (sort of). |
541 | // | 543 | // |
542 | int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths ) | 544 | int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths ) |
543 | { | 545 | { |
544 | GfxPath *path = state-> getPath ( ); | 546 | GfxPath *path = state-> getPath ( ); |
545 | int n = path-> getNumSubpaths ( ); | 547 | int n = path-> getNumSubpaths ( ); |
546 | 548 | ||
547 | lengths. resize ( n ); | 549 | lengths. resize ( n ); |
548 | 550 | ||
549 | // do each subpath | 551 | // do each subpath |
550 | for ( int i = 0; i < n; i++ ) { | 552 | for ( int i = 0; i < n; i++ ) { |
551 | // transform the points | 553 | // transform the points |
552 | lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points ); | 554 | lengths [i] = convertSubpath ( state, path-> getSubpath ( i ), points ); |
553 | } | 555 | } |
554 | 556 | ||
555 | return n; | 557 | return n; |
556 | } | 558 | } |
557 | 559 | ||
558 | // | 560 | // |
559 | // Transform points in a single subpath and convert curves to line | 561 | // Transform points in a single subpath and convert curves to line |
560 | // segments. | 562 | // segments. |
561 | // | 563 | // |
562 | int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points ) | 564 | int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArray &points ) |
563 | { | 565 | { |
564 | int oldcnt = points. count ( ); | 566 | int oldcnt = points. count ( ); |
565 | 567 | ||
566 | fp_t x0, y0, x1, y1, x2, y2, x3, y3; | 568 | fp_t x0, y0, x1, y1, x2, y2, x3, y3; |
567 | 569 | ||
568 | int m = subpath-> getNumPoints ( ); | 570 | int m = subpath-> getNumPoints ( ); |
569 | int i = 0; | 571 | int i = 0; |
570 | 572 | ||
571 | while ( i < m ) { | 573 | while ( i < m ) { |
572 | if ( i >= 1 && subpath-> getCurve ( i )) { | 574 | if ( i >= 1 && subpath-> getCurve ( i )) { |
573 | state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 ); | 575 | state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 ); |
574 | state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); | 576 | state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); |
575 | state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 ); | 577 | state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 ); |
576 | state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 ); | 578 | state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 ); |
577 | 579 | ||
578 | QPointArray tmp; | 580 | QPointArray tmp; |
579 | tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ), | 581 | tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ), |
580 | lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 )); | 582 | lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 )); |
581 | 583 | ||
582 | #if QT_VERSION < 300 | 584 | #if QT_VERSION < 300 |
583 | tmp = tmp. quadBezier ( ); | 585 | tmp = tmp. quadBezier ( ); |
584 | 586 | ||
585 | for ( uint loop = 0; loop < tmp. count ( ); loop++ ) { | 587 | for ( uint loop = 0; loop < tmp. count ( ); loop++ ) { |
586 | QPoint p = tmp. point ( loop ); | 588 | QPoint p = tmp. point ( loop ); |
587 | points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( )); | 589 | points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( )); |
588 | } | 590 | } |
589 | #else | 591 | #else |
590 | tmp = tmp. cubicBezier ( ); | 592 | tmp = tmp. cubicBezier ( ); |
591 | points. putPoints ( points. count ( ), tmp. count ( ), tmp ); | 593 | points. putPoints ( points. count ( ), tmp. count ( ), tmp ); |
592 | #endif | 594 | #endif |
593 | 595 | ||
594 | i += 3; | 596 | i += 3; |
595 | } | 597 | } |
596 | else { | 598 | else { |
597 | state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); | 599 | state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); |
598 | 600 | ||
599 | points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 )); | 601 | points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 )); |
600 | ++i; | 602 | ++i; |
601 | } | 603 | } |
602 | } | 604 | } |
603 | return points. count ( ) - oldcnt; | 605 | return points. count ( ) - oldcnt; |
604 | } | 606 | } |
605 | 607 | ||
606 | 608 | ||
607 | void QOutputDev::beginString ( GfxState *state, GString */*s*/ ) | 609 | void QOutputDev::beginString ( GfxState *state, GString */*s*/ ) |
608 | { | 610 | { |
609 | m_text-> beginString ( state ); | 611 | m_text-> beginString ( state ); |
610 | } | 612 | } |
611 | 613 | ||
612 | void QOutputDev::endString ( GfxState */*state*/ ) | 614 | void QOutputDev::endString ( GfxState */*state*/ ) |
613 | { | 615 | { |
614 | m_text-> endString ( ); | 616 | m_text-> endString ( ); |
615 | } | 617 | } |
616 | 618 | ||
617 | void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, | 619 | void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, |
618 | fp_t dx, fp_t dy, fp_t originX, fp_t originY, | 620 | fp_t dx, fp_t dy, fp_t originX, fp_t originY, |
619 | CharCode code, Unicode *u, int uLen ) | 621 | CharCode code, Unicode *u, int uLen ) |
620 | { | 622 | { |
621 | fp_t x1, y1, dx1, dy1; | 623 | fp_t x1, y1, dx1, dy1; |
622 | 624 | ||
623 | if ( uLen > 0 ) | 625 | if ( uLen > 0 ) |
624 | m_text-> addChar ( state, x, y, dx, dy, u, uLen ); | 626 | m_text-> addChar ( state, x, y, dx, dy, u, uLen ); |
625 | 627 | ||
626 | // check for invisible text -- this is used by Acrobat Capture | 628 | // check for invisible text -- this is used by Acrobat Capture |
627 | if (( state-> getRender ( ) & 3 ) == 3 ) { | 629 | if (( state-> getRender ( ) & 3 ) == 3 ) { |
628 | return; | 630 | return; |
629 | } | 631 | } |
630 | 632 | ||
631 | x -= originX; | 633 | x -= originX; |
632 | y -= originY; | 634 | y -= originY; |
633 | state-> transform ( x, y, &x1, &y1 ); | 635 | state-> transform ( x, y, &x1, &y1 ); |
634 | state-> transformDelta ( dx, dy, &dx1, &dy1 ); | 636 | state-> transformDelta ( dx, dy, &dx1, &dy1 ); |
635 | 637 | ||
636 | 638 | ||
637 | if ( uLen > 0 ) { | 639 | if ( uLen > 0 ) { |
638 | QString str; | 640 | QString str; |
639 | QFontMetrics fm = m_painter-> fontMetrics ( ); | 641 | QFontMetrics fm = m_painter-> fontMetrics ( ); |
640 | 642 | ||
641 | for ( int i = 0; i < uLen; i++ ) { | 643 | for ( int i = 0; i < uLen; i++ ) { |
642 | QChar c = QChar ( u [i] ); | 644 | QChar c = QChar ( u [i] ); |
643 | 645 | ||
644 | if ( fm. inFont ( c )) { | 646 | if ( fm. inFont ( c )) { |
645 | str [i] = QChar ( u [i] ); | 647 | str [i] = QChar ( u [i] ); |
646 | } | 648 | } |
647 | else { | 649 | else { |
648 | str [i] = ' '; | 650 | str [i] = ' '; |
649 | QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( ))); | 651 | QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( ))); |
650 | } | 652 | } |
651 | } | 653 | } |
652 | 654 | ||
653 | if (( uLen == 1 ) && ( str [0] == ' ' )) | 655 | if (( uLen == 1 ) && ( str [0] == ' ' )) |
654 | return; | 656 | return; |
655 | 657 | ||
656 | 658 | ||
657 | fp_t m11, m12, m21, m22; | 659 | fp_t m11, m12, m21, m22; |
658 | 660 | ||
659 | state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); | 661 | state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); |
660 | m11 *= state-> getHorizScaling ( ); | 662 | m11 *= state-> getHorizScaling ( ); |
661 | m12 *= state-> getHorizScaling ( ); | 663 | m12 *= state-> getHorizScaling ( ); |
662 | 664 | ||
663 | fp_t fsize = m_painter-> font ( ). pixelSize ( ); | 665 | fp_t fsize = m_painter-> font ( ). pixelSize ( ); |
664 | 666 | ||
665 | #ifndef QT_NO_TRANSFORMATIONS | 667 | #ifndef QT_NO_TRANSFORMATIONS |
666 | QWMatrix oldmat; | 668 | QWMatrix oldmat; |
667 | 669 | ||
668 | bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 )); | 670 | bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 )); |
669 | 671 | ||
670 | if ( dorot ) { | 672 | if ( dorot ) { |
671 | oldmat = m_painter-> worldMatrix ( ); | 673 | oldmat = m_painter-> worldMatrix ( ); |
672 | 674 | ||
673 | cerr << endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl; | 675 | std::cerr << std::endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl; |
674 | 676 | ||
675 | QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 )); | 677 | QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 )); |
676 | 678 | ||
677 | m_painter-> setWorldMatrix ( mat ); | 679 | m_painter-> setWorldMatrix ( mat ); |
678 | 680 | ||
679 | x1 = 0; | 681 | x1 = 0; |
680 | y1 = 0; | 682 | y1 = 0; |
681 | } | 683 | } |
682 | #endif | 684 | #endif |
683 | 685 | ||
684 | QPen oldpen = m_painter-> pen ( ); | 686 | QPen oldpen = m_painter-> pen ( ); |
685 | 687 | ||
686 | if (!( state-> getRender ( ) & 1 )) { | 688 | if (!( state-> getRender ( ) & 1 )) { |
687 | QPen fillpen = oldpen; | 689 | QPen fillpen = oldpen; |
688 | 690 | ||
689 | fillpen. setColor ( m_painter-> brush ( ). color ( )); | 691 | fillpen. setColor ( m_painter-> brush ( ). color ( )); |
690 | m_painter-> setPen ( fillpen ); | 692 | m_painter-> setPen ( fillpen ); |
691 | } | 693 | } |
692 | 694 | ||
693 | if ( fsize > 5 ) | 695 | if ( fsize > 5 ) |
694 | m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str ); | 696 | m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str ); |
695 | else | 697 | else |
696 | m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( )); | 698 | m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( )); |
697 | 699 | ||
698 | m_painter-> setPen ( oldpen ); | 700 | m_painter-> setPen ( oldpen ); |
699 | 701 | ||
700 | #ifndef QT_NO_TRANSFORMATIONS | 702 | #ifndef QT_NO_TRANSFORMATIONS |
701 | if ( dorot ) | 703 | if ( dorot ) |
702 | m_painter-> setWorldMatrix ( oldmat ); | 704 | m_painter-> setWorldMatrix ( oldmat ); |
703 | #endif | 705 | #endif |
704 | 706 | ||
705 | QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 ))); | 707 | QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 ))); |
706 | } | 708 | } |
707 | else if ( code != 0 ) { | 709 | else if ( code != 0 ) { |
708 | // some PDF files use CID 0, which is .notdef, so just ignore it | 710 | // some PDF files use CID 0, which is .notdef, so just ignore it |
709 | qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 )); | 711 | qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 )); |
710 | } | 712 | } |
711 | qApp-> processEvents ( ); | 713 | qApp-> processEvents ( ); |
712 | } | 714 | } |
713 | 715 | ||
714 | 716 | ||
715 | 717 | ||
716 | void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg ) | 718 | void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg ) |
717 | { | 719 | { |
718 | // get CTM, check for singular matrix | 720 | // get CTM, check for singular matrix |
719 | fp_t *ctm = state-> getCTM ( ); | 721 | fp_t *ctm = state-> getCTM ( ); |
720 | 722 | ||
721 | if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { | 723 | if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { |
722 | qWarning ( "Singular CTM in drawImage\n" ); | 724 | qWarning ( "Singular CTM in drawImage\n" ); |
723 | 725 | ||
724 | if ( inlineImg ) { | 726 | if ( inlineImg ) { |
725 | str-> reset ( ); | 727 | str-> reset ( ); |
726 | int j = height * (( width + 7 ) / 8 ); | 728 | int j = height * (( width + 7 ) / 8 ); |
727 | for ( int i = 0; i < j; i++ ) | 729 | for ( int i = 0; i < j; i++ ) |
728 | str->getChar(); | 730 | str->getChar(); |
729 | 731 | ||
730 | str->close(); | 732 | str->close(); |
731 | } | 733 | } |
732 | return; | 734 | return; |
733 | } | 735 | } |
734 | 736 | ||
735 | GfxRGB rgb; | 737 | GfxRGB rgb; |
736 | state-> getFillRGB ( &rgb ); | 738 | state-> getFillRGB ( &rgb ); |
737 | uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); | 739 | uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); |
738 | 740 | ||
739 | 741 | ||
740 | QImage img ( width, height, 32 ); | 742 | QImage img ( width, height, 32 ); |
741 | img. setAlphaBuffer ( true ); | 743 | img. setAlphaBuffer ( true ); |
742 | 744 | ||
743 | QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height )); | 745 | QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height )); |
744 | 746 | ||
745 | // initialize the image stream | 747 | // initialize the image stream |
746 | ImageStream *imgStr = new ImageStream ( str, width, 1, 1 ); | 748 | ImageStream *imgStr = new ImageStream ( str, width, 1, 1 ); |
747 | imgStr-> reset ( ); | 749 | imgStr-> reset ( ); |
748 | 750 | ||
749 | uchar **scanlines = img. jumpTable ( ); | 751 | uchar **scanlines = img. jumpTable ( ); |
750 | 752 | ||
751 | if ( ctm [3] > 0 ) | 753 | if ( ctm [3] > 0 ) |
752 | scanlines += ( height - 1 ); | 754 | scanlines += ( height - 1 ); |
753 | 755 | ||
754 | for ( int y = 0; y < height; y++ ) { | 756 | for ( int y = 0; y < height; y++ ) { |
755 | QRgb *scanline = (QRgb *) *scanlines; | 757 | QRgb *scanline = (QRgb *) *scanlines; |
756 | 758 | ||
757 | if ( ctm [0] < 0 ) | 759 | if ( ctm [0] < 0 ) |
758 | scanline += ( width - 1 ); | 760 | scanline += ( width - 1 ); |
759 | 761 | ||
760 | for ( int x = 0; x < width; x++ ) { | 762 | for ( int x = 0; x < width; x++ ) { |
761 | Guchar alpha; | 763 | Guchar alpha; |
762 | 764 | ||
763 | imgStr-> getPixel ( &alpha ); | 765 | imgStr-> getPixel ( &alpha ); |
764 | 766 | ||
765 | if ( invert ) | 767 | if ( invert ) |
766 | alpha ^= 1; | 768 | alpha ^= 1; |
767 | 769 | ||
768 | *scanline = ( alpha == 0 ) ? 0xff000000 | val : val; | 770 | *scanline = ( alpha == 0 ) ? 0xff000000 | val : val; |
769 | 771 | ||
770 | ctm [0] < 0 ? scanline-- : scanline++; | 772 | ctm [0] < 0 ? scanline-- : scanline++; |
771 | } | 773 | } |
772 | ctm [3] > 0 ? scanlines-- : scanlines++; | 774 | ctm [3] > 0 ? scanlines-- : scanlines++; |
773 | 775 | ||
774 | qApp-> processEvents ( ); | 776 | qApp-> processEvents ( ); |
775 | } | 777 | } |
776 | 778 | ||
777 | #ifndef QT_NO_TRANSFORMATIONS | 779 | #ifndef QT_NO_TRANSFORMATIONS |
778 | QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); | 780 | QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); |
779 | 781 | ||
780 | cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << endl | 782 | std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl |
781 | << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << endl; | 783 | << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl; |
782 | 784 | ||
783 | QWMatrix oldmat = m_painter-> worldMatrix ( ); | 785 | QWMatrix oldmat = m_painter-> worldMatrix ( ); |
784 | m_painter-> setWorldMatrix ( mat, true ); | 786 | m_painter-> setWorldMatrix ( mat, true ); |
785 | 787 | ||
786 | #ifdef QWS | 788 | #ifdef QWS |
787 | QPixmap pm; | 789 | QPixmap pm; |
788 | pm. convertFromImage ( img ); | 790 | pm. convertFromImage ( img ); |
789 | m_painter-> drawPixmap ( 0, 0, pm ); | 791 | m_painter-> drawPixmap ( 0, 0, pm ); |
790 | #else | 792 | #else |
791 | m_painter-> drawImage ( QPoint ( 0, 0 ), img ); | 793 | m_painter-> drawImage ( QPoint ( 0, 0 ), img ); |
792 | #endif | 794 | #endif |
793 | 795 | ||
794 | m_painter-> setWorldMatrix ( oldmat ); | 796 | m_painter-> setWorldMatrix ( oldmat ); |
795 | 797 | ||
796 | #else | 798 | #else |
797 | if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { | 799 | if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { |
798 | QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); | 800 | QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); |
799 | } | 801 | } |
800 | else { | 802 | else { |
801 | int x = lrint ( ctm [4] ); | 803 | int x = lrint ( ctm [4] ); |
802 | int y = lrint ( ctm [5] ); | 804 | int y = lrint ( ctm [5] ); |
803 | 805 | ||
804 | int w = lrint ( ctm [0] ); | 806 | int w = lrint ( ctm [0] ); |
805 | int h = lrint ( ctm [3] ); | 807 | int h = lrint ( ctm [3] ); |
806 | 808 | ||
807 | if ( w < 0 ) { | 809 | if ( w < 0 ) { |
808 | x += w; | 810 | x += w; |
809 | w = -w; | 811 | w = -w; |
810 | } | 812 | } |
811 | if ( h < 0 ) { | 813 | if ( h < 0 ) { |
812 | y += h; | 814 | y += h; |
813 | h = -h; | 815 | h = -h; |
814 | } | 816 | } |
815 | 817 | ||
816 | QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h )); | 818 | QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h )); |
817 | 819 | ||
818 | img = img. smoothScale ( w, h ); | 820 | img = img. smoothScale ( w, h ); |
819 | qApp-> processEvents ( ); | 821 | qApp-> processEvents ( ); |
820 | m_painter-> drawImage ( x, y, img ); | 822 | m_painter-> drawImage ( x, y, img ); |
821 | } | 823 | } |
822 | 824 | ||
823 | #endif | 825 | #endif |
824 | 826 | ||
825 | delete imgStr; | 827 | delete imgStr; |
826 | qApp-> processEvents ( ); | 828 | qApp-> processEvents ( ); |
827 | } | 829 | } |
828 | 830 | ||
829 | 831 | ||
830 | void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg ) | 832 | void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg ) |
831 | { | 833 | { |
832 | int nComps, nVals, nBits; | 834 | int nComps, nVals, nBits; |
833 | 835 | ||
834 | // image parameters | 836 | // image parameters |
835 | nComps = colorMap->getNumPixelComps ( ); | 837 | nComps = colorMap->getNumPixelComps ( ); |
836 | nVals = width * nComps; | 838 | nVals = width * nComps; |
837 | nBits = colorMap-> getBits ( ); | 839 | nBits = colorMap-> getBits ( ); |
838 | 840 | ||
839 | // get CTM, check for singular matrix | 841 | // get CTM, check for singular matrix |
840 | fp_t *ctm = state-> getCTM ( ); | 842 | fp_t *ctm = state-> getCTM ( ); |
841 | 843 | ||
842 | if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { | 844 | if ( fabs ( ctm [0] * ctm [3] - ctm [1] * ctm [2] ) < 0.000001 ) { |
843 | qWarning ( "Singular CTM in drawImage\n" ); | 845 | qWarning ( "Singular CTM in drawImage\n" ); |
844 | 846 | ||
845 | if ( inlineImg ) { | 847 | if ( inlineImg ) { |
846 | str-> reset ( ); | 848 | str-> reset ( ); |
847 | int j = height * (( nVals * nBits + 7 ) / 8 ); | 849 | int j = height * (( nVals * nBits + 7 ) / 8 ); |
848 | for ( int i = 0; i < j; i++ ) | 850 | for ( int i = 0; i < j; i++ ) |
849 | str->getChar(); | 851 | str->getChar(); |
850 | 852 | ||
851 | str->close(); | 853 | str->close(); |
852 | } | 854 | } |
853 | return; | 855 | return; |
854 | } | 856 | } |
855 | 857 | ||
856 | QImage img ( width, height, 32 ); | 858 | QImage img ( width, height, 32 ); |
857 | 859 | ||
858 | if ( maskColors ) | 860 | if ( maskColors ) |
859 | img. setAlphaBuffer ( true ); | 861 | img. setAlphaBuffer ( true ); |
860 | 862 | ||
861 | QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height )); | 863 | QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height )); |
862 | 864 | ||
863 | // initialize the image stream | 865 | // initialize the image stream |
864 | ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits ); | 866 | ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits ); |
865 | imgStr-> reset ( ); | 867 | imgStr-> reset ( ); |
866 | 868 | ||
867 | Guchar pixBuf [gfxColorMaxComps]; | 869 | Guchar pixBuf [gfxColorMaxComps]; |
868 | GfxRGB rgb; | 870 | GfxRGB rgb; |
869 | 871 | ||
870 | 872 | ||
871 | uchar **scanlines = img. jumpTable ( ); | 873 | uchar **scanlines = img. jumpTable ( ); |
872 | 874 | ||
873 | if ( ctm [3] > 0 ) | 875 | if ( ctm [3] > 0 ) |
874 | scanlines += ( height - 1 ); | 876 | scanlines += ( height - 1 ); |
875 | 877 | ||
876 | for ( int y = 0; y < height; y++ ) { | 878 | for ( int y = 0; y < height; y++ ) { |
877 | QRgb *scanline = (QRgb *) *scanlines; | 879 | QRgb *scanline = (QRgb *) *scanlines; |
878 | 880 | ||
879 | if ( ctm [0] < 0 ) | 881 | if ( ctm [0] < 0 ) |
880 | scanline += ( width - 1 ); | 882 | scanline += ( width - 1 ); |
881 | 883 | ||
882 | for ( int x = 0; x < width; x++ ) { | 884 | for ( int x = 0; x < width; x++ ) { |
883 | imgStr-> getPixel ( pixBuf ); | 885 | imgStr-> getPixel ( pixBuf ); |
884 | colorMap-> getRGB ( pixBuf, &rgb ); | 886 | colorMap-> getRGB ( pixBuf, &rgb ); |
885 | 887 | ||
886 | uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); | 888 | uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); |
887 | 889 | ||
888 | if ( maskColors ) { | 890 | if ( maskColors ) { |
889 | for ( int k = 0; k < nComps; ++k ) { | 891 | for ( int k = 0; k < nComps; ++k ) { |
890 | if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) { | 892 | if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) { |
891 | val |= 0xff000000; | 893 | val |= 0xff000000; |
892 | break; | 894 | break; |
893 | } | 895 | } |
894 | } | 896 | } |
895 | } | 897 | } |
896 | *scanline = val; | 898 | *scanline = val; |
897 | 899 | ||
898 | ctm [0] < 0 ? scanline-- : scanline++; | 900 | ctm [0] < 0 ? scanline-- : scanline++; |
899 | } | 901 | } |
900 | ctm [3] > 0 ? scanlines-- : scanlines++; | 902 | ctm [3] > 0 ? scanlines-- : scanlines++; |
901 | 903 | ||
902 | qApp-> processEvents ( ); | 904 | qApp-> processEvents ( ); |
903 | } | 905 | } |
904 | 906 | ||
905 | 907 | ||
906 | #ifndef QT_NO_TRANSFORMATIONS | 908 | #ifndef QT_NO_TRANSFORMATIONS |
907 | QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); | 909 | QWMatrix mat ( ctm [0] / width, ctm [1], ctm [2], ctm [3] / height, ctm [4], ctm [5] ); |
908 | 910 | ||
909 | cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << endl | 911 | std::cerr << "MATRIX T=" << mat. dx ( ) << "/" << mat. dy ( ) << std::endl |
910 | << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << endl; | 912 | << " - M=" << mat. m11 ( ) << "/" << mat. m12 ( ) << "/" << mat. m21 ( ) << "/" << mat. m22 ( ) << std::endl; |
911 | 913 | ||
912 | QWMatrix oldmat = m_painter-> worldMatrix ( ); | 914 | QWMatrix oldmat = m_painter-> worldMatrix ( ); |
913 | m_painter-> setWorldMatrix ( mat, true ); | 915 | m_painter-> setWorldMatrix ( mat, true ); |
914 | 916 | ||
915 | #ifdef QWS | 917 | #ifdef QWS |
916 | QPixmap pm; | 918 | QPixmap pm; |
917 | pm. convertFromImage ( img ); | 919 | pm. convertFromImage ( img ); |
918 | m_painter-> drawPixmap ( 0, 0, pm ); | 920 | m_painter-> drawPixmap ( 0, 0, pm ); |
919 | #else | 921 | #else |
920 | m_painter-> drawImage ( QPoint ( 0, 0 ), img ); | 922 | m_painter-> drawImage ( QPoint ( 0, 0 ), img ); |
921 | #endif | 923 | #endif |
922 | 924 | ||
923 | m_painter-> setWorldMatrix ( oldmat ); | 925 | m_painter-> setWorldMatrix ( oldmat ); |
924 | 926 | ||
925 | #else // QT_NO_TRANSFORMATIONS | 927 | #else // QT_NO_TRANSFORMATIONS |
926 | 928 | ||
927 | if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { | 929 | if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { |
928 | QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); | 930 | QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); |
929 | } | 931 | } |
930 | else { | 932 | else { |
931 | int x = lrint ( ctm [4] ); | 933 | int x = lrint ( ctm [4] ); |
932 | int y = lrint ( ctm [5] ); | 934 | int y = lrint ( ctm [5] ); |
933 | 935 | ||
934 | int w = lrint ( ctm [0] ); | 936 | int w = lrint ( ctm [0] ); |
935 | int h = lrint ( ctm [3] ); | 937 | int h = lrint ( ctm [3] ); |
936 | 938 | ||
937 | if ( w < 0 ) { | 939 | if ( w < 0 ) { |
938 | x += w; | 940 | x += w; |
939 | w = -w; | 941 | w = -w; |
940 | } | 942 | } |
941 | if ( h < 0 ) { | 943 | if ( h < 0 ) { |
942 | y += h; | 944 | y += h; |
943 | h = -h; | 945 | h = -h; |
944 | } | 946 | } |
945 | 947 | ||
946 | QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h )); | 948 | QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h )); |
947 | 949 | ||
948 | img = img. smoothScale ( w, h ); | 950 | img = img. smoothScale ( w, h ); |
949 | qApp-> processEvents ( ); | 951 | qApp-> processEvents ( ); |
950 | m_painter-> drawImage ( x, y, img ); | 952 | m_painter-> drawImage ( x, y, img ); |
951 | } | 953 | } |
952 | 954 | ||
953 | #endif | 955 | #endif |
954 | 956 | ||
955 | 957 | ||
956 | delete imgStr; | 958 | delete imgStr; |
957 | qApp-> processEvents ( ); | 959 | qApp-> processEvents ( ); |
958 | } | 960 | } |
959 | 961 | ||
960 | 962 | ||
961 | 963 | ||
962 | bool QOutputDev::findText ( const QString &str, QRect &r, bool top, bool bottom ) | 964 | bool QOutputDev::findText ( const QString &str, QRect &r, bool top, bool bottom ) |
963 | { | 965 | { |
964 | int l, t, w, h; | 966 | int l, t, w, h; |
965 | r. rect ( &l, &t, &w, &h ); | 967 | r. rect ( &l, &t, &w, &h ); |
966 | 968 | ||
967 | bool res = findText ( str, l, t, w, h, top, bottom ); | 969 | bool res = findText ( str, l, t, w, h, top, bottom ); |
968 | 970 | ||
969 | r. setRect ( l, t, w, h ); | 971 | r. setRect ( l, t, w, h ); |
970 | return res; | 972 | return res; |
971 | } | 973 | } |
972 | 974 | ||
973 | bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, bool top, bool bottom ) | 975 | bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, bool top, bool bottom ) |
974 | { | 976 | { |
975 | bool found = false; | 977 | bool found = false; |
976 | uint len = str. length ( ); | 978 | uint len = str. length ( ); |
977 | Unicode *s = new Unicode [len]; | 979 | Unicode *s = new Unicode [len]; |
978 | 980 | ||
979 | for ( uint i = 0; i < len; i++ ) | 981 | for ( uint i = 0; i < len; i++ ) |
980 | s [i] = str [i]. unicode ( ); | 982 | s [i] = str [i]. unicode ( ); |
981 | 983 | ||
982 | fp_t x1 = (fp_t) l; | 984 | fp_t x1 = (fp_t) l; |
983 | fp_t y1 = (fp_t) t; | 985 | fp_t y1 = (fp_t) t; |
984 | fp_t x2 = (fp_t) l + w - 1; | 986 | fp_t x2 = (fp_t) l + w - 1; |
985 | fp_t y2 = (fp_t) t + h - 1; | 987 | fp_t y2 = (fp_t) t + h - 1; |
986 | 988 | ||
987 | if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) { | 989 | if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) { |
988 | l = lrint ( x1 ); | 990 | l = lrint ( x1 ); |
989 | t = lrint ( y1 ); | 991 | t = lrint ( y1 ); |
990 | w = lrint ( x2 ) - l + 1; | 992 | w = lrint ( x2 ) - l + 1; |
991 | h = lrint ( y2 ) - t + 1; | 993 | h = lrint ( y2 ) - t + 1; |
992 | found = true; | 994 | found = true; |
993 | } | 995 | } |
994 | delete [] s; | 996 | delete [] s; |
995 | 997 | ||
996 | return found; | 998 | return found; |
997 | } | 999 | } |
998 | 1000 | ||
999 | GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax ) | 1001 | GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax ) |
1000 | { | 1002 | { |
1001 | bool found = false; | 1003 | bool found = false; |
1002 | fp_t xMin1 = (double) *xMin; | 1004 | fp_t xMin1 = (double) *xMin; |
1003 | fp_t yMin1 = (double) *yMin; | 1005 | fp_t yMin1 = (double) *yMin; |
1004 | fp_t xMax1 = (double) *xMax; | 1006 | fp_t xMax1 = (double) *xMax; |
1005 | fp_t yMax1 = (double) *yMax; | 1007 | fp_t yMax1 = (double) *yMax; |
1006 | 1008 | ||
1007 | if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) { | 1009 | if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) { |
1008 | *xMin = lrint ( xMin1 ); | 1010 | *xMin = lrint ( xMin1 ); |
1009 | *xMax = lrint ( xMax1 ); | 1011 | *xMax = lrint ( xMax1 ); |
1010 | *yMin = lrint ( yMin1 ); | 1012 | *yMin = lrint ( yMin1 ); |
1011 | *yMax = lrint ( yMax1 ); | 1013 | *yMax = lrint ( yMax1 ); |
1012 | found = true; | 1014 | found = true; |
1013 | } | 1015 | } |
1014 | return found; | 1016 | return found; |
1015 | } | 1017 | } |
1016 | 1018 | ||
1017 | QString QOutputDev::getText ( int l, int t, int w, int h ) | 1019 | QString QOutputDev::getText ( int l, int t, int w, int h ) |
1018 | { | 1020 | { |
1019 | GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 ); | 1021 | GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 ); |
1020 | QString str = gstr-> getCString ( ); | 1022 | QString str = gstr-> getCString ( ); |
1021 | delete gstr; | 1023 | delete gstr; |
1022 | return str; | 1024 | return str; |
1023 | } | 1025 | } |
1024 | 1026 | ||
1025 | QString QOutputDev::getText ( const QRect &r ) | 1027 | QString QOutputDev::getText ( const QRect &r ) |
1026 | { | 1028 | { |
1027 | return getText ( r. left ( ), r. top ( ), r. width ( ), r. height ( )); | 1029 | return getText ( r. left ( ), r. top ( ), r. width ( ), r. height ( )); |
1028 | } | 1030 | } |
1029 | 1031 | ||
1030 | 1032 | ||
1031 | 1033 | ||
1032 | void QOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph ) | 1034 | void QOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph ) |
1033 | { | 1035 | { |
1034 | if ( m_pixmap ) | 1036 | if ( m_pixmap ) |
1035 | p-> drawPixmap ( clipx, clipy, *m_pixmap, clipx, clipy, clipw, cliph ); | 1037 | p-> drawPixmap ( clipx, clipy, *m_pixmap, clipx, clipy, clipw, cliph ); |
1036 | else | 1038 | else |
1037 | p-> fillRect ( clipx, clipy, clipw, cliph, white ); | 1039 | p-> fillRect ( clipx, clipy, clipw, cliph, white ); |
1038 | } | 1040 | } |