summarylogtreecommitdiffstats
path: root/0002-allow-ISO-646.1991-IRV-as-well-adobe-standard-for-bd.patch
blob: 2a4e0875de9604d5f61178c2f23697fc1baa0825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
From 07230480293018e2f5a7fa7c2ddb7aaebd567897 Mon Sep 17 00:00:00 2001
From: Ryan Farley <ryan.farley@gmx.com>
Date: Sat, 31 Aug 2019 06:42:24 -0500
Subject: [PATCH app/fonttosfnt 2/2] allow ISO-646.1991-IRV as well, adobe
 standard for bdf

Allow for BDF file with no specified encoding to be read as Adobe
Standard (per freetype's BDF driver), and handle any Unicode-equivalent
encoding without changing the encoding name.
---
 read.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/read.c b/read.c
index 5e80cc5..05f7b4f 100644
--- a/read.c
+++ b/read.c
@@ -64,6 +64,7 @@ readFile(char *filename, FontPtr font)
     StrikePtr strike;
     BitmapPtr bitmap;
     int symbol = 0;
+    int force_unicode = 1;
     char *encoding_name = NULL;
     FontMapPtr mapping = NULL;
     FontMapReversePtr reverse = NULL;
@@ -79,13 +80,20 @@ readFile(char *filename, FontPtr font)
         return -1;
     }
 
-    /* FreeType will handle Unicode and automatically map ISO-8859-1 to
-     * Unicode for us -- everything else needs a mapping */
+    /* FreeType will insist on encodings which are simple subsets of unicode
+     * to be read as unicode regardless of what we call them. */
+    for(j = 0; j < face->num_charmaps; ++j) {
+        if((face->charmaps[j]->encoding == ft_encoding_none) ||
+           (face->charmaps[j]->encoding == ft_encoding_adobe_standard)) {
+            force_unicode = 0;
+            break;
+        }
+    }
+
     encoding_name = faceEncoding(face);
     if(encoding_name == NULL) {
         symbol = 1;
-    } else if((strcasecmp(encoding_name, "iso10646-1") != 0) &&
-              (strcasecmp(encoding_name, "iso8859-1") != 0)) {
+    } else if(strcasecmp(encoding_name, "iso10646-1") != 0) {
         if(reencode_flag)
             mapping = FontEncMapFind(encoding_name,
                                      FONT_ENCODING_UNICODE, 0, 0, NULL);
@@ -228,10 +236,16 @@ readFile(char *filename, FontPtr font)
         return -1;
     }
 
-    if(!symbol && !mapping)
+    if((!symbol && !mapping) || force_unicode) {
         rc = FT_Select_Charmap(face, ft_encoding_unicode);
-    else
+    } else {
         rc = FT_Select_Charmap(face, ft_encoding_none);
+        if(rc != 0) {
+            /* BDF will default to Adobe Standard even for nonstandard
+             * encodings, so try that as a last resort. */
+            rc = FT_Select_Charmap(face, ft_encoding_adobe_standard);
+        }
+    }
     if(rc != 0) {
         fprintf(stderr, "Couldn't select character map: %x.\n", rc);
         return -1;
-- 
2.23.0