[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2022-chariri-2 2e043b9 29/30: [ftinspect] Support
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] gsoc-2022-chariri-2 2e043b9 29/30: [ftinspect] Support Stroked SubMode in "Continuous Mode" |
Date: |
Mon, 11 Jul 2022 07:17:41 -0400 (EDT) |
branch: gsoc-2022-chariri-2
commit 2e043b9fbbdb7dc1aa664e46381463e317bc464f
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>
[ftinspect] Support Stroked SubMode in "Continuous Mode"
* src/ftinspect/panels/continuous.cpp, src/ftinspect/panels/continuous.hpp:
GUI update.
* src/ftinspect/rendering/glyphcontinuous.cpp,
src/ftinspect/rendering/glyphcontinuous.hpp: Add support.
---
src/ftinspect/panels/continuous.cpp | 21 ++++++++++++++++
src/ftinspect/panels/continuous.hpp | 3 +++
src/ftinspect/rendering/glyphcontinuous.cpp | 38 ++++++++++++++++++++++++++---
src/ftinspect/rendering/glyphcontinuous.hpp | 9 +++++--
4 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/src/ftinspect/panels/continuous.cpp
b/src/ftinspect/panels/continuous.cpp
index b3c955a..58f75a3 100644
--- a/src/ftinspect/panels/continuous.cpp
+++ b/src/ftinspect/panels/continuous.cpp
@@ -134,6 +134,7 @@ ContinuousTab::updateFromCurrentSubTab()
canvas_->setFancyParams(allGlyphsTab_->xEmboldening(),
allGlyphsTab_->yEmboldening(),
allGlyphsTab_->slanting());
+ canvas_->setStrokeRadius(allGlyphsTab_->strokeRadius());
break;
}
}
@@ -196,6 +197,13 @@ ContinousAllGlyphsTab::slanting()
}
+double
+ContinousAllGlyphsTab::strokeRadius()
+{
+ return strokeRadiusSpinBox_->value();
+}
+
+
int
ContinousAllGlyphsTab::charMapIndex()
{
@@ -294,9 +302,11 @@ void
ContinousAllGlyphsTab::checkSubMode()
{
auto isFancy = subMode() == GlyphContinuous::AG_Fancy;
+ auto isStroked = subMode() == GlyphContinuous::AG_Stroked;
xEmboldeningSpinBox_->setEnabled(isFancy);
yEmboldeningSpinBox_->setEnabled(isFancy);
slantSpinBox_->setEnabled(isFancy);
+ strokeRadiusSpinBox_->setEnabled(isStroked);
emit changed();
}
@@ -326,10 +336,12 @@ ContinousAllGlyphsTab::createLayout()
xEmboldeningLabel_ = new QLabel(tr("Hori. Embolding (for Fancy):"), this);
yEmboldeningLabel_ = new QLabel(tr("Vert. Embolding (for Fancy):"), this);
slantLabel_ = new QLabel(tr("Slanting (for Fancy):"), this);
+ strokeRadiusLabel_ = new QLabel(tr("Stroke Radius (for Stroked):"), this);
xEmboldeningSpinBox_ = new QDoubleSpinBox(this);
yEmboldeningSpinBox_ = new QDoubleSpinBox(this);
slantSpinBox_ = new QDoubleSpinBox(this);
+ strokeRadiusSpinBox_ = new QDoubleSpinBox(this);
xEmboldeningSpinBox_->setSingleStep(0.005);
xEmboldeningSpinBox_->setMinimum(-0.1);
@@ -340,6 +352,9 @@ ContinousAllGlyphsTab::createLayout()
slantSpinBox_->setSingleStep(0.02);
slantSpinBox_->setMinimum(-1);
slantSpinBox_->setMaximum(1);
+ strokeRadiusSpinBox_->setSingleStep(0.005);
+ strokeRadiusSpinBox_->setMinimum(0);
+ strokeRadiusSpinBox_->setMaximum(0.05);
layout_ = new QGridLayout;
layout_->addWidget(indexSelector_, 0, 0, 1, 2);
@@ -351,9 +366,11 @@ ContinousAllGlyphsTab::createLayout()
layout_->addWidget(xEmboldeningLabel_, 1, 2);
layout_->addWidget(yEmboldeningLabel_, 2, 2);
layout_->addWidget(slantLabel_, 3, 2);
+ layout_->addWidget(strokeRadiusLabel_, 3, 0);
layout_->addWidget(xEmboldeningSpinBox_, 1, 3);
layout_->addWidget(yEmboldeningSpinBox_, 2, 3);
layout_->addWidget(slantSpinBox_, 3, 3);
+ layout_->addWidget(strokeRadiusSpinBox_, 3, 1);
layout_->setColumnStretch(1, 1);
layout_->setColumnStretch(3, 1);
@@ -380,6 +397,9 @@ ContinousAllGlyphsTab::createConnections()
connect(slantSpinBox_,
QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &ContinousAllGlyphsTab::changed);
+ connect(strokeRadiusSpinBox_,
+ QOverload<double>::of(&QDoubleSpinBox::valueChanged),
+ this, &ContinousAllGlyphsTab::changed);
}
@@ -420,6 +440,7 @@ ContinousAllGlyphsTab::setDefaults()
xEmboldeningSpinBox_->setValue(0.04);
yEmboldeningSpinBox_->setValue(0.04);
slantSpinBox_->setValue(0.22);
+ strokeRadiusSpinBox_->setValue(0.02);
}
diff --git a/src/ftinspect/panels/continuous.hpp
b/src/ftinspect/panels/continuous.hpp
index c716aca..657e3af 100644
--- a/src/ftinspect/panels/continuous.hpp
+++ b/src/ftinspect/panels/continuous.hpp
@@ -82,6 +82,7 @@ public:
double xEmboldening();
double yEmboldening();
double slanting();
+ double strokeRadius();
// -1: Glyph order, otherwise the char map index in the original list
int charMapIndex();
@@ -114,10 +115,12 @@ private:
QLabel* xEmboldeningLabel_;
QLabel* yEmboldeningLabel_;
QLabel* slantLabel_;
+ QLabel* strokeRadiusLabel_;
QDoubleSpinBox* xEmboldeningSpinBox_;
QDoubleSpinBox* yEmboldeningSpinBox_;
QDoubleSpinBox* slantSpinBox_;
+ QDoubleSpinBox* strokeRadiusSpinBox_;
QGridLayout* layout_;
diff --git a/src/ftinspect/rendering/glyphcontinuous.cpp
b/src/ftinspect/rendering/glyphcontinuous.cpp
index 33e4954..e59ed20 100644
--- a/src/ftinspect/rendering/glyphcontinuous.cpp
+++ b/src/ftinspect/rendering/glyphcontinuous.cpp
@@ -4,13 +4,13 @@
#include "glyphcontinuous.hpp"
+#include "../engine/engine.hpp"
+#include "../rendering/renderutils.hpp"
+
#include <cmath>
#include <QPainter>
#include <QWheelEvent>
-#include "../engine/engine.hpp"
-#include "../rendering/renderutils.hpp"
-
GlyphContinuous::GlyphContinuous(QWidget* parent, Engine* engine)
: QWidget(parent), engine_(engine)
@@ -18,6 +18,15 @@ GlyphContinuous::GlyphContinuous(QWidget* parent, Engine*
engine)
setAcceptDrops(false);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
graphicsDefault_ = GraphicsDefault::deafultInstance();
+
+ FT_Stroker_New(engine_->ftLibrary(), &stroker_);
+}
+
+
+GlyphContinuous::~GlyphContinuous()
+{
+ cleanCloned();
+ FT_Stroker_Done(stroker_);
}
@@ -70,6 +79,15 @@ GlyphContinuous::wheelEvent(QWheelEvent* event)
void
GlyphContinuous::paintAG(QPainter* painter)
{
+ if (modeAG_ == AG_Stroked)
+ {
+ auto radius = static_cast<FT_Fixed>(metrics_.y_ppem * 64 * strokeRadius_);
+ FT_Stroker_Set(stroker_, radius,
+ FT_STROKER_LINECAP_ROUND,
+ FT_STROKER_LINEJOIN_ROUND,
+ 0);
+ }
+
for (int i = beginIndex_; i < limitIndex_; i++)
{
unsigned index = i;
@@ -123,7 +141,7 @@ GlyphContinuous::transformGlyphAGFancy()
FT_Pos xstr, ystr;
shear.xx = 1 << 16;
- shear.xy = (FT_Fixed)(slant_ * (1 << 16));
+ shear.xy = static_cast<FT_Fixed>(slant_ * (1 << 16));
shear.yx = 0;
shear.yy = 1 << 16;
@@ -155,6 +173,18 @@ GlyphContinuous::transformGlyphAGFancy()
void
GlyphContinuous::transformGlyphAGStroked()
{
+ //if (!isGlyphCloned_)
+ //cloneGlyph();
+ // Well, now here only outline glyph is supported.
+ if (glyph_->format != FT_GLYPH_FORMAT_OUTLINE)
+ return;
+ auto error = FT_Glyph_Stroke(&glyph_, stroker_, 0);
+ if (!error)
+ {
+ isGlyphCloned_ = true;
+ isOutlineCloned_ = false;
+ outline_ = reinterpret_cast<FT_OutlineGlyph>(glyph_)->outline;
+ }
}
diff --git a/src/ftinspect/rendering/glyphcontinuous.hpp
b/src/ftinspect/rendering/glyphcontinuous.hpp
index 5206170..9df2452 100644
--- a/src/ftinspect/rendering/glyphcontinuous.hpp
+++ b/src/ftinspect/rendering/glyphcontinuous.hpp
@@ -9,6 +9,7 @@
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <freetype/ftoutln.h>
+#include <freetype/ftstroke.h>
class Engine;
class GlyphContinuous
@@ -17,7 +18,7 @@ class GlyphContinuous
Q_OBJECT
public:
GlyphContinuous(QWidget* parent, Engine* engine);
- ~GlyphContinuous() override = default;
+ ~GlyphContinuous() override;
enum Mode : int
{
@@ -47,6 +48,7 @@ public:
boldY_ = boldY;
slant_ = slant;
}
+ void setStrokeRadius(double radius) { strokeRadius_ = radius; }
signals:
void wheelNavigate(int steps);
@@ -66,7 +68,8 @@ private:
int beginIndex_;
int limitIndex_;
int charMapIndex_;
- double boldX_ = 0.04, boldY_ = 0.04, slant_ = 0.22;
+ double boldX_, boldY_, slant_;
+ double strokeRadius_;
int displayingCount_ = 0;
FT_Size_Metrics metrics_;
@@ -78,6 +81,8 @@ private:
// but `isOutlineCloned` won't be set!
bool isGlyphCloned_ = false, isOutlineCloned_ = false;
+ FT_Stroker stroker_;
+
void paintAG(QPainter* painter);
void transformGlyphAGFancy();
void transformGlyphAGStroked();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2022-chariri-2 2e043b9 29/30: [ftinspect] Support Stroked SubMode in "Continuous Mode",
Werner Lemberg <=