[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] ftinspect-psname 7ab0e1d 2/2: [ftinspect] Add PostScri
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] ftinspect-psname 7ab0e1d 2/2: [ftinspect] Add PostScript constructed name display for MM/GX fonts. |
Date: |
Thu, 5 Oct 2023 03:09:10 -0400 (EDT) |
branch: ftinspect-psname
commit 7ab0e1d3967cbe237942141a38e4c2cef72545b0
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>
[ftinspect] Add PostScript constructed name display for MM/GX fonts.
Fixes #57 . Added a text box showing current constructed PostScript name
with MM/GX coords included according to TN #5902.
* src/ftinspect/panels/settingpanelmmgx.cpp,
src/ftinspect/panels/settingpanelmmgx.hpp:
Add the PostScript name text box.
Track the dirty state of the axes, so when all axes are in "default" state
the "basic" PS name will be displayed (e.g. "NotoSansCJKtc-DemiLight"),
while when any axis has its value modified, the constructed PS name will
be displayed (e.g. "NotoSansCJKTC_350wght").
Even when the value equals to the default one, as long as the value was
touched by user, the name will be the constructed one. To clear the dirty
state, the "Def" button for each axis, or the "Reset to Default" button
should be used.
* src/ftinspect/engine/engine.cpp, src/ftinspect/engine/engine.hpp:
Add two fields tracking PS name (one with "basic" name, and one possibly
constructed from MM/GX coords).
* src/ftinspect/engine/fontinfo.cpp: Change to use the PS name from engine.
---
src/ftinspect/engine/engine.cpp | 9 +++++++++
src/ftinspect/engine/engine.hpp | 10 ++++++++++
src/ftinspect/engine/fontinfo.cpp | 4 +---
src/ftinspect/panels/settingpanelmmgx.cpp | 31 +++++++++++++++++++++++++++++--
src/ftinspect/panels/settingpanelmmgx.hpp | 8 ++++++++
5 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/src/ftinspect/engine/engine.cpp b/src/ftinspect/engine/engine.cpp
index ce59ba9..f016b76 100644
--- a/src/ftinspect/engine/engine.cpp
+++ b/src/ftinspect/engine/engine.cpp
@@ -392,6 +392,12 @@ Engine::loadFont(int fontIndex,
{
curFamilyName_ = QString(ftFallbackFace_->family_name);
curStyleName_ = QString(ftFallbackFace_->style_name);
+ auto* psName = FT_Get_Postscript_Name(ftFallbackFace_);
+ if (psName)
+ curPostScriptNameWithoutCoords_ = psName;
+ else
+ curPostScriptNameWithoutCoords_ = QString();
+ curPostScriptNameWithCoords_ = curPostScriptNameWithoutCoords_;
const char* moduleName = FT_FACE_DRIVER_NAME(ftFallbackFace_);
@@ -873,6 +879,9 @@ Engine::applyMMGXDesignCoords(FT_Fixed* coords,
FT_Set_Var_Design_Coordinates(ftSize_->face,
static_cast<unsigned>(count),
coords);
+ auto* psName = FT_Get_Postscript_Name(ftSize_->face);
+ if (psName)
+ curPostScriptNameWithCoords_ = psName;
}
diff --git a/src/ftinspect/engine/engine.hpp b/src/ftinspect/engine/engine.hpp
index cf2710c..a025322 100644
--- a/src/ftinspect/engine/engine.hpp
+++ b/src/ftinspect/engine/engine.hpp
@@ -129,6 +129,14 @@ public:
int currentFontType() const { return fontType_; }
const QString& currentFamilyName() { return curFamilyName_; }
const QString& currentStyleName() { return curStyleName_; }
+ const QString& currentPostScriptNameWithoutCoords()
+ {
+ return curPostScriptNameWithoutCoords_;
+ }
+ const QString& currentPostScriptNameWithCoords()
+ {
+ return curPostScriptNameWithCoords_;
+ }
int currentFontNumberOfGlyphs() { return curNumGlyphs_; }
std::vector<PaletteInfo>& currentFontPalettes() { return curPaletteInfos_; }
@@ -235,6 +243,8 @@ private:
int fontType_ = FontType_Other;
QString curFamilyName_;
QString curStyleName_;
+ QString curPostScriptNameWithoutCoords_;
+ QString curPostScriptNameWithCoords_;
int curNumGlyphs_ = -1;
std::vector<CharMapInfo> curCharMaps_;
std::vector<PaletteInfo> curPaletteInfos_;
diff --git a/src/ftinspect/engine/fontinfo.cpp
b/src/ftinspect/engine/fontinfo.cpp
index 42c3c57..eba67dd 100644
--- a/src/ftinspect/engine/fontinfo.cpp
+++ b/src/ftinspect/engine/fontinfo.cpp
@@ -202,9 +202,7 @@ FontBasicInfo::get(Engine* engine)
if (face->style_name)
result.styleName = QString(face->style_name);
- auto psName = FT_Get_Postscript_Name(face);
- if (psName)
- result.postscriptName = QString(psName);
+ result.postscriptName = engine->currentPostScriptNameWithoutCoords();
auto head = static_cast<TT_Header*>(FT_Get_Sfnt_Table(face, FT_SFNT_HEAD));
if (head)
diff --git a/src/ftinspect/panels/settingpanelmmgx.cpp
b/src/ftinspect/panels/settingpanelmmgx.cpp
index e01e178..2758893 100644
--- a/src/ftinspect/panels/settingpanelmmgx.cpp
+++ b/src/ftinspect/panels/settingpanelmmgx.cpp
@@ -74,6 +74,10 @@ SettingPanelMMGX::applySettings()
engine_->reloadFont();
engine_->applyMMGXDesignCoords(currentValues_.data(),
currentValues_.size());
+ if (checkDirty())
+ psNameText_->setPlainText(engine_->currentPostScriptNameWithCoords());
+ else
+ psNameText_->setPlainText(engine_->currentPostScriptNameWithoutCoords());
}
@@ -88,6 +92,15 @@ SettingPanelMMGX::checkHidden()
}
+bool
+SettingPanelMMGX::checkDirty() const
+{
+ for (auto w : itemWidgets_)
+ if (w->dirty()) return true;
+ return false;
+}
+
+
void
SettingPanelMMGX::createLayout()
{
@@ -96,15 +109,19 @@ SettingPanelMMGX::createLayout()
resetDefaultButton_ = new QPushButton(tr("Reset Default"), this);
itemsListWidget_ = new QWidget(this);
scrollArea_ = new UnboundScrollArea(this);
+ psNameBox_ = new QGroupBox("PostScript Name", this);
+ psNameText_ = new QPlainTextEdit(psNameBox_);
scrollArea_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
scrollArea_->setWidget(itemsListWidget_);
scrollArea_->setWidgetResizable(true);
itemsListWidget_->setAutoFillBackground(false);
+ psNameText_->setReadOnly(true);
mainLayout_ = new QVBoxLayout;
listLayout_ = new QVBoxLayout;
listWrapperLayout_ = new QVBoxLayout;
+ psNameBoxLayout_ = new QVBoxLayout;
listLayout_->setSpacing(0);
listLayout_->setContentsMargins(0, 0, 0, 0);
@@ -115,10 +132,16 @@ SettingPanelMMGX::createLayout()
listWrapperLayout_->addLayout(listLayout_);
listWrapperLayout_->addStretch(1);
+ psNameText_->setMaximumHeight(50);
+ psNameText_->setMinimumHeight(50);
+ psNameBox_->setLayout(psNameBoxLayout_);
+ psNameBoxLayout_->addWidget(psNameText_);
+
mainLayout_->addWidget(showHiddenCheckBox_);
mainLayout_->addWidget(groupingCheckBox_);
mainLayout_->addWidget(resetDefaultButton_);
- mainLayout_->addWidget(scrollArea_, 1);
+ mainLayout_->addWidget(scrollArea_, 2);
+ mainLayout_->addWidget(psNameBox_, 0);
setLayout(mainLayout_);
}
@@ -169,7 +192,7 @@ SettingPanelMMGX::resetDefaultClicked()
{
for (auto w : itemWidgets_)
w->resetDefault();
-
+
retrieveValues();
emit mmgxCoordsChanged();
}
@@ -234,6 +257,7 @@ void
MMGXSettingItem::setValue(FT_Fixed value)
{
actualValue_ = value;
+ dirty_ = true;
updateSlider();
updateLineEdit();
}
@@ -243,6 +267,7 @@ void
MMGXSettingItem::resetDefault()
{
setValue(static_cast<FT_Fixed>(axisInfo_.def * 65536.0));
+ dirty_ = false;
}
@@ -305,6 +330,7 @@ MMGXSettingItem::sliderValueChanged()
* (axisInfo_.maximum - axisInfo_.minimum)
+ axisInfo_.minimum;
actualValue_ = static_cast<FT_Fixed>(value * 65536.0);
+ dirty_ = true;
if (axisInfo_.isMM)
actualValue_ = FT_RoundFix(actualValue_);
@@ -326,6 +352,7 @@ MMGXSettingItem::lineEditChanged()
}
actualValue_ = static_cast<FT_Fixed>(newValue / 65536.0);
+ dirty_ = true;
updateSlider();
emit valueChanged();
diff --git a/src/ftinspect/panels/settingpanelmmgx.hpp
b/src/ftinspect/panels/settingpanelmmgx.hpp
index ecc88ec..8f71f8a 100644
--- a/src/ftinspect/panels/settingpanelmmgx.hpp
+++ b/src/ftinspect/panels/settingpanelmmgx.hpp
@@ -12,11 +12,13 @@
#include <QCheckBox>
#include <QDoubleValidator>
#include <QFrame>
+#include <QGroupBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QScrollArea>
+#include <QPlainTextEdit>
#include <QSlider>
#include <QToolButton>
#include <QWidget>
@@ -40,6 +42,7 @@ public:
void reloadFont();
void applySettings();
void checkHidden();
+ bool checkDirty() const;
std::vector<FT_Fixed>& mmgxCoords() { return currentValues_; }
signals:
@@ -53,11 +56,14 @@ private:
QPushButton* resetDefaultButton_;
QWidget* itemsListWidget_;
UnboundScrollArea* scrollArea_;
+ QGroupBox* psNameBox_;
+ QPlainTextEdit* psNameText_;
std::vector<MMGXSettingItem*> itemWidgets_;
QVBoxLayout* mainLayout_;
QVBoxLayout* listLayout_;
QVBoxLayout* listWrapperLayout_;
+ QVBoxLayout* psNameBoxLayout_;
std::vector<FT_Fixed> currentValues_;
std::vector<MMGXAxisInfo> currentAxes_;
@@ -83,6 +89,7 @@ public:
void updateInfo(MMGXAxisInfo& info);
FT_Fixed value() { return actualValue_; }
+ bool dirty() { return dirty_; }
void setValue(FT_Fixed value);
void resetDefault();
@@ -100,6 +107,7 @@ private:
FT_Fixed actualValue_;
MMGXAxisInfo axisInfo_;
+ bool dirty_ = false;
void createLayout();
void createConnections();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] ftinspect-psname 7ab0e1d 2/2: [ftinspect] Add PostScript constructed name display for MM/GX fonts.,
Werner Lemberg <=