freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][gsoc-2022-chariri-final] 2 commits: [ftin


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][gsoc-2022-chariri-final] 2 commits: [ftinspect] WIP: Rewrite `MainGUI`.
Date: Sat, 03 Sep 2022 14:28:13 +0000

Charlie Jiang pushed to branch gsoc-2022-chariri-final at FreeType / FreeType Demo Programs

Commits:

  • 721eab6f
    by Charlie Jiang at 2022-09-02T21:18:01+08:00
    [ftinspect] WIP: Rewrite `MainGUI`.
    
    Note: This commit doesn't compile. This change is splitted into 2 commits
    to avoid a complicated diff.
    
    * src/ftinspect/maingui.cpp, src/ftinspect/maingui.hpp: Old version removed.
    
  • 665ae2ef
    by Charlie Jiang at 2022-09-03T22:10:51+08:00
    [ftinspect] Rewrite `MainGUI`.
    
    Note: This commit compiles, but the main view is removed, so you will get a
    blank right panel. The singular view will be added back with major changes
    in the next commit.
    
    This commit mainly introduces below changes:
    
    1. The original `MainGUI` contains almost all GUI elements. Most of them are
       taken out to modular components. The current `MainGUI` serves only as
       a skeleton provides coordinate between components, greatly shortened.
       It also provides some auxiliary code such as calling to file chooser.
    2. The left panel is moved to `SettingPanel` class. The current
       `settingpanel.[ch]pp` are directly modified from the latest code, so they
       contains some options not implemented in the `Engine`.
       Structural code that is only added accompanying later change is removed,
       such as the comparator mode. Such code will be added back with the
       related feature. However, code for unimplemented options are simply
       commented out.
    3. The main part is transformed into a tabbed view. The original code is
       removed. Refactored, it will be added back in the next commit.
    4. The navigation buttons (Next/Prev Font/Face/NI) are changed into the new
       triplet-selector, which is a major UI improvement.
    
    * src/ftinspect/maingui.cpp, src/ftinspect/maingui.hpp: As described.
    
    * src/ftinspect/panels/abstracttab.hpp: Add `AbstractTab` which is an
      interface for all tabs listening for font reloading and repainting.
    
    * src/ftinspect/panels/settingpanel.cpp,
      src/ftinspect/panels/settingpanel.hpp:
      As described, this is the left panel. This requires intensive reviewing
      since many bugs had rooted here.
    
    * src/ftinspect/widgets/tripletselector.cpp,
      src/ftinspect/widgets/tripletselector.hpp:
      As described, this is the triplet (Font/Subface/NI) selector.
      This component is also responsible for repopulating triplet information
      and keep up with the font file change (i.e. the
      `FontFileManager::currentFileChanged` event is captured here).
    
    * src/ftinspect/engine/engine.cpp, src/ftinspect/engine/engine.hpp:
      Add `fontValid` and `namedInstanceName` since `TripletSelector` requires
      them. However, they'll subject to change later.
    
    * src/ftinspect/ftinspect.cpp: Remove call to `MainGUI::setDefaults`.
    
    * src/ftinspect/CMakeLists.txt, src/ftinspect/meson.build: Updated.
    

12 changed files:

Changes:

  • src/ftinspect/CMakeLists.txt
    ... ... @@ -30,8 +30,11 @@ add_executable(ftinspect
    30 30
       "glyphcomponents/grid.cpp"
    
    31 31
     
    
    32 32
       "widgets/customwidgets.cpp"
    
    33
    +  "widgets/tripletselector.cpp"
    
    33 34
     
    
    34 35
       "models/customcomboboxmodels.cpp"
    
    36
    +
    
    37
    +  "panels/settingpanel.cpp"
    
    35 38
     )
    
    36 39
     target_link_libraries(ftinspect
    
    37 40
       Qt5::Core Qt5::Widgets
    

  • src/ftinspect/engine/engine.cpp
    ... ... @@ -237,6 +237,50 @@ Engine::numberOfNamedInstances(int fontIndex,
    237 237
     }
    
    238 238
     
    
    239 239
     
    
    240
    +QString
    
    241
    +Engine::namedInstanceName(int fontIndex, long faceIndex, int index)
    
    242
    +{
    
    243
    +  if (fontIndex < 0)
    
    244
    +    return {};
    
    245
    +
    
    246
    +  FT_Face face;
    
    247
    +  QString name;
    
    248
    +
    
    249
    +  // search triplet (fontIndex, faceIndex, index)
    
    250
    +  FTC_FaceID ftcFaceID = reinterpret_cast<FTC_FaceID>
    
    251
    +                           (faceIDMap_.value(FaceID(fontIndex,
    
    252
    +                                                    faceIndex,
    
    253
    +                                                    index)));
    
    254
    +  if (ftcFaceID)
    
    255
    +  {
    
    256
    +    // found
    
    257
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    258
    +      name = QString("%1 %2")
    
    259
    +               .arg(face->family_name)
    
    260
    +               .arg(face->style_name);
    
    261
    +  }
    
    262
    +  else
    
    263
    +  {
    
    264
    +    // not found; try to load triplet (fontIndex, faceIndex, index)
    
    265
    +    ftcFaceID = reinterpret_cast<FTC_FaceID>(faceCounter_);
    
    266
    +    faceIDMap_.insert(FaceID(fontIndex, faceIndex, index),
    
    267
    +                      faceCounter_++);
    
    268
    +
    
    269
    +    if (!FTC_Manager_LookupFace(cacheManager_, ftcFaceID, &face))
    
    270
    +      name = QString("%1 %2")
    
    271
    +               .arg(face->family_name)
    
    272
    +               .arg(face->style_name);
    
    273
    +    else
    
    274
    +    {
    
    275
    +      faceIDMap_.remove(FaceID(fontIndex, faceIndex, 0));
    
    276
    +      faceCounter_--;
    
    277
    +    }
    
    278
    +  }
    
    279
    +
    
    280
    +  return name;
    
    281
    +}
    
    282
    +
    
    283
    +
    
    240 284
     int
    
    241 285
     Engine::loadFont(int fontIndex,
    
    242 286
                      long faceIndex,
    
    ... ... @@ -394,6 +438,14 @@ Engine::numberOfOpenedFonts()
    394 438
     }
    
    395 439
     
    
    396 440
     
    
    441
    +bool
    
    442
    +Engine::fontValid()
    
    443
    +{
    
    444
    +  // TODO: use fallback font
    
    445
    +  return ftSize_ != NULL;
    
    446
    +}
    
    447
    +
    
    448
    +
    
    397 449
     void
    
    398 450
     Engine::openFonts(QStringList fontFileNames)
    
    399 451
     {
    

  • src/ftinspect/engine/engine.hpp
    ... ... @@ -85,6 +85,7 @@ public:
    85 85
       int numberOfOpenedFonts();
    
    86 86
     
    
    87 87
       // (for current fonts)
    
    88
    +  bool fontValid();
    
    88 89
       int currentFontType() const { return fontType_; }
    
    89 90
       const QString& currentFamilyName() { return curFamilyName_; }
    
    90 91
       const QString& currentStyleName() { return curStyleName_; }
    
    ... ... @@ -92,6 +93,7 @@ public:
    92 93
       long numberOfFaces(int fontIndex);
    
    93 94
       int numberOfNamedInstances(int fontIndex,
    
    94 95
                                  long faceIndex);
    
    96
    +  QString namedInstanceName(int fontIndex, long faceIndex, int index);
    
    95 97
     
    
    96 98
       //////// Setters (direct or indirect)
    
    97 99
     
    

  • src/ftinspect/ftinspect.cpp
    ... ... @@ -23,7 +23,6 @@ main(int argc,
    23 23
     
    
    24 24
       Engine engine;
    
    25 25
       MainGUI gui(&engine);
    
    26
    -  gui.setDefaults();
    
    27 26
     
    
    28 27
       gui.show();
    
    29 28
     
    

  • src/ftinspect/maingui.cpp
    ... ... @@ -4,30 +4,27 @@
    4 4
     
    
    5 5
     
    
    6 6
     #include "maingui.hpp"
    
    7
    -#include "glyphcomponents/grid.hpp"
    
    8
    -#include "uihelper.hpp"
    
    9 7
     
    
    10 8
     #include <QApplication>
    
    11 9
     #include <QFileDialog>
    
    12 10
     #include <QMessageBox>
    
    13 11
     #include <QSettings>
    
    14
    -
    
    15
    -#include <freetype/ftdriver.h>
    
    12
    +#include <QScrollBar>
    
    13
    +#include <QStatusBar>
    
    16 14
     
    
    17 15
     
    
    18 16
     MainGUI::MainGUI(Engine* engine)
    
    19 17
     : engine_(engine)
    
    20 18
     {
    
    21
    -  setGraphicsDefaults();
    
    22 19
       createLayout();
    
    23 20
       createConnections();
    
    24 21
       createActions();
    
    25 22
       createMenus();
    
    26
    -  createStatusBar();
    
    27 23
     
    
    28 24
       readSettings();
    
    29
    -
    
    30 25
       setUnifiedTitleAndToolBarOnMac(true);
    
    26
    +
    
    27
    +  show();
    
    31 28
     }
    
    32 29
     
    
    33 30
     
    
    ... ... @@ -47,6 +44,15 @@ MainGUI::closeEvent(QCloseEvent* event)
    47 44
     }
    
    48 45
     
    
    49 46
     
    
    47
    +void
    
    48
    +MainGUI::keyPressEvent(QKeyEvent* event)
    
    49
    +{
    
    50
    +  // Delegate key events to tabs
    
    51
    +  if (!tabWidget_->currentWidget()->eventFilter(this, event))
    
    52
    +    QMainWindow::keyPressEvent(event);
    
    53
    +}
    
    54
    +
    
    55
    +
    
    50 56
     void
    
    51 57
     MainGUI::about()
    
    52 58
     {
    
    ... ... @@ -81,8 +87,6 @@ MainGUI::aboutQt()
    81 87
     void
    
    82 88
     MainGUI::loadFonts()
    
    83 89
     {
    
    84
    -  int oldSize = engine_->numberOfOpenedFonts();
    
    85
    -
    
    86 90
       QStringList files = QFileDialog::getOpenFileNames(
    
    87 91
                             this,
    
    88 92
                             tr("Load one or more fonts"),
    
    ... ... @@ -90,630 +94,60 @@ MainGUI::loadFonts()
    90 94
                             "",
    
    91 95
                             NULL,
    
    92 96
                             QFileDialog::ReadOnly);
    
    93
    -
    
    94
    -  engine_->openFonts(files);
    
    95
    -
    
    96
    -  // if we have new fonts, set the current index to the first new one
    
    97
    -  if (oldSize < engine_->numberOfOpenedFonts())
    
    98
    -    currentFontIndex_ = oldSize;
    
    99
    -
    
    100
    -  showFont();
    
    101
    -}
    
    102
    -
    
    103
    -
    
    104
    -void
    
    105
    -MainGUI::closeFont()
    
    106
    -{
    
    107
    -  if (currentFontIndex_ < engine_->numberOfOpenedFonts())
    
    108
    -  {
    
    109
    -    engine_->removeFont(currentFontIndex_);
    
    110
    -  }
    
    111
    -
    
    112
    -  // show next font after deletion, i.e., retain index if possible
    
    113
    -  int num = engine_->numberOfOpenedFonts();
    
    114
    -  if (num)
    
    115
    -  {
    
    116
    -    if (currentFontIndex_ >= num)
    
    117
    -      currentFontIndex_ = num - 1;
    
    118
    -  }
    
    119
    -  else
    
    120
    -    currentFontIndex_ = 0;
    
    121
    -
    
    122
    -  showFont();
    
    123
    -}
    
    124
    -
    
    125
    -
    
    126
    -void
    
    127
    -MainGUI::watchCurrentFont()
    
    128
    -{
    
    129
    -  showFont();
    
    130
    -}
    
    131
    -
    
    132
    -
    
    133
    -void
    
    134
    -MainGUI::showFont()
    
    135
    -{
    
    136
    -  // we do lazy computation of FT_Face objects
    
    137
    -
    
    138
    -  if (currentFontIndex_ < engine_->numberOfOpenedFonts())
    
    139
    -  {
    
    140
    -    QFileInfo& fileInfo = engine_->fontFileManager()[currentFontIndex_];
    
    141
    -    QString fontName = fileInfo.fileName();
    
    142
    -
    
    143
    -    engine_->fontFileManager().updateWatching(currentFontIndex_);
    
    144
    -    if (fileInfo.isSymLink())
    
    145
    -    {
    
    146
    -      fontName.prepend("<i>");
    
    147
    -      fontName.append("</i>");
    
    148
    -    }
    
    149
    -
    
    150
    -    if (!fileInfo.exists())
    
    151
    -    {
    
    152
    -      // On Unix-like systems, the symlink's target gets opened; this
    
    153
    -      // implies that deletion of a symlink doesn't make `engine->loadFont'
    
    154
    -      // fail since it operates on a file handle pointing to the target.
    
    155
    -      // For this reason, we remove the font to enforce a reload.
    
    156
    -      // However, we're just removing it from the Engine cache,
    
    157
    -      // not deleting the entry in the font file manager
    
    158
    -      engine_->removeFont(currentFontIndex_, false);
    
    159
    -    }
    
    160
    -
    
    161
    -    fontFilenameLabel_->setText(fontName);
    
    162
    -  }
    
    163
    -  else
    
    164
    -    fontFilenameLabel_->clear();
    
    165
    -
    
    166
    -  applySettings();
    
    167
    -  currentNumberOfFaces_
    
    168
    -    = engine_->numberOfFaces(currentFontIndex_);
    
    169
    -  currentNumberOfNamedInstances_
    
    170
    -    = engine_->numberOfNamedInstances(currentFontIndex_,
    
    171
    -                                     currentFaceIndex_);
    
    172
    -  currentNumberOfGlyphs_
    
    173
    -    = engine_->loadFont(currentFontIndex_,
    
    174
    -                       currentFaceIndex_,
    
    175
    -                       currentNamedInstanceIndex_);
    
    176
    -
    
    177
    -  if (currentNumberOfGlyphs_ < 0)
    
    178
    -  {
    
    179
    -    // there might be various reasons why the current
    
    180
    -    // (file, face, instance) triplet is invalid or missing;
    
    181
    -    // we thus start our timer to periodically test
    
    182
    -    // whether the font starts working
    
    183
    -    if (currentFontIndex_ > 0
    
    184
    -        && currentFontIndex_ < engine_->numberOfOpenedFonts())
    
    185
    -      engine_->fontFileManager().timerStart();
    
    186
    -  }
    
    187
    -
    
    188
    -  fontNameLabel_->setText(QString("%1 %2")
    
    189
    -                         .arg(engine_->currentFamilyName())
    
    190
    -                         .arg(engine_->currentStyleName()));
    
    191
    -
    
    192
    -  checkCurrentFontIndex();
    
    193
    -  checkCurrentFaceIndex();
    
    194
    -  checkCurrentNamedInstanceIndex();
    
    195
    -  checkHinting();
    
    196
    -  adjustGlyphIndex(0);
    
    197
    -
    
    198
    -  drawGlyph();
    
    199
    -}
    
    200
    -
    
    201
    -
    
    202
    -void
    
    203
    -MainGUI::applySettings()
    
    204
    -{
    
    205
    -  // Spinbox value cannot become negative
    
    206
    -  engine_->setDPI(static_cast<unsigned int>(dpiSpinBox_->value()));
    
    207
    -
    
    208
    -  if (unitsComboBox_->currentIndex() == Units_px)
    
    209
    -    engine_->setSizeByPixel(sizeDoubleSpinBox_->value());
    
    210
    -  else
    
    211
    -    engine_->setSizeByPoint(sizeDoubleSpinBox_->value());
    
    212
    -
    
    213
    -  engine_->setHinting(hintingCheckBox_->isChecked());
    
    214
    -  engine_->setAutoHinting(autoHintingCheckBox_->isChecked());
    
    215
    -  engine_->setHorizontalHinting(horizontalHintingCheckBox_->isChecked());
    
    216
    -  engine_->setVerticalHinting(verticalHintingCheckBox_->isChecked());
    
    217
    -  engine_->setBlueZoneHinting(blueZoneHintingCheckBox_->isChecked());
    
    218
    -  engine_->setShowSegments(segmentDrawingCheckBox_->isChecked());
    
    219
    -
    
    220
    -  engine_->setGamma(gammaSlider_->value());
    
    221
    -
    
    222
    -  engine_->setAntiAliasingTarget(
    
    223
    -    antiAliasingComboBoxModel_
    
    224
    -      ->indexToValue(antiAliasingComboBox_->currentIndex())
    
    225
    -      .loadFlag);
    
    226
    -}
    
    227
    -
    
    228
    -
    
    229
    -void
    
    230
    -MainGUI::clearStatusBar()
    
    231
    -{
    
    232
    -  statusBar()->clearMessage();
    
    233
    -  statusBar()->setStyleSheet("");
    
    234
    -}
    
    235
    -
    
    236
    -
    
    237
    -void
    
    238
    -MainGUI::checkHinting()
    
    239
    -{
    
    240
    -  if (hintingCheckBox_->isChecked())
    
    241
    -  {
    
    242
    -    if (engine_->currentFontType() == Engine::FontType_CFF)
    
    243
    -    {
    
    244
    -      hintingModeComboBoxModel_->setCurrentEngineType(
    
    245
    -        HintingModeComboBoxModel::HintingEngineType_CFF, false); // XXX tricky
    
    246
    -      hintingModeComboBox_->setCurrentIndex(currentCFFHintingMode_);
    
    247
    -    }
    
    248
    -    else if (engine_->currentFontType() == Engine::FontType_TrueType)
    
    249
    -    {
    
    250
    -      hintingModeComboBoxModel_->setCurrentEngineType( // XXX tricky
    
    251
    -        HintingModeComboBoxModel::HintingEngineType_TrueType, false);
    
    252
    -      hintingModeComboBox_->setCurrentIndex(currentTTInterpreterVersion_);
    
    253
    -    }
    
    254
    -    else
    
    255
    -    {
    
    256
    -      hintingModeLabel_->setEnabled(false);
    
    257
    -      hintingModeComboBox_->setEnabled(false);
    
    258
    -    }
    
    259
    -
    
    260
    -    autoHintingCheckBox_->setEnabled(true);
    
    261
    -    checkAutoHinting();
    
    262
    -  }
    
    263
    -  else
    
    264
    -  {
    
    265
    -    hintingModeLabel_->setEnabled(false);
    
    266
    -    hintingModeComboBox_->setEnabled(false);
    
    267
    -
    
    268
    -    autoHintingCheckBox_->setEnabled(false);
    
    269
    -    horizontalHintingCheckBox_->setEnabled(false);
    
    270
    -    verticalHintingCheckBox_->setEnabled(false);
    
    271
    -    blueZoneHintingCheckBox_->setEnabled(false);
    
    272
    -    segmentDrawingCheckBox_->setEnabled(false);
    
    273
    -
    
    274
    -    antiAliasingComboBoxModel_->setLightAntiAliasingEnabled(false);
    
    275
    -    if (antiAliasingComboBox_->currentIndex()
    
    276
    -      == AntiAliasingComboBoxModel::AntiAliasing_Light)
    
    277
    -      antiAliasingComboBox_->setCurrentIndex(
    
    278
    -        AntiAliasingComboBoxModel::AntiAliasing_Normal);
    
    279
    -  }
    
    280
    -
    
    281
    -  drawGlyph();
    
    282
    -}
    
    283
    -
    
    284
    -
    
    285
    -void
    
    286
    -MainGUI::checkHintingMode()
    
    287
    -{
    
    288
    -  int index = hintingModeComboBox_->currentIndex();
    
    289
    -
    
    290
    -  if (engine_->currentFontType() == Engine::FontType_CFF)
    
    291
    -  {
    
    292
    -    engine_->setCFFHintingMode(
    
    293
    -      hintingModeComboBoxModel_->indexToCFFMode(index));
    
    294
    -    currentCFFHintingMode_ = index;
    
    295
    -  }
    
    296
    -  else if (engine_->currentFontType() == Engine::FontType_TrueType)
    
    297
    -  {
    
    298
    -    engine_->setTTInterpreterVersion(
    
    299
    -      hintingModeComboBoxModel_->indexToTTInterpreterVersion(index));
    
    300
    -    currentTTInterpreterVersion_ = index;
    
    301
    -  }
    
    302
    -
    
    303
    -  // this enforces reloading of the font
    
    304
    -  showFont();
    
    305
    -}
    
    306
    -
    
    307
    -
    
    308
    -void
    
    309
    -MainGUI::checkAutoHinting()
    
    310
    -{
    
    311
    -  if (autoHintingCheckBox_->isChecked())
    
    312
    -  {
    
    313
    -    hintingModeLabel_->setEnabled(false);
    
    314
    -    hintingModeComboBox_->setEnabled(false);
    
    315
    -
    
    316
    -    horizontalHintingCheckBox_->setEnabled(true);
    
    317
    -    verticalHintingCheckBox_->setEnabled(true);
    
    318
    -    blueZoneHintingCheckBox_->setEnabled(true);
    
    319
    -    segmentDrawingCheckBox_->setEnabled(true);
    
    320
    -
    
    321
    -    antiAliasingComboBoxModel_->setLightAntiAliasingEnabled(true);
    
    322
    -  }
    
    323
    -  else
    
    324
    -  {
    
    325
    -    if (engine_->currentFontType() == Engine::FontType_CFF
    
    326
    -        || engine_->currentFontType() == Engine::FontType_TrueType)
    
    327
    -    {
    
    328
    -      hintingModeLabel_->setEnabled(true);
    
    329
    -      hintingModeComboBox_->setEnabled(true);
    
    330
    -    }
    
    331
    -
    
    332
    -    horizontalHintingCheckBox_->setEnabled(false);
    
    333
    -    verticalHintingCheckBox_->setEnabled(false);
    
    334
    -    blueZoneHintingCheckBox_->setEnabled(false);
    
    335
    -    segmentDrawingCheckBox_->setEnabled(false);
    
    336
    -
    
    337
    -    antiAliasingComboBoxModel_->setLightAntiAliasingEnabled(false);
    
    338
    -
    
    339
    -    if (antiAliasingComboBox_->currentIndex()
    
    340
    -        == AntiAliasingComboBoxModel::AntiAliasing_Light)
    
    341
    -      antiAliasingComboBox_->setCurrentIndex(
    
    342
    -          AntiAliasingComboBoxModel::AntiAliasing_Normal);
    
    343
    -  }
    
    344
    -
    
    345
    -  drawGlyph();
    
    346
    -}
    
    347
    -
    
    348
    -
    
    349
    -void
    
    350
    -MainGUI::checkAntiAliasing()
    
    351
    -{
    
    352
    -  int index = antiAliasingComboBox_->currentIndex();
    
    353
    -
    
    354
    -  if (index == AntiAliasingComboBoxModel::AntiAliasing_None
    
    355
    -      || index == AntiAliasingComboBoxModel::AntiAliasing_Normal
    
    356
    -      || index == AntiAliasingComboBoxModel::AntiAliasing_Light)
    
    357
    -  {
    
    358
    -    lcdFilterLabel_->setEnabled(false);
    
    359
    -    lcdFilterComboBox_->setEnabled(false);
    
    360
    -  }
    
    361
    -  else
    
    362
    -  {
    
    363
    -    lcdFilterLabel_->setEnabled(true);
    
    364
    -    lcdFilterComboBox_->setEnabled(true);
    
    365
    -  }
    
    366
    -
    
    367
    -  drawGlyph();
    
    368
    -}
    
    369
    -
    
    370
    -
    
    371
    -void
    
    372
    -MainGUI::checkLcdFilter()
    
    373
    -{
    
    374
    -  int index = lcdFilterComboBox_->currentIndex();
    
    375
    -  engine_->setLcdFilter(static_cast<FT_LcdFilter>(
    
    376
    -    lcdFilterComboboxModel_->indexToValue(index)));
    
    377
    -}
    
    378
    -
    
    379
    -
    
    380
    -void
    
    381
    -MainGUI::checkShowPoints()
    
    382
    -{
    
    383
    -  if (showPointsCheckBox_->isChecked())
    
    384
    -    showPointNumbersCheckBox_->setEnabled(true);
    
    385
    -  else
    
    386
    -    showPointNumbersCheckBox_->setEnabled(false);
    
    387
    -
    
    388
    -  drawGlyph();
    
    389
    -}
    
    390
    -
    
    391
    -
    
    392
    -void
    
    393
    -MainGUI::checkUnits()
    
    394
    -{
    
    395
    -  int index = unitsComboBox_->currentIndex();
    
    396
    -
    
    397
    -  if (index == Units_px)
    
    398
    -  {
    
    399
    -    dpiLabel_->setEnabled(false);
    
    400
    -    dpiSpinBox_->setEnabled(false);
    
    401
    -    sizeDoubleSpinBox_->setSingleStep(1);
    
    402
    -    sizeDoubleSpinBox_->setValue(qRound(sizeDoubleSpinBox_->value()));
    
    403
    -  }
    
    404
    -  else
    
    405
    -  {
    
    406
    -    dpiLabel_->setEnabled(true);
    
    407
    -    dpiSpinBox_->setEnabled(true);
    
    408
    -    sizeDoubleSpinBox_->setSingleStep(0.5);
    
    409
    -  }
    
    410
    -
    
    411
    -  drawGlyph();
    
    412
    -}
    
    413
    -
    
    414
    -
    
    415
    -void
    
    416
    -MainGUI::adjustGlyphIndex(int delta)
    
    417
    -{
    
    418
    -  // only adjust current glyph index if we have a valid font
    
    419
    -  if (currentNumberOfGlyphs_ > 0)
    
    420
    -  {
    
    421
    -    currentGlyphIndex_ += delta;
    
    422
    -    currentGlyphIndex_ = qBound(0,
    
    423
    -                               currentGlyphIndex_,
    
    424
    -                               currentNumberOfGlyphs_ - 1);
    
    425
    -  }
    
    426
    -
    
    427
    -  QString upperHex = QString::number(currentGlyphIndex_, 16).toUpper();
    
    428
    -  glyphIndexLabel_->setText(QString("%1 (0x%2)")
    
    429
    -                                   .arg(currentGlyphIndex_)
    
    430
    -                                   .arg(upperHex));
    
    431
    -  glyphNameLabel_->setText(engine_->glyphName(currentGlyphIndex_));
    
    432
    -
    
    433
    -  drawGlyph();
    
    97
    +  openFonts(files);
    
    434 98
     }
    
    435 99
     
    
    436 100
     
    
    437 101
     void
    
    438
    -MainGUI::checkCurrentFontIndex()
    
    102
    +MainGUI::openFonts(QStringList const& fileNames)
    
    439 103
     {
    
    440
    -  if (engine_->numberOfOpenedFonts() < 2)
    
    441
    -  {
    
    442
    -    previousFontButton_->setEnabled(false);
    
    443
    -    nextFontButton_->setEnabled(false);
    
    444
    -  }
    
    445
    -  else if (currentFontIndex_ == 0)
    
    446
    -  {
    
    447
    -    previousFontButton_->setEnabled(false);
    
    448
    -    nextFontButton_->setEnabled(true);
    
    449
    -  }
    
    450
    -  else if (currentFontIndex_ >= engine_->numberOfOpenedFonts() - 1)
    
    451
    -  {
    
    452
    -    previousFontButton_->setEnabled(true);
    
    453
    -    nextFontButton_->setEnabled(false);
    
    454
    -  }
    
    455
    -  else
    
    456
    -  {
    
    457
    -    previousFontButton_->setEnabled(true);
    
    458
    -    nextFontButton_->setEnabled(true);
    
    459
    -  }
    
    104
    +  engine_->openFonts(fileNames);
    
    105
    +  tripletSelector_->repopulateFonts();
    
    460 106
     }
    
    461 107
     
    
    462 108
     
    
    463 109
     void
    
    464
    -MainGUI::checkCurrentFaceIndex()
    
    110
    +MainGUI::onTripletChanged()
    
    465 111
     {
    
    466
    -  if (currentNumberOfFaces_ < 2)
    
    467
    -  {
    
    468
    -    previousFaceButton_->setEnabled(false);
    
    469
    -    nextFaceButton_->setEnabled(false);
    
    470
    -  }
    
    471
    -  else if (currentFaceIndex_ == 0)
    
    472
    -  {
    
    473
    -    previousFaceButton_->setEnabled(false);
    
    474
    -    nextFaceButton_->setEnabled(true);
    
    475
    -  }
    
    476
    -  else if (currentFaceIndex_ >= currentNumberOfFaces_ - 1)
    
    477
    -  {
    
    478
    -    previousFaceButton_->setEnabled(true);
    
    479
    -    nextFaceButton_->setEnabled(false);
    
    480
    -  }
    
    481
    -  else
    
    482
    -  {
    
    483
    -    previousFaceButton_->setEnabled(true);
    
    484
    -    nextFaceButton_->setEnabled(true);
    
    485
    -  }
    
    112
    +  auto state = settingPanel_->blockSignals(true);
    
    113
    +  settingPanel_->onFontChanged();
    
    114
    +  settingPanel_->blockSignals(state);
    
    115
    +  reloadCurrentTabFont();
    
    486 116
     }
    
    487 117
     
    
    488 118
     
    
    489 119
     void
    
    490
    -MainGUI::checkCurrentNamedInstanceIndex()
    
    120
    +MainGUI::switchTab()
    
    491 121
     {
    
    492
    -  if (currentNumberOfNamedInstances_ < 2)
    
    493
    -  {
    
    494
    -    previousNamedInstanceButton_->setEnabled(false);
    
    495
    -    nextNamedInstanceButton_->setEnabled(false);
    
    496
    -  }
    
    497
    -  else if (currentNamedInstanceIndex_ == 0)
    
    498
    -  {
    
    499
    -    previousNamedInstanceButton_->setEnabled(false);
    
    500
    -    nextNamedInstanceButton_->setEnabled(true);
    
    501
    -  }
    
    502
    -  else if (currentNamedInstanceIndex_ >= currentNumberOfNamedInstances_ - 1)
    
    503
    -  {
    
    504
    -    previousNamedInstanceButton_->setEnabled(true);
    
    505
    -    nextNamedInstanceButton_->setEnabled(false);
    
    506
    -  }
    
    507
    -  else
    
    508
    -  {
    
    509
    -    previousNamedInstanceButton_->setEnabled(true);
    
    510
    -    nextNamedInstanceButton_->setEnabled(true);
    
    511
    -  }
    
    122
    +  reloadCurrentTabFont();
    
    123
    +  lastTab_ = tabWidget_->currentWidget();
    
    512 124
     }
    
    513 125
     
    
    514 126
     
    
    515 127
     void
    
    516
    -MainGUI::previousFont()
    
    128
    +MainGUI::repaintCurrentTab()
    
    517 129
     {
    
    518
    -  if (currentFontIndex_ > 0)
    
    519
    -  {
    
    520
    -    currentFontIndex_--;
    
    521
    -    currentFaceIndex_ = 0;
    
    522
    -    currentNamedInstanceIndex_ = 0;
    
    523
    -    showFont();
    
    524
    -  }
    
    525
    -}
    
    526
    -
    
    527
    -
    
    528
    -void
    
    529
    -MainGUI::nextFont()
    
    530
    -{
    
    531
    -  if (currentFontIndex_ < engine_->numberOfOpenedFonts() - 1)
    
    532
    -  {
    
    533
    -    currentFontIndex_++;
    
    534
    -    currentFaceIndex_ = 0;
    
    535
    -    currentNamedInstanceIndex_ = 0;
    
    536
    -    showFont();
    
    537
    -  }
    
    538
    -}
    
    539
    -
    
    540
    -
    
    541
    -void
    
    542
    -MainGUI::previousFace()
    
    543
    -{
    
    544
    -  if (currentFaceIndex_ > 0)
    
    545
    -  {
    
    546
    -    currentFaceIndex_--;
    
    547
    -    currentNamedInstanceIndex_ = 0;
    
    548
    -    showFont();
    
    549
    -  }
    
    550
    -}
    
    551
    -
    
    552
    -
    
    553
    -void
    
    554
    -MainGUI::nextFace()
    
    555
    -{
    
    556
    -  if (currentFaceIndex_ < currentNumberOfFaces_ - 1)
    
    557
    -  {
    
    558
    -    currentFaceIndex_++;
    
    559
    -    currentNamedInstanceIndex_ = 0;
    
    560
    -    showFont();
    
    561
    -  }
    
    562
    -}
    
    563
    -
    
    564
    -
    
    565
    -void
    
    566
    -MainGUI::previousNamedInstance()
    
    567
    -{
    
    568
    -  if (currentNamedInstanceIndex_ > 0)
    
    569
    -  {
    
    570
    -    currentNamedInstanceIndex_--;
    
    571
    -    showFont();
    
    572
    -  }
    
    573
    -}
    
    574
    -
    
    575
    -
    
    576
    -void
    
    577
    -MainGUI::nextNamedInstance()
    
    578
    -{
    
    579
    -  if (currentNamedInstanceIndex_ < currentNumberOfNamedInstances_ - 1)
    
    580
    -  {
    
    581
    -    currentNamedInstanceIndex_++;
    
    582
    -    showFont();
    
    583
    -  }
    
    584
    -}
    
    585
    -
    
    586
    -
    
    587
    -void
    
    588
    -MainGUI::zoom()
    
    589
    -{
    
    590
    -  int scale = static_cast<int>(zoomSpinBox_->value());
    
    591
    -
    
    592
    -  QTransform transform;
    
    593
    -  transform.scale(scale, scale);
    
    594
    -
    
    595
    -  // we want horizontal and vertical 1px lines displayed with full pixels;
    
    596
    -  // we thus have to shift the coordinate system accordingly, using a value
    
    597
    -  // that represents 0.5px (i.e., half the 1px line width) after the scaling
    
    598
    -  qreal shift = 0.5 / scale;
    
    599
    -  transform.translate(shift, shift);
    
    600
    -
    
    601
    -  glyphView_->setTransform(transform);
    
    130
    +  applySettings();
    
    131
    +  tabs_[tabWidget_->currentIndex()]->repaintGlyph();
    
    602 132
     }
    
    603 133
     
    
    604 134
     
    
    605 135
     void
    
    606
    -MainGUI::setGraphicsDefaults()
    
    136
    +MainGUI::reloadCurrentTabFont()
    
    607 137
     {
    
    608
    -  // color tables (with suitable opacity values) for converting
    
    609
    -  // FreeType's pixmaps to something Qt understands
    
    610
    -  monoColorTable_.append(QColor(Qt::transparent).rgba());
    
    611
    -  monoColorTable_.append(QColor(Qt::black).rgba());
    
    612
    -
    
    613
    -  for (int i = 0xFF; i >= 0; i--)
    
    614
    -    grayColorTable_.append(qRgba(i, i, i, 0xFF - i));
    
    615
    -
    
    616
    -  // XXX make this user-configurable
    
    617
    -
    
    618
    -  axisPen_.setColor(Qt::black);
    
    619
    -  axisPen_.setWidth(0);
    
    620
    -  blueZonePen_.setColor(QColor(64, 64, 255, 64)); // light blue
    
    621
    -  blueZonePen_.setWidth(0);
    
    622
    -  gridPen_.setColor(Qt::lightGray);
    
    623
    -  gridPen_.setWidth(0);
    
    624
    -  offPen_.setColor(Qt::darkGreen);
    
    625
    -  offPen_.setWidth(3);
    
    626
    -  onPen_.setColor(Qt::red);
    
    627
    -  onPen_.setWidth(3);
    
    628
    -  outlinePen_.setColor(Qt::red);
    
    629
    -  outlinePen_.setWidth(0);
    
    630
    -  segmentPen_.setColor(QColor(64, 255, 128, 64)); // light green
    
    631
    -  segmentPen_.setWidth(0);
    
    138
    +  engine_->resetCache();
    
    139
    +  applySettings();
    
    140
    +  if (tabWidget_->currentIndex() > 0 
    
    141
    +      && static_cast<size_t>(tabWidget_->currentIndex()) < tabs_.size())
    
    142
    +    tabs_[tabWidget_->currentIndex()]->reloadFont();
    
    632 143
     }
    
    633 144
     
    
    634 145
     
    
    635 146
     void
    
    636
    -MainGUI::drawGlyph()
    
    147
    +MainGUI::applySettings()
    
    637 148
     {
    
    638
    -  // the call to `engine->loadOutline' updates FreeType's load flags
    
    639
    -
    
    640
    -  if (!engine_)
    
    641
    -    return;
    
    642
    -
    
    643
    -  if (currentGlyphBitmapItem_)
    
    644
    -  {
    
    645
    -    glyphScene_->removeItem(currentGlyphBitmapItem_);
    
    646
    -    delete currentGlyphBitmapItem_;
    
    647
    -
    
    648
    -    currentGlyphBitmapItem_ = NULL;
    
    649
    -  }
    
    650
    -
    
    651
    -  if (currentGlyphOutlineItem_)
    
    652
    -  {
    
    653
    -    glyphScene_->removeItem(currentGlyphOutlineItem_);
    
    654
    -    delete currentGlyphOutlineItem_;
    
    655
    -
    
    656
    -    currentGlyphOutlineItem_ = NULL;
    
    657
    -  }
    
    658
    -
    
    659
    -  if (currentGlyphPointsItem_)
    
    660
    -  {
    
    661
    -    glyphScene_->removeItem(currentGlyphPointsItem_);
    
    662
    -    delete currentGlyphPointsItem_;
    
    663
    -
    
    664
    -    currentGlyphPointsItem_ = NULL;
    
    665
    -  }
    
    666
    -
    
    667
    -  if (currentGlyphPointNumbersItem_)
    
    668
    -  {
    
    669
    -    glyphScene_->removeItem(currentGlyphPointNumbersItem_);
    
    670
    -    delete currentGlyphPointNumbersItem_;
    
    671
    -
    
    672
    -    currentGlyphPointNumbersItem_ = NULL;
    
    673
    -  }
    
    674
    -
    
    675
    -  applySettings();
    
    676
    -  FT_Outline* outline = engine_->loadOutline(currentGlyphIndex_);
    
    677
    -  if (outline)
    
    678
    -  {
    
    679
    -    if (showBitmapCheckBox_->isChecked())
    
    680
    -    {
    
    681
    -      // XXX support LCD
    
    682
    -      FT_Pixel_Mode pixelMode = FT_PIXEL_MODE_GRAY;
    
    683
    -      if (antiAliasingComboBox_->currentIndex()
    
    684
    -          == AntiAliasingComboBoxModel::AntiAliasing_None)
    
    685
    -        pixelMode = FT_PIXEL_MODE_MONO;
    
    686
    -
    
    687
    -      currentGlyphBitmapItem_ = new GlyphBitmap(outline,
    
    688
    -                                               engine_->ftLibrary(),
    
    689
    -                                               pixelMode,
    
    690
    -                                               monoColorTable_,
    
    691
    -                                               grayColorTable_);
    
    692
    -      glyphScene_->addItem(currentGlyphBitmapItem_);
    
    693
    -    }
    
    694
    -
    
    695
    -    if (showOutlinesCheckBox_->isChecked())
    
    696
    -    {
    
    697
    -      currentGlyphOutlineItem_ = new GlyphOutline(outlinePen_, outline);
    
    698
    -      glyphScene_->addItem(currentGlyphOutlineItem_);
    
    699
    -    }
    
    700
    -
    
    701
    -    if (showPointsCheckBox_->isChecked())
    
    702
    -    {
    
    703
    -      currentGlyphPointsItem_ = new GlyphPoints(onPen_, offPen_, outline);
    
    704
    -      glyphScene_->addItem(currentGlyphPointsItem_);
    
    705
    -
    
    706
    -      if (showPointNumbersCheckBox_->isChecked())
    
    707
    -      {
    
    708
    -        currentGlyphPointNumbersItem_ = new GlyphPointNumbers(onPen_,
    
    709
    -                                                             offPen_,
    
    710
    -                                                             outline);
    
    711
    -        glyphScene_->addItem(currentGlyphPointNumbersItem_);
    
    712
    -      }
    
    713
    -    }
    
    714
    -  }
    
    715
    -
    
    716
    -  glyphScene_->update();
    
    149
    +  settingPanel_->applySettings();
    
    150
    +  settingPanel_->applyDelayedSettings();
    
    717 151
     }
    
    718 152
     
    
    719 153
     
    
    ... ... @@ -723,299 +157,58 @@ void
    723 157
     MainGUI::createLayout()
    
    724 158
     {
    
    725 159
       // left side
    
    726
    -  fontFilenameLabel_ = new QLabel;
    
    727
    -
    
    728
    -  hintingCheckBox_ = new QCheckBox(tr("Hinting"));
    
    729
    -
    
    730
    -  hintingModeLabel_ = new QLabel(tr("Hinting Mode"));
    
    731
    -  hintingModeLabel_->setAlignment(Qt::AlignRight);
    
    732
    -
    
    733
    -  hintingModeComboBoxModel_ = new HintingModeComboBoxModel(this);
    
    734
    -  hintingModeComboBox_ = new QComboBox;
    
    735
    -  hintingModeComboBox_->setModel(hintingModeComboBoxModel_);
    
    736
    -  hintingModeLabel_->setBuddy(hintingModeComboBox_);
    
    737
    -
    
    738
    -  autoHintingCheckBox_ = new QCheckBox(tr("Auto-Hinting"));
    
    739
    -  horizontalHintingCheckBox_ = new QCheckBox(tr("Horizontal Hinting"));
    
    740
    -  verticalHintingCheckBox_ = new QCheckBox(tr("Vertical Hinting"));
    
    741
    -  blueZoneHintingCheckBox_ = new QCheckBox(tr("Blue-Zone Hinting"));
    
    742
    -  segmentDrawingCheckBox_ = new QCheckBox(tr("Segment Drawing"));
    
    743
    -
    
    744
    -  antiAliasingLabel_ = new QLabel(tr("Anti-Aliasing"));
    
    745
    -  antiAliasingLabel_->setAlignment(Qt::AlignRight);
    
    746
    -
    
    747
    -  antiAliasingComboBoxModel_ = new AntiAliasingComboBoxModel(this);
    
    748
    -  antiAliasingComboBox_ = new QComboBox;
    
    749
    -  antiAliasingComboBox_->setModel(antiAliasingComboBoxModel_);
    
    750
    -  antiAliasingLabel_->setBuddy(antiAliasingComboBox_);
    
    751
    -
    
    752
    -  lcdFilterLabel_ = new QLabel(tr("LCD Filter"));
    
    753
    -  lcdFilterLabel_->setAlignment(Qt::AlignRight);
    
    754
    -
    
    755
    -  lcdFilterComboboxModel_ = new LCDFilterComboBoxModel(this);
    
    756
    -  lcdFilterComboBox_ = new QComboBox;
    
    757
    -  lcdFilterComboBox_->setModel(lcdFilterComboboxModel_);
    
    758
    -  lcdFilterLabel_->setBuddy(lcdFilterComboBox_);
    
    759
    -
    
    760
    -  int width;
    
    761