Commits:
-
f10ef416
by Charlie Jiang
at 2022-07-28T21:19:06+08:00
[ftinspect] Properly handle advance for prerendered `QImage`s.
* src/ftinspect/rendering/glyphcontinuous.cpp,
src/ftinspect/rendering/glyphcontinuous.hpp: Remove `hasAdvance` field
from `GlyphCacheEntry` struct, and set the proper advance for `QImage`
prerendered entries.
* src/ftinspect/engine/stringrenderer.cpp,
src/ftinspect/engine/stringrenderer.hpp: Add an argument to the
`RenderImageCallback` to pass the advance.
4 changed files:
Changes:
src/ftinspect/engine/stringrenderer.cpp
... |
... |
@@ -510,7 +510,7 @@ StringRenderer::renderLine(int x, |
510
|
510
|
{
|
511
|
511
|
rect.setX(rect.x() + (pen.x >> 6));
|
512
|
512
|
rect.setY(height - rect.y() - (pen.y >> 6));
|
513
|
|
- renderImageCallback_(colorLayerImage, rect, ctx);
|
|
513
|
+ renderImageCallback_(colorLayerImage, rect, advance, ctx);
|
514
|
514
|
}
|
515
|
515
|
else
|
516
|
516
|
{
|
src/ftinspect/engine/stringrenderer.hpp
... |
... |
@@ -71,6 +71,7 @@ public: |
71
|
71
|
*/
|
72
|
72
|
using RenderImageCallback = std::function<void(QImage*,
|
73
|
73
|
QRect,
|
|
74
|
+ FT_Vector,
|
74
|
75
|
GlyphContext&)>;
|
75
|
76
|
/*
|
76
|
77
|
* The glyph pointer may be replaced. In that case, ownership is transfered
|
src/ftinspect/rendering/glyphcontinuous.cpp
... |
... |
@@ -37,7 +37,6 @@ GlyphCacheEntry::operator=(GlyphCacheEntry&& other) noexcept |
37
|
37
|
charCode = other.charCode;
|
38
|
38
|
glyphIndex = other.glyphIndex;
|
39
|
39
|
advance = other.advance;
|
40
|
|
- hasAdvance = other.hasAdvance;
|
41
|
40
|
other.image = oldImage;
|
42
|
41
|
return *this;
|
43
|
42
|
}
|
... |
... |
@@ -223,9 +222,9 @@ GlyphContinuous::paintByRenderer() |
223
|
222
|
saveSingleGlyph(glyph, penPos, ctx);
|
224
|
223
|
});
|
225
|
224
|
stringRenderer_.setImageCallback(
|
226
|
|
- [&](QImage* image, QRect pos, GlyphContext& ctx)
|
|
225
|
+ [&](QImage* image, QRect pos, FT_Vector advance, GlyphContext& ctx)
|
227
|
226
|
{
|
228
|
|
- saveSingleGlyphImage(image, pos, ctx);
|
|
227
|
+ saveSingleGlyphImage(image, pos, advance, ctx);
|
229
|
228
|
});
|
230
|
229
|
stringRenderer_.setPreprocessCallback(
|
231
|
230
|
[&](FT_Glyph* ptr)
|
... |
... |
@@ -435,19 +434,20 @@ GlyphContinuous::saveSingleGlyph(FT_Glyph glyph, |
435
|
434
|
void
|
436
|
435
|
GlyphContinuous::saveSingleGlyphImage(QImage* image,
|
437
|
436
|
QRect pos,
|
|
437
|
+ FT_Vector advance,
|
438
|
438
|
GlyphContext gctx)
|
439
|
439
|
{
|
440
|
440
|
if (!currentWritingLine_)
|
441
|
441
|
return;
|
442
|
442
|
|
443
|
|
- currentWritingLine_->entries.push_back(std::move(GlyphCacheEntry{}));
|
|
443
|
+ currentWritingLine_->entries.push_back(GlyphCacheEntry{});
|
444
|
444
|
auto& entry = currentWritingLine_->entries.back();
|
445
|
445
|
|
446
|
446
|
entry.image = image;
|
447
|
447
|
entry.basePosition = pos;
|
448
|
448
|
entry.charCode = gctx.charCode;
|
449
|
449
|
entry.glyphIndex = gctx.glyphIndex;
|
450
|
|
- entry.hasAdvance = false;
|
|
450
|
+ entry.advance = advance;
|
451
|
451
|
}
|
452
|
452
|
|
453
|
453
|
|
src/ftinspect/rendering/glyphcontinuous.hpp
... |
... |
@@ -28,7 +28,6 @@ struct GlyphCacheEntry |
28
|
28
|
int glyphIndex = -1;
|
29
|
29
|
|
30
|
30
|
FT_Vector advance = {};
|
31
|
|
- bool hasAdvance = false;
|
32
|
31
|
|
33
|
32
|
GlyphCacheEntry() {}
|
34
|
33
|
~GlyphCacheEntry();
|
... |
... |
@@ -156,6 +155,7 @@ private: |
156
|
155
|
GlyphContext gctx);
|
157
|
156
|
void saveSingleGlyphImage(QImage* image,
|
158
|
157
|
QRect pos,
|
|
158
|
+ FT_Vector advance,
|
159
|
159
|
GlyphContext gctx);
|
160
|
160
|
void beginDrawCacheLine(QPainter* painter,
|
161
|
161
|
GlyphCacheLine& line);
|
|