freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] gsoc-2022-chariri-3 b9bf1a7 28/36: [ftinspect] Properl


From: Werner Lemberg
Subject: [freetype2-demos] gsoc-2022-chariri-3 b9bf1a7 28/36: [ftinspect] Properly handling cases of glyph hAdvance == 0
Date: Wed, 27 Jul 2022 06:32:46 -0400 (EDT)

branch: gsoc-2022-chariri-3
commit b9bf1a7c49473a74f067553e4fc665ad155f786e
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>

    [ftinspect] Properly handling cases of glyph hAdvance == 0
    
    Sometimes the glyph contains no control point thus can't be properly
    translated to the pen position. Therefore the correct pen position must
    be passed to the drawing callback.
    
    * src/ftinspect/engine/stringrenderer.cpp,
      src/ftinspect/engine/stringrenderer.hpp: Pass pen position to the
      callback. Adjust the check of control box to allow x, y = 0, 0 cases.
    
    * src/ftinspect/rendering/glyphcontinuous.cpp,
      src/ftinspect/rendering/glyphcontinuous.hpp: Use the received pen position
      to draw the red square.
---
 src/ftinspect/engine/stringrenderer.cpp     | 17 +++++++++--------
 src/ftinspect/engine/stringrenderer.hpp     |  7 ++++++-
 src/ftinspect/rendering/glyphcontinuous.cpp | 15 ++++++++-------
 src/ftinspect/rendering/glyphcontinuous.hpp |  3 ++-
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/ftinspect/engine/stringrenderer.cpp 
b/src/ftinspect/engine/stringrenderer.cpp
index 6c05422..d1e95a9 100644
--- a/src/ftinspect/engine/stringrenderer.cpp
+++ b/src/ftinspect/engine/stringrenderer.cpp
@@ -523,21 +523,22 @@ StringRenderer::renderLine(int x,
     if (matrixEnabled_)
       FT_Vector_Transform(&advance, &matrix_);
 
-    pen.x += advance.x;
-    pen.y += advance.y;
-
     FT_Glyph_Get_CBox(image, FT_GLYPH_BBOX_PIXELS, &bbox);
 
     // check bounding box; if it is completely outside the
     // display surface, we don't need to render it
-    if (bbox.xMax > 0 
-        && bbox.yMax > 0
-        && bbox.xMin < width
-        && bbox.yMin < height)
+    if (bbox.xMax >= 0 
+        && bbox.yMax >= 0
+        && bbox.xMin <= width
+        && bbox.yMin <= height)
     {
-      renderCallback_(image);
+      FT_Vector penPos = { (pen.x >> 6), height - (pen.y >> 6) };
+      renderCallback_(image, penPos);
     }
 
+    pen.x += advance.x;
+    pen.y += advance.y;
+
     FT_Done_Glyph(image);
   }
 
diff --git a/src/ftinspect/engine/stringrenderer.hpp 
b/src/ftinspect/engine/stringrenderer.hpp
index f4f62cd..b55b412 100644
--- a/src/ftinspect/engine/stringrenderer.hpp
+++ b/src/ftinspect/engine/stringrenderer.hpp
@@ -56,7 +56,12 @@ public:
     KM_Smart
   };
 
-  using RenderCallback = std::function<void(FT_Glyph)>;
+  /*
+   * Need to pass the pen position because sometimes the outline vector
+   * contains no points, and thus can't be translated to the desired pen
+   * position.
+   */
+  using RenderCallback = std::function<void(FT_Glyph, FT_Vector)>;
   /*
    * The glyph pointer may be replaced. In that case, ownership is transfered
    * to the renderer, and the new glyph will be eventually freed by
diff --git a/src/ftinspect/rendering/glyphcontinuous.cpp 
b/src/ftinspect/rendering/glyphcontinuous.cpp
index c93f764..0d7f63b 100644
--- a/src/ftinspect/rendering/glyphcontinuous.cpp
+++ b/src/ftinspect/rendering/glyphcontinuous.cpp
@@ -97,9 +97,9 @@ GlyphContinuous::paintByRenderer(QPainter* painter)
 
   stringRenderer_.setRepeated(source_ == SRC_TextStringRepeated);
   stringRenderer_.setCallback(
-    [&](FT_Glyph glyph)
+    [&](FT_Glyph glyph, FT_Vector penPos)
     {
-      drawSingleGlyph(painter, glyph);
+      drawSingleGlyph(painter, glyph, penPos);
     });
   stringRenderer_.setPreprocessCallback(
     [&](FT_Glyph* ptr)
@@ -261,17 +261,18 @@ GlyphContinuous::beginLine(QPainter* painter,
 
 
 void
-GlyphContinuous::drawSingleGlyph(QPainter* painter, FT_Glyph glyph)
+GlyphContinuous::drawSingleGlyph(QPainter* painter, 
+                                 FT_Glyph glyph,
+                                 FT_Vector penPos)
 {
   // ftview.c:557
   int width = glyph->advance.x ? glyph->advance.x >> 16
-                                : metrics_.y_ppem / 2;
-  
+                               : metrics_.y_ppem / 2;
+
   if (glyph->advance.x == 0 && !stringRenderer_.isWaterfall())
   {
     // Draw a red square to indicate
-      painter->fillRect(x_, y_ - width, width, width,
-                        Qt::red);
+    painter->fillRect(penPos.x, penPos.y - width, width, width, Qt::red);
   }
 
   QRect rect;
diff --git a/src/ftinspect/rendering/glyphcontinuous.hpp 
b/src/ftinspect/rendering/glyphcontinuous.hpp
index 7ead399..9260b50 100644
--- a/src/ftinspect/rendering/glyphcontinuous.hpp
+++ b/src/ftinspect/rendering/glyphcontinuous.hpp
@@ -101,7 +101,8 @@ private:
                  FT_Vector pos, 
                  double sizePoint);
   void drawSingleGlyph(QPainter* painter,
-                       FT_Glyph glyph);
+                       FT_Glyph glyph,
+                       FT_Vector penPos);
 };
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]