[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master a4d3a27 36/41: [ftinspect] Format `src/ftinspec
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master a4d3a27 36/41: [ftinspect] Format `src/ftinspect/glyphcomponents/*`. |
Date: |
Mon, 3 Oct 2022 11:27:04 -0400 (EDT) |
branch: master
commit a4d3a279a8e6ed00c101ff83988518241c5a0cad
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>
[ftinspect] Format `src/ftinspect/glyphcomponents/*`.
---
src/ftinspect/glyphcomponents/glyphbitmap.cpp | 49 +++++----
src/ftinspect/glyphcomponents/glyphbitmap.hpp | 10 +-
src/ftinspect/glyphcomponents/glyphcontinuous.cpp | 122 +++++++++++----------
src/ftinspect/glyphcomponents/glyphcontinuous.hpp | 49 +++++----
src/ftinspect/glyphcomponents/glyphoutline.hpp | 8 +-
.../glyphcomponents/glyphpointnumbers.cpp | 37 ++++---
src/ftinspect/glyphcomponents/glyphpoints.cpp | 10 +-
src/ftinspect/glyphcomponents/graphicsdefault.cpp | 3 +-
src/ftinspect/glyphcomponents/graphicsdefault.hpp | 7 +-
src/ftinspect/glyphcomponents/grid.cpp | 44 ++++----
src/ftinspect/glyphcomponents/grid.hpp | 13 ++-
11 files changed, 186 insertions(+), 166 deletions(-)
diff --git a/src/ftinspect/glyphcomponents/glyphbitmap.cpp
b/src/ftinspect/glyphcomponents/glyphbitmap.cpp
index 30f6552..c93092c 100644
--- a/src/ftinspect/glyphcomponents/glyphbitmap.cpp
+++ b/src/ftinspect/glyphcomponents/glyphbitmap.cpp
@@ -3,15 +3,16 @@
// Copyright (C) 2016-2022 by Werner Lemberg.
-#include "glyphbitmap.hpp"
-
#include "../engine/engine.hpp"
+#include "glyphbitmap.hpp"
#include <cmath>
#include <utility>
+
#include <qevent.h>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
+
#include <freetype/ftbitmap.h>
@@ -20,22 +21,24 @@ GlyphBitmap::GlyphBitmap(QImage* image,
: image_(image),
boundingRect_(rect)
{
-
}
-GlyphBitmap::GlyphBitmap(int glyphIndex,
+GlyphBitmap::GlyphBitmap(int glyphIndex,
FT_Glyph glyph,
Engine* engine)
{
QRect bRect;
- image_ = engine->renderingEngine()->tryDirectRenderColorLayers(glyphIndex,
- &bRect, true);
+ image_ = engine->renderingEngine()->tryDirectRenderColorLayers(
+ glyphIndex,
+ &bRect,
+ true);
if (!image_)
- image_ = engine->renderingEngine()->convertGlyphToQImage(glyph, &bRect,
+ image_ = engine->renderingEngine()->convertGlyphToQImage(glyph,
+ &bRect,
true);
- boundingRect_ = bRect; // QRect to QRectF
+ boundingRect_ = bRect; // QRect to QRectF.
}
@@ -44,6 +47,7 @@ GlyphBitmap::~GlyphBitmap()
delete image_;
}
+
QRectF
GlyphBitmap::boundingRect() const
{
@@ -58,17 +62,17 @@ GlyphBitmap::paint(QPainter* painter,
{
if (!image_)
return;
-
+
// `drawImage' doesn't work as expected:
// the larger the zoom, the more the pixel rectangle positions
- // deviate from the grid lines
+ // deviate from the grid lines.
#if 0
painter->drawImage(QPoint(bRect.left(), bRect.top()),
image.convertToFormat(
QImage::Format_ARGB32_Premultiplied));
#else
const qreal lod = QStyleOptionGraphicsItem::levelOfDetailFromTransform(
- painter->worldTransform());
+ painter->worldTransform());
painter->setPen(Qt::NoPen);
@@ -87,7 +91,6 @@ GlyphBitmap::paint(QPainter* painter,
qAlpha(p)));
}
#endif
-
}
@@ -115,7 +118,7 @@ GlyphBitmapWidget::updateImage(QImage* image,
rect_ = rect;
placeholderRect_ = placeholderRect;
- auto zeroedRect = rect; // `GlyphBitmap` doesn't play well with offset
+ auto zeroedRect = rect; // `GlyphBitmap` doesn't play well with offset.
zeroedRect.moveTopLeft({ 0, 0 });
bitmapItem_ = new GlyphBitmap(copied, zeroedRect);
@@ -143,7 +146,7 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event)
std::min(rect_.top(), placeholderRect_.top())),
QPoint(std::max(rect_.right(), placeholderRect_.right()),
std::max(rect_.bottom(), placeholderRect_.bottom())));
-
+
double xScale = 0.9 * s.width() / br.width();
double yScale = 0.9 * s.height() / br.height();
auto margin = br.width() * 0.05;
@@ -151,48 +154,48 @@ GlyphBitmapWidget::paintEvent(QPaintEvent* event)
QPainter painter(this);
painter.fillRect(rect(), Qt::white);
- painter.save(); // push before scaling
+ painter.save(); // Push before scaling.
painter.scale(scale, scale);
painter.translate(-br.topLeft() + QPointF(margin, margin));
double scaledLineWidth = 4 / scale;
double scaledLineWidthHalf = scaledLineWidth / 2;
painter.setPen(QPen(Qt::blue, scaledLineWidth));
- // Blue line: Ink box
+ // Blue line: Ink box.
painter.drawRect(QRectF(rect_).adjusted(-scaledLineWidthHalf,
-scaledLineWidthHalf,
scaledLineWidthHalf,
scaledLineWidthHalf));
- painter.save(); // push before translating
+ painter.save(); // Push before translating.
painter.translate(rect_.topLeft());
QStyleOptionGraphicsItem ogi;
ogi.exposedRect = br;
bitmapItem_->paint(&painter, &ogi, this);
- painter.restore(); // undo translating.
+ painter.restore(); // Undo translation.
scaledLineWidth /= 2;
scaledLineWidthHalf /= 2;
- // Light gray line: EM box
+ // Light gray line: EM box.
painter.setPen(QPen(Qt::lightGray, scaledLineWidth));
- painter.drawRect(QRectF(placeholderRect_).adjusted(-scaledLineWidthHalf,
+ painter.drawRect(QRectF(placeholderRect_).adjusted(-scaledLineWidthHalf,
-scaledLineWidthHalf,
scaledLineWidthHalf,
scaledLineWidthHalf));
auto tfForAxis = painter.transform().inverted();
painter.setPen(QPen(Qt::black, scaledLineWidth / 2));
- // Thin black line: xy-axis
+ // Thin black line: x- and y-axis.
painter.drawLine(QPointF(tfForAxis.map(QPointF(0, 0)).x(), 0),
QPointF(tfForAxis.map(QPointF(s.width(), 0)).x(), 0));
painter.drawLine(QPointF(0, tfForAxis.map(QPointF(0, 0)).y()),
QPointF(0, tfForAxis.map(QPointF(0, s.height())).y()));
- painter.restore(); // undo scaling.
+ painter.restore(); // Undo scaling.
- // main border
+ // Main border.
painter.setPen(QPen(Qt::black, 4));
painter.drawRect(rect().adjusted(2, 2, -2, -2));
}
diff --git a/src/ftinspect/glyphcomponents/glyphbitmap.hpp
b/src/ftinspect/glyphcomponents/glyphbitmap.hpp
index 11d5f3f..c3bb312 100644
--- a/src/ftinspect/glyphcomponents/glyphbitmap.hpp
+++ b/src/ftinspect/glyphcomponents/glyphbitmap.hpp
@@ -6,8 +6,8 @@
#pragma once
#include <QGraphicsItem>
-#include <QPen>
#include <QPaintEvent>
+#include <QPen>
#include <QWidget>
#include <ft2build.h>
@@ -39,7 +39,7 @@ private:
};
-// Sometimes we don't want a complicated QGraphicsView
+// Sometimes we don't want a complicated `QGraphicsView`
// for this kind of work...
class GlyphBitmapWidget
: public QWidget
@@ -48,8 +48,10 @@ class GlyphBitmapWidget
public:
GlyphBitmapWidget(QWidget* parent);
~GlyphBitmapWidget() override;
-
- void updateImage(QImage* image, QRect rect, QRect placeholderRect = {});
+
+ void updateImage(QImage* image,
+ QRect rect,
+ QRect placeholderRect = {});
void releaseImage();
signals:
diff --git a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
index ebdac27..440b21e 100644
--- a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
+++ b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
@@ -2,9 +2,8 @@
// Copyright (C) 2022 by Charlie Jiang.
-#include "glyphcontinuous.hpp"
-
#include "../engine/engine.hpp"
+#include "glyphcontinuous.hpp"
#include <QPainter>
#include <QWheelEvent>
@@ -43,7 +42,8 @@ GlyphCacheEntry::operator=(GlyphCacheEntry&& other) noexcept
}
-GlyphContinuous::GlyphContinuous(QWidget* parent, Engine* engine)
+GlyphContinuous::GlyphContinuous(QWidget* parent,
+ Engine* engine)
: QWidget(parent),
engine_(engine),
stringRenderer_(engine)
@@ -177,9 +177,9 @@ GlyphContinuous::mousePressEvent(QMouseEvent* event)
prevHoriPosition_ = stringRenderer_.position();
prevIndex_ = beginIndex_;
// We need to precalculate this value because after the first change of
- // the begin index, the average line count would change. If we don't use
the
- // old value, then moving up/down for the same distance would not return
- // to the original index which is confusing.
+ // the begin index, the average line count would change. If we don't
+ // use the old value, then moving up/down for the same distance would
+ // not return to the original index, which is confusing.
averageLineCount_ = calculateAverageLineCount();
}
}
@@ -197,19 +197,20 @@ GlyphContinuous::mouseMoveEvent(QMouseEvent* event)
if (source_ == SRC_AllGlyphs)
{
auto deltaIndex = -delta.x() / HorizontalUnitLength
- - delta.y() / VerticalUnitLength * averageLineCount_;
+ - delta.y() / VerticalUnitLength * averageLineCount_;
if (prevIndex_ + deltaIndex != beginIndex_)
emit beginIndexChangeRequest(beginIndex_ + deltaIndex);
}
else if (source_ == SRC_TextString)
{
positionDelta_ = prevPositionDelta_ + delta;
- positionDelta_.setX(0); // Don't move horizontally
-
- // but use the renderer
- // purpose for two scale_: one for undoing the `delta /= scale_`
- // the other for effectively dividing width by the scale
- auto horiPos = delta.x() * scale_ * scale_ / static_cast<double>(width());
+ positionDelta_.setX(0); // Don't move horizontally.
+ // but use the renderer // WL: ???
+ // Note the double use of `scale_`: one for undoing `delta /= scale_`,
+ // the other one for effectively dividing the width by the scaling
+ // factor.
+ auto horiPos = delta.x() * scale_
+ * scale_ / static_cast<double>(width());
horiPos += prevHoriPosition_;
horiPos = qBound(0.0, horiPos, 1.0);
stringRenderer_.setPosition(horiPos);
@@ -252,14 +253,17 @@ GlyphContinuous::paintByRenderer()
stringRenderer_.setRepeated(source_ == SRC_TextStringRepeated);
stringRenderer_.setCallback(
- [&](FT_Glyph glyph, FT_Vector penPos, GlyphContext& ctx)
+ [&](FT_Glyph glyph,
+ FT_Vector penPos,
+ GlyphContext& ctx)
{
saveSingleGlyph(glyph, penPos, ctx);
});
stringRenderer_.setImageCallback(
[&](QImage* image,
- QRect pos,
- FT_Vector penPos, FT_Vector advance,
+ QRect pos,
+ FT_Vector penPos,
+ FT_Vector advance,
GlyphContext& ctx)
{
saveSingleGlyphImage(image, pos, penPos, advance, ctx);
@@ -270,11 +274,12 @@ GlyphContinuous::paintByRenderer()
preprocessGlyph(ptr);
});
stringRenderer_.setLineBeginCallback(
- [&](FT_Vector pos, double size)
+ [&](FT_Vector pos,
+ double size)
{
beginSaveLine(pos, size);
});
- auto count = stringRenderer_.render(static_cast<int>(width() / scale_),
+ auto count = stringRenderer_.render(static_cast<int>(width() / scale_),
static_cast<int>(height() / scale_),
beginIndex_);
if (source_ == SRC_AllGlyphs)
@@ -290,7 +295,7 @@ GlyphContinuous::transformGlyphFancy(FT_Glyph glyph)
auto& metrics = engine_->currentFontMetrics();
auto emboldeningX = (FT_Pos)(metrics.y_ppem * 64 * boldX_);
auto emboldeningY = (FT_Pos)(metrics.y_ppem * 64 * boldY_);
- // adopted from ftview.c:289
+ // Adopted from `ftview.c:289`.
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
{
auto outline = reinterpret_cast<FT_OutlineGlyph>(glyph)->outline;
@@ -313,8 +318,8 @@ GlyphContinuous::transformGlyphFancy(FT_Glyph glyph)
auto ystr = emboldeningY & ~63;
auto bitmap = &reinterpret_cast<FT_BitmapGlyph>(glyph)->bitmap;
- // No shearing support for bitmap
- FT_Bitmap_Embolden(engine_->ftLibrary(), bitmap,
+ // No shearing support for bitmap.
+ FT_Bitmap_Embolden(engine_->ftLibrary(), bitmap,
xstr, ystr);
}
else
@@ -341,7 +346,7 @@ GlyphContinuous::paintCache(QPainter* painter)
bool flashFlipFlop = false;
if (flashRemainingCount_ >= 0)
{
- if (flashGlyphIndex_ >= 0) // only flash when the glyph index valid
+ if (flashGlyphIndex_ >= 0) // Only flash if the glyph index is valid.
flashFlipFlop = flashRemainingCount_ % 2 == 1;
else
{
@@ -386,22 +391,17 @@ GlyphContinuous::prePaint()
{
displayingCount_ = 0;
- // Used by fancy:
- // adopted from ftview.c:289
- /***************************************************************/
- /* */
- /* 2*2 affine transformation matrix, 16.16 fixed float format */
- /* */
- /* Shear matrix: */
- /* */
- /* | x' | | 1 k | | x | x' = x + ky */
- /* | | = | | * | | <==> */
- /* | y' | | 0 1 | | y | y' = y */
- /* */
- /* outline' shear outline */
- /* */
- /***************************************************************/
-
+ // Used by 'fancy' mode; adopted from `ftview.c:289`.
+ //
+ // 2*2 affine transformation matrix, 16.16 fixed float format:
+ //
+ // Shear matrix:
+ //
+ // | x' | | 1 k | | x | x' = x + ky
+ // | | = | | * | | <==>
+ // | y' | | 0 1 | | y | y' = y
+ //
+ // outline' shear outline
shearMatrix_.xx = 1 << 16;
shearMatrix_.xy = static_cast<FT_Fixed>(slant_ * (1 << 16));
@@ -419,7 +419,8 @@ GlyphContinuous::updateStroke()
auto& metrics = engine_->currentFontMetrics();
auto radius = static_cast<FT_Fixed>(metrics.y_ppem * 64 * strokeRadius_);
strokeRadiusForSize_ = radius;
- FT_Stroker_Set(stroker_, radius,
+ FT_Stroker_Set(stroker_,
+ radius,
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
@@ -444,16 +445,17 @@ GlyphContinuous::preprocessGlyph(FT_Glyph* glyphPtr)
transformGlyphFancy(glyph);
break;
case M_Stroked:
- {
- auto stroked = transformGlyphStroked(glyph);
- if (stroked)
{
- FT_Done_Glyph(glyph);
- *glyphPtr = stroked;
+ auto stroked = transformGlyphStroked(glyph);
+ if (stroked)
+ {
+ FT_Done_Glyph(glyph);
+ *glyphPtr = stroked;
+ }
}
- }
- break;
- default:; // Nothing for M_NORMAL.
+ break;
+ default:
+ ; // Nothing for M_NORMAL.
}
}
@@ -481,8 +483,8 @@ GlyphContinuous::saveSingleGlyph(FT_Glyph glyph,
return;
QRect rect;
- QImage* image = engine_->renderingEngine()->convertGlyphToQImage(glyph,
- &rect,
+ QImage* image = engine_->renderingEngine()->convertGlyphToQImage(glyph,
+ &rect,
true);
saveSingleGlyphImage(image, rect, penPos, glyph->advance, gctx);
}
@@ -534,7 +536,7 @@ GlyphContinuous::beginDrawCacheLine(QPainter* painter,
auto printSize = line.sizePoint;
if (engine_->currentFontBitmapOnly())
- printSize = printSize * engine_->dpi() / 72.0; // convert back
+ printSize = printSize * engine_->dpi() / 72.0; // Convert back.
auto sizePrefix = QString("%1: ").arg(printSize);
painter->drawText(line.basePosition, sizePrefix);
@@ -548,22 +550,22 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter,
const GlyphCacheEntry& entry,
bool colorInverted)
{
- // ftview.c:557
- // Well, metrics is also part of the cache...
+ // From `ftview.c:557`.
+ // Well, metrics are also part of the cache...
int width = entry.advance.x ? entry.advance.x >> 16
: entry.nonSpacingPlaceholder;
auto xOffset = 0;
- if (entry.advance.x == 0
+ if (entry.advance.x == 0
&& !stringRenderer_.isWaterfall()
&& source_ == SRC_AllGlyphs)
{
- // Draw a red square to indicate non-spacing glyphs
+ // Draw a red square to indicate non-spacing glyphs.
auto squarePoint = entry.penPos;
squarePoint.setY(squarePoint.y() - width);
auto rect = QRect(squarePoint, QSize(width, width));
painter->fillRect(rect, Qt::red);
- xOffset = width; // let the glyph be drawn on the red square
+ xOffset = width; // Let the glyph be drawn on the red square.
}
QRect rect = entry.basePosition;
@@ -594,11 +596,11 @@ GlyphContinuous::findGlyphByMouse(QPoint position,
auto rect2 = QRect();
rect.moveLeft(rect.x() + line.sizeIndicatorOffset);
- if (entry.advance.x == 0
+ if (entry.advance.x == 0
&& !stringRenderer_.isWaterfall()
&& source_ == SRC_AllGlyphs)
{
- // Consider the red square
+ // Consider the red square.
int width = static_cast<int>(entry.nonSpacingPlaceholder);
if (width < 0)
continue;
@@ -609,7 +611,7 @@ GlyphContinuous::findGlyphByMouse(QPoint position,
rect2 = QRect(squarePoint, QSize(width, width));
rect.moveLeft(rect.x() + width);
}
-
+
if (rect.contains(position) || rect2.contains(position))
{
if (outSizePoint)
@@ -627,8 +629,8 @@ GlyphContinuous::calculateAverageLineCount()
int averageLineCount = 0;
for (auto& line : glyphCache_)
{
- // line.entries.size must < INT_MAX because the total glyph count in
- // the renderer is below that
+ // `line.entries.size` must be smaller than `INT_MAX` because the total
+ // glyph count in the renderer is below that.
averageLineCount += static_cast<int>(line.entries.size());
}
if (!glyphCache_.empty())
diff --git a/src/ftinspect/glyphcomponents/glyphcontinuous.hpp
b/src/ftinspect/glyphcomponents/glyphcontinuous.hpp
index 87c822c..ba451fa 100644
--- a/src/ftinspect/glyphcomponents/glyphcontinuous.hpp
+++ b/src/ftinspect/glyphcomponents/glyphcontinuous.hpp
@@ -4,15 +4,15 @@
#pragma once
-#include "graphicsdefault.hpp"
#include "../engine/stringrenderer.hpp"
+#include "graphicsdefault.hpp"
#include <utility>
#include <vector>
-#include <QWidget>
#include <QImage>
#include <QTimer>
+#include <QWidget>
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
@@ -53,12 +53,14 @@ struct GlyphCacheLine
class Engine;
+
class GlyphContinuous
: public QWidget
{
Q_OBJECT
public:
- GlyphContinuous(QWidget* parent, Engine* engine);
+ GlyphContinuous(QWidget* parent,
+ Engine* engine);
~GlyphContinuous() override;
enum Source : int
@@ -78,12 +80,14 @@ public:
int displayingCount() { return displayingCount_; }
StringRenderer& stringRenderer() { return stringRenderer_; }
- // all those setters don't trigger repaint.
+ // All those setters don't trigger a repaint operation.
void setBeginIndex(int index) { beginIndex_ = index; }
void setSource(Source source);
void setMode(Mode mode) { mode_ = mode; }
void setScale(double scale) { scale_ = scale; }
- void setFancyParams(double boldX, double boldY, double slant)
+ void setFancyParams(double boldX,
+ double boldY,
+ double slant)
{
boldX_ = boldX;
boldY_ = boldY;
@@ -92,10 +96,8 @@ public:
void setStrokeRadius(double radius) { strokeRadius_ = radius; }
void setSourceText(QString text);
void setMouseOperationEnabled(bool enabled)
- {
- mouseOperationEnabled_ = enabled;
- }
-
+ { mouseOperationEnabled_ = enabled; }
+
void flashOnGlyph(int glyphIndex);
void stopFlashing();
void purgeCache();
@@ -107,8 +109,11 @@ signals:
void wheelZoom(int steps);
void beginIndexChangeRequest(int newIndex);
void displayingCountUpdated(int newCount);
- void rightClickGlyph(int glyphIndex, double sizePoint);
- void updateGlyphDetails(GlyphCacheEntry* ctxt, int charMapIndex, bool open);
+ void rightClickGlyph(int glyphIndex,
+ double sizePoint);
+ void updateGlyphDetails(GlyphCacheEntry* ctxt,
+ int charMapIndex,
+ bool open);
protected:
void paintEvent(QPaintEvent* event) override;
@@ -129,7 +134,9 @@ private:
Source source_ = SRC_AllGlyphs;
Mode mode_ = M_Normal;
int beginIndex_;
- double boldX_, boldY_, slant_;
+ double boldX_;
+ double boldY_;
+ double slant_;
double strokeRadius_;
QString text_;
int sizeIndicatorOffset_ = 0; // For Waterfall Rendering...
@@ -146,8 +153,8 @@ private:
QColor backgroundColorCache_;
GlyphCacheLine* currentWritingLine_ = NULL;
- // Mouse operation related fields
- QPoint positionDelta_; // For dragging on the text to move
+ // Fields related to mouse operation.
+ QPoint positionDelta_; // For dragging on the text to move.
double prevHoriPosition_;
QPoint prevPositionDelta_ = { 0, 0 };
QPoint mouseDownPostition_ = { 0, 0 };
@@ -156,8 +163,9 @@ private:
void paintByRenderer();
- // These two assume ownership of glyphs, but don't free them.
- // However, remember to free the glyph returned from `transformGlyphStroked`
+ // These two assume functions ownership of glyphs, but don't free them.
+ // However, remember to free the glyph returned from
+ // `transformGlyphStroked`.
void transformGlyphFancy(FT_Glyph glyph);
FT_Glyph transformGlyphStroked(FT_Glyph glyph);
@@ -167,6 +175,7 @@ private:
void updateStroke();
void updateRendererText();
void preprocessGlyph(FT_Glyph* glyphPtr);
+
// Callbacks
void beginSaveLine(FT_Vector pos,
double sizePoint);
@@ -179,26 +188,26 @@ private:
FT_Vector advance,
GlyphContext gctx);
- // Funcs drawing from the cache
+ // Functions drawing from the cache.
void beginDrawCacheLine(QPainter* painter,
GlyphCacheLine& line);
void drawCacheGlyph(QPainter* painter,
const GlyphCacheEntry& entry,
bool colorInverted = false);
- // Mouse operations
+ // Mouse operations.
GlyphCacheEntry* findGlyphByMouse(QPoint position,
double* outSizePoint);
int calculateAverageLineCount();
void flashTimerFired();
- // Mouse constants
+ // Mouse constants.
constexpr static int ClickDragThreshold = 10;
constexpr static int HorizontalUnitLength = 100;
constexpr static int VerticalUnitLength = 150;
- // Flash Timer constants
+ // Flash timer constants.
constexpr static int FlashIntervalMs = 250;
constexpr static int FlashDurationMs = 3000;
};
diff --git a/src/ftinspect/glyphcomponents/glyphoutline.hpp
b/src/ftinspect/glyphcomponents/glyphoutline.hpp
index 728cbc7..1d8959a 100644
--- a/src/ftinspect/glyphcomponents/glyphoutline.hpp
+++ b/src/ftinspect/glyphcomponents/glyphoutline.hpp
@@ -5,8 +5,8 @@
#pragma once
-#include <QPainterPath>
#include <QGraphicsItem>
+#include <QPainterPath>
#include <QPen>
#include <ft2build.h>
@@ -33,10 +33,8 @@ private:
};
-/*
- * This class is common for all classes holding an outline.
- * But `GlyphOutline` class itself don't need to hold the outline...
- */
+// This class is common for all classes holding an outline.
+// However, clss `GlyphOutline` itself doesn't need to hold the outline...
class GlyphUsingOutline
: public QGraphicsItem
diff --git a/src/ftinspect/glyphcomponents/glyphpointnumbers.cpp
b/src/ftinspect/glyphcomponents/glyphpointnumbers.cpp
index c364b31..d20eebf 100644
--- a/src/ftinspect/glyphcomponents/glyphpointnumbers.cpp
+++ b/src/ftinspect/glyphcomponents/glyphpointnumbers.cpp
@@ -31,16 +31,16 @@ GlyphPointNumbers::paint(QPainter* painter,
auto lod = QStyleOptionGraphicsItem::levelOfDetailFromTransform(
painter->worldTransform());
- // don't draw point numbers if magnification is too small
+ // Don't draw point numbers if magnification is too small.
if (lod >= 10)
{
QFont font = painter->font();
- // the following doesn't work correctly with scaling;
+ // The following doesn't work correctly with scaling;
// it seems that Qt doesn't allow arbitrarily small font sizes
- // that get magnified later on
+ // that get magnified later on.
#if 0
- // we want the same text size regardless of the scaling
+ // We want the same text size regardless of the scaling.
font.setPointSizeF(font.pointSizeF() / lod);
painter->setFont(font);
#else
@@ -72,9 +72,10 @@ GlyphPointNumbers::paint(QPainter* painter,
{
for (;;)
{
- short prevIdx, nextIdx;
+ short prevIdx;
+ short nextIdx;
- // find previous and next point in outline
+ // Find previous and next point in outline.
if (contIdx == 0)
{
if (contours[contIdx] == 0)
@@ -98,7 +99,7 @@ GlyphPointNumbers::paint(QPainter* painter,
: contours[contIdx - 1] + 1;
}
- // get vectors to previous and next point and normalize them;
+ // Get vectors to previous and next point and normalize them.
QVector2D in(static_cast<float>(points[prevIdx].x
- points[ptIdx].x) / 64,
-static_cast<float>(points[prevIdx].y
@@ -112,35 +113,35 @@ GlyphPointNumbers::paint(QPainter* painter,
out = out.normalized();
QVector2D middle = in + out;
- // check whether vector is very small, using a threshold of 1/8px
+ // Check whether vector is very small, using a threshold of 1/8px.
if (qAbs(middle.x()) < 1.0f / 8
&& qAbs(middle.y()) < 1.0f / 8)
{
- // in case of vectors in almost exactly opposite directions,
- // use a vector orthogonal to them
+ // In case of vectors in almost exactly opposite directions,
+ // use a vector orthogonal to them.
middle.setX(out.y());
middle.setY(-out.x());
if (qAbs(middle.x()) < 1.0f / 8
&& qAbs(middle.y()) < 1.0f / 8)
{
- // use direction based on point index for the offset
- // if we still don't have a good value
+ // Use direction based on point index for the offset
+ // if we still don't have a good value.
middle = octants[ptIdx % 8];
}
}
- // normalize `middle' vector (which is never zero),
+ // Normalize `middle` vector (which is never zero),
// then multiply by 8 to get some distance between
- // the point and the number
+ // the point and the number.
middle = middle.normalized() * 8;
- // we now position the point number in the opposite
- // direction of the `middle' vector,
+ // We now position the point number in the opposite
+ // direction of the `middle` vector.
QString number = QString::number(ptIdx);
#if 0
- // this fails, see comment above
+ // This fails, see comment above.
int size = 10000;
qreal x = qreal(points[ptIdx].x) / 64 - middle.x() / lod;
qreal y = -qreal(points[ptIdx].y) / 64 - middle.y() / lod;
@@ -158,7 +159,7 @@ GlyphPointNumbers::paint(QPainter* painter,
painter->drawText(posRect, flags, number);
#else
- // convert text string to a path object
+ // Convert text string to a path object.
QPainterPath path;
path.addText(QPointF(0, 0), font, number);
QRectF ctrlPtRect = path.controlPointRect();
diff --git a/src/ftinspect/glyphcomponents/glyphpoints.cpp
b/src/ftinspect/glyphcomponents/glyphpoints.cpp
index 56a9c09..3ddc698 100644
--- a/src/ftinspect/glyphcomponents/glyphpoints.cpp
+++ b/src/ftinspect/glyphcomponents/glyphpoints.cpp
@@ -31,14 +31,14 @@ GlyphPoints::paint(QPainter* painter,
const qreal lod = option->levelOfDetailFromTransform(
painter->worldTransform());
- // don't draw points if magnification is too small
+ // Don't draw points if magnification is too small.
if (lod >= 5)
{
- // we want the same dot size regardless of the scaling;
- // for good optical results, the pen widths should be uneven integers
+ // We want the same dot size regardless of the scaling;
+ // for good optical results, the pen widths should be uneven integers.
- // interestingly, using `drawPoint' doesn't work as expected:
- // the larger the zoom, the more horizontally stretched the dot appears
+ // Interestingly, using `drawPoint` doesn't work as expected:
+ // the larger the zoom, the more horizontally stretched the dot appears.
#if 0
qreal origOnPenWidth = onPen.widthF();
qreal origOffPenWidth = offPen.widthF();
diff --git a/src/ftinspect/glyphcomponents/graphicsdefault.cpp
b/src/ftinspect/glyphcomponents/graphicsdefault.cpp
index ad5ae00..bc48418 100644
--- a/src/ftinspect/glyphcomponents/graphicsdefault.cpp
+++ b/src/ftinspect/glyphcomponents/graphicsdefault.cpp
@@ -4,6 +4,7 @@
#include "graphicsdefault.hpp"
+
GraphicsDefault* GraphicsDefault::instance_ = NULL;
GraphicsDefault::GraphicsDefault()
@@ -14,7 +15,7 @@ GraphicsDefault::GraphicsDefault()
axisPen.setWidth(0);
blueZonePen.setColor(QColor(64, 64, 255, 64)); // light blue
blueZonePen.setWidth(0);
- // Don't make this solid
+ // Don't make this solid.
gridPen.setColor(QColor(0, 0, 0, 255 - QColor(Qt::lightGray).red()));
gridPen.setWidth(0);
offPen.setColor(Qt::darkGreen);
diff --git a/src/ftinspect/glyphcomponents/graphicsdefault.hpp
b/src/ftinspect/glyphcomponents/graphicsdefault.hpp
index 991771c..996fe1d 100644
--- a/src/ftinspect/glyphcomponents/graphicsdefault.hpp
+++ b/src/ftinspect/glyphcomponents/graphicsdefault.hpp
@@ -4,11 +4,12 @@
#pragma once
-#include <QVector>
-#include <QRgb>
#include <QPen>
+#include <QRgb>
+#include <QVector>
+
-// This is default graphics objects fed into render functions.
+// This is the default graphics object fed into render functions.
struct GraphicsDefault
{
QPen axisPen;
diff --git a/src/ftinspect/glyphcomponents/grid.cpp
b/src/ftinspect/glyphcomponents/grid.cpp
index 29740ed..ba15ed4 100644
--- a/src/ftinspect/glyphcomponents/grid.cpp
+++ b/src/ftinspect/glyphcomponents/grid.cpp
@@ -3,20 +3,18 @@
// Copyright (C) 2016-2022 by Werner Lemberg.
-#include "grid.hpp"
-
#include "graphicsdefault.hpp"
+#include "grid.hpp"
+#include <QGraphicsView>
+#include <QGraphicsWidget>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
-#include <QGraphicsWidget>
-#include <QGraphicsView>
Grid::Grid(QGraphicsView* parentView)
-: parentView_(parentView)
+: parentView_(parentView)
{
- // empty
updateRect();
}
@@ -32,14 +30,14 @@ void
Grid::updateRect()
{
auto viewport = parentView_->mapToScene(parentView_->viewport()->geometry())
- .boundingRect()
- .toRect();
+ .boundingRect()
+ .toRect();
int minX = std::min(viewport.left() - 10, -100);
int minY = std::min(viewport.top() - 10, -100);
int maxX = std::max(viewport.right() + 10, 100);
int maxY = std::max(viewport.bottom() + 10, 100);
- auto newSceneRect = QRectF(QPointF(minX - 20, minY - 20),
+ auto newSceneRect = QRectF(QPointF(minX - 20, minY - 20),
QPointF(maxX + 20, maxY + 20));
if (sceneRect_ != newSceneRect && scene())
{
@@ -47,9 +45,9 @@ Grid::updateRect()
sceneRect_ = newSceneRect;
}
- // no need to take care of pen width
- rect_ = QRectF(QPointF(minX, minY),
- QPointF(maxX, maxY));
+ // No need to take care of pen width.
+ rect_ = QRectF(QPointF(minX, minY),
+ QPointF(maxX, maxY));
}
@@ -70,13 +68,12 @@ Grid::paint(QPainter* painter,
if (showGrid_)
{
painter->setPen(gb->gridPen);
-
- // don't mark pixel center with a cross if magnification is too small
+
+ // Don't mark pixel center with a cross if magnification is too small.
if (lod > 20)
{
int halfLength = 1;
-
- // cf. QSpinBoxx
+
if (lod > 640)
halfLength = 6;
else if (lod > 320)
@@ -87,7 +84,7 @@ Grid::paint(QPainter* painter,
halfLength = 3;
else if (lod > 40)
halfLength = 2;
-
+
for (qreal x = minX; x < maxX; x++)
for (qreal y = minY; y < maxY; y++)
{
@@ -97,8 +94,8 @@ Grid::paint(QPainter* painter,
x + 0.5 + halfLength / lod, y + 0.5));
}
}
-
- // don't draw grid if magnification is too small
+
+ // Don't draw grid if magnification is too small.
if (lod >= 5)
{
for (int x = minX; x <= maxX; x++)
@@ -108,9 +105,9 @@ Grid::paint(QPainter* painter,
painter->drawLine(minX, y,
maxX, y);
}
-
+
painter->setPen(gb->axisPen);
-
+
painter->drawLine(0, minY,
0, maxY);
painter->drawLine(minX, 0,
@@ -133,7 +130,8 @@ Grid::paint(QPainter* painter,
void
-Grid::setShowGrid(bool showGrid, bool showAuxLines)
+Grid::setShowGrid(bool showGrid,
+ bool showAuxLines)
{
showGrid_ = showGrid;
showAuxLines_ = showAuxLines;
@@ -146,7 +144,7 @@ Grid::updateParameters(int ascenderPx,
int descenderPx,
int advancePx)
{
- // Need to flip the Y coord (originally Cartesian)
+ // Need to flip the Y coord (originally Cartesian).
ascender_ = -ascenderPx;
descender_ = -descenderPx;
advance_ = advancePx;
diff --git a/src/ftinspect/glyphcomponents/grid.hpp
b/src/ftinspect/glyphcomponents/grid.hpp
index 92008d7..ca8307f 100644
--- a/src/ftinspect/glyphcomponents/grid.hpp
+++ b/src/ftinspect/glyphcomponents/grid.hpp
@@ -9,6 +9,7 @@
#include <QGraphicsView>
#include <QPen>
+
class Grid
: public QGraphicsItem
{
@@ -19,10 +20,13 @@ public:
const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
- void setShowGrid(bool showGrid, bool showAuxLines);
- void updateParameters(int ascenderPx, int descenderPx, int advancePx);
+ void setShowGrid(bool showGrid,
+ bool showAuxLines);
+ void updateParameters(int ascenderPx,
+ int descenderPx,
+ int advancePx);
- void updateRect(); // there's no signal/slots for QGraphicsItem.
+ void updateRect(); // There's no signal/slots for QGraphicsItem.
private:
QGraphicsView* parentView_;
@@ -32,7 +36,8 @@ private:
bool showGrid_ = true;
bool showAuxLines_ = false;
- int ascender_ = 0, descender_ = 0;
+ int ascender_ = 0;
+ int descender_ = 0;
int advance_ = 0;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master a4d3a27 36/41: [ftinspect] Format `src/ftinspect/glyphcomponents/*`.,
Werner Lemberg <=