]> code.bitgloo.com Git - clyne/arabtype.git/commitdiff
move the example to the example folder
authorElOraiby <wael.eloraiby@gmail.com>
Mon, 1 Jun 2015 00:53:45 +0000 (20:53 -0400)
committerElOraiby <wael.eloraiby@gmail.com>
Mon, 1 Jun 2015 00:53:45 +0000 (20:53 -0400)
14 files changed:
ae_Tholoth.ttf [deleted file]
arabic_string_layout.pro [deleted file]
arabic_test.txt [deleted file]
example/ae_Tholoth.ttf [new file with mode: 0644]
example/arabic_string_layout.pro [new file with mode: 0644]
example/arabic_test.txt [new file with mode: 0644]
example/main.cpp [new file with mode: 0644]
example/mainwindow.cpp [new file with mode: 0644]
example/mainwindow.h [new file with mode: 0644]
example/mainwindow.ui [new file with mode: 0644]
main.cpp [deleted file]
mainwindow.cpp [deleted file]
mainwindow.h [deleted file]
mainwindow.ui [deleted file]

diff --git a/ae_Tholoth.ttf b/ae_Tholoth.ttf
deleted file mode 100644 (file)
index 74df449..0000000
Binary files a/ae_Tholoth.ttf and /dev/null differ
diff --git a/arabic_string_layout.pro b/arabic_string_layout.pro
deleted file mode 100644 (file)
index 979b395..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2012-09-21T20:12:51
-#
-#-------------------------------------------------
-
-QT       += core gui
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
-TARGET = arabic_string_layout
-TEMPLATE = app
-
-QMAKE_CFLAGS_DEBUG += -std=c99
-QMAKE_CFLAGS_RELEASE += -std=c99
-
-CONFIG += link_pkgconfig
-
-PKGCONFIG      += freetype2
-
-SOURCES += main.cpp\
-       mainwindow.cpp \
-    utf8.c \
-    arabtype.c
-
-HEADERS  += mainwindow.h \
-    utf8.h \
-    arabtype.h
-
-FORMS    += mainwindow.ui
diff --git a/arabic_test.txt b/arabic_test.txt
deleted file mode 100644 (file)
index 5c014fa..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-أعطني الناي وغني فالغنا سر الوجود
-وأنين الناي يبقى بعد أن يفنى الوجود
-هل إتخذت الغاب مثلي منزلاً دون القصور
-فتتبعت السواقي وتسلقت الصخور
-هل تحممت بعطر وتنشفت بنور
-وشربت الفجر خمراً فى كؤوس من أثير
-هل جلست العصر مثلي بين جفنات العنب
-والعناقيد تدلت كثريات الذهب
-هل فرشت العشب ليلاً وتلحفت الفضاء
-زاهداً في ما سيأتي ناسياً ما قد مضى
-أعطني الناي وغني وانسى داء ودواء
-إنما الناس سطورٌ كتبت لكن بماء
-
diff --git a/example/ae_Tholoth.ttf b/example/ae_Tholoth.ttf
new file mode 100644 (file)
index 0000000..74df449
Binary files /dev/null and b/example/ae_Tholoth.ttf differ
diff --git a/example/arabic_string_layout.pro b/example/arabic_string_layout.pro
new file mode 100644 (file)
index 0000000..b4256b3
--- /dev/null
@@ -0,0 +1,30 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2012-09-21T20:12:51
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = arabic_string_layout
+TEMPLATE = app
+
+QMAKE_CFLAGS_DEBUG += -std=c99
+QMAKE_CFLAGS_RELEASE += -std=c99
+
+CONFIG += link_pkgconfig
+
+PKGCONFIG      += freetype2
+
+SOURCES += main.cpp\
+       mainwindow.cpp \
+    ../utf8.c \
+    ../arabtype.c
+
+HEADERS  += mainwindow.h \
+    ../utf8.h \
+    ../arabtype.h
+
+FORMS    += mainwindow.ui
diff --git a/example/arabic_test.txt b/example/arabic_test.txt
new file mode 100644 (file)
index 0000000..5c014fa
--- /dev/null
@@ -0,0 +1,13 @@
+أعطني الناي وغني فالغنا سر الوجود
+وأنين الناي يبقى بعد أن يفنى الوجود
+هل إتخذت الغاب مثلي منزلاً دون القصور
+فتتبعت السواقي وتسلقت الصخور
+هل تحممت بعطر وتنشفت بنور
+وشربت الفجر خمراً فى كؤوس من أثير
+هل جلست العصر مثلي بين جفنات العنب
+والعناقيد تدلت كثريات الذهب
+هل فرشت العشب ليلاً وتلحفت الفضاء
+زاهداً في ما سيأتي ناسياً ما قد مضى
+أعطني الناي وغني وانسى داء ودواء
+إنما الناس سطورٌ كتبت لكن بماء
+
diff --git a/example/main.cpp b/example/main.cpp
new file mode 100644 (file)
index 0000000..24a397b
--- /dev/null
@@ -0,0 +1,11 @@
+#include <QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+       QApplication a(argc, argv);
+       MainWindow w;
+       w.show();
+       
+       return a.exec();
+}
diff --git a/example/mainwindow.cpp b/example/mainwindow.cpp
new file mode 100644 (file)
index 0000000..81f82be
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+** Arabtype Copyright 2012-2015(c) Wael El Oraiby. All Rights Reserved
+**
+** This file is in public domain
+*/
+
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QtGui>
+#include <cassert>
+#include <iostream>
+#include <vector>
+#include <string>
+#include <fstream>
+
+#include "../arabtype.h"
+
+FT_Library MainWindow::ftlib__ = NULL;
+
+
+MainWindow::MainWindow(QWidget *parent) :
+       QMainWindow(parent),
+       ui__(new Ui::MainWindow)
+{
+       ui__->setupUi(this);
+
+       int     width   = 480;
+       int     height  = 392;
+       int     font_size       = 24;
+
+       std::ifstream   ifs("arabic_test.txt");
+       assert( ifs.is_open() );
+       std::vector<uchar>      arabic_string;
+
+       while( ifs.good() )
+       {
+               uchar ch = ifs.get();
+               if( ifs.good() )
+                       arabic_string.push_back(ch);
+       }
+
+       std::cout << "size: " << arabic_string.size() << std::endl;
+       ifs.close();
+
+
+       uint32_t*       arabic_cp       = new uint32_t[arabic_string.size()];
+       uint32_t        acp_size        = get_presentation_form_b(arabic_string.size(), &arabic_string[0], arabic_string.size() * sizeof(uint32_t), arabic_cp);
+
+       for( size_t i = 0; i < acp_size; ++i )
+               std::cout << "0x" << std::hex << arabic_cp[i] << std::endl;
+
+       std::cout << std::dec;
+
+       if( !ftlib__ )
+       {
+               FT_Error        error = FT_Init_FreeType(&ftlib__);
+               assert( !error && "Error loading freetype" );
+       }
+
+       // load the font
+       FT_Face         face;
+       FT_Error        error;
+
+       error           = FT_New_Face(ftlib__, "ae_Tholoth.ttf", 0, &face);
+       assert( !error && "unable to load font file" );
+
+       // set font size
+       error           = FT_Set_Pixel_Sizes(face, 0, font_size);
+       assert( !error && "Error setting font size" );
+
+       // setup glyph
+       // render chars
+       FT_GlyphSlot    slot            = face->glyph;
+
+       FT_Int32        load_flags      = FT_LOAD_DEFAULT | FT_LOAD_FORCE_AUTOHINT;
+       FT_Render_Mode  render_flags    = FT_RENDER_MODE_NORMAL;
+
+
+       data__  = new uchar[width * height * 4];
+       memset(data__, 0, width * height * 4);
+       int     col     = width - font_size;
+       int     line    = font_size;
+       QImage  img(data__, width, height, QImage::Format_RGB32);
+       // render the arabic glyphs
+       for( size_t idx = 0; idx < acp_size; ++idx )
+       {
+               uint ch = arabic_cp[idx];
+
+               if( ch == 0xA ) {
+                       line    += font_size + 5;
+                       col     = width - font_size;
+                       continue;
+               }
+
+               if ( ch == 0xC ) {
+                       continue;
+               }
+
+               if ( ch == -1 ) {
+                       continue;
+               }
+
+               assert(ch != 0);
+
+               int glyph_index = FT_Get_Char_Index(face, ch);
+               assert( glyph_index && "invalid character" );
+
+               error   = FT_Load_Glyph(face, glyph_index, load_flags);
+               assert( !error && "couldn't load glyph" );
+
+               error = FT_Render_Glyph(slot, render_flags);
+               assert( !error && "couldn't render glyph" );
+
+               FT_Glyph glyph;
+               FT_Get_Glyph(slot, &glyph);
+
+               FT_BBox box;
+               FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &box);
+
+               int     temp_col        = col - (slot->advance.x >> 6);
+
+               for( int y = 0; y < slot->bitmap.rows; y++ )
+               {
+                       for( int x = 0; x < slot->bitmap.width; x++ )
+                       {
+                               uchar   co      = slot->bitmap.buffer[x + y * slot->bitmap.pitch];
+                               if( co && x + temp_col < width && x + temp_col >= 0 )
+                               {
+                                       uint rgb = img.pixel(x + temp_col + slot->bitmap_left, y - slot->bitmap_top + line);
+                                       img.setPixel(x + temp_col + slot->bitmap_left, y - slot->bitmap_top + line, rgb | qRgb(co, co, co));
+                               }
+
+                               //std::cout << uint(co) << " ";
+                       }
+                       //std::cout << std::endl;
+               }
+
+               //std::cout << std::endl;
+
+               col -= slot->advance.x >> 6;
+
+               FT_Done_Glyph(glyph);
+       }
+
+       delete[] arabic_cp;
+
+       QPixmap pixmap = QPixmap::fromImage(img);
+       ui__->label->setPixmap(pixmap);
+
+       FT_Done_Face(face);
+}
+
+MainWindow::~MainWindow()
+{
+       FT_Done_FreeType(ftlib__);
+       delete ui__;
+       delete data__;
+}
+
+void MainWindow::paintEvent ( QPaintEvent * event )
+{
+}
diff --git a/example/mainwindow.h b/example/mainwindow.h
new file mode 100644 (file)
index 0000000..f86c17d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+** Arabtype Copyright 2012-2015(c) Wael El Oraiby. All Rights Reserved
+**
+** This file is in public domain
+*/
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+       Q_OBJECT
+
+public:
+       explicit MainWindow(QWidget *parent = 0);
+       ~MainWindow();
+
+protected:
+       virtual void            paintEvent(QPaintEvent* event);
+
+private:
+       Ui::MainWindow*         ui__;
+       uchar*                  data__;
+       static FT_Library       ftlib__;
+};
+
+#endif // MAINWINDOW_H
diff --git a/example/mainwindow.ui b/example/mainwindow.ui
new file mode 100644 (file)
index 0000000..062f947
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <layout class="QVBoxLayout" name="verticalLayout">
+    <item>
+     <widget class="QLabel" name="label">
+      <property name="text">
+       <string/>
+      </property>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>400</width>
+     <height>23</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/main.cpp b/main.cpp
deleted file mode 100644 (file)
index 24a397b..0000000
--- a/main.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include <QApplication>
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
-       QApplication a(argc, argv);
-       MainWindow w;
-       w.show();
-       
-       return a.exec();
-}
diff --git a/mainwindow.cpp b/mainwindow.cpp
deleted file mode 100644 (file)
index ad6cde7..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
-** Arabtype Copyright 2012-2015(c) Wael El Oraiby. All Rights Reserved
-**
-** This file is in public domain
-*/
-
-#include "mainwindow.h"
-#include "ui_mainwindow.h"
-#include <QtGui>
-#include <cassert>
-#include <iostream>
-#include <vector>
-#include <string>
-#include <fstream>
-
-#include "utf8.h"
-#include "arabtype.h"
-
-FT_Library MainWindow::ftlib__ = NULL;
-
-
-MainWindow::MainWindow(QWidget *parent) :
-       QMainWindow(parent),
-       ui__(new Ui::MainWindow)
-{
-       ui__->setupUi(this);
-
-       int     width   = 480;
-       int     height  = 392;
-       int     font_size       = 24;
-
-       std::ifstream   ifs("arabic_test.txt");
-       assert( ifs.is_open() );
-       std::vector<uchar>      arabic_string;
-
-       while( ifs.good() )
-       {
-               uchar ch = ifs.get();
-               if( ifs.good() )
-                       arabic_string.push_back(ch);
-       }
-
-       std::cout << "size: " << arabic_string.size() << std::endl;
-       ifs.close();
-
-
-       uint32_t*       arabic_cp       = new uint32_t[arabic_string.size()];
-       uint32_t        acp_size        = get_presentation_form_b(arabic_string.size(), &arabic_string[0], arabic_string.size() * sizeof(uint32_t), arabic_cp);
-
-       for( size_t i = 0; i < acp_size; ++i )
-               std::cout << "0x" << std::hex << arabic_cp[i] << std::endl;
-
-       std::cout << std::dec;
-
-       if( !ftlib__ )
-       {
-               FT_Error        error = FT_Init_FreeType(&ftlib__);
-               assert( !error && "Error loading freetype" );
-       }
-
-       // load the font
-       FT_Face         face;
-       FT_Error        error;
-
-       error           = FT_New_Face(ftlib__, "ae_Tholoth.ttf", 0, &face);
-       assert( !error && "unable to load font file" );
-
-       // set font size
-       error           = FT_Set_Pixel_Sizes(face, 0, font_size);
-       assert( !error && "Error setting font size" );
-
-       // setup glyph
-       // render chars
-       FT_GlyphSlot    slot            = face->glyph;
-
-       FT_Int32        load_flags      = FT_LOAD_DEFAULT | FT_LOAD_FORCE_AUTOHINT;
-       FT_Render_Mode  render_flags    = FT_RENDER_MODE_NORMAL;
-
-
-       data__  = new uchar[width * height * 4];
-       memset(data__, 0, width * height * 4);
-       int     col     = width - font_size;
-       int     line    = font_size;
-       QImage  img(data__, width, height, QImage::Format_RGB32);
-       // render the arabic glyphs
-       for( size_t idx = 0; idx < acp_size; ++idx )
-       {
-               uint ch = arabic_cp[idx];
-
-               if( ch == 0xA ) {
-                       line    += font_size + 5;
-                       col     = width - font_size;
-                       continue;
-               }
-
-               if ( ch == 0xC ) {
-                       continue;
-               }
-
-               if ( ch == -1 ) {
-                       continue;
-               }
-
-               assert(ch != 0);
-
-               int glyph_index = FT_Get_Char_Index(face, ch);
-               assert( glyph_index && "invalid character" );
-
-               error   = FT_Load_Glyph(face, glyph_index, load_flags);
-               assert( !error && "couldn't load glyph" );
-
-               error = FT_Render_Glyph(slot, render_flags);
-               assert( !error && "couldn't render glyph" );
-
-               FT_Glyph glyph;
-               FT_Get_Glyph(slot, &glyph);
-
-               FT_BBox box;
-               FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &box);
-
-               int     temp_col        = col - (slot->advance.x >> 6);
-
-               for( int y = 0; y < slot->bitmap.rows; y++ )
-               {
-                       for( int x = 0; x < slot->bitmap.width; x++ )
-                       {
-                               uchar   co      = slot->bitmap.buffer[x + y * slot->bitmap.pitch];
-                               if( co && x + temp_col < width && x + temp_col >= 0 )
-                               {
-                                       uint rgb = img.pixel(x + temp_col + slot->bitmap_left, y - slot->bitmap_top + line);
-                                       img.setPixel(x + temp_col + slot->bitmap_left, y - slot->bitmap_top + line, rgb | qRgb(co, co, co));
-                               }
-
-                               //std::cout << uint(co) << " ";
-                       }
-                       //std::cout << std::endl;
-               }
-
-               //std::cout << std::endl;
-
-               col -= slot->advance.x >> 6;
-
-               FT_Done_Glyph(glyph);
-       }
-
-       delete[] arabic_cp;
-
-       QPixmap pixmap = QPixmap::fromImage(img);
-       ui__->label->setPixmap(pixmap);
-
-       FT_Done_Face(face);
-}
-
-MainWindow::~MainWindow()
-{
-       FT_Done_FreeType(ftlib__);
-       delete ui__;
-       delete data__;
-}
-
-void MainWindow::paintEvent ( QPaintEvent * event )
-{
-}
diff --git a/mainwindow.h b/mainwindow.h
deleted file mode 100644 (file)
index f86c17d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-** Arabtype Copyright 2012-2015(c) Wael El Oraiby. All Rights Reserved
-**
-** This file is in public domain
-*/
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#include <QMainWindow>
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
-
-namespace Ui {
-class MainWindow;
-}
-
-class MainWindow : public QMainWindow
-{
-       Q_OBJECT
-
-public:
-       explicit MainWindow(QWidget *parent = 0);
-       ~MainWindow();
-
-protected:
-       virtual void            paintEvent(QPaintEvent* event);
-
-private:
-       Ui::MainWindow*         ui__;
-       uchar*                  data__;
-       static FT_Library       ftlib__;
-};
-
-#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
deleted file mode 100644 (file)
index 062f947..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>400</width>
-    <height>300</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>MainWindow</string>
-  </property>
-  <widget class="QWidget" name="centralWidget">
-   <layout class="QVBoxLayout" name="verticalLayout">
-    <item>
-     <widget class="QLabel" name="label">
-      <property name="text">
-       <string/>
-      </property>
-     </widget>
-    </item>
-   </layout>
-  </widget>
-  <widget class="QMenuBar" name="menuBar">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>400</width>
-     <height>23</height>
-    </rect>
-   </property>
-  </widget>
-  <widget class="QToolBar" name="mainToolBar">
-   <attribute name="toolBarArea">
-    <enum>TopToolBarArea</enum>
-   </attribute>
-   <attribute name="toolBarBreak">
-    <bool>false</bool>
-   </attribute>
-  </widget>
-  <widget class="QStatusBar" name="statusBar"/>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections/>
-</ui>