freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] gsoc-2019-veeki c3773ef 2/3: Segment drawing added


From: Veeki Yadav
Subject: [freetype2-demos] gsoc-2019-veeki c3773ef 2/3: Segment drawing added
Date: Tue, 18 Jun 2019 21:40:00 -0400 (EDT)

branch: gsoc-2019-veeki
commit c3773ef822cebfe69dd40ded55324fbbbab18505
Author: gevic <address@hidden>
Commit: gevic <address@hidden>

    Segment drawing added
---
 src/ftinspect/engine/engine.cpp          |   8 ++
 src/ftinspect/engine/engine.hpp          |   1 +
 src/ftinspect/ftinspect.pro              |   2 +-
 src/ftinspect/maingui.cpp                |  18 ++++
 src/ftinspect/maingui.hpp                |   2 +
 src/ftinspect/rendering/glyphsegment.cpp | 138 +++++++++++++++++++++++++++++++
 src/ftinspect/rendering/glyphsegment.hpp |  31 +++++++
 7 files changed, 199 insertions(+), 1 deletion(-)

diff --git a/src/ftinspect/engine/engine.cpp b/src/ftinspect/engine/engine.cpp
index d1f6a5f..d9c207a 100644
--- a/src/ftinspect/engine/engine.cpp
+++ b/src/ftinspect/engine/engine.cpp
@@ -555,6 +555,13 @@ Engine::setCFFHintingMode(int mode)
 }
 
 
+FT_Size
+Engine::getFtSize()
+{
+  return ftSize;
+}
+
+
 void
 Engine::setTTInterpreterVersion(int mode)
 {
@@ -644,6 +651,7 @@ Engine::update()
   }
   setWarping();
 
+
   if (doHinting)
   {
     unsigned long target;
diff --git a/src/ftinspect/engine/engine.hpp b/src/ftinspect/engine/engine.hpp
index 37d2593..6f4f42f 100644
--- a/src/ftinspect/engine/engine.hpp
+++ b/src/ftinspect/engine/engine.hpp
@@ -57,6 +57,7 @@ public:
   void removeFont(int fontIndex);
   void setCFFHintingMode(int mode);
   void setWarping();
+  FT_Size getFtSize();
   void setTTInterpreterVersion(int version);
   void update();
 
diff --git a/src/ftinspect/ftinspect.pro b/src/ftinspect/ftinspect.pro
index fba7119..ad1df64 100644
--- a/src/ftinspect/ftinspect.pro
+++ b/src/ftinspect/ftinspect.pro
@@ -7,7 +7,7 @@ QMAKE_CXXFLAGS += -isystem ../../../freetype2/include
 #
 # You should adapt this to your setup.
 unix|macx {
-  LIBS += ../../../freetype2/objs/.libs/libfreetype.a
+  LIBS += ../../../freetype2/objs/libfreetype.a
 
   CONFIG += link_pkgconfig
   PKGCONFIG += libpng harfbuzz zlib bzip2
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index 21c02bf..866455f 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -643,6 +643,14 @@ MainGUI::drawGlyph()
     currentGlyphBitmapItem = NULL;
   }
 
+  if (currentGlyphSegmentItem)
+  {
+    glyphScene->removeItem(currentGlyphSegmentItem);
+    delete currentGlyphSegmentItem;
+
+    currentGlyphSegmentItem = NULL;
+  }
+
   if (currentGlyphOutlineItem)
   {
     glyphScene->removeItem(currentGlyphOutlineItem);
@@ -685,6 +693,14 @@ MainGUI::drawGlyph()
       glyphScene->addItem(currentGlyphBitmapItem);
     }
 
+    if (segmentDrawingCheckBox->isChecked())
+    {
+      currentGlyphSegmentItem = new GlyphSegment(segmentPen,
+                                                 blueZonePen,
+                                                 engine->getFtSize());
+      glyphScene->addItem(currentGlyphSegmentItem);
+    }
+
     if (showOutlinesCheckBox->isChecked())
     {
       currentGlyphOutlineItem = new GlyphOutline(outlinePen, outline);
@@ -1052,6 +1068,8 @@ MainGUI::createConnections()
           SLOT(drawGlyph()));
   connect(warpingCheckBox, SIGNAL(clicked()),
           SLOT(drawGlyph()));
+  connect(segmentDrawingCheckBox, SIGNAL(clicked()),
+          SLOT(drawGlyph()));
   connect(showBitmapCheckBox, SIGNAL(clicked()),
           SLOT(drawGlyph()));
   connect(showPointsCheckBox, SIGNAL(clicked()),
diff --git a/src/ftinspect/maingui.hpp b/src/ftinspect/maingui.hpp
index 8c2bb98..92d32a9 100644
--- a/src/ftinspect/maingui.hpp
+++ b/src/ftinspect/maingui.hpp
@@ -9,6 +9,7 @@
 #include "rendering/glyphbitmap.hpp"
 #include "rendering/glyphoutline.hpp"
 #include "rendering/glyphpointnumbers.hpp"
+#include "rendering/glyphsegment.hpp"
 #include "rendering/glyphpoints.hpp"
 #include "widgets/qcomboboxx.hpp"
 #include "widgets/qgraphicsviewx.hpp"
@@ -114,6 +115,7 @@ private:
   // layout related stuff
   GlyphOutline *currentGlyphOutlineItem;
   GlyphPoints *currentGlyphPointsItem;
+  GlyphSegment *currentGlyphSegmentItem;
   GlyphPointNumbers *currentGlyphPointNumbersItem;
   GlyphBitmap *currentGlyphBitmapItem;
 
diff --git a/src/ftinspect/rendering/glyphsegment.cpp 
b/src/ftinspect/rendering/glyphsegment.cpp
new file mode 100644
index 0000000..dd0869c
--- /dev/null
+++ b/src/ftinspect/rendering/glyphsegment.cpp
@@ -0,0 +1,138 @@
+#include "glyphsegment.hpp"
+
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
+#include <QtDebug>
+
+
+/* these variables, structures, and declarations are for  */
+/* communication with the debugger in the autofit module; */
+/* normal programs don't need this */
+struct  AF_GlyphHintsRec_;
+typedef struct AF_GlyphHintsRec_*  AF_GlyphHints;
+extern AF_GlyphHints  _af_debug_hints;
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+  extern void
+  af_glyph_hints_dump_segments( AF_GlyphHints  hints,
+                                FT_Bool        to_stdout );
+  extern void
+  af_glyph_hints_dump_points( AF_GlyphHints  hints,
+                              FT_Bool        to_stdout );
+  extern void
+  af_glyph_hints_dump_edges( AF_GlyphHints  hints,
+                             FT_Bool        to_stdout );
+  extern FT_Error
+  af_glyph_hints_get_num_segments( AF_GlyphHints  hints,
+                                   FT_Int         dimension,
+                                   FT_Int*        num_segments );
+  extern FT_Error
+  af_glyph_hints_get_segment_offset( AF_GlyphHints  hints,
+                                     FT_Int         dimension,
+                                     FT_Int         idx,
+                                     FT_Pos        *offset,
+                                     FT_Bool       *is_blue,
+                                     FT_Pos        *blue_offset );
+#ifdef __cplusplus
+  }
+#endif
+
+
+GlyphSegment::GlyphSegment(const QPen& segmentP,
+                           const QPen& bluezoneP,
+                           FT_Size fts)
+: segmentPen(segmentP),
+  bluezonePen(bluezoneP),
+  ftsize(fts)
+{
+}
+
+
+QRectF
+GlyphSegment::boundingRect() const
+{
+  return QRectF(-100, -100,
+                200, 200);
+}
+
+
+void
+GlyphSegment::paint(QPainter* painter,
+            const QStyleOptionGraphicsItem* option,
+            QWidget*)
+{
+
+  const qreal lod = option->levelOfDetailFromTransform(
+                              painter->worldTransform());
+
+  FT_Fixed  x_scale = ftsize->metrics.x_scale;
+  FT_Fixed  y_scale = ftsize->metrics.y_scale;
+
+  FT_Int  dimension;
+  int     x_org = 0;
+  int     y_org = 0;
+ 
+
+  painter->setPen(segmentPen);
+
+  for ( dimension = 1; dimension >= 0; dimension-- )
+  {
+    FT_Int  num_seg;
+    FT_Int  count;
+
+    af_glyph_hints_get_num_segments( _af_debug_hints, dimension, &num_seg );
+
+    for ( count = 0; count < num_seg; count++ )
+    {
+      int      pos;
+      FT_Pos   offset;
+      FT_Bool  is_blue;
+      FT_Pos   blue_offset;
+
+      af_glyph_hints_get_segment_offset( _af_debug_hints, dimension,
+                                           count, &offset,
+                                           &is_blue, &blue_offset);
+      
+      if ( dimension == 0 )
+      {
+        offset = FT_MulFix( offset, x_scale );
+        pos    = x_org + ( ( offset) >> 6 );
+        painter->drawLine(pos, -100, pos, 100);
+      }
+      else
+      {
+        offset = FT_MulFix( offset, y_scale );
+        pos    = y_org - ( ( offset) >> 6 );
+
+        if ( is_blue )
+        {
+          int  blue_pos;
+
+
+          blue_offset = FT_MulFix( blue_offset, y_scale );
+          blue_pos    = y_org - ( ( blue_offset) >> 6 );
+          if ( blue_pos == pos )
+          {
+            painter->drawLine(-100, pos, 100, pos);
+          }
+          else
+          {
+            painter->setPen(bluezonePen);
+            painter->drawLine(-100, blue_pos, 100, blue_pos);
+            painter->setPen(segmentPen);
+            painter->drawLine(-100, pos, 100, pos);
+          }
+        }
+        else
+        {
+          painter->drawLine(-100, pos, 100, pos);
+        }
+      }
+    }
+  }
+}
+
+
+// end of grid.cpp
\ No newline at end of file
diff --git a/src/ftinspect/rendering/glyphsegment.hpp 
b/src/ftinspect/rendering/glyphsegment.hpp
new file mode 100644
index 0000000..4da5049
--- /dev/null
+++ b/src/ftinspect/rendering/glyphsegment.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <QGraphicsItem>
+#include <QPen>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_OUTLINE_H
+
+
+class GlyphSegment
+: public QGraphicsItem
+{
+public:
+  GlyphSegment(const QPen& segmentPen,
+               const QPen& bluezonePen,
+               FT_Size ftsize);
+  QRectF boundingRect() const;
+  void paint(QPainter* painter,
+             const QStyleOptionGraphicsItem* option,
+             QWidget* widget);
+
+private:
+  QPen segmentPen;
+  QPen bluezonePen;
+  FT_Size ftsize;
+  QRectF bRect;
+};
+
+
+// end of glyphsegment.hpp
\ No newline at end of file



reply via email to

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