freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] veeki-gsoc-experimental 1c21248 1/7: Added Fancy and p


From: Veeki Yadav
Subject: [freetype2-demos] veeki-gsoc-experimental 1c21248 1/7: Added Fancy and proper UI format
Date: Wed, 17 Jul 2019 01:12:11 -0400 (EDT)

branch: veeki-gsoc-experimental
commit 1c2124893667b5f2821639fa22b06b623ab2f12e
Author: gevic <address@hidden>
Commit: gevic <address@hidden>

    Added Fancy and proper UI format
---
 .vscode/settings.json            |   9 ++
 src/ftinspect/ftinspect.pro      |   2 +
 src/ftinspect/maingui.cpp        | 142 +++++++++++++++++++++++-
 src/ftinspect/maingui.hpp        |  25 +++++
 src/ftinspect/rendering/view.cpp | 234 +++++++++++++++++++++++++++++++++++++++
 src/ftinspect/rendering/view.hpp |  60 ++++++++++
 6 files changed, 470 insertions(+), 2 deletions(-)

diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..98540ff
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,9 @@
+{
+  "files.associations": {
+    "mlgetopt.h": "c",
+    "ftcommon.h": "c",
+    "common.h": "c",
+    "gblblit.h": "c",
+    "gblender.h": "c"
+  }
+}
\ No newline at end of file
diff --git a/src/ftinspect/ftinspect.pro b/src/ftinspect/ftinspect.pro
index 10225eb..19c6542 100644
--- a/src/ftinspect/ftinspect.pro
+++ b/src/ftinspect/ftinspect.pro
@@ -29,6 +29,7 @@ SOURCES += \
   rendering/glyphpointnumbers.cpp \
   rendering/glyphpoints.cpp \
   rendering/glyphsegment.cpp \
+  rendering/view.cpp \
   rendering/grid.cpp \
   widgets/qcomboboxx.cpp \
   widgets/qgraphicsviewx.cpp \
@@ -44,6 +45,7 @@ HEADERS += \
   rendering/glyphpointnumbers.hpp \
   rendering/glyphpoints.hpp \
   rendering/glyphsegment.hpp \
+  rendering/view.hpp \
   rendering/grid.hpp \
   widgets/qcomboboxx.hpp \
   widgets/qgraphicsviewx.hpp \
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index 0c86c72..8c88521 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -11,6 +11,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QSettings>
+#include <QtDebug>
 
 #include FT_DRIVER_H
 #include FT_TRUETYPE_TABLES_H
@@ -486,6 +487,88 @@ MainGUI::checkAutoHinting()
 
 
 void
+MainGUI::gridViewRender()
+{
+  if (gridView->isChecked())
+  {
+    if (currentRenderAllItem)
+    {
+      glyphScene->removeItem(currentRenderAllItem);
+      delete currentRenderAllItem;
+
+      currentRenderAllItem = NULL;
+    }
+
+    currentGridItem = new Grid(gridPen, axisPen);
+    glyphScene->addItem(currentGridItem);
+    zoomSpinBox->setValue(20);
+    //drawGlyph();
+  }
+
+}
+
+
+void
+MainGUI::renderAll()
+{
+  // Basic definition
+  FT_Size size;
+  FT_Face face;
+  FT_Color* palette;
+  FTC_CMapCache cmap_cache;
+  FT_Error error;
+
+  // Basic Initialization
+  size = engine->getFtSize();
+
+  // Set the charmap for now
+  //error = FT_Set_Charmap( size->face, size->face->charmaps[0]);
+  // chache manager
+  FTC_Manager cacheManager = engine->cacheManager;
+  FTC_FaceID  face_id = engine->scaler.face_id;
+  //face = size->face;
+  // Render glyphs normally
+  if (allGlyphs->isChecked())
+  {
+    render_mode = 1;
+  }
+  if (fancyCheckbox->isChecked())
+  {
+    render_mode = 2;
+  }
+
+  error = FTC_CMapCache_New(cacheManager, &cmap_cache );
+
+  if (currentGridItem)
+  {
+    glyphScene->removeItem(currentGridItem);
+    delete currentGridItem;
+
+    currentGridItem = NULL;
+  }
+
+  if (currentRenderAllItem)
+  {
+    glyphScene->removeItem(currentRenderAllItem);
+    delete currentRenderAllItem;
+
+    currentRenderAllItem = NULL;
+  }
+
+  /* now, draw to our target surface */
+  currentRenderAllItem = new RenderAll(size->face,
+                                  size,
+                                  cacheManager,
+                                  face_id,
+                                  cmap_cache,
+                                  engine->library,
+                                  render_mode);
+  glyphScene->addItem(currentRenderAllItem);
+  zoomSpinBox->setValue(1);
+}
+
+
+void
 MainGUI::checkAntiAliasing()
 {
   int index = antiAliasingComboBoxx->currentIndex();
@@ -818,6 +901,15 @@ MainGUI::drawGlyph()
     currentGlyphPointNumbersItem = NULL;
   }
 
+  /* if (currentRenderAllItem)
+  {
+    glyphScene->removeItem(currentRenderAllItem);
+    delete currentRenderAllItem;
+
+    currentRenderAllItem = NULL;
+
+  }*/
+
   FT_Outline* outline = engine->loadOutline(currentGlyphIndex);
   if (outline)
   {
@@ -1027,14 +1119,32 @@ MainGUI::createLayout()
   generalTabLayout->addLayout(pointNumbersLayout);
   generalTabLayout->addWidget(showOutlinesCheckBox);
 
+  normalCheckbox = new QCheckBox(tr("Normal"));
+  fancyCheckbox = new QCheckBox(tr("Fancy"));
+  strokedCheckbox = new QCheckBox(tr("Stroked"));
+  textStringCheckbox = new QCheckBox(tr("Text String"));
+  waterFallCheckbox = new QCheckBox(tr("Waterfall"));
+
+  viewlayout = new QVBoxLayout;
+  viewlayout->addWidget(normalCheckbox);
+  viewlayout->addWidget(fancyCheckbox);
+  viewlayout->addWidget(strokedCheckbox);
+  viewlayout->addWidget(textStringCheckbox);
+  viewlayout->addWidget(waterFallCheckbox);
+
   generalTabWidget = new QWidget;
   generalTabWidget->setLayout(generalTabLayout);
 
   mmgxTabWidget = new QWidget;
 
+  // set layout ftview
+  viewTabWidget = new QWidget;
+  viewTabWidget->setLayout(viewlayout);
+
   tabWidget = new QTabWidget;
   tabWidget->addTab(generalTabWidget, tr("General"));
   tabWidget->addTab(mmgxTabWidget, tr("MM/GX"));
+  tabWidget->addTab(viewTabWidget, tr("Ftview"));
 
   leftLayout = new QVBoxLayout;
   leftLayout->addLayout(infoLeftLayout);
@@ -1058,14 +1168,14 @@ MainGUI::createLayout()
   fontNameLabel = new QLabel;
 
   glyphScene = new QGraphicsScene;
-  glyphScene->addItem(new Grid(gridPen, axisPen));
+  gridView->setChecked(true);
 
   currentGlyphBitmapItem = NULL;
   currentGlyphOutlineItem = NULL;
   currentGlyphPointsItem = NULL;
   currentGlyphPointNumbersItem = NULL;
   currentGlyphSegmentItem = NULL;
-  drawGlyph();
+  currentRenderAllItem = NULL;
 
   glyphView = new QGraphicsViewx;
   glyphView->setRenderHint(QPainter::Antialiasing, true);
@@ -1125,6 +1235,19 @@ MainGUI::createLayout()
   infoRightLayout->addWidget(glyphNameLabel, 0, 1);
   infoRightLayout->addWidget(fontNameLabel, 0, 2);
 
+  programNavigationLayout = new QHBoxLayout;
+  programNavigationLayout->addStretch(2);
+  programNavigationLayout->addWidget(gridView);
+  programNavigationLayout->addStretch(1);
+  programNavigationLayout->addWidget(allGlyphs);
+  programNavigationLayout->addStretch(1);
+  programNavigationLayout->addWidget(stringView);
+  programNavigationLayout->addStretch(1);
+  programNavigationLayout->addWidget(multiView);
+  programNavigationLayout->addStretch(1);
+  programNavigationLayout->addStretch(2);
+
+
   navigationLayout = new QHBoxLayout;
   navigationLayout->setSpacing(0);
   navigationLayout->addStretch(1);
@@ -1168,6 +1291,7 @@ MainGUI::createLayout()
   rightLayout = new QVBoxLayout;
   rightLayout->addLayout(infoRightLayout);
   rightLayout->addWidget(glyphView);
+  rightLayout->addLayout(programNavigationLayout);
   rightLayout->addLayout(navigationLayout);
   rightLayout->addSpacing(10); // XXX px
   rightLayout->addLayout(sizeLayout);
@@ -1203,6 +1327,19 @@ MainGUI::createConnections()
   connect(lcdFilterComboBox, SIGNAL(currentIndexChanged(int)),
           SLOT(checkLcdFilter()));
 
+  connect(allGlyphs, SIGNAL(clicked()),
+          SLOT(renderAll()));
+  connect(fancyCheckbox, SIGNAL(clicked()),
+          SLOT(renderAll()));
+  connect(strokedCheckbox, SIGNAL(clicked()),
+          SLOT(renderAll()));
+  connect(textStringCheckbox, SIGNAL(clicked()),
+          SLOT(renderAll()));
+  connect(waterFallCheckbox, SIGNAL(clicked()),
+          SLOT(renderAll()));
+  connect(gridView, SIGNAL(clicked()),
+          SLOT(gridViewRender()));
+
   connect(autoHintingCheckBox, SIGNAL(clicked()),
           SLOT(checkAutoHinting()));
   connect(horizontalHintingCheckBox, SIGNAL(clicked()),
@@ -1442,6 +1579,7 @@ MainGUI::setDefaults()
   checkCurrentNamedInstanceIndex();
   adjustGlyphIndex(0);
   zoom();
+  gridViewRender();
 }
 
 
diff --git a/src/ftinspect/maingui.hpp b/src/ftinspect/maingui.hpp
index c983270..0323c26 100644
--- a/src/ftinspect/maingui.hpp
+++ b/src/ftinspect/maingui.hpp
@@ -11,6 +11,8 @@
 #include "rendering/glyphpointnumbers.hpp"
 #include "rendering/glyphsegment.hpp"
 #include "rendering/glyphpoints.hpp"
+#include "rendering/view.hpp"
+#include "rendering/grid.hpp"
 #include "widgets/qcomboboxx.hpp"
 #include "widgets/qgraphicsviewx.hpp"
 #include "widgets/qpushbuttonx.hpp"
@@ -42,9 +44,11 @@
 #include <QTimer>
 #include <QVariant>
 #include <QVBoxLayout>
+#include <QRadioButton>
 
 #include <ft2build.h>
 #include FT_LCD_FILTER_H
+#include FT_COLOR_H
 
 
 class MainGUI
@@ -96,6 +100,8 @@ private slots:
   void previousNamedInstance();
   void watchCurrentFont();
   void zoom();
+  void renderAll();
+  void gridViewRender();
 
 private:
   Engine* engine;
@@ -115,12 +121,16 @@ private:
   int currentCFFHintingMode;
   int currentTTInterpreterVersion;
 
+  int render_mode;
+
   // layout related stuff
   GlyphOutline *currentGlyphOutlineItem;
   GlyphPoints *currentGlyphPointsItem;
   GlyphSegment *currentGlyphSegmentItem;
   GlyphPointNumbers *currentGlyphPointNumbersItem;
   GlyphBitmap *currentGlyphBitmapItem;
+  RenderAll *currentRenderAllItem;
+  Grid *currentGridItem;
 
   QAction *aboutAct;
   QAction *aboutQtAct;
@@ -142,6 +152,13 @@ private:
   QCheckBox *showPointsCheckBox;
   QCheckBox *verticalHintingCheckBox;
   QCheckBox *warpingCheckBox;
+  // ftview options
+  QCheckBox *normalCheckbox;
+  QCheckBox *fancyCheckbox;
+  QCheckBox *strokedCheckbox;
+  QCheckBox *textStringCheckbox;
+  QCheckBox *waterFallCheckbox;
+  
 
   QComboBoxx *antiAliasingComboBoxx;
   QComboBoxx *hintingModeComboBoxx;
@@ -176,6 +193,7 @@ private:
   QHBoxLayout *sizeLayout;
   QHBoxLayout *verticalHintingLayout;
   QHBoxLayout *warpingLayout;
+  QHBoxLayout *programNavigationLayout;
 
   QLabel *antiAliasingLabel;
   QLabel *dpiLabel;
@@ -189,6 +207,11 @@ private:
   QLabel *sizeLabel;
   QLabel *zoomLabel;
 
+  QRadioButton *gridView = new QRadioButton(tr("Grid View"));
+  QRadioButton *allGlyphs = new QRadioButton(tr("All Glyphs"));
+  QRadioButton *stringView = new QRadioButton(tr("Render String"));
+  QRadioButton *multiView = new QRadioButton(tr("Multi View"));
+
   QList<int> hintingModesAlwaysDisabled;
 
   QLocale *locale;
@@ -237,6 +260,7 @@ private:
   QVBoxLayout *generalTabLayout;
   QVBoxLayout *leftLayout;
   QVBoxLayout *rightLayout;
+  QVBoxLayout *viewlayout;
 
   QVector<QRgb> grayColorTable;
   QVector<QRgb> monoColorTable;
@@ -246,6 +270,7 @@ private:
   QWidget *leftWidget;
   QWidget *rightWidget;
   QWidget *mmgxTabWidget;
+  QWidget *viewTabWidget;
 
   enum AntiAliasing
   {
diff --git a/src/ftinspect/rendering/view.cpp b/src/ftinspect/rendering/view.cpp
new file mode 100644
index 0000000..75271b4
--- /dev/null
+++ b/src/ftinspect/rendering/view.cpp
@@ -0,0 +1,234 @@
+#include "view.hpp"
+
+#include <cmath>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
+#include <QWidget>
+#include <QFile>
+#include <QImage>
+#include <iostream>
+#include <QtDebug>
+
+#define ft_render_mode_normal  FT_RENDER_MODE_NORMAL
+  /* special encoding to display glyphs in order */
+#define FT_ENCODING_ORDER  0xFFFF
+#define ft_encoding_unicode         FT_ENCODING_UNICODE
+
+#define TRUNC(x) ((x) >> 6)
+
+
+RenderAll::RenderAll(FT_Face face,
+          FT_Size  size,
+          FTC_Manager cacheManager,
+          FTC_FaceID  face_id,
+          FTC_CMapCache  cmap_cache,
+          FT_Library lib,
+          int render_mode)
+:face(face),
+size(size),
+cacheManager(cacheManager),
+face_id(face_id),
+cmap_cache(cmap_cache),
+library(lib),
+mode(render_mode)
+{
+}
+
+
+RenderAll::~RenderAll()
+{
+  //FT_Done_Face(face);
+}
+
+QRectF
+RenderAll::boundingRect() const
+{
+  return QRectF(-350, -200,
+                700, 400);
+}
+
+
+void
+RenderAll::paint(QPainter* painter,
+                   const QStyleOptionGraphicsItem* option,
+                   QWidget*)
+{
+  // Basic def
+  FT_GlyphSlot  slot;
+  FT_Int cmap_index;
+
+  
+  // Basic def or just pass size 
+  slot = face->glyph;
+  FT_UInt  glyph_idx;
+  int x = -350;
+  int y = -180;
+  
+  if (mode == 1)
+  {
+    // Normal rendering
+    for ( int i = 0; i < face->num_glyphs; i++ )
+    {
+      // get char index
+      //glyph_idx = FT_Get_Char_Index( face , (FT_ULong)i );
+      if ( face->charmap->encoding != FT_ENCODING_ORDER )
+      {
+        glyph_idx = FTC_CMapCache_Lookup(cmap_cache, face_id,
+                                          FT_Get_Charmap_Index(face->charmap), 
(FT_UInt32)i);
+      }
+      else
+      {
+        glyph_idx = (FT_UInt32)i;
+      }
+      //glyph_idx = (FT_UInt)i;
+      /* load glyph image into the slot (erase previous one) */
+      error = FT_Load_Glyph( face, glyph_idx, FT_LOAD_DEFAULT );
+      if ( error )
+      {
+        break;  /* ignore errors */
+      } 
+
+      error = FT_Render_Glyph(face->glyph,
+                                FT_RENDER_MODE_NORMAL);
+
+      QImage glyphImage(face->glyph->bitmap.buffer,
+                          face->glyph->bitmap.width,
+                          face->glyph->bitmap.rows,
+                          face->glyph->bitmap.pitch,
+                          QImage::Format_Indexed8);
+
+      
+
+      QVector<QRgb> colorTable;
+      for (int i = 0; i < 256; ++i)
+      {
+        colorTable << qRgba(0, 0, 0, i);
+      }
+        
+      glyphImage.setColorTable(colorTable);
+      
+
+      painter->drawImage(x, y,
+                        glyphImage, 0, 0, -1, -1);
+      x = x + 20;
+
+      if (x >= 350)
+      { 
+        y = y + 30;
+        x = -350;
+      }
+    }
+  }
+
+  if (mode == 2)
+  {
+    // fancy render
+    FT_Matrix shear;
+    FT_Pos xstr, ystr;
+
+    shear.xx = 1 << 16;
+    shear.xy = (FT_Fixed)( ( 1 << 16 ) );
+    shear.yx = 0;
+    shear.yy = 1 << 16;
+
+    xstr = (FT_Pos)( size->metrics.y_ppem * 64 * 0 );
+    ystr = (FT_Pos)( size->metrics.y_ppem * 64 * 0 ); 
+
+    for ( int i = 0; i < face->num_glyphs; i++ )
+    {
+      // get char index 
+      //glyph_idx = FT_Get_Char_Index( face , (FT_ULong)i );
+      if ( face->charmap->encoding != FT_ENCODING_ORDER )
+      {
+        glyph_idx = FTC_CMapCache_Lookup(cmap_cache, face_id,
+                                          FT_Get_Charmap_Index(face->charmap), 
(FT_UInt32)i);
+      }
+      else
+      {
+        glyph_idx = (FT_UInt32)i;
+      }
+
+      /* load glyph image into the slot (erase previous one) */
+      error = FT_Load_Glyph( face, glyph_idx, FT_LOAD_DEFAULT );
+      if ( error )
+      {
+        break;  /* ignore errors */
+      }
+
+      /* this is essentially the code of function */
+      /* `FT_GlyphSlot_Embolden'                  */
+      if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
+      {
+        FT_Outline_Transform( &slot->outline, &shear );
+
+        error = FT_Outline_EmboldenXY( &slot->outline, xstr, ystr );
+        /* ignore error */
+      }
+      else if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
+      {
+        /* round to full pixels */
+        xstr &= ~63;
+        ystr &= ~63;
+
+        error = FT_GlyphSlot_Own_Bitmap( slot );
+        if ( error )
+          break;
+
+        error = FT_Bitmap_Embolden( slot->library, &slot->bitmap,
+                                    xstr, ystr );
+        if ( error )
+          break;
+      }
+      else
+      {
+        break;
+      }
+
+      if ( slot->advance.x )
+          slot->advance.x += xstr;
+
+      if ( slot->advance.y )
+        slot->advance.y += ystr;
+
+      slot->metrics.width        += xstr;
+      slot->metrics.height       += ystr;
+      slot->metrics.horiAdvance  += xstr;
+      slot->metrics.vertAdvance  += ystr;
+
+      if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
+        slot->bitmap_top += ystr >> 6;
+
+      error = FT_Render_Glyph(face->glyph,
+                                FT_RENDER_MODE_NORMAL);
+
+      QImage glyphImage(face->glyph->bitmap.buffer,
+                          face->glyph->bitmap.width,
+                          face->glyph->bitmap.rows,
+                          face->glyph->bitmap.pitch,
+                          QImage::Format_Indexed8);
+
+      
+
+      QVector<QRgb> colorTable;
+      for (int i = 0; i < 256; ++i)
+      {
+        colorTable << qRgba(0, 0, 0, i);
+      }
+        
+      glyphImage.setColorTable(colorTable);
+      
+
+      painter->drawImage(x, y,
+                        glyphImage, 0, 0, -1, -1);
+      x = x + 20;
+
+      if (x >= 350)
+      { 
+        y = y + 30;
+        x = -350;
+      }
+    }
+  }
+}
+
+// end of RenderAll.cpp
diff --git a/src/ftinspect/rendering/view.hpp b/src/ftinspect/rendering/view.hpp
new file mode 100644
index 0000000..49688ee
--- /dev/null
+++ b/src/ftinspect/rendering/view.hpp
@@ -0,0 +1,60 @@
+#pragma once
+
+#include <QGraphicsItem>
+#include <QPen>
+
+#include <ft2build.h>
+#include "../engine/engine.hpp"
+#include FT_FREETYPE_H
+#include FT_OUTLINE_H
+#include FT_GLYPH_H
+#include FT_TYPES_H
+#include FT_RENDER_H
+#include FT_STROKER_H
+
+#include FT_INTERNAL_DEBUG_H
+
+  /* showing driver name */
+#include FT_MODULE_H
+#include FT_INTERNAL_OBJECTS_H
+#include FT_INTERNAL_DRIVER_H
+
+#include FT_SYNTHESIS_H
+#include FT_LCD_FILTER_H
+#include FT_DRIVER_H
+
+#include FT_COLOR_H
+#include FT_BITMAP_H
+
+
+class RenderAll
+: public QGraphicsItem
+{
+public:
+  RenderAll(FT_Face face,
+       FT_Size  size,
+       FTC_Manager cacheManager,
+       FTC_FaceID  face_id,
+       FTC_CMapCache  cmap_cache,
+       FT_Library library,
+       int mode);
+  ~RenderAll();
+  QRectF boundingRect() const;
+  void paint(QPainter* painter,
+             const QStyleOptionGraphicsItem* option,
+             QWidget* widget);
+
+private:
+  FT_Face face;
+  FT_Library library;
+  QRectF m_glyphRect;
+  FT_Error error;
+  FTC_Manager cacheManager;
+  FTC_FaceID face_id;
+  FTC_CMapCache cmap_cache;
+  FT_Size size;
+  int mode;
+};
+
+
+// end of glyphbitmap.hpp



reply via email to

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