# HG changeset patch # User Edouard Tisserant # Date 1617197289 -7200 # Node ID da2481f359b7da6f5470b1ad617dd30d4a96cc3b # Parent 2b5b3f4f26f0c6905a8c4a6880fcd7adad2f94b6 SVGHMI: fixed embedded fonts family name not matching when using windows version of inkscape diff -r 2b5b3f4f26f0 -r da2481f359b7 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()