[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 552ce60 37/41: [ftinspect] Format `src/ftinspec
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master 552ce60 37/41: [ftinspect] Format `src/ftinspect/models/*`. |
Date: |
Mon, 3 Oct 2022 11:27:04 -0400 (EDT) |
branch: master
commit 552ce60285260946a459c5c9150637ef2e97efa4
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>
[ftinspect] Format `src/ftinspect/models/*`.
---
src/ftinspect/models/customcomboboxmodels.cpp | 11 ++--
src/ftinspect/models/customcomboboxmodels.hpp | 38 +++++-------
src/ftinspect/models/fontinfomodels.cpp | 86 ++++++++++++++------------
src/ftinspect/models/fontinfomodels.hpp | 88 ++++++++++++++++-----------
4 files changed, 121 insertions(+), 102 deletions(-)
diff --git a/src/ftinspect/models/customcomboboxmodels.cpp
b/src/ftinspect/models/customcomboboxmodels.cpp
index a3ad5ad..6c844f4 100644
--- a/src/ftinspect/models/customcomboboxmodels.cpp
+++ b/src/ftinspect/models/customcomboboxmodels.cpp
@@ -7,6 +7,7 @@
#include <QApplication>
#include <QPalette>
+
#include <freetype/ftdriver.h>
#include <freetype/ftlcdfil.h>
@@ -68,7 +69,7 @@ HintingModeComboBoxModel::rowCount(const QModelIndex& parent)
const
QVariant
HintingModeComboBoxModel::data(const QModelIndex& index,
- int role) const
+ int role) const
{
int r = index.row();
if (r < 0 || r >= items_.size())
@@ -83,7 +84,7 @@ HintingModeComboBoxModel::data(const QModelIndex& index,
if (item.enabled && item.supported)
return QVariant {};
else
- return QApplication::palette().color(QPalette::Disabled,
+ return QApplication::palette().color(QPalette::Disabled,
QPalette::Text);
default:
return QVariant {};
@@ -96,7 +97,7 @@ HintingModeComboBoxModel::flags(const QModelIndex& index)
const
{
int r = index.row();
if (r < 0 || r >= items_.size())
- return Qt::ItemFlags {}; // not selectable, not enabled
+ return Qt::ItemFlags {}; // Not selectable, not enabled.
HintingModeItem const& item = items_[r];
if (item.enabled && item.supported)
@@ -177,7 +178,7 @@ HintingModeComboBoxModel::setSupportedModes(QList<int>
supportedTTIVersions,
void
-HintingModeComboBoxModel::setCurrentEngineType(HintingEngineType type,
+HintingModeComboBoxModel::setCurrentEngineType(HintingEngineType type,
bool tricky)
{
for (auto& item : items_)
@@ -272,7 +273,7 @@ AntiAliasingComboBoxModel::data(const QModelIndex& index,
if (role == Qt::ForegroundRole)
if ((row == AntiAliasing_Light || row == AntiAliasing_Light_SubPixel)
&& !lightAntiAliasingEnabled_)
- return QApplication::palette().color(QPalette::Disabled,
+ return QApplication::palette().color(QPalette::Disabled,
QPalette::Text);
return SimpleComboBoxModelImpl::data(index, role);
}
diff --git a/src/ftinspect/models/customcomboboxmodels.hpp
b/src/ftinspect/models/customcomboboxmodels.hpp
index 6c7eb9e..ffabe6f 100644
--- a/src/ftinspect/models/customcomboboxmodels.hpp
+++ b/src/ftinspect/models/customcomboboxmodels.hpp
@@ -8,6 +8,7 @@
#include <QAbstractListModel>
#include <QHash>
+
class HintingModeComboBoxModel
: public QAbstractListModel
{
@@ -51,8 +52,8 @@ private:
HintingEngineType type) const;
public:
- // Note: Ensure related funcs are also changed when
- // these enums are changed!
+ // Note: Ensure related funcs are also updated when
+ // these enums are changed!
enum HintingEngineType : int
{
HintingEngineType_TrueType,
@@ -70,7 +71,7 @@ public:
};
-// A simple key-displayName-value model for QComboBox.
+// A simple key-displayName-value model for `QComboBox`.
template <class T>
class SimpleComboBoxModelImpl
{
@@ -93,7 +94,7 @@ public:
virtual QVariant
data(const QModelIndex& index,
- int role) const
+ int role) const
{
if (role != Qt::DisplayRole)
return QVariant{};
@@ -123,6 +124,7 @@ class LCDFilterComboBoxModel
public SimpleComboBoxModelImpl<int>
{
Q_OBJECT
+
public:
enum LCDFilter : int;
struct LCDFilterItem
@@ -131,23 +133,16 @@ public:
QString displayName;
};
-
explicit LCDFilterComboBoxModel(QObject* parent);
~LCDFilterComboBoxModel() override = default;
-
int rowCount(const QModelIndex& parent) const override
- {
- return SimpleComboBoxModelImpl::rowCount(parent);
- }
+ { return SimpleComboBoxModelImpl::rowCount(parent); }
- QVariant
- data(const QModelIndex& index,
- int role) const override
- {
- return SimpleComboBoxModelImpl::data(index, role);
- }
+ QVariant data(const QModelIndex& index,
+ int role) const override
+ { return SimpleComboBoxModelImpl::data(index, role); }
public:
enum LCDFilter : int
@@ -174,27 +169,22 @@ class AntiAliasingComboBoxModel
public SimpleComboBoxModelImpl<AASetting>
{
Q_OBJECT
+
public:
enum AntiAliasing : int;
explicit AntiAliasingComboBoxModel(QObject* parent);
~AntiAliasingComboBoxModel() override = default;
-
+
QVariant data(const QModelIndex& index,
int role) const;
Qt::ItemFlags flags(const QModelIndex& index) const;
-
int rowCount(const QModelIndex& parent) const override
- {
- return SimpleComboBoxModelImpl::rowCount(parent);
- }
-
+ { return SimpleComboBoxModelImpl::rowCount(parent); }
void setLightAntiAliasingEnabled(bool enabled)
- {
- lightAntiAliasingEnabled_ = enabled;
- }
+ { lightAntiAliasingEnabled_ = enabled; }
private:
bool lightAntiAliasingEnabled_;
diff --git a/src/ftinspect/models/fontinfomodels.cpp
b/src/ftinspect/models/fontinfomodels.cpp
index e99b757..cb3d5d1 100644
--- a/src/ftinspect/models/fontinfomodels.cpp
+++ b/src/ftinspect/models/fontinfomodels.cpp
@@ -2,11 +2,12 @@
// Copyright (C) 2022 by Charlie Jiang.
-#include "fontinfomodels.hpp"
#include "../engine/engine.hpp"
+#include "fontinfomodels.hpp"
#include <cstdint>
+
int
FixedSizeInfoModel::rowCount(const QModelIndex& parent) const
{
@@ -27,7 +28,7 @@ FixedSizeInfoModel::columnCount(const QModelIndex& parent)
const
QVariant
FixedSizeInfoModel::data(const QModelIndex& index,
- int role) const
+ int role) const
{
if (index.row() < 0 || index.column() < 0)
return {};
@@ -59,8 +60,8 @@ FixedSizeInfoModel::data(const QModelIndex& index,
QVariant
FixedSizeInfoModel::headerData(int section,
- Qt::Orientation orientation,
- int role) const
+ Qt::Orientation orientation,
+ int role) const
{
if (role != Qt::DisplayRole)
return {};
@@ -122,7 +123,7 @@ CharMapInfoModel::data(const QModelIndex& index,
auto& obj = storage_[r];
switch (static_cast<Columns>(index.column()))
{
- case CMIM_Platform:
+ case CMIM_Platform:
return QString("%1 {%2}")
.arg(obj.platformID)
.arg(*mapTTPlatformIDToName(obj.platformID));
@@ -130,11 +131,11 @@ CharMapInfoModel::data(const QModelIndex& index,
return QString("%1 {%2}")
.arg(obj.encodingID)
.arg(*obj.encodingName);
- case CMIM_FormatID:
+ case CMIM_FormatID:
return static_cast<long long>(obj.formatID);
case CMIM_Language:
return static_cast<unsigned long long>(obj.languageID);
- case CMIM_MaxIndex:
+ case CMIM_MaxIndex:
return obj.maxIndex;
default:
break;
@@ -217,7 +218,7 @@ SFNTNameModel::data(const QModelIndex& index,
return QString::number(obj.nameID);
return QString("%1 {%2}").arg(QString::number(obj.nameID),
*mapSFNTNameIDToName(obj.nameID));
-
+
case SNM_Platform:
return QString("%1 {%2}")
.arg(obj.platformID)
@@ -235,7 +236,7 @@ SFNTNameModel::data(const QModelIndex& index,
.arg(*mapTTLanguageIDToName(obj.platformID, obj.languageID));
return QString("%1 {%2}")
.arg(obj.languageID)
- .arg(*mapTTLanguageIDToName(obj.platformID, obj.languageID));
+ .arg(*mapTTLanguageIDToName(obj.platformID, obj.languageID));
case SNM_Content:
return obj.str;
default:
@@ -333,20 +334,20 @@ SFNTTableInfoModel::data(const QModelIndex& index,
case STIM_SharedFaces:
if (obj.sharedFaces.empty())
return "[]";
- {
- auto result = QString('[') + QString::number(*obj.sharedFaces.begin());
- for (auto it = std::next(obj.sharedFaces.begin());
- it != obj.sharedFaces.end();
- ++it)
{
- auto xStr = QString::number(*it);
- result.reserve(result.length() + xStr.length() + 2);
- result += ", ";
- result += xStr;
+ auto result = QString('[') + QString::number(*obj.sharedFaces.begin());
+ for (auto it = std::next(obj.sharedFaces.begin());
+ it != obj.sharedFaces.end();
+ ++it)
+ {
+ auto xStr = QString::number(*it);
+ result.reserve(result.length() + xStr.length() + 2);
+ result += ", ";
+ result += xStr;
+ }
+ result += ']';
+ return result;
}
- result += ']';
- return result;
- }
default:
break;
}
@@ -379,7 +380,8 @@ SFNTTableInfoModel::headerData(int section,
return "Valid";
case STIM_SharedFaces:
return "Subfont Indices";
- default:;
+ default:
+ ;
}
return {};
@@ -464,7 +466,8 @@ MMGXAxisInfoModel::headerData(int section,
return "Hidden";
case MAIM_Name:
return "Name";
- default: ;
+ default:
+ ;
}
return {};
@@ -501,25 +504,26 @@ CompositeGlyphsInfoModel::index(int row,
int column,
const QModelIndex& parent) const
{
- long long parentIdx = -1; // node index.
- if (parent.isValid()) // Not top-level
+ long long parentIdx = -1; // Node index.
+ if (parent.isValid()) // Not top-level.
parentIdx = static_cast<long long>(parent.internalId());
if (parentIdx < 0)
parentIdx = -1;
- // find existing node by row and parent index, -1 for top-level
+ // Find existing node by row and parent index, -1 for top-level.
auto lookupPair = std::pair<int, long long>(row, parentIdx);
auto iter = nodeLookup_.find(lookupPair);
if (iter != nodeLookup_.end())
{
- if (iter->second < 0 || static_cast<size_t>(iter->second) >= nodes_.size())
+ if (iter->second < 0
+ || static_cast<size_t>(iter->second) >= nodes_.size())
return {};
return createIndex(row, column, iter->second);
}
int glyphIndex = -1;
CompositeGlyphInfo::SubGlyph const* sgInfo = nullptr;
- if (!parent.isValid()) // top-level nodes
+ if (!parent.isValid()) // Top-level nodes.
glyphIndex = glyphs_[row].index;
else if (parent.internalId() < nodes_.size())
{
@@ -540,10 +544,12 @@ CompositeGlyphsInfoModel::index(int row,
auto iterGlyphInfoIter = glyphMapper_.find(glyphIndex);
if (iterGlyphInfoIter != glyphMapper_.end())
glyphInfoIndex = static_cast<ptrdiff_t>(iterGlyphInfoIter->second);
-
+
InfoNode node = {
parentIdx,
- row, glyphIndex, glyphInfoIndex,
+ row,
+ glyphIndex,
+ glyphInfoIndex,
sgInfo
};
nodes_.push_back(node);
@@ -583,7 +589,7 @@
generatePositionTransformationText(CompositeGlyphInfo::SubGlyph const& info)
result += QString("scale: %1, ")
.arg(QString::number(info.transformation[0]));
break;
- case CompositeGlyphInfo::SubGlyph::TT_XYScale:
+ case CompositeGlyphInfo::SubGlyph::TT_XYScale:
result += QString("xy scale: (%1, %2), ")
.arg(QString::number(info.transformation[0]),
QString::number(info.transformation[1]));
@@ -596,7 +602,7 @@
generatePositionTransformationText(CompositeGlyphInfo::SubGlyph const& info)
QString::number(info.transformation[3]));
break;
}
-
+
switch (info.positionType)
{
case CompositeGlyphInfo::SubGlyph::PT_Offset:
@@ -615,6 +621,7 @@
generatePositionTransformationText(CompositeGlyphInfo::SubGlyph const& info)
QString::number(info.position.second));
break;
}
+
return result;
}
@@ -652,19 +659,20 @@ CompositeGlyphsInfoModel::data(const QModelIndex& index,
{
case CGIM_Glyph:
if (engine_->currentFontHasGlyphName())
- return QString("%1
{%2}").arg(glyphIdx).arg(engine_->glyphName(glyphIdx));
+ return QString("%1 {%2}")
+ .arg(glyphIdx).arg(engine_->glyphName(glyphIdx));
return QString::number(glyphIdx);
case CGIM_Flag:
if (!n.subGlyphInfo)
return {};
- return QString("0x%1").arg(n.subGlyphInfo->flag, 4, 16, QLatin1Char('0'));
+ return QString("0x%1")
+ .arg(n.subGlyphInfo->flag, 4, 16, QLatin1Char('0'));
case CGIM_PositionTransformation:
- {
if (!n.subGlyphInfo)
return {};
return generatePositionTransformationText(*n.subGlyphInfo);
- }
- default:;
+ default:
+ ;
}
return {};
@@ -689,8 +697,10 @@ CompositeGlyphsInfoModel::headerData(int section,
return tr("Flags");
case CGIM_PositionTransformation:
return tr("Position and Transformation");
- default:;
+ default:
+ ;
}
+
return {};
}
diff --git a/src/ftinspect/models/fontinfomodels.hpp
b/src/ftinspect/models/fontinfomodels.hpp
index ab73c80..a607531 100644
--- a/src/ftinspect/models/fontinfomodels.hpp
+++ b/src/ftinspect/models/fontinfomodels.hpp
@@ -4,21 +4,25 @@
#pragma once
-#include "../engine/fontinfo.hpp"
#include "../engine/charmap.hpp"
+#include "../engine/fontinfo.hpp"
#include "../engine/mmgx.hpp"
-#include <vector>
#include <unordered_map>
+#include <vector>
+
#include <QAbstractTableModel>
#include <QPixmap>
+
class FixedSizeInfoModel
: public QAbstractTableModel
{
Q_OBJECT
+
public:
- explicit FixedSizeInfoModel(QObject* parent) : QAbstractTableModel(parent) {}
+ explicit FixedSizeInfoModel(QObject* parent)
+ : QAbstractTableModel(parent) {}
~FixedSizeInfoModel() override = default;
int rowCount(const QModelIndex& parent) const override;
@@ -29,12 +33,12 @@ public:
Qt::Orientation orientation,
int role) const override;
- // Since we need to call `beginResetModel` right before updating, and need to
- // call `endResetModel` after the internal storage is changed
- // The model should be updated on-demand, and the internal storage is updated
- // from `FontFixedSize::get`, we provide a callback for `get` to ensure the
- // `beginResetModel` is called before the storage is changed,
- // and the caller is responsible to call `endResetModel` according to `get`'s
+ // Since we need to call `beginResetModel` right before updating, we need
+ // to call `endResetModel` after the internal storage is changed. The
+ // model should be updated on-demand, and the internal storage is updated
+ // from `FontFixedSize::get`. We provide a callback for `get` to ensure
+ // the `beginResetModel` is called before the storage is changed, and the
+ // caller is responsible to call `endResetModel` according to `get`'s
// return value.
void beginModelUpdate() { beginResetModel(); }
void endModelUpdate() { endResetModel(); }
@@ -60,8 +64,10 @@ class CharMapInfoModel
: public QAbstractTableModel
{
Q_OBJECT
+
public:
- explicit CharMapInfoModel(QObject* parent) : QAbstractTableModel(parent) {}
+ explicit CharMapInfoModel(QObject* parent)
+ : QAbstractTableModel(parent) {}
~CharMapInfoModel() override = default;
int rowCount(const QModelIndex& parent) const override;
@@ -72,14 +78,14 @@ public:
Qt::Orientation orientation,
int role) const override;
- // Same to `FixedSizeInfoModel`
+ // The same as `FixedSizeInfoModel`.
void beginModelUpdate() { beginResetModel(); }
void endModelUpdate() { endResetModel(); }
std::vector<CharMapInfo>& storage() { return storage_; }
enum Columns : int
{
- CMIM_Platform = 0,
+ CMIM_Platform = 0,
CMIM_Encoding,
CMIM_FormatID,
CMIM_Language,
@@ -97,8 +103,10 @@ class SFNTNameModel
: public QAbstractTableModel
{
Q_OBJECT
+
public:
- explicit SFNTNameModel(QObject* parent) : QAbstractTableModel(parent) {}
+ explicit SFNTNameModel(QObject* parent)
+ : QAbstractTableModel(parent) {}
~SFNTNameModel() override = default;
int rowCount(const QModelIndex& parent) const override;
@@ -109,14 +117,14 @@ public:
Qt::Orientation orientation,
int role) const override;
- // Same to `FixedSizeInfoModel`
+ // The same as `FixedSizeInfoModel`.
void beginModelUpdate() { beginResetModel(); }
void endModelUpdate() { endResetModel(); }
std::vector<SFNTName>& storage() { return storage_; }
enum Columns : int
{
- SNM_Name = 0,
+ SNM_Name = 0,
SNM_Platform,
SNM_Encoding,
SNM_Language,
@@ -134,8 +142,10 @@ class SFNTTableInfoModel
: public QAbstractTableModel
{
Q_OBJECT
+
public:
- explicit SFNTTableInfoModel(QObject* parent) : QAbstractTableModel(parent) {}
+ explicit SFNTTableInfoModel(QObject* parent)
+ : QAbstractTableModel(parent) {}
~SFNTTableInfoModel() override = default;
int rowCount(const QModelIndex& parent) const override;
@@ -146,7 +156,7 @@ public:
Qt::Orientation orientation,
int role) const override;
- // Same to `FixedSizeInfoModel`
+ // The same as `FixedSizeInfoModel`.
void beginModelUpdate() { beginResetModel(); }
void endModelUpdate() { endResetModel(); }
std::vector<SFNTTableInfo>& storage() { return storage_; }
@@ -171,8 +181,10 @@ class MMGXAxisInfoModel
: public QAbstractTableModel
{
Q_OBJECT
+
public:
- explicit MMGXAxisInfoModel(QObject* parent) : QAbstractTableModel(parent) {}
+ explicit MMGXAxisInfoModel(QObject* parent)
+ : QAbstractTableModel(parent) {}
~MMGXAxisInfoModel() override = default;
int rowCount(const QModelIndex& parent) const override;
@@ -183,7 +195,7 @@ public:
Qt::Orientation orientation,
int role) const override;
- // Same to `FixedSizeInfoModel`
+ // The same as `FixedSizeInfoModel`.
void beginModelUpdate() { beginResetModel(); }
void endModelUpdate() { endResetModel(); }
std::vector<MMGXAxisInfo>& storage() { return storage_; }
@@ -222,9 +234,11 @@ public:
// A tree model, so much more complicated.
-class CompositeGlyphsInfoModel : public QAbstractItemModel
+class CompositeGlyphsInfoModel
+: public QAbstractItemModel
{
Q_OBJECT
+
public:
// A lazily created info node.
struct InfoNode
@@ -236,8 +250,10 @@ public:
CompositeGlyphInfo::SubGlyph const* subGlyphInfo;
};
- explicit CompositeGlyphsInfoModel(QObject* parent, Engine* engine)
- : QAbstractItemModel(parent), engine_(engine)
+ explicit CompositeGlyphsInfoModel(QObject* parent,
+ Engine* engine)
+ : QAbstractItemModel(parent),
+ engine_(engine)
{
}
@@ -245,11 +261,14 @@ public:
int rowCount(const QModelIndex& parent) const override;
int columnCount(const QModelIndex& parent) const override;
- QModelIndex index(int row, int column,
+ QModelIndex index(int row,
+ int column,
const QModelIndex& parent) const override;
QModelIndex parent(const QModelIndex& child) const override;
- QVariant data(const QModelIndex& index, int role) const override;
- QVariant headerData(int section, Qt::Orientation orientation,
+ QVariant data(const QModelIndex& index,
+ int role) const override;
+ QVariant headerData(int section,
+ Qt::Orientation orientation,
int role) const override;
int glyphIndexFromIndex(const QModelIndex& idx);
@@ -267,18 +286,17 @@ public:
private:
Engine* engine_;
- /*
- * Take care of 3 types of index:
- * 1. Glyph Index in Font File
- * 2. Glyph Index in `glyphs_` - often called as "glyph info index"
- * 3. Node Index
- */
+ // Take care of 3 types of indices:
+ //
+ // 1. the glyph index in a font file
+ // 2. the glyph index in `glyphs_` - often called 'glyph info index'
+ // 3. a node index
std::vector<CompositeGlyphInfo> glyphs_;
- // glyph index -> glyph info index
+ // Glyph index -> glyph info index.
std::unordered_map<int, size_t> glyphMapper_;
- // map <row, parentId> to node
- // the internal id of `QModelIndex` is the node's index
+ // Map <row, parentId> to node.
+ // The internal ID of `QModelIndex` is the node's index.
mutable std::unordered_map<std::pair<int, long long>,
long long, LookupPairHash>
nodeLookup_;
@@ -286,7 +304,7 @@ private:
mutable std::unordered_map<int, QPixmap> glyphIcons_;
- // has to be const
+ // This has to be const.
QPixmap renderIcon(int glyphIndex) const;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 552ce60 37/41: [ftinspect] Format `src/ftinspect/models/*`.,
Werner Lemberg <=