[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2022-chariri-3 2261646 20/36: [ftinspect] Fix Sin
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] gsoc-2022-chariri-3 2261646 20/36: [ftinspect] Fix Singular Grid View. |
Date: |
Wed, 27 Jul 2022 06:32:45 -0400 (EDT) |
branch: gsoc-2022-chariri-3
commit 226164633cedcdb8455b70152499596b7423fdd9
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>
[ftinspect] Fix Singular Grid View.
When drawing a `FT_BitmapGlyph`, sometimes the `bitmap->top` need to be
negated while sometimes not, so add a argument to control this behavior.
* src/ftinspect/engine/engine.cpp, src/ftinspect/engine/engine.hpp:
Add `inverseRectY` arg to `Engine::convertGlyphToQImage`.
* src/ftinspect/rendering/glyphbitmap.cpp: Negate Y coord.
* src/ftinspect/rendering/glyphcontinuous.cpp: Don't negate Y coord.
---
src/ftinspect/engine/engine.cpp | 17 +++++++++++++----
src/ftinspect/engine/engine.hpp | 6 ++++--
src/ftinspect/rendering/glyphbitmap.cpp | 2 +-
src/ftinspect/rendering/glyphcontinuous.cpp | 2 +-
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/ftinspect/engine/engine.cpp b/src/ftinspect/engine/engine.cpp
index 32794de..da0573b 100644
--- a/src/ftinspect/engine/engine.cpp
+++ b/src/ftinspect/engine/engine.cpp
@@ -882,7 +882,9 @@ cleanup:
QImage*
-Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
+Engine::convertGlyphToQImage(FT_Glyph src,
+ QRect* outRect,
+ bool inverseRectY)
{
FT_BitmapGlyph bitmapGlyph;
bool ownBitmapGlyph
@@ -895,7 +897,10 @@ Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
if (result && outRect)
{
outRect->setLeft(bitmapGlyph->left);
- outRect->setTop(bitmapGlyph->top);
+ if (inverseRectY)
+ outRect->setTop(-bitmapGlyph->top);
+ else
+ outRect->setTop(bitmapGlyph->top);
outRect->setWidth(bitmapGlyph->bitmap.width);
outRect->setHeight(bitmapGlyph->bitmap.rows);
}
@@ -908,7 +913,7 @@ Engine::convertGlyphToQImage(FT_Glyph src, QRect* outRect)
QPoint
-Engine::computeGlyphOffset(FT_Glyph glyph)
+Engine::computeGlyphOffset(FT_Glyph glyph, bool inverseY)
{
if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
{
@@ -919,13 +924,17 @@ Engine::computeGlyphOffset(FT_Glyph glyph)
cbox.yMin &= ~63;
cbox.xMax = (cbox.xMax + 63) & ~63;
cbox.yMax = (cbox.yMax + 63) & ~63;
+ if (inverseY)
+ cbox.yMax = -cbox.yMax;
return { static_cast<int>(cbox.xMin) / 64,
static_cast<int>(cbox.yMax / 64) };
}
if (glyph->format == FT_GLYPH_FORMAT_BITMAP)
{
auto bg = reinterpret_cast<FT_BitmapGlyph>(glyph);
- return { bg->left, -bg->top };
+ if (inverseY)
+ return { bg->left, -bg->top };
+ return { bg->left, bg->top };
}
return {};
diff --git a/src/ftinspect/engine/engine.hpp b/src/ftinspect/engine/engine.hpp
index 47001b7..eb345a8 100644
--- a/src/ftinspect/engine/engine.hpp
+++ b/src/ftinspect/engine/engine.hpp
@@ -89,8 +89,10 @@ public:
bool convertGlyphToBitmapGlyph(FT_Glyph src, FT_Glyph* out);
FT_Bitmap convertBitmapTo8Bpp(FT_Bitmap* bitmap);
QImage* convertBitmapToQImage(FT_Bitmap* src);
- QImage* convertGlyphToQImage(FT_Glyph src, QRect* outRect);
- QPoint computeGlyphOffset(FT_Glyph glyph);
+ QImage* convertGlyphToQImage(FT_Glyph src,
+ QRect* outRect,
+ bool inverseRectY);
+ QPoint computeGlyphOffset(FT_Glyph glyph, bool inverseY);
// reload current triplet, but with updated settings, useful for updating
// `ftSize_` only
diff --git a/src/ftinspect/rendering/glyphbitmap.cpp
b/src/ftinspect/rendering/glyphbitmap.cpp
index aab7776..a3a35db 100644
--- a/src/ftinspect/rendering/glyphbitmap.cpp
+++ b/src/ftinspect/rendering/glyphbitmap.cpp
@@ -18,7 +18,7 @@ GlyphBitmap::GlyphBitmap(FT_Glyph glyph,
Engine* engine)
{
QRect bRect;
- image_ = engine->convertGlyphToQImage(glyph, &bRect);
+ image_ = engine->convertGlyphToQImage(glyph, &bRect, true);
boundingRect_ = bRect; // QRectF to QRect
}
diff --git a/src/ftinspect/rendering/glyphcontinuous.cpp
b/src/ftinspect/rendering/glyphcontinuous.cpp
index 3eb61c6..f30ea51 100644
--- a/src/ftinspect/rendering/glyphcontinuous.cpp
+++ b/src/ftinspect/rendering/glyphcontinuous.cpp
@@ -244,7 +244,7 @@ GlyphContinuous::drawSingleGlyph(QPainter* painter,
FT_Glyph glyph)
}
QRect rect;
- QImage* image = engine_->convertGlyphToQImage(glyph, &rect);
+ QImage* image = engine_->convertGlyphToQImage(glyph, &rect, false);
rect.setTop(height() - rect.top());
painter->drawImage(rect.topLeft(), *image);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2022-chariri-3 2261646 20/36: [ftinspect] Fix Singular Grid View.,
Werner Lemberg <=