[haiku-development] [PATCH][app_server][font] Display Chinese

  • From: "Anthony Lee" <don.anthony.lee@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 31 Dec 2007 14:11:32 +0800

Hi,

With the patch, now Haiku can display chinese well.
You can find GPL'd CJK font on "http://sourceforge.net/projects/wqy";

The patch and screenshot attached to this mail.


A.L.

Attachment: screen1.png
Description: PNG image

Index: src/servers/app/FontEngine.cpp
===================================================================
--- src/servers/app/FontEngine.cpp      (revision 23185)
+++ src/servers/app/FontEngine.cpp      (working copy)
@@ -421,47 +421,50 @@
 
        switch(fGlyphRendering) {
                case glyph_ren_native_mono:
-                       fLastError = FT_Render_Glyph(fFace->glyph, 
FT_RENDER_MODE_MONO);
+               case glyph_ren_native_gray8:
+                       fLastError = FT_Render_Glyph(fFace->glyph,
+                                                    fGlyphRendering == 
glyph_ren_native_mono ?
+                                                       FT_RENDER_MODE_MONO : 
FT_RENDER_MODE_NORMAL);
                        if (fLastError == 0) {
-                               decompose_ft_bitmap_mono(fFace->glyph->bitmap, 
+                               switch (fFace->glyph->bitmap.pixel_mode) {
+                                       case FT_PIXEL_MODE_MONO:
+                                               
decompose_ft_bitmap_mono(fFace->glyph->bitmap, 
                                                                                
 fFace->glyph->bitmap_left,
                                                                                
 kFlipY ? -fFace->glyph->bitmap_top : 
                                                                                
                         fFace->glyph->bitmap_top,
                                                                                
 kFlipY,
                                                                                
 fScanlineBin,
                                                                                
 fScanlineStorageBin);
-                               fBounds.x1 = fScanlineStorageBin.min_x();
-                               fBounds.y1 = fScanlineStorageBin.min_y();
-                               fBounds.x2 = fScanlineStorageBin.max_x();
-                               fBounds.y2 = fScanlineStorageBin.max_y();
-                               fDataSize = fScanlineStorageBin.byte_size(); 
-                               fDataType = glyph_data_mono;
-                               return true;
-                       }
-                       break;
-       
-       
-               case glyph_ren_native_gray8:
-                       fLastError = FT_Render_Glyph(fFace->glyph, 
FT_RENDER_MODE_NORMAL);
-                       if (fLastError == 0) {
-                               decompose_ft_bitmap_gray8(fFace->glyph->bitmap, 
+                                               fBounds.x1 = 
fScanlineStorageBin.min_x();
+                                               fBounds.y1 = 
fScanlineStorageBin.min_y();
+                                               fBounds.x2 = 
fScanlineStorageBin.max_x();
+                                               fBounds.y2 = 
fScanlineStorageBin.max_y();
+                                               fDataSize = 
fScanlineStorageBin.byte_size(); 
+                                               fDataType = glyph_data_mono;
+                                               return true;
+
+                                       case FT_PIXEL_MODE_GRAY:
+                                               
decompose_ft_bitmap_gray8(fFace->glyph->bitmap, 
                                                                                
  fFace->glyph->bitmap_left,
                                                                                
  kFlipY ? -fFace->glyph->bitmap_top : 
                                                                                
                          fFace->glyph->bitmap_top,
                                                                                
  kFlipY,
                                                                                
  fScanlineAA,
                                                                                
  fScanlineStorageAA);
-                               fBounds.x1 = fScanlineStorageAA.min_x();
-                               fBounds.y1 = fScanlineStorageAA.min_y();
-                               fBounds.x2 = fScanlineStorageAA.max_x();
-                               fBounds.y2 = fScanlineStorageAA.max_y();
-                               fDataSize = fScanlineStorageAA.byte_size(); 
-                               fDataType = glyph_data_gray8;
-                               return true;
+                                               fBounds.x1 = 
fScanlineStorageAA.min_x();
+                                               fBounds.y1 = 
fScanlineStorageAA.min_y();
+                                               fBounds.x2 = 
fScanlineStorageAA.max_x();
+                                               fBounds.y2 = 
fScanlineStorageAA.max_y();
+                                               fDataSize = 
fScanlineStorageAA.byte_size(); 
+                                               fDataType = glyph_data_gray8;
+                                               return true;
+
+                                       default:
+                                               break;
+                               }
                        }
                        break;
-       
-       
+
                case glyph_ren_outline:
                        fPath.remove_all();
                        if (decompose_ft_outline(fFace->glyph->outline, kFlipY,
@@ -583,8 +586,12 @@
                unsigned(size * 64.0) >> 6,     // pixel_width
                unsigned(size * 64.0) >> 6);  // pixel_height
 
-       if (charMap != FT_ENCODING_NONE)
+       if (charMap != FT_ENCODING_NONE) {
                fLastError = FT_Select_Charmap(fFace, charMap);
+       } else {
+               if (FT_Select_Charmap(fFace, FT_ENCODING_UNICODE) != 0)
+                       fLastError = FT_Select_Charmap(fFace, FT_ENCODING_NONE);
+       }
 
        return fLastError == 0;
 }

Other related posts: