Rev 16941 | Rev 20606 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
364 | Franz | 7 | /*************************************************************************** |
8 | * Copyright (C) 2004 by Riku Leino * |
||
1184 | tsoots | 9 | * tsoots@gmail.com * |
364 | Franz | 10 | * * |
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 * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | * This program is distributed in the hope that it will be useful, * |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
19 | * GNU General Public License for more details. * |
||
20 | * * |
||
21 | * You should have received a copy of the GNU General Public License * |
||
22 | * along with this program; if not, write to the * |
||
23 | * Free Software Foundation, Inc., * |
||
18122 | mrdocs | 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
364 | Franz | 25 | ***************************************************************************/ |
26 | |||
27 | #include "gtfont.h" |
||
28 | |||
29 | const QString gtFont::fontWeights[FontWeightMAX] = |
||
30 | { |
||
31 | "", |
||
32 | "Demi Bold", |
||
33 | "Extra Black", |
||
34 | "Extra Bold", |
||
35 | "Extra Heavy", |
||
36 | "Extra Light", |
||
37 | "Semi Bold", |
||
38 | "Black", |
||
39 | "Bold", |
||
40 | "Book", |
||
41 | "Demi", |
||
42 | "Heavy", |
||
43 | "Light", |
||
759 | cbradney | 44 | "Lite", |
364 | Franz | 45 | "Medium", |
379 | Franz | 46 | "Regular", |
47 | "Roman" |
||
364 | Franz | 48 | }; |
49 | |||
50 | const QString gtFont::fontSlants[FontSlantMAX] = |
||
51 | { |
||
52 | "", |
||
53 | "Italic", |
||
54 | "Oblique" |
||
55 | }; |
||
56 | |||
57 | const QString gtFont::fontWidths[FontWidthMAX] = |
||
58 | { |
||
59 | "", |
||
60 | "Extra Condensed", |
||
61 | "Semi Condensed", |
||
62 | "Ultra Condensed", |
||
387 | Franz | 63 | "Extra Compressed", |
64 | "Semi Compressed", |
||
65 | "Ultra Compressed", |
||
66 | "Condensed", |
||
67 | "Compressed" |
||
364 | Franz | 68 | }; |
69 | |||
70 | gtFont::gtFont() |
||
71 | { |
||
12895 | jghali | 72 | setflags = 0; |
364 | Franz | 73 | noEffects(); |
74 | name = ""; |
||
75 | family = ""; |
||
76 | weight = ""; |
||
77 | slant = ""; |
||
78 | width = ""; |
||
387 | Franz | 79 | append = ""; |
16941 | jghali | 80 | size = 120; |
364 | Franz | 81 | color = "Black"; |
82 | shade = 100; |
||
83 | strokeColor = "Black"; |
||
84 | strokeShade = 100; |
||
2501 | fschmid | 85 | hscale = 1000; |
86 | kerning = 0; |
||
387 | Franz | 87 | useFullName = true; |
88 | weightIndex = 0; |
||
89 | slantIndex = 1; |
||
90 | widthIndex = 2; |
||
403 | Franz | 91 | smallestIndex = -1; |
92 | biggestIndex = - 1; |
||
93 | index = -1; |
||
94 | tmpWeightIndex = -1; |
||
95 | tmpSlantIndex = -1; |
||
96 | tmpWidthIndex = -1; |
||
364 | Franz | 97 | } |
98 | |||
99 | gtFont::gtFont(const gtFont& f) |
||
100 | { |
||
101 | name = f.name; |
||
102 | family = f.family; |
||
103 | weight = f.weight; |
||
104 | slant = f.slant; |
||
105 | width = f.width; |
||
387 | Franz | 106 | append = f.append; |
364 | Franz | 107 | size = f.size; |
108 | color = f.color; |
||
109 | shade = f.shade; |
||
110 | strokeColor = f.strokeColor; |
||
111 | strokeShade = f.strokeShade; |
||
112 | hscale = f.hscale; |
||
113 | kerning = f.kerning; |
||
387 | Franz | 114 | useFullName = f.useFullName; |
115 | weightIndex = f.weightIndex; |
||
116 | slantIndex = f.slantIndex; |
||
117 | widthIndex = f.widthIndex; |
||
9416 | jghali | 118 | smallestIndex = f.smallestIndex; |
119 | biggestIndex = f.biggestIndex; |
||
120 | index = f.index; |
||
121 | tmpWeightIndex = f.tmpWeightIndex; |
||
122 | tmpSlantIndex = f.tmpSlantIndex; |
||
123 | tmpWidthIndex = f.tmpWidthIndex; |
||
364 | Franz | 124 | fontEffects[NORMAL] = f.fontEffects[NORMAL]; |
125 | fontEffects[UNDERLINE] = f.fontEffects[UNDERLINE]; |
||
126 | fontEffects[STRIKETHROUGH] = f.fontEffects[STRIKETHROUGH]; |
||
127 | fontEffects[SMALL_CAPS] = f.fontEffects[SMALL_CAPS]; |
||
128 | fontEffects[SUPERSCRIPT] = f.fontEffects[SUPERSCRIPT]; |
||
129 | fontEffects[SUBSCRIPT] = f.fontEffects[SUBSCRIPT]; |
||
130 | fontEffects[OUTLINE] = f.fontEffects[OUTLINE]; |
||
12895 | jghali | 131 | setflags = f.setflags; |
364 | Franz | 132 | } |
133 | |||
12895 | jghali | 134 | int gtFont::getFlags() |
135 | { |
||
136 | return setflags; |
||
137 | } |
||
138 | |||
364 | Franz | 139 | bool gtFont::isToggled(FontEffect fe) |
140 | { |
||
141 | return fontEffects[fe]; |
||
142 | } |
||
143 | |||
144 | bool gtFont::toggleEffect(FontEffect fe) |
||
145 | { |
||
146 | switch (fe) |
||
147 | { |
||
148 | case NORMAL: |
||
149 | if (!fontEffects[NORMAL]) |
||
150 | noEffects(); |
||
151 | break; |
||
152 | case SUPERSCRIPT: |
||
153 | fontEffects[SUPERSCRIPT] = !fontEffects[SUPERSCRIPT]; |
||
154 | if (fontEffects[SUPERSCRIPT]) |
||
155 | { |
||
156 | fontEffects[SUBSCRIPT] = false; |
||
157 | fontEffects[NORMAL] = false; |
||
158 | } |
||
159 | break; |
||
160 | case SUBSCRIPT: |
||
161 | fontEffects[SUBSCRIPT] = !fontEffects[SUBSCRIPT]; |
||
162 | if (fontEffects[SUBSCRIPT]) |
||
163 | { |
||
164 | fontEffects[SUPERSCRIPT] = false; |
||
165 | fontEffects[NORMAL] = false; |
||
166 | } |
||
167 | break; |
||
168 | default: |
||
169 | fontEffects[fe] = !fontEffects[fe]; |
||
170 | if (fontEffects[fe]) |
||
171 | fontEffects[NORMAL] = false; |
||
172 | } |
||
12895 | jghali | 173 | setflags |= effectWasSet; |
364 | Franz | 174 | return fontEffects[fe]; |
175 | } |
||
176 | |||
177 | int gtFont::getEffectsValue() |
||
178 | { |
||
179 | int b = 0; |
||
180 | if (isToggled(NORMAL)) |
||
181 | b = 0; |
||
182 | if (isToggled(UNDERLINE)) |
||
183 | b |= 8; |
||
184 | if (isToggled(STRIKETHROUGH)) |
||
185 | b |= 16; |
||
186 | if (isToggled(SMALL_CAPS)) |
||
187 | b |= 64; |
||
188 | if (isToggled(SUPERSCRIPT)) |
||
189 | b |= 1; |
||
190 | if (isToggled(SUBSCRIPT)) |
||
191 | b |= 2; |
||
192 | if (isToggled(OUTLINE)) |
||
193 | b |= 4; |
||
194 | return b; |
||
195 | } |
||
196 | |||
197 | void gtFont::setName(QString newName) |
||
198 | { |
||
199 | name = newName; |
||
375 | Franz | 200 | setWeight(NO_WEIGHT); |
201 | setSlant(NO_SLANT); |
||
202 | setWidth(NO_WIDTH); |
||
364 | Franz | 203 | parseName(); |
387 | Franz | 204 | useFullName = true; |
12895 | jghali | 205 | setflags |= familyWasSet; |
364 | Franz | 206 | } |
207 | |||
208 | void gtFont::setFamily(QString newFamily) |
||
209 | { |
||
210 | family = newFamily; |
||
387 | Franz | 211 | useFullName = false; |
12895 | jghali | 212 | setflags |= familyWasSet; |
364 | Franz | 213 | } |
214 | |||
387 | Franz | 215 | QString gtFont::getFamily() |
216 | { |
||
217 | return family; |
||
218 | } |
||
219 | |||
364 | Franz | 220 | void gtFont::setWeight(FontWeight newWeight) |
221 | { |
||
222 | weight = fontWeights[newWeight]; |
||
387 | Franz | 223 | useFullName = false; |
12895 | jghali | 224 | setflags |= weightWasSet; |
387 | Franz | 225 | if ((newWeight == ROMAN) || (newWeight == REGULAR)) |
226 | { |
||
227 | setSlant(NO_SLANT); |
||
228 | setWidth(NO_WIDTH); |
||
12895 | jghali | 229 | setflags &= ~weightWasSet; |
387 | Franz | 230 | } |
1577 | tsoots | 231 | if (weightIndex < 0) |
232 | { |
||
233 | weightIndex = 0; |
||
234 | slantIndex = 1; |
||
235 | widthIndex = 2; |
||
236 | } |
||
364 | Franz | 237 | } |
238 | |||
387 | Franz | 239 | void gtFont::setWeight(QString newWeight) |
364 | Franz | 240 | { |
387 | Franz | 241 | weight = newWeight; |
242 | useFullName = false; |
||
12895 | jghali | 243 | setflags |= weightWasSet; |
1577 | tsoots | 244 | if ((newWeight == fontWeights[ROMAN]) || |
245 | (newWeight == fontWeights[REGULAR])) |
||
387 | Franz | 246 | { |
247 | setSlant(NO_SLANT); |
||
248 | setWidth(NO_WIDTH); |
||
14550 | jghali | 249 | setflags &= ~weightWasSet; |
387 | Franz | 250 | } |
1577 | tsoots | 251 | if (weightIndex < 0) |
252 | { |
||
253 | weightIndex = 0; |
||
254 | slantIndex = 1; |
||
255 | widthIndex = 2; |
||
256 | } |
||
364 | Franz | 257 | } |
258 | |||
387 | Franz | 259 | QString gtFont::getWeight() |
364 | Franz | 260 | { |
387 | Franz | 261 | return weight; |
364 | Franz | 262 | } |
263 | |||
387 | Franz | 264 | void gtFont::setSlant(FontSlant newSlant) |
364 | Franz | 265 | { |
387 | Franz | 266 | slant = fontSlants[newSlant]; |
267 | useFullName = false; |
||
12895 | jghali | 268 | setflags &= ~slantWasSet; |
387 | Franz | 269 | if (newSlant != NO_SLANT) |
270 | { |
||
271 | if (weight == fontWeights[REGULAR]) |
||
272 | setWeight(NO_WEIGHT); |
||
273 | else if (weight == fontWeights[ROMAN]) |
||
274 | setWeight(NO_WEIGHT); |
||
12895 | jghali | 275 | setflags |= slantWasSet; |
387 | Franz | 276 | } |
1577 | tsoots | 277 | if (slantIndex < 0) |
278 | { |
||
279 | weightIndex = 0; |
||
280 | slantIndex = 1; |
||
281 | widthIndex = 2; |
||
282 | } |
||
364 | Franz | 283 | } |
284 | |||
285 | void gtFont::setSlant(QString newSlant) |
||
286 | { |
||
287 | slant = newSlant; |
||
387 | Franz | 288 | useFullName = false; |
12895 | jghali | 289 | setflags &= ~slantWasSet; |
2877 | cbradney | 290 | if (!newSlant.isEmpty()) |
387 | Franz | 291 | { |
292 | if (weight == fontWeights[REGULAR]) |
||
293 | setWeight(NO_WEIGHT); |
||
294 | else if (weight == fontWeights[ROMAN]) |
||
295 | setWeight(NO_WEIGHT); |
||
12895 | jghali | 296 | setflags |= slantWasSet; |
387 | Franz | 297 | } |
1577 | tsoots | 298 | if (slantIndex < 0) |
299 | { |
||
300 | weightIndex = 0; |
||
301 | slantIndex = 1; |
||
302 | widthIndex = 2; |
||
303 | } |
||
364 | Franz | 304 | } |
305 | |||
387 | Franz | 306 | QString gtFont::getSlant() |
307 | { |
||
308 | return slant; |
||
309 | } |
||
310 | |||
311 | void gtFont::setWidth(FontWidth newWidth) |
||
312 | { |
||
313 | width = fontWidths[newWidth]; |
||
314 | useFullName = false; |
||
12895 | jghali | 315 | setflags &= ~widthWasSet; |
387 | Franz | 316 | if (newWidth != NO_WIDTH) |
317 | { |
||
318 | if (weight == fontWeights[REGULAR]) |
||
319 | setWeight(NO_WEIGHT); |
||
320 | else if (weight == fontWeights[ROMAN]) |
||
321 | setWeight(NO_WEIGHT); |
||
12895 | jghali | 322 | setflags |= widthWasSet; |
387 | Franz | 323 | } |
1577 | tsoots | 324 | if (widthIndex < 0) |
325 | { |
||
326 | weightIndex = 0; |
||
327 | slantIndex = 1; |
||
328 | widthIndex = 2; |
||
329 | } |
||
387 | Franz | 330 | } |
331 | |||
364 | Franz | 332 | void gtFont::setWidth(QString newWidth) |
333 | { |
||
334 | width = newWidth; |
||
387 | Franz | 335 | useFullName = false; |
12895 | jghali | 336 | setflags &= ~widthWasSet; |
2877 | cbradney | 337 | if (!newWidth.isEmpty()) |
387 | Franz | 338 | { |
339 | if (weight == fontWeights[REGULAR]) |
||
340 | setWeight(NO_WEIGHT); |
||
341 | else if (weight == fontWeights[ROMAN]) |
||
342 | setWeight(NO_WEIGHT); |
||
12895 | jghali | 343 | setflags |= widthWasSet; |
387 | Franz | 344 | } |
1577 | tsoots | 345 | if (widthIndex < 0) |
346 | { |
||
347 | weightIndex = 0; |
||
348 | slantIndex = 1; |
||
349 | widthIndex = 2; |
||
350 | } |
||
364 | Franz | 351 | } |
352 | |||
387 | Franz | 353 | QString gtFont::getWidth() |
354 | { |
||
355 | return width; |
||
356 | } |
||
357 | |||
364 | Franz | 358 | void gtFont::setSize(int newSize) |
359 | { |
||
360 | size = newSize; |
||
12895 | jghali | 361 | setflags |= sizeWasSet; |
364 | Franz | 362 | } |
363 | |||
364 | void gtFont::setSize(double newSize) |
||
365 | { |
||
10024 | jghali | 366 | size = static_cast<int>(newSize); |
12895 | jghali | 367 | setflags |= sizeWasSet; |
364 | Franz | 368 | } |
369 | |||
370 | void gtFont::setColor(QString newColor) |
||
371 | { |
||
372 | color = newColor; |
||
12895 | jghali | 373 | setflags |= fillColorWasSet; |
364 | Franz | 374 | } |
375 | |||
376 | void gtFont::setShade(int newShade) |
||
377 | { |
||
378 | shade = newShade; |
||
12895 | jghali | 379 | setflags |= fillShadeWasSet; |
364 | Franz | 380 | } |
381 | |||
382 | void gtFont::setStrokeColor(QString newColor) |
||
383 | { |
||
384 | strokeColor = newColor; |
||
12895 | jghali | 385 | setflags |= strokeColorWasSet; |
364 | Franz | 386 | } |
387 | |||
388 | void gtFont::setStrokeShade(int newShade) |
||
389 | { |
||
390 | strokeShade = newShade; |
||
12895 | jghali | 391 | setflags |= strokeShadeWasSet; |
364 | Franz | 392 | } |
393 | |||
394 | QString gtFont::getName() |
||
395 | { |
||
387 | Franz | 396 | if (useFullName) |
397 | return name; |
||
398 | |||
399 | QString name2 = family + " "; |
||
1577 | tsoots | 400 | |
387 | Franz | 401 | if (weightIndex == 0) |
402 | name2 += weight + " "; |
||
403 | else if (slantIndex == 0) |
||
404 | name2 += slant + " "; |
||
405 | else if (widthIndex == 0) |
||
406 | name2 += width + " "; |
||
1577 | tsoots | 407 | |
387 | Franz | 408 | if (weightIndex == 1) |
409 | name2 += weight + " "; |
||
410 | else if (slantIndex == 1) |
||
411 | name2 += slant + " "; |
||
412 | else if (widthIndex == 1) |
||
413 | name2 += width + " "; |
||
1577 | tsoots | 414 | |
387 | Franz | 415 | if (weightIndex == 2) |
416 | name2 += weight + " "; |
||
417 | else if (slantIndex == 2) |
||
418 | name2 += slant + " "; |
||
419 | else if (widthIndex == 2) |
||
420 | name2 += width + " "; |
||
1577 | tsoots | 421 | |
387 | Franz | 422 | name2 += append; |
10394 | cbradney | 423 | name2 = name2.simplified(); |
364 | Franz | 424 | return name2; |
387 | Franz | 425 | } |
364 | Franz | 426 | |
387 | Franz | 427 | QString gtFont::getName(uint i) |
428 | { |
||
429 | QString fname = family + " "; |
||
430 | switch (i) |
||
431 | { |
||
432 | case 0: |
||
433 | fname = fname + weight + " " + slant + " " + width + " " + append; |
||
434 | break; |
||
435 | case 1: |
||
436 | fname = fname + weight + " " + width + " " + slant + " " + append; |
||
437 | break; |
||
438 | case 2: |
||
439 | fname = fname + slant + " " + weight + " " + width + " " + append; |
||
440 | break; |
||
441 | case 3: |
||
442 | fname = fname + slant + " " + width + " " + weight + " " + append; |
||
443 | break; |
||
444 | case 4: |
||
445 | fname = fname + width + " " + weight + " " + slant + " " + append; |
||
446 | break; |
||
447 | case 5: |
||
448 | fname = fname + width + " " + slant + " " + weight + " " + append; |
||
449 | break; |
||
450 | case 6: |
||
451 | fname = fname + " " + append + " " + weight + " " + slant + " " + width; |
||
452 | break; |
||
453 | case 7: |
||
454 | fname = fname + " " + append + " " + weight + " " + width + " " + slant; |
||
455 | break; |
||
456 | case 8: |
||
457 | fname = fname + " " + append + " " + slant + " " + weight + " " + width; |
||
458 | break; |
||
459 | case 9: |
||
460 | fname = fname + " " + append + " " + slant + " " + width + " " + weight; |
||
461 | break; |
||
462 | case 10: |
||
463 | fname = fname + " " + append + " " + width + " " + weight + " " + slant; |
||
464 | break; |
||
465 | case 11: |
||
466 | fname = fname + " " + append + " " + width + " " + slant + " " + weight; |
||
467 | break; |
||
468 | case 12: |
||
2877 | cbradney | 469 | if ((append.isEmpty()) && (weight.isEmpty()) && (slant.isEmpty()) && (width.isEmpty())) |
387 | Franz | 470 | fname = fname + " " + fontWeights[REGULAR]; |
471 | break; |
||
472 | case 13: |
||
2877 | cbradney | 473 | if ((append.isEmpty()) && (weight.isEmpty()) && (slant.isEmpty()) && (width.isEmpty())) |
387 | Franz | 474 | fname = fname + " " + fontWeights[ROMAN]; |
475 | break; |
||
476 | } |
||
10394 | cbradney | 477 | fname = fname.simplified(); |
387 | Franz | 478 | return fname; |
364 | Franz | 479 | } |
480 | |||
481 | int gtFont::getSize() |
||
482 | { |
||
483 | return size; |
||
484 | } |
||
485 | |||
486 | QString gtFont::getColor() |
||
487 | { |
||
488 | return color; |
||
489 | } |
||
490 | |||
491 | int gtFont::getShade() |
||
492 | { |
||
493 | return shade; |
||
494 | } |
||
495 | |||
496 | QString gtFont::getStrokeColor() |
||
497 | { |
||
498 | return strokeColor; |
||
499 | } |
||
500 | |||
501 | int gtFont::getStrokeShade() |
||
502 | { |
||
503 | return strokeShade; |
||
504 | } |
||
505 | |||
506 | void gtFont::noEffects() |
||
507 | { |
||
508 | fontEffects[NORMAL] = true; |
||
509 | fontEffects[UNDERLINE] = false; |
||
510 | fontEffects[STRIKETHROUGH] = false; |
||
511 | fontEffects[SMALL_CAPS] = false; |
||
512 | fontEffects[SUPERSCRIPT] = false; |
||
513 | fontEffects[SUBSCRIPT] = false; |
||
514 | fontEffects[OUTLINE] = false; |
||
12895 | jghali | 515 | setflags &= ~effectWasSet; |
364 | Franz | 516 | } |
517 | |||
518 | int gtFont::getHscale() |
||
519 | { |
||
520 | return hscale; |
||
521 | } |
||
522 | |||
12895 | jghali | 523 | void gtFont::setHscale(int newHscale) |
364 | Franz | 524 | { |
525 | hscale = newHscale; |
||
12895 | jghali | 526 | setflags |= hscaleWasSet; |
364 | Franz | 527 | } |
528 | |||
2501 | fschmid | 529 | int gtFont::getKerning() |
364 | Franz | 530 | { |
531 | return kerning; |
||
532 | } |
||
533 | |||
2501 | fschmid | 534 | void gtFont::setKerning(int newKerning) |
364 | Franz | 535 | { |
536 | kerning = newKerning; |
||
12895 | jghali | 537 | setflags |= kerningWasSet; |
364 | Franz | 538 | } |
539 | |||
540 | void gtFont::parseName() |
||
541 | { |
||
403 | Franz | 542 | smallestIndex = -1; |
543 | biggestIndex = - 1; |
||
544 | index = -1; |
||
545 | tmpWeightIndex = -1; |
||
546 | tmpSlantIndex = -1; |
||
547 | tmpWidthIndex = -1; |
||
548 | parseWeight(); |
||
549 | parseSlant(); |
||
550 | parseWidth(); |
||
551 | parseFamily(); |
||
552 | } |
||
553 | |||
554 | void gtFont::parseWeight() |
||
555 | { |
||
364 | Franz | 556 | bool found = false; |
557 | for (int i = 1; i < FontWeightMAX; ++i) |
||
558 | { |
||
10398 | cbradney | 559 | index = name.indexOf(fontWeights[i]); // f.e. Demi Bold |
364 | Franz | 560 | QString tmpWeight = ""; |
10398 | cbradney | 561 | if ((index == -1) && (fontWeights[i].indexOf(" ") != -1) && (fontWeights[i].indexOf(" ") != 1)) |
364 | Franz | 562 | { |
563 | QString fw2 = fontWeights[i]; |
||
564 | fw2.replace(" ", "-"); // f.e. Demi-Bold |
||
10398 | cbradney | 565 | index = name.indexOf(fw2); |
364 | Franz | 566 | if (index == -1) |
567 | { |
||
568 | fw2 = fontWeights[i]; |
||
569 | fw2.replace(" ", ""); // f.e. DemiBold |
||
10398 | cbradney | 570 | index = name.indexOf(fw2); |
364 | Franz | 571 | if (index == -1) |
572 | { |
||
573 | fw2 = fontWeights[i]; |
||
574 | fw2.replace(" B", " b"); // f.e. Demibold |
||
575 | fw2.replace(" C", " c"); |
||
576 | fw2.replace(" H", " h"); |
||
577 | fw2.replace(" L", " l"); |
||
578 | fw2.replace(" ", ""); |
||
10398 | cbradney | 579 | index = name.indexOf(fw2); |
364 | Franz | 580 | if (index != -1) |
581 | tmpWeight = fw2; |
||
582 | } |
||
583 | else |
||
584 | tmpWeight = fw2; |
||
585 | } |
||
586 | else |
||
587 | { |
||
588 | tmpWeight = fw2; |
||
589 | } |
||
590 | } |
||
591 | else |
||
592 | tmpWeight = fontWeights[i]; |
||
593 | if (index != -1) |
||
594 | { |
||
595 | weight = tmpWeight; |
||
596 | if (smallestIndex == -1 || smallestIndex > index) |
||
597 | smallestIndex = index; |
||
387 | Franz | 598 | if ((biggestIndex == -1) || (biggestIndex < index + static_cast<int>(tmpWeight.length()) - 1)) |
599 | biggestIndex = index + tmpWeight.length(); |
||
364 | Franz | 600 | found = true; |
387 | Franz | 601 | tmpWeightIndex = index; |
364 | Franz | 602 | break; |
603 | } |
||
604 | } |
||
605 | if (!found) |
||
606 | weight = fontWeights[NO_WEIGHT]; |
||
403 | Franz | 607 | } |
364 | Franz | 608 | |
403 | Franz | 609 | void gtFont::parseSlant() |
610 | { |
||
611 | bool found = false; |
||
364 | Franz | 612 | for (int i = 1; i < FontSlantMAX; ++i) |
613 | { |
||
10398 | cbradney | 614 | index = name.indexOf(fontSlants[i]); |
364 | Franz | 615 | if (index != -1) |
616 | { |
||
617 | slant = fontSlants[i]; |
||
618 | if (smallestIndex == -1 || smallestIndex > index) |
||
619 | smallestIndex = index; |
||
387 | Franz | 620 | if ((biggestIndex == -1) || (biggestIndex < index + static_cast<int>(slant.length()) - 1)) |
621 | biggestIndex = index + slant.length(); |
||
364 | Franz | 622 | found = true; |
387 | Franz | 623 | tmpSlantIndex = index; |
364 | Franz | 624 | break; |
625 | } |
||
626 | } |
||
627 | if (!found) |
||
628 | slant = fontSlants[NO_SLANT]; |
||
403 | Franz | 629 | } |
364 | Franz | 630 | |
403 | Franz | 631 | void gtFont::parseWidth() |
632 | { |
||
633 | bool found = false; |
||
364 | Franz | 634 | for (int i = 1; i < FontWidthMAX; ++i) |
635 | { |
||
10398 | cbradney | 636 | index = name.indexOf(fontWidths[i]); |
364 | Franz | 637 | QString tmpWidth = ""; |
10398 | cbradney | 638 | if ((index == -1) && (fontWidths[i].indexOf(" ") != -1) && (fontWidths[i].indexOf(" ") != 1)) |
364 | Franz | 639 | { |
640 | QString fw2 = fontWidths[i]; |
||
641 | fw2.replace(" ", "-"); |
||
10398 | cbradney | 642 | index = name.indexOf(fw2); |
364 | Franz | 643 | if (index == -1) |
644 | { |
||
645 | fw2 = fontWidths[i]; |
||
646 | fw2.replace(" ", ""); |
||
10398 | cbradney | 647 | index = name.indexOf(fw2); |
364 | Franz | 648 | if (index == -1) |
649 | { |
||
650 | fw2 = fontWidths[i]; |
||
387 | Franz | 651 | fw2.replace(" B", " b"); |
364 | Franz | 652 | fw2.replace(" C", " c"); |
653 | fw2.replace(" H", " h"); |
||
654 | fw2.replace(" L", " l"); |
||
655 | fw2.replace(" ", ""); |
||
10398 | cbradney | 656 | index = name.indexOf(fw2); |
364 | Franz | 657 | if (index != -1) |
658 | tmpWidth = fw2; |
||
659 | } |
||
660 | else |
||
661 | tmpWidth = fw2; |
||
662 | } |
||
663 | else |
||
664 | { |
||
665 | tmpWidth = fw2; |
||
666 | } |
||
667 | } |
||
668 | else |
||
669 | tmpWidth = fontWidths[i]; |
||
670 | if (index != -1) |
||
671 | { |
||
672 | width = tmpWidth; |
||
673 | if (smallestIndex == -1 || smallestIndex > index) |
||
674 | smallestIndex = index; |
||
387 | Franz | 675 | if ((biggestIndex == -1) || (biggestIndex < index + static_cast<int>(tmpWidth.length()) - 1)) |
676 | biggestIndex = index + tmpWidth.length(); |
||
364 | Franz | 677 | found = true; |
387 | Franz | 678 | tmpWidthIndex = index; |
364 | Franz | 679 | break; |
680 | } |
||
681 | } |
||
682 | if (!found) |
||
683 | width = fontWidths[NO_WIDTH]; |
||
403 | Franz | 684 | } |
685 | |||
686 | void gtFont::parseFamily() |
||
687 | { |
||
387 | Franz | 688 | if (tmpWeightIndex < tmpSlantIndex) |
689 | { |
||
690 | weightIndex = 0; |
||
691 | slantIndex = 1; |
||
692 | if (tmpWidthIndex < tmpWeightIndex) |
||
693 | { |
||
694 | widthIndex = 0; |
||
695 | weightIndex = 1; |
||
696 | slantIndex = 2; |
||
697 | } |
||
698 | else if (tmpWidthIndex < tmpSlantIndex) |
||
699 | { |
||
700 | widthIndex = 1; |
||
701 | slantIndex = 2; |
||
702 | } |
||
703 | else |
||
704 | widthIndex = 2; |
||
705 | } |
||
706 | else if (tmpWeightIndex > tmpSlantIndex) |
||
707 | { |
||
708 | slantIndex = 0; |
||
709 | weightIndex = 1; |
||
710 | if (tmpWidthIndex < tmpSlantIndex) |
||
711 | { |
||
712 | widthIndex = 0; |
||
713 | slantIndex = 1; |
||
714 | weightIndex = 2; |
||
715 | } |
||
716 | else if (tmpWidthIndex < tmpWeightIndex) |
||
717 | { |
||
718 | widthIndex = 1; |
||
719 | weightIndex = 2; |
||
720 | } |
||
721 | else |
||
722 | widthIndex = 2; |
||
723 | } |
||
724 | else |
||
725 | { |
||
726 | weightIndex = -2; |
||
727 | widthIndex = -1; |
||
728 | slantIndex = 0; |
||
729 | } |
||
403 | Franz | 730 | |
364 | Franz | 731 | if (smallestIndex == -1) |
732 | family = name; |
||
733 | else |
||
734 | family = name.left(smallestIndex); |
||
9416 | jghali | 735 | if (biggestIndex == -1 || biggestIndex >= name.length()) |
387 | Franz | 736 | append = ""; |
737 | else |
||
403 | Franz | 738 | append = name.right(name.length() - biggestIndex - 1); |
10394 | cbradney | 739 | family = family.trimmed(); |
364 | Franz | 740 | } |
741 | |||
403 | Franz | 742 | int gtFont::find(const QString& where, const QString& what) |
743 | { |
||
744 | QString realWhat = " " + what; |
||
10427 | cbradney | 745 | int index = where.lastIndexOf(realWhat); // f.e. Demi Bold |
403 | Franz | 746 | if (index != -1) |
747 | { |
||
748 | if (index + realWhat.length() != where.length()) |
||
8551 | subik | 749 | if (where[index + realWhat.length() + 1] != ' ') |
405 | Franz | 750 | index = -1; |
403 | Franz | 751 | } |
752 | return index; |
||
753 | } |
||
754 | |||
364 | Franz | 755 | gtFont::~gtFont() |
756 | { |
||
757 | |||
758 | } |