[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master faffad8 2/2: [ftinspect] Start with FreeType in
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master faffad8 2/2: [ftinspect] Start with FreeType initialization. |
Date: |
Tue, 03 May 2016 09:59:13 +0000 |
branch: master
commit faffad8262b3d901c1c5c780319b48087acb6aa2
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Start with FreeType initialization.
* src/ftinspect.h: Include some FreeType headers.
(Font): New structure for holding a (physical) font.
(Engine): New class for communication with FreeType library.
(MainGUI): Make `engine' a friend.
* src/ftinspect.cpp (faceRequester): New function for FreeType's
cache manager.
(Engine::Engine, Engine::update): Some basic functions; to be
extensively revised in later commits.
(main): Updated.
* src/ftinspect.pro: Add support for FreeType and dependent
libraries. Right now, you have to adjust paths manually.
---
ChangeLog | 18 +++++++++++
src/ftinspect.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ftinspect.h | 51 ++++++++++++++++++++++++++++++
src/ftinspect.pro | 17 ++++++++++
4 files changed, 176 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index fe3a784..9cc48e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
2016-05-02 Werner Lemberg <address@hidden>
+ [ftinspect] Start with FreeType initialization.
+
+ * src/ftinspect.h: Include some FreeType headers.
+ (Font): New structure for holding a (physical) font.
+ (Engine): New class for communication with FreeType library.
+ (MainGUI): Make `engine' a friend.
+
+ * src/ftinspect.cpp (faceRequester): New function for FreeType's
+ cache manager.
+ (Engine::Engine, Engine::update): Some basic functions; to be
+ extensively revised in later commits.
+ (main): Updated.
+
+ * src/ftinspect.pro: Add support for FreeType and dependent
+ libraries. Right now, you have to adjust paths manually.
+
+2016-05-02 Werner Lemberg <address@hidden>
+
[ftinspect] Minor.
* src/ftinspect.h, src/ftinspect.cpp:
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index b99fbcd..aed4279 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -8,6 +8,93 @@
#define VERSION "X.Y.Z"
+// The face requester is a function provided by the client application to
+// the cache manager to translate an `abstract' face ID into a real
+// `FT_Face' object.
+//
+// Here, the face IDs are simply pointers to `Font' objects.
+
+static FT_Error
+faceRequester(FTC_FaceID faceID,
+ FT_Library library,
+ FT_Pointer /* requestData */,
+ FT_Face* faceP)
+{
+ Font* font = static_cast<Font*>(faceID);
+
+ return FT_New_Face(library,
+ font->filePathname,
+ font->faceIndex,
+ faceP);
+}
+
+
+Engine::Engine()
+{
+ FT_Error error;
+
+ error = FT_Init_FreeType(&library);
+ if (error)
+ {
+ // XXX error handling
+ }
+
+ error = FTC_Manager_New(library, 0, 0, 0,
+ faceRequester, 0, &cacheManager);
+ if (error)
+ {
+ // XXX error handling
+ }
+
+ error = FTC_SBitCache_New(cacheManager, &sbitsCache);
+ if (error)
+ {
+ // XXX error handling
+ }
+
+ error = FTC_ImageCache_New(cacheManager, &imageCache);
+ if (error)
+ {
+ // XXX error handling
+ }
+}
+
+
+void
+Engine::update(const MainGUI& gui)
+{
+ dpi = gui.dpiSpinBox->value();
+ zoom = gui.zoomSpinBox->value();
+
+ if (gui.unitsComboBox->currentIndex() == MainGUI::Units_px)
+ {
+ pointSize = gui.sizeDoubleSpinBox->value();
+ pixelSize = pointSize * dpi / 72.0;
+ }
+ else
+ {
+ pixelSize = gui.sizeDoubleSpinBox->value();
+ pointSize = pixelSize * 72.0 / dpi;
+ }
+
+ doHorizontalHinting = gui.horizontalHintingCheckBox->isChecked();
+ doVerticalHinting = gui.verticalHintingCheckBox->isChecked();
+ doBlueZoneHinting = gui.blueZoneHintingCheckBox->isChecked();
+ showSegments = gui.segmentDrawingCheckBox->isChecked();
+ doWarping = gui.warpingCheckBox->isChecked();
+
+ showBitmap = gui.showBitmapCheckBox->isChecked();
+ showPoints = gui.showPointsCheckBox->isChecked();
+ if (showPoints)
+ showPointIndices = gui.showPointIndicesCheckBox->isChecked();
+ else
+ showPointIndices = false;
+ showOutlines = gui.showOutlinesCheckBox->isChecked();
+
+ gamma = gui.gammaSlider->value();
+}
+
+
MainGUI::MainGUI()
{
createLayout();
@@ -534,7 +621,10 @@ main(int argc,
app.setOrganizationName("FreeType");
app.setOrganizationDomain("freetype.org");
+ Engine engine;
MainGUI gui;
+
+ engine.update(gui);
gui.show();
return app.exec();
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 79b715a..63434b0 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -3,6 +3,10 @@
#ifndef FTINSPECT_H_
#define FTINSPECT_H_
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_CACHE_H
+
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
@@ -32,6 +36,51 @@
#include <QWidget>
+class MainGUI;
+
+
+struct Font
+{
+ const char* filePathname;
+ int faceIndex;
+ int numIndices;
+ size_t fileSize;
+};
+
+
+class Engine
+{
+public:
+ Engine();
+
+ void update(const MainGUI&);
+
+private:
+ FT_Library library;
+ FTC_Manager cacheManager;
+ FTC_ImageCache imageCache;
+ FTC_SBitCache sbitsCache;
+
+ double pointSize;
+ double pixelSize;
+ int dpi;
+ int zoom;
+
+ bool doHorizontalHinting;
+ bool doVerticalHinting;
+ bool doBlueZoneHinting;
+ bool showSegments;
+ bool doWarping;
+
+ bool showBitmap;
+ bool showPoints;
+ bool showPointIndices;
+ bool showOutlines;
+
+ double gamma;
+};
+
+
class MainGUI
: public QMainWindow
{
@@ -41,6 +90,8 @@ public:
MainGUI();
~MainGUI();
+ friend class Engine;
+
protected:
void closeEvent(QCloseEvent*);
diff --git a/src/ftinspect.pro b/src/ftinspect.pro
index 63483a9..3ff8310 100644
--- a/src/ftinspect.pro
+++ b/src/ftinspect.pro
@@ -1,3 +1,20 @@
+INCLUDEPATH += ../../freetype2/include
+
+# To avoid conflicts with the FreeType version compiled into or used by Qt,
+# we use the static library.
+#
+# You should adapt this to your setup.
+unix|macx {
+ LIBS += ../../freetype2/objs/libfreetype.a
+
+ CONFIG += link_pkgconfig
+ PKGCONFIG += libpng harfbuzz zlib bzip2
+}
+win32 {
+ LIBS += ../../freetyp2/objs/vc2010/freetype263.lib
+ LIBS += -lpng -lharfbuzz -lz -lbz2 -lm
+}
+
CONFIG += qt debug
SOURCES += ftinspect.cpp
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master faffad8 2/2: [ftinspect] Start with FreeType initialization.,
Werner LEMBERG <=