]> git.imager.perl.org - imager.git/commitdiff
modify the Freetype2 font code to pick it's own encoding rather than
authorTony Cook <tony@develop=help.com>
Wed, 9 Jan 2002 13:05:08 +0000 (13:05 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 9 Jan 2002 13:05:08 +0000 (13:05 +0000)
using whatever strange translation FT2 happens to pick

Changes
freetyp2.c
t/t38ft2font.t

diff --git a/Changes b/Changes
index f0db98cf3f34595f8adf7393b3dec69353a70f58..ed7dd807059ded5625b7a09f477072b4e00ffa5f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -578,6 +578,9 @@ Revision history for Perl extension Imager.
         - read/write multi-image tiff files
         - tests in t50basicoo.t for multi-image/file
         - ASCII PBM files were reading white as dark gray (255 vs 1)
+        - modify the Freetype2 font code to pick it's own encoding
+          rather than using whatever strange translation FT2 happens to 
+          pick
 
 =================================================================
 
index e155d5258e9392a5a678012e07e5e593d1fbc683..a7c1528ec8cac077bb1df5a8a406045020cb12e3 100644 (file)
@@ -71,11 +71,33 @@ struct FT2_Fonthandle {
   FT_Face face;
   int xdpi, ydpi;
   int hint;
+  FT_Encoding encoding;
 
   /* used to adjust so we can align the draw point to the top-left */
   double matrix[6];
 };
 
+/* the following is used to select a "best" encoding */
+static struct enc_score {
+  FT_Encoding encoding;
+  int score;
+} enc_scores[] =
+{
+  /* the selections here are fairly arbitrary
+     ideally we need to give the user a list of encodings available
+     and a mechanism to choose one */
+  { ft_encoding_unicode,        10 },
+  { ft_encoding_sjis,            8 },
+  { ft_encoding_gb2312,          8 },
+  { ft_encoding_big5,            8 },
+  { ft_encoding_wansung,         8 },
+  { ft_encoding_johab,           8 },  
+  { ft_encoding_latin_2,         6 },
+  { ft_encoding_apple_roman,     6 },
+  { ft_encoding_adobe_standard,  6 },
+  { ft_encoding_adobe_expert,    6 },
+};
+
 /*
 =item i_ft2_new(char *name, int index)
 
@@ -95,6 +117,9 @@ i_ft2_new(char *name, int index) {
   FT_Face face;
   double matrix[6] = { 1, 0, 0,
                        0, 1, 0 };
+  int i, j;
+  FT_Encoding encoding;
+  int score;
 
   mm_log((1, "i_ft2_new(name %p, index %d)\n", name, index));
 
@@ -106,9 +131,28 @@ i_ft2_new(char *name, int index) {
     return NULL;
   }
 
+  encoding = face->num_charmaps ? face->charmaps[0]->encoding : ft_encoding_unicode;
+  score = 0;
+  for (i = 0; i < face->num_charmaps; ++i) {
+    FT_Encoding enc_entry = face->charmaps[i]->encoding;
+    mm_log((2, "i_ft2_new, encoding %lX platform %u encoding %u\n",
+            enc_entry, face->charmaps[i]->platform_id,
+            face->charmaps[i]->encoding_id));
+    for (j = 0; j < sizeof(enc_scores) / sizeof(*enc_scores); ++j) {
+      if (enc_scores[j].encoding == enc_entry && enc_scores[j].score > score) {
+        encoding = enc_entry;
+        score = enc_scores[j].score;
+        break;
+      }
+    }
+  }
+  FT_Select_Charmap(face, encoding);
+  mm_log((2, "i_ft2_new, selected encoding %lX\n", encoding));
+
   result = mymalloc(sizeof(FT2_Fonthandle));
   result->face = face;
   result->xdpi = result->ydpi = 72;
+  result->encoding = encoding;
 
   /* by default we disable hinting on a call to i_ft2_settransform()
      if we don't do this, then the hinting can the untransformed text
index 81cd4abafa18f91dfe4f29ba4cd762990a87e783..6b04ed242e0a7fdc31d0c31fcb936f2bef8fa671 100644 (file)
@@ -13,7 +13,7 @@ use Imager qw(:all);
 $loaded = 1;
 print "ok 1\n";
 
-init_log("testout/t38ft2font.log",1);
+init_log("testout/t38ft2font.log",2);
 
 sub skip { 
   for (2..14) {