1 /* GNUPLOT - qt_conversion.cpp */
2
3 /*[
4 * Copyright 2009 Jérôme Lodewyck
5 *
6 * Permission to use, copy, and distribute this software and its
7 * documentation for any purpose with or without fee is hereby granted,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation.
11 *
12 * Permission to modify the software is granted, but not the right to
13 * distribute the complete modified source code. Modifications are to
14 * be distributed as patches to the released version. Permission to
15 * distribute binaries produced by compiling modified sources is granted,
16 * provided you
17 * 1. distribute the corresponding source modifications from the
18 * released version in the form of a patch file along with the binaries,
19 * 2. add special version identification to distinguish your version
20 * in addition to the base release version number,
21 * 3. provide your name and address as the primary contact for the
22 * support of your modified version, and
23 * 4. retain our contact information in regard to use of the base
24 * software.
25 * Permission to distribute the released version of the source code along
26 * with corresponding source modifications in the form of a patch file is
27 * granted with same provisions 2 through 4 for binary distributions.
28 *
29 * This software is provided "as is" without express or implied warranty
30 * to the extent permitted by applicable law.
31 *
32 *
33 * Alternatively, the contents of this file may be used under the terms of the
34 * GNU General Public License Version 2 or later (the "GPL"), in which case the
35 * provisions of GPL are applicable instead of those above. If you wish to allow
36 * use of your version of this file only under the terms of the GPL and not
37 * to allow others to use your version of this file under the above gnuplot
38 * license, indicate your decision by deleting the provisions above and replace
39 * them with the notice and other provisions required by the GPL. If you do not
40 * delete the provisions above, a recipient may use your version of this file
41 * under either the GPL or the gnuplot license.
42 ]*/
43
44 static QColor qt_colorList[12] =
45 {
46 Qt::white,
47 Qt::black,
48 Qt::gray,
49 Qt::red,
50 Qt::green,
51 Qt::blue,
52 Qt::magenta,
53 Qt::cyan,
54 Qt::yellow,
55 Qt::black,
56 QColor(255, 76, 0), // Orange
57 Qt::gray
58 };
59
qt_encodingToCodec(set_encoding_id encoding)60 QTextCodec* qt_encodingToCodec(set_encoding_id encoding)
61 {
62 switch (encoding)
63 {
64 case S_ENC_DEFAULT : return QTextCodec::codecForLocale();
65 case S_ENC_ISO8859_1 : return QTextCodec::codecForMib( 4);
66 case S_ENC_ISO8859_2 : return QTextCodec::codecForMib( 5);
67 case S_ENC_ISO8859_9 : return QTextCodec::codecForMib( 12);
68 case S_ENC_ISO8859_15 : return QTextCodec::codecForMib( 111);
69 case S_ENC_CP437 : return QTextCodec::codecForMib(2011);
70 case S_ENC_CP850 : return QTextCodec::codecForMib(2009);
71 case S_ENC_CP852 : return QTextCodec::codecForMib(2010);
72 case S_ENC_CP950 : return QTextCodec::codecForMib(2026); // Note: CP950 has no IANA number. 2026 is for Big5, which is close to CP950
73 case S_ENC_CP1250 : return QTextCodec::codecForMib(2250);
74 case S_ENC_CP1251 : return QTextCodec::codecForMib(2251);
75 case S_ENC_CP1252 : return QTextCodec::codecForMib(2252);
76 case S_ENC_CP1254 : return QTextCodec::codecForMib(2254);
77 case S_ENC_KOI8_R : return QTextCodec::codecForMib(2084);
78 case S_ENC_KOI8_U : return QTextCodec::codecForMib(2088);
79 case S_ENC_SJIS : return QTextCodec::codecForMib( 17);
80 case S_ENC_UTF8 : return QTextCodec::codecForMib( 106);
81 default : return QTextCodec::codecForLocale();
82 }
83 }
84
qt_imageToQImage(int M,int N,coordval * image,t_imagecolor color_mode)85 QImage qt_imageToQImage(int M, int N, coordval* image, t_imagecolor color_mode)
86 {
87 QImage qimage(QSize(M, N), QImage::Format_ARGB32_Premultiplied);
88
89 rgb_color rgb1;
90 rgb255_color rgb255;
91
92 // TrueColor 24-bit color mode
93 if (color_mode == IC_RGB)
94 for (int n = 0; n < N; n++)
95 {
96 QRgb* line = (QRgb*)(qimage.scanLine(n));
97 for (int m = 0; m < M; m++)
98 {
99 rgb1.r = *image++;
100 rgb1.g = *image++;
101 rgb1.b = *image++;
102 rgb255_from_rgb1(rgb1, &rgb255);
103 *line++ = qRgb(rgb255.r, rgb255.g, rgb255.b);
104 }
105 }
106 else if (color_mode == IC_RGBA)
107 for (int n = 0; n < N; n++)
108 {
109 QRgb* line = (QRgb*)(qimage.scanLine(n));
110 for (int m = 0; m < M; m++)
111 {
112 unsigned char alpha255 = *(image + 3);
113 float alpha1 = float(alpha255 / 255.);
114 rgb1.r = alpha1 * (*image++);
115 rgb1.g = alpha1 * (*image++);
116 rgb1.b = alpha1 * (*image++);
117 image++;
118 rgb255_from_rgb1(rgb1, &rgb255);
119 *line++ = qRgba(rgb255.r, rgb255.g, rgb255.b, alpha255);
120 }
121 }
122 // Palette color lookup from gray value
123 else
124 for (int n = 0; n < N; n++)
125 {
126 QRgb* line = (QRgb*)(qimage.scanLine(n));
127 for (int m = 0; m < M; m++)
128 {
129 if (*image != *image)
130 {
131 image++;
132 *line++ = 0x00000000;
133 }
134 else
135 {
136 rgb255maxcolors_from_gray(*image++, &rgb255);
137 *line++ = qRgb(rgb255.r, rgb255.g, rgb255.b);
138 }
139 }
140 }
141
142 return qimage;
143 }
144
145 // Generated from http://unicode.org/Public/MAPPINGS/VENDORS/ADOBE/symbol.txt
qt_symbolToUnicode(int c)146 QChar qt_symbolToUnicode(int c)
147 {
148 switch (c)
149 {
150 case 0x22: return QChar(0x2200); // FOR ALL // universal
151 case 0x24: return QChar(0x2203); // THERE EXISTS // existential
152 case 0x27: return QChar(0x220B); // CONTAINS AS MEMBER // suchthat
153 case 0x2A: return QChar(0x2217); // ASTERISK OPERATOR // asteriskmath
154 case 0x2D: return QChar(0x2212); // MINUS SIGN // minus
155 case 0x40: return QChar(0x2245); // APPROXIMATELY EQUAL TO // congruent
156 case 0x41: return QChar(0x0391); // GREEK CAPITAL LETTER ALPHA // Alpha
157 case 0x42: return QChar(0x0392); // GREEK CAPITAL LETTER BETA // Beta
158 case 0x43: return QChar(0x03A7); // GREEK CAPITAL LETTER CHI // Chi
159 case 0x44: return QChar(0x0394); // GREEK CAPITAL LETTER DELTA // Delta
160 case 0x45: return QChar(0x0395); // GREEK CAPITAL LETTER EPSILON // Epsilon
161 case 0x46: return QChar(0x03A6); // GREEK CAPITAL LETTER PHI // Phi
162 case 0x47: return QChar(0x0393); // GREEK CAPITAL LETTER GAMMA // Gamma
163 case 0x48: return QChar(0x0397); // GREEK CAPITAL LETTER ETA // Eta
164 case 0x49: return QChar(0x0399); // GREEK CAPITAL LETTER IOTA // Iota
165 case 0x4A: return QChar(0x03D1); // GREEK THETA SYMBOL // theta1
166 case 0x4B: return QChar(0x039A); // GREEK CAPITAL LETTER KAPPA // Kappa
167 case 0x4C: return QChar(0x039B); // GREEK CAPITAL LETTER LAMDA // Lambda
168 case 0x4D: return QChar(0x039C); // GREEK CAPITAL LETTER MU // Mu
169 case 0x4E: return QChar(0x039D); // GREEK CAPITAL LETTER NU // Nu
170 case 0x4F: return QChar(0x039F); // GREEK CAPITAL LETTER OMICRON // Omicron
171 case 0x50: return QChar(0x03A0); // GREEK CAPITAL LETTER PI // Pi
172 case 0x51: return QChar(0x0398); // GREEK CAPITAL LETTER THETA // Theta
173 case 0x52: return QChar(0x03A1); // GREEK CAPITAL LETTER RHO // Rho
174 case 0x53: return QChar(0x03A3); // GREEK CAPITAL LETTER SIGMA // Sigma
175 case 0x54: return QChar(0x03A4); // GREEK CAPITAL LETTER TAU // Tau
176 case 0x55: return QChar(0x03A5); // GREEK CAPITAL LETTER UPSILON // Upsilon
177 case 0x56: return QChar(0x03C2); // GREEK SMALL LETTER FINAL SIGMA // sigma1
178 case 0x57: return QChar(0x03A9); // GREEK CAPITAL LETTER OMEGA // Omega
179 case 0x58: return QChar(0x039E); // GREEK CAPITAL LETTER XI // Xi
180 case 0x59: return QChar(0x03A8); // GREEK CAPITAL LETTER PSI // Psi
181 case 0x5A: return QChar(0x0396); // GREEK CAPITAL LETTER ZETA // Zeta
182 case 0x5C: return QChar(0x2234); // THEREFORE // therefore
183 case 0x5E: return QChar(0x22A5); // UP TACK // perpendicular
184 case 0x60: return QChar(0xF8E5); // RADICAL EXTENDER // radicalex (CUS)
185 case 0x61: return QChar(0x03B1); // GREEK SMALL LETTER ALPHA // alpha
186 case 0x62: return QChar(0x03B2); // GREEK SMALL LETTER BETA // beta
187 case 0x63: return QChar(0x03C7); // GREEK SMALL LETTER CHI // chi
188 case 0x64: return QChar(0x03B4); // GREEK SMALL LETTER DELTA // delta
189 case 0x65: return QChar(0x03B5); // GREEK SMALL LETTER EPSILON // epsilon
190 case 0x66: return QChar(0x03C6); // GREEK SMALL LETTER PHI // phi
191 case 0x67: return QChar(0x03B3); // GREEK SMALL LETTER GAMMA // gamma
192 case 0x68: return QChar(0x03B7); // GREEK SMALL LETTER ETA // eta
193 case 0x69: return QChar(0x03B9); // GREEK SMALL LETTER IOTA // iota
194 case 0x6A: return QChar(0x03D5); // GREEK PHI SYMBOL // phi1
195 case 0x6B: return QChar(0x03BA); // GREEK SMALL LETTER KAPPA // kappa
196 case 0x6C: return QChar(0x03BB); // GREEK SMALL LETTER LAMDA // lambda
197 case 0x6D: return QChar(0x03BC); // GREEK SMALL LETTER MU // mu
198 case 0x6E: return QChar(0x03BD); // GREEK SMALL LETTER NU // nu
199 case 0x6F: return QChar(0x03BF); // GREEK SMALL LETTER OMICRON // omicron
200 case 0x70: return QChar(0x03C0); // GREEK SMALL LETTER PI // pi
201 case 0x71: return QChar(0x03B8); // GREEK SMALL LETTER THETA // theta
202 case 0x72: return QChar(0x03C1); // GREEK SMALL LETTER RHO // rho
203 case 0x73: return QChar(0x03C3); // GREEK SMALL LETTER SIGMA // sigma
204 case 0x74: return QChar(0x03C4); // GREEK SMALL LETTER TAU // tau
205 case 0x75: return QChar(0x03C5); // GREEK SMALL LETTER UPSILON // upsilon
206 case 0x76: return QChar(0x03D6); // GREEK PI SYMBOL // omega1
207 case 0x77: return QChar(0x03C9); // GREEK SMALL LETTER OMEGA // omega
208 case 0x78: return QChar(0x03BE); // GREEK SMALL LETTER XI // xi
209 case 0x79: return QChar(0x03C8); // GREEK SMALL LETTER PSI // psi
210 case 0x7A: return QChar(0x03B6); // GREEK SMALL LETTER ZETA // zeta
211 case 0x7E: return QChar(0x223C); // TILDE OPERATOR // similar
212 case 0xA0: return QChar(0x20AC); // EURO SIGN // Euro
213 case 0xA1: return QChar(0x03D2); // GREEK UPSILON WITH HOOK SYMBOL // Upsilon1
214 case 0xA2: return QChar(0x2032); // PRIME // minute
215 case 0xA3: return QChar(0x2264); // LESS-THAN OR EQUAL TO // lessequal
216 case 0xA4: return QChar(0x2044); // FRACTION SLASH // fraction
217 case 0xA5: return QChar(0x221E); // INFINITY // infinity
218 case 0xA6: return QChar(0x0192); // LATIN SMALL LETTER F WITH HOOK // florin
219 case 0xA7: return QChar(0x2663); // BLACK CLUB SUIT // club
220 case 0xA8: return QChar(0x2666); // BLACK DIAMOND SUIT // diamond
221 case 0xA9: return QChar(0x2665); // BLACK HEART SUIT // heart
222 case 0xAA: return QChar(0x2660); // BLACK SPADE SUIT // spade
223 case 0xAB: return QChar(0x2194); // LEFT RIGHT ARROW // arrowboth
224 case 0xAC: return QChar(0x2190); // LEFTWARDS ARROW // arrowleft
225 case 0xAD: return QChar(0x2191); // UPWARDS ARROW // arrowup
226 case 0xAE: return QChar(0x2192); // RIGHTWARDS ARROW // arrowright
227 case 0xAF: return QChar(0x2193); // DOWNWARDS ARROW // arrowdown
228 case 0xB2: return QChar(0x2033); // DOUBLE PRIME // second
229 case 0xB3: return QChar(0x2265); // GREATER-THAN OR EQUAL TO // greaterequal
230 case 0xB4: return QChar(0x00D7); // MULTIPLICATION SIGN // multiply
231 case 0xB5: return QChar(0x221D); // PROPORTIONAL TO // proportional
232 case 0xB6: return QChar(0x2202); // PARTIAL DIFFERENTIAL // partialdiff
233 case 0xB7: return QChar(0x2022); // BULLET // bullet
234 case 0xB8: return QChar(0x00F7); // DIVISION SIGN // divide
235 case 0xB9: return QChar(0x2260); // NOT EQUAL TO // notequal
236 case 0xBA: return QChar(0x2261); // IDENTICAL TO // equivalence
237 case 0xBB: return QChar(0x2248); // ALMOST EQUAL TO // approxequal
238 case 0xBC: return QChar(0x2026); // HORIZONTAL ELLIPSIS // ellipsis
239 case 0xBD: return QChar(0xF8E6); // VERTICAL ARROW EXTENDER // arrowvertex (CUS)
240 case 0xBE: return QChar(0xF8E7); // HORIZONTAL ARROW EXTENDER // arrowhorizex (CUS)
241 case 0xBF: return QChar(0x21B5); // DOWNWARDS ARROW WITH CORNER LEFTWARDS // carriagereturn
242 case 0xC0: return QChar(0x2135); // ALEF SYMBOL // aleph
243 case 0xC1: return QChar(0x2111); // BLACK-LETTER CAPITAL I // Ifraktur
244 case 0xC2: return QChar(0x211C); // BLACK-LETTER CAPITAL R // Rfraktur
245 case 0xC3: return QChar(0x2118); // SCRIPT CAPITAL P // weierstrass
246 case 0xC4: return QChar(0x2297); // CIRCLED TIMES // circlemultiply
247 case 0xC5: return QChar(0x2295); // CIRCLED PLUS // circleplus
248 case 0xC6: return QChar(0x2205); // EMPTY SET // emptyset
249 case 0xC7: return QChar(0x2229); // INTERSECTION // intersection
250 case 0xC8: return QChar(0x222A); // UNION // union
251 case 0xC9: return QChar(0x2283); // SUPERSET OF // propersuperset
252 case 0xCA: return QChar(0x2287); // SUPERSET OF OR EQUAL TO // reflexsuperset
253 case 0xCB: return QChar(0x2284); // NOT A SUBSET OF // notsubset
254 case 0xCC: return QChar(0x2282); // SUBSET OF // propersubset
255 case 0xCD: return QChar(0x2286); // SUBSET OF OR EQUAL TO // reflexsubset
256 case 0xCE: return QChar(0x2208); // ELEMENT OF // element
257 case 0xCF: return QChar(0x2209); // NOT AN ELEMENT OF // notelement
258 case 0xD0: return QChar(0x2220); // ANGLE // angle
259 case 0xD1: return QChar(0x2207); // NABLA // gradient
260 case 0xD2: return QChar(0xF6DA); // REGISTERED SIGN SERIF // registerserif (CUS)
261 case 0xD3: return QChar(0xF6D9); // COPYRIGHT SIGN SERIF // copyrightserif (CUS)
262 case 0xD4: return QChar(0xF6DB); // TRADE MARK SIGN SERIF // trademarkserif (CUS)
263 case 0xD5: return QChar(0x220F); // N-ARY PRODUCT // product
264 case 0xD6: return QChar(0x221A); // SQUARE ROOT // radical
265 case 0xD7: return QChar(0x22C5); // DOT OPERATOR // dotmath
266 case 0xD8: return QChar(0x00AC); // NOT SIGN // logicalnot
267 case 0xD9: return QChar(0x2227); // LOGICAL AND // logicaland
268 case 0xDA: return QChar(0x2228); // LOGICAL OR // logicalor
269 case 0xDB: return QChar(0x21D4); // LEFT RIGHT DOUBLE ARROW // arrowdblboth
270 case 0xDC: return QChar(0x21D0); // LEFTWARDS DOUBLE ARROW // arrowdblleft
271 case 0xDD: return QChar(0x21D1); // UPWARDS DOUBLE ARROW // arrowdblup
272 case 0xDE: return QChar(0x21D2); // RIGHTWARDS DOUBLE ARROW // arrowdblright
273 case 0xDF: return QChar(0x21D3); // DOWNWARDS DOUBLE ARROW // arrowdbldown
274 case 0xE0: return QChar(0x25CA); // LOZENGE // lozenge
275 case 0xE1: return QChar(0x2329); // LEFT-POINTING ANGLE BRACKET // angleleft
276 case 0xE2: return QChar(0xF8E8); // REGISTERED SIGN SANS SERIF // registersans (CUS)
277 case 0xE3: return QChar(0xF8E9); // COPYRIGHT SIGN SANS SERIF // copyrightsans (CUS)
278 case 0xE4: return QChar(0xF8EA); // TRADE MARK SIGN SANS SERIF // trademarksans (CUS)
279 case 0xE5: return QChar(0x2211); // N-ARY SUMMATION // summation
280 case 0xE6: return QChar(0xF8EB); // LEFT PAREN TOP // parenlefttp (CUS)
281 case 0xE7: return QChar(0xF8EC); // LEFT PAREN EXTENDER // parenleftex (CUS)
282 case 0xE8: return QChar(0xF8ED); // LEFT PAREN BOTTOM // parenleftbt (CUS)
283 case 0xE9: return QChar(0xF8EE); // LEFT SQUARE BRACKET TOP // bracketlefttp (CUS)
284 case 0xEA: return QChar(0xF8EF); // LEFT SQUARE BRACKET EXTENDER // bracketleftex (CUS)
285 case 0xEB: return QChar(0xF8F0); // LEFT SQUARE BRACKET BOTTOM // bracketleftbt (CUS)
286 case 0xEC: return QChar(0xF8F1); // LEFT CURLY BRACKET TOP // bracelefttp (CUS)
287 case 0xED: return QChar(0xF8F2); // LEFT CURLY BRACKET MID // braceleftmid (CUS)
288 case 0xEE: return QChar(0xF8F3); // LEFT CURLY BRACKET BOTTOM // braceleftbt (CUS)
289 case 0xEF: return QChar(0xF8F4); // CURLY BRACKET EXTENDER // braceex (CUS)
290 case 0xF1: return QChar(0x232A); // RIGHT-POINTING ANGLE BRACKET // angleright
291 case 0xF2: return QChar(0x222B); // INTEGRAL // integral
292 case 0xF3: return QChar(0x2320); // TOP HALF INTEGRAL // integraltp
293 case 0xF4: return QChar(0xF8F5); // INTEGRAL EXTENDER // integralex (CUS)
294 case 0xF5: return QChar(0x2321); // BOTTOM HALF INTEGRAL // integralbt
295 case 0xF6: return QChar(0xF8F6); // RIGHT PAREN TOP // parenrighttp (CUS)
296 case 0xF7: return QChar(0xF8F7); // RIGHT PAREN EXTENDER // parenrightex (CUS)
297 case 0xF8: return QChar(0xF8F8); // RIGHT PAREN BOTTOM // parenrightbt (CUS)
298 case 0xF9: return QChar(0xF8F9); // RIGHT SQUARE BRACKET TOP // bracketrighttp (CUS)
299 case 0xFA: return QChar(0xF8FA); // RIGHT SQUARE BRACKET EXTENDER // bracketrightex (CUS)
300 case 0xFB: return QChar(0xF8FB); // RIGHT SQUARE BRACKET BOTTOM // bracketrightbt (CUS)
301 case 0xFC: return QChar(0xF8FC); // RIGHT CURLY BRACKET TOP // bracerighttp (CUS)
302 case 0xFD: return QChar(0xF8FD); // RIGHT CURLY BRACKET MID // bracerightmid (CUS)
303 case 0xFE: return QChar(0xF8FE); // RIGHT CURLY BRACKET BOTTOM // bracerightbt (CUS)
304 default : return QChar(c);
305 }
306 }
307