Charlie Jiang pushed to branch reorg-maingui at FreeType / FreeType Demo Programs
Commits:
-
164d062e
by Charlie Jiang at 2022-06-29T16:53:55+08:00
5 changed files:
- src/ftinspect/engine/engine.cpp
- src/ftinspect/engine/engine.hpp
- src/ftinspect/ftinspect.cpp
- src/ftinspect/maingui.cpp
- src/ftinspect/maingui.hpp
Changes:
... | ... | @@ -4,7 +4,6 @@ |
4 | 4 | |
5 | 5 | |
6 | 6 | #include "engine.hpp"
|
7 | -#include "../maingui.hpp"
|
|
8 | 7 | |
9 | 8 | #include <stdexcept>
|
10 | 9 | #include <stdint.h>
|
... | ... | @@ -77,7 +76,7 @@ faceRequester(FTC_FaceID ftcFaceID, |
77 | 76 | FT_Pointer requestData,
|
78 | 77 | FT_Face* faceP)
|
79 | 78 | {
|
80 | - MainGUI* gui = static_cast<MainGUI*>(requestData);
|
|
79 | + Engine* engine = static_cast<Engine*>(requestData);
|
|
81 | 80 | // `ftcFaceID' is actually an integer
|
82 | 81 | // -> first convert pointer to same-width integer, then discard superfluous
|
83 | 82 | // bits (e.g., on x86_64 where pointers are wider than int)
|
... | ... | @@ -88,16 +87,16 @@ faceRequester(FTC_FaceID ftcFaceID, |
88 | 87 | "Pointer size must be at least the size of int"
|
89 | 88 | " in order to treat FTC_FaceID correctly");
|
90 | 89 | |
91 | - const FaceID& faceID = gui->engine->faceIDMap.key(val);
|
|
90 | + const FaceID& faceID = engine->faceIDMap.key(val);
|
|
92 | 91 | |
93 | 92 | // this is the only place where we have to check the validity of the font
|
94 | 93 | // index; note that the validity of both the face and named instance index
|
95 | 94 | // is checked by FreeType itself
|
96 | 95 | if (faceID.fontIndex < 0
|
97 | - || faceID.fontIndex >= gui->engine->numberOfOpenedFonts())
|
|
96 | + || faceID.fontIndex >= engine->numberOfOpenedFonts())
|
|
98 | 97 | return FT_Err_Invalid_Argument;
|
99 | 98 | |
100 | - QString font = gui->engine->fileManager[faceID.fontIndex].filePath();
|
|
99 | + QString font = engine->fileManager[faceID.fontIndex].filePath();
|
|
101 | 100 | long faceIndex = faceID.faceIndex;
|
102 | 101 | |
103 | 102 | if (faceID.namedInstanceIndex > 0)
|
... | ... | @@ -116,9 +115,8 @@ faceRequester(FTC_FaceID ftcFaceID, |
116 | 115 | //
|
117 | 116 | /////////////////////////////////////////////////////////////////////////////
|
118 | 117 | |
119 | -Engine::Engine(MainGUI* g)
|
|
118 | +Engine::Engine()
|
|
120 | 119 | {
|
121 | - gui = g;
|
|
122 | 120 | ftSize = NULL;
|
123 | 121 | // we reserve value 0 for the `invalid face ID'
|
124 | 122 | faceCounter = 1;
|
... | ... | @@ -132,7 +130,7 @@ Engine::Engine(MainGUI* g) |
132 | 130 | }
|
133 | 131 | |
134 | 132 | error = FTC_Manager_New(library, 0, 0, 0,
|
135 | - faceRequester, gui, &cacheManager);
|
|
133 | + faceRequester, this, &cacheManager);
|
|
136 | 134 | if (error)
|
137 | 135 | {
|
138 | 136 | // XXX error handling
|
... | ... | @@ -150,98 +148,7 @@ Engine::Engine(MainGUI* g) |
150 | 148 | // XXX error handling
|
151 | 149 | }
|
152 | 150 | |
153 | - // query engines and check for alternatives
|
|
154 | - |
|
155 | - // CFF
|
|
156 | - error = FT_Property_Get(library,
|
|
157 | - "cff",
|
|
158 | - "hinting-engine",
|
|
159 | - &cffHintingEngineDefault);
|
|
160 | - if (error)
|
|
161 | - {
|
|
162 | - // no CFF engine
|
|
163 | - cffHintingEngineDefault = -1;
|
|
164 | - cffHintingEngineOther = -1;
|
|
165 | - }
|
|
166 | - else
|
|
167 | - {
|
|
168 | - int engines[] =
|
|
169 | - {
|
|
170 | - FT_HINTING_FREETYPE,
|
|
171 | - FT_HINTING_ADOBE
|
|
172 | - };
|
|
173 | - |
|
174 | - int i;
|
|
175 | - for (i = 0; i < 2; i++)
|
|
176 | - if (cffHintingEngineDefault == engines[i])
|
|
177 | - break;
|
|
178 | - |
|
179 | - cffHintingEngineOther = engines[(i + 1) % 2];
|
|
180 | - |
|
181 | - error = FT_Property_Set(library,
|
|
182 | - "cff",
|
|
183 | - "hinting-engine",
|
|
184 | - &cffHintingEngineOther);
|
|
185 | - if (error)
|
|
186 | - cffHintingEngineOther = -1;
|
|
187 | - |
|
188 | - // reset
|
|
189 | - FT_Property_Set(library,
|
|
190 | - "cff",
|
|
191 | - "hinting-engine",
|
|
192 | - &cffHintingEngineDefault);
|
|
193 | - }
|
|
194 | - |
|
195 | - // TrueType
|
|
196 | - error = FT_Property_Get(library,
|
|
197 | - "truetype",
|
|
198 | - "interpreter-version",
|
|
199 | - &ttInterpreterVersionDefault);
|
|
200 | - if (error)
|
|
201 | - {
|
|
202 | - // no TrueType engine
|
|
203 | - ttInterpreterVersionDefault = -1;
|
|
204 | - ttInterpreterVersionOther = -1;
|
|
205 | - ttInterpreterVersionOther1 = -1;
|
|
206 | - }
|
|
207 | - else
|
|
208 | - {
|
|
209 | - int interpreters[] =
|
|
210 | - {
|
|
211 | - TT_INTERPRETER_VERSION_35,
|
|
212 | - TT_INTERPRETER_VERSION_38,
|
|
213 | - TT_INTERPRETER_VERSION_40
|
|
214 | - };
|
|
215 | - |
|
216 | - int i;
|
|
217 | - for (i = 0; i < 3; i++)
|
|
218 | - if (ttInterpreterVersionDefault == interpreters[i])
|
|
219 | - break;
|
|
220 | - |
|
221 | - ttInterpreterVersionOther = interpreters[(i + 1) % 3];
|
|
222 | - |
|
223 | - error = FT_Property_Set(library,
|
|
224 | - "truetype",
|
|
225 | - "interpreter-version",
|
|
226 | - &ttInterpreterVersionOther);
|
|
227 | - if (error)
|
|
228 | - ttInterpreterVersionOther = -1;
|
|
229 | - |
|
230 | - ttInterpreterVersionOther1 = interpreters[(i + 2) % 3];
|
|
231 | - |
|
232 | - error = FT_Property_Set(library,
|
|
233 | - "truetype",
|
|
234 | - "interpreter-version",
|
|
235 | - &ttInterpreterVersionOther1);
|
|
236 | - if (error)
|
|
237 | - ttInterpreterVersionOther1 = -1;
|
|
238 | - |
|
239 | - // reset
|
|
240 | - FT_Property_Set(library,
|
|
241 | - "truetype",
|
|
242 | - "interpreter-version",
|
|
243 | - &ttInterpreterVersionDefault);
|
|
244 | - }
|
|
151 | + queryEngine();
|
|
245 | 152 | }
|
246 | 153 | |
247 | 154 | |
... | ... | @@ -395,6 +302,13 @@ Engine::loadFont(int fontIndex, |
395 | 302 | }
|
396 | 303 | |
397 | 304 | |
305 | +void
|
|
306 | +Engine::openFonts(QStringList fontFileNames)
|
|
307 | +{
|
|
308 | + fileManager.append(fontFileNames);
|
|
309 | +}
|
|
310 | + |
|
311 | + |
|
398 | 312 | void
|
399 | 313 | Engine::removeFont(int fontIndex, bool closeFile)
|
400 | 314 | {
|
... | ... | @@ -423,20 +337,6 @@ Engine::removeFont(int fontIndex, bool closeFile) |
423 | 337 | }
|
424 | 338 | |
425 | 339 | |
426 | -const QString&
|
|
427 | -Engine::currentFamilyName()
|
|
428 | -{
|
|
429 | - return curFamilyName;
|
|
430 | -}
|
|
431 | - |
|
432 | - |
|
433 | -const QString&
|
|
434 | -Engine::currentStyleName()
|
|
435 | -{
|
|
436 | - return curStyleName;
|
|
437 | -}
|
|
438 | - |
|
439 | - |
|
440 | 340 | QString
|
441 | 341 | Engine::glyphName(int index)
|
442 | 342 | {
|
... | ... | @@ -492,27 +392,45 @@ Engine::loadOutline(int glyphIndex) |
492 | 392 | return &outlineGlyph->outline;
|
493 | 393 | }
|
494 | 394 | |
395 | + |
|
495 | 396 | int
|
496 | 397 | Engine::numberOfOpenedFonts()
|
497 | 398 | {
|
498 | 399 | return fileManager.size();
|
499 | 400 | }
|
500 | 401 | |
402 | + |
|
501 | 403 | void
|
502 | -Engine::openFonts(QStringList fontFileNames)
|
|
404 | +Engine::setSizeByPixel(double pixelSize)
|
|
503 | 405 | {
|
504 | - fileManager.append(fontFileNames);
|
|
406 | + this->pixelSize = pixelSize;
|
|
407 | + pointSize = pixelSize * 72.0 / dpi;
|
|
408 | + usingPixelSize = true;
|
|
505 | 409 | }
|
506 | 410 | |
507 | 411 | void
|
508 | -Engine::setCFFHintingMode(int mode)
|
|
412 | +Engine::setSizeByPoint(double pointSize)
|
|
509 | 413 | {
|
510 | - int index = gui->hintingModesCFFHash.key(mode);
|
|
414 | + this->pointSize = pointSize;
|
|
415 | + pixelSize = pointSize * dpi / 72.0;
|
|
416 | + usingPixelSize = false;
|
|
417 | +}
|
|
511 | 418 | |
419 | + |
|
420 | +void
|
|
421 | +Engine::setLcdFilter(FT_LcdFilter filter)
|
|
422 | +{
|
|
423 | + FT_Library_SetLcdFilter(library, filter);
|
|
424 | +}
|
|
425 | + |
|
426 | + |
|
427 | +void
|
|
428 | +Engine::setCFFHintingMode(int mode)
|
|
429 | +{
|
|
512 | 430 | FT_Error error = FT_Property_Set(library,
|
513 | 431 | "cff",
|
514 | 432 | "hinting-engine",
|
515 | - &index);
|
|
433 | + &mode);
|
|
516 | 434 | if (!error)
|
517 | 435 | {
|
518 | 436 | // reset the cache
|
... | ... | @@ -522,14 +440,12 @@ Engine::setCFFHintingMode(int mode) |
522 | 440 | |
523 | 441 | |
524 | 442 | void
|
525 | -Engine::setTTInterpreterVersion(int mode)
|
|
443 | +Engine::setTTInterpreterVersion(int version)
|
|
526 | 444 | {
|
527 | - int index = gui->hintingModesTrueTypeHash.key(mode);
|
|
528 | - |
|
529 | 445 | FT_Error error = FT_Property_Set(library,
|
530 | 446 | "truetype",
|
531 | 447 | "interpreter-version",
|
532 | - &index);
|
|
448 | + &version);
|
|
533 | 449 | if (!error)
|
534 | 450 | {
|
535 | 451 | // reset the cache
|
... | ... | @@ -541,58 +457,32 @@ Engine::setTTInterpreterVersion(int mode) |
541 | 457 | void
|
542 | 458 | Engine::update()
|
543 | 459 | {
|
544 | - // Spinbox value cannot become negative
|
|
545 | - dpi = static_cast<unsigned int>(gui->dpiSpinBox->value());
|
|
546 | - |
|
547 | - if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
|
|
548 | - {
|
|
549 | - pixelSize = gui->sizeDoubleSpinBox->value();
|
|
550 | - pointSize = pixelSize * 72.0 / dpi;
|
|
551 | - }
|
|
552 | - else
|
|
553 | - {
|
|
554 | - pointSize = gui->sizeDoubleSpinBox->value();
|
|
555 | - pixelSize = pointSize * dpi / 72.0;
|
|
556 | - }
|
|
557 | - |
|
558 | - doHinting = gui->hintingCheckBox->isChecked();
|
|
559 | - |
|
560 | - doAutoHinting = gui->autoHintingCheckBox->isChecked();
|
|
561 | - doHorizontalHinting = gui->horizontalHintingCheckBox->isChecked();
|
|
562 | - doVerticalHinting = gui->verticalHintingCheckBox->isChecked();
|
|
563 | - doBlueZoneHinting = gui->blueZoneHintingCheckBox->isChecked();
|
|
564 | - showSegments = gui->segmentDrawingCheckBox->isChecked();
|
|
565 | - |
|
566 | - gamma = gui->gammaSlider->value();
|
|
567 | - |
|
568 | 460 | loadFlags = FT_LOAD_DEFAULT;
|
569 | 461 | if (doAutoHinting)
|
570 | 462 | loadFlags |= FT_LOAD_FORCE_AUTOHINT;
|
571 | 463 | loadFlags |= FT_LOAD_NO_BITMAP; // XXX handle bitmap fonts also
|
572 | 464 | |
573 | - int index = gui->antiAliasingComboBoxx->currentIndex();
|
|
574 | - |
|
575 | 465 | if (doHinting)
|
576 | 466 | {
|
577 | 467 | unsigned long target;
|
578 | 468 | |
579 | - if (index == MainGUI::AntiAliasing_None)
|
|
469 | + if (antiAliasingMode == AntiAliasing_None)
|
|
580 | 470 | target = FT_LOAD_TARGET_MONO;
|
581 | 471 | else
|
582 | 472 | {
|
583 | - switch (index)
|
|
473 | + switch (antiAliasingMode)
|
|
584 | 474 | {
|
585 | - case MainGUI::AntiAliasing_Light:
|
|
475 | + case AntiAliasing_Light:
|
|
586 | 476 | target = FT_LOAD_TARGET_LIGHT;
|
587 | 477 | break;
|
588 | 478 | |
589 | - case MainGUI::AntiAliasing_LCD:
|
|
590 | - case MainGUI::AntiAliasing_LCD_BGR:
|
|
479 | + case AntiAliasing_LCD:
|
|
480 | + case AntiAliasing_LCD_BGR: // TODO Differenate RGB/BGR here?
|
|
591 | 481 | target = FT_LOAD_TARGET_LCD;
|
592 | 482 | break;
|
593 | 483 | |
594 | - case MainGUI::AntiAliasing_LCD_Vertical:
|
|
595 | - case MainGUI::AntiAliasing_LCD_Vertical_BGR:
|
|
484 | + case AntiAliasing_LCD_Vertical:
|
|
485 | + case AntiAliasing_LCD_Vertical_BGR:
|
|
596 | 486 | target = FT_LOAD_TARGET_LCD_V;
|
597 | 487 | break;
|
598 | 488 | |
... | ... | @@ -607,7 +497,7 @@ Engine::update() |
607 | 497 | {
|
608 | 498 | loadFlags |= FT_LOAD_NO_HINTING;
|
609 | 499 | |
610 | - if (index == MainGUI::AntiAliasing_None)
|
|
500 | + if (antiAliasingMode == AntiAliasing_None)
|
|
611 | 501 | loadFlags |= FT_LOAD_MONOCHROME;
|
612 | 502 | }
|
613 | 503 | |
... | ... | @@ -615,7 +505,7 @@ Engine::update() |
615 | 505 | |
616 | 506 | scaler.pixel = 0; // use 26.6 format
|
617 | 507 | |
618 | - if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
|
|
508 | + if (usingPixelSize)
|
|
619 | 509 | {
|
620 | 510 | scaler.width = static_cast<unsigned int>(pixelSize * 64.0);
|
621 | 511 | scaler.height = static_cast<unsigned int>(pixelSize * 64.0);
|
... | ... | @@ -631,11 +521,104 @@ Engine::update() |
631 | 521 | }
|
632 | 522 | }
|
633 | 523 | |
634 | -FontFileManager&
|
|
635 | -Engine::fontFileManager()
|
|
524 | + |
|
525 | +void
|
|
526 | +Engine::queryEngine()
|
|
636 | 527 | {
|
637 | - return fileManager;
|
|
638 | -}
|
|
528 | + FT_Error error;
|
|
529 | + |
|
530 | + // query engines and check for alternatives
|
|
639 | 531 | |
532 | + // CFF
|
|
533 | + error = FT_Property_Get(library,
|
|
534 | + "cff",
|
|
535 | + "hinting-engine",
|
|
536 | + &defaults.cffHintingEngineDefault);
|
|
537 | + if (error)
|
|
538 | + {
|
|
539 | + // no CFF engine
|
|
540 | + defaults.cffHintingEngineDefault = -1;
|
|
541 | + defaults.cffHintingEngineOther = -1;
|
|
542 | + }
|
|
543 | + else
|
|
544 | + {
|
|
545 | + int engines[] =
|
|
546 | + {
|
|
547 | + FT_HINTING_FREETYPE,
|
|
548 | + FT_HINTING_ADOBE
|
|
549 | + };
|
|
550 | + |
|
551 | + int i;
|
|
552 | + for (i = 0; i < 2; i++)
|
|
553 | + if (defaults.cffHintingEngineDefault == engines[i])
|
|
554 | + break;
|
|
555 | + |
|
556 | + defaults.cffHintingEngineOther = engines[(i + 1) % 2];
|
|
557 | + |
|
558 | + error = FT_Property_Set(library,
|
|
559 | + "cff",
|
|
560 | + "hinting-engine",
|
|
561 | + &defaults.cffHintingEngineOther);
|
|
562 | + if (error)
|
|
563 | + defaults.cffHintingEngineOther = -1;
|
|
564 | + |
|
565 | + // reset
|
|
566 | + FT_Property_Set(library,
|
|
567 | + "cff",
|
|
568 | + "hinting-engine",
|
|
569 | + &defaults.cffHintingEngineDefault);
|
|
570 | + }
|
|
571 | + |
|
572 | + // TrueType
|
|
573 | + error = FT_Property_Get(library,
|
|
574 | + "truetype",
|
|
575 | + "interpreter-version",
|
|
576 | + &defaults.ttInterpreterVersionDefault);
|
|
577 | + if (error)
|
|
578 | + {
|
|
579 | + // no TrueType engine
|
|
580 | + defaults.ttInterpreterVersionDefault = -1;
|
|
581 | + defaults.ttInterpreterVersionOther = -1;
|
|
582 | + defaults.ttInterpreterVersionOther1 = -1;
|
|
583 | + }
|
|
584 | + else
|
|
585 | + {
|
|
586 | + int interpreters[] =
|
|
587 | + {
|
|
588 | + TT_INTERPRETER_VERSION_35,
|
|
589 | + TT_INTERPRETER_VERSION_38,
|
|
590 | + TT_INTERPRETER_VERSION_40
|
|
591 | + };
|
|
592 | + |
|
593 | + int i;
|
|
594 | + for (i = 0; i < 3; i++)
|
|
595 | + if (defaults.ttInterpreterVersionDefault == interpreters[i])
|
|
596 | + break;
|
|
597 | + |
|
598 | + defaults.ttInterpreterVersionOther = interpreters[(i + 1) % 3];
|
|
599 | + |
|
600 | + error = FT_Property_Set(library,
|
|
601 | + "truetype",
|
|
602 | + "interpreter-version",
|
|
603 | + &defaults.ttInterpreterVersionOther);
|
|
604 | + if (error)
|
|
605 | + defaults.ttInterpreterVersionOther = -1;
|
|
606 | + |
|
607 | + defaults.ttInterpreterVersionOther1 = interpreters[(i + 2) % 3];
|
|
608 | + |
|
609 | + error = FT_Property_Set(library,
|
|
610 | + "truetype",
|
|
611 | + "interpreter-version",
|
|
612 | + &defaults.ttInterpreterVersionOther1);
|
|
613 | + if (error)
|
|
614 | + defaults.ttInterpreterVersionOther1 = -1;
|
|
615 | + |
|
616 | + // reset
|
|
617 | + FT_Property_Set(library,
|
|
618 | + "truetype",
|
|
619 | + "interpreter-version",
|
|
620 | + &defaults.ttInterpreterVersionDefault);
|
|
621 | + }
|
|
622 | +}
|
|
640 | 623 | |
641 | 624 | // end of engine.cpp |
... | ... | @@ -14,6 +14,7 @@ |
14 | 14 | #include <freetype/freetype.h>
|
15 | 15 | #include <freetype/ftoutln.h>
|
16 | 16 | #include <freetype/ftcache.h>
|
17 | +#include <freetype/ftlcdfil.h>
|
|
17 | 18 | |
18 | 19 | |
19 | 20 | // This structure maps the (font, face, instance) index triplet to abstract
|
... | ... | @@ -35,62 +36,103 @@ struct FaceID |
35 | 36 | bool operator<(const FaceID& other) const;
|
36 | 37 | };
|
37 | 38 | |
38 | - |
|
39 | -class MainGUI;
|
|
40 | - |
|
41 | 39 | // FreeType specific data.
|
42 | 40 | |
43 | 41 | class Engine
|
44 | 42 | {
|
45 | 43 | public:
|
46 | - Engine(MainGUI*);
|
|
44 | + //////// Nested definitions (forward decl)
|
|
45 | + |
|
46 | + // TODO these would be dropped with custom QAbstractItemModel
|
|
47 | + enum AntiAliasing : int;
|
|
48 | + enum FontType : int;
|
|
49 | + |
|
50 | + struct EngineDefaultValues
|
|
51 | + {
|
|
52 | + int cffHintingEngineDefault;
|
|
53 | + int cffHintingEngineOther;
|
|
54 | + |
|
55 | + int ttInterpreterVersionDefault;
|
|
56 | + int ttInterpreterVersionOther;
|
|
57 | + int ttInterpreterVersionOther1;
|
|
58 | + };
|
|
59 | + |
|
60 | + //////// Ctors & Dtors
|
|
61 | + |
|
62 | + Engine();
|
|
47 | 63 | ~Engine();
|
48 | 64 | |
49 | 65 | // Disable copying
|
50 | 66 | Engine(const Engine& other) = delete;
|
51 | 67 | Engine& operator=(const Engine& other) = delete;
|
52 | 68 | |
53 | - const QString& currentFamilyName();
|
|
54 | - const QString& currentStyleName();
|
|
55 | - QString glyphName(int glyphIndex);
|
|
56 | - long numberOfFaces(int fontIndex);
|
|
57 | - int numberOfNamedInstances(int fontIndex,
|
|
58 | - long faceIndex);
|
|
69 | + //////// Actions
|
|
70 | + |
|
59 | 71 | int loadFont(int fontIndex,
|
60 | 72 | long faceIndex,
|
61 | 73 | int namedInstanceIndex); // return number of glyphs
|
62 | 74 | FT_Outline* loadOutline(int glyphIndex);
|
63 | 75 | |
64 | - int numberOfOpenedFonts();
|
|
65 | 76 | void openFonts(QStringList fontFileNames);
|
66 | 77 | void removeFont(int fontIndex, bool closeFile = true);
|
78 | +
|
|
79 | + void update();
|
|
67 | 80 | |
81 | + //////// Getters
|
|
82 | + |
|
83 | + FT_Library ftLibrary() const { return library; }
|
|
84 | + int currentFontType() const { return fontType; }
|
|
85 | + const QString& currentFamilyName() { return curFamilyName; }
|
|
86 | + const QString& currentStyleName() { return curStyleName; }
|
|
87 | + int numberOfOpenedFonts();
|
|
88 | + QString glyphName(int glyphIndex);
|
|
89 | + long numberOfFaces(int fontIndex);
|
|
90 | + int numberOfNamedInstances(int fontIndex,
|
|
91 | + long faceIndex);
|
|
92 | + |
|
93 | + // XXX We should prepend '_' to all private member variable so we can create
|
|
94 | + // getter without naming conflict... e.g. var named _fontFileManager while
|
|
95 | + // getter named fontFileManager
|
|
96 | + FontFileManager& fontFileManager() { return fileManager; }
|
|
97 | + EngineDefaultValues& engineDefaults() { return defaults; }
|
|
98 | + |
|
99 | + //////// Setters (direct or indirect)
|
|
100 | + |
|
101 | + void setDPI(int d) { dpi = d; }
|
|
102 | + void setSizeByPixel(double pixelSize);
|
|
103 | + void setSizeByPoint(double pointSize);
|
|
104 | + void setHinting(bool hinting) { doHinting = hinting; }
|
|
105 | + void setAutoHinting(bool autoHinting) { doAutoHinting = autoHinting; }
|
|
106 | + void setHorizontalHinting(bool horHinting)
|
|
107 | + {
|
|
108 | + doHorizontalHinting = horHinting;
|
|
109 | + }
|
|
110 | + void setVerticalHinting(bool verticalHinting)
|
|
111 | + {
|
|
112 | + doVerticalHinting = verticalHinting;
|
|
113 | + }
|
|
114 | + void setBlueZoneHinting(bool blueZoneHinting)
|
|
115 | + {
|
|
116 | + doBlueZoneHinting = blueZoneHinting;
|
|
117 | + }
|
|
118 | + void setShowSegments(bool showSegments) { this->showSegments = showSegments; }
|
|
119 | + void setGamma(double gamma) { this->gamma = gamma; }
|
|
120 | + void setAntiAliasingMode(AntiAliasing mode) { antiAliasingMode = mode; }
|
|
121 | + |
|
122 | + // Note: These 3 functions now takes actual mode/version from FreeType,
|
|
123 | + // instead of values from enum in MainGUI!
|
|
124 | + void setLcdFilter(FT_LcdFilter filter);
|
|
68 | 125 | void setCFFHintingMode(int mode);
|
69 | 126 | void setTTInterpreterVersion(int version);
|
70 | - void update();
|
|
71 | 127 | |
72 | - friend class MainGUI;
|
|
128 | + //////// Misc
|
|
129 | + |
|
73 | 130 | friend FT_Error faceRequester(FTC_FaceID,
|
74 | 131 | FT_Library,
|
75 | 132 | FT_Pointer,
|
76 | 133 | FT_Face*);
|
77 | 134 | |
78 | - // XXX cover all available modules
|
|
79 | - enum FontType
|
|
80 | - {
|
|
81 | - FontType_CFF,
|
|
82 | - FontType_TrueType,
|
|
83 | - FontType_Other
|
|
84 | - };
|
|
85 | - |
|
86 | - // XXX We should prepend '_' to all private member variable so we can create
|
|
87 | - // getter without naming conflict... e.g. var named _fontFileManager while
|
|
88 | - // getter named fontFileManager
|
|
89 | - FontFileManager& fontFileManager();
|
|
90 | - |
|
91 | 135 | private:
|
92 | - MainGUI* gui;
|
|
93 | - |
|
94 | 136 | using FTC_IDType = uintptr_t;
|
95 | 137 | FTC_IDType faceCounter; // a running number used to initialize `faceIDMap'
|
96 | 138 | QMap<FaceID, FTC_IDType> faceIDMap;
|
... | ... | @@ -108,15 +150,11 @@ private: |
108 | 150 | FTC_ScalerRec scaler;
|
109 | 151 | FT_Size ftSize;
|
110 | 152 | |
111 | - int cffHintingEngineDefault;
|
|
112 | - int cffHintingEngineOther;
|
|
113 | - |
|
114 | - int ttInterpreterVersionDefault;
|
|
115 | - int ttInterpreterVersionOther;
|
|
116 | - int ttInterpreterVersionOther1;
|
|
153 | + EngineDefaultValues defaults;
|
|
117 | 154 | |
118 | 155 | int fontType;
|
119 | 156 | |
157 | + bool usingPixelSize = false;
|
|
120 | 158 | double pointSize;
|
121 | 159 | double pixelSize;
|
122 | 160 | unsigned int dpi;
|
... | ... | @@ -127,10 +165,36 @@ private: |
127 | 165 | bool doVerticalHinting;
|
128 | 166 | bool doBlueZoneHinting;
|
129 | 167 | bool showSegments;
|
168 | + AntiAliasing antiAliasingMode;
|
|
130 | 169 | |
131 | 170 | double gamma;
|
132 | 171 | |
133 | 172 | unsigned long loadFlags;
|
173 | + |
|
174 | + void queryEngine();
|
|
175 | + |
|
176 | +public:
|
|
177 | + |
|
178 | + /// Actual definition
|
|
179 | +
|
|
180 | + enum AntiAliasing
|
|
181 | + {
|
|
182 | + AntiAliasing_None,
|
|
183 | + AntiAliasing_Normal,
|
|
184 | + AntiAliasing_Light,
|
|
185 | + AntiAliasing_LCD,
|
|
186 | + AntiAliasing_LCD_BGR,
|
|
187 | + AntiAliasing_LCD_Vertical,
|
|
188 | + AntiAliasing_LCD_Vertical_BGR
|
|
189 | + };
|
|
190 | + |
|
191 | + // XXX cover all available modules
|
|
192 | + enum FontType
|
|
193 | + {
|
|
194 | + FontType_CFF,
|
|
195 | + FontType_TrueType,
|
|
196 | + FontType_Other
|
|
197 | + };
|
|
134 | 198 | };
|
135 | 199 | |
136 | 200 |
... | ... | @@ -22,7 +22,7 @@ main(int argc, |
22 | 22 | app.setOrganizationDomain("freetype.org");
|
23 | 23 | |
24 | 24 | MainGUI gui;
|
25 | - Engine engine(&gui);
|
|
25 | + Engine engine;
|
|
26 | 26 | |
27 | 27 | gui.update(&engine);
|
28 | 28 | gui.setDefaults();
|
... | ... | @@ -174,6 +174,7 @@ MainGUI::showFont() |
174 | 174 | else
|
175 | 175 | fontFilenameLabel->clear();
|
176 | 176 | |
177 | + syncSettings();
|
|
177 | 178 | currentNumberOfFaces
|
178 | 179 | = engine->numberOfFaces(currentFontIndex);
|
179 | 180 | currentNumberOfNamedInstances
|
... | ... | @@ -209,12 +210,45 @@ MainGUI::showFont() |
209 | 210 | }
|
210 | 211 | |
211 | 212 | |
213 | +void
|
|
214 | +MainGUI::syncSettings()
|
|
215 | +{
|
|
216 | + // Spinbox value cannot become negative
|
|
217 | + engine->setDPI(static_cast<unsigned int>(dpiSpinBox->value()));
|
|
218 | + |
|
219 | + if (unitsComboBox->currentIndex() == Units_px)
|
|
220 | + engine->setSizeByPixel(sizeDoubleSpinBox->value());
|
|
221 | + else
|
|
222 | + engine->setSizeByPoint(sizeDoubleSpinBox->value());
|
|
223 | + |
|
224 | + engine->setHinting(hintingCheckBox->isChecked());
|
|
225 | + engine->setAutoHinting(autoHintingCheckBox->isChecked());
|
|
226 | + engine->setHorizontalHinting(horizontalHintingCheckBox->isChecked());
|
|
227 | + engine->setVerticalHinting(verticalHintingCheckBox->isChecked());
|
|
228 | + engine->setBlueZoneHinting(blueZoneHintingCheckBox->isChecked());
|
|
229 | + engine->setShowSegments(segmentDrawingCheckBox->isChecked());
|
|
230 | + |
|
231 | + engine->setGamma(gammaSlider->value());
|
|
232 | + |
|
233 | + engine->setAntiAliasingMode(static_cast<Engine::AntiAliasing>(
|
|
234 | + antiAliasingComboBoxx->currentIndex()));
|
|
235 | +}
|
|
236 | + |
|
237 | + |
|
238 | +void
|
|
239 | +MainGUI::clearStatusBar()
|
|
240 | +{
|
|
241 | + statusBar()->clearMessage();
|
|
242 | + statusBar()->setStyleSheet("");
|
|
243 | +}
|
|
244 | + |
|
245 | + |
|
212 | 246 | void
|
213 | 247 | MainGUI::checkHinting()
|
214 | 248 | {
|
215 | 249 | if (hintingCheckBox->isChecked())
|
216 | 250 | {
|
217 | - if (engine->fontType == Engine::FontType_CFF)
|
|
251 | + if (engine->currentFontType() == Engine::FontType_CFF)
|
|
218 | 252 | {
|
219 | 253 | for (int i = 0; i < hintingModeComboBoxx->count(); i++)
|
220 | 254 | {
|
... | ... | @@ -226,7 +260,7 @@ MainGUI::checkHinting() |
226 | 260 | |
227 | 261 | hintingModeComboBoxx->setCurrentIndex(currentCFFHintingMode);
|
228 | 262 | }
|
229 | - else if (engine->fontType == Engine::FontType_TrueType)
|
|
263 | + else if (engine->currentFontType() == Engine::FontType_TrueType)
|
|
230 | 264 | {
|
231 | 265 | for (int i = 0; i < hintingModeComboBoxx->count(); i++)
|
232 | 266 | {
|
... | ... | @@ -262,7 +296,7 @@ MainGUI::checkHinting() |
262 | 296 | blueZoneHintingCheckBox->setEnabled(false);
|
263 | 297 | segmentDrawingCheckBox->setEnabled(false);
|
264 | 298 | |
265 | - antiAliasingComboBoxx->setItemEnabled(AntiAliasing_Light, false);
|
|
299 | + antiAliasingComboBoxx->setItemEnabled(Engine::AntiAliasing_Light, false);
|
|
266 | 300 | }
|
267 | 301 | |
268 | 302 | drawGlyph();
|
... | ... | @@ -274,14 +308,14 @@ MainGUI::checkHintingMode() |
274 | 308 | {
|
275 | 309 | int index = hintingModeComboBoxx->currentIndex();
|
276 | 310 | |
277 | - if (engine->fontType == Engine::FontType_CFF)
|
|
311 | + if (engine->currentFontType() == Engine::FontType_CFF)
|
|
278 | 312 | {
|
279 | - engine->setCFFHintingMode(index);
|
|
313 | + engine->setCFFHintingMode(hintingModesCFFHash.key(index));
|
|
280 | 314 | currentCFFHintingMode = index;
|
281 | 315 | }
|
282 | - else if (engine->fontType == Engine::FontType_TrueType)
|
|
316 | + else if (engine->currentFontType() == Engine::FontType_TrueType)
|
|
283 | 317 | {
|
284 | - engine->setTTInterpreterVersion(index);
|
|
318 | + engine->setTTInterpreterVersion(hintingModesTrueTypeHash.key(index));
|
|
285 | 319 | currentTTInterpreterVersion = index;
|
286 | 320 | }
|
287 | 321 | |
... | ... | @@ -303,12 +337,12 @@ MainGUI::checkAutoHinting() |
303 | 337 | blueZoneHintingCheckBox->setEnabled(true);
|
304 | 338 | segmentDrawingCheckBox->setEnabled(true);
|
305 | 339 | |
306 | - antiAliasingComboBoxx->setItemEnabled(AntiAliasing_Light, true);
|
|
340 | + antiAliasingComboBoxx->setItemEnabled(Engine::AntiAliasing_Light, true);
|
|
307 | 341 | }
|
308 | 342 | else
|
309 | 343 | {
|
310 | - if (engine->fontType == Engine::FontType_CFF
|
|
311 | - || engine->fontType == Engine::FontType_TrueType)
|
|
344 | + if (engine->currentFontType() == Engine::FontType_CFF
|
|
345 | + || engine->currentFontType() == Engine::FontType_TrueType)
|
|
312 | 346 | {
|
313 | 347 | hintingModeLabel->setEnabled(true);
|
314 | 348 | hintingModeComboBoxx->setEnabled(true);
|
... | ... | @@ -319,10 +353,10 @@ MainGUI::checkAutoHinting() |
319 | 353 | blueZoneHintingCheckBox->setEnabled(false);
|
320 | 354 | segmentDrawingCheckBox->setEnabled(false);
|
321 | 355 | |
322 | - antiAliasingComboBoxx->setItemEnabled(AntiAliasing_Light, false);
|
|
356 | + antiAliasingComboBoxx->setItemEnabled(Engine::AntiAliasing_Light, false);
|
|
323 | 357 | |
324 | - if (antiAliasingComboBoxx->currentIndex() == AntiAliasing_Light)
|
|
325 | - antiAliasingComboBoxx->setCurrentIndex(AntiAliasing_Normal);
|
|
358 | + if (antiAliasingComboBoxx->currentIndex() == Engine::AntiAliasing_Light)
|
|
359 | + antiAliasingComboBoxx->setCurrentIndex(Engine::AntiAliasing_Normal);
|
|
326 | 360 | }
|
327 | 361 | |
328 | 362 | drawGlyph();
|
... | ... | @@ -334,9 +368,9 @@ MainGUI::checkAntiAliasing() |
334 | 368 | {
|
335 | 369 | int index = antiAliasingComboBoxx->currentIndex();
|
336 | 370 | |
337 | - if (index == AntiAliasing_None
|
|
338 | - || index == AntiAliasing_Normal
|
|
339 | - || index == AntiAliasing_Light)
|
|
371 | + if (index == Engine::AntiAliasing_None
|
|
372 | + || index == Engine::AntiAliasing::AntiAliasing_Normal
|
|
373 | + || index == Engine::AntiAliasing_Light)
|
|
340 | 374 | {
|
341 | 375 | lcdFilterLabel->setEnabled(false);
|
342 | 376 | lcdFilterComboBox->setEnabled(false);
|
... | ... | @@ -355,7 +389,7 @@ void |
355 | 389 | MainGUI::checkLcdFilter()
|
356 | 390 | {
|
357 | 391 | int index = lcdFilterComboBox->currentIndex();
|
358 | - FT_Library_SetLcdFilter(engine->library, lcdFilterHash.key(index));
|
|
392 | + engine->setLcdFilter(lcdFilterHash.key(index));
|
|
359 | 393 | }
|
360 | 394 | |
361 | 395 | |
... | ... | @@ -654,6 +688,7 @@ MainGUI::drawGlyph() |
654 | 688 | currentGlyphPointNumbersItem = NULL;
|
655 | 689 | }
|
656 | 690 | |
691 | + syncSettings();
|
|
657 | 692 | FT_Outline* outline = engine->loadOutline(currentGlyphIndex);
|
658 | 693 | if (outline)
|
659 | 694 | {
|
... | ... | @@ -661,11 +696,11 @@ MainGUI::drawGlyph() |
661 | 696 | {
|
662 | 697 | // XXX support LCD
|
663 | 698 | FT_Pixel_Mode pixelMode = FT_PIXEL_MODE_GRAY;
|
664 | - if (antiAliasingComboBoxx->currentIndex() == AntiAliasing_None)
|
|
699 | + if (antiAliasingComboBoxx->currentIndex() == Engine::AntiAliasing_None)
|
|
665 | 700 | pixelMode = FT_PIXEL_MODE_MONO;
|
666 | 701 | |
667 | 702 | currentGlyphBitmapItem = new GlyphBitmap(outline,
|
668 | - engine->library,
|
|
703 | + engine->ftLibrary(),
|
|
669 | 704 | pixelMode,
|
670 | 705 | monoColorTable,
|
671 | 706 | grayColorTable);
|
... | ... | @@ -731,19 +766,19 @@ MainGUI::createLayout() |
731 | 766 | antiAliasingLabel = new QLabel(tr("Anti-Aliasing"));
|
732 | 767 | antiAliasingLabel->setAlignment(Qt::AlignRight);
|
733 | 768 | antiAliasingComboBoxx = new QComboBoxx;
|
734 | - antiAliasingComboBoxx->insertItem(AntiAliasing_None,
|
|
769 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_None,
|
|
735 | 770 | tr("None"));
|
736 | - antiAliasingComboBoxx->insertItem(AntiAliasing_Normal,
|
|
771 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_Normal,
|
|
737 | 772 | tr("Normal"));
|
738 | - antiAliasingComboBoxx->insertItem(AntiAliasing_Light,
|
|
773 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_Light,
|
|
739 | 774 | tr("Light"));
|
740 | - antiAliasingComboBoxx->insertItem(AntiAliasing_LCD,
|
|
775 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_LCD,
|
|
741 | 776 | tr("LCD (RGB)"));
|
742 | - antiAliasingComboBoxx->insertItem(AntiAliasing_LCD_BGR,
|
|
777 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_LCD_BGR,
|
|
743 | 778 | tr("LCD (BGR)"));
|
744 | - antiAliasingComboBoxx->insertItem(AntiAliasing_LCD_Vertical,
|
|
779 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_LCD_Vertical,
|
|
745 | 780 | tr("LCD (vert. RGB)"));
|
746 | - antiAliasingComboBoxx->insertItem(AntiAliasing_LCD_Vertical_BGR,
|
|
781 | + antiAliasingComboBoxx->insertItem(Engine::AntiAliasing_LCD_Vertical_BGR,
|
|
747 | 782 | tr("LCD (vert. BGR)"));
|
748 | 783 | antiAliasingLabel->setBuddy(antiAliasingComboBoxx);
|
749 | 784 | |
... | ... | @@ -1139,14 +1174,6 @@ MainGUI::createStatusBar() |
1139 | 1174 | }
|
1140 | 1175 | |
1141 | 1176 | |
1142 | -void
|
|
1143 | -MainGUI::clearStatusBar()
|
|
1144 | -{
|
|
1145 | - statusBar()->clearMessage();
|
|
1146 | - statusBar()->setStyleSheet("");
|
|
1147 | -}
|
|
1148 | - |
|
1149 | - |
|
1150 | 1177 | void
|
1151 | 1178 | MainGUI::setDefaults()
|
1152 | 1179 | {
|
... | ... | @@ -1163,20 +1190,22 @@ MainGUI::setDefaults() |
1163 | 1190 | lcdFilterHash[FT_LCD_FILTER_NONE] = LCDFilter_None;
|
1164 | 1191 | lcdFilterHash[FT_LCD_FILTER_LEGACY] = LCDFilter_Legacy;
|
1165 | 1192 | |
1193 | + Engine::EngineDefaultValues& defaults = engine->engineDefaults();
|
|
1194 | + |
|
1166 | 1195 | // make copies and remove existing elements...
|
1167 | 1196 | QHash<int, int> hmTTHash = hintingModesTrueTypeHash;
|
1168 | - if (hmTTHash.contains(engine->ttInterpreterVersionDefault))
|
|
1169 | - hmTTHash.remove(engine->ttInterpreterVersionDefault);
|
|
1170 | - if (hmTTHash.contains(engine->ttInterpreterVersionOther))
|
|
1171 | - hmTTHash.remove(engine->ttInterpreterVersionOther);
|
|
1172 | - if (hmTTHash.contains(engine->ttInterpreterVersionOther1))
|
|
1173 | - hmTTHash.remove(engine->ttInterpreterVersionOther1);
|
|
1197 | + if (hmTTHash.contains(defaults.ttInterpreterVersionDefault))
|
|
1198 | + hmTTHash.remove(defaults.ttInterpreterVersionDefault);
|
|
1199 | + if (hmTTHash.contains(defaults.ttInterpreterVersionOther))
|
|
1200 | + hmTTHash.remove(defaults.ttInterpreterVersionOther);
|
|
1201 | + if (hmTTHash.contains(defaults.ttInterpreterVersionOther1))
|
|
1202 | + hmTTHash.remove(defaults.ttInterpreterVersionOther1);
|
|
1174 | 1203 | |
1175 | 1204 | QHash<int, int> hmCFFHash = hintingModesCFFHash;
|
1176 | - if (hmCFFHash.contains(engine->cffHintingEngineDefault))
|
|
1177 | - hmCFFHash.remove(engine->cffHintingEngineDefault);
|
|
1178 | - if (hmCFFHash.contains(engine->cffHintingEngineOther))
|
|
1179 | - hmCFFHash.remove(engine->cffHintingEngineOther);
|
|
1205 | + if (hmCFFHash.contains(defaults.cffHintingEngineDefault))
|
|
1206 | + hmCFFHash.remove(defaults.cffHintingEngineDefault);
|
|
1207 | + if (hmCFFHash.contains(defaults.cffHintingEngineOther))
|
|
1208 | + hmCFFHash.remove(defaults.cffHintingEngineOther);
|
|
1180 | 1209 | |
1181 | 1210 | // ... to construct a list of always disabled hinting mode combo box items
|
1182 | 1211 | hintingModesAlwaysDisabled = hmTTHash.values();
|
... | ... | @@ -1193,13 +1222,13 @@ MainGUI::setDefaults() |
1193 | 1222 | currentGlyphIndex = 0;
|
1194 | 1223 | |
1195 | 1224 | currentCFFHintingMode
|
1196 | - = hintingModesCFFHash[engine->cffHintingEngineDefault];
|
|
1225 | + = hintingModesCFFHash[defaults.cffHintingEngineDefault];
|
|
1197 | 1226 | currentTTInterpreterVersion
|
1198 | - = hintingModesTrueTypeHash[engine->ttInterpreterVersionDefault];
|
|
1227 | + = hintingModesTrueTypeHash[defaults.ttInterpreterVersionDefault];
|
|
1199 | 1228 | |
1200 | 1229 | hintingCheckBox->setChecked(true);
|
1201 | 1230 | |
1202 | - antiAliasingComboBoxx->setCurrentIndex(AntiAliasing_Normal);
|
|
1231 | + antiAliasingComboBoxx->setCurrentIndex(Engine::AntiAliasing_Normal);
|
|
1203 | 1232 | lcdFilterComboBox->setCurrentIndex(LCDFilter_Light);
|
1204 | 1233 | |
1205 | 1234 | horizontalHintingCheckBox->setChecked(true);
|
... | ... | @@ -230,17 +230,7 @@ private: |
230 | 230 | QWidget *leftWidget;
|
231 | 231 | QWidget *rightWidget;
|
232 | 232 | QWidget *mmgxTabWidget;
|
233 | - |
|
234 | - enum AntiAliasing
|
|
235 | - {
|
|
236 | - AntiAliasing_None,
|
|
237 | - AntiAliasing_Normal,
|
|
238 | - AntiAliasing_Light,
|
|
239 | - AntiAliasing_LCD,
|
|
240 | - AntiAliasing_LCD_BGR,
|
|
241 | - AntiAliasing_LCD_Vertical,
|
|
242 | - AntiAliasing_LCD_Vertical_BGR
|
|
243 | - };
|
|
233 | +
|
|
244 | 234 | enum HintingMode
|
245 | 235 | {
|
246 | 236 | HintingMode_TrueType_v35,
|
... | ... | @@ -262,15 +252,18 @@ private: |
262 | 252 | Units_pt
|
263 | 253 | };
|
264 | 254 | |
255 | + void showFont();
|
|
256 | + void syncSettings();
|
|
257 | + void clearStatusBar();
|
|
258 | + |
|
265 | 259 | void createActions();
|
266 | 260 | void createConnections();
|
267 | 261 | void createLayout();
|
268 | 262 | void createMenus();
|
269 | - void clearStatusBar();
|
|
270 | 263 | void createStatusBar();
|
271 | - void readSettings();
|
|
272 | 264 | void setGraphicsDefaults();
|
273 | - void showFont();
|
|
265 | + |
|
266 | + void readSettings();
|
|
274 | 267 | void writeSettings();
|
275 | 268 | };
|
276 | 269 |