1. 程式人生 > >MiniGUI TTF旋轉字型檔製作並豎直顯示文字

MiniGUI TTF旋轉字型檔製作並豎直顯示文字

一. 製作TTF旋轉字型檔

1.下載fontforge,可以在Ubuntu軟體中心下載

FontForge

2. 用該軟體開啟字型檔之後,按ctrl+a全選文字

全選文字

3.點選上面工具欄的基礎–>變換–>如圖設定

變換
需要注意的是

  1. 需要選擇字形原點,不能按選中部分的中心旋轉,不然會導致漢字與數字和英文顯示的高度不在同一水平線上,如果按選中部分的中心旋轉,第3步換成第4步
  2. 需要選擇順時針旋轉90度,如果逆時針旋轉90度的話,文字顯示會由“你好”變成“好你”,並且對齊方式是向右對齊,需要做一些額外的處理
  3. 需要選擇向Y軸移動220個單位,不同字型可能需要移動的數字不同,可以在MiniGUI中用TextOut函式設定y的值為0,看文字是否顯示在y為0的位置上,動態除錯
  4. 第2步旋轉之後,只選擇數字和英文,點選基礎–>變換,選擇字形原點,選擇向Y軸移動100個單位,之後點選尺寸–>設定左邊位,設定好數值,然後在MiniGUI中觀看效果,動態除錯
  5. 因為MiniGUI的TextOut,DrawText函式不支援豎直輸出文字,需要修改MiniGUI原始碼,使文字豎直輸出

這裡對上面的一些概念做一些說明,還沒有旋轉之前
概念描述
當按中心旋轉之後,左邊位變成-25,所以需要調整左邊位,不然數字與漢字顯示不在同一水平線上,因為漢字寬高都是256,所以漢字不需要調整左邊位
按中心旋轉
當按原點旋轉之後,Y軸距離變大了很多,所以需要向上移動一定的距離,不然文字顯示的時候會空出一些,因為是按原點旋轉,漢字與數字可以顯示在同一水平線上,因此可以不用改動左邊位,但是我們也可以看到,左邊位也是變小了,也可以根據需要修改
按原點旋轉

4.檔案–>生成字型–>TrueType

生成字型

二. MiniGUI豎直顯示文字

主要是把下一次輸出的x,y軸的座標對換就可以了,下面的補丁只是針對TTF文字順時針旋轉90度
需要注意的是DrawText與TabbedTextOut函式,檢測到/n的時候需要換行,因此需要把y +=改成ctxt.start_x -=
如果TTF文字是逆時針旋轉90度,需要把y +=改成ctxt.start_x +=

1. TextOut

修改libminigui-gpl-3.2/src/newgdi/textout.c

diff --git a/src/newgdi/textout.c b/src/newgdi/textout.
c index 2d5852c..2cbdd2f 100644 --- a/src/newgdi/textout.c +++ b/src/newgdi/textout.c @@ -127,8 +127,8 @@ static BOOL cb_draw_glyph (void* context, Glyph32 glyph_value, int glyph_type) ctxt->advance += DrawGlyph (ctxt->hdc, ctxt->x, ctxt->y, glyph_value, &adv_x, &adv_y); } - ctxt->x += adv_x; - ctxt->y += adv_y; + ctxt->x += adv_y; + ctxt->y += adv_x; return TRUE; } @@ -196,8 +196,8 @@ static BOOL cb_textout (void* context, Glyph32 glyph_value, int glyph_type) ctxt->x, ctxt->y, &adv_x, &adv_y); } - ctxt->x += adv_x; - ctxt->y += adv_y; + ctxt->x += adv_y; + ctxt->y += adv_x; return TRUE; } @@ -359,8 +359,8 @@ static BOOL cb_textout_omitted (void* context, Glyph32 glyph_value, int glyph_ty ctxt->x, ctxt->y, &adv_x, &adv_y); } - ctxt->x += adv_x; - ctxt->y += adv_y; + ctxt->x += adv_y; + ctxt->y += adv_x; return TRUE; }

2. DrawText

修改libminigui-gpl-3.2/src/newgdi/drawtext.c

diff --git a/src/newgdi/drawtext.c b/src/newgdi/drawtext.c
index 6f003b8..84ac576 100644
--- a/src/newgdi/drawtext.c
+++ b/src/newgdi/drawtext.c
@@ -370,8 +370,8 @@ static BOOL cb_drawtextex2 (void* context, Glyph32 glyph_value,
             break;
     }
 
-    ctxt->x += adv_x;
-    ctxt->y += adv_y;
+    ctxt->x += adv_y;
+    ctxt->y += adv_x;
 
     return TRUE;
 }
@@ -597,13 +597,13 @@ int DrawTextEx2 (HDC hdc, const char* pText, int nCount,
 
             line_len -= ctxt.nCount;
             pline  +=  ctxt.nCount;
-            y += ctxt.line_height;
+            ctxt.start_x -= ctxt.line_height;
             nLines ++;
         }
 
         /* continuous multiline '\n'.*/
         if ((nr_delim_newline-1) > 0){
-            y += ctxt.line_height * (nr_delim_newline-1);
+        	ctxt.start_x -= ctxt.line_height * (nr_delim_newline-1);
             nLines += (nr_delim_newline-1);
         }
 

3. TabbedTextOut

修改libminigui-gpl-3.2/src/newgdi/tabbedtextout.c

diff --git a/src/newgdi/tabbedtextout.c b/src/newgdi/tabbedtextout.c
index 245a947..c3f248f 100644
--- a/src/newgdi/tabbedtextout.c
+++ b/src/newgdi/tabbedtextout.c
@@ -168,8 +168,8 @@ static BOOL cb_tabbedtextout (void* context, Glyph32 glyph_value,
             break;
     }
 
-    ctxt->x += adv_x;
-    ctxt->y += adv_y;
+    ctxt->x += adv_y;
+    ctxt->y += adv_x;
 
     return TRUE;
 }
@@ -235,8 +235,8 @@ static BOOL cb_tabbedtextoutex (void* context, Glyph32 glyph_value,
             break;
     }
 
-    ctxt->x += adv_x;
-    ctxt->y += adv_y;
+    ctxt->x += adv_y;
+    ctxt->y += adv_x;
 
     return TRUE;
 }
@@ -270,6 +270,8 @@ int _gdi_tabbed_text_out (PDC pdc, int x, int y,
                 (const char*)text, len, '\n', &nr_delim_newline);
 
         ctxt.x = ctxt.start_x;
+    	/*If there is no ctxt.y = y, the y-axis distance is different when the line is changed.*/
+    	ctxt.y = y;
         ctxt.advance = 0;
 
         if(nr_delim_newline){
@@ -283,7 +285,7 @@ int _gdi_tabbed_text_out (PDC pdc, int x, int y,
             }
             len -= line_len + nr_delim_newline;
             text = text + line_len + nr_delim_newline;
-            ctxt.y += ctxt.line_height * nr_delim_newline;
+            ctxt.start_x -= ctxt.line_height * nr_delim_newline;
             ctxt.max_y = ctxt.y;
         }
         else{
@@ -297,7 +299,7 @@ int _gdi_tabbed_text_out (PDC pdc, int x, int y,
                 ctxt.max_advance = ctxt.advance;
                 ctxt.max_x = ctxt.x;
             }
-            ctxt.y += ctxt.line_height;
+            ctxt.start_x -= ctxt.line_height;
             ctxt.max_y = ctxt.y;
             break;
         }
@@ -425,6 +427,8 @@ int _gdi_tabbedex_text_out (PDC pdc, int x, int y,
                 (const char*)text, len, '\n', &nr_delim_newline);
 
         ctxt.x = ctxt.start_x;
+    	/*If there is no ctxt.y = y, the y-axis distance is different when the line is changed.*/
+    	ctxt.y = y;
         ctxt.advance = 0;
         /* reset the tab relative info for new line. */
         ctxt.nTabOrig = nTabOrig;
@@ -440,7 +444,7 @@ int _gdi_tabbedex_text_out (PDC pdc, int x, int y,
             }
             len -= line_len + nr_delim_newline;
             text = text + line_len + nr_delim_newline;
-            ctxt.y += ctxt.line_height * nr_delim_newline;
+            ctxt.start_x -= ctxt.line_height * nr_delim_newline;
         }
         else{
             /* output the final line. */