Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SFNT Table support #199

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions freetype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,32 @@ def set_var_named_instance(self, instance_name):

# named instance not found; do nothing

def get_sfnt_table(self, tag: int):
'''
Get the SFNT table specified by the tag (see `ft_enums/ft_sfnt_tags.py`).

**Note**

The return value will be invalid once the face has deleted.
'''
if tag < 0 or tag >= FT_SFNT_MAX:
raise ValueError(f"SFNT tag out of range 0..{FT_SFNT_MAX - 1}.")
if not self.is_sfnt:
raise RuntimeError("This font has no SFNT data.")
res = FT_Get_Sfnt_Table(self._FT_Face, tag)
if res is None:
return None
_sfnt_table_cast = {
ft_sfnt_head: TT_Header,
ft_sfnt_maxp: TT_MaxProfile,
ft_sfnt_os2: TT_OS2,
ft_sfnt_hhea: TT_HoriHeader,
ft_sfnt_vhea: TT_VertHeader,
ft_sfnt_post: TT_Postscript,
ft_sfnt_pclt: TT_PCLT,
}
return cast(c_void_p(res), POINTER(_sfnt_table_cast[tag])).contents

def _get_postscript_name( self ):
return FT_Get_Postscript_Name( self._FT_Face )
postscript_name = property( _get_postscript_name,
Expand Down
1 change: 1 addition & 0 deletions freetype/ft_enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
from freetype.ft_enums.ft_outline_flags import *
from freetype.ft_enums.ft_pixel_modes import *
from freetype.ft_enums.ft_render_modes import *
from freetype.ft_enums.ft_sfnt_tags import *
from freetype.ft_enums.ft_stroker_borders import *
from freetype.ft_enums.ft_stroker_linecaps import *
from freetype.ft_enums.ft_stroker_linejoins import *
Expand Down
19 changes: 19 additions & 0 deletions freetype/ft_enums/ft_sfnt_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FT_SFNT_TAGS = {
'FT_SFNT_HEAD' : 0,
'FT_SFNT_MAXP' : 1,
'FT_SFNT_OS2' : 2,
'FT_SFNT_HHEA' : 3,
'FT_SFNT_VHEA' : 4,
'FT_SFNT_POST' : 5,
'FT_SFNT_PCLT' : 6,
}
FT_SFNT_MAX = len(FT_SFNT_TAGS)
# get value from dict indirectly to avoid complains from static checkers
ft_sfnt_head = FT_SFNT_TAGS['FT_SFNT_HEAD']
ft_sfnt_maxp = FT_SFNT_TAGS['FT_SFNT_MAXP']
ft_sfnt_os2 = FT_SFNT_TAGS['FT_SFNT_OS2']
ft_sfnt_hhea = FT_SFNT_TAGS['FT_SFNT_HHEA']
ft_sfnt_vhea = FT_SFNT_TAGS['FT_SFNT_VHEA']
ft_sfnt_post = FT_SFNT_TAGS['FT_SFNT_POST']
ft_sfnt_pclt = FT_SFNT_TAGS['FT_SFNT_PCLT']
globals().update(FT_SFNT_TAGS)
Loading
Loading