freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] veeki-gsoc-experimental 3183504: Added comparator


From: Veeki Yadav
Subject: [freetype2-demos] veeki-gsoc-experimental 3183504: Added comparator
Date: Tue, 30 Jul 2019 05:17:38 -0400 (EDT)

branch: veeki-gsoc-experimental
commit 31835047a3505105b3e845b98d2d47d20d395adc
Author: gevic <address@hidden>
Commit: gevic <address@hidden>

    Added comparator
---
 src/ftinspect/ftinspect.pro            |   2 +
 src/ftinspect/maingui.cpp              | 229 ++++++++++++++++++++++++++++++++-
 src/ftinspect/maingui.hpp              |  46 ++++++-
 src/ftinspect/rendering/comparator.cpp | 222 ++++++++++++++++++++++++++++++++
 src/ftinspect/rendering/comparator.hpp |  64 +++++++++
 5 files changed, 561 insertions(+), 2 deletions(-)

diff --git a/src/ftinspect/ftinspect.pro b/src/ftinspect/ftinspect.pro
index 19c6542..d5db3cb 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/comparator.cpp \
   rendering/view.cpp \
   rendering/grid.cpp \
   widgets/qcomboboxx.cpp \
@@ -45,6 +46,7 @@ HEADERS += \
   rendering/glyphpointnumbers.hpp \
   rendering/glyphpoints.hpp \
   rendering/glyphsegment.hpp \
+  rendering/comparator.hpp \
   rendering/view.hpp \
   rendering/grid.hpp \
   widgets/qcomboboxx.hpp \
diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index 531834f..743347a 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -476,6 +476,34 @@ MainGUI::checkKerningMode()
 
 
 void
+MainGUI::checkColumnHinting()
+{
+  int index = hintingModeColumnComboBoxx->currentIndex();
+  hintingModeColumnComboBoxx->setItemEnabled(index, true);
+  int column_index = columnComboBoxx->currentIndex();
+
+  if (!(hintingModeColumnComboBoxx->itemText(index).compare("Unhinted")))
+  {
+    state[column_index].hint_mode = HINT_MODE_UNHINTED;
+  } else if 
(!(hintingModeColumnComboBoxx->itemText(index).compare("Auto-hinting")))
+  {
+    state[column_index].hint_mode = HINT_MODE_AUTOHINT;
+  } else if (!(hintingModeColumnComboBoxx->itemText(index).compare("Light 
Auto-hinting")))
+  {
+    state[column_index].hint_mode = HINT_MODE_AUTOHINT_LIGHT;
+  } else if (!(hintingModeColumnComboBoxx->itemText(index).compare("Light 
Auto-hinting (Subp.)")))
+  {
+    state[column_index].hint_mode = HINT_MODE_AUTOHINT_LIGHT_SUBPIXEL;
+  } else
+  {
+    state[column_index].hint_mode = HINT_MODE_BYTECODE;
+  }
+
+  comparatorViewRender();
+}
+
+
+void
 MainGUI::checkKerningDegree()
 {
   int index = kerningDegreeComboBoxx->currentIndex();
@@ -564,6 +592,104 @@ MainGUI::checkAutoHinting()
 
 
 void
+MainGUI::comparatorViewRender()
+{
+    // Basic definition
+  FT_Size size;
+  
+  // Basic Initialization
+  size = engine->getFtSize();
+
+  if (comparatorView->isChecked())
+  {
+    if (currentRenderAllItem)
+    {
+      glyphScene->removeItem(currentRenderAllItem);
+      delete currentRenderAllItem;
+
+      currentRenderAllItem = NULL;
+    }
+
+    if (currentGridItem)
+    {
+      glyphScene->removeItem(currentGridItem);
+      delete currentGridItem;
+
+      currentGridItem = NULL;
+    }
+
+    if (currentComparatorItem)
+    {
+      glyphScene->removeItem(currentComparatorItem);
+      delete currentComparatorItem;
+
+      currentComparatorItem = NULL;
+    }
+
+    for (int col = 0; col < 3; col++)
+    {
+      // load flags
+      load_flags[col] = FT_LOAD_DEFAULT;
+
+      if ( state[col].hint_mode == HINT_MODE_AUTOHINT )
+      {
+        load_flags[col] = FT_LOAD_FORCE_AUTOHINT;
+      }
+
+      if ( state[col].hint_mode == HINT_MODE_AUTOHINT_LIGHT          ||
+          state[col].hint_mode == HINT_MODE_AUTOHINT_LIGHT_SUBPIXEL )
+      {
+        load_flags[col] = FT_LOAD_TARGET_LIGHT;
+      }
+
+      if ( state[col].hint_mode == HINT_MODE_UNHINTED )
+      {
+        load_flags[col] |= FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
+      }
+
+      int column_index = columnComboBoxx->currentIndex();
+
+      // set warping
+      if (warpingColumnCheckBox->isChecked())
+      {
+        warping[column_index] = true;
+      }
+
+      // set kerning
+      if (kerningColumnCheckBox->isChecked())
+      {
+        kerningCol[column_index] = true;
+      }
+
+      // rendering mode set
+      int index = renderingModeComboBoxx->currentIndex();
+      renderingModeComboBoxx->setItemEnabled(index, true);
+
+      if (!(renderingModeComboBoxx->itemText(index).compare("Grey Rendering")))
+      {
+        pixelMode[column_index] = FT_PIXEL_MODE_GRAY;
+      }
+
+    }
+
+    currentComparatorItem = new Comparator(engine->library,
+                                size->face,
+                                size,
+                                fontList,
+                                load_flags,
+                                pixelMode,
+                                grayColorTable,
+                                monoColorTable,
+                                warping,
+                                kerningCol);
+    glyphScene->addItem(currentComparatorItem);
+    sizeDoubleSpinBox->setValue(11);
+    zoomSpinBox->setValue(1);
+  }
+}
+
+
+void
 MainGUI::gridViewRender()
 {
   if (gridView->isChecked())
@@ -576,6 +702,16 @@ MainGUI::gridViewRender()
       currentRenderAllItem = NULL;
     }
 
+    if (currentComparatorItem)
+    {
+      glyphScene->removeItem(currentComparatorItem);
+      delete currentComparatorItem;
+
+      currentComparatorItem = NULL;
+    }
+
+   
+
     currentGridItem = new Grid(gridPen, axisPen);
     glyphScene->addItem(currentGridItem);
     zoomSpinBox->setValue(20);
@@ -663,6 +799,14 @@ MainGUI::renderAll()
     currentRenderAllItem = NULL;
   }
 
+  if (currentComparatorItem)
+  {
+    glyphScene->removeItem(currentComparatorItem);
+    delete currentComparatorItem;
+
+    currentComparatorItem = NULL;
+  }
+
   /* now, draw to our target surface */
   currentRenderAllItem = new RenderAll(size->face,
                                   size,
@@ -680,6 +824,7 @@ MainGUI::renderAll()
                                   kerning_mode,
                                   kerning_degree);
   glyphScene->addItem(currentRenderAllItem);
+  sizeDoubleSpinBox->setValue(20);
   zoomSpinBox->setValue(1);
 }
 
@@ -1166,6 +1311,34 @@ MainGUI::createLayout()
   kerningDegreeComboBoxx->insertItem(KERNING_DEGREE_TIGHT, tr("Tight"));
   kerningDegreeLabel->setBuddy(kerningDegreeComboBoxx);
 
+  columnLabel = new QLabel(tr("Column"));
+  columnLabel->setAlignment(Qt::AlignTop);
+  columnComboBoxx = new QComboBoxx;
+  columnComboBoxx->addItem("Column 1");
+  columnComboBoxx->addItem("Column 2");
+  columnComboBoxx->addItem("Column 3");
+  columnLabel->setBuddy(columnComboBoxx);
+
+  hintingColumnLabel = new QLabel(tr("Hinting Mode"));
+  hintingColumnLabel->setAlignment(Qt::AlignTop);
+  hintingModeColumnComboBoxx = new QComboBoxx;
+  hintingModeColumnComboBoxx->insertItem(HINT_MODE_UNHINTED, tr("Unhinted"));
+  hintingModeColumnComboBoxx->insertItem(HINT_MODE_AUTOHINT, 
tr("Auto-hinting"));
+  hintingModeColumnComboBoxx->insertItem(HINT_MODE_AUTOHINT_LIGHT, tr("Light 
Auto-hinting"));
+  hintingModeColumnComboBoxx->insertItem(HINT_MODE_AUTOHINT_LIGHT_SUBPIXEL, 
tr("Light Auto-hinting (Subp.)"));
+  hintingModeColumnComboBoxx->insertItem(HINT_MODE_BYTECODE, tr("Native"));
+  hintingColumnLabel->setBuddy(hintingModeColumnComboBoxx);
+
+  renderColumnLabel = new QLabel(tr("Render Mode"));
+  renderColumnLabel->setAlignment(Qt::AlignTop);
+  renderingModeColumnComboBoxx = new QComboBoxx;
+  renderingModeColumnComboBoxx->addItem(tr("LCD Rendering"));
+  renderingModeColumnComboBoxx->addItem(tr("Grey Rendering"));
+  renderColumnLabel->setBuddy(renderingModeColumnComboBoxx);
+
+  warpingColumnCheckBox = new QCheckBox(tr("Warping"));
+  kerningColumnCheckBox = new QCheckBox(tr("Kerning"));
+
   int width;
   // make all labels have the same width
   width = hintingModeLabel->minimumSizeHint().width();
@@ -1174,12 +1347,18 @@ MainGUI::createLayout()
   width = qMax(renderingModeLabel->minimumSizeHint().width(), width);
   width = qMax(kerningModeLabel->minimumSizeHint().width(), width);
   width = qMax(kerningDegreeLabel->minimumSizeHint().width(), width);
+  width = qMax(columnLabel->minimumSizeHint().width(), width);
+  width = qMax(renderColumnLabel->minimumSizeHint().width(), width);
+  width = qMax(hintingColumnLabel->minimumSizeHint().width(), width);
   hintingModeLabel->setMinimumWidth(width);
   antiAliasingLabel->setMinimumWidth(width);
   lcdFilterLabel->setMinimumWidth(width);
   renderingModeLabel->setMinimumWidth(width);
   kerningModeLabel->setMinimumWidth(width);
   kerningDegreeLabel->setMinimumWidth(width);
+  columnLabel->setMinimumWidth(width);
+  renderColumnLabel->setMinimumWidth(width);
+  hintingColumnLabel->setMinimumWidth(width);
 
   // ensure that all items in combo boxes fit completely;
   // also make all combo boxes have the same width
@@ -1189,12 +1368,18 @@ MainGUI::createLayout()
   width = qMax(renderingModeComboBoxx->minimumSizeHint().width(), width);
   width = qMax(kerningModeComboBoxx->minimumSizeHint().width(), width);
   width = qMax(kerningDegreeComboBoxx->minimumSizeHint().width(), width);
+  width = qMax(columnComboBoxx->minimumSizeHint().width(), width);
+  width = qMax(hintingModeColumnComboBoxx->minimumSizeHint().width(), width);
+  width = qMax(renderingModeColumnComboBoxx->minimumSizeHint().width(), width);
   hintingModeComboBoxx->setMinimumWidth(width);
   antiAliasingComboBoxx->setMinimumWidth(width);
   lcdFilterComboBox->setMinimumWidth(width);
   renderingModeComboBoxx->setMinimumWidth(width);
   kerningModeComboBoxx->setMinimumWidth(width);
   kerningDegreeComboBoxx->setMinimumWidth(width);
+  columnComboBoxx->setMinimumWidth(width);
+  hintingModeColumnComboBoxx->setMinimumWidth(width);
+  renderingModeColumnComboBoxx->setMinimumWidth(width);
 
   gammaLabel = new QLabel(tr("Gamma"));
   gammaLabel->setAlignment(Qt::AlignRight);
@@ -1263,6 +1448,14 @@ MainGUI::createLayout()
   warpingLayout->addSpacing(20); // XXX px
   warpingLayout->addWidget(warpingCheckBox);
 
+  warpingColumnLayout = new QHBoxLayout;
+  warpingColumnLayout->addSpacing(20); // XXX px
+  warpingColumnLayout->addWidget(warpingColumnCheckBox);
+
+  kerningColumnLayout = new QHBoxLayout;
+  kerningColumnLayout->addSpacing(20); // XXX px
+  kerningColumnLayout->addWidget(kerningColumnCheckBox);
+
   antiAliasingLayout = new QHBoxLayout;
   antiAliasingLayout->addWidget(antiAliasingLabel);
   antiAliasingLayout->addWidget(antiAliasingComboBoxx);
@@ -1330,6 +1523,18 @@ MainGUI::createLayout()
   degreeLayout->addWidget(kerningDegreeLabel);
   degreeLayout->addWidget(kerningDegreeComboBoxx);
 
+  columnLayout = new QHBoxLayout;
+  columnLayout->addWidget(columnLabel);
+  columnLayout->addWidget(columnComboBoxx);
+
+  hintColumnLayout = new QHBoxLayout;
+  hintColumnLayout->addWidget(hintingColumnLabel);
+  hintColumnLayout->addWidget(hintingModeColumnComboBoxx);
+
+  renderColumnLayout = new QHBoxLayout;
+  renderColumnLayout->addWidget(renderColumnLabel);
+  renderColumnLayout->addWidget(renderingModeColumnComboBoxx);
+
   viewTabLayout = new QVBoxLayout;
   viewTabLayout->addLayout(renderLayout);
   viewTabLayout->addLayout(kerningLayout);
@@ -1348,11 +1553,24 @@ MainGUI::createLayout()
   viewTabWidget = new QWidget;
   viewTabWidget->setLayout(viewTabLayout);
 
+  diffTabLayout = new QVBoxLayout;
+  diffTabLayout->addLayout(columnLayout);
+  diffTabLayout->addLayout(renderColumnLayout);
+  diffTabLayout->addLayout(hintColumnLayout);
+  diffTabLayout->addWidget(kerningColumnCheckBox);
+  diffTabLayout->addLayout(kerningColumnLayout);
+  diffTabLayout->addWidget(warpingColumnCheckBox);
+  diffTabLayout->addLayout(warpingColumnLayout);
+  
+  diffTabWidget = new QWidget;
+  diffTabWidget->setLayout(diffTabLayout);
+
 
   tabWidget = new QTabWidget;
   tabWidget->addTab(generalTabWidget, tr("General"));
   tabWidget->addTab(mmgxTabWidget, tr("MM/GX"));
   tabWidget->addTab(viewTabWidget, tr("Ftview"));
+  tabWidget->addTab(diffTabWidget, tr("Ftdiff"));
 
   leftLayout = new QVBoxLayout;
   leftLayout->addLayout(infoLeftLayout);
@@ -1384,6 +1602,7 @@ MainGUI::createLayout()
   currentGlyphPointNumbersItem = NULL;
   currentGlyphSegmentItem = NULL;
   currentRenderAllItem = NULL;
+  currentComparatorItem = NULL;
 
   glyphView = new QGraphicsViewx;
   glyphView->setRenderHint(QPainter::Antialiasing, true);
@@ -1449,7 +1668,7 @@ MainGUI::createLayout()
   programNavigationLayout->addStretch(1);
   programNavigationLayout->addWidget(allGlyphs);
   programNavigationLayout->addStretch(1);
-  programNavigationLayout->addWidget(stringView);
+  programNavigationLayout->addWidget(comparatorView);
   programNavigationLayout->addStretch(1);
   programNavigationLayout->addWidget(multiView);
   programNavigationLayout->addStretch(1);
@@ -1540,11 +1759,17 @@ MainGUI::createConnections()
           SLOT(checkKerningMode()));
   connect(kerningDegreeComboBoxx, SIGNAL(currentIndexChanged(int)),
           SLOT(checkKerningDegree()));
+  connect(hintingModeColumnComboBoxx, SIGNAL(currentIndexChanged(int)),
+        SLOT(checkColumnHinting()));
+  connect(renderingModeColumnComboBoxx, SIGNAL(currentIndexChanged(int)),
+        SLOT(comparatorViewRender()));
 
   connect(allGlyphs, SIGNAL(clicked()),
           SLOT(renderAll()));
   connect(gridView, SIGNAL(clicked()),
           SLOT(gridViewRender()));
+  connect(comparatorView, SIGNAL(clicked()),
+          SLOT(comparatorViewRender()));
 
   connect(autoHintingCheckBox, SIGNAL(clicked()),
           SLOT(checkAutoHinting()));
@@ -1566,6 +1791,8 @@ MainGUI::createConnections()
           SLOT(drawGlyph()));
   connect(showOutlinesCheckBox, SIGNAL(clicked()),
           SLOT(drawGlyph()));
+  connect(warpingColumnCheckBox, SIGNAL(clicked()),
+          SLOT(comparatorViewRender()));
   connect(gammaSlider, SIGNAL(valueChanged(int)),
           SLOT(drawGlyph()));
   connect(embolden_x_Slider, SIGNAL(valueChanged(int)),
diff --git a/src/ftinspect/maingui.hpp b/src/ftinspect/maingui.hpp
index afb836b..48ec7e3 100644
--- a/src/ftinspect/maingui.hpp
+++ b/src/ftinspect/maingui.hpp
@@ -12,6 +12,7 @@
 #include "rendering/glyphsegment.hpp"
 #include "rendering/glyphpoints.hpp"
 #include "rendering/view.hpp"
+#include "rendering/comparator.hpp"
 #include "rendering/grid.hpp"
 #include "widgets/qcomboboxx.hpp"
 #include "widgets/qgraphicsviewx.hpp"
@@ -89,6 +90,7 @@ private slots:
   void checkRenderingMode();
   void checkKerningMode();
   void checkKerningDegree();
+  void checkColumnHinting();
   void checkLcdFilter();
   void checkShowPoints();
   void checkUnits();
@@ -105,6 +107,7 @@ private slots:
   void zoom();
   void renderAll();
   void gridViewRender();
+  void comparatorViewRender();
 
 private:
   Engine* engine;
@@ -114,6 +117,7 @@ private:
   int kerning_mode = 0;
   int kerning_degree = 0;
 
+
   QStringList fontList;
   int currentFontIndex;
 
@@ -138,6 +142,7 @@ private:
   GlyphPointNumbers *currentGlyphPointNumbersItem;
   GlyphBitmap *currentGlyphBitmapItem;
   RenderAll *currentRenderAllItem;
+  Comparator *currentComparatorItem;
   Grid *currentGridItem;
 
   QAction *aboutAct;
@@ -160,6 +165,8 @@ private:
   QCheckBox *showPointsCheckBox;
   QCheckBox *verticalHintingCheckBox;
   QCheckBox *warpingCheckBox;
+  QCheckBox *warpingColumnCheckBox;
+  QCheckBox *kerningColumnCheckBox;
   
 
   QComboBoxx *antiAliasingComboBoxx;
@@ -167,6 +174,9 @@ private:
   QComboBoxx *renderingModeComboBoxx;
   QComboBoxx *kerningModeComboBoxx;
   QComboBoxx *kerningDegreeComboBoxx;
+  QComboBoxx *columnComboBoxx;
+  QComboBoxx *hintingModeColumnComboBoxx;
+  QComboBoxx *renderingModeColumnComboBoxx;
   QComboBox *lcdFilterComboBox;
   QComboBox *unitsComboBox;
 
@@ -206,6 +216,11 @@ private:
   QHBoxLayout *emboldenHorzLayout;
   QHBoxLayout *slantLayout;
   QHBoxLayout *strokeLayout;
+  QHBoxLayout *columnLayout;
+  QHBoxLayout *hintColumnLayout;
+  QHBoxLayout *renderColumnLayout;
+  QHBoxLayout *warpingColumnLayout;
+  QHBoxLayout *kerningColumnLayout;
 
   QLabel *antiAliasingLabel;
   QLabel *dpiLabel;
@@ -225,10 +240,13 @@ private:
   QLabel *yLabel;
   QLabel *slantLabel;
   QLabel *strokeLabel;
+  QLabel *columnLabel;
+  QLabel *hintingColumnLabel;
+  QLabel *renderColumnLabel;
 
   QRadioButton *gridView = new QRadioButton(tr("Grid View"));
   QRadioButton *allGlyphs = new QRadioButton(tr("All Glyphs"));
-  QRadioButton *stringView = new QRadioButton(tr("Render String"));
+  QRadioButton *comparatorView = new QRadioButton(tr("Comparator"));
   QRadioButton *multiView = new QRadioButton(tr("Multi View"));
 
   QList<int> hintingModesAlwaysDisabled;
@@ -284,6 +302,7 @@ private:
   QVBoxLayout *leftLayout;
   QVBoxLayout *rightLayout;
   QVBoxLayout *viewTabLayout;
+  QVBoxLayout *diffTabLayout;
 
   QVector<QRgb> grayColorTable;
   QVector<QRgb> monoColorTable;
@@ -294,6 +313,7 @@ private:
   QWidget *rightWidget;
   QWidget *mmgxTabWidget;
   QWidget *viewTabWidget;
+  QWidget *diffTabWidget;
 
   enum AntiAliasing
   {
@@ -348,6 +368,30 @@ private:
     KERNING_DEGREE_TIGHT
   };
 
+  typedef enum  HintMode_
+  {
+    HINT_MODE_UNHINTED,
+    HINT_MODE_AUTOHINT,
+    HINT_MODE_AUTOHINT_LIGHT,
+    HINT_MODE_AUTOHINT_LIGHT_SUBPIXEL,
+    HINT_MODE_BYTECODE,
+    HINT_MODE_MAX
+
+  } HintMode;
+
+  
+  typedef struct  ColumnStateRec_
+  {
+    HintMode       hint_mode;
+  } ColumnStateRec, *ColumnState;
+  
+  HintMode hintmode;
+  ColumnStateRec state[3];
+  int load_flags[3] = { 0, 0, 0};
+  int pixelMode[3] = {FT_PIXEL_MODE_MONO, FT_PIXEL_MODE_MONO, 
FT_PIXEL_MODE_MONO};
+  bool warping[3] = {false, false, false};
+  bool kerningCol[3] = {false, false, false};;
+
   void createActions();
   void createConnections();
   void createLayout();
diff --git a/src/ftinspect/rendering/comparator.cpp 
b/src/ftinspect/rendering/comparator.cpp
new file mode 100644
index 0000000..f3e98a9
--- /dev/null
+++ b/src/ftinspect/rendering/comparator.cpp
@@ -0,0 +1,222 @@
+// glyphbitmap.cpp
+
+// Copyright (C) 2016-2019 by Werner Lemberg.
+
+
+#include "comparator.hpp"
+
+#include <cmath>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
+#include <QtDebug>
+
+  /* baseline distance between header lines */
+#define HEADER_HEIGHT  12
+
+static const char*  default_text =
+    "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras sit amet"
+    " dui.  Nam sapien. Fusce vestibulum ornare metus. Maecenas ligula orci,"
+    " consequat vitae, dictum nec, lacinia non, elit. Aliquam iaculis"
+    " molestie neque. Maecenas suscipit felis ut pede convallis malesuada."
+    " Aliquam erat volutpat. Nunc pulvinar condimentum nunc. Donec ac sem vel"
+    " leo bibendum aliquam. Pellentesque habitant morbi tristique senectus et"
+    " netus et malesuada fames ac turpis egestas.\n"
+    "\n"
+    "Sed commodo. Nulla ut libero sit amet justo varius blandit. Mauris vitae"
+    " nulla eget lorem pretium ornare. Proin vulputate erat porta risus."
+    " Vestibulum malesuada, odio at vehicula lobortis, nisi metus hendrerit"
+    " est, vitae feugiat quam massa a ligula. Aenean in tellus. Praesent"
+    " convallis. Nullam vel lacus.  Aliquam congue erat non urna mollis"
+    " faucibus. Morbi vitae mauris faucibus quam condimentum ornare. Quisque"
+    " sit amet augue. Morbi ullamcorper mattis enim. Aliquam erat volutpat."
+    " Morbi nec felis non enim pulvinar lobortis.  Ut libero. Nullam id orci"
+    " quis nisl dapibus rutrum. Suspendisse consequat vulputate leo. Aenean"
+    " non orci non tellus iaculis vestibulum. Sed neque.\n"
+    "\n";
+
+
+Comparator::Comparator(FT_Library lib,
+                        FT_Face face,
+                        FT_Size  size,
+                        QStringList fontList,
+                        int load_flags[],
+                        int pixelMode[],
+                        QVector<QRgb> grayColorTable,
+                        QVector<QRgb> monoColorTable,
+                        bool warping[],
+                        bool kerningCol[])
+: library(lib),
+face(face),
+size(size),
+fontList(fontList),
+grayColorTable(grayColorTable),
+monoColorTable(monoColorTable)
+{
+  load[0] = load_flags[0];
+  load[1] = load_flags[1];
+  load[2] = load_flags[2];
+
+  warping_col[0] = warping[0];
+  warping_col[1] = warping[1];
+  warping_col[2] = warping[2];
+
+  pixelMode_col[0] = pixelMode[0];
+  pixelMode_col[1] = pixelMode[1];
+  pixelMode_col[2] = pixelMode[2];
+
+  kerning[0] = kerningCol[0];
+  kerning[1] = kerningCol[1];
+  kerning[2] = kerningCol[2];
+}
+
+
+Comparator::~Comparator()
+{
+}
+
+QRectF
+Comparator::boundingRect() const
+{
+  return QRectF(-350, -250,
+              700, 500);
+}
+
+
+void
+Comparator::paint(QPainter* painter,
+                   const QStyleOptionGraphicsItem* option,
+                   QWidget*)
+{
+  const char*  p;
+  const char*  pEnd;
+  int          ch;
+  FT_UInt  glyph_idx;
+  long load_flags[3];
+  int column_selected;
+  
+  p    = default_text;
+  pEnd = p + strlen( default_text ); 
+  int length = strlen(default_text);
+
+  int  border_width;
+
+  int  column_x_start[3];
+  int  column_x_end[3];
+  int  column_x_temp[3];
+  int  column_y_start;
+
+  int  column_height;
+  int  column_width;
+  
+  /* We have this layout:                                */
+  /*                                                     */
+  /*  | n ----x---- n  n ----x---- n  n ----x---- n |    */
+  /*                                                     */
+  /* w = 6 * n + 3 * x                                   */
+
+  border_width = 10;                                /* n */
+  int width = -350;
+  column_width = ( 700 - 6 * border_width ) / 3;  /* x */
+
+  column_x_start[0] = width + border_width;
+  column_x_start[1] = width + 3 * border_width + column_width;
+  column_x_start[2] = width + 5 * border_width + 2 * column_width;
+
+  column_x_end[0] = column_x_start[0] + column_width;
+  column_x_end[1] = column_x_start[1] + column_width;
+  column_x_end[2] = column_x_start[2] + column_width;
+
+  column_x_temp[0] = width + border_width;
+  column_x_temp[1] = width + 3 * border_width + column_width;
+  column_x_temp[2] = width + 5 * border_width + 2 * column_width;
+
+  int height = -220;
+
+  /* error = FT_New_Face(library,
+                fontList[0].toLatin1().constData(),
+                0,
+                &f);
+
+  error = FT_Set_Char_Size(face,
+                        0,
+                        16 * 64,
+                        0,
+                        72);*/
+                        
+  //column_y_start = 10 + 2 * HEADER_HEIGHT;
+  //column_height  = height - 8 * HEADER_HEIGHT - 5;
+  for (int col = 0; col < 3; col++)
+  {
+    FT_UInt previous;
+    height = -230;
+
+    FT_Error error = FT_Property_Set(library,
+                              "autofitter",
+                              "warping",
+                              &warping_col[col]);
+
+    for ( int i = 0; i < length; i++ )
+    {
+      QChar ch = default_text[i];
+
+      // get char index 
+      glyph_idx = FT_Get_Char_Index( face , ch.unicode());
+
+      if ( kerning[col] && glyph_idx != 0 && previous != 0 )
+      {
+        FT_Vector  vec;
+
+        FT_Get_Kerning( face, previous, glyph_idx, kerning_mode, &vec );
+
+        column_x_start[col] += vec.x;
+      }
+
+      /* load glyph image into the slot (erase previous one) */
+      error = FT_Load_Glyph( face, glyph_idx, load[col] );
+      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);
+      }
+
+      if (pixelMode_col[col] == FT_PIXEL_MODE_GRAY)
+      {
+        glyphImage.setColorTable(colorTable);
+      } else
+      {
+        glyphImage.setColorTable(grayColorTable);
+      }
+
+      painter->drawImage(column_x_start[col], height,
+                        glyphImage, 0, 0, -1, -1);
+
+
+      column_x_start[col] += face->glyph->advance.x/64;
+
+      if (column_x_start[col] >= column_x_end[col])
+      { 
+        height += (size->metrics.height + 4)/64;
+        column_x_start[col] = column_x_temp[col];
+      }
+
+      previous = glyph_idx;
+    }
+  }
+}
+
+
+// end of glyphbitmap.cpp
diff --git a/src/ftinspect/rendering/comparator.hpp 
b/src/ftinspect/rendering/comparator.hpp
new file mode 100644
index 0000000..58c7272
--- /dev/null
+++ b/src/ftinspect/rendering/comparator.hpp
@@ -0,0 +1,64 @@
+// glyphbitmap.hpp
+
+// Copyright (C) 2016-2019 by Werner Lemberg.
+
+
+#pragma once
+
+#include <QGraphicsItem>
+#include <QPen>
+
+#include "../engine/engine.hpp"
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_OUTLINE_H
+
+
+#include FT_DRIVER_H
+#include FT_LCD_FILTER_H
+
+// internal FreeType header files; only available in the source code bundle
+#include FT_INTERNAL_DRIVER_H
+#include FT_INTERNAL_OBJECTS_H
+
+
+class Comparator
+: public QGraphicsItem
+{
+public:
+  Comparator(FT_Library library,
+             FT_Face face,
+             FT_Size  size,
+             QStringList fontList,
+             int load_flags[],
+             int pixelMode[],
+             QVector<QRgb> grayColorTable,
+             QVector<QRgb> monoColorTable,
+             bool warping[],
+             bool kerningCol[]);
+  ~Comparator();
+  QRectF boundingRect() const;
+  void paint(QPainter* painter,
+             const QStyleOptionGraphicsItem* option,
+             QWidget* widget);
+
+private:
+  FT_Library library;
+  FT_Face f;
+  FT_Face face;
+  FT_Size  size;
+  FT_Error error;
+  Engine* engine;
+  QStringList fontList;
+  int load[3];
+  int pixelMode_col[3];
+  bool warping_col[3];
+  QVector<QRgb> grayColorTable;
+  QVector<QRgb> monoColorTable;
+  FT_UInt kerning_mode = FT_KERNING_DEFAULT;
+  bool kerning[3];
+};
+
+
+// end of glyphbitmap.hpp



reply via email to

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