diff options
author | ElOraiby <wael.eloraiby@gmail.com> | 2015-05-30 15:21:07 -0400 |
---|---|---|
committer | ElOraiby <wael.eloraiby@gmail.com> | 2015-05-30 15:21:07 -0400 |
commit | 3341cc55671378288e6bb4f94b15fedb24c93e1c (patch) | |
tree | 40f3168b1116b613b53e1a987d28077ce3c06c6d | |
parent | 5e1fd7a1ee767b6c8e0d7461b1044d93a42989a2 (diff) |
cleanup
-rw-r--r-- | arabtype.c | 6 | ||||
-rw-r--r-- | mainwindow.cpp | 28 |
2 files changed, 18 insertions, 16 deletions
@@ -16,6 +16,8 @@ #define INITIAL 2 #define MEDIAL 3 +#define UNICODE_LAM 0x644 + // // 0: isolated form // 1: ending form @@ -73,10 +75,10 @@ static all_form_t arabic_forms_b[] = { static inline bool is_arabic_letter(uint32_t cp) { return ( cp >= ARABIC_LETTER_START && cp <= ARABIC_LETTER_END ); } -static inline bool is_lam_alef(uint32_t cp, uint32_t next) { return cp == 0x644 && +static inline bool is_lam_alef(uint32_t cp, uint32_t next) { return cp == UNICODE_LAM && is_arabic_letter(next) && arabic_forms_b[next - ARABIC_LETTER_START][1][INITIAL] != 0; } -static inline bool is_alef_prev_lam(uint32_t prev, uint32_t cp) { return prev == 0x644 && +static inline bool is_alef_prev_lam(uint32_t prev, uint32_t cp) { return prev == UNICODE_LAM && is_arabic_letter(cp) && arabic_forms_b[cp - ARABIC_LETTER_START][1][INITIAL] != 0; } static inline bool is_linking_type(uint32_t cp) { diff --git a/mainwindow.cpp b/mainwindow.cpp index 60d9d51..015bcb7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -51,6 +51,10 @@ MainWindow::MainWindow(QWidget *parent) : { ui__->setupUi(this); + int width = 480; + int height = 320; + int font_size = 24; + std::ifstream ifs("arabic_test.txt"); assert( ifs.is_open() ); std::vector<uchar> arabic_string; @@ -86,7 +90,7 @@ MainWindow::MainWindow(QWidget *parent) : assert( !error && "unable to load font file" ); // set font size - error = FT_Set_Pixel_Sizes(face, 0, 24); + error = FT_Set_Pixel_Sizes(face, 0, font_size); assert( !error && "Error setting font size" ); // setup glyph @@ -97,18 +101,18 @@ MainWindow::MainWindow(QWidget *parent) : FT_Render_Mode render_flags = FT_RENDER_MODE_NORMAL; - data__ = new uchar[1024 * 1024 * 4]; - memset(data__, 0, 1024 * 1024 * 4); - int col = 1024 - 1; - int line = 100; - QImage img(data__, 1024, 1024, QImage::Format_RGB32); + 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 < arabic_cp.size(); ++idx ) { uint ch = get_arabic_form(arabic_cp, idx); if( ch == 0xA ) { - line += 30; - col = 1024 - 1; + line += font_size; + col = width - font_size; continue; } @@ -137,17 +141,16 @@ MainWindow::MainWindow(QWidget *parent) : FT_BBox box; FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &box); - int temp_col = col - (slot->advance.x >> 6);//slot->bitmap.width; + 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 < 1024 && x + temp_col >= 0 ) + 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)); } @@ -164,9 +167,6 @@ MainWindow::MainWindow(QWidget *parent) : } - for( int i = 0; i < 1024; ++i ) - //data__[i + 128 * 512 * 4 + 1] = 0xFF; - img.setPixel(i, 128, 0xFF000000); QPixmap pixmap = QPixmap::fromImage(img); ui__->label->setPixmap(pixmap); |