freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][reorg-maingui] 3 commits: [ftinspect] Mov


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][reorg-maingui] 3 commits: [ftinspect] Move out font file managing/watching out to a new class.
Date: Wed, 29 Jun 2022 15:00:43 +0000

Charlie Jiang pushed to branch reorg-maingui at FreeType / FreeType Demo Programs

Commits:

  • 600a9006
    by Charlie Jiang at 2022-06-29T22:57:23+08:00
    [ftinspect] Move out font file managing/watching out to a new class.
    
    * src/ftinspect/CMakeLists.txt: Add `fontfilemanager.cpp`.
    
    * src/ftinspect/meson.build: Add `fontfilemanager.cpp`.
    
    * src/ftinspect/fontfilemanager.hpp: Font file managing/watching goes here.
    
    * src/ftinspect/fontfilemanager.cpp: Font file managing/watching goes here.
    
    * src/ftinspect/maingui.hpp: Remove `fontList`, `fontWatcher` and `timer`..
    
    * src/ftinspect/maingui.cpp: Remove code related to font file managing, they
    were all moved to `FontFileManager` class.
    
    * src/ftinspect/engine.hpp: `Engine` class now holds `FontFileManager`. Also,
    `MainGUI` will open and close fonts indirectly via `Engine`.
    
    * src/ftinspect/engine.cpp: Same as `engine.hpp`.
    
    TODO: Maybe we should remove dependency against `FontFileManager` from
    `MainGUI`?
    
  • 19ad7297
    by Charlie Jiang at 2022-06-29T22:58:06+08:00
    [ftinspect] Decouple `Engine` from `MainGUI`.
    
    Relevant info can be found in #13. This commit removes dependency against
    `MainGUI` from `Engine` class. All settings will be explicitly passed via
    setters of `Engine`. Also see `MainGUI::syncSettings` and simplified
    `Engine::update`.
    
    This commit removes friend relation between the two classes.
    
    TODO: Some GUI components in MainGUI lacks proper connections. When changing
    their value, the glyph isn't updated in time.
    
    * src/ftinspect/ftinspect.cpp: No longer need to pass GUI when constructing
    `Engine`.
    
    * src/ftinspect/maingui.hpp: Move `AntiAliasing` enum to `Engine` class, add
    `syncSettings` function, reorder some functions.
    
    * src/ftinspect/maingui.cpp: Because of the removal of friend relationship,
    change all access to private fields of `Engine` to getter/setter call.
    Add implementation of `syncSettings`, and make sure it's called before
    loading font and rendering. Moving of `AntiAliasing` enum is also taken care
    of.
    
    * src/ftinspect/engine/engine.hpp: Removed dependency against `MainGUI`.
    Added getters/setters and reordered some functions. The default values
    queried from engine are all grouped together into `EngineDefaultValues`
    struct.
    Added `queryEngine` function (see below).
    New `setSizeByPoint` and `setSizeByPoint` lifted the branch to `MainGUI`.
    Note: Setters of LCD filter mode, CFF mode and TTI version now accepts the
    actual values of FreeType instead of values of enums in `MainGUI` used to
    initialize combo boxes.
    However, `antiAliasingMode` is still using enum values (but moved into
    `Engine`) because it's complex to convert to FreeType value.
    
    * src/ftinspect/engine/engine.cpp: `faceRequester` now use the `Engine`
    object instead of `MainGUI` as `requestData`.
    Moved code preparing engine default values to the `queryEngine` function.
    Moved some single-line getters to the header file to benefit from inlineing.
    Simplified `update` function since we no longer need to actively fetch
    settings.
    `usingPixelSize` is used to determine if pixel or point unit is used. This
    flag is updated by `setSizeByPixel` and `setSizeByPoint` functions.
    
  • 7d0d3a57
    by Charlie Jiang at 2022-06-29T22:59:12+08:00
    [ftinspect] Rename all private member variables with an underscore suffix.
    
    (pure mechnical commit)
    
    * src/ftinspect/**: Renaming. Also some variables with abbreviations
    were renamed.
    
    This will enable nicer getter/setters, as discussed in #13.
    

21 changed files:

Changes:

  • src/ftinspect/CMakeLists.txt
    ... ... @@ -20,6 +20,7 @@ add_executable(ftinspect
    20 20
       "maingui.cpp"
    
    21 21
       
    
    22 22
       "engine/engine.cpp"
    
    23
    +  "engine/fontfilemanager.cpp"
    
    23 24
     
    
    24 25
       "rendering/glyphbitmap.cpp"
    
    25 26
       "rendering/glyphoutline.cpp"
    

  • src/ftinspect/engine/engine.cpp
    ... ... @@ -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->fontList.size())
    
    96
    +      || faceID.fontIndex >= engine->numberOfOpenedFonts())
    
    98 97
         return FT_Err_Invalid_Argument;
    
    99 98
     
    
    100
    -  QString& font = gui->fontList[faceID.fontIndex];
    
    99
    +  QString font = engine->fontFileManager_[faceID.fontIndex].filePath();
    
    101 100
       long faceIndex = faceID.faceIndex;
    
    102 101
     
    
    103 102
       if (faceID.namedInstanceIndex > 0)
    
    ... ... @@ -116,139 +115,47 @@ faceRequester(FTC_FaceID ftcFaceID,
    116 115
     //
    
    117 116
     /////////////////////////////////////////////////////////////////////////////
    
    118 117
     
    
    119
    -Engine::Engine(MainGUI* g)
    
    118
    +Engine::Engine()
    
    120 119
     {
    
    121
    -  gui = g;
    
    122
    -  ftSize = NULL;
    
    120
    +  ftSize_ = NULL;
    
    123 121
       // we reserve value 0 for the `invalid face ID'
    
    124
    -  faceCounter = 1;
    
    122
    +  faceCounter_ = 1;
    
    125 123
     
    
    126 124
       FT_Error error;
    
    127 125
     
    
    128
    -  error = FT_Init_FreeType(&library);
    
    126
    +  error = FT_Init_FreeType(&library_);
    
    129 127
       if (error)
    
    130 128
       {
    
    131 129
         // XXX error handling
    
    132 130
       }
    
    133 131
     
    
    134
    -  error = FTC_Manager_New(library, 0, 0, 0,
    
    135
    -                          faceRequester, gui, &cacheManager);
    
    132
    +  error = FTC_Manager_New(library_, 0, 0, 0,
    
    133
    +                          faceRequester, this, &cacheManager_);
    
    136 134
       if (error)
    
    137 135
       {
    
    138 136
         // XXX error handling
    
    139 137
       }
    
    140 138
     
    
    141
    -  error = FTC_SBitCache_New(cacheManager, &sbitsCache);
    
    139
    +  error = FTC_SBitCache_New(cacheManager_, &sbitsCache_);
    
    142 140
       if (error)
    
    143 141
       {
    
    144 142
         // XXX error handling
    
    145 143
       }
    
    146 144
     
    
    147
    -  error = FTC_ImageCache_New(cacheManager, &imageCache);
    
    145
    +  error = FTC_ImageCache_New(cacheManager_, &imageCache_);
    
    148 146
       if (error)
    
    149 147
       {
    
    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
     
    
    248 155
     Engine::~Engine()
    
    249 156
     {
    
    250
    -  FTC_Manager_Done(cacheManager);
    
    251
    -  FT_Done_FreeType(library);
    
    157
    +  FTC_Manager_Done(cacheManager_);
    
    158
    +  FT_Done_FreeType(library_);
    
    252 159
     }
    
    253 160
     
    
    254 161
     
    
    ... ... @@ -260,28 +167,28 @@ Engine::numberOfFaces(int fontIndex)
    260 167
     
    
    261 168
       // search triplet (fontIndex, 0, 0)
    
    262 169
       FTC_FaceID ftcFaceID = reinterpret_cast<FTC_FaceID>
    
    263
    -                           (faceIDMap.value(FaceID(fontIndex,
    
    170
    +                           (faceIDMap_.value(FaceID(fontIndex,
    
    264 171
                                                        0,
    
    265 172
                                                        0)));
    
    266 173
       if (ftcFaceID)
    
    267 174
       {
    
    268 175
         // found
    
    269
    -    if (!FTC_Manager_LookupFace(cacheManager, ftcFaceID, &face))
    
    176
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    270 177
           numFaces = face->num_faces;
    
    271 178
       }
    
    272 179
       else
    
    273 180
       {
    
    274 181
         // not found; try to load triplet (fontIndex, 0, 0)
    
    275
    -    ftcFaceID = reinterpret_cast<FTC_FaceID>(faceCounter);
    
    276
    -    faceIDMap.insert(FaceID(fontIndex, 0, 0),
    
    277
    -                     faceCounter++);
    
    182
    +    ftcFaceID = reinterpret_cast<FTC_FaceID>(faceCounter_);
    
    183
    +    faceIDMap_.insert(FaceID(fontIndex, 0, 0),
    
    184
    +                     faceCounter_++);
    
    278 185
     
    
    279
    -    if (!FTC_Manager_LookupFace(cacheManager, ftcFaceID, &face))
    
    186
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    280 187
           numFaces = face->num_faces;
    
    281 188
         else
    
    282 189
         {
    
    283
    -      faceIDMap.remove(FaceID(fontIndex, 0, 0));
    
    284
    -      faceCounter--;
    
    190
    +      faceIDMap_.remove(FaceID(fontIndex, 0, 0));
    
    191
    +      faceCounter_--;
    
    285 192
         }
    
    286 193
       }
    
    287 194
     
    
    ... ... @@ -300,28 +207,28 @@ Engine::numberOfNamedInstances(int fontIndex,
    300 207
     
    
    301 208
       // search triplet (fontIndex, faceIndex, 0)
    
    302 209
       FTC_FaceID ftcFaceID = reinterpret_cast<FTC_FaceID>
    
    303
    -                           (faceIDMap.value(FaceID(fontIndex,
    
    210
    +                           (faceIDMap_.value(FaceID(fontIndex,
    
    304 211
                                                        faceIndex,
    
    305 212
                                                        0)));
    
    306 213
       if (ftcFaceID)
    
    307 214
       {
    
    308 215
         // found
    
    309
    -    if (!FTC_Manager_LookupFace(cacheManager, ftcFaceID, &face))
    
    216
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    310 217
           numNamedInstances = static_cast<int>((face->style_flags >> 16) + 1);
    
    311 218
       }
    
    312 219
       else
    
    313 220
       {
    
    314 221
         // not found; try to load triplet (fontIndex, faceIndex, 0)
    
    315
    -    ftcFaceID = reinterpret_cast<FTC_FaceID>(faceCounter);
    
    316
    -    faceIDMap.insert(FaceID(fontIndex, faceIndex, 0),
    
    317
    -                     faceCounter++);
    
    222
    +    ftcFaceID = reinterpret_cast<FTC_FaceID>(faceCounter_);
    
    223
    +    faceIDMap_.insert(FaceID(fontIndex, faceIndex, 0),
    
    224
    +                     faceCounter_++);
    
    318 225
     
    
    319
    -    if (!FTC_Manager_LookupFace(cacheManager, ftcFaceID, &face))
    
    226
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    320 227
           numNamedInstances = static_cast<int>((face->style_flags >> 16) + 1);
    
    321 228
         else
    
    322 229
         {
    
    323
    -      faceIDMap.remove(FaceID(fontIndex, faceIndex, 0));
    
    324
    -      faceCounter--;
    
    230
    +      faceIDMap_.remove(FaceID(fontIndex, faceIndex, 0));
    
    231
    +      faceCounter_--;
    
    325 232
         }
    
    326 233
       }
    
    327 234
     
    
    ... ... @@ -335,60 +242,60 @@ Engine::loadFont(int fontIndex,
    335 242
                      int namedInstanceIndex)
    
    336 243
     {
    
    337 244
       int numGlyphs = -1;
    
    338
    -  fontType = FontType_Other;
    
    245
    +  fontType_ = FontType_Other;
    
    339 246
     
    
    340 247
       update();
    
    341 248
     
    
    342 249
       // search triplet (fontIndex, faceIndex, namedInstanceIndex)
    
    343
    -  scaler.face_id = reinterpret_cast<FTC_FaceID>
    
    344
    -                     (faceIDMap.value(FaceID(fontIndex,
    
    250
    +  scaler_.face_id = reinterpret_cast<FTC_FaceID>
    
    251
    +                     (faceIDMap_.value(FaceID(fontIndex,
    
    345 252
                                                  faceIndex,
    
    346 253
                                                  namedInstanceIndex)));
    
    347
    -  if (scaler.face_id)
    
    254
    +  if (scaler_.face_id)
    
    348 255
       {
    
    349 256
         // found
    
    350
    -    if (!FTC_Manager_LookupSize(cacheManager, &scaler, &ftSize))
    
    351
    -      numGlyphs = ftSize->face->num_glyphs;
    
    257
    +    if (!FTC_Manager_LookupSize(cacheManager_, &scaler_, &ftSize_))
    
    258
    +      numGlyphs = ftSize_->face->num_glyphs;
    
    352 259
       }
    
    353 260
       else
    
    354 261
       {
    
    355 262
         // not found; try to load triplet
    
    356 263
         // (fontIndex, faceIndex, namedInstanceIndex)
    
    357
    -    scaler.face_id = reinterpret_cast<FTC_FaceID>(faceCounter);
    
    358
    -    faceIDMap.insert(FaceID(fontIndex,
    
    264
    +    scaler_.face_id = reinterpret_cast<FTC_FaceID>(faceCounter_);
    
    265
    +    faceIDMap_.insert(FaceID(fontIndex,
    
    359 266
                                 faceIndex,
    
    360 267
                                 namedInstanceIndex),
    
    361
    -                     faceCounter++);
    
    268
    +                     faceCounter_++);
    
    362 269
     
    
    363
    -    if (!FTC_Manager_LookupSize(cacheManager, &scaler, &ftSize))
    
    364
    -      numGlyphs = ftSize->face->num_glyphs;
    
    270
    +    if (!FTC_Manager_LookupSize(cacheManager_, &scaler_, &ftSize_))
    
    271
    +      numGlyphs = ftSize_->face->num_glyphs;
    
    365 272
         else
    
    366 273
         {
    
    367
    -      faceIDMap.remove(FaceID(fontIndex,
    
    274
    +      faceIDMap_.remove(FaceID(fontIndex,
    
    368 275
                                   faceIndex,
    
    369 276
                                   namedInstanceIndex));
    
    370
    -      faceCounter--;
    
    277
    +      faceCounter_--;
    
    371 278
         }
    
    372 279
       }
    
    373 280
     
    
    374 281
       if (numGlyphs < 0)
    
    375 282
       {
    
    376
    -    ftSize = NULL;
    
    377
    -    curFamilyName = QString();
    
    378
    -    curStyleName = QString();
    
    283
    +    ftSize_ = NULL;
    
    284
    +    curFamilyName_ = QString();
    
    285
    +    curStyleName_ = QString();
    
    379 286
       }
    
    380 287
       else
    
    381 288
       {
    
    382
    -    curFamilyName = QString(ftSize->face->family_name);
    
    383
    -    curStyleName = QString(ftSize->face->style_name);
    
    289
    +    curFamilyName_ = QString(ftSize_->face->family_name);
    
    290
    +    curStyleName_ = QString(ftSize_->face->style_name);
    
    384 291
     
    
    385
    -    const char* moduleName = FT_FACE_DRIVER_NAME( ftSize->face );
    
    292
    +    const char* moduleName = FT_FACE_DRIVER_NAME( ftSize_->face );
    
    386 293
     
    
    387 294
         // XXX cover all available modules
    
    388 295
         if (!strcmp(moduleName, "cff"))
    
    389
    -      fontType = FontType_CFF;
    
    296
    +      fontType_ = FontType_CFF;
    
    390 297
         else if (!strcmp(moduleName, "truetype"))
    
    391
    -      fontType = FontType_TrueType;
    
    298
    +      fontType_ = FontType_TrueType;
    
    392 299
       }
    
    393 300
     
    
    394 301
       return numGlyphs;
    
    ... ... @@ -396,16 +303,16 @@ Engine::loadFont(int fontIndex,
    396 303
     
    
    397 304
     
    
    398 305
     void
    
    399
    -Engine::removeFont(int fontIndex)
    
    306
    +Engine::removeFont(int fontIndex, bool closeFile)
    
    400 307
     {
    
    401 308
       // we iterate over all triplets that contain the given font index
    
    402 309
       // and remove them
    
    403 310
       QMap<FaceID, FTC_IDType>::iterator iter
    
    404
    -    = faceIDMap.lowerBound(FaceID(fontIndex, 0, 0));
    
    311
    +    = faceIDMap_.lowerBound(FaceID(fontIndex, 0, 0));
    
    405 312
     
    
    406 313
       for (;;)
    
    407 314
       {
    
    408
    -    if (iter == faceIDMap.end())
    
    315
    +    if (iter == faceIDMap_.end())
    
    409 316
           break;
    
    410 317
     
    
    411 318
         FaceID faceID = iter.key();
    
    ... ... @@ -413,24 +320,13 @@ Engine::removeFont(int fontIndex)
    413 320
           break;
    
    414 321
     
    
    415 322
         FTC_FaceID ftcFaceID = reinterpret_cast<FTC_FaceID>(iter.value());
    
    416
    -    FTC_Manager_RemoveFaceID(cacheManager, ftcFaceID);
    
    323
    +    FTC_Manager_RemoveFaceID(cacheManager_, ftcFaceID);
    
    417 324
     
    
    418
    -    iter = faceIDMap.erase(iter);
    
    325
    +    iter = faceIDMap_.erase(iter);
    
    419 326
       }
    
    420
    -}
    
    421 327
     
    
    422
    -
    
    423
    -const QString&
    
    424
    -Engine::currentFamilyName()
    
    425
    -{
    
    426
    -  return curFamilyName;
    
    427
    -}
    
    428
    -
    
    429
    -
    
    430
    -const QString&
    
    431
    -Engine::currentStyleName()
    
    432
    -{
    
    433
    -  return curStyleName;
    
    328
    +  if (closeFile)
    
    329
    +    fontFileManager_.remove(fontIndex);
    
    434 330
     }
    
    435 331
     
    
    436 332
     
    
    ... ... @@ -442,10 +338,10 @@ Engine::glyphName(int index)
    442 338
       if (index < 0)
    
    443 339
         throw std::runtime_error("Invalid glyph index");
    
    444 340
     
    
    445
    -  if (ftSize && FT_HAS_GLYPH_NAMES(ftSize->face))
    
    341
    +  if (ftSize_ && FT_HAS_GLYPH_NAMES(ftSize_->face))
    
    446 342
       {
    
    447 343
         char buffer[256];
    
    448
    -    if (!FT_Get_Glyph_Name(ftSize->face,
    
    344
    +    if (!FT_Get_Glyph_Name(ftSize_->face,
    
    449 345
                                static_cast<unsigned int>(index),
    
    450 346
                                buffer,
    
    451 347
                                sizeof(buffer)))
    
    ... ... @@ -470,9 +366,9 @@ Engine::loadOutline(int glyphIndex)
    470 366
     
    
    471 367
       // the `scaler' object is set up by the
    
    472 368
       // `update' and `loadFont' methods
    
    473
    -  if (FTC_ImageCache_LookupScaler(imageCache,
    
    474
    -                                  &scaler,
    
    475
    -                                  loadFlags | FT_LOAD_NO_BITMAP,
    
    369
    +  if (FTC_ImageCache_LookupScaler(imageCache_,
    
    370
    +                                  &scaler_,
    
    371
    +                                  loadFlags_ | FT_LOAD_NO_BITMAP,
    
    476 372
                                       static_cast<unsigned int>(glyphIndex),
    
    477 373
                                       &glyph,
    
    478 374
                                       NULL))
    
    ... ... @@ -490,36 +386,70 @@ Engine::loadOutline(int glyphIndex)
    490 386
     }
    
    491 387
     
    
    492 388
     
    
    389
    +int
    
    390
    +Engine::numberOfOpenedFonts()
    
    391
    +{
    
    392
    +  return fontFileManager_.size();
    
    393
    +}
    
    394
    +
    
    395
    +
    
    493 396
     void
    
    494
    -Engine::setCFFHintingMode(int mode)
    
    397
    +Engine::openFonts(QStringList fontFileNames)
    
    398
    +{
    
    399
    +  fontFileManager_.append(fontFileNames);
    
    400
    +}
    
    401
    +
    
    402
    +
    
    403
    +void
    
    404
    +Engine::setSizeByPixel(double pixelSize)
    
    405
    +{
    
    406
    +  this->pixelSize_ = pixelSize;
    
    407
    +  pointSize_ = pixelSize * 72.0 / dpi_;
    
    408
    +  usingPixelSize_ = true;
    
    409
    +}
    
    410
    +
    
    411
    +void
    
    412
    +Engine::setSizeByPoint(double pointSize)
    
    413
    +{
    
    414
    +  this->pointSize_ = pointSize;
    
    415
    +  pixelSize_ = pointSize * dpi_ / 72.0;
    
    416
    +  usingPixelSize_ = false;
    
    417
    +}
    
    418
    +
    
    419
    +
    
    420
    +void
    
    421
    +Engine::setLcdFilter(FT_LcdFilter filter)
    
    495 422
     {
    
    496
    -  int index = gui->hintingModesCFFHash.key(mode);
    
    423
    +  FT_Library_SetLcdFilter(library_, filter);
    
    424
    +}
    
    497 425
     
    
    498
    -  FT_Error error = FT_Property_Set(library,
    
    426
    +
    
    427
    +void
    
    428
    +Engine::setCFFHintingMode(int mode)
    
    429
    +{
    
    430
    +  FT_Error error = FT_Property_Set(library_,
    
    499 431
                                        "cff",
    
    500 432
                                        "hinting-engine",
    
    501
    -                                   &index);
    
    433
    +                                   &mode);
    
    502 434
       if (!error)
    
    503 435
       {
    
    504 436
         // reset the cache
    
    505
    -    FTC_Manager_Reset(cacheManager);
    
    437
    +    FTC_Manager_Reset(cacheManager_);
    
    506 438
       }
    
    507 439
     }
    
    508 440
     
    
    509 441
     
    
    510 442
     void
    
    511
    -Engine::setTTInterpreterVersion(int mode)
    
    443
    +Engine::setTTInterpreterVersion(int version)
    
    512 444
     {
    
    513
    -  int index = gui->hintingModesTrueTypeHash.key(mode);
    
    514
    -
    
    515
    -  FT_Error error = FT_Property_Set(library,
    
    445
    +  FT_Error error = FT_Property_Set(library_,
    
    516 446
                                        "truetype",
    
    517 447
                                        "interpreter-version",
    
    518
    -                                   &index);
    
    448
    +                                   &version);
    
    519 449
       if (!error)
    
    520 450
       {
    
    521 451
         // reset the cache
    
    522
    -    FTC_Manager_Reset(cacheManager);
    
    452
    +    FTC_Manager_Reset(cacheManager_);
    
    523 453
       }
    
    524 454
     }
    
    525 455
     
    
    ... ... @@ -527,58 +457,32 @@ Engine::setTTInterpreterVersion(int mode)
    527 457
     void
    
    528 458
     Engine::update()
    
    529 459
     {
    
    530
    -  // Spinbox value cannot become negative
    
    531
    -  dpi = static_cast<unsigned int>(gui->dpiSpinBox->value());
    
    460
    +  loadFlags_ = FT_LOAD_DEFAULT;
    
    461
    +  if (doAutoHinting_)
    
    462
    +    loadFlags_ |= FT_LOAD_FORCE_AUTOHINT;
    
    463
    +  loadFlags_ |= FT_LOAD_NO_BITMAP; // XXX handle bitmap fonts also
    
    532 464
     
    
    533
    -  if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
    
    534
    -  {
    
    535
    -    pixelSize = gui->sizeDoubleSpinBox->value();
    
    536
    -    pointSize = pixelSize * 72.0 / dpi;
    
    537
    -  }
    
    538
    -  else
    
    539
    -  {
    
    540
    -    pointSize = gui->sizeDoubleSpinBox->value();
    
    541
    -    pixelSize = pointSize * dpi / 72.0;
    
    542
    -  }
    
    543
    -
    
    544
    -  doHinting = gui->hintingCheckBox->isChecked();
    
    545
    -
    
    546
    -  doAutoHinting = gui->autoHintingCheckBox->isChecked();
    
    547
    -  doHorizontalHinting = gui->horizontalHintingCheckBox->isChecked();
    
    548
    -  doVerticalHinting = gui->verticalHintingCheckBox->isChecked();
    
    549
    -  doBlueZoneHinting = gui->blueZoneHintingCheckBox->isChecked();
    
    550
    -  showSegments = gui->segmentDrawingCheckBox->isChecked();
    
    551
    -
    
    552
    -  gamma = gui->gammaSlider->value();
    
    553
    -
    
    554
    -  loadFlags = FT_LOAD_DEFAULT;
    
    555
    -  if (doAutoHinting)
    
    556
    -    loadFlags |= FT_LOAD_FORCE_AUTOHINT;
    
    557
    -  loadFlags |= FT_LOAD_NO_BITMAP; // XXX handle bitmap fonts also
    
    558
    -
    
    559
    -  int index = gui->antiAliasingComboBoxx->currentIndex();
    
    560
    -
    
    561
    -  if (doHinting)
    
    465
    +  if (doHinting_)
    
    562 466
       {
    
    563 467
         unsigned long target;
    
    564 468
     
    
    565
    -    if (index == MainGUI::AntiAliasing_None)
    
    469
    +    if (antiAliasingMode_ == AntiAliasing_None)
    
    566 470
           target = FT_LOAD_TARGET_MONO;
    
    567 471
         else
    
    568 472
         {
    
    569
    -      switch (index)
    
    473
    +      switch (antiAliasingMode_)
    
    570 474
           {
    
    571
    -      case MainGUI::AntiAliasing_Light:
    
    475
    +      case AntiAliasing_Light:
    
    572 476
             target = FT_LOAD_TARGET_LIGHT;
    
    573 477
             break;
    
    574 478
     
    
    575
    -      case MainGUI::AntiAliasing_LCD:
    
    576
    -      case MainGUI::AntiAliasing_LCD_BGR:
    
    479
    +      case AntiAliasing_LCD:
    
    480
    +      case AntiAliasing_LCD_BGR: // TODO Differenate RGB/BGR here?
    
    577 481
             target = FT_LOAD_TARGET_LCD;
    
    578 482
             break;
    
    579 483
     
    
    580
    -      case MainGUI::AntiAliasing_LCD_Vertical:
    
    581
    -      case MainGUI::AntiAliasing_LCD_Vertical_BGR:
    
    484
    +      case AntiAliasing_LCD_Vertical:
    
    485
    +      case AntiAliasing_LCD_Vertical_BGR:
    
    582 486
             target = FT_LOAD_TARGET_LCD_V;
    
    583 487
             break;
    
    584 488
     
    
    ... ... @@ -587,35 +491,134 @@ Engine::update()
    587 491
           }
    
    588 492
         }
    
    589 493
     
    
    590
    -    loadFlags |= target;
    
    494
    +    loadFlags_ |= target;
    
    591 495
       }
    
    592 496
       else
    
    593 497
       {
    
    594
    -    loadFlags |= FT_LOAD_NO_HINTING;
    
    498
    +    loadFlags_ |= FT_LOAD_NO_HINTING;
    
    595 499
     
    
    596
    -    if (index == MainGUI::AntiAliasing_None)
    
    597
    -      loadFlags |= FT_LOAD_MONOCHROME;
    
    500
    +    if (antiAliasingMode_ == AntiAliasing_None)
    
    501
    +      loadFlags_ |= FT_LOAD_MONOCHROME;
    
    598 502
       }
    
    599 503
     
    
    600 504
       // XXX handle color fonts also
    
    601 505
     
    
    602
    -  scaler.pixel = 0; // use 26.6 format
    
    506
    +  scaler_.pixel = 0; // use 26.6 format
    
    603 507
     
    
    604
    -  if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
    
    508
    +  if (usingPixelSize_)
    
    605 509
       {
    
    606
    -    scaler.width = static_cast<unsigned int>(pixelSize * 64.0);
    
    607
    -    scaler.height = static_cast<unsigned int>(pixelSize * 64.0);
    
    608
    -    scaler.x_res = 0;
    
    609
    -    scaler.y_res = 0;
    
    510
    +    scaler_.width = static_cast<unsigned int>(pixelSize_ * 64.0);
    
    511
    +    scaler_.height = static_cast<unsigned int>(pixelSize_ * 64.0);
    
    512
    +    scaler_.x_res = 0;
    
    513
    +    scaler_.y_res = 0;
    
    610 514
       }
    
    611 515
       else
    
    612 516
       {
    
    613
    -    scaler.width = static_cast<unsigned int>(pointSize * 64.0);
    
    614
    -    scaler.height = static_cast<unsigned int>(pointSize * 64.0);
    
    615
    -    scaler.x_res = dpi;
    
    616
    -    scaler.y_res = dpi;
    
    517
    +    scaler_.width = static_cast<unsigned int>(pointSize_ * 64.0);
    
    518
    +    scaler_.height = static_cast<unsigned int>(pointSize_ * 64.0);
    
    519
    +    scaler_.x_res = dpi_;
    
    520
    +    scaler_.y_res = dpi_;
    
    617 521
       }
    
    618 522
     }
    
    619 523
     
    
    620 524
     
    
    525
    +void
    
    526
    +Engine::queryEngine()
    
    527
    +{
    
    528
    +  FT_Error error;
    
    529
    +
    
    530
    +  // query engines and check for alternatives
    
    531
    +
    
    532
    +  // CFF
    
    533
    +  error = FT_Property_Get(library_,
    
    534
    +                          "cff",
    
    535
    +                          "hinting-engine",
    
    536
    +                          &engineDefaults_.cffHintingEngineDefault);
    
    537
    +  if (error)
    
    538
    +  {
    
    539
    +    // no CFF engine
    
    540
    +    engineDefaults_.cffHintingEngineDefault = -1;
    
    541
    +    engineDefaults_.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 (engineDefaults_.cffHintingEngineDefault == engines[i])
    
    554
    +        break;
    
    555
    +
    
    556
    +    engineDefaults_.cffHintingEngineOther = engines[(i + 1) % 2];
    
    557
    +
    
    558
    +    error = FT_Property_Set(library_,
    
    559
    +                            "cff",
    
    560
    +                            "hinting-engine",
    
    561
    +                            &engineDefaults_.cffHintingEngineOther);
    
    562
    +    if (error)
    
    563
    +      engineDefaults_.cffHintingEngineOther = -1;
    
    564
    +
    
    565
    +    // reset
    
    566
    +    FT_Property_Set(library_,
    
    567
    +                    "cff",
    
    568
    +                    "hinting-engine",
    
    569
    +                    &engineDefaults_.cffHintingEngineDefault);
    
    570
    +  }
    
    571
    +
    
    572
    +  // TrueType
    
    573
    +  error = FT_Property_Get(library_,
    
    574
    +                          "truetype",
    
    575
    +                          "interpreter-version",
    
    576
    +                          &engineDefaults_.ttInterpreterVersionDefault);
    
    577
    +  if (error)
    
    578
    +  {
    
    579
    +    // no TrueType engine
    
    580
    +    engineDefaults_.ttInterpreterVersionDefault = -1;
    
    581
    +    engineDefaults_.ttInterpreterVersionOther = -1;
    
    582
    +    engineDefaults_.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 (engineDefaults_.ttInterpreterVersionDefault == interpreters[i])
    
    596
    +        break;
    
    597
    +
    
    598
    +    engineDefaults_.ttInterpreterVersionOther = interpreters[(i + 1) % 3];
    
    599
    +
    
    600
    +    error = FT_Property_Set(library_,
    
    601
    +                            "truetype",
    
    602
    +                            "interpreter-version",
    
    603
    +                            &engineDefaults_.ttInterpreterVersionOther);
    
    604
    +    if (error)
    
    605
    +      engineDefaults_.ttInterpreterVersionOther = -1;
    
    606
    +
    
    607
    +    engineDefaults_.ttInterpreterVersionOther1 = interpreters[(i + 2) % 3];
    
    608
    +
    
    609
    +    error = FT_Property_Set(library_,
    
    610
    +                            "truetype",
    
    611
    +                            "interpreter-version",
    
    612
    +                            &engineDefaults_.ttInterpreterVersionOther1);
    
    613
    +    if (error)
    
    614
    +      engineDefaults_.ttInterpreterVersionOther1 = -1;
    
    615
    +
    
    616
    +    // reset
    
    617
    +    FT_Property_Set(library_,
    
    618
    +                    "truetype",
    
    619
    +                    "interpreter-version",
    
    620
    +                    &engineDefaults_.ttInterpreterVersionDefault);
    
    621
    +  }
    
    622
    +}
    
    623
    +
    
    621 624
     // end of engine.cpp

  • src/ftinspect/engine/engine.hpp
    ... ... @@ -5,6 +5,8 @@
    5 5
     
    
    6 6
     #pragma once
    
    7 7
     
    
    8
    +#include "fontfilemanager.hpp"
    
    9
    +
    
    8 10
     #include <QString>
    
    9 11
     #include <QMap>
    
    10 12
     
    
    ... ... @@ -12,6 +14,7 @@
    12 14
     #include <freetype/freetype.h>
    
    13 15
     #include <freetype/ftoutln.h>
    
    14 16
     #include <freetype/ftcache.h>
    
    17
    +#include <freetype/ftlcdfil.h>
    
    15 18
     
    
    16 19
     
    
    17 20
     // This structure maps the (font, face, instance) index triplet to abstract
    
    ... ... @@ -33,87 +36,165 @@ struct FaceID
    33 36
       bool operator<(const FaceID& other) const;
    
    34 37
     };
    
    35 38
     
    
    36
    -
    
    37
    -class MainGUI;
    
    38
    -
    
    39 39
     // FreeType specific data.
    
    40 40
     
    
    41 41
     class Engine
    
    42 42
     {
    
    43 43
     public:
    
    44
    -  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();
    
    45 63
       ~Engine();
    
    46 64
     
    
    47
    -  const QString& currentFamilyName();
    
    48
    -  const QString& currentStyleName();
    
    49
    -  QString glyphName(int glyphIndex);
    
    50
    -  long numberOfFaces(int fontIndex);
    
    51
    -  int numberOfNamedInstances(int fontIndex,
    
    52
    -                             long faceIndex);
    
    65
    +  // Disable copying
    
    66
    +  Engine(const Engine& other) = delete;
    
    67
    +  Engine& operator=(const Engine& other) = delete;
    
    68
    +
    
    69
    +  //////// Actions
    
    70
    +
    
    53 71
       int loadFont(int fontIndex,
    
    54 72
                    long faceIndex,
    
    55 73
                    int namedInstanceIndex); // return number of glyphs
    
    56 74
       FT_Outline* loadOutline(int glyphIndex);
    
    57
    -  void removeFont(int fontIndex);
    
    75
    +
    
    76
    +  void openFonts(QStringList fontFileNames);
    
    77
    +  void removeFont(int fontIndex, bool closeFile = true);
    
    78
    +  
    
    79
    +  void update();
    
    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 fontFileManager_; }
    
    97
    +  EngineDefaultValues& engineDefaults() { return engineDefaults_; }
    
    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;