Start work on rendering fonts using FreeType

This commit is contained in:
Kovid Goyal 2016-10-23 23:12:00 +05:30
parent 6f81e12041
commit 6a23dbe1ec
37 changed files with 6064 additions and 19 deletions

1910
freetype/__init__.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
'''
Freetype enum types
-------------------
FT_PIXEL_MODES: An enumeration type used to describe the format of pixels in a
given bitmap. Note that additional formats may be added in the
future.
FT_GLYPH_BBOX_MODES: The mode how the values of FT_Glyph_Get_CBox are returned.
FT_GLYPH_FORMATS: An enumeration type used to describe the format of a given
glyph image. Note that this version of FreeType only supports
two image formats, even though future font drivers will be
able to register their own format.
FT_ENCODINGS: An enumeration used to specify character sets supported by
charmaps. Used in the FT_Select_Charmap API function.
FT_RENDER_MODES: An enumeration type that lists the render modes supported by
FreeType 2. Each mode corresponds to a specific type of
scanline conversion performed on the outline.
FT_LOAD_TARGETS: A list of values that are used to select a specific hinting
algorithm to use by the hinter. You should OR one of these
values to your 'load_flags' when calling FT_Load_Glyph.
FT_LOAD_FLAGS: A list of bit-field constants used with FT_Load_Glyph to
indicate what kind of operations to perform during glyph
loading.
FT_STYLE_FLAGS: A list of bit-flags used to indicate the style of a given
face. These are used in the 'style_flags' field of FT_FaceRec.
FT_FSTYPES: A list of bit flags that inform client applications of embedding
and subsetting restrictions associated with a font.
FT_FACE_FLAGS: A list of bit flags used in the 'face_flags' field of the
FT_FaceRec structure. They inform client applications of
properties of the corresponding face.
FT_OUTLINE_FLAGS: A list of bit-field constants use for the flags in an
outline's 'flags' field.
FT_OPEN_MODES: A list of bit-field constants used within the 'flags' field of
the FT_Open_Args structure.
FT_KERNING_MODES: An enumeration used to specify which kerning values to return
in FT_Get_Kerning.
FT_STROKER_LINEJOINS: These values determine how two joining lines are rendered
in a stroker.
FT_STROKER_LINECAPS: These values determine how the end of opened sub-paths are
rendered in a stroke.
FT_STROKER_BORDERS: These values are used to select a given stroke border in
FT_Stroker_GetBorderCounts and FT_Stroker_ExportBorder.
FT_LCD_FILTERS: A list of values to identify various types of LCD filters.
TT_PLATFORMS: A list of valid values for the 'platform_id' identifier code in
FT_CharMapRec and FT_SfntName structures.
TT_APPLE_IDS: A list of valid values for the 'encoding_id' for
TT_PLATFORM_APPLE_UNICODE charmaps and name entries.
TT_MAC_IDS: A list of valid values for the 'encoding_id' for
TT_PLATFORM_MACINTOSH charmaps and name entries.
TT_MS_IDS: A list of valid values for the 'encoding_id' for
TT_PLATFORM_MICROSOFT charmaps and name entries.
TT_ADOBE_IDS: A list of valid values for the 'encoding_id' for
TT_PLATFORM_ADOBE charmaps. This is a FreeType-specific
extension!
TT_MAC_LANGIDS: Possible values of the language identifier field in the name
records of the TTF `name' table if the `platform' identifier
code is TT_PLATFORM_MACINTOSH.
TT_MS_LANGIDS: Possible values of the language identifier field in the name
records of the TTF `name' table if the `platform' identifier
code is TT_PLATFORM_MICROSOFT.
TT_NAME_IDS: Possible values of the `name' identifier field in the name
records of the TTF `name' table. These values are platform
independent.
'''
from freetype.ft_enums.ft_fstypes import *
from freetype.ft_enums.ft_face_flags import *
from freetype.ft_enums.ft_encodings import *
from freetype.ft_enums.ft_glyph_bbox_modes import *
from freetype.ft_enums.ft_glyph_formats import *
from freetype.ft_enums.ft_kerning_modes import *
from freetype.ft_enums.ft_lcd_filters import *
from freetype.ft_enums.ft_load_flags import *
from freetype.ft_enums.ft_load_targets import *
from freetype.ft_enums.ft_open_modes import *
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_stroker_borders import *
from freetype.ft_enums.ft_stroker_linecaps import *
from freetype.ft_enums.ft_stroker_linejoins import *
from freetype.ft_enums.ft_style_flags import *
from freetype.ft_enums.tt_adobe_ids import *
from freetype.ft_enums.tt_apple_ids import *
from freetype.ft_enums.tt_mac_ids import *
from freetype.ft_enums.tt_ms_ids import *
from freetype.ft_enums.tt_ms_langids import *
from freetype.ft_enums.tt_mac_langids import *
from freetype.ft_enums.tt_name_ids import *
from freetype.ft_enums.tt_platforms import *

View File

@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
An enumeration used to specify character sets supported by charmaps. Used in
the FT_Select_Charmap API function.
FT_ENCODING_NONE
The encoding value 0 is reserved.
FT_ENCODING_UNICODE
Corresponds to the Unicode character set. This value covers all versions of
the Unicode repertoire, including ASCII and Latin-1. Most fonts include a
Unicode charmap, but not all of them.
For example, if you want to access Unicode value U+1F028 (and the font
contains it), use value 0x1F028 as the input value for FT_Get_Char_Index.
FT_ENCODING_MS_SYMBOL
Corresponds to the Microsoft Symbol encoding, used to encode mathematical
symbols in the 32..255 character code range. For more information, see
'http://www.ceviz.net/symbol.htm'.
FT_ENCODING_SJIS
Corresponds to Japanese SJIS encoding. More info at at
'http://langsupport.japanreference.com/encoding.shtml'. See note on
multi-byte encodings below.
FT_ENCODING_GB2312
Corresponds to an encoding system for Simplified Chinese as used used in
mainland China.
FT_ENCODING_BIG5
Corresponds to an encoding system for Traditional Chinese as used in Taiwan
and Hong Kong.
FT_ENCODING_WANSUNG
Corresponds to the Korean encoding system known as Wansung. For more
information see 'http://www.microsoft.com/typography/unicode/949.txt'.
FT_ENCODING_JOHAB
The Korean standard character set (KS C 5601-1992), which corresponds to MS
Windows code page 1361. This character set includes all possible Hangeul
character combinations.
FT_ENCODING_ADOBE_LATIN_1
Corresponds to a Latin-1 encoding as defined in a Type 1 PostScript font. It
is limited to 256 character codes.
FT_ENCODING_ADOBE_STANDARD
Corresponds to the Adobe Standard encoding, as found in Type 1, CFF, and
OpenType/CFF fonts. It is limited to 256 character codes.
FT_ENCODING_ADOBE_EXPERT
Corresponds to the Adobe Expert encoding, as found in Type 1, CFF, and
OpenType/CFF fonts. It is limited to 256 character codes.
FT_ENCODING_ADOBE_CUSTOM
Corresponds to a custom encoding, as found in Type 1, CFF, and OpenType/CFF
fonts. It is limited to 256 character codes.
FT_ENCODING_APPLE_ROMAN
Corresponds to the 8-bit Apple roman encoding. Many TrueType and OpenType
fonts contain a charmap for this encoding, since older versions of Mac OS are
able to use it.
FT_ENCODING_OLD_LATIN_2
This value is deprecated and was never used nor reported by FreeType. Don't
use or test for it.
"""
def _FT_ENC_TAG(a,b,c,d):
return ( ord(a) << 24 | ord(b) << 16 | ord(c) << 8 | ord(d) )
FT_ENCODINGS = {'FT_ENCODING_NONE' : _FT_ENC_TAG('\0','\0','\0','\0'),
'FT_ENCODING_MS_SYMBOL' : _FT_ENC_TAG( 's','y','m','b' ),
'FT_ENCODING_UNICODE' : _FT_ENC_TAG( 'u','n','i','c' ),
'FT_ENCODING_SJIS' : _FT_ENC_TAG( 's','j','i','s' ),
'FT_ENCODING_GB2312' : _FT_ENC_TAG( 'g','b',' ',' ' ),
'FT_ENCODING_BIG5' : _FT_ENC_TAG( 'b','i','g','5' ),
'FT_ENCODING_WANSUNG' : _FT_ENC_TAG( 'w','a','n','s' ),
'FT_ENCODING_JOHAB' : _FT_ENC_TAG( 'j','o','h','a' ),
'FT_ENCODING_ADOBE_STANDARD' : _FT_ENC_TAG( 'A','D','O','B' ),
'FT_ENCODING_ADOBE_EXPERT' : _FT_ENC_TAG( 'A','D','B','E' ),
'FT_ENCODING_ADOBE_CUSTOM' : _FT_ENC_TAG( 'A','D','B','C' ),
'FT_ENCODING_ADOBE_LATIN1' : _FT_ENC_TAG( 'l','a','t','1' ),
'FT_ENCODING_OLD_LATIN2' : _FT_ENC_TAG( 'l','a','t','2' ),
'FT_ENCODING_APPLE_ROMAN' : _FT_ENC_TAG( 'a','r','m','n' ) }
globals().update(FT_ENCODINGS)

View File

@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit flags used in the 'face_flags' field of the FT_FaceRec
structure. They inform client applications of properties of the corresponding
face.
FT_FACE_FLAG_SCALABLE
Indicates that the face contains outline glyphs. This doesn't prevent bitmap
strikes, i.e., a face can have both this and and FT_FACE_FLAG_FIXED_SIZES
set.
FT_FACE_FLAG_FIXED_SIZES
Indicates that the face contains bitmap strikes. See also the
'num_fixed_sizes' and 'available_sizes' fields of FT_FaceRec.
FT_FACE_FLAG_FIXED_WIDTH
Indicates that the face contains fixed-width characters (like Courier,
Lucido, MonoType, etc.).
FT_FACE_FLAG_SFNT
Indicates that the face uses the 'sfnt' storage scheme. For now, this means
TrueType and OpenType.
FT_FACE_FLAG_HORIZONTAL
Indicates that the face contains horizontal glyph metrics. This should be set
for all common formats.
FT_FACE_FLAG_VERTICAL
Indicates that the face contains vertical glyph metrics. This is only
available in some formats, not all of them.
FT_FACE_FLAG_KERNING
Indicates that the face contains kerning information. If set, the kerning
distance can be retrieved through the function FT_Get_Kerning. Otherwise the
function always return the vector (0,0). Note that FreeType doesn't handle
kerning data from the 'GPOS' table (as present in some OpenType fonts).
FT_FACE_FLAG_MULTIPLE_MASTERS
Indicates that the font contains multiple masters and is capable of
interpolating between them. See the multiple-masters specific API for
details.
FT_FACE_FLAG_GLYPH_NAMES
Indicates that the font contains glyph names that can be retrieved through
FT_Get_Glyph_Name. Note that some TrueType fonts contain broken glyph name
tables. Use the function FT_Has_PS_Glyph_Names when needed.
FT_FACE_FLAG_EXTERNAL_STREAM
Used internally by FreeType to indicate that a face's stream was provided by
the client application and should not be destroyed when FT_Done_Face is
called. Don't read or test this flag.
FT_FACE_FLAG_HINTER
Set if the font driver has a hinting machine of its own. For example, with
TrueType fonts, it makes sense to use data from the SFNT 'gasp' table only if
the native TrueType hinting engine (with the bytecode interpreter) is
available and active.
FT_FACE_FLAG_CID_KEYED
Set if the font is CID-keyed. In that case, the font is not accessed by glyph
indices but by CID values. For subsetted CID-keyed fonts this has the
consequence that not all index values are a valid argument to
FT_Load_Glyph. Only the CID values for which corresponding glyphs in the
subsetted font exist make FT_Load_Glyph return successfully; in all other
cases you get an 'FT_Err_Invalid_Argument' error.
Note that CID-keyed fonts which are in an SFNT wrapper don't have this flag
set since the glyphs are accessed in the normal way (using contiguous
indices); the 'CID-ness' isn't visible to the application.
FT_FACE_FLAG_TRICKY
Set if the font is 'tricky', this is, it always needs the font format's
native hinting engine to get a reasonable result. A typical example is the
Chinese font 'mingli.ttf' which uses TrueType bytecode instructions to move
and scale all of its subglyphs.
It is not possible to autohint such fonts using FT_LOAD_FORCE_AUTOHINT; it
will also ignore FT_LOAD_NO_HINTING. You have to set both FT_LOAD_NO_HINTING
and FT_LOAD_NO_AUTOHINT to really disable hinting; however, you probably
never want this except for demonstration purposes.
Currently, there are six TrueType fonts in the list of tricky fonts; they are
hard-coded in file 'ttobjs.c'.
"""
FT_FACE_FLAGS = { 'FT_FACE_FLAG_SCALABLE' : 1 << 0,
'FT_FACE_FLAG_FIXED_SIZES' : 1 << 1,
'FT_FACE_FLAG_FIXED_WIDTH' : 1 << 2,
'FT_FACE_FLAG_SFNT' : 1 << 3,
'FT_FACE_FLAG_HORIZONTAL' : 1 << 4,
'FT_FACE_FLAG_VERTICAL' : 1 << 5,
'FT_FACE_FLAG_KERNING' : 1 << 6,
'FT_FACE_FLAG_FAST_GLYPHS' : 1 << 7,
'FT_FACE_FLAG_MULTIPLE_MASTERS' : 1 << 8,
'FT_FACE_FLAG_GLYPH_NAMES' : 1 << 9,
'FT_FACE_FLAG_EXTERNAL_STREAM' : 1 << 10,
'FT_FACE_FLAG_HINTER' : 1 << 11,
'FT_FACE_FLAG_CID_KEYED' : 1 << 12,
'FT_FACE_FLAG_TRICKY' : 1 << 13
}
globals().update(FT_FACE_FLAGS)

View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit flags that inform client applications of embedding and
subsetting restrictions associated with a font.
FT_FSTYPE_INSTALLABLE_EMBEDDING
Fonts with no fsType bit set may be embedded and permanently installed on
the remote system by an application.
FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING
Fonts that have only this bit set must not be modified, embedded or exchanged
in any manner without first obtaining permission of the font software
copyright owner.
FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING
If this bit is set, the font may be embedded and temporarily loaded on the
remote system. Documents containing Preview & Print fonts must be opened
'read-only'; no edits can be applied to the document.
FT_FSTYPE_EDITABLE_EMBEDDING
If this bit is set, the font may be embedded but must only be installed
temporarily on other systems. In contrast to Preview & Print fonts,
documents containing editable fonts may be opened for reading, editing is
permitted, and changes may be saved.
FT_FSTYPE_NO_SUBSETTING
If this bit is set, the font may not be subsetted prior to embedding.
FT_FSTYPE_BITMAP_EMBEDDING_ONLY
If this bit is set, only bitmaps contained in the font may be embedded; no
outline data may be embedded. If there are no bitmaps available in the font,
then the font is unembeddable.
"""
FT_FSTYPES = {'FT_FSTYPE_INSTALLABLE_EMBEDDING' : 0x0000,
'FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING' : 0x0002,
'FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING' : 0x0004,
'FT_FSTYPE_EDITABLE_EMBEDDING' : 0x0008,
'FT_FSTYPE_NO_SUBSETTING' : 0x0100,
'FT_FSTYPE_BITMAP_EMBEDDING_ONLY' : 0x0200,}
globals().update(FT_FSTYPES)
ft_fstype_installable_embedding = FT_FSTYPE_INSTALLABLE_EMBEDDING
ft_fstype_restricted_license_embedding = FT_FSTYPE_RESTRICTED_LICENSE_EMBEDDING
ft_fstype_preview_and_print_embedding = FT_FSTYPE_PREVIEW_AND_PRINT_EMBEDDING
ft_fstype_editable_embedding = FT_FSTYPE_EDITABLE_EMBEDDING
ft_fstype_no_subsetting = FT_FSTYPE_NO_SUBSETTING
ft_fstype_bitmap_embedding_only = FT_FSTYPE_BITMAP_EMBEDDING_ONLY

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
The mode how the values of FT_Glyph_Get_CBox are returned.
FT_GLYPH_BBOX_UNSCALED
Return unscaled font units.
FT_GLYPH_BBOX_SUBPIXELS
Return unfitted 26.6 coordinates.
FT_GLYPH_BBOX_GRIDFIT
Return grid-fitted 26.6 coordinates.
FT_GLYPH_BBOX_TRUNCATE
Return coordinates in integer pixels.
FT_GLYPH_BBOX_PIXELS
Return grid-fitted pixel coordinates.
"""
FT_GLYPH_BBOX_MODES = {'FT_GLYPH_BBOX_UNSCALED' : 0,
'FT_GLYPH_BBOX_SUBPIXELS' : 0,
'FT_GLYPH_BBOX_GRIDFIT' : 1,
'FT_GLYPH_BBOX_TRUNCATE' : 2,
'FT_GLYPH_BBOX_PIXELS' : 3}
globals().update(FT_GLYPH_BBOX_MODES)

View File

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
An enumeration type used to describe the format of a given glyph image. Note
that this version of FreeType only supports two image formats, even though
future font drivers will be able to register their own format.
FT_GLYPH_FORMAT_NONE
The value 0 is reserved.
FT_GLYPH_FORMAT_COMPOSITE
The glyph image is a composite of several other images. This format is only
used with FT_LOAD_NO_RECURSE, and is used to report compound glyphs (like
accented characters).
FT_GLYPH_FORMAT_BITMAP
The glyph image is a bitmap, and can be described as an FT_Bitmap. You
generally need to access the 'bitmap' field of the FT_GlyphSlotRec structure
to read it.
FT_GLYPH_FORMAT_OUTLINE
The glyph image is a vectorial outline made of line segments and Bezier arcs;
it can be described as an FT_Outline; you generally want to access the
'outline' field of the FT_GlyphSlotRec structure to read it.
FT_GLYPH_FORMAT_PLOTTER
The glyph image is a vectorial path with no inside and outside contours. Some
Type 1 fonts, like those in the Hershey family, contain glyphs in this
format. These are described as FT_Outline, but FreeType isn't currently
capable of rendering them correctly.
"""
def _FT_IMAGE_TAG(a,b,c,d):
return ( ord(a) << 24 | ord(b) << 16 | ord(c) << 8 | ord(d) )
FT_GLYPH_FORMATS = {
'FT_GLYPH_FORMAT_NONE' : _FT_IMAGE_TAG( '\0','\0','\0','\0' ),
'FT_GLYPH_FORMAT_COMPOSITE' : _FT_IMAGE_TAG( 'c','o','m','p' ),
'FT_GLYPH_FORMAT_BITMAP' : _FT_IMAGE_TAG( 'b','i','t','s' ),
'FT_GLYPH_FORMAT_OUTLINE' : _FT_IMAGE_TAG( 'o','u','t','l' ),
'FT_GLYPH_FORMAT_PLOTTER' : _FT_IMAGE_TAG( 'p','l','o','t' )}
globals().update(FT_GLYPH_FORMATS)
ft_glyph_format_none = FT_GLYPH_FORMAT_NONE
ft_glyph_format_composite = FT_GLYPH_FORMAT_COMPOSITE
ft_glyph_format_bitmap = FT_GLYPH_FORMAT_BITMAP
ft_glyph_format_outline = FT_GLYPH_FORMAT_OUTLINE
ft_glyph_format_plotter = FT_GLYPH_FORMAT_PLOTTER

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
An enumeration used to specify which kerning values to return in
FT_Get_Kerning.
FT_KERNING_DEFAULT
Return scaled and grid-fitted kerning distances (value is 0).
FT_KERNING_UNFITTED
Return scaled but un-grid-fitted kerning distances.
FT_KERNING_UNSCALED
Return the kerning vector in original font units.
"""
FT_KERNING_MODES = { 'FT_KERNING_DEFAULT' : 0,
'FT_KERNING_UNFITTED' : 1,
'FT_KERNING_UNSCALED' : 2 }
globals().update(FT_KERNING_MODES)

View File

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of values to identify various types of LCD filters.
FT_LCD_FILTER_NONE
Do not perform filtering. When used with subpixel rendering, this results in
sometimes severe color fringes.
FT_LCD_FILTER_DEFAULT
The default filter reduces color fringes considerably, at the cost of a
slight blurriness in the output.
FT_LCD_FILTER_LIGHT
The light filter is a variant that produces less blurriness at the cost of
slightly more color fringes than the default one. It might be better,
depending on taste, your monitor, or your personal vision.
FT_LCD_FILTER_LEGACY
This filter corresponds to the original libXft color filter. It provides high
contrast output but can exhibit really bad color fringes if glyphs are not
extremely well hinted to the pixel grid. In other words, it only works well
if the TrueType bytecode interpreter is enabled and high-quality hinted fonts
are used.
This filter is only provided for comparison purposes, and might be disabled
or stay unsupported in the future.
"""
FT_LCD_FILTERS = {'FT_LCD_FILTER_NONE' : 0,
'FT_LCD_FILTER_DEFAULT' : 1,
'FT_LCD_FILTER_LIGHT' : 2,
'FT_LCD_FILTER_LEGACY' : 16}
globals().update(FT_LCD_FILTERS)

View File

@ -0,0 +1,153 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit-field constants used with FT_Load_Glyph to indicate what kind
of operations to perform during glyph loading.
FT_LOAD_DEFAULT
Corresponding to 0, this value is used as the default glyph load
operation. In this case, the following happens:
1. FreeType looks for a bitmap for the glyph corresponding to the face's
current size. If one is found, the function returns. The bitmap data can
be accessed from the glyph slot (see note below).
2. If no embedded bitmap is searched or found, FreeType looks for a scalable
outline. If one is found, it is loaded from the font file, scaled to
device pixels, then 'hinted' to the pixel grid in order to optimize
it. The outline data can be accessed from the glyph slot (see note below).
Note that by default, the glyph loader doesn't render outlines into
bitmaps. The following flags are used to modify this default behaviour to
more specific and useful cases.
FT_LOAD_NO_SCALE
Don't scale the outline glyph loaded, but keep it in font units.
This flag implies FT_LOAD_NO_HINTING and FT_LOAD_NO_BITMAP, and unsets
FT_LOAD_RENDER.
FT_LOAD_NO_HINTING
Disable hinting. This generally generates 'blurrier' bitmap glyph when the
glyph is rendered in any of the anti-aliased modes. See also the note below.
This flag is implied by FT_LOAD_NO_SCALE.
FT_LOAD_RENDER
Call FT_Render_Glyph after the glyph is loaded. By default, the glyph is
rendered in FT_RENDER_MODE_NORMAL mode. This can be overridden by
FT_LOAD_TARGET_XXX or FT_LOAD_MONOCHROME.
This flag is unset by FT_LOAD_NO_SCALE.
FT_LOAD_NO_BITMAP
Ignore bitmap strikes when loading. Bitmap-only fonts ignore this flag.
FT_LOAD_NO_SCALE always sets this flag.
FT_LOAD_VERTICAL_LAYOUT
Load the glyph for vertical text layout. Don't use it as it is problematic
currently.
FT_LOAD_FORCE_AUTOHINT
Indicates that the auto-hinter is preferred over the font's native
hinter. See also the note below.
FT_LOAD_CROP_BITMAP
Indicates that the font driver should crop the loaded bitmap glyph (i.e.,
remove all space around its black bits). Not all drivers implement this.
FT_LOAD_PEDANTIC
Indicates that the font driver should perform pedantic verifications during
glyph loading. This is mostly used to detect broken glyphs in fonts. By
default, FreeType tries to handle broken fonts also.
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
Indicates that the font driver should ignore the global advance width defined
in the font. By default, that value is used as the advance width for all
glyphs when the face has FT_FACE_FLAG_FIXED_WIDTH set.
This flag exists for historical reasons (to support buggy CJK fonts).
FT_LOAD_NO_RECURSE
This flag is only used internally. It merely indicates that the font driver
should not load composite glyphs recursively. Instead, it should set the
'num_subglyph' and 'subglyphs' values of the glyph slot accordingly, and set
'glyph->format' to FT_GLYPH_FORMAT_COMPOSITE.
The description of sub-glyphs is not available to client applications for now.
This flag implies FT_LOAD_NO_SCALE and FT_LOAD_IGNORE_TRANSFORM.
FT_LOAD_IGNORE_TRANSFORM
Indicates that the transform matrix set by FT_Set_Transform should be ignored.
FT_LOAD_MONOCHROME
This flag is used with FT_LOAD_RENDER to indicate that you want to render an
outline glyph to a 1-bit monochrome bitmap glyph, with 8 pixels packed into
each byte of the bitmap data.
Note that this has no effect on the hinting algorithm used. You should rather
use FT_LOAD_TARGET_MONO so that the monochrome-optimized hinting algorithm is
used.
FT_LOAD_LINEAR_DESIGN
Indicates that the 'linearHoriAdvance' and 'linearVertAdvance' fields of
FT_GlyphSlotRec should be kept in font units. See FT_GlyphSlotRec for
details.
FT_LOAD_NO_AUTOHINT
Disable auto-hinter. See also the note below.
"""
FT_LOAD_FLAGS = { 'FT_LOAD_DEFAULT' : 0x0,
'FT_LOAD_NO_SCALE' : 0x1,
'FT_LOAD_NO_HINTING' : 0x2,
'FT_LOAD_RENDER' : 0x4,
'FT_LOAD_NO_BITMAP' : 0x8,
'FT_LOAD_VERTICAL_LAYOUT' : 0x10,
'FT_LOAD_FORCE_AUTOHINT' : 0x20,
'FT_LOAD_CROP_BITMAP' : 0x40,
'FT_LOAD_PEDANTIC' : 0x80,
'FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH' : 0x200,
'FT_LOAD_NO_RECURSE' : 0x400,
'FT_LOAD_IGNORE_TRANSFORM' : 0x800,
'FT_LOAD_MONOCHROME' : 0x1000,
'FT_LOAD_LINEAR_DESIGN' : 0x2000,
'FT_LOAD_NO_AUTOHINT' : 0x8000 }
globals().update(FT_LOAD_FLAGS)

View File

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of values that are used to select a specific hinting algorithm to use
by the hinter. You should OR one of these values to your 'load_flags' when
calling FT_Load_Glyph.
Note that font's native hinters may ignore the hinting algorithm you have
specified (e.g., the TrueType bytecode interpreter). You can set
FT_LOAD_FORCE_AUTOHINT to ensure that the auto-hinter is used.
Also note that FT_LOAD_TARGET_LIGHT is an exception, in that it always
implies FT_LOAD_FORCE_AUTOHINT.
FT_LOAD_TARGET_NORMAL
This corresponds to the default hinting algorithm, optimized for standard
gray-level rendering. For monochrome output, use FT_LOAD_TARGET_MONO instead.
FT_LOAD_TARGET_LIGHT
A lighter hinting algorithm for non-monochrome modes. Many generated glyphs
are more fuzzy but better resemble its original shape. A bit like rendering
on Mac OS X.
As a special exception, this target implies FT_LOAD_FORCE_AUTOHINT.
FT_LOAD_TARGET_MONO
Strong hinting algorithm that should only be used for monochrome output. The
result is probably unpleasant if the glyph is rendered in non-monochrome
modes.
FT_LOAD_TARGET_LCD
A variant of FT_LOAD_TARGET_NORMAL optimized for horizontally decimated LCD
displays.
FT_LOAD_TARGET_LCD_V
A variant of FT_LOAD_TARGET_NORMAL optimized for vertically decimated LCD
displays.
"""
from freetype.ft_enums.ft_render_modes import *
def _FT_LOAD_TARGET_(x):
return (x & 15) << 16
FT_LOAD_TARGETS = {
'FT_LOAD_TARGET_NORMAL' : _FT_LOAD_TARGET_(FT_RENDER_MODE_NORMAL),
'FT_LOAD_TARGET_LIGHT' : _FT_LOAD_TARGET_(FT_RENDER_MODE_LIGHT),
'FT_LOAD_TARGET_MONO' : _FT_LOAD_TARGET_(FT_RENDER_MODE_MONO),
'FT_LOAD_TARGET_LCD' : _FT_LOAD_TARGET_(FT_RENDER_MODE_LCD),
'FT_LOAD_TARGET_LCD_V' : _FT_LOAD_TARGET_(FT_RENDER_MODE_LCD_V) }
globals().update(FT_LOAD_TARGETS)
#def FT_LOAD_TARGET_MODE(x):
# return (x >> 16) & 15

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit-field constants used within the 'flags' field of the
FT_Open_Args structure.
FT_OPEN_MEMORY
This is a memory-based stream.
FT_OPEN_STREAM
Copy the stream from the 'stream' field.
FT_OPEN_PATHNAME
Create a new input stream from a C path name.
FT_OPEN_DRIVER
Use the 'driver' field.
FT_OPEN_PARAMS
Use the 'num_params' and 'params' fields.
"""
FT_OPEN_MODES = {'FT_OPEN_MEMORY': 0x1,
'FT_OPEN_STREAM': 0x2,
'FT_OPEN_PATHNAME': 0x4,
'FT_OPEN_DRIVER': 0x8,
'FT_OPEN_PARAMS': 0x10 }
globals().update(FT_OPEN_MODES)

View File

@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit-field constants use for the flags in an outline's 'flags'
field.
FT_OUTLINE_NONE
Value 0 is reserved.
FT_OUTLINE_OWNER
If set, this flag indicates that the outline's field arrays (i.e., 'points',
'flags', and 'contours') are 'owned' by the outline object, and should thus
be freed when it is destroyed.
FT_OUTLINE_EVEN_ODD_FILL
By default, outlines are filled using the non-zero winding rule. If set to 1,
the outline will be filled using the even-odd fill rule (only works with the
smooth rasterizer).
FT_OUTLINE_REVERSE_FILL
By default, outside contours of an outline are oriented in clock-wise
direction, as defined in the TrueType specification. This flag is set if the
outline uses the opposite direction (typically for Type 1 fonts). This flag
is ignored by the scan converter.
FT_OUTLINE_IGNORE_DROPOUTS
By default, the scan converter will try to detect drop-outs in an outline and
correct the glyph bitmap to ensure consistent shape continuity. If set, this
flag hints the scan-line converter to ignore such cases. See below for more
information.
FT_OUTLINE_SMART_DROPOUTS
Select smart dropout control. If unset, use simple dropout control. Ignored
if FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more information.
FT_OUTLINE_INCLUDE_STUBS
If set, turn pixels on for 'stubs', otherwise exclude them. Ignored if
FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more information.
FT_OUTLINE_HIGH_PRECISION
This flag indicates that the scan-line converter should try to convert this
outline to bitmaps with the highest possible quality. It is typically set for
small character sizes. Note that this is only a hint that might be completely
ignored by a given scan-converter.
FT_OUTLINE_SINGLE_PASS
This flag is set to force a given scan-converter to only use a single pass
over the outline to render a bitmap glyph image. Normally, it is set for very
large character sizes. It is only a hint that might be completely ignored by
a given scan-converter.
"""
FT_OUTLINE_FLAGS = { 'FT_OUTLINE_NONE' : 0x0,
'FT_OUTLINE_OWNER' : 0x1,
'FT_OUTLINE_EVEN_ODD_FILL' : 0x2,
'FT_OUTLINE_REVERSE_FILL' : 0x4,
'FT_OUTLINE_IGNORE_DROPOUTS' : 0x8,
'FT_OUTLINE_SMART_DROPOUTS' : 0x10,
'FT_OUTLINE_INCLUDE_STUBS' : 0x20,
'FT_OUTLINE_HIGH_PRECISION' : 0x100,
'FT_OUTLINE_SINGLE_PASS' : 0x200 }
globals().update(FT_OUTLINE_FLAGS)

View File

@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
An enumeration type that lists the render modes supported by FreeType 2. Each
mode corresponds to a specific type of scanline conversion performed on the
outline.
FT_PIXEL_MODE_NONE
Value 0 is reserved.
FT_PIXEL_MODE_MONO
A monochrome bitmap, using 1 bit per pixel. Note that pixels are stored in
most-significant order (MSB), which means that the left-most pixel in a byte
has value 128.
FT_PIXEL_MODE_GRAY
An 8-bit bitmap, generally used to represent anti-aliased glyph images. Each
pixel is stored in one byte. Note that the number of 'gray' levels is stored
in the 'num_grays' field of the FT_Bitmap structure (it generally is 256).
FT_PIXEL_MODE_GRAY2
A 2-bit per pixel bitmap, used to represent embedded anti-aliased bitmaps in
font files according to the OpenType specification. We haven't found a single
font using this format, however.
FT_PIXEL_MODE_GRAY4
A 4-bit per pixel bitmap, representing embedded anti-aliased bitmaps in font
files according to the OpenType specification. We haven't found a single font
using this format, however.
FT_PIXEL_MODE_LCD
An 8-bit bitmap, representing RGB or BGR decimated glyph images used for
display on LCD displays; the bitmap is three times wider than the original
glyph image. See also FT_RENDER_MODE_LCD.
FT_PIXEL_MODE_LCD_V
An 8-bit bitmap, representing RGB or BGR decimated glyph images used for
display on rotated LCD displays; the bitmap is three times taller than the
original glyph image. See also FT_RENDER_MODE_LCD_V.
"""
FT_PIXEL_MODES = {'FT_PIXEL_MODE_NONE' : 0,
'FT_PIXEL_MODE_MONO' : 1,
'FT_PIXEL_MODE_GRAY' : 2,
'FT_PIXEL_MODE_GRAY2': 3,
'FT_PIXEL_MODE_GRAY4': 4,
'FT_PIXEL_MODE_LCD' : 5,
'FT_PIXEL_MODE_LCD_V': 6,
'FT_PIXEL_MODE_MAX' : 7}
globals().update(FT_PIXEL_MODES)
ft_pixel_mode_none = FT_PIXEL_MODE_NONE
ft_pixel_mode_mono = FT_PIXEL_MODE_MONO
ft_pixel_mode_grays = FT_PIXEL_MODE_GRAY
ft_pixel_mode_pal2 = FT_PIXEL_MODE_GRAY2
ft_pixel_mode_pal4 = FT_PIXEL_MODE_GRAY4

View File

@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
An enumeration type that lists the render modes supported by FreeType 2. Each
mode corresponds to a specific type of scanline conversion performed on the
outline.
For bitmap fonts and embedded bitmaps the 'bitmap->pixel_mode' field in the
FT_GlyphSlotRec structure gives the format of the returned bitmap.
All modes except FT_RENDER_MODE_MONO use 256 levels of opacity.
FT_RENDER_MODE_NORMAL
This is the default render mode; it corresponds to 8-bit anti-aliased
bitmaps.
FT_RENDER_MODE_LIGHT
This is equivalent to FT_RENDER_MODE_NORMAL. It is only defined as a separate
value because render modes are also used indirectly to define hinting
algorithm selectors. See FT_LOAD_TARGET_XXX for details.
FT_RENDER_MODE_MONO
This mode corresponds to 1-bit bitmaps (with 2 levels of opacity).
FT_RENDER_MODE_LCD
This mode corresponds to horizontal RGB and BGR sub-pixel displays like LCD
screens. It produces 8-bit bitmaps that are 3 times the width of the original
glyph outline in pixels, and which use the FT_PIXEL_MODE_LCD mode.
FT_RENDER_MODE_LCD_V
This mode corresponds to vertical RGB and BGR sub-pixel displays (like PDA
screens, rotated LCD displays, etc.). It produces 8-bit bitmaps that are 3
times the height of the original glyph outline in pixels and use the
FT_PIXEL_MODE_LCD_V mode.
"""
FT_RENDER_MODES = { 'FT_RENDER_MODE_NORMAL' : 0,
'FT_RENDER_MODE_LIGHT' : 1,
'FT_RENDER_MODE_MONO' : 2,
'FT_RENDER_MODE_LCD' : 3,
'FT_RENDER_MODE_LCD_V' : 4 }
globals().update(FT_RENDER_MODES)

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
These values are used to select a given stroke border in
FT_Stroker_GetBorderCounts and FT_Stroker_ExportBorder.
FT_STROKER_BORDER_LEFT
Select the left border, relative to the drawing direction.
FT_STROKER_BORDER_RIGHT
Select the right border, relative to the drawing direction.
Note
Applications are generally interested in the 'inside' and 'outside'
borders. However, there is no direct mapping between these and the 'left' and
'right' ones, since this really depends on the glyph's drawing orientation,
which varies between font formats.
You can however use FT_Outline_GetInsideBorder and
FT_Outline_GetOutsideBorder to get these.
"""
FT_STROKER_BORDERS = { 'FT_STROKER_BORDER_LEFT' : 0,
'FT_STROKER_BORDER_RIGHT' : 1}
globals().update(FT_STROKER_BORDERS)

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
These values determine how the end of opened sub-paths are rendered in a
stroke.
FT_STROKER_LINECAP_BUTT
The end of lines is rendered as a full stop on the last point itself.
FT_STROKER_LINECAP_ROUND
The end of lines is rendered as a half-circle around the last point.
FT_STROKER_LINECAP_SQUARE
The end of lines is rendered as a square around the last point.
"""
FT_STROKER_LINECAPS = { 'FT_STROKER_LINECAP_BUTT' : 0,
'FT_STROKER_LINECAP_ROUND' : 1,
'FT_STROKER_LINECAP_SQUARE' : 2}
globals().update(FT_STROKER_LINECAPS)

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
These values determine how two joining lines are rendered in a stroker.
FT_STROKER_LINEJOIN_ROUND
Used to render rounded line joins. Circular arcs are used to join two lines
smoothly.
FT_STROKER_LINEJOIN_BEVEL
Used to render beveled line joins; i.e., the two joining lines are extended
until they intersect.
FT_STROKER_LINEJOIN_MITER
Same as beveled rendering, except that an additional line break is added if
the angle between the two joining lines is too closed (this is useful to
avoid unpleasant spikes in beveled rendering).
"""
FT_STROKER_LINEJOINS = { 'FT_STROKER_LINEJOIN_ROUND' : 0,
'FT_STROKER_LINEJOIN_BEVEL' : 1,
'FT_STROKER_LINEJOIN_MITER' : 2}
globals().update(FT_STROKER_LINEJOINS)

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of bit-flags used to indicate the style of a given face. These are
used in the 'style_flags' field of FT_FaceRec.
FT_STYLE_FLAG_ITALIC
Indicates that a given face style is italic or oblique.
FT_STYLE_FLAG_BOLD
Indicates that a given face is bold.
"""
FT_STYLE_FLAGS = {'FT_STYLE_FLAG_ITALIC' : 1,
'FT_STYLE_FLAG_BOLD' : 2 }
globals().update(FT_STYLE_FLAGS)

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of valid values for the 'encoding_id' for TT_PLATFORM_ADOBE
charmaps. This is a FreeType-specific extension!
TT_ADOBE_ID_STANDARD
Adobe standard encoding.
TT_ADOBE_ID_EXPERT
Adobe expert encoding.
TT_ADOBE_ID_CUSTOM
Adobe custom encoding.
TT_ADOBE_ID_LATIN_1
Adobe Latin 1 encoding.
"""
TT_ADOBE_IDS = {
'TT_ADOBE_ID_STANDARD' : 0,
'TT_ADOBE_ID_EXPERT' : 1,
'TT_ADOBE_ID_CUSTOM' : 2,
'TT_ADOBE_ID_LATIN_1' : 3 }
globals().update(TT_ADOBE_IDS)

View File

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of valid values for the 'encoding_id' for TT_PLATFORM_APPLE_UNICODE
charmaps and name entries.
TT_APPLE_ID_DEFAULT
Unicode version 1.0.
TT_APPLE_ID_UNICODE_1_1
Unicode 1.1; specifies Hangul characters starting at U+34xx.
TT_APPLE_ID_ISO_10646
Deprecated (identical to preceding).
TT_APPLE_ID_UNICODE_2_0
Unicode 2.0 and beyond (UTF-16 BMP only).
TT_APPLE_ID_UNICODE_32
Unicode 3.1 and beyond, using UTF-32.
TT_APPLE_ID_VARIANT_SELECTOR
From Adobe, not Apple. Not a normal cmap. Specifies variations on a real
cmap.
"""
TT_APPLE_IDS = {
'TT_APPLE_ID_DEFAULT' : 0,
'TT_APPLE_ID_UNICODE_1_1' : 1,
'TT_APPLE_ID_ISO_10646' : 2,
'TT_APPLE_ID_UNICODE_2_0' : 3,
'TT_APPLE_ID_UNICODE_32' : 4,
'TT_APPLE_ID_VARIANT_SELECTOR' : 5 }
globals().update(TT_APPLE_IDS)

View File

@ -0,0 +1,116 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of valid values for the 'encoding_id' for TT_PLATFORM_MACINTOSH
charmaps and name entries.
TT_MAC_ID_ROMAN
TT_MAC_ID_TELUGU
TT_MAC_ID_GURMUKHI
TT_MAC_ID_TIBETAN
TT_MAC_ID_SIMPLIFIED_CHINESE
TT_MAC_ID_SINDHI
TT_MAC_ID_SINHALESE
TT_MAC_ID_RUSSIAN
TT_MAC_ID_KANNADA
TT_MAC_ID_VIETNAMESE
TT_MAC_ID_MONGOLIAN
TT_MAC_ID_DEVANAGARI
TT_MAC_ID_HEBREW
TT_MAC_ID_TAMIL
TT_MAC_ID_THAI
TT_MAC_ID_BURMESE
TT_MAC_ID_MALDIVIAN
TT_MAC_ID_TRADITIONAL_CHINESE
TT_MAC_ID_JAPANESE
TT_MAC_ID_GREEK
TT_MAC_ID_LAOTIAN
TT_MAC_ID_KHMER
TT_MAC_ID_UNINTERP
TT_MAC_ID_ORIYA
TT_MAC_ID_RSYMBOL
TT_MAC_ID_MALAYALAM
TT_MAC_ID_GEEZ
TT_MAC_ID_KOREAN
TT_MAC_ID_GUJARATI
TT_MAC_ID_BENGALI
TT_MAC_ID_ARABIC
TT_MAC_ID_GEORGIAN
TT_MAC_ID_ARMENIAN
TT_MAC_ID_SLAVIC
"""
TT_MAC_IDS = {
'TT_MAC_ID_ROMAN' : 0,
'TT_MAC_ID_JAPANESE' : 1,
'TT_MAC_ID_TRADITIONAL_CHINESE' : 2,
'TT_MAC_ID_KOREAN' : 3,
'TT_MAC_ID_ARABIC' : 4,
'TT_MAC_ID_HEBREW' : 5,
'TT_MAC_ID_GREEK' : 6,
'TT_MAC_ID_RUSSIAN' : 7,
'TT_MAC_ID_RSYMBOL' : 8,
'TT_MAC_ID_DEVANAGARI' : 9,
'TT_MAC_ID_GURMUKHI' : 10,
'TT_MAC_ID_GUJARATI' : 11,
'TT_MAC_ID_ORIYA' : 12,
'TT_MAC_ID_BENGALI' : 13,
'TT_MAC_ID_TAMIL' : 14,
'TT_MAC_ID_TELUGU' : 15,
'TT_MAC_ID_KANNADA' : 16,
'TT_MAC_ID_MALAYALAM' : 17,
'TT_MAC_ID_SINHALESE' : 18,
'TT_MAC_ID_BURMESE' : 19,
'TT_MAC_ID_KHMER' : 20,
'TT_MAC_ID_THAI' : 21,
'TT_MAC_ID_LAOTIAN' : 22,
'TT_MAC_ID_GEORGIAN' : 23,
'TT_MAC_ID_ARMENIAN' : 24,
'TT_MAC_ID_MALDIVIAN' : 25,
'TT_MAC_ID_SIMPLIFIED_CHINESE' : 25,
'TT_MAC_ID_TIBETAN' : 26,
'TT_MAC_ID_MONGOLIAN' : 27,
'TT_MAC_ID_GEEZ' : 28,
'TT_MAC_ID_SLAVIC' : 29,
'TT_MAC_ID_VIETNAMESE' : 30,
'TT_MAC_ID_SINDHI' : 31,
'TT_MAC_ID_UNINTERP' : 32}
globals().update(TT_MAC_IDS)

View File

@ -0,0 +1,373 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
Possible values of the language identifier field in the name records of the
TTF 'name' table if the 'platform' identifier code is TT_PLATFORM_MACINTOSH.
TT_MAC_LANGID_LATIN
TT_MAC_LANGID_MALAY_ARABIC_SCRIPT
TT_MAC_LANGID_HINDI
TT_MAC_LANGID_CATALAN
TT_MAC_LANGID_MARATHI
TT_MAC_LANGID_ICELANDIC
TT_MAC_LANGID_ARABIC
TT_MAC_LANGID_SWAHILI
TT_MAC_LANGID_KHMER
TT_MAC_LANGID_UKRAINIAN
TT_MAC_LANGID_FINNISH
TT_MAC_LANGID_POLISH
TT_MAC_LANGID_NEPALI
TT_MAC_LANGID_UZBEK
TT_MAC_LANGID_TELUGU
TT_MAC_LANGID_MALTESE
TT_MAC_LANGID_AFRIKAANS
TT_MAC_LANGID_CHEWA
TT_MAC_LANGID_BASQUE
TT_MAC_LANGID_CZECH
TT_MAC_LANGID_ROMANIAN
TT_MAC_LANGID_QUECHUA
TT_MAC_LANGID_TAGALOG
TT_MAC_LANGID_HUNGARIAN
TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT
TT_MAC_LANGID_TONGAN
TT_MAC_LANGID_SUNDANESE
TT_MAC_LANGID_JAPANESE
TT_MAC_LANGID_MONGOLIAN
TT_MAC_LANGID_ALBANIAN
TT_MAC_LANGID_NORWEGIAN
TT_MAC_LANGID_SLOVAK
TT_MAC_LANGID_MALAGASY
TT_MAC_LANGID_DZONGKHA
TT_MAC_LANGID_DUTCH
TT_MAC_LANGID_MALAY_ROMAN_SCRIPT
TT_MAC_LANGID_SERBIAN
TT_MAC_LANGID_GERMAN
TT_MAC_LANGID_SOMALI
TT_MAC_LANGID_KOREAN
TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT
TT_MAC_LANGID_CROATIAN
TT_MAC_LANGID_TURKISH
TT_MAC_LANGID_MOLDAVIAN
TT_MAC_LANGID_LAO
TT_MAC_LANGID_ORIYA
TT_MAC_LANGID_BRETON
TT_MAC_LANGID_PASHTO
TT_MAC_LANGID_GUARANI
TT_MAC_LANGID_HEBREW
TT_MAC_LANGID_SLOVENIAN
TT_MAC_LANGID_ESTONIAN
TT_MAC_LANGID_RUNDI
TT_MAC_LANGID_URDU
TT_MAC_LANGID_CHINESE_TRADITIONAL
TT_MAC_LANGID_TATAR
TT_MAC_LANGID_CHINESE_SIMPLIFIED
TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT
TT_MAC_LANGID_SANSKRIT
TT_MAC_LANGID_KURDISH
TT_MAC_LANGID_FAEROESE
TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT
TT_MAC_LANGID_TIGRINYA
TT_MAC_LANGID_THAI
TT_MAC_LANGID_DANISH
TT_MAC_LANGID_KAZAKH
TT_MAC_LANGID_YIDDISH
TT_MAC_LANGID_ESPERANTO
TT_MAC_LANGID_LITHUANIAN
TT_MAC_LANGID_FARSI
TT_MAC_LANGID_LETTISH
TT_MAC_LANGID_VIETNAMESE
TT_MAC_LANGID_PORTUGUESE
TT_MAC_LANGID_IRISH
TT_MAC_LANGID_WELSH
TT_MAC_LANGID_PUNJABI
TT_MAC_LANGID_GREEK
TT_MAC_LANGID_INUKTITUT
TT_MAC_LANGID_FRENCH
TT_MAC_LANGID_GREEK_POLYTONIC
TT_MAC_LANGID_AZERBAIJANI
TT_MAC_LANGID_JAVANESE
TT_MAC_LANGID_SWEDISH
TT_MAC_LANGID_UIGHUR
TT_MAC_LANGID_BENGALI
TT_MAC_LANGID_RUANDA
TT_MAC_LANGID_SINDHI
TT_MAC_LANGID_TIBETAN
TT_MAC_LANGID_ENGLISH
TT_MAC_LANGID_SAAMISK
TT_MAC_LANGID_INDONESIAN
TT_MAC_LANGID_MANX_GAELIC
TT_MAC_LANGID_BYELORUSSIAN
TT_MAC_LANGID_BULGARIAN
TT_MAC_LANGID_GEORGIAN
TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT
TT_MAC_LANGID_ITALIAN
TT_MAC_LANGID_SCOTTISH_GAELIC
TT_MAC_LANGID_ARMENIAN
TT_MAC_LANGID_GALLA
TT_MAC_LANGID_MACEDONIAN
TT_MAC_LANGID_IRISH_GAELIC
TT_MAC_LANGID_KIRGHIZ
TT_MAC_LANGID_TAMIL
TT_MAC_LANGID_SPANISH
TT_MAC_LANGID_BURMESE
TT_MAC_LANGID_KANNADA
TT_MAC_LANGID_GALICIAN
TT_MAC_LANGID_FLEMISH
TT_MAC_LANGID_TAJIKI
TT_MAC_LANGID_ASSAMESE
TT_MAC_LANGID_SINHALESE
TT_MAC_LANGID_GREELANDIC
TT_MAC_LANGID_AMHARIC
TT_MAC_LANGID_KASHMIRI
TT_MAC_LANGID_AYMARA
TT_MAC_LANGID_GUJARATI
TT_MAC_LANGID_RUSSIAN
TT_MAC_LANGID_TURKMEN
TT_MAC_LANGID_MALAYALAM
"""
TT_MAC_LANGIDS = {
'TT_MAC_LANGID_ENGLISH' : 0,
'TT_MAC_LANGID_FRENCH' : 1,
'TT_MAC_LANGID_GERMAN' : 2,
'TT_MAC_LANGID_ITALIAN' : 3,
'TT_MAC_LANGID_DUTCH' : 4,
'TT_MAC_LANGID_SWEDISH' : 5,
'TT_MAC_LANGID_SPANISH' : 6,
'TT_MAC_LANGID_DANISH' : 7,
'TT_MAC_LANGID_PORTUGUESE' : 8,
'TT_MAC_LANGID_NORWEGIAN' : 9,
'TT_MAC_LANGID_HEBREW' : 10,
'TT_MAC_LANGID_JAPANESE' : 11,
'TT_MAC_LANGID_ARABIC' : 12,
'TT_MAC_LANGID_FINNISH' : 13,
'TT_MAC_LANGID_GREEK' : 14,
'TT_MAC_LANGID_ICELANDIC' : 15,
'TT_MAC_LANGID_MALTESE' : 16,
'TT_MAC_LANGID_TURKISH' : 17,
'TT_MAC_LANGID_CROATIAN' : 18,
'TT_MAC_LANGID_CHINESE_TRADITIONAL' : 19,
'TT_MAC_LANGID_URDU' : 20,
'TT_MAC_LANGID_HINDI' : 21,
'TT_MAC_LANGID_THAI' : 22,
'TT_MAC_LANGID_KOREAN' : 23,
'TT_MAC_LANGID_LITHUANIAN' : 24,
'TT_MAC_LANGID_POLISH' : 25,
'TT_MAC_LANGID_HUNGARIAN' : 26,
'TT_MAC_LANGID_ESTONIAN' : 27,
'TT_MAC_LANGID_LETTISH' : 28,
'TT_MAC_LANGID_SAAMISK' : 29,
'TT_MAC_LANGID_FAEROESE' : 30,
'TT_MAC_LANGID_FARSI' : 31,
'TT_MAC_LANGID_RUSSIAN' : 32,
'TT_MAC_LANGID_CHINESE_SIMPLIFIED' : 33,
'TT_MAC_LANGID_FLEMISH' : 34,
'TT_MAC_LANGID_IRISH' : 35,
'TT_MAC_LANGID_ALBANIAN' : 36,
'TT_MAC_LANGID_ROMANIAN' : 37,
'TT_MAC_LANGID_CZECH' : 38,
'TT_MAC_LANGID_SLOVAK' : 39,
'TT_MAC_LANGID_SLOVENIAN' : 40,
'TT_MAC_LANGID_YIDDISH' : 41,
'TT_MAC_LANGID_SERBIAN' : 42,
'TT_MAC_LANGID_MACEDONIAN' : 43,
'TT_MAC_LANGID_BULGARIAN' : 44,
'TT_MAC_LANGID_UKRAINIAN' : 45,
'TT_MAC_LANGID_BYELORUSSIAN' : 46,
'TT_MAC_LANGID_UZBEK' : 47,
'TT_MAC_LANGID_KAZAKH' : 48,
'TT_MAC_LANGID_AZERBAIJANI' : 49,
'TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT': 49,
'TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT' : 50,
'TT_MAC_LANGID_ARMENIAN' : 51,
'TT_MAC_LANGID_GEORGIAN' : 52,
'TT_MAC_LANGID_MOLDAVIAN' : 53,
'TT_MAC_LANGID_KIRGHIZ' : 54,
'TT_MAC_LANGID_TAJIKI' : 55,
'TT_MAC_LANGID_TURKMEN' : 56,
'TT_MAC_LANGID_MONGOLIAN' : 57,
'TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT' : 57,
'TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT' : 58,
'TT_MAC_LANGID_PASHTO' : 59,
'TT_MAC_LANGID_KURDISH' : 60,
'TT_MAC_LANGID_KASHMIRI' : 61,
'TT_MAC_LANGID_SINDHI' : 62,
'TT_MAC_LANGID_TIBETAN' : 63,
'TT_MAC_LANGID_NEPALI' : 64,
'TT_MAC_LANGID_SANSKRIT' : 65,
'TT_MAC_LANGID_MARATHI' : 66,
'TT_MAC_LANGID_BENGALI' : 67,
'TT_MAC_LANGID_ASSAMESE' : 68,
'TT_MAC_LANGID_GUJARATI' : 69,
'TT_MAC_LANGID_PUNJABI' : 70,
'TT_MAC_LANGID_ORIYA' : 71,
'TT_MAC_LANGID_MALAYALAM' : 72,
'TT_MAC_LANGID_KANNADA' : 73,
'TT_MAC_LANGID_TAMIL' : 74,
'TT_MAC_LANGID_TELUGU' : 75,
'TT_MAC_LANGID_SINHALESE' : 76,
'TT_MAC_LANGID_BURMESE' : 77,
'TT_MAC_LANGID_KHMER' : 78,
'TT_MAC_LANGID_LAO' : 79,
'TT_MAC_LANGID_VIETNAMESE' : 80,
'TT_MAC_LANGID_INDONESIAN' : 81,
'TT_MAC_LANGID_TAGALOG' : 82,
'TT_MAC_LANGID_MALAY_ROMAN_SCRIPT' : 83,
'TT_MAC_LANGID_MALAY_ARABIC_SCRIPT' : 84,
'TT_MAC_LANGID_AMHARIC' : 85,
'TT_MAC_LANGID_TIGRINYA' : 86,
'TT_MAC_LANGID_GALLA' : 87,
'TT_MAC_LANGID_SOMALI' : 88,
'TT_MAC_LANGID_SWAHILI' : 89,
'TT_MAC_LANGID_RUANDA' : 90,
'TT_MAC_LANGID_RUNDI' : 91,
'TT_MAC_LANGID_CHEWA' : 92,
'TT_MAC_LANGID_MALAGASY' : 93,
'TT_MAC_LANGID_ESPERANTO' : 94,
'TT_MAC_LANGID_WELSH' : 128,
'TT_MAC_LANGID_BASQUE' : 129,
'TT_MAC_LANGID_CATALAN' : 130,
'TT_MAC_LANGID_LATIN' : 131,
'TT_MAC_LANGID_QUECHUA' : 132,
'TT_MAC_LANGID_GUARANI' : 133,
'TT_MAC_LANGID_AYMARA' : 134,
'TT_MAC_LANGID_TATAR' : 135,
'TT_MAC_LANGID_UIGHUR' : 136,
'TT_MAC_LANGID_DZONGKHA' : 137,
'TT_MAC_LANGID_JAVANESE' : 138,
'TT_MAC_LANGID_SUNDANESE' : 139,
'TT_MAC_LANGID_GALICIAN' : 140,
'TT_MAC_LANGID_AFRIKAANS' : 141,
'TT_MAC_LANGID_BRETON' : 142,
'TT_MAC_LANGID_INUKTITUT' : 143,
'TT_MAC_LANGID_SCOTTISH_GAELIC' : 144,
'TT_MAC_LANGID_MANX_GAELIC' : 145,
'TT_MAC_LANGID_IRISH_GAELIC' : 146,
'TT_MAC_LANGID_TONGAN' : 147,
'TT_MAC_LANGID_GREEK_POLYTONIC' : 148,
'TT_MAC_LANGID_GREELANDIC' : 149,
'TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT' : 150 }
globals().update(TT_MAC_LANGIDS)

View File

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of valid values for the 'encoding_id' for TT_PLATFORM_MICROSOFT
charmaps and name entries.
TT_MS_ID_SYMBOL_CS
Corresponds to Microsoft symbol encoding. See FT_ENCODING_MS_SYMBOL.
TT_MS_ID_UNICODE_CS
Corresponds to a Microsoft WGL4 charmap, matching Unicode. See
FT_ENCODING_UNICODE.
TT_MS_ID_SJIS
Corresponds to SJIS Japanese encoding. See FT_ENCODING_SJIS.
TT_MS_ID_GB2312
Corresponds to Simplified Chinese as used in Mainland China. See
FT_ENCODING_GB2312.
TT_MS_ID_BIG_5
Corresponds to Traditional Chinese as used in Taiwan and Hong Kong. See
FT_ENCODING_BIG5.
TT_MS_ID_WANSUNG
Corresponds to Korean Wansung encoding. See FT_ENCODING_WANSUNG.
TT_MS_ID_JOHAB
Corresponds to Johab encoding. See FT_ENCODING_JOHAB.
TT_MS_ID_UCS_4
Corresponds to UCS-4 or UTF-32 charmaps. This has been added to the OpenType
specification version 1.4 (mid-2001.)
"""
TT_MS_IDS = {
'TT_MS_ID_SYMBOL_CS' : 0,
'TT_MS_ID_UNICODE_CS' : 1,
'TT_MS_ID_SJIS' : 2,
'TT_MS_ID_GB2312' : 3,
'TT_MS_ID_BIG_5' : 4,
'TT_MS_ID_WANSUNG' : 5,
'TT_MS_ID_JOHAB' : 6,
'TT_MS_ID_UCS_4' : 10 }
globals().update(TT_MS_IDS)

View File

@ -0,0 +1,749 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
Possible values of the language identifier field in the name records of the
TTF 'name' table if the 'platform' identifier code is TT_PLATFORM_MICROSOFT.
TT_MS_LANGID_SANSKRIT_INDIA
TT_MS_LANGID_ENGLISH_UNITED_KINGDOM
TT_MS_LANGID_ENGLISH_BELIZE
TT_MS_LANGID_ARABIC_LEBANON
TT_MS_LANGID_MOLDAVIAN_MOLDAVIA
TT_MS_LANGID_TURKISH_TURKEY
TT_MS_LANGID_WELSH_WALES
TT_MS_LANGID_GERMAN_AUSTRIA
TT_MS_LANGID_DUTCH_BELGIUM
TT_MS_LANGID_YI_CHINA
TT_MS_LANGID_QUECHUA_ECUADOR
TT_MS_LANGID_SPANISH_EL_SALVADOR
TT_MS_LANGID_SWAHILI_KENYA
TT_MS_LANGID_QUECHUA_BOLIVIA
TT_MS_LANGID_SLOVENE_SLOVENIA
TT_MS_LANGID_ORIYA_INDIA
TT_MS_LANGID_FARSI_IRAN
TT_MS_LANGID_ENGLISH_CANADA
TT_MS_LANGID_NEPALI_NEPAL
TT_MS_LANGID_DHIVEHI_MALDIVES
TT_MS_LANGID_GERMAN_LIECHTENSTEI
TT_MS_LANGID_TAMIL_INDIA
TT_MS_LANGID_ARABIC_UAE
TT_MS_LANGID_JAPANESE_JAPAN
TT_MS_LANGID_TAMAZIGHT_MOROCCO
TT_MS_LANGID_FRENCH_FRANCE
TT_MS_LANGID_CHINESE_MACAU
TT_MS_LANGID_VIETNAMESE_VIET_NAM
TT_MS_LANGID_HEBREW_ISRAEL
TT_MS_LANGID_SAMI_NORTHERN_SWEDEN
TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN
TT_MS_LANGID_SWEDISH_SWEDEN
TT_MS_LANGID_FRENCH_REUNION
TT_MS_LANGID_ARABIC_BAHRAIN
TT_MS_LANGID_ENGLISH_INDIA
TT_MS_LANGID_NEPALI_INDIA
TT_MS_LANGID_THAI_THAILAND
TT_MS_LANGID_ENGLISH_GENERAL
TT_MS_LANGID_SAMI_LULE_NORWAY
TT_MS_LANGID_ARABIC_OMAN
TT_MS_LANGID_SPANISH_HONDURAS
TT_MS_LANGID_ENGLISH_JAMAICA
TT_MS_LANGID_ESTONIAN_ESTONIA
TT_MS_LANGID_FRISIAN_NETHERLANDS
TT_MS_LANGID_LATIN
TT_MS_LANGID_ENGLISH_INDONESIA
TT_MS_LANGID_ENGLISH_IRELAND
TT_MS_LANGID_TIBETAN_CHINA
TT_MS_LANGID_PUNJABI_INDIA
TT_MS_LANGID_FRENCH_MALI
TT_MS_LANGID_GERMAN_LUXEMBOURG
TT_MS_LANGID_SUTU_SOUTH_AFRICA
TT_MS_LANGID_FRENCH_CAMEROON
TT_MS_LANGID_FRENCH_CONGO
TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA
TT_MS_LANGID_MALAYALAM_INDIA
TT_MS_LANGID_SAMI_SOUTHERN_SWEDEN
TT_MS_LANGID_CHEROKEE_UNITED_STATES
TT_MS_LANGID_SPANISH_GUATEMALA
TT_MS_LANGID_CZECH_CZECH_REPUBLIC
TT_MS_LANGID_MANIPURI_INDIA
TT_MS_LANGID_ENGLISH_AUSTRALIA
TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC
TT_MS_LANGID_ARABIC_LIBYA
TT_MS_LANGID_FRENCH_WEST_INDIES
TT_MS_LANGID_ENGLISH_TRINIDAD
TT_MS_LANGID_ARABIC_QATAR
TT_MS_LANGID_SPANISH_COLOMBIA
TT_MS_LANGID_GUARANI_PARAGUAY
TT_MS_LANGID_EDO_NIGERIA
TT_MS_LANGID_SEPEDI_SOUTH_AFRICA
TT_MS_LANGID_ENGLISH_HONG_KONG
TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA
TT_MS_LANGID_TATAR_TATARSTAN
TT_MS_LANGID_PASHTO_AFGHANISTAN
TT_MS_LANGID_KASHMIRI_PAKISTAN
TT_MS_LANGID_GALICIAN_SPAIN
TT_MS_LANGID_TAJIK_TAJIKISTAN
TT_MS_LANGID_SAMI_INARI_FINLAND
TT_MS_LANGID_KASHMIRI_SASIA
TT_MS_LANGID_SPANISH_ARGENTINA
TT_MS_LANGID_SAMI_SOUTHERN_NORWAY
TT_MS_LANGID_CROATIAN_CROATIA
TT_MS_LANGID_GUJARATI_INDIA
TT_MS_LANGID_TIBETAN_BHUTAN
TT_MS_LANGID_TIGRIGNA_ETHIOPIA
TT_MS_LANGID_FINNISH_FINLAND
TT_MS_LANGID_ENGLISH_UNITED_STATES
TT_MS_LANGID_ITALIAN_SWITZERLAND
TT_MS_LANGID_ARABIC_EGYPT
TT_MS_LANGID_SPANISH_LATIN_AMERICA
TT_MS_LANGID_LITHUANIAN_LITHUANIA
TT_MS_LANGID_ARABIC_ALGERIA
TT_MS_LANGID_MALAY_MALAYSIA
TT_MS_LANGID_ARABIC_GENERAL
TT_MS_LANGID_CHINESE_PRC
TT_MS_LANGID_BENGALI_BANGLADESH
TT_MS_LANGID_SPANISH_PERU
TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT
TT_MS_LANGID_DIVEHI_MALDIVES
TT_MS_LANGID_LATVIAN_LATVIA
TT_MS_LANGID_TURKMEN_TURKMENISTAN
TT_MS_LANGID_XHOSA_SOUTH_AFRICA
TT_MS_LANGID_KHMER_CAMBODIA
TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK
TT_MS_LANGID_ARABIC_MOROCCO
TT_MS_LANGID_FRENCH_SENEGAL
TT_MS_LANGID_YORUBA_NIGERIA
TT_MS_LANGID_CATALAN_SPAIN
TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA
TT_MS_LANGID_ZULU_SOUTH_AFRICA
TT_MS_LANGID_SPANISH_URUGUAY
TT_MS_LANGID_SPANISH_ECUADOR
TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA
TT_MS_LANGID_CHINESE_GENERAL
TT_MS_LANGID_SPANISH_PARAGUAY
TT_MS_LANGID_HINDI_INDIA
TT_MS_LANGID_FRENCH_LUXEMBOURG
TT_MS_LANGID_TSWANA_SOUTH_AFRICA
TT_MS_LANGID_HUNGARIAN_HUNGARY
TT_MS_LANGID_CROATIAN_BOSNIA_HERZEGOVINA
TT_MS_LANGID_ENGLISH_SINGAPORE
TT_MS_LANGID_MALTESE_MALTA
TT_MS_LANGID_SAMI_NORTHERN_FINLAND
TT_MS_LANGID_FRENCH_CANADA
TT_MS_LANGID_SAMI_LULE_SWEDEN
TT_MS_LANGID_KANURI_NIGERIA
TT_MS_LANGID_IRISH_GAELIC_IRELAND
TT_MS_LANGID_ARABIC_SAUDI_ARABIA
TT_MS_LANGID_FRENCH_HAITI
TT_MS_LANGID_SPANISH_PUERTO_RICO
TT_MS_LANGID_BURMESE_MYANMAR
TT_MS_LANGID_POLISH_POLAND
TT_MS_LANGID_PORTUGUESE_PORTUGAL
TT_MS_LANGID_ENGLISH_CARIBBEAN
TT_MS_LANGID_KIRGHIZ_KIRGHIZ_REPUBLIC
TT_MS_LANGID_ICELANDIC_ICELAND
TT_MS_LANGID_BENGALI_INDIA
TT_MS_LANGID_HAUSA_NIGERIA
TT_MS_LANGID_BASQUE_SPAIN
TT_MS_LANGID_UIGHUR_CHINA
TT_MS_LANGID_ENGLISH_MALAYSIA
TT_MS_LANGID_FRENCH_MONACO
TT_MS_LANGID_SPANISH_BOLIVIA
TT_MS_LANGID_SORBIAN_GERMANY
TT_MS_LANGID_SINDHI_INDIA
TT_MS_LANGID_CHINESE_SINGAPORE
TT_MS_LANGID_FRENCH_COTE_D_IVOIRE
TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT
TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC
TT_MS_LANGID_SAMI_SKOLT_FINLAND
TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_CYRILLIC
TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM
TT_MS_LANGID_ARABIC_JORDAN
TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN
TT_MS_LANGID_SERBIAN_SERBIA_LATIN
TT_MS_LANGID_RUSSIAN_RUSSIA
TT_MS_LANGID_ROMANIAN_ROMANIA
TT_MS_LANGID_FRENCH_NORTH_AFRICA
TT_MS_LANGID_MONGOLIAN_MONGOLIA
TT_MS_LANGID_TSONGA_SOUTH_AFRICA
TT_MS_LANGID_SOMALI_SOMALIA
TT_MS_LANGID_SAAMI_LAPONIA
TT_MS_LANGID_SPANISH_COSTA_RICA
TT_MS_LANGID_ARABIC_SYRIA
TT_MS_LANGID_SPANISH_PANAMA
TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES
TT_MS_LANGID_ASSAMESE_INDIA
TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM
TT_MS_LANGID_DUTCH_NETHERLANDS
TT_MS_LANGID_SINDHI_PAKISTAN
TT_MS_LANGID_MACEDONIAN_MACEDONIA
TT_MS_LANGID_KAZAK_KAZAKSTAN
TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN
TT_MS_LANGID_BELARUSIAN_BELARUS
TT_MS_LANGID_FRENCH_MOROCCO
TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_LATIN
TT_MS_LANGID_ALBANIAN_ALBANIA
TT_MS_LANGID_SINHALESE_SRI_LANKA
TT_MS_LANGID_SPANISH_MEXICO
TT_MS_LANGID_ENGLISH_ZIMBABWE
TT_MS_LANGID_OROMO_ETHIOPIA
TT_MS_LANGID_INDONESIAN_INDONESIA
TT_MS_LANGID_SAMI_NORTHERN_NORWAY
TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN
TT_MS_LANGID_SLOVAK_SLOVAKIA
TT_MS_LANGID_KASHMIRI_INDIA
TT_MS_LANGID_GERMAN_SWITZERLAND
TT_MS_LANGID_URDU_INDIA
TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS
TT_MS_LANGID_SYRIAC_SYRIA
TT_MS_LANGID_SPANISH_CHILE
TT_MS_LANGID_FILIPINO_PHILIPPINES
TT_MS_LANGID_ARABIC_YEMEN
TT_MS_LANGID_KONKANI_INDIA
TT_MS_LANGID_AMHARIC_ETHIOPIA
TT_MS_LANGID_ENGLISH_NEW_ZEALAND
TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND
TT_MS_LANGID_ARABIC_TUNISIA
TT_MS_LANGID_SOTHO_SOUTHERN_SOUTH_AFRICA
TT_MS_LANGID_QUECHUA_PERU
TT_MS_LANGID_DANISH_DENMARK
TT_MS_LANGID_ENGLISH_PHILIPPINES
TT_MS_LANGID_SPANISH_NICARAGUA
TT_MS_LANGID_INUKTITUT_CANADA
TT_MS_LANGID_UKRAINIAN_UKRAINE
TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL
TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC
TT_MS_LANGID_FRENCH_BELGIUM
TT_MS_LANGID_ENGLISH_SOUTH_AFRICA
TT_MS_LANGID_HAWAIIAN_UNITED_STATES
TT_MS_LANGID_ARABIC_IRAQ
TT_MS_LANGID_KANNADA_INDIA
TT_MS_LANGID_DZONGHKA_BHUTAN
TT_MS_LANGID_CHINESE_TAIWAN
TT_MS_LANGID_SPANISH_UNITED_STATES
TT_MS_LANGID_ARMENIAN_ARMENIA
TT_MS_LANGID_LAO_LAOS
TT_MS_LANGID_TIGRIGNA_ERYTREA
TT_MS_LANGID_MARATHI_INDIA
TT_MS_LANGID_ARABIC_KUWAIT
TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN
TT_MS_LANGID_PORTUGUESE_BRAZIL
TT_MS_LANGID_TIGRIGNA_ERYTHREA
TT_MS_LANGID_GREEK_GREECE
TT_MS_LANGID_URDU_PAKISTAN
TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN
TT_MS_LANGID_YIDDISH_GERMANY
TT_MS_LANGID_GERMAN_GERMANY
TT_MS_LANGID_TELUGU_INDIA
TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC
TT_MS_LANGID_KOREAN_JOHAB_KOREA
TT_MS_LANGID_ITALIAN_ITALY
TT_MS_LANGID_MAORI_NEW_ZEALAND
TT_MS_LANGID_SPANISH_VENEZUELA
TT_MS_LANGID_IGBO_NIGERIA
TT_MS_LANGID_IBIBIO_NIGERIA
TT_MS_LANGID_CHINESE_HONG_KONG
TT_MS_LANGID_FRENCH_SWITZERLAND
TT_MS_LANGID_BULGARIAN_BULGARIA
TT_MS_LANGID_FULFULDE_NIGERIA
TT_MS_LANGID_RUSSIAN_MOLDAVIA
TT_MS_LANGID_VENDA_SOUTH_AFRICA
TT_MS_LANGID_GEORGIAN_GEORGIA
TT_MS_LANGID_SWEDISH_FINLAND
"""
TT_MS_LANGIDS = {
'TT_MS_LANGID_ARABIC_GENERAL' : 0x0001,
'TT_MS_LANGID_ARABIC_SAUDI_ARABIA' : 0x0401,
'TT_MS_LANGID_ARABIC_IRAQ' : 0x0801,
'TT_MS_LANGID_ARABIC_EGYPT' : 0x0c01,
'TT_MS_LANGID_ARABIC_LIBYA' : 0x1001,
'TT_MS_LANGID_ARABIC_ALGERIA' : 0x1401,
'TT_MS_LANGID_ARABIC_MOROCCO' : 0x1801,
'TT_MS_LANGID_ARABIC_TUNISIA' : 0x1c01,
'TT_MS_LANGID_ARABIC_OMAN' : 0x2001,
'TT_MS_LANGID_ARABIC_YEMEN' : 0x2401,
'TT_MS_LANGID_ARABIC_SYRIA' : 0x2801,
'TT_MS_LANGID_ARABIC_JORDAN' : 0x2c01,
'TT_MS_LANGID_ARABIC_LEBANON' : 0x3001,
'TT_MS_LANGID_ARABIC_KUWAIT' : 0x3401,
'TT_MS_LANGID_ARABIC_UAE' : 0x3801,
'TT_MS_LANGID_ARABIC_BAHRAIN' : 0x3c01,
'TT_MS_LANGID_ARABIC_QATAR' : 0x4001,
'TT_MS_LANGID_BULGARIAN_BULGARIA' : 0x0402,
'TT_MS_LANGID_CATALAN_SPAIN' : 0x0403,
'TT_MS_LANGID_CHINESE_GENERAL' : 0x0004,
'TT_MS_LANGID_CHINESE_TAIWAN' : 0x0404,
'TT_MS_LANGID_CHINESE_PRC' : 0x0804,
'TT_MS_LANGID_CHINESE_HONG_KONG' : 0x0c04,
'TT_MS_LANGID_CHINESE_SINGAPORE' : 0x1004,
'TT_MS_LANGID_CHINESE_MACAU' : 0x1404,
'TT_MS_LANGID_CZECH_CZECH_REPUBLIC' : 0x0405,
'TT_MS_LANGID_DANISH_DENMARK' : 0x0406,
'TT_MS_LANGID_GERMAN_GERMANY' : 0x0407,
'TT_MS_LANGID_GERMAN_SWITZERLAND' : 0x0807,
'TT_MS_LANGID_GERMAN_AUSTRIA' : 0x0c07,
'TT_MS_LANGID_GERMAN_LUXEMBOURG' : 0x1007,
'TT_MS_LANGID_GERMAN_LIECHTENSTEI' : 0x1407,
'TT_MS_LANGID_GREEK_GREECE' : 0x0408,
'TT_MS_LANGID_ENGLISH_GENERAL' : 0x0009,
'TT_MS_LANGID_ENGLISH_UNITED_STATES' : 0x0409,
'TT_MS_LANGID_ENGLISH_UNITED_KINGDOM' : 0x0809,
'TT_MS_LANGID_ENGLISH_AUSTRALIA' : 0x0c09,
'TT_MS_LANGID_ENGLISH_CANADA' : 0x1009,
'TT_MS_LANGID_ENGLISH_NEW_ZEALAND' : 0x1409,
'TT_MS_LANGID_ENGLISH_IRELAND' : 0x1809,
'TT_MS_LANGID_ENGLISH_SOUTH_AFRICA' : 0x1c09,
'TT_MS_LANGID_ENGLISH_JAMAICA' : 0x2009,
'TT_MS_LANGID_ENGLISH_CARIBBEAN' : 0x2409,
'TT_MS_LANGID_ENGLISH_BELIZE' : 0x2809,
'TT_MS_LANGID_ENGLISH_TRINIDAD' : 0x2c09,
'TT_MS_LANGID_ENGLISH_ZIMBABWE' : 0x3009,
'TT_MS_LANGID_ENGLISH_PHILIPPINES' : 0x3409,
'TT_MS_LANGID_ENGLISH_INDONESIA' : 0x3809,
'TT_MS_LANGID_ENGLISH_HONG_KONG' : 0x3c09,
'TT_MS_LANGID_ENGLISH_INDIA' : 0x4009,
'TT_MS_LANGID_ENGLISH_MALAYSIA' : 0x4409,
'TT_MS_LANGID_ENGLISH_SINGAPORE' : 0x4809,
'TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT' : 0x040a,
'TT_MS_LANGID_SPANISH_MEXICO' : 0x080a,
'TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT' : 0x0c0a,
'TT_MS_LANGID_SPANISH_GUATEMALA' : 0x100a,
'TT_MS_LANGID_SPANISH_COSTA_RICA' : 0x140a,
'TT_MS_LANGID_SPANISH_PANAMA' : 0x180a,
'TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC' : 0x1c0a,
'TT_MS_LANGID_SPANISH_VENEZUELA' : 0x200a,
'TT_MS_LANGID_SPANISH_COLOMBIA' : 0x240a,
'TT_MS_LANGID_SPANISH_PERU' : 0x280a,
'TT_MS_LANGID_SPANISH_ARGENTINA' : 0x2c0a,
'TT_MS_LANGID_SPANISH_ECUADOR' : 0x300a,
'TT_MS_LANGID_SPANISH_CHILE' : 0x340a,
'TT_MS_LANGID_SPANISH_URUGUAY' : 0x380a,
'TT_MS_LANGID_SPANISH_PARAGUAY' : 0x3c0a,
'TT_MS_LANGID_SPANISH_BOLIVIA' : 0x400a,
'TT_MS_LANGID_SPANISH_EL_SALVADOR' : 0x440a,
'TT_MS_LANGID_SPANISH_HONDURAS' : 0x480a,
'TT_MS_LANGID_SPANISH_NICARAGUA' : 0x4c0a,
'TT_MS_LANGID_SPANISH_PUERTO_RICO' : 0x500a,
'TT_MS_LANGID_SPANISH_UNITED_STATES' : 0x540a,
'TT_MS_LANGID_SPANISH_LATIN_AMERICA' : 0xE40a,
'TT_MS_LANGID_FINNISH_FINLAND' : 0x040b,
'TT_MS_LANGID_FRENCH_FRANCE' : 0x040c,
'TT_MS_LANGID_FRENCH_BELGIUM' : 0x080c,
'TT_MS_LANGID_FRENCH_CANADA' : 0x0c0c,
'TT_MS_LANGID_FRENCH_SWITZERLAND' : 0x100c,
'TT_MS_LANGID_FRENCH_LUXEMBOURG' : 0x140c,
'TT_MS_LANGID_FRENCH_MONACO' : 0x180c,
'TT_MS_LANGID_FRENCH_WEST_INDIES' : 0x1c0c,
'TT_MS_LANGID_FRENCH_REUNION' : 0x200c,
'TT_MS_LANGID_FRENCH_CONGO' : 0x240c,
'TT_MS_LANGID_FRENCH_SENEGAL' : 0x280c,
'TT_MS_LANGID_FRENCH_CAMEROON' : 0x2c0c,
'TT_MS_LANGID_FRENCH_COTE_D_IVOIRE' : 0x300c,
'TT_MS_LANGID_FRENCH_MALI' : 0x340c,
'TT_MS_LANGID_FRENCH_MOROCCO' : 0x380c,
'TT_MS_LANGID_FRENCH_HAITI' : 0x3c0c,
'TT_MS_LANGID_FRENCH_NORTH_AFRICA' : 0xE40c,
'TT_MS_LANGID_HEBREW_ISRAEL' : 0x040d,
'TT_MS_LANGID_HUNGARIAN_HUNGARY' : 0x040e,
'TT_MS_LANGID_ICELANDIC_ICELAND' : 0x040f,
'TT_MS_LANGID_ITALIAN_ITALY' : 0x0410,
'TT_MS_LANGID_ITALIAN_SWITZERLAND' : 0x0810,
'TT_MS_LANGID_JAPANESE_JAPAN' : 0x0411,
'TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA' : 0x0412,
'TT_MS_LANGID_KOREAN_JOHAB_KOREA' : 0x0812,
'TT_MS_LANGID_DUTCH_NETHERLANDS' : 0x0413,
'TT_MS_LANGID_DUTCH_BELGIUM' : 0x0813,
'TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL' : 0x0414,
'TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK' : 0x0814,
'TT_MS_LANGID_POLISH_POLAND' : 0x0415,
'TT_MS_LANGID_PORTUGUESE_BRAZIL' : 0x0416,
'TT_MS_LANGID_PORTUGUESE_PORTUGAL' : 0x0816,
'TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND' : 0x0417,
'TT_MS_LANGID_ROMANIAN_ROMANIA' : 0x0418,
'TT_MS_LANGID_MOLDAVIAN_MOLDAVIA' : 0x0818,
'TT_MS_LANGID_RUSSIAN_RUSSIA' : 0x0419,
'TT_MS_LANGID_RUSSIAN_MOLDAVIA' : 0x0819,
'TT_MS_LANGID_CROATIAN_CROATIA' : 0x041a,
'TT_MS_LANGID_SERBIAN_SERBIA_LATIN' : 0x081a,
'TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC' : 0x0c1a,
'TT_MS_LANGID_CROATIAN_BOSNIA_HERZEGOVINA' : 0x101a,
'TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA' : 0x141a,
'TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_LATIN' : 0x181a,
'TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_CYRILLIC' : 0x181a,
'TT_MS_LANGID_SLOVAK_SLOVAKIA' : 0x041b,
'TT_MS_LANGID_ALBANIAN_ALBANIA' : 0x041c,
'TT_MS_LANGID_SWEDISH_SWEDEN' : 0x041d,
'TT_MS_LANGID_SWEDISH_FINLAND' : 0x081d,
'TT_MS_LANGID_THAI_THAILAND' : 0x041e,
'TT_MS_LANGID_TURKISH_TURKEY' : 0x041f,
'TT_MS_LANGID_URDU_PAKISTAN' : 0x0420,
'TT_MS_LANGID_URDU_INDIA' : 0x0820,
'TT_MS_LANGID_INDONESIAN_INDONESIA' : 0x0421,
'TT_MS_LANGID_UKRAINIAN_UKRAINE' : 0x0422,
'TT_MS_LANGID_BELARUSIAN_BELARUS' : 0x0423,
'TT_MS_LANGID_SLOVENE_SLOVENIA' : 0x0424,
'TT_MS_LANGID_ESTONIAN_ESTONIA' : 0x0425,
'TT_MS_LANGID_LATVIAN_LATVIA' : 0x0426,
'TT_MS_LANGID_LITHUANIAN_LITHUANIA' : 0x0427,
'TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA' : 0x0827,
'TT_MS_LANGID_TAJIK_TAJIKISTAN' : 0x0428,
'TT_MS_LANGID_FARSI_IRAN' : 0x0429,
'TT_MS_LANGID_VIETNAMESE_VIET_NAM' : 0x042a,
'TT_MS_LANGID_ARMENIAN_ARMENIA' : 0x042b,
'TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN' : 0x042c,
'TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC' : 0x082c,
'TT_MS_LANGID_BASQUE_SPAIN' : 0x042d,
'TT_MS_LANGID_SORBIAN_GERMANY' : 0x042e,
'TT_MS_LANGID_MACEDONIAN_MACEDONIA' : 0x042f,
'TT_MS_LANGID_SUTU_SOUTH_AFRICA' : 0x0430,
'TT_MS_LANGID_TSONGA_SOUTH_AFRICA' : 0x0431,
'TT_MS_LANGID_TSWANA_SOUTH_AFRICA' : 0x0432,
'TT_MS_LANGID_VENDA_SOUTH_AFRICA' : 0x0433,
'TT_MS_LANGID_XHOSA_SOUTH_AFRICA' : 0x0434,
'TT_MS_LANGID_ZULU_SOUTH_AFRICA' : 0x0435,
'TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA' : 0x0436,
'TT_MS_LANGID_GEORGIAN_GEORGIA' : 0x0437,
'TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS' : 0x0438,
'TT_MS_LANGID_HINDI_INDIA' : 0x0439,
'TT_MS_LANGID_MALTESE_MALTA' : 0x043a,
'TT_MS_LANGID_SAMI_NORTHERN_NORWAY' : 0x043b,
'TT_MS_LANGID_SAMI_NORTHERN_SWEDEN' : 0x083b,
'TT_MS_LANGID_SAMI_NORTHERN_FINLAND' : 0x0C3b,
'TT_MS_LANGID_SAMI_LULE_NORWAY' : 0x103b,
'TT_MS_LANGID_SAMI_LULE_SWEDEN' : 0x143b,
'TT_MS_LANGID_SAMI_SOUTHERN_NORWAY' : 0x183b,
'TT_MS_LANGID_SAMI_SOUTHERN_SWEDEN' : 0x1C3b,
'TT_MS_LANGID_SAMI_SKOLT_FINLAND' : 0x203b,
'TT_MS_LANGID_SAMI_INARI_FINLAND' : 0x243b,
'TT_MS_LANGID_SAAMI_LAPONIA' : 0x043b,
'TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM' : 0x083c,
'TT_MS_LANGID_IRISH_GAELIC_IRELAND' : 0x043c,
'TT_MS_LANGID_YIDDISH_GERMANY' : 0x043d,
'TT_MS_LANGID_MALAY_MALAYSIA' : 0x043e,
'TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM' : 0x083e,
'TT_MS_LANGID_KAZAK_KAZAKSTAN' : 0x043f,
'TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN' : 0x0440,
'TT_MS_LANGID_KIRGHIZ_KIRGHIZ_REPUBLIC' : 0x0440,
'TT_MS_LANGID_SWAHILI_KENYA' : 0x0441,
'TT_MS_LANGID_TURKMEN_TURKMENISTAN' : 0x0442,
'TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN' : 0x0443,
'TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC' : 0x0843,
'TT_MS_LANGID_TATAR_TATARSTAN' : 0x0444,
'TT_MS_LANGID_BENGALI_INDIA' : 0x0445,
'TT_MS_LANGID_BENGALI_BANGLADESH' : 0x0845,
'TT_MS_LANGID_PUNJABI_INDIA' : 0x0446,
'TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN' : 0x0846,
'TT_MS_LANGID_GUJARATI_INDIA' : 0x0447,
'TT_MS_LANGID_ORIYA_INDIA' : 0x0448,
'TT_MS_LANGID_TAMIL_INDIA' : 0x0449,
'TT_MS_LANGID_TELUGU_INDIA' : 0x044a,
'TT_MS_LANGID_KANNADA_INDIA' : 0x044b,
'TT_MS_LANGID_MALAYALAM_INDIA' : 0x044c,
'TT_MS_LANGID_ASSAMESE_INDIA' : 0x044d,
'TT_MS_LANGID_MARATHI_INDIA' : 0x044e,
'TT_MS_LANGID_SANSKRIT_INDIA' : 0x044f,
'TT_MS_LANGID_MONGOLIAN_MONGOLIA' : 0x0450,
'TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN' : 0x0850,
'TT_MS_LANGID_TIBETAN_CHINA' : 0x0451,
'TT_MS_LANGID_DZONGHKA_BHUTAN' : 0x0851,
'TT_MS_LANGID_TIBETAN_BHUTAN' : 0x0851,
'TT_MS_LANGID_WELSH_WALES' : 0x0452,
'TT_MS_LANGID_KHMER_CAMBODIA' : 0x0453,
'TT_MS_LANGID_LAO_LAOS' : 0x0454,
'TT_MS_LANGID_BURMESE_MYANMAR' : 0x0455,
'TT_MS_LANGID_GALICIAN_SPAIN' : 0x0456,
'TT_MS_LANGID_KONKANI_INDIA' : 0x0457,
'TT_MS_LANGID_MANIPURI_INDIA' : 0x0458,
'TT_MS_LANGID_SINDHI_INDIA' : 0x0459,
'TT_MS_LANGID_SINDHI_PAKISTAN' : 0x0859,
'TT_MS_LANGID_SYRIAC_SYRIA' : 0x045a,
'TT_MS_LANGID_SINHALESE_SRI_LANKA' : 0x045b,
'TT_MS_LANGID_CHEROKEE_UNITED_STATES' : 0x045c,
'TT_MS_LANGID_INUKTITUT_CANADA' : 0x045d,
'TT_MS_LANGID_AMHARIC_ETHIOPIA' : 0x045e,
'TT_MS_LANGID_TAMAZIGHT_MOROCCO' : 0x045f,
'TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN' : 0x085f,
'TT_MS_LANGID_KASHMIRI_PAKISTAN' : 0x0460,
'TT_MS_LANGID_KASHMIRI_SASIA' : 0x0860,
'TT_MS_LANGID_KASHMIRI_INDIA' : 0x0860,
'TT_MS_LANGID_NEPALI_NEPAL' : 0x0461,
'TT_MS_LANGID_NEPALI_INDIA' : 0x0861,
'TT_MS_LANGID_FRISIAN_NETHERLANDS' : 0x0462,
'TT_MS_LANGID_PASHTO_AFGHANISTAN' : 0x0463,
'TT_MS_LANGID_FILIPINO_PHILIPPINES' : 0x0464,
'TT_MS_LANGID_DHIVEHI_MALDIVES' : 0x0465,
'TT_MS_LANGID_DIVEHI_MALDIVES' : 0x0465,
'TT_MS_LANGID_EDO_NIGERIA' : 0x0466,
'TT_MS_LANGID_FULFULDE_NIGERIA' : 0x0467,
'TT_MS_LANGID_HAUSA_NIGERIA' : 0x0468,
'TT_MS_LANGID_IBIBIO_NIGERIA' : 0x0469,
'TT_MS_LANGID_YORUBA_NIGERIA' : 0x046a,
'TT_MS_LANGID_QUECHUA_BOLIVIA' : 0x046b,
'TT_MS_LANGID_QUECHUA_ECUADOR' : 0x086b,
'TT_MS_LANGID_QUECHUA_PERU' : 0x0c6b,
'TT_MS_LANGID_SEPEDI_SOUTH_AFRICA' : 0x046c,
'TT_MS_LANGID_SOTHO_SOUTHERN_SOUTH_AFRICA' : 0x046c,
'TT_MS_LANGID_IGBO_NIGERIA' : 0x0470,
'TT_MS_LANGID_KANURI_NIGERIA' : 0x0471,
'TT_MS_LANGID_OROMO_ETHIOPIA' : 0x0472,
'TT_MS_LANGID_TIGRIGNA_ETHIOPIA' : 0x0473,
'TT_MS_LANGID_TIGRIGNA_ERYTHREA' : 0x0873,
'TT_MS_LANGID_TIGRIGNA_ERYTREA' : 0x0873,
'TT_MS_LANGID_GUARANI_PARAGUAY' : 0x0474,
'TT_MS_LANGID_HAWAIIAN_UNITED_STATES' : 0x0475,
'TT_MS_LANGID_LATIN' : 0x0476,
'TT_MS_LANGID_SOMALI_SOMALIA' : 0x0477,
'TT_MS_LANGID_YI_CHINA' : 0x0478,
'TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES' : 0x0479,
'TT_MS_LANGID_UIGHUR_CHINA' : 0x0480,
'TT_MS_LANGID_MAORI_NEW_ZEALAND' : 0x0481 }
globals().update(TT_MS_LANGIDS)

View File

@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
Possible values of the 'name' identifier field in the name records of the TTF
'name' table. These values are platform independent.
TT_NAME_ID_COPYRIGHT
TT_NAME_ID_FONT_FAMILY
TT_NAME_ID_FONT_SUBFAMILY
TT_NAME_ID_UNIQUE_ID
TT_NAME_ID_FULL_NAME
TT_NAME_ID_VERSION_STRING
TT_NAME_ID_PS_NAME
TT_NAME_ID_TRADEMARK
TT_NAME_ID_MANUFACTURER
TT_NAME_ID_DESIGNER
TT_NAME_ID_DESCRIPTION
TT_NAME_ID_VENDOR_URL
TT_NAME_ID_DESIGNER_URL
TT_NAME_ID_LICENSE
TT_NAME_ID_LICENSE_URL
TT_NAME_ID_PREFERRED_FAMILY
TT_NAME_ID_PREFERRED_SUBFAMILY
TT_NAME_ID_MAC_FULL_NAME
TT_NAME_ID_SAMPLE_TEXT
TT_NAME_ID_CID_FINDFONT_NAME
TT_NAME_ID_WWS_FAMILY
TT_NAME_ID_WWS_SUBFAMILY
"""
TT_NAME_IDS = {
'TT_NAME_ID_COPYRIGHT' : 0,
'TT_NAME_ID_FONT_FAMILY' : 1,
'TT_NAME_ID_FONT_SUBFAMILY' : 2,
'TT_NAME_ID_UNIQUE_ID' : 3,
'TT_NAME_ID_FULL_NAME' : 4,
'TT_NAME_ID_VERSION_STRING' : 5,
'TT_NAME_ID_PS_NAME' : 6,
'TT_NAME_ID_TRADEMARK' : 7,
# the following values are from the OpenType spec
'TT_NAME_ID_MANUFACTURER' : 8,
'TT_NAME_ID_DESIGNER' : 9,
'TT_NAME_ID_DESCRIPTION' : 10,
'TT_NAME_ID_VENDOR_URL' : 11,
'TT_NAME_ID_DESIGNER_URL' : 12,
'TT_NAME_ID_LICENSE' : 13,
'TT_NAME_ID_LICENSE_URL' : 14,
# number 15 is reserved
'TT_NAME_ID_PREFERRED_FAMILY' : 16,
'TT_NAME_ID_PREFERRED_SUBFAMILY' : 17,
'TT_NAME_ID_MAC_FULL_NAME' : 18,
# The following code is new as of 2000-01-21
'TT_NAME_ID_SAMPLE_TEXT' : 19,
# This is new in OpenType 1.3
'TT_NAME_ID_CID_FINDFONT_NAME' : 20,
# This is new in OpenType 1.5
'TT_NAME_ID_WWS_FAMILY' : 21,
'TT_NAME_ID_WWS_SUBFAMILY' : 22 }
globals().update(TT_NAME_IDS)

View File

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
"""
A list of valid values for the 'platform_id' identifier code in FT_CharMapRec
and FT_SfntName structures.
TT_PLATFORM_APPLE_UNICODE
Used by Apple to indicate a Unicode character map and/or name entry. See
TT_APPLE_ID_XXX for corresponding 'encoding_id' values. Note that name
entries in this format are coded as big-endian UCS-2 character codes only.
TT_PLATFORM_MACINTOSH
Used by Apple to indicate a MacOS-specific charmap and/or name entry. See
TT_MAC_ID_XXX for corresponding 'encoding_id' values. Note that most TrueType
fonts contain an Apple roman charmap to be usable on MacOS systems (even if
they contain a Microsoft charmap as well).
TT_PLATFORM_ISO
This value was used to specify ISO/IEC 10646 charmaps. It is however now
deprecated. See TT_ISO_ID_XXX for a list of corresponding 'encoding_id'
values.
TT_PLATFORM_MICROSOFT
Used by Microsoft to indicate Windows-specific charmaps. See TT_MS_ID_XXX for
a list of corresponding 'encoding_id' values. Note that most fonts contain a
Unicode charmap using (TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS).
TT_PLATFORM_CUSTOM
Used to indicate application-specific charmaps.
TT_PLATFORM_ADOBE
This value isn't part of any font format specification, but is used by
FreeType to report Adobe-specific charmaps in an FT_CharMapRec structure. See
TT_ADOBE_ID_XXX.
"""
TT_PLATFORMS = {
'TT_PLATFORM_APPLE_UNICODE' : 0,
'TT_PLATFORM_MACINTOSH' : 1,
'TT_PLATFORM_ISO' : 2, # deprecated
'TT_PLATFORM_MICROSOFT' : 3,
'TT_PLATFORM_CUSTOM' : 4,
'TT_PLATFORM_ADOBE' : 7} # artificial
globals().update(TT_PLATFORMS)

104
freetype/ft_errors.py Normal file
View File

@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
'''
Internal exception with freetype error message
'''
class FT_Exception(Exception):
def __init__(self, errcode, message=''):
self.message = message
self.errcode = errcode
def __str__(self):
return '%s: %s (%s)'%(self.__class__.__name__, self.message,
self._errors.get(self.errcode, 'unknown error'))
_errors = {
0x00: "no error" ,
0x01: "cannot open resource" ,
0x02: "unknown file format" ,
0x03: "broken file" ,
0x04: "invalid FreeType version" ,
0x05: "module version is too low" ,
0x06: "invalid argument" ,
0x07: "unimplemented feature" ,
0x08: "broken table" ,
0x09: "broken offset within table" ,
0x10: "invalid glyph index" ,
0x11: "invalid character code" ,
0x12: "unsupported glyph image format" ,
0x13: "cannot render this glyph format" ,
0x14: "invalid outline" ,
0x15: "invalid composite glyph" ,
0x16: "too many hints" ,
0x17: "invalid pixel size" ,
0x20: "invalid object handle" ,
0x21: "invalid library handle" ,
0x22: "invalid module handle" ,
0x23: "invalid face handle" ,
0x24: "invalid size handle" ,
0x25: "invalid glyph slot handle" ,
0x26: "invalid charmap handle" ,
0x27: "invalid cache manager handle" ,
0x28: "invalid stream handle" ,
0x30: "too many modules" ,
0x31: "too many extensions" ,
0x40: "out of memory" ,
0x41: "unlisted object" ,
0x51: "cannot open stream" ,
0x52: "invalid stream seek" ,
0x53: "invalid stream skip" ,
0x54: "invalid stream read" ,
0x55: "invalid stream operation" ,
0x56: "invalid frame operation" ,
0x57: "nested frame access" ,
0x58: "invalid frame read" ,
0x60: "raster uninitialized" ,
0x61: "raster corrupted" ,
0x62: "raster overflow" ,
0x63: "negative height while rastering" ,
0x70: "too many registered caches" ,
0x80: "invalid opcode" ,
0x81: "too few arguments" ,
0x82: "stack overflow" ,
0x83: "code overflow" ,
0x84: "bad argument" ,
0x85: "division by zero" ,
0x86: "invalid reference" ,
0x87: "found debug opcode" ,
0x88: "found ENDF opcode in execution stream" ,
0x89: "nested DEFS" ,
0x8A: "invalid code range" ,
0x8B: "execution context too long" ,
0x8C: "too many function definitions" ,
0x8D: "too many instruction definitions" ,
0x8E: "SFNT font table missing" ,
0x8F: "horizontal header (hhea, table missing" ,
0x90: "locations (loca, table missing" ,
0x91: "name table missing" ,
0x92: "character map (cmap, table missing" ,
0x93: "horizontal metrics (hmtx, table missing" ,
0x94: "PostScript (post, table missing" ,
0x95: "invalid horizontal metrics" ,
0x96: "invalid character map (cmap, format" ,
0x97: "invalid ppem value" ,
0x98: "invalid vertical metrics" ,
0x99: "could not find context" ,
0x9A: "invalid PostScript (post, table format" ,
0x9B: "invalid PostScript (post, table" ,
0xA0: "opcode syntax error" ,
0xA1: "argument stack underflow" ,
0xA2: "ignore" ,
0xB0: "`STARTFONT' field missing" ,
0xB1: "`FONT' field missing" ,
0xB2: "`SIZE' field missing" ,
0xB3: "`CHARS' field missing" ,
0xB4: "`STARTCHAR' field missing" ,
0xB5: "`ENCODING' field missing" ,
0xB6: "`BBX' field missing" ,
0xB7: "`BBX' too big" ,
}

944
freetype/ft_structs.py Normal file
View File

@ -0,0 +1,944 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
'''
Freetype structured types
-------------------------
FT_Library: A handle to a FreeType library instance.
FT_Vector: A simple structure used to store a 2D vector.
FT_BBox: A structure used to hold an outline's bounding box.
FT_Matrix: A simple structure used to store a 2x2 matrix.
FT_UnitVector: A simple structure used to store a 2D vector unit vector.
FT_Bitmap: A structure used to describe a bitmap or pixmap to the raster.
FT_Data: Read-only binary data represented as a pointer and a length.
FT_Generic: Client applications generic data.
FT_Bitmap_Size: Metrics of a bitmap strike.
FT_Charmap: The base charmap structure.
FT_Glyph_Metrics:A structure used to model the metrics of a single glyph.
FT_Outline: This structure is used to describe an outline to the scan-line
converter.
FT_GlyphSlot: FreeType root glyph slot class structure.
FT_Glyph: The root glyph structure contains a given glyph image plus its
advance width in 16.16 fixed float format.
FT_Size_Metrics: The size metrics structure gives the metrics of a size object.
FT_Size: FreeType root size class structure.
FT_Face: FreeType root face class structure.
FT_Parameter: A simple structure used to pass more or less generic parameters
to FT_Open_Face.
FT_Open_Args: A structure used to indicate how to open a new font file or
stream.
FT_SfntName: A structure used to model an SFNT 'name' table entry.
FT_Stroker: Opaque handler to a path stroker object.
FT_BitmapGlyph: A structure used for bitmap glyph images.
'''
from freetype.ft_types import *
# -----------------------------------------------------------------------------
# A handle to a FreeType library instance. Each 'library' is completely
# independent from the others; it is the 'root' of a set of objects like fonts,
# faces, sizes, etc.
class FT_LibraryRec(Structure):
'''
A handle to a FreeType library instance. Each 'library' is completely
independent from the others; it is the 'root' of a set of objects like
fonts, faces, sizes, etc.
'''
_fields_ = [ ]
FT_Library = POINTER(FT_LibraryRec)
# -----------------------------------------------------------------------------
# A simple structure used to store a 2D vector; coordinates are of the FT_Pos
# type.
class FT_Vector(Structure):
'''
A simple structure used to store a 2D vector; coordinates are of the FT_Pos
type.
x: The horizontal coordinate.
y: The vertical coordinate.
'''
_fields_ = [('x', FT_Pos),
('y', FT_Pos)]
# -----------------------------------------------------------------------------
# A structure used to hold an outline's bounding box, i.e., the coordinates of
# its extrema in the horizontal and vertical directions.
#
# The bounding box is specified with the coordinates of the lower left and the
# upper right corner. In PostScript, those values are often called (llx,lly)
# and (urx,ury), respectively.
#
# If 'yMin' is negative, this value gives the glyph's descender. Otherwise, the
# glyph doesn't descend below the baseline. Similarly, if 'ymax' is positive,
# this value gives the glyph's ascender.
#
# 'xMin' gives the horizontal distance from the glyph's origin to the left edge
# of the glyph's bounding box. If 'xMin' is negative, the glyph extends to the
# left of the origin.
class FT_BBox(Structure):
'''
A structure used to hold an outline's bounding box, i.e., the coordinates
of its extrema in the horizontal and vertical directions.
The bounding box is specified with the coordinates of the lower left and
the upper right corner. In PostScript, those values are often called
(llx,lly) and (urx,ury), respectively.
If 'yMin' is negative, this value gives the glyph's descender. Otherwise,
the glyph doesn't descend below the baseline. Similarly, if 'ymax' is
positive, this value gives the glyph's ascender.
'xMin' gives the horizontal distance from the glyph's origin to the left
edge of the glyph's bounding box. If 'xMin' is negative, the glyph extends
to the left of the origin.
xMin: The horizontal minimum (left-most).
yMin: The vertical minimum (bottom-most).
xMax: The horizontal maximum (right-most).
yMax: The vertical maximum (top-most).
'''
_fields_ = [('xMin', FT_Pos),
('yMin', FT_Pos),
('xMax', FT_Pos),
('yMax', FT_Pos)]
# -----------------------------------------------------------------------------
# A simple structure used to store a 2x2 matrix. Coefficients are in 16.16
# fixed float format. The computation performed is:
# x' = x*xx + y*xy
# y' = x*yx + y*yy
class FT_Matrix(Structure):
'''
A simple structure used to store a 2x2 matrix. Coefficients are in 16.16
fixed float format. The computation performed is:
x' = x*xx + y*xy
y' = x*yx + y*yy
xx: Matrix coefficient.
xy: Matrix coefficient.
yx: Matrix coefficient.
yy: Matrix coefficient.
'''
_fields_ = [('xx', FT_Fixed),
('xy', FT_Fixed),
('yx', FT_Fixed),
('yy', FT_Fixed)]
# -----------------------------------------------------------------------------
# A simple structure used to store a 2D vector unit vector. Uses FT_F2Dot14
# types.
class FT_UnitVector(Structure):
'''
A simple structure used to store a 2D vector unit vector. Uses FT_F2Dot14
types.
x: The horizontal coordinate.
y: The vertical coordinate.
'''
_fields_ = [('x', FT_F2Dot14),
('y', FT_F2Dot14)]
# -----------------------------------------------------------------------------
# A structure used to describe a bitmap or pixmap to the raster. Note that we
# now manage pixmaps of various depths through the 'pixel_mode' field.
class FT_Bitmap(Structure):
'''
A structure used to describe a bitmap or pixmap to the raster. Note that we
now manage pixmaps of various depths through the 'pixel_mode' field.
rows: The number of bitmap rows.
width: The number of pixels in bitmap row.
pitch: The pitch's absolute value is the number of bytes taken by one
bitmap row, including padding. However, the pitch is positive when
the bitmap has a 'down' flow, and negative when it has an 'up'
flow. In all cases, the pitch is an offset to add to a bitmap
pointer in order to go down one row.
Note that 'padding' means the alignment of a bitmap to a byte
border, and FreeType functions normally align to the smallest
possible integer value.
For the B/W rasterizer, 'pitch' is always an even number.
To change the pitch of a bitmap (say, to make it a multiple of 4),
use FT_Bitmap_Convert. Alternatively, you might use callback
functions to directly render to the application's surface; see the
file 'example2.py' in the tutorial for a demonstration.
buffer: A typeless pointer to the bitmap buffer. This value should be
aligned on 32-bit boundaries in most cases.
num_grays: This field is only used with FT_PIXEL_MODE_GRAY; it gives the
number of gray levels used in the bitmap.
pixel_mode: The pixel mode, i.e., how pixel bits are stored. See
FT_Pixel_Mode for possible values.
palette_mode: This field is intended for paletted pixel modes; it indicates
how the palette is stored. Not used currently.
palette: A typeless pointer to the bitmap palette; this field is intended
for paletted pixel modes. Not used currently.
'''
_fields_ = [
('rows', c_int),
('width', c_int),
('pitch', c_int),
# declaring buffer as c_char_p confuses ctypes
('buffer', POINTER(c_ubyte)),
('num_grays', c_short),
('pixel_mode', c_ubyte),
('palette_mode', c_char),
('palette', c_void_p) ]
# -----------------------------------------------------------------------------
# Read-only binary data represented as a pointer and a length.
class FT_Data(Structure):
'''
Read-only binary data represented as a pointer and a length.
pointer: The data.
length: The length of the data in bytes.
'''
_fields_ = [('pointer', POINTER(FT_Byte)),
('y', FT_Int)]
# -----------------------------------------------------------------------------
# Client applications often need to associate their own data to a variety of
# FreeType core objects. For example, a text layout API might want to associate
# a glyph cache to a given size object.
#
# Most FreeType object contains a 'generic' field, of type FT_Generic, which
# usage is left to client applications and font servers.
#
# It can be used to store a pointer to client-specific data, as well as the
# address of a 'finalizer' function, which will be called by FreeType when the
# object is destroyed (for example, the previous client example would put the
# address of the glyph cache destructor in the 'finalizer' field).
class FT_Generic(Structure):
'''
Client applications often need to associate their own data to a variety of
FreeType core objects. For example, a text layout API might want to
associate a glyph cache to a given size object.
Most FreeType object contains a 'generic' field, of type FT_Generic, which
usage is left to client applications and font servers.
It can be used to store a pointer to client-specific data, as well as the
address of a 'finalizer' function, which will be called by FreeType when
the object is destroyed (for example, the previous client example would put
the address of the glyph cache destructor in the 'finalizer' field).
data: A typeless pointer to any client-specified data. This field is
completely ignored by the FreeType library.
finalizer: A pointer to a 'generic finalizer' function, which will be
called when the object is destroyed. If this field is set to
NULL, no code will be called.
'''
_fields_ = [('data', c_void_p),
('finalizer', FT_Generic_Finalizer)]
# -----------------------------------------------------------------------------
# This structure models the metrics of a bitmap strike (i.e., a set of glyphs
# for a given point size and resolution) in a bitmap font. It is used for the
# 'available_sizes' field of FT_Face.
class FT_Bitmap_Size(Structure):
'''
This structure models the metrics of a bitmap strike (i.e., a set of glyphs
for a given point size and resolution) in a bitmap font. It is used for the
'available_sizes' field of FT_Face.
height: The vertical distance, in pixels, between two consecutive
baselines. It is always positive.
width: The average width, in pixels, of all glyphs in the strike.
size: The nominal size of the strike in 26.6 fractional points. This field
is not very useful.
x_ppem: The horizontal ppem (nominal width) in 26.6 fractional pixels.
y_ppem: The vertical ppem (nominal height) in 26.6 fractional pixels.
'''
_fields_ = [
('height', FT_Short),
('width', FT_Short),
('size', FT_Pos),
('x_ppem', FT_Pos),
('y_ppem', FT_Pos) ]
# -----------------------------------------------------------------------------
# The base charmap structure.
class FT_CharmapRec(Structure):
'''
The base charmap structure.
face : A handle to the parent face object.
encoding : An FT_Encoding tag identifying the charmap. Use this with
FT_Select_Charmap.
platform_id: An ID number describing the platform for the following
encoding ID. This comes directly from the TrueType
specification and should be emulated for other formats.
encoding_id: A platform specific encoding number. This also comes from the
TrueType specification and should be emulated similarly.
'''
_fields_ = [
('face', c_void_p), # Shoudl be FT_Face
('encoding', FT_Encoding),
('platform_id', FT_UShort),
('encoding_id', FT_UShort),
]
FT_Charmap = POINTER(FT_CharmapRec)
# -----------------------------------------------------------------------------
# A structure used to model the metrics of a single glyph. The values are
# expressed in 26.6 fractional pixel format; if the flag FT_LOAD_NO_SCALE has
# been used while loading the glyph, values are expressed in font units
# instead.
class FT_Glyph_Metrics(Structure):
'''
A structure used to model the metrics of a single glyph. The values are
expressed in 26.6 fractional pixel format; if the flag FT_LOAD_NO_SCALE has
been used while loading the glyph, values are expressed in font units
instead.
width: The glyph's width.
height: The glyph's height.
horiBearingX: Left side bearing for horizontal layout.
horiBearingY: Top side bearing for horizontal layout.
horiAdvance: Advance width for horizontal layout.
vertBearingX: Left side bearing for vertical layout.
vertBearingY: Top side bearing for vertical layout.
vertAdvance: Advance height for vertical layout.
'''
_fields_ = [
('width', FT_Pos),
('height', FT_Pos),
('horiBearingX', FT_Pos),
('horiBearingY', FT_Pos),
('horiAdvance', FT_Pos),
('vertBearingX', FT_Pos),
('vertBearingY', FT_Pos),
('vertAdvance', FT_Pos),
]
# -----------------------------------------------------------------------------
# This structure is used to describe an outline to the scan-line converter.
class FT_Outline(Structure):
'''
This structure is used to describe an outline to the scan-line converter.
n_contours: The number of contours in the outline.
n_points: The number of points in the outline.
points: A pointer to an array of 'n_points' FT_Vector elements, giving the
outline's point coordinates.
tags: A pointer to an array of 'n_points' chars, giving each outline
point's type.
If bit 0 is unset, the point is 'off' the curve, i.e., a Bezier
control point, while it is 'on' if set.
Bit 1 is meaningful for 'off' points only. If set, it indicates a
third-order Bezier arc control point; and a second-order control
point if unset.
If bit 2 is set, bits 5-7 contain the drop-out mode (as defined in
the OpenType specification; the value is the same as the argument to
the SCANMODE instruction).
Bits 3 and 4 are reserved for internal purposes.
contours: An array of 'n_contours' shorts, giving the end point of each
contour within the outline. For example, the first contour is
defined by the points '0' to 'contours[0]', the second one is
defined by the points 'contours[0]+1' to 'contours[1]', etc.
flags: A set of bit flags used to characterize the outline and give hints
to the scan-converter and hinter on how to convert/grid-fit it. See
FT_OUTLINE_FLAGS.
'''
_fields_ = [
('n_contours', c_short),
('n_points', c_short),
('points', POINTER(FT_Vector)),
# declaring buffer as c_char_p would prevent us to acces all tags
('tags', POINTER(c_ubyte)),
('contours', POINTER(c_short)),
('flags', c_int),
]
# -----------------------------------------------------------------------------
# The root glyph structure contains a given glyph image plus its advance width
# in 16.16 fixed float format.
class FT_GlyphRec(Structure):
'''
The root glyph structure contains a given glyph image plus its advance
width in 16.16 fixed float format.
library: A handle to the FreeType library object.
clazz: A pointer to the glyph's class. Private.
format: The format of the glyph's image.
advance: A 16.16 vector that gives the glyph's advance width.
'''
_fields_ = [
('library', FT_Library),
('clazz', c_void_p),
('format', FT_Glyph_Format),
('advance', FT_Vector)
]
FT_Glyph = POINTER(FT_GlyphRec)
# -----------------------------------------------------------------------------
# FreeType root glyph slot class structure. A glyph slot is a container where
# individual glyphs can be loaded, be they in outline or bitmap format.
class FT_GlyphSlotRec(Structure):
'''
FreeType root glyph slot class structure. A glyph slot is a container where
individual glyphs can be loaded, be they in outline or bitmap format.
library: A handle to the FreeType library instance this slot belongs to.
face: A handle to the parent face object.
next: In some cases (like some font tools), several glyph slots per face
object can be a good thing. As this is rare, the glyph slots are
listed through a direct, single-linked list using its 'next' field.
generic: A typeless pointer which is unused by the FreeType library or any
of its drivers. It can be used by client applications to link
their own data to each glyph slot object.
metrics: The metrics of the last loaded glyph in the slot. The returned
values depend on the last load flags (see the FT_Load_Glyph API
function) and can be expressed either in 26.6 fractional pixels or
font units.
Note that even when the glyph image is transformed, the metrics
are not.
linearHoriAdvance: The advance width of the unhinted glyph. Its value is
expressed in 16.16 fractional pixels, unless
FT_LOAD_LINEAR_DESIGN is set when loading the
glyph. This field can be important to perform correct
WYSIWYG layout. Only relevant for outline glyphs.
linearVertAdvance: The advance height of the unhinted glyph. Its value is
expressed in 16.16 fractional pixels, unless
FT_LOAD_LINEAR_DESIGN is set when loading the
glyph. This field can be important to perform correct
WYSIWYG layout. Only relevant for outline glyphs.
advance: This shorthand is, depending on FT_LOAD_IGNORE_TRANSFORM, the
transformed advance width for the glyph (in 26.6 fractional pixel
format). As specified with FT_LOAD_VERTICAL_LAYOUT, it uses either
the 'horiAdvance' or the 'vertAdvance' value of 'metrics' field.
format: This field indicates the format of the image contained in the glyph
slot. Typically FT_GLYPH_FORMAT_BITMAP, FT_GLYPH_FORMAT_OUTLINE, or
FT_GLYPH_FORMAT_COMPOSITE, but others are possible.
bitmap: This field is used as a bitmap descriptor when the slot format is
FT_GLYPH_FORMAT_BITMAP. Note that the address and content of the
bitmap buffer can change between calls of FT_Load_Glyph and a few
other functions.
bitmap_left: This is the bitmap's left bearing expressed in integer
pixels. Of course, this is only valid if the format is
FT_GLYPH_FORMAT_BITMAP.
bitmap_top: This is the bitmap's top bearing expressed in integer
pixels. Remember that this is the distance from the baseline to
the top-most glyph scanline, upwards y coordinates being
positive.
outline: The outline descriptor for the current glyph image if its format
is FT_GLYPH_FORMAT_OUTLINE. Once a glyph is loaded, 'outline' can
be transformed, distorted, embolded, etc. However, it must not be
freed.
num_subglyphs: The number of subglyphs in a composite glyph. This field is
only valid for the composite glyph format that should
normally only be loaded with the FT_LOAD_NO_RECURSE
flag. For now this is internal to FreeType.
subglyphs: An array of subglyph descriptors for composite glyphs. There are
'num_subglyphs' elements in there. Currently internal to
FreeType.
control_data: Certain font drivers can also return the control data for a
given glyph image (e.g. TrueType bytecode, Type 1
charstrings, etc.). This field is a pointer to such data.
control_len: This is the length in bytes of the control data.
other: Really wicked formats can use this pointer to present their own
glyph image to client applications. Note that the application needs
to know about the image format.
lsb_delta: The difference between hinted and unhinted left side bearing
while autohinting is active. Zero otherwise.
rsb_delta: The difference between hinted and unhinted right side bearing
while autohinting is active. Zero otherwise.
'''
_fields_ = [
('library', FT_Library),
('face', c_void_p),
('next', c_void_p),
('reserved', c_uint),
('generic', FT_Generic),
('metrics', FT_Glyph_Metrics),
('linearHoriAdvance', FT_Fixed),
('linearVertAdvance', FT_Fixed),
('advance', FT_Vector),
('format', FT_Glyph_Format),
('bitmap', FT_Bitmap),
('bitmap_left', FT_Int),
('bitmap_top', FT_Int),
('outline', FT_Outline),
('num_subglyphs', FT_UInt),
('subglyphs', c_void_p),
('control_data', c_void_p),
('control_len', c_long),
('lsb_delta', FT_Pos),
('rsb_delta', FT_Pos),
('other', c_void_p),
('internal', c_void_p),
]
FT_GlyphSlot = POINTER(FT_GlyphSlotRec)
# -----------------------------------------------------------------------------
# The size metrics structure gives the metrics of a size object.
class FT_Size_Metrics(Structure):
'''
The size metrics structure gives the metrics of a size object.
x_ppem: The width of the scaled EM square in pixels, hence the term 'ppem'
(pixels per EM). It is also referred to as 'nominal width'.
y_ppem: The height of the scaled EM square in pixels, hence the term 'ppem'
(pixels per EM). It is also referred to as 'nominal height'.
x_scale: A 16.16 fractional scaling value used to convert horizontal
metrics from font units to 26.6 fractional pixels. Only relevant
for scalable font formats.
y_scale: A 16.16 fractional scaling value used to convert vertical metrics
from font units to 26.6 fractional pixels. Only relevant for
scalable font formats.
ascender: The ascender in 26.6 fractional pixels. See FT_FaceRec for the
details.
descender: The descender in 26.6 fractional pixels. See FT_FaceRec for the
details.
height: The height in 26.6 fractional pixels. See FT_FaceRec for the
details.
max_advance: The maximal advance width in 26.6 fractional pixels. See
FT_FaceRec for the details.
'''
_fields_ = [
('x_ppem', FT_UShort),
('y_ppem', FT_UShort),
('x_scale', FT_Fixed),
('y_scale', FT_Fixed),
('ascender', FT_Pos),
('descender', FT_Pos),
('height', FT_Pos),
('max_advance', FT_Pos),
]
# -----------------------------------------------------------------------------
# FreeType root size class structure. A size object models a face object at a
# given size.
class FT_SizeRec(Structure):
'''
FreeType root size class structure. A size object models a face object at a
given size.
face: Handle to the parent face object.
generic: A typeless pointer, which is unused by the FreeType library or any
of its drivers. It can be used by client applications to link
their own data to each size object.
metrics: Metrics for this size object. This field is read-only.
'''
_fields_ = [
('face', c_void_p),
('generic', FT_Generic),
('metrics', FT_Size_Metrics),
('internal', c_void_p),
]
FT_Size = POINTER(FT_SizeRec)
# -----------------------------------------------------------------------------
# FreeType root face class structure. A face object models a typeface in a font
# file.
class FT_FaceRec(Structure):
'''
FreeType root face class structure. A face object models a typeface in a
font file.
num_faces: The number of faces in the font file. Some font formats can have
multiple faces in a font file.
face_index: The index of the face in the font file. It is set to 0 if there
is only one face in the font file.
face_flags: A set of bit flags that give important information about the
face; see FT_FACE_FLAG_XXX for the details.
style_flags: A set of bit flags indicating the style of the face; see
FT_STYLE_FLAG_XXX for the details.
num_glyphs: The number of glyphs in the face. If the face is scalable and
has sbits (see 'num_fixed_sizes'), it is set to the number of
outline glyphs.
For CID-keyed fonts, this value gives the highest CID used in
the font.
family_name: The face's family name. This is an ASCII string, usually in
English, which describes the typeface's family (like 'Times
New Roman', 'Bodoni', 'Garamond', etc). This is a least common
denominator used to list fonts. Some formats (TrueType &
OpenType) provide localized and Unicode versions of this
string. Applications should use the format specific interface
to access them. Can be NULL (e.g., in fonts embedded in a PDF
file).
style_name: The face's style name. This is an ASCII string, usually in
English, which describes the typeface's style (like 'Italic',
'Bold', 'Condensed', etc). Not all font formats provide a style
name, so this field is optional, and can be set to NULL. As for
'family_name', some formats provide localized and Unicode
versions of this string. Applications should use the format
specific interface to access them.
num_fixed_sizes: The number of bitmap strikes in the face. Even if the face
is scalable, there might still be bitmap strikes, which
are called 'sbits' in that case.
available_sizes: An array of FT_Bitmap_Size for all bitmap strikes in the
face. It is set to NULL if there is no bitmap strike.
num_charmaps: The number of charmaps in the face.
charmaps: An array of the charmaps of the face.
generic: A field reserved for client uses. See the FT_Generic type
description.
bbox: The font bounding box. Coordinates are expressed in font units (see
'units_per_EM'). The box is large enough to contain any glyph from
the font. Thus, 'bbox.yMax' can be seen as the 'maximal ascender',
and 'bbox.yMin' as the 'minimal descender'. Only relevant for
scalable formats.
Note that the bounding box might be off by (at least) one pixel for
hinted fonts. See FT_Size_Metrics for further discussion.
units_per_EM: The number of font units per EM square for this face. This is
typically 2048 for TrueType fonts, and 1000 for Type 1
fonts. Only relevant for scalable formats.
ascender: The typographic ascender of the face, expressed in font
units. For font formats not having this information, it is set to
'bbox.yMax'. Only relevant for scalable formats.
descender: The typographic descender of the face, expressed in font
units. For font formats not having this information, it is set
to 'bbox.yMin'. Note that this field is usually negative. Only
relevant for scalable formats.
height: The height is the vertical distance between two consecutive
baselines, expressed in font units. It is always positive. Only
relevant for scalable formats.
max_advance_width: The maximal advance width, in font units, for all glyphs
in this face. This can be used to make word wrapping
computations faster. Only relevant for scalable formats.
max_advance_height: The maximal advance height, in font units, for all
glyphs in this face. This is only relevant for vertical
layouts, and is set to 'height' for fonts that do not
provide vertical metrics. Only relevant for scalable
formats.
underline_position: The position, in font units, of the underline line for
this face. It is the center of the underlining
stem. Only relevant for scalable formats.
underline_thickness: The thickness, in font units, of the underline for
this face. Only relevant for scalable formats.
glyph: The face's associated glyph slot(s).
size: The current active size for this face.
charmap: The current active charmap for this face.
'''
_fields_ = [
('num_faces', FT_Long),
('face_index', FT_Long),
('face_flags', FT_Long),
('style_flags', FT_Long),
('num_glyphs', FT_Long),
('family_name', FT_String_p),
('style_name', FT_String_p),
('num_fixed_sizes', FT_Int),
('available_sizes', POINTER(FT_Bitmap_Size)),
('num_charmaps', c_int),
('charmaps', POINTER(FT_Charmap)),
('generic', FT_Generic),
# The following member variables (down to `underline_thickness')
# are only relevant to scalable outlines; cf. @FT_Bitmap_Size
# for bitmap fonts.
('bbox', FT_BBox),
('units_per_EM', FT_UShort),
('ascender', FT_Short),
('descender', FT_Short),
('height', FT_Short),
('max_advance_width', FT_Short),
('max_advance_height', FT_Short),
('underline_position', FT_Short),
('underline_thickness', FT_Short),
('glyph', FT_GlyphSlot),
('size', FT_Size),
('charmap', FT_Charmap),
# private
('driver', c_void_p),
('memory', c_void_p),
('stream', c_void_p),
('sizes_list_head', c_void_p),
('sizes_list_tail', c_void_p),
('autohint', FT_Generic),
('extensions', c_void_p),
('internal', c_void_p),
]
FT_Face = POINTER(FT_FaceRec)
# -----------------------------------------------------------------------------
# A simple structure used to pass more or less generic parameters to
# FT_Open_Face.
class FT_Parameter(Structure):
'''
A simple structure used to pass more or less generic parameters to
FT_Open_Face.
tag: A four-byte identification tag.
data: A pointer to the parameter data
'''
_fields_ = [
('tag', FT_ULong),
('data', FT_Pointer) ]
FT_Parameter_p = POINTER(FT_Parameter)
# -----------------------------------------------------------------------------
# A structure used to indicate how to open a new font file or stream. A pointer
# to such a structure can be used as a parameter for the functions FT_Open_Face
# and FT_Attach_Stream.
class FT_Open_Args(Structure):
'''
A structure used to indicate how to open a new font file or stream. A pointer
to such a structure can be used as a parameter for the functions FT_Open_Face
and FT_Attach_Stream.
flags: A set of bit flags indicating how to use the structure.
memory_base: The first byte of the file in memory.
memory_size: The size in bytes of the file in memory.
pathname: A pointer to an 8-bit file pathname.
stream: A handle to a source stream object.
driver: This field is exclusively used by FT_Open_Face; it simply specifies
the font driver to use to open the face. If set to 0, FreeType
tries to load the face with each one of the drivers in its list.
num_params: The number of extra parameters.
params: Extra parameters passed to the font driver when opening a new face.
'''
_fields_ = [
('flags', FT_UInt),
('memory_base', POINTER(FT_Byte)),
('memory_size', FT_Long),
('pathname', FT_String_p),
('stream', c_void_p),
('driver', c_void_p),
('num_params', FT_Int),
('params', FT_Parameter_p) ]
# -----------------------------------------------------------------------------
# A structure used to model an SFNT 'name' table entry.
class FT_SfntName(Structure):
'''
platform_id: The platform ID for 'string'.
encoding_id: The encoding ID for 'string'.
language_id: The language ID for 'string'
name_id: An identifier for 'string'
string: The 'name' string. Note that its format differs depending on the
(platform,encoding) pair. It can be a Pascal String, a UTF-16 one,
etc.
Generally speaking, the string is not zero-terminated. Please refer
to the TrueType specification for details.
string_len: The length of 'string' in bytes.
'''
_fields_ = [
('platform_id', FT_UShort),
('encoding_id', FT_UShort),
('language_id', FT_UShort),
('name_id', FT_UShort),
# this string is *not* null-terminated!
('string', POINTER(FT_Byte)),
('string_len', FT_UInt) ]
# -----------------------------------------------------------------------------
# Opaque handler to a path stroker object.
class FT_StrokerRec(Structure):
'''
Opaque handler to a path stroker object.
'''
_fields_ = [ ]
FT_Stroker = POINTER(FT_StrokerRec)
# -----------------------------------------------------------------------------
# A structure used for bitmap glyph images. This really is a 'sub-class' of
# FT_GlyphRec.
#
class FT_BitmapGlyphRec(Structure):
'''
A structure used for bitmap glyph images. This really is a 'sub-class' of
FT_GlyphRec.
'''
_fields_ = [
('root' , FT_GlyphRec),
('left', FT_Int),
('top', FT_Int),
('bitmap', FT_Bitmap)
]
FT_BitmapGlyph = POINTER(FT_BitmapGlyphRec)

155
freetype/ft_types.py Normal file
View File

@ -0,0 +1,155 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
#
# FreeType high-level python API - Copyright 2011 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
#
# -----------------------------------------------------------------------------
'''
Freetype basic data types
-------------------------
FT_Byte : A simple typedef for the unsigned char type.
FT_Bytes : A typedef for constant memory areas.
FT_Char : A simple typedef for the signed char type.
FT_Int : A typedef for the int type.
FT_UInt : A typedef for the unsigned int type.
FT_Int16 : A typedef for a 16bit signed integer type.
FT_UInt16 : A typedef for a 16bit unsigned integer type.
FT_Int32 : A typedef for a 32bit signed integer type.
FT_UInt32 : A typedef for a 32bit unsigned integer type.
FT_Short : A typedef for signed short.
FT_UShort : A typedef for unsigned short.
FT_Long : A typedef for signed long.
FT_ULong : A typedef for unsigned long.
FT_Bool : A typedef of unsigned char, used for simple booleans. As usual,
values 1 and 0 represent true and false, respectively.
FT_Offset : This is equivalent to the ANSI C 'size_t' type, i.e., the largest
unsigned integer type used to express a file size or position, or
a memory block size.
FT_PtrDist : This is equivalent to the ANSI C 'ptrdiff_t' type, i.e., the
largest signed integer type used to express the distance between
two pointers.
FT_String : A simple typedef for the char type, usually used for strings.
FT_Tag : A typedef for 32-bit tags (as used in the SFNT format).
FT_Error : The FreeType error code type. A value of 0 is always interpreted as
a successful operation.
FT_Fixed : This type is used to store 16.16 fixed float values, like scaling
values or matrix coefficients.
FT_Pointer : A simple typedef for a typeless pointer.
FT_Pos : The type FT_Pos is used to store vectorial coordinates. Depending on
the context, these can represent distances in integer font units, or
16.16, or 26.6 fixed float pixel coordinates.
FT_FWord : A signed 16-bit integer used to store a distance in original font
units.
FT_UFWord : An unsigned 16-bit integer used to store a distance in original
font units.
FT_F2Dot14 : A signed 2.14 fixed float type used for unit vectors.
FT_F26Dot6 : A signed 26.6 fixed float type used for vectorial pixel
coordinates.
'''
from ctypes import *
FT_Byte = c_ubyte # A simple typedef for the unsigned char type.
FT_Bytes = c_char_p # A typedef for constant memory areas.
FT_Char = c_char # A simple typedef for the signed char type.
FT_Int = c_int # A typedef for the int type.
FT_UInt = c_uint # A typedef for the unsigned int type.
FT_Int16 = c_short # A typedef for a 16bit signed integer type.
FT_UInt16 = c_ushort # A typedef for a 16bit unsigned integer type.
FT_Int32 = c_int32 # A typedef for a 32bit signed integer type.
FT_UInt32 = c_uint32 # A typedef for a 32bit unsigned integer type.
FT_Short = c_short # A typedef for signed short.
FT_UShort = c_ushort # A typedef for unsigned short.
FT_Long = c_long # A typedef for signed long.
FT_ULong = c_ulong # A typedef for unsigned long.
FT_Bool = c_char # A typedef of unsigned char, used for simple booleans. As
# usual, values 1 and 0 represent true and false,
# respectively.
FT_Offset = c_size_t # This is equivalent to the ANSI C 'size_t' type, i.e.,
# the largest unsigned integer type used to express a file
# size or position, or a memory block size.
FT_PtrDist = c_longlong # This is equivalent to the ANSI C 'ptrdiff_t' type,
# i.e., the largest signed integer type used to express
# the distance between two pointers.
FT_String = c_char # A simple typedef for the char type, usually used for strings.
FT_String_p= c_char_p
FT_Tag = FT_UInt32 # A typedef for 32-bit tags (as used in the SFNT format).
FT_Error = c_int # The FreeType error code type. A value of 0 is always
# interpreted as a successful operation.
FT_Fixed = c_long # This type is used to store 16.16 fixed float values,
# like scaling values or matrix coefficients.
FT_Pointer = c_void_p # A simple typedef for a typeless pointer.
FT_Pos = c_long # The type FT_Pos is used to store vectorial
# coordinates. Depending on the context, these can
# represent distances in integer font units, or 16.16, or
# 26.6 fixed float pixel coordinates.
FT_FWord = c_short # A signed 16-bit integer used to store a distance in
# original font units.
FT_UFWord = c_ushort # An unsigned 16-bit integer used to store a distance in
# original font units.
FT_F2Dot14 = c_short # A signed 2.14 fixed float type used for unit vectors.
FT_F26Dot6 = c_long # A signed 26.6 fixed float type used for vectorial pixel
# coordinates.
FT_Glyph_Format = c_int
FT_Encoding = c_int
# Describe a function used to destroy the 'client' data of any FreeType
# object. See the description of the FT_Generic type for details of usage.
FT_Generic_Finalizer = CFUNCTYPE(None, c_void_p)

128
freetype/raw.py Normal file
View File

@ -0,0 +1,128 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier
# Distributed under the terms of the new BSD license.
# -----------------------------------------------------------------------------
'''
Freetype raw API
This is the raw ctypes freetype binding.
'''
import os
import platform
from ctypes import *
import ctypes.util
from freetype.ft_types import *
from freetype.ft_enums import *
from freetype.ft_errors import *
from freetype.ft_structs import *
# on windows all ctypes does when checking for the library
# is to append .dll to the end and look for an exact match
# within any entry in PATH.
filename = ctypes.util.find_library('freetype')
if filename is None:
if platform.system() == 'Windows':
# Check current working directory for dll as ctypes fails to do so
filename = os.path.join(os.path.realpath('.'), 'freetype.dll')
else:
filename = 'libfreetype.so.6'
try:
_lib = ctypes.CDLL(filename)
except (OSError, TypeError):
_lib = None
raise RuntimeError('Freetype library not found')
FT_Init_FreeType = _lib.FT_Init_FreeType
FT_Done_FreeType = _lib.FT_Done_FreeType
FT_Library_Version = _lib.FT_Library_Version
try:
FT_Library_SetLcdFilter= _lib.FT_Library_SetLcdFilter
except AttributeError:
def FT_Library_SetLcdFilter (*args, **kwargs):
return 0
try:
FT_Library_SetLcdFilterWeights = _lib.FT_Library_SetLcdFilterWeights
except AttributeError:
pass
FT_New_Face = _lib.FT_New_Face
FT_New_Memory_Face = _lib.FT_New_Memory_Face
FT_Open_Face = _lib.FT_Open_Face
FT_Attach_File = _lib.FT_Attach_File
FT_Attach_Stream = _lib.FT_Attach_Stream
try:
FT_Reference_Face = _lib.FT_Reference_Face
except AttributeError:
pass
FT_Done_Face = _lib.FT_Done_Face
FT_Done_Glyph = _lib.FT_Done_Glyph
FT_Select_Size = _lib.FT_Select_Size
FT_Request_Size = _lib.FT_Request_Size
FT_Set_Char_Size = _lib.FT_Set_Char_Size
FT_Set_Pixel_Sizes = _lib.FT_Set_Pixel_Sizes
FT_Load_Glyph = _lib.FT_Load_Glyph
FT_Load_Char = _lib.FT_Load_Char
FT_Set_Transform = _lib.FT_Set_Transform
FT_Render_Glyph = _lib.FT_Render_Glyph
FT_Get_Kerning = _lib.FT_Get_Kerning
FT_Get_Track_Kerning = _lib.FT_Get_Track_Kerning
FT_Get_Glyph_Name = _lib.FT_Get_Glyph_Name
FT_Get_Glyph = _lib.FT_Get_Glyph
FT_Glyph_Get_CBox = _lib.FT_Glyph_Get_CBox
FT_Get_Postscript_Name = _lib.FT_Get_Postscript_Name
FT_Get_Postscript_Name.restype = c_char_p
FT_Select_Charmap = _lib.FT_Select_Charmap
FT_Set_Charmap = _lib.FT_Set_Charmap
FT_Get_Charmap_Index = _lib.FT_Get_Charmap_Index
FT_Get_CMap_Language_ID= _lib.FT_Get_CMap_Language_ID
FT_Get_CMap_Format = _lib.FT_Get_CMap_Format
FT_Get_Char_Index = _lib.FT_Get_Char_Index
FT_Get_First_Char = _lib.FT_Get_First_Char
FT_Get_Next_Char = _lib.FT_Get_Next_Char
FT_Get_Name_Index = _lib.FT_Get_Name_Index
FT_Get_SubGlyph_Info = _lib.FT_Get_SubGlyph_Info
try:
FT_Get_FSType_Flags = _lib.FT_Get_FSType_Flags
FT_Get_FSType_Flags.restype = c_ushort
except AttributeError:
pass
FT_Get_X11_Font_Format = _lib.FT_Get_X11_Font_Format
FT_Get_X11_Font_Format.restype = c_char_p
FT_Get_Sfnt_Name_Count = _lib.FT_Get_Sfnt_Name_Count
FT_Get_Sfnt_Name = _lib.FT_Get_Sfnt_Name
FT_Get_Advance = _lib.FT_Get_Advance
FT_Outline_GetInsideBorder = _lib.FT_Outline_GetInsideBorder
FT_Outline_GetOutsideBorder = _lib.FT_Outline_GetOutsideBorder
FT_Outline_Get_BBox = _lib.FT_Outline_Get_BBox
FT_Outline_Get_CBox = _lib.FT_Outline_Get_CBox
FT_Stroker_New = _lib.FT_Stroker_New
FT_Stroker_Set = _lib.FT_Stroker_Set
FT_Stroker_Rewind = _lib.FT_Stroker_Rewind
FT_Stroker_ParseOutline = _lib.FT_Stroker_ParseOutline
FT_Stroker_BeginSubPath = _lib.FT_Stroker_BeginSubPath
FT_Stroker_EndSubPath = _lib.FT_Stroker_EndSubPath
FT_Stroker_LineTo = _lib.FT_Stroker_LineTo
FT_Stroker_ConicTo = _lib.FT_Stroker_ConicTo
FT_Stroker_CubicTo = _lib.FT_Stroker_CubicTo
FT_Stroker_GetBorderCounts = _lib.FT_Stroker_GetBorderCounts
FT_Stroker_ExportBorder = _lib.FT_Stroker_ExportBorder
FT_Stroker_GetCounts = _lib.FT_Stroker_GetCounts
FT_Stroker_Export = _lib.FT_Stroker_Export
FT_Stroker_Done = _lib.FT_Stroker_Done
FT_Glyph_Stroke = _lib.FT_Glyph_Stroke
FT_Glyph_StrokeBorder = _lib.FT_Glyph_StrokeBorder
FT_Glyph_To_Bitmap = _lib.FT_Glyph_To_Bitmap

14
glfw.py
View File

@ -36,6 +36,7 @@
import os
import ctypes.util
from collections import namedtuple
from ctypes import (Structure, POINTER, CFUNCTYPE, byref, c_char_p, c_int,
c_uint, c_double, c_float, c_ushort)
@ -580,15 +581,14 @@ def glfwGetMonitorPhysicalSize(monitor):
return width.value, height.value
VideoMode = namedtuple('VideoMode', 'width height redBits blueBits greenBits refreshRate')
def glfwGetVideoMode(monitor):
_glfw.glfwGetVideoMode.restype = POINTER(GLFWvidmode)
c_mode = _glfw.glfwGetVideoMode(monitor)
return (c_mode.width,
c_mode.height,
c_mode.redBits,
c_mode.blueBits,
c_mode.greenBits,
c_mode.refreshRate)
c_mode = _glfw.glfwGetVideoMode(monitor).contents
return VideoMode(
c_mode.width, c_mode.height, c_mode.redBits, c_mode.blueBits, c_mode.greenBits, c_mode.refreshRate)
def GetGammaRamp(monitor):

View File

@ -52,7 +52,7 @@ class Boss(Thread):
def on_wakeup(self):
try:
os.read(self.read_wakeup_fd, 1024)
except Exception:
except (EnvironmentError, BlockingIOError):
pass
buf = b''
while True:
@ -96,6 +96,8 @@ class Boss(Thread):
return
try:
data = os.read(self.child_fd, io.DEFAULT_BUFFER_SIZE)
except BlockingIOError:
return
except EnvironmentError:
data = b''
if not data:

View File

@ -6,6 +6,9 @@ import re
from collections import namedtuple
from typing import Tuple
from .fonts import validate_monospace_font
key_pat = re.compile(r'([a-zA-Z][a-zA-Z0-9_-]*)\s+(.+)$')
# Color definitions {{{
color_pat = re.compile(r'^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$')
@ -203,7 +206,9 @@ type_map = {
'cursor_opacity': float,
'cursor_shape': to_cursor_shape,
'cursor_blink': to_bool,
'font_family': validate_monospace_font,
}
for name in 'foreground foreground_bold background cursor'.split():
type_map[name] = lambda x: to_color(x, validate=True)
for i in range(16):
@ -215,7 +220,6 @@ term xterm-kitty
foreground #dddddd
foreground_bold #ffffff
cursor #eeeeee
cursor_opacity 1.0
cursor_shape block
cursor_blink no
background #000000
@ -293,11 +297,6 @@ def load_config(path: str) -> Options:
return Options(**ans)
def validate_font(opts: Options):
if False: # TODO: Implement this
raise ValueError('The font specified in the configuration "{}" is not a monospace font'.format(opts.font_family))
def build_ansi_color_tables(opts: Options) -> Tuple[dict, dict]:
def col(i):
return getattr(opts, 'color{}'.format(i))

53
kitty/fonts.py Normal file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import subprocess
import re
from freetype import Face
def escape_family_name(name):
return re.sub(r'([-:,\\])', lambda m: '\\' + m.group(1), name)
def fc_match(q, bold=False, italic=False):
q = escape_family_name(q)
if bold:
q += ':bold=200'
if italic:
q += ':slant=100'
return subprocess.check_output(['fc-match', q, '-f', '%{file}']).decode('utf-8')
def validate_monospace_font(raw_name):
raw = fc_match(raw_name)
if not raw:
raise ValueError('Failed to find a font matching the name: {}'.format(raw_name))
f = Face(raw)
if not f.is_fixed_width:
raise ValueError('The font {} is not a monospace font'.format(raw_name))
return f, raw_name
def get_font_files(family):
ans = {}
b = fc_match(family, bold=True)
if b:
ans['bold'] = Face(b)
i = fc_match(family, italic=True)
if i:
ans['italic'] = Face(i)
bi = fc_match(family, True, True)
if bi:
ans['bi'] = Face(bi)
return ans
def load_font_family(r):
face, raw_name = r
ans = get_font_files(raw_name)
ans['regular'] = face
return ans

View File

@ -9,7 +9,7 @@ import pwd
from gettext import gettext as _
from .config import load_config, validate_font
from .config import load_config
from .constants import appname, str_version, config_dir
from .boss import Boss
from .utils import fork_child, hangup
@ -78,10 +78,6 @@ def main():
exec(args.cmd)
return
opts = load_config(args.config)
try:
validate_font(opts)
except ValueError as err:
raise SystemExit(str(err)) from None
glfw.glfwSetErrorCallback(on_glfw_error)
if not glfw.glfwInit():
raise SystemExit('GLFW initialization failed')

View File

@ -4,6 +4,7 @@
import os
import re
import subprocess
import sys
import termios
import struct
@ -15,6 +16,8 @@ from contextlib import contextmanager
from functools import lru_cache
from time import monotonic
import glfw
from .constants import terminfo_dir
libc = ctypes.CDLL(None)
@ -103,3 +106,17 @@ def timeit(name, do_timing=False):
def sanitize_title(x):
return re.sub(r'\s+', ' ', re.sub(r'[\0-\x19]', '', x))
def get_dpi():
if not hasattr(get_dpi, 'ans'):
m = glfw.glfwGetPrimaryMonitor()
width, height = glfw.glfwGetMonitorPhysicalSize(m)
vmode = glfw.glfwGetVideoMode(m)
dpix = vmode.width / (width / 25.4)
dpiy = vmode.height / (height / 25.4)
get_dpi.ans = {'physical': (dpix, dpiy)}
raw = subprocess.check_output(['xdpyinfo']).decode('utf-8')
m = re.search(r'^\s*resolution:\s*(\d+)+x(\d+)', raw, flags=re.MULTILINE)
get_dpi.ans['logical'] = (int(m.group(1)), int(m.group(2)))
return get_dpi.ans