freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master fbc7269 23/41: [ftinspect] Add "Continuous View


From: Werner Lemberg
Subject: [freetype2-demos] master fbc7269 23/41: [ftinspect] Add "Continuous View".
Date: Mon, 3 Oct 2022 11:27:02 -0400 (EDT)

branch: master
commit fbc7269cbff8bec2eb3d8508bbbeb6a6c3d7e74e
Author: Charlie Jiang <w@chariri.moe>
Commit: Werner Lemberg <wl@gnu.org>

    [ftinspect] Add "Continuous View".
    
    Most new features in the continuous view are included in the commit, except
    the mouse left (details pane)/right (go to singular) click behaviour.
    
    * src/ftinspect/panels/continuous.cpp, src/ftinspect/panels/continuous.hpp:
      New files, the main continuous tab.
    
    * src/ftinspect/glyphcomponents/glyphcontinuous.cpp,
      src/ftinspect/glyphcomponents/glyphcontinuous.hpp:
      New files, adding the `GlyphContinuous` as the actual canvas for
      continuous rendering.
    
    * src/ftinspect/engine/stringrenderer.cpp,
      src/ftinspect/engine/stringrenderer.hpp:
      New files, adding `StringRenderer` to layout the strings and produce
      glyphs for the canvas to draw.
    
    * src/ftinspect/widgets/charmapcombobox.cpp,
      src/ftinspect/widgets/charmapcombobox.hpp:
      New files, add the `CharMapComboBox` widget.
    
    * src/ftinspect/engine/charmap.cpp,src/ftinspect/engine/charmap.hpp:
      New files, adding `CharMapInfo` class.
    
    * src/ftinspect/engine/engine.cpp, src/ftinspect/engine/engine.hpp:
      Add necessary fields and getters for string rendering.
      Retrieve charmap when loading fonts.
    
    * src/ftinspect/maingui.cpp, src/ftinspect/maingui.hpp:
      Add the continuous view to the main window.
      Call `ContinuousTab::highlightGlyph` when switching from singular to
      continuous view.
    
    * src/ftinspect/panels/settingpanel.cpp: Uncomment functional code.
    
    * src/ftinspect/CMakeLists.txt, src/ftinspect/meson.build: Updated.
---
 src/ftinspect/engine/stringrenderer.cpp           |  7 +++++++
 src/ftinspect/glyphcomponents/glyphcontinuous.cpp | 24 +++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/ftinspect/engine/stringrenderer.cpp 
b/src/ftinspect/engine/stringrenderer.cpp
index bd9eaf1..20fa666 100644
--- a/src/ftinspect/engine/stringrenderer.cpp
+++ b/src/ftinspect/engine/stringrenderer.cpp
@@ -505,9 +505,13 @@ StringRenderer::render(int width,
   auto stepY = static_cast<int>(metrics.height >> 6) + 1;
   y += 4 + static_cast<int>(metrics.ascender >> 6);
 
+  auto lastOffset = 0;
   while (offset < static_cast<int>(activeGlyphs_.size()))
   {
     offset = renderLine(x, y, width, height, offset, true);
+    if (offset == lastOffset) // prevent inf loop.
+      break;
+    lastOffset = offset;
     y += stepY;
   }
   return offset - initialOffset;
@@ -522,6 +526,9 @@ StringRenderer::renderLine(int x,
                            int offset,
                            bool handleMultiLine)
 {
+  // Don't limit the x y to be within the canvas viewport: string can be moved
+  // by the mouse
+
   y = height - y; // change to Cartesian coordinates
 
   FT_Vector pen = { 0, 0 };
diff --git a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp 
b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
index 64e46ce..37f7db5 100644
--- a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
+++ b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
@@ -527,6 +527,7 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter,
   // Well, metrics is also part of the cache...
   int width = entry.advance.x ? entry.advance.x >> 16
                               : entry.nonSpacingPlaceholder;
+  auto xOffset = 0;
 
   if (entry.advance.x == 0 
       && !stringRenderer_.isWaterfall()
@@ -537,10 +538,11 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter,
     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
   }
 
   QRect rect = entry.basePosition;
-  rect.moveLeft(rect.x() + sizeIndicatorOffset_);
+  rect.moveLeft(rect.x() + sizeIndicatorOffset_ + xOffset);
   rect.translate(positionDelta_);
 
   if (colorInverted)
@@ -564,8 +566,26 @@ GlyphContinuous::findGlyphByMouse(QPoint position,
     for (auto& entry : line.entries)
     {
       auto rect = entry.basePosition;
+      auto rect2 = QRect();
       rect.moveLeft(rect.x() + line.sizeIndicatorOffset);
-      if (rect.contains(position))
+
+      if (entry.advance.x == 0 
+          && !stringRenderer_.isWaterfall()
+          && source_ == SRC_AllGlyphs)
+      {
+        // Consider the red square
+        int width = static_cast<int>(entry.nonSpacingPlaceholder);
+        if (width < 0)
+          continue;
+
+        auto squarePoint = entry.penPos;
+        squarePoint.setY(squarePoint.y() - width);
+
+        rect2 = QRect(squarePoint, QSize(width, width));
+        rect.moveLeft(rect.x() + width);
+      }
+      
+      if (rect.contains(position) || rect2.contains(position))
       {
         if (outSizePoint)
           *outSizePoint = line.sizePoint;



reply via email to

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