svghmi/fonts.py
branchsvghmi
changeset 3215 da2481f359b7
parent 3211 938b55abe946
child 3933 6750083ae878
equal deleted inserted replaced
3212:2b5b3f4f26f0 3215:da2481f359b7
     5 # Copyright (C) 2021: Edouard TISSERANT
     5 # Copyright (C) 2021: Edouard TISSERANT
     6 #
     6 #
     7 # See COPYING file for copyrights details.
     7 # See COPYING file for copyrights details.
     8 
     8 
     9 from __future__ import print_function
     9 from __future__ import print_function
       
    10 import sys
    10 from base64 import b64encode
    11 from base64 import b64encode
    11 
    12 
    12 from fontTools import ttLib
    13 from fontTools import ttLib
       
    14 
       
    15 # Inkscape seems to refer to font with different family name depending on platform.
       
    16 # this are heuristics that would need extensive testing to be sure.
       
    17 FamilyNameIDs = [1] if sys.platform.startswith('win') else [1, 16]
    13 
    18 
    14 def GetFontTypeAndFamilyName(filename):
    19 def GetFontTypeAndFamilyName(filename):
    15     """
    20     """
    16     Getting font family, format and MIME type
    21     Getting font family, format and MIME type
    17     """
    22     """
    22     mimetype = None
    27     mimetype = None
    23 
    28 
    24     font = ttLib.TTFont(filename)
    29     font = ttLib.TTFont(filename)
    25     # https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
    30     # https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
    26     for name in font["name"].names:
    31     for name in font["name"].names:
    27         if name.nameID in [1,16] and name.platformID==3 and name.langID==1033:
    32         #print(name.nameID, name.platformID, name.langID, name.toUnicode())
       
    33         if name.nameID in FamilyNameIDs and name.platformID==3 and name.langID==1033:
    28             familyname = name.toUnicode()
    34             familyname = name.toUnicode()
    29         if name.nameID==4 and name.platformID==3 and name.langID==1033:
    35         if name.nameID==4 and name.platformID==3 and name.langID==1033:
    30             uniquename = name.toUnicode()
    36             uniquename = name.toUnicode()
    31 
    37 
    32     if font.flavor :
    38     if font.flavor :