SVGHMI: fixed embedded fonts family name not matching when using windows version of inkscape svghmi
authorEdouard Tisserant
Wed, 31 Mar 2021 15:28:09 +0200
branchsvghmi
changeset 3215 da2481f359b7
parent 3212 2b5b3f4f26f0
child 3216 d6d002766a93
SVGHMI: fixed embedded fonts family name not matching when using windows version of inkscape
svghmi/fonts.py
--- a/svghmi/fonts.py	Tue Mar 30 14:56:04 2021 +0200
+++ b/svghmi/fonts.py	Wed Mar 31 15:28:09 2021 +0200
@@ -7,10 +7,15 @@
 # See COPYING file for copyrights details.
 
 from __future__ import print_function
+import sys
 from base64 import b64encode
 
 from fontTools import ttLib
 
+# Inkscape seems to refer to font with different family name depending on platform.
+# this are heuristics that would need extensive testing to be sure.
+FamilyNameIDs = [1] if sys.platform.startswith('win') else [1, 16]
+
 def GetFontTypeAndFamilyName(filename):
     """
     Getting font family, format and MIME type
@@ -24,7 +29,8 @@
     font = ttLib.TTFont(filename)
     # https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
     for name in font["name"].names:
-        if name.nameID in [1,16] and name.platformID==3 and name.langID==1033:
+        #print(name.nameID, name.platformID, name.langID, name.toUnicode())
+        if name.nameID in FamilyNameIDs and name.platformID==3 and name.langID==1033:
             familyname = name.toUnicode()
         if name.nameID==4 and name.platformID==3 and name.langID==1033:
             uniquename = name.toUnicode()