[freetype-py] r76 committed - Prepare 0.4 release

7 views
Skip to first unread message

freet...@googlecode.com

unread,
Nov 9, 2012, 2:36:53 AM11/9/12
to Nicolas...@inria.fr
Revision: 76
Author: Nicolas.Rougier
Date: Thu Nov 8 23:36:08 2012
Log: Prepare 0.4 release
http://code.google.com/p/freetype-py/source/detail?r=76

Added:
/tags/release-0.4
/tags/release-0.4/NOTES.txt
/tags/release-0.4/README.txt
/tags/release-0.4/doc
/tags/release-0.4/examples/ftdump.py
/tags/release-0.4/examples/glyph-color.py
/tags/release-0.4/examples/glyph-metrics.py
/tags/release-0.4/examples/glyph-outline.py
/tags/release-0.4/examples/glyph-vector-2.py
/tags/release-0.4/examples/shader.py
/tags/release-0.4/examples/subpixel-positioning.py
/tags/release-0.4/examples/texture_font.py
/tags/release-0.4/examples/wordle.py
/tags/release-0.4/freetype/ft_enums
Deleted:
/tags/release-0.4/freetype/ft_enums.py
Modified:
/trunk/setup.py
Replaced:
/tags/release-0.4/examples/agg-trick.py
/tags/release-0.4/examples/ascii.py
/tags/release-0.4/examples/example_1.py
/tags/release-0.4/examples/font-info.py
/tags/release-0.4/examples/glyph-alpha.py
/tags/release-0.4/examples/glyph-lcd.py
/tags/release-0.4/examples/glyph-monochrome.py
/tags/release-0.4/examples/hello-world.py
/tags/release-0.4/examples/opengl.py
/tags/release-0.4/examples/sfnt-names.py
/tags/release-0.4/freetype/__init__.py
/tags/release-0.4/freetype/ft_errors.py
/tags/release-0.4/freetype/ft_structs.py
/tags/release-0.4/freetype/ft_types.py
/tags/release-0.4/setup.py

=======================================
--- /dev/null
+++ /tags/release-0.4/NOTES.txt Thu Nov 8 23:36:08 2012
@@ -0,0 +1,40 @@
+Release notes for 0.3.3
+=======================
+* Fixed a bug in Face.load_char
+* Added get_format and get_fstype in Face (titusz.pan)
+
+Release notes for 0.3.3
+=======================
+* Fixed a bug in get_kerning
+* Added test against freetype version for FT_ReferenceFace and
FT_Get_FSType_Flags
+
+Release notes for 0.3.2
+=======================
+* Added wordle.py example
+* Added get_bbox for Outline class
+* Added get_cbox for Outline and Glyph classes
+* Added __del__ method to Face class
+* Set encoding (utf-8) to all source files and examples.
+* Added test against freetype version for FT_Library_SetLcdFilterWeights.
+
+Release notes for 0.3.1
+=======================
+* Added FT_Stroker bindings (enums, structs and methods)
+* Added ft-outline and ft-color examples
+* Fixed first/next char in Face
+* Pythonic interface has been documented
+
+Release notes for 0.3.0
+=======================
+* Added ftdump.py demo and necessary functions
+
+Release notes for 0.2.0
+=======================
+* Added sfnt functions
+* Added TT_XXX flags in ft_enums
+* New examples
+
+Release notes for 0.1.1
+=======================
+* Initial release
+* Working examples
=======================================
--- /dev/null
+++ /tags/release-0.4/README.txt Thu Nov 8 23:36:08 2012
@@ -0,0 +1,10 @@
+#
-----------------------------------------------------------------------------
+#
+# FreeType high-level python API - copyright 2011 Nicolas P. Rougier
+# Distributed under the terms of the new BSD license.
+#
+#
-----------------------------------------------------------------------------
+
+Contributors:
+
+* Titusz Pan
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/ftdump.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,295 @@
+#!/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.
+#
-----------------------------------------------------------------------------
+from __future__ import print_function
+from __future__ import division
+import sys
+from freetype import *
+
+verbose = 0
+debug = 0
+name_tables = 0
+
+def usage( execname ):
+ print( )
+ print( "ftdump: simple font dumper -- part of the FreeType project" )
+ print( "----------------------------------------------------------" )
+ print( "Usage: %s [options] fontname", execname )
+ print( )
+ print( " -n print SFNT name tables" )
+ print( " -v be verbose" )
+ print( )
+ sys.exit()
+
+
+def Print_Name( face ):
+ print( "font name entries" );
+ print( " family: %s" % face.family_name )
+ print( " style: %s" % face.style_name )
+ ps_name = face.postscript_name or "UNAVAILABLE"
+ print( " postscript: %s" % ps_name )
+
+
+def Print_Type( face ):
+
+ print( "font type entries" )
+
+ # module = &face->driver->root;
+ # printf( " FreeType driver: %s\n", module->clazz->module_name );
+
+ # Is it better to dump all sfnt tag names?
+ print( " sfnt wrapped: ",end="")
+ if face.is_sfnt: print( "yes")
+ else: print( "no")
+
+ # is scalable ?
+ print( " type: ", end="")
+ if face.is_scalable:
+ print( "scalable, ", end="")
+ if face.has_multiple_masters:
+ print( "multiple_masters, ", end="")
+ if face.has_fixed_sizes:
+ print( "fixed size",end="")
+ print()
+
+ # Direction
+ print( " direction: ", end="" )
+ if face.has_horizontal:
+ print( "horizontal, ", end="")
+ if face.has_vertical:
+ print( "vertical", end="")
+ print( )
+
+ # Fixed width
+ print( " fixed width: ", end="")
+ if face.is_fixed_width: print( "yes")
+ else: print( "no")
+
+ # Glyph names
+ print( " glyph names: ", end="")
+ if face.has_glyph_names: print( "yes")
+ else: print( "no")
+
+ if face.is_scalable:
+ print( " EM size: %d" % face.units_per_EM )
+ print( " global BBox: (%ld,%ld):(%ld,%ld)" %
+ (face.bbox.xMin, face.bbox.yMin,
+ face.bbox.xMax, face.bbox.yMax ))
+ print( " ascent: %d" % face.ascender )
+ print( " descent: %d" % face.descender )
+ print( " text height: %d" % face.height )
+
+
+def get_platform_id( platform_id ):
+ if platform_id == TT_PLATFORM_APPLE_UNICODE:
+ return "Apple (Unicode)"
+ elif platform_id == TT_PLATFORM_MACINTOSH:
+ return "Macintosh"
+ elif platform_id == TT_PLATFORM_ISO:
+ return "ISO (deprecated)"
+ elif platform_id == TT_PLATFORM_MICROSOFT:
+ return "Microsoft"
+ elif platform_id == TT_PLATFORM_CUSTOM:
+ return "custom"
+ elif platform_id == TT_PLATFORM_ADOBE:
+ return "Adobe"
+ else:
+ return "UNKNOWN"
+
+def get_name_id( name_id ):
+ if name_id == TT_NAME_ID_COPYRIGHT:
+ return "copyright"
+ elif name_id == TT_NAME_ID_FONT_FAMILY:
+ return "font family"
+ elif name_id == TT_NAME_ID_FONT_SUBFAMILY:
+ return "font subfamily"
+ elif name_id == TT_NAME_ID_UNIQUE_ID:
+ return "unique ID"
+ elif name_id == TT_NAME_ID_FULL_NAME:
+ return "full name"
+ elif name_id == TT_NAME_ID_VERSION_STRING:
+ return "version string"
+ elif name_id == TT_NAME_ID_PS_NAME:
+ return "PostScript name"
+ elif name_id == TT_NAME_ID_TRADEMARK:
+ return "trademark"
+
+ # the following values are from the OpenType spec
+ elif name_id == TT_NAME_ID_MANUFACTURER:
+ return "manufacturer"
+ elif name_id == TT_NAME_ID_DESIGNER:
+ return "designer"
+ elif name_id == TT_NAME_ID_DESCRIPTION:
+ return "description"
+ elif name_id == TT_NAME_ID_VENDOR_URL:
+ return "vendor URL"
+ elif name_id == TT_NAME_ID_DESIGNER_URL:
+ return "designer URL"
+ elif name_id == TT_NAME_ID_LICENSE:
+ return "license"
+ elif name_id == TT_NAME_ID_LICENSE_URL:
+ return "license URL"
+ # number 15 is reserved
+ elif name_id == TT_NAME_ID_PREFERRED_FAMILY:
+ return "preferred family"
+ elif name_id == TT_NAME_ID_PREFERRED_SUBFAMILY:
+ return "preferred subfamily"
+ elif name_id == TT_NAME_ID_MAC_FULL_NAME:
+ return "Mac full name"
+
+ # The following code is new as of 2000-01-21
+ elif name_id == TT_NAME_ID_SAMPLE_TEXT:
+ return "sample text"
+
+ # This is new in OpenType 1.3
+ elif name_id == TT_NAME_ID_CID_FINDFONT_NAME:
+ return "CID 'findfont' name"
+ else:
+ return "UNKNOWN";
+
+
+def Print_Sfnt_Names( face ):
+ print( "font string entries" );
+
+ for i in range(face.sfnt_name_count):
+
+ name = face.get_sfnt_name(i)
+ print( " %-15s [%s]" % ( get_name_id( name.name_id ),
+ get_platform_id( name.platform_id
)),end="")
+
+ if name.platform_id == TT_PLATFORM_APPLE_UNICODE:
+ if name.encoding_id in [TT_APPLE_ID_DEFAULT,
+ TT_APPLE_ID_UNICODE_1_1,
+ TT_APPLE_ID_ISO_10646,
+ TT_APPLE_ID_UNICODE_2_0]:
+ print(name.string.decode('utf-16be', 'ignore'))
+ else:
+ print( "{unsupported encoding %d}" % name.encoding_id )
+
+ elif name.platform_id == TT_PLATFORM_MACINTOSH:
+ if name.language_id != TT_MAC_LANGID_ENGLISH:
+ print( " (language=%d)" % name.language_id )
+ print ( " : " )
+ if name.encoding_id == TT_MAC_ID_ROMAN:
+ # FIXME: convert from MacRoman to ASCII/ISO8895-1/whatever
+ # (MacRoman is mostly like ISO8895-1 but there are
differences)
+ print(name.string)
+ else:
+ print( "{unsupported encoding %d}" % name.encoding_id )
+
+ elif name.platform_id == TT_PLATFORM_ISO:
+ if name.encoding_id in [ TT_ISO_ID_7BIT_ASCII,
+ TT_ISO_ID_8859_1]:
+ print(name.string)
+ print ( " : " )
+ if name.encoding_id == TT_ISO_ID_10646:
+ print(name.string.decode('utf-16be', 'ignore'))
+ else:
+ print( "{unsupported encoding %d}" % name.encoding_id )
+
+ elif name.platform_id == TT_PLATFORM_MICROSOFT:
+ if name.language_id != TT_MS_LANGID_ENGLISH_UNITED_STATES:
+ print( " (language=0x%04x)" % name.language_id );
+ print( " : " )
+ if name.encoding_id in [TT_MS_ID_SYMBOL_CS,
+ TT_MS_ID_UNICODE_CS]:
+ print(name.string.decode('utf-16be', 'ignore'))
+ else:
+ print( "{unsupported encoding %d}" % name.encoding_id )
+ else:
+ print( "{unsupported platform}" )
+
+ print( )
+
+
+def Print_Fixed( face ):
+
+ # num_fixed_size
+ print( "fixed size\n" )
+
+ # available size
+ for i,bsize in enumerate(face.available_sizes):
+ print( " %3d: height %d, width %d\n",
+ i, bsize.height, bsize.width )
+ print( " size %.3f, x_ppem %.3f, y_ppem %.3f\n",
+ bsize.size / 64.0,
+ bsize.x_ppem / 64.0, bsize.y_ppem / 64.0 )
+
+
+def Print_Charmaps( face ):
+ global verbose
+ active = -1
+ if face.charmap:
+ active = face.charmap.index
+
+ # CharMaps
+ print( "charmaps" )
+ for i,charmap in enumerate(face.charmaps):
+ print( " %d: platform %d, encoding %d, language %d" %
+ (i, charmap.platform_id, charmap.encoding_id,
+ int(charmap.cmap_language_id)), end="" )
+ if i == active:
+ print( " (active)", end="" )
+ print ( )
+ if verbose:
+ face.set_charmap( charmap )
+ charcode, gindex = face.get_first_char()
+ while ( gindex ):
+ print( " 0x%04lx => %d" % (charcode, gindex) )
+ charcode, gindex = face.get_next_char( charcode, gindex )
+
+
+
+#
-----------------------------------------------------------------------------
+if __name__ == '__main__':
+ import getopt
+ execname = sys.argv[0]
+
+ if len(sys.argv) < 2:
+ usage( execname )
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], ':nv')
+ except getopt.GetoptError, err:
+ usage( execname )
+
+ verbose = False
+ name_tables = False
+
+ for o, a in opts:
+ if o == "-v": verbose = True
+ elif o == "-n": name_tables = True
+ else: usage( execname )
+
+
+ face = Face(args[0])
+ num_faces = face.num_faces
+
+ if num_faces > 1:
+ print( "There are %d faces in this file." % num_faces)
+ else:
+ print( "There is 1 face in this file.")
+
+ for i in range(num_faces):
+ face = Face(args[0], i)
+
+ print( "\n----- Face number: %d -----\n" % i )
+ Print_Name( face )
+ print( "" )
+ Print_Type( face )
+ print( " glyph count: %d" % face.num_glyphs )
+
+ if name_tables and face.is_sfnt:
+ print( )
+ Print_Sfnt_Names( face )
+
+ if face.num_fixed_sizes:
+ print( )
+ Print_Fixed( face )
+
+ if face.num_charmaps:
+ print( )
+ Print_Charmaps( face )
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/glyph-color.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,95 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Glyph colored rendering (with outline)
+'''
+from freetype import *
+
+if __name__ == '__main__':
+ import numpy as np
+ import matplotlib.pyplot as plt
+
+ face = Face('./Vera.ttf')
+ face.set_char_size( 96*64 )
+ RGBA = [('R',float), ('G',float), ('B',float), ('A',float)]
+
+ # Outline
+ flags = FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP
+ face.load_char('S', flags )
+ slot = face.glyph
+ glyph = slot.get_glyph()
+ stroker = Stroker( )
+ stroker.set(64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0
)
+ glyph.stroke( stroker )
+ blyph = glyph.to_bitmap(FT_RENDER_MODE_NORMAL, Vector(0,0))
+ bitmap = blyph.bitmap
+ width, rows, pitch = bitmap.width, bitmap.rows, bitmap.pitch
+ top, left = blyph.top, blyph.left
+ data = []
+ for i in range(rows):
+ data.extend(bitmap.buffer[i*pitch:i*pitch+width])
+ Z = np.array(data).reshape(rows, width)/255.0
+ O = np.zeros((rows,width), dtype=RGBA)
+ O['A'] = Z
+ O['R'] = 1
+ O['G'] = 0
+ O['B'] = 0
+
+ # Plain
+ flags = FT_LOAD_RENDER
+ face.load_char('S', flags)
+ F = np.zeros((rows,width), dtype=RGBA)
+ Z = np.zeros((rows, width))
+ bitmap = face.glyph.bitmap
+ width, rows, pitch = bitmap.width, bitmap.rows, bitmap.pitch
+ top, left = face.glyph.bitmap_top, face.glyph.bitmap_left
+ dy = blyph.top - face.glyph.bitmap_top
+ dx = face.glyph.bitmap_left - blyph.left
+ data = []
+ for i in range(rows):
+ data.extend(bitmap.buffer[i*pitch:i*pitch+width])
+ Z[dx:dx+rows,dy:dy+width] = np.array(data).reshape(rows, width)/255.
+ F['R'] = 1
+ F['G'] = 1
+ F['B'] = 0
+ F['A'] = Z
+
+ # Combine outline and plain
+ R1,G1,B1,A1 = O['R'],O['G'],O['B'],O['A']
+ R2,G2,B2,A2 = F['R'],F['G'],F['B'],F['A']
+ Z = np.zeros(O.shape, dtype=RGBA)
+ Z['R'] = (A1 * R1 + A2 * (1 - A1) * R2)
+ Z['G'] = (A1 * G1 + A2 * (1 - A1) * G2)
+ Z['B'] = (A1 * B1 + A2 * (1 - A1) * B2)
+ Z['A'] = (A1 + A2 * (1 - A1))
+
+
+ # Draw
+ plt.figure(figsize=(12,5))
+
+ plt.subplot(1,3,1)
+ plt.title('Plain')
+ plt.xticks([]), plt.yticks([])
+ I = F.view(dtype=float).reshape(O.shape[0],O.shape[1],4)
+ plt.imshow(I, interpolation='nearest')
+
+ plt.subplot(1,3,2)
+ plt.title('Outline')
+ plt.xticks([]), plt.yticks([])
+ I = O.view(dtype=float).reshape(O.shape[0],O.shape[1],4)
+ plt.imshow(I, interpolation='nearest')
+
+ plt.subplot(1,3,3)
+ plt.title('Outline + Plain')
+ plt.xticks([]), plt.yticks([])
+ I = Z.view(dtype=float).reshape(O.shape[0],O.shape[1],4)
+ plt.imshow(I, interpolation='nearest')
+
+ plt.show()
+
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/glyph-metrics.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,233 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Show glyph metrics in horizontal and vertical layout
+'''
+from freetype import *
+
+def arrow( x,y, dx, dy, **kwargs):
+ kwargs['shape'] = 'full'
+ kwargs['head_width'] = 30
+ kwargs['head_length'] = 40
+ kwargs['length_includes_head'] =True
+ kwargs['facecolor'] = 'k'
+ kwargs['edgecolor'] ='k'
+ kwargs['linewidth'] =.5
+ plt.arrow(x,y,dx,dy,**kwargs)
+
+def double_arrow(x, y, dx, dy, **kwargs):
+ cx,cy = x+dx/2., y+dy/2.
+ dx /= 2.0
+ dy /= 2.0
+ arrow(cx,cy,+dx,+dy,**kwargs)
+ arrow(cx,cy,-dx,-dy,**kwargs)
+
+def line(x, y, dx, dy, **kwargs):
+ kwargs['color'] = 'k'
+ kwargs['linewidth'] =.5
+ plt.plot([x,x+dx],[y,y+dy],**kwargs)
+
+def point(x, y, r, **kwargs):
+ kwargs['color'] = 'k'
+ plt.scatter([x],[y],r,**kwargs)
+
+def text( x,y,text, **kwargs):
+ kwargs['fontsize'] = 18
+ plt.text(x, y, text, **kwargs)
+
+
+
+if __name__ == '__main__':
+ import numpy as np
+ import matplotlib.pyplot as plt
+ from matplotlib.path import Path
+ import matplotlib.patches as patches
+
+
+ face = Face('./Vera.ttf')
+ face.set_char_size( 32*64 )
+ face.load_char('g')
+ slot = face.glyph
+ bitmap = slot.bitmap
+ width = slot.bitmap.width
+ rows = slot.bitmap.rows
+ pitch = slot.bitmap.pitch
+ outline= slot.outline
+
+ start, end = 0, 0
+ VERTS, CODES = [], []
+ # Iterate over each contour
+ for i in range(len(outline.contours)):
+ end = outline.contours[i]
+ points = outline.points[start:end+1]
+ points.append(points[0])
+ tags = outline.tags[start:end+1]
+ tags.append(tags[0])
+ segments = [ [points[0],], ]
+ for j in range(1, len(points) ):
+ segments[-1].append(points[j])
+ if tags[j] & (1 << 0) and j < (len(points)-1):
+ segments.append( [points[j],] )
+ verts = [points[0], ]
+ codes = [Path.MOVETO,]
+ for segment in segments:
+ if len(segment) == 2:
+ verts.extend(segment[1:])
+ codes.extend([Path.LINETO])
+ elif len(segment) == 3:
+ verts.extend(segment[1:])
+ codes.extend([Path.CURVE3, Path.CURVE3])
+ else:
+ verts.append(segment[1])
+ codes.append(Path.CURVE3)
+ for i in range(1,len(segment)-2):
+ A,B = segment[i], segment[i+1]
+ C = ((A[0]+B[0])/2.0, (A[1]+B[1])/2.0)
+ verts.extend([ C, B ])
+ codes.extend([ Path.CURVE3, Path.CURVE3])
+ verts.append(segment[-1])
+ codes.append(Path.CURVE3)
+ VERTS.extend(verts)
+ CODES.extend(codes)
+ start = end+1
+ VERTS = np.array(VERTS)
+ x,y = VERTS[:,0], VERTS[:,1]
+ VERTS[:,0], VERTS[:,1] = x, y
+
+
+ path = Path(VERTS, CODES)
+ xmin, xmax = x.min(), x.max()
+ ymin, ymax = y.min(), y.max()
+ width,height = xmax-xmin, ymax-ymin
+ dw, dh = 0.2*width, 0.1*height
+ bearing = xmin - slot.metrics.horiBearingX, ymin -
slot.metrics.horiBearingY
+ advance = slot.advance
+ origin = bearing
+
+
+ figure = plt.figure(figsize=(16,10), frameon=False, facecolor="white")
+
+ axes = plt.subplot(121, frameon=False, aspect=1)
+ glyph = patches.PathPatch(path, fill = True, facecolor='k', lw=0)
+ plt.xlim(xmin - .25*width, xmax + .75*width)
+ plt.ylim(ymin - .5*height, xmax + .75*height)
+ plt.xticks([]), plt.yticks([])
+ axes.add_patch(glyph)
+
+ # Y axis
+ arrow(origin[0], ymin-dh, 0, height+3*dh)
+
+ # X axis
+ arrow(origin[0]-dw, 0, width+3*dw, 0)
+
+ # origin
+ point(0,0,50)
+ text( -20, -20, "$origin$", va='top', ha='right')
+
+ # Bounding box
+ bbox = patches.Rectangle( (xmin,ymin), width, height, fill = False,
lw=.5)
+ axes.add_patch(bbox)
+
+ # Width
+ line(xmin, ymax, 0, 3*dh, linestyle="dotted")
+ text( xmin, ymax+3.25*dh, "$x_{min}$", va='bottom', ha='center')
+ line(xmax, ymax, 0, 3*dh, linestyle="dotted")
+ text( xmax, ymax+3.25*dh, "$x_{max}$", va='bottom', ha='center')
+ double_arrow(xmin, ymax+2.5*dh, width, 0)
+ text(xmin+width/2., ymax+1.75*dh, "$width$", va='bottom', ha='center')
+
+ # Height
+ line(xmax, ymin, 3*dw, 0, linestyle="dotted")
+ text(xmax+3.25*dw, ymin, "$y_{min}$", va='baseline', ha='left')
+ line(xmax, ymax, 3*dw, 0, linestyle="dotted")
+ text(xmax+3.25*dw, ymax, "$y_{max}$", va='baseline', ha='left')
+ double_arrow(xmax+2.5*dw, ymin, 0, height)
+ text(xmax+2.75*dw, ymin+height/2., "$height$", va='center', ha='left')
+
+ # Advance
+ point(advance.x,0,50)
+ line(advance.x, 0, 0, ymin-dh, linestyle="dotted")
+ arrow(0, ymin-.5*dh, advance.x, 0)
+ text(advance.x/2., ymin-1.25*dh, "$advance$", va='bottom', ha='center')
+
+ # Bearing Y
+ arrow(xmax+.25*dw, 0, 0, ymax)
+ text(xmax+.5*dw, ymax/2, "$Y_{bearing}$", va='center', ha='left')
+
+ # Bearing X
+ arrow(0, ymax/2., xmin, 0)
+ text(-10, ymax/2, "$X_{bearing}$", va='baseline', ha='right')
+
+
+ #
-------------------------------------------------------------------------
+
+ axes = plt.subplot(122, frameon=False, aspect=1)
+ glyph = patches.PathPatch(path, fill = True, facecolor='k', lw=0)
+ axes.add_patch(glyph)
+
+ plt.xlim(xmin - .25*width, xmax + .75*width)
+ plt.ylim(ymin - .5*height, xmax + .75*height)
+ plt.xticks([]), plt.yticks([])
+
+
+ advance = slot.metrics.vertAdvance
+ x_bearing = slot.metrics.vertBearingX
+ y_bearing = slot.metrics.vertBearingY
+
+ # Y axis
+ arrow(xmin-x_bearing, ymax+y_bearing+2*dh, 0, -advance-3*dh)
+
+ # X axis
+ arrow(xmin-2*dw, ymax+y_bearing, width+4*dw, 0)
+
+ # origin
+ point( xmin-x_bearing, ymax+y_bearing, 50)
+ text( xmin-x_bearing-30, ymax+y_bearing+10, "$origin$", va='bottom',
ha='right')
+
+ # Bounding box
+ bbox = patches.Rectangle( (xmin,ymin), width, height, fill = False,
lw=.5)
+ axes.add_patch(bbox)
+
+
+ # # Advance
+ point(xmin-x_bearing, ymax+y_bearing-advance, 50)
+ line(xmin-x_bearing, ymax+y_bearing-advance, xmax-dw, 0,
linestyle="dotted")
+ arrow(xmax+dw, ymax+y_bearing, 0, -advance)
+ text(xmax+1.25*dw, ymax+y_bearing-advance/2., "$advance$",
va='baseline', ha='left')
+
+
+ # Width
+ line(xmin, ymin, 0, -4*dh, linestyle="dotted")
+ text( xmin, ymin-4.25*dh, "$x_{min}$", va='top', ha='center')
+ line(xmax, ymin, 0, -4*dh, linestyle="dotted")
+ text( xmax, ymin-4.25*dh, "$x_{max}$", va='top', ha='center')
+ double_arrow(xmin, ymin-3.5*dh, width, 0)
+ text(xmin+width/2., ymin-3.75*dh, "$width$", va='top', ha='center')
+
+ # Height
+ line(xmin, ymin, -3*dw, 0, linestyle="dotted")
+ text(xmin-1.5*dw, ymin, "$y_{min}$", va='baseline', ha='right')
+ line(xmin, ymax, -3*dw, 0, linestyle="dotted")
+ text(xmin-1.5*dw, ymax, "$y_{max}$", va='baseline', ha='right')
+ double_arrow(xmin-.5*dw, ymin, 0, height)
+ text(xmin-.75*dw, ymin+height/2., "$height$", va='center', ha='right')
+
+
+ #point(xmin-x_bearing, ymax+y_bearing, 50)
+ # Bearing Y
+ arrow(xmax-.5*dw, ymax+y_bearing, 0, -y_bearing)
+ text(xmax-.5*dw, ymax+y_bearing+.25*dh, "$Y_{bearing}$", va='bottom',
ha='center')
+
+ # # Bearing X
+ line(xmin, ymax, 0, 3*dh, linestyle="dotted")
+ arrow(xmin-x_bearing, ymax+y_bearing+dh, x_bearing, 0)
+ text(xmin-.25*dw, ymax+y_bearing+dh, "$X_{bearing}$", va='baseline',
ha='right')
+
+ plt.savefig('glyph-metrics.pdf')
+ plt.show()
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/glyph-outline.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,39 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Glyph outline rendering
+'''
+from freetype import *
+
+if __name__ == '__main__':
+ import numpy
+ import matplotlib.pyplot as plt
+
+ face = Face('./Vera.ttf')
+ face.set_char_size( 4*48*64 )
+ flags = FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP
+ face.load_char('S', flags )
+ slot = face.glyph
+ glyph = slot.get_glyph()
+ stroker = Stroker( )
+ stroker.set(64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0
)
+ glyph.stroke( stroker )
+ blyph = glyph.to_bitmap(FT_RENDER_MODE_NORMAL, Vector(0,0))
+ bitmap = blyph.bitmap
+ width, rows, pitch = bitmap.width, bitmap.rows, bitmap.pitch
+ top, left = blyph.top, blyph.left
+ data = []
+ for i in range(rows):
+ data.extend(bitmap.buffer[i*pitch:i*pitch+width])
+ Z = numpy.array(data,dtype=numpy.ubyte).reshape(rows, width)
+ plt.figure(figsize=(6,8))
+ plt.imshow(Z, interpolation='nearest', cmap=plt.cm.gray_r)
+ plt.show()
+
+
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/glyph-vector-2.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,101 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Show how to access glyph outline description.
+'''
+from freetype import *
+
+if __name__ == '__main__':
+ import numpy
+ import matplotlib.pyplot as plt
+ from matplotlib.path import Path
+ import matplotlib.patches as patches
+
+ face = Face('./Vera.ttf')
+ face.set_char_size( 32*64 )
+ face.load_char('g')
+ slot = face.glyph
+
+ bitmap = face.glyph.bitmap
+ width = face.glyph.bitmap.width
+ rows = face.glyph.bitmap.rows
+ pitch = face.glyph.bitmap.pitch
+
+ data = []
+ for i in range(rows):
+ data.extend(bitmap.buffer[i*pitch:i*pitch+width])
+ Z = numpy.array(data,dtype=numpy.ubyte).reshape(rows, width)
+
+ outline = slot.outline
+ points = numpy.array(outline.points, dtype=[('x',float), ('y',float)])
+ x, y = points['x'], points['y']
+
+ figure = plt.figure(figsize=(8,10))
+ axis = figure.add_subplot(111)
+ #axis.scatter(points['x'], points['y'], alpha=.25)
+ start, end = 0, 0
+
+ VERTS, CODES = [], []
+ # Iterate over each contour
+ for i in range(len(outline.contours)):
+ end = outline.contours[i]
+ points = outline.points[start:end+1]
+ points.append(points[0])
+ tags = outline.tags[start:end+1]
+ tags.append(tags[0])
+
+ segments = [ [points[0],], ]
+ for j in range(1, len(points) ):
+ segments[-1].append(points[j])
+ if tags[j] & (1 << 0) and j < (len(points)-1):
+ segments.append( [points[j],] )
+ verts = [points[0], ]
+ codes = [Path.MOVETO,]
+ for segment in segments:
+ if len(segment) == 2:
+ verts.extend(segment[1:])
+ codes.extend([Path.LINETO])
+ elif len(segment) == 3:
+ verts.extend(segment[1:])
+ codes.extend([Path.CURVE3, Path.CURVE3])
+ else:
+ verts.append(segment[1])
+ codes.append(Path.CURVE3)
+ for i in range(1,len(segment)-2):
+ A,B = segment[i], segment[i+1]
+ C = ((A[0]+B[0])/2.0, (A[1]+B[1])/2.0)
+ verts.extend([ C, B ])
+ codes.extend([ Path.CURVE3, Path.CURVE3])
+ verts.append(segment[-1])
+ codes.append(Path.CURVE3)
+ VERTS.extend(verts)
+ CODES.extend(codes)
+ start = end+1
+
+
+ # Draw glyph
+ path = Path(VERTS, CODES)
+ glyph = patches.PathPatch(path, fill = True, facecolor=(0.8,0.5,0.8),
alpha=.25, lw=0)
+ glyph_outline = patches.PathPatch(path, fill = False,
edgecolor='black', lw=3)
+
+ plt.imshow(Z, extent=[x.min(), x.max(),y.min(), y.max()],
+ interpolation='nearest', cmap = plt.cm.gray_r, vmin=0,
vmax=400)
+ plt.xticks(numpy.linspace(x.min(), x.max(), Z.shape[1]+1), ())
+ plt.yticks(numpy.linspace(y.min(), y.max(), Z.shape[0]+1), ())
+ plt.grid(color='k', linewidth=1, linestyle='-')
+ axis.add_patch(glyph)
+ axis.add_patch(glyph_outline)
+ axis.set_xlim(x.min(), x.max())
+ axis.set_ylim(y.min(), y.max())
+
+ plt.savefig('test.svg')
+ plt.show()
+
+
+
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/shader.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,163 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
-----------------------------------------------------------------------------
+# Copyright (C) 2009-2010 Nicolas P. Rougier
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
+#
-----------------------------------------------------------------------------
+#
+# Copyright Tristam Macdonald 2008.
+#
+# Distributed under the Boost Software License, Version 1.0
+# (see http://www.boost.org/LICENSE_1_0.txt)
+#
+''' Base shader class.
+
+ Example:
+ --------
+ shader = Shader()
+
+ shader.bind()
+ glActiveTexture(GL_TEXTURE1)
+ glBindTexture(lut.target, lut.id)
+ shader.uniformi('lut', 1)
+
+ glActiveTexture(GL_TEXTURE0)
+ glBindTexture(texture.target, texture.id)
+ shader.uniformi('texture', 0)
+ shader.uniformf('pixel', 1.0/texture.width, 1.0/texture.height)
+
+ texture.blit(x,y,w,h)
+ shader.unbind()
+'''
+import os
+import OpenGL.GL as gl
+import ctypes
+
+class Shader:
+ ''' Base shader class. '''
+
+ def __init__(self, vert = None, frag = None, name=''):
+ ''' vert, frag and geom take arrays of source strings
+ the arrays will be concatenated into one string by OpenGL.'''
+
+ self.uniforms = {}
+ self.name = name
+ # create the program handle
+ self.handle = gl.glCreateProgram()
+ # we are not linked yet
+ self.linked = False
+ # create the vertex shader
+ self._build_shader(vert, gl.GL_VERTEX_SHADER)
+ # create the fragment shader
+ self._build_shader(frag, gl.GL_FRAGMENT_SHADER)
+ # the geometry shader will be the same, once pyglet supports the
+ # extension self.createShader(frag, GL_GEOMETRY_SHADER_EXT)
attempt to
+ # link the program
+ self._link()
+
+ def _build_shader(self, strings, stype):
+ ''' Actual building of the shader '''
+
+ count = len(strings)
+ # if we have no source code, ignore this shader
+ if count < 1:
+ return
+
+ # create the shader handle
+ shader = gl.glCreateShader(stype)
+
+ # Upload shader code
+ gl.glShaderSource(shader, strings)
+
+ # compile the shader
+ gl.glCompileShader(shader)
+
+ # retrieve the compile status
+ status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS)
+
+ # if compilation failed, print the log
+ if not status:
+ # display the log
+ print gl.glGetShaderInfoLog(shader)
+ else:
+ # all is well, so attach the shader to the program
+ gl.glAttachShader(self.handle, shader)
+
+ def _link(self):
+ ''' Link the program '''
+
+ gl.glLinkProgram(self.handle)
+ # retrieve the link status
+ temp = ctypes.c_int(0)
+ gl.glGetProgramiv(self.handle, gl.GL_LINK_STATUS,
ctypes.byref(temp))
+
+ # if linking failed, print the log
+ if not temp:
+ # retrieve the log length
+ gl.glGetProgramiv(self.handle,
+ gl.GL_INFO_LOG_LENGTH, ctypes.byref(temp))
+ # create a buffer for the log
+ #buffer = ctypes.create_string_buffer(temp.value)
+ # retrieve the log text
+ log = gl.glGetProgramInfoLog(self.handle) #, temp, None,
buffer)
+ # print the log to the console
+ print log
+ else:
+ # all is well, so we are linked
+ self.linked = True
+
+ def bind(self):
+ ''' Bind the program, i.e. use it. '''
+ gl.glUseProgram(self.handle)
+
+ def unbind(self):
+ ''' Unbind whatever program is currently bound - not necessarily
this
+ program, so this should probably be a class method instead. '''
+ gl.glUseProgram(0)
+
+ def uniformf(self, name, *vals):
+ ''' Uploads float uniform(s), program must be currently bound. '''
+
+ loc = self.uniforms.get(name,
+ gl.glGetUniformLocation(self.handle,name))
+ self.uniforms[name] = loc
+
+ # Check there are 1-4 values
+ if len(vals) in range(1, 5):
+ # Select the correct function
+ { 1 : gl.glUniform1f,
+ 2 : gl.glUniform2f,
+ 3 : gl.glUniform3f,
+ 4 : gl.glUniform4f
+ # Retrieve uniform location, and set it
+ }[len(vals)](loc, *vals)
+
+ def uniformi(self, name, *vals):
+ ''' Upload integer uniform(s), program must be currently bound. '''
+
+ loc = self.uniforms.get(name,
+ gl.glGetUniformLocation(self.handle,name))
+ self.uniforms[name] = loc
+
+ # Checks there are 1-4 values
+ if len(vals) in range(1, 5):
+ # Selects the correct function
+ { 1 : gl.glUniform1i,
+ 2 : gl.glUniform2i,
+ 3 : gl.glUniform3i,
+ 4 : gl.glUniform4i
+ # Retrieves uniform location, and set it
+ }[len(vals)](loc, *vals)
+
+
+ def uniform_matrixf(self, name, mat):
+ ''' Upload uniform matrix, program must be currently bound. '''
+
+ loc = self.uniforms.get(name,
+ gl.glGetUniformLocation(self.handle,name))
+ self.uniforms[name] = loc
+
+ # Upload the 4x4 floating point matrix
+ gl.glUniformMatrix4fv(loc, 1, False, (ctypes.c_float * 16)(*mat))
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/subpixel-positioning.py Thu Nov 8 23:36:08
2012
@@ -0,0 +1,222 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Subpixel rendering AND positioning using OpenGL and shaders.
+
+'''
+import numpy as np
+import OpenGL.GL as gl
+import OpenGL.GLUT as glut
+from texture_font import TextureFont, TextureAtlas
+from shader import Shader
+
+
+vert='''
+uniform sampler2D texture;
+uniform vec2 pixel;
+attribute float modulo;
+varying float m;
+void main() {
+ gl_FrontColor = gl_Color;
+ gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+ m = modulo;
+}
+'''
+
+frag='''
+uniform sampler2D texture;
+uniform vec2 pixel;
+varying float m;
+void main() {
+ vec2 uv = gl_TexCoord[0].xy;
+ vec4 current = texture2D(texture, uv);
+ vec4 previous= texture2D(texture, uv+vec2(-1,0)*pixel);
+ float r = current.r;
+ float g = current.g;
+ float b = current.b;
+ float a = current.a;
+ if( m <= 0.333 )
+ {
+ float z = m/0.333;
+ r = mix(current.r, previous.b, z);
+ g = mix(current.g, current.r, z);
+ b = mix(current.b, current.g, z);
+ }
+ else if( m <= 0.666 )
+ {
+ float z = (m-0.33)/0.333;
+ r = mix(previous.b, previous.g, z);
+ g = mix(current.r, previous.b, z);
+ b = mix(current.g, current.r, z);
+ }
+ else if( m < 1.0 )
+ {
+ float z = (m-0.66)/0.334;
+ r = mix(previous.g, previous.r, z);
+ g = mix(previous.b, previous.g, z);
+ b = mix(current.r, previous.b, z);
+ }
+ gl_FragColor = vec4(r,g,b,a);
+}
+'''
+
+
+
+
+
+class Label:
+ def __init__(self, text, font, color=(1.0, 1.0, 1.0, 0.0), x=0, y=0,
+ width=None, height=None, anchor_x='left',
anchor_y='baseline'):
+ self.text = text
+ self.vertices = np.zeros((len(text)*4,3), dtype=np.float32)
+ self.indices = np.zeros((len(text)*6, ), dtype=np.uint)
+ self.colors = np.zeros((len(text)*4,4), dtype=np.float32)
+ self.texcoords= np.zeros((len(text)*4,2), dtype=np.float32)
+ self.attrib = np.zeros((len(text)*4,1), dtype=np.float32)
+ pen = [x,y]
+ prev = None
+
+ for i,charcode in enumerate(text):
+ glyph = font[charcode]
+ kerning = glyph.get_kerning(prev)
+ x0 = pen[0] + glyph.offset[0] + kerning
+ dx = x0-int(x0)
+ x0 = int(x0)
+ y0 = pen[1] + glyph.offset[1]
+ x1 = x0 + glyph.size[0]
+ y1 = y0 - glyph.size[1]
+ u0 = glyph.texcoords[0]
+ v0 = glyph.texcoords[1]
+ u1 = glyph.texcoords[2]
+ v1 = glyph.texcoords[3]
+
+ index = i*4
+ indices = [index, index+1, index+2, index, index+2, index+3]
+ vertices = [[x0,y0,1],[x0,y1,1],[x1,y1,1], [x1,y0,1]]
+ texcoords = [[u0,v0],[u0,v1],[u1,v1], [u1,v0]]
+ colors = [color,]*4
+
+ self.vertices[i*4:i*4+4] = vertices
+ self.indices[i*6:i*6+6] = indices
+ self.texcoords[i*4:i*4+4] = texcoords
+ self.colors[i*4:i*4+4] = colors
+ self.attrib[i*4:i*4+4] = dx
+ pen[0] = pen[0]+glyph.advance[0]/64.0 + kerning
+ pen[1] = pen[1]+glyph.advance[1]/64.0
+ prev = charcode
+
+ width = pen[0]-glyph.advance[0]/64.0+glyph.size[0]
+
+ if anchor_y == 'top':
+ dy = -round(font.ascender)
+ elif anchor_y == 'center':
+ dy = +round(-font.height/2-font.descender)
+ elif anchor_y == 'bottom':
+ dy = -round(font.descender)
+ else:
+ dy = 0
+
+ if anchor_x == 'right':
+ dx = -width/1.0
+ elif anchor_x == 'center':
+ dx = -width/2.0
+ else:
+ dx = 0
+ self.vertices += (round(dx), round(dy), 0)
+
+
+ def draw(self):
+ gl.glEnable( gl.GL_TEXTURE_2D )
+ gl.glDisable( gl.GL_DEPTH_TEST )
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY)
+ gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
+
+ gl.glVertexPointer(3, gl.GL_FLOAT, 0, self.vertices)
+ gl.glColorPointer(4, gl.GL_FLOAT, 0, self.colors)
+ gl.glTexCoordPointer(2, gl.GL_FLOAT, 0, self.texcoords)
+
+ alpha = 1
+ gl.glEnable( gl.GL_COLOR_MATERIAL )
+ gl.glBlendFunc( gl.GL_CONSTANT_COLOR_EXT,
+ gl.GL_ONE_MINUS_SRC_COLOR )
+ gl.glEnable( gl.GL_BLEND )
+ gl.glColor3f( alpha, alpha, alpha )
+ gl.glBlendColor( 1-alpha, 1-alpha, 1-alpha, 1 )
+ gl.glEnableVertexAttribArray( 1 );
+ gl.glVertexAttribPointer( 1, 1, gl.GL_FLOAT, gl.GL_FALSE, 0,
self.attrib)
+ shader.bind()
+ shader.uniformi('texture', 0)
+ shader.uniformf('pixel', 1.0/512, 1.0/512)
+ gl.glDrawElements(gl.GL_TRIANGLES, len(self.indices),
+ gl.GL_UNSIGNED_INT, self.indices)
+ shader.unbind()
+ gl.glDisableVertexAttribArray( 1 );
+ gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY)
+ gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+ gl.glDisable( gl.GL_TEXTURE_2D )
+ gl.glDisable( gl.GL_BLEND )
+
+
+
+
+if __name__ == '__main__':
+ import sys
+
+ atlas = TextureAtlas(512,512,3)
+
+ def on_display( ):
+ gl.glClearColor(1,1,1,1)
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
+ gl.glBindTexture( gl.GL_TEXTURE_2D, atlas.texid )
+ for label in labels: label.draw()
+ gl.glColor(0,0,0,1)
+ gl.glBegin(gl.GL_LINES)
+ gl.glVertex2i(15,0)
+ gl.glVertex2i(15, 330)
+ gl.glVertex2i(225, 0)
+ gl.glVertex2i(225, 330)
+ gl.glEnd()
+ glut.glutSwapBuffers( )
+
+ def on_reshape( width, height ):
+ gl.glViewport( 0, 0, width, height )
+ gl.glMatrixMode( gl.GL_PROJECTION )
+ gl.glLoadIdentity( )
+ gl.glOrtho( 0, width, 0, height, -1, 1 )
+ gl.glMatrixMode( gl.GL_MODELVIEW )
+ gl.glLoadIdentity( )
+
+ def on_keyboard( key, x, y ):
+ if key == '\033':
+ sys.exit( )
+
+ glut.glutInit( sys.argv )
+ glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA |
glut.GLUT_DEPTH )
+ glut.glutCreateWindow( "Freetype OpenGL" )
+ glut.glutReshapeWindow( 240, 330 )
+ glut.glutDisplayFunc( on_display )
+ glut.glutReshapeFunc( on_reshape )
+ glut.glutKeyboardFunc( on_keyboard )
+
+ font = TextureFont(atlas, './Arial.ttf', 9)
+ text = "|... A Quick Brown Fox Jumps Over The Lazy Dog"
+ labels = []
+ x,y = 20,310
+ for i in range(30):
+ labels.append(Label(text=text, font=font, x=x, y=y))
+ x += 0.1000000000001
+ y -= 10
+ atlas.upload()
+ shader = Shader(vert,frag)
+ glut.glutMainLoop( )
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/texture_font.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,421 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+'''
+Texture font class
+
+'''
+import sys
+import math
+import numpy as np
+import OpenGL.GL as gl
+from freetype import *
+
+
+class TextureAtlas:
+ '''
+ Group multiple small data regions into a larger texture.
+
+ The algorithm is based on the article by Jukka Jylänki : "A Thousand
Ways
+ to Pack the Bin - A Practical Approach to Two-Dimensional Rectangle Bin
+ Packing", February 27, 2010. More precisely, this is an implementation
of
+ the Skyline Bottom-Left algorithm based on C++ sources provided by
Jukka
+ Jylänki at: http://clb.demon.fi/files/RectangleBinPack/
+
+ Example usage:
+ --------------
+
+ atlas = TextureAtlas(512,512,3)
+ region = atlas.get_region(20,20)
+ ...
+ atlas.set_region(region, data)
+ '''
+
+ def __init__(self, width=1024, height=1024, depth=1):
+ '''
+ Initialize a new atlas of given size.
+
+ Parameters
+ ----------
+
+ width : int
+ Width of the underlying texture
+
+ height : int
+ Height of the underlying texture
+
+ depth : 1 or 3
+ Depth of the underlying texture
+ '''
+ self.width = int(math.pow(2, int(math.log(width, 2) + 0.5)))
+ self.height = int(math.pow(2, int(math.log(height, 2) + 0.5)))
+ self.depth = depth
+ self.nodes = [ (0,0,self.width), ]
+ self.data = np.zeros((self.height, self.width, self.depth),
+ dtype=np.ubyte)
+ self.texid = 0
+ self.used = 0
+
+
+
+ def upload(self):
+ '''
+ Upload atlas data into video memory.
+ '''
+
+ if not self.texid:
+ self.texid = gl.glGenTextures(1)
+
+ gl.glBindTexture( gl.GL_TEXTURE_2D, self.texid )
+ gl.glTexParameteri( gl.GL_TEXTURE_2D,
+ gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP )
+ gl.glTexParameteri( gl.GL_TEXTURE_2D,
+ gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP )
+ gl.glTexParameteri( gl.GL_TEXTURE_2D,
+ gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR )
+ gl.glTexParameteri( gl.GL_TEXTURE_2D,
+ gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR )
+ if self.depth == 1:
+ gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_ALPHA,
+ self.width, self.height, 0,
+ gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE, self.data )
+ else:
+ gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGB,
+ self.width, self.height, 0,
+ gl.GL_RGB, gl.GL_UNSIGNED_BYTE, self.data )
+
+
+
+ def set_region(self, region, data):
+ '''
+ Set a given region width provided data.
+
+ Parameters
+ ----------
+
+ region : (int,int,int,int)
+ an allocated region (x,y,width,height)
+
+ data : numpy array
+ data to be copied into given region
+ '''
+
+ x, y, width, height = region
+ self.data[y:y+height,x:x+width, :] = data
+
+
+
+ def get_region(self, width, height):
+ '''
+ Get a free region of given size and allocate it
+
+ Parameters
+ ----------
+
+ width : int
+ Width of region to allocate
+
+ height : int
+ Height of region to allocate
+
+ Return
+ ------
+ A newly allocated region as (x,y,width,height) or (-1,-1,0,0)
+ '''
+
+ best_height = sys.maxint
+ best_index = -1
+ best_width = sys.maxint
+ region = 0, 0, width, height
+
+ for i in range(len(self.nodes)):
+ y = self.fit(i, width, height)
+ if y >= 0:
+ node = self.nodes[i]
+ if (y+height < best_height or
+ (y+height == best_height and node[2] < best_width)):
+ best_height = y+height
+ best_index = i
+ best_width = node[2]
+ region = node[0], y, width, height
+
+ if best_index == -1:
+ return -1,-1,0,0
+
+ node = region[0], region[1]+height, width
+ self.nodes.insert(best_index, node)
+
+ i = best_index+1
+ while i < len(self.nodes):
+ node = self.nodes[i]
+ prev_node = self.nodes[i-1]
+ if node[0] < prev_node[0]+prev_node[2]:
+ shrink = prev_node[0]+prev_node[2] - node[0]
+ x,y,w = self.nodes[i]
+ self.nodes[i] = x+shrink, y, w-shrink
+ if self.nodes[i][2] <= 0:
+ del self.nodes[i]
+ i -= 1
+ else:
+ break
+ else:
+ break
+ i += 1
+
+ self.merge()
+ self.used += width*height
+ return region
+
+
+
+ def fit(self, index, width, height):
+ '''
+ Test if region (width,height) fit into self.nodes[index]
+
+ Parameters
+ ----------
+
+ index : int
+ Index of the internal node to be tested
+
+ width : int
+ Width or the region to be tested
+
+ height : int
+ Height or the region to be tested
+
+ '''
+
+ node = self.nodes[index]
+ x,y = node[0], node[1]
+ width_left = width
+
+ if x+width > self.width:
+ return -1
+
+ i = index
+ while width_left > 0:
+ node = self.nodes[i]
+ y = max(y, node[1])
+ if y+height > self.height:
+ return -1
+ width_left -= node[2]
+ i += 1
+ return y
+
+
+
+ def merge(self):
+ '''
+ Merge nodes
+ '''
+
+ i = 0
+ while i < len(self.nodes)-1:
+ node = self.nodes[i]
+ next_node = self.nodes[i+1]
+ if node[1] == next_node[1]:
+ self.nodes[i] = node[0], node[1], node[2]+next_node[2]
+ del self.nodes[i+1]
+ else:
+ i += 1
+
+
+class TextureFont:
+ '''
+ A texture font gathers a set of glyph relatively to a given font
filename
+ and size.
+ '''
+
+ def __init__(self, atlas, filename, size):
+ '''
+ Initialize font
+
+ Parameters:
+ -----------
+
+ atlas: TextureAtlas
+ Texture atlas where glyph texture will be stored
+
+ filename: str
+ Font filename
+
+ size : float
+ Font size
+ '''
+ self.atlas = atlas
+ self.filename = filename
+ self.size = size
+ self.glyphs = {}
+ face = Face( self.filename )
+ face.set_char_size( int(self.size*64))
+ self._dirty = False
+ metrics = face.size
+ self.ascender = metrics.ascender/64.0
+ self.descender = metrics.descender/64.0
+ self.height = metrics.height/64.0
+ self.linegap = self.height - self.ascender + self.descender
+ self.depth = atlas.depth
+ set_lcd_filter(FT_LCD_FILTER_LIGHT)
+
+
+ def __getitem__(self, charcode):
+ '''
+ x.__getitem__(y) <==> x[y]
+ '''
+ if charcode not in self.glyphs.keys():
+ self.load('%c' % charcode)
+ return self.glyphs[charcode]
+
+
+
+ def get_texid(self):
+ '''
+ Get underlying texture identity .
+ '''
+
+ if self._dirty:
+ self.atlas.upload()
+ self._dirty = False
+ return self.atlas.texid
+
+ texid = property(get_texid,
+ doc='''Underlying texture identity.''')
+
+
+
+ def load(self, charcodes = ''):
+ '''
+ Build glyphs corresponding to individual characters in charcodes.
+
+ Parameters:
+ -----------
+
+ charcodes: [str | unicode]
+ Set of characters to be represented
+ '''
+ face = Face( self.filename )
+ pen = Vector(0,0)
+ hres = 16*72
+ hscale = 1.0/16
+
+ for charcode in charcodes:
+ face.set_char_size( int(self.size * 64), 0, hres, 72 )
+ matrix = Matrix( int((hscale) * 0x10000L), int((0.0) *
0x10000L),
+ int((0.0) * 0x10000L), int((1.0) *
0x10000L) )
+ face.set_transform( matrix, pen )
+ if charcode in self.glyphs.keys():
+ continue
+
+ self.dirty = True
+ flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT
+ flags |= FT_LOAD_TARGET_LCD
+
+ face.load_char( charcode, flags )
+ bitmap = face.glyph.bitmap
+ left = face.glyph.bitmap_left
+ top = face.glyph.bitmap_top
+ width = face.glyph.bitmap.width
+ rows = face.glyph.bitmap.rows
+ pitch = face.glyph.bitmap.pitch
+
+ x,y,w,h = self.atlas.get_region(width/self.depth+2, rows+2)
+ if x < 0:
+ print 'Missed !'
+ continue
+ x,y = x+1, y+1
+ w,h = w-2, h-2
+ data = []
+ for i in range(rows):
+ data.extend(bitmap.buffer[i*pitch:i*pitch+width])
+ data = np.array(data,dtype=np.ubyte).reshape(h,w,3)
+ gamma = 1.5
+ Z = ((data/255.0)**(gamma))
+ data = (Z*255).astype(np.ubyte)
+ self.atlas.set_region((x,y,w,h), data)
+
+ # Build glyph
+ size = w,h
+ offset = left, top
+ advance= face.glyph.advance.x, face.glyph.advance.y
+
+ u0 = (x + 0.0)/float(self.atlas.width)
+ v0 = (y + 0.0)/float(self.atlas.height)
+ u1 = (x + w - 0.0)/float(self.atlas.width)
+ v1 = (y + h - 0.0)/float(self.atlas.height)
+ texcoords = (u0,v0,u1,v1)
+ glyph = TextureGlyph(charcode, size, offset, advance,
texcoords)
+ self.glyphs[charcode] = glyph
+
+ # Generate kerning
+ for g in self.glyphs.values():
+ # 64 * 64 because of 26.6 encoding AND the transform
matrix used
+ # in texture_font_load_face (hres = 64)
+ kerning = face.get_kerning(g.charcode, charcode,
mode=FT_KERNING_UNFITTED)
+ if kerning.x != 0:
+ glyph.kerning[g.charcode] = kerning.x/(64.0*64.0)
+ kerning = face.get_kerning(charcode, g.charcode,
mode=FT_KERNING_UNFITTED)
+ if kerning.x != 0:
+ g.kerning[charcode] = kerning.x/(64.0*64.0)
+
+ # High resolution advance.x calculation
+ # gindex = face.get_char_index( charcode )
+ # a = face.get_advance(gindex, FT_LOAD_RENDER |
FT_LOAD_TARGET_LCD)/(64*72)
+ # glyph.advance = a, glyph.advance[1]
+
+
+class TextureGlyph:
+ '''
+ A texture glyph gathers information relative to the
size/offset/advance and
+ texture coordinates of a single character. It is generally built
+ automatically by a TextureFont.
+ '''
+
+ def __init__(self, charcode, size, offset, advance, texcoords):
+ '''
+ Build a new texture glyph
+
+ Parameter:
+ ----------
+
+ charcode : char
+ Represented character
+
+ size: tuple of 2 ints
+ Glyph size in pixels
+
+ offset: tuple of 2 floats
+ Glyph offset relatively to anchor point
+
+ advance: tuple of 2 floats
+ Glyph advance
+
+ texcoords: tuple of 4 floats
+ Texture coordinates of bottom-left and top-right corner
+ '''
+ self.charcode = charcode
+ self.size = size
+ self.offset = offset
+ self.advance = advance
+ self.texcoords = texcoords
+ self.kerning = {}
+
+
+ def get_kerning(self, charcode):
+ ''' Get kerning information
+
+ Parameters:
+ -----------
+
+ charcode: char
+ Character preceding this glyph
+ '''
+ if charcode in self.kerning.keys():
+ return self.kerning[charcode]
+ else:
+ return 0
=======================================
--- /dev/null
+++ /tags/release-0.4/examples/wordle.py Thu Nov 8 23:36:08 2012
@@ -0,0 +1,138 @@
+#!/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.
+#
+#
-----------------------------------------------------------------------------
+import math
+import numpy as np
+from freetype import *
+import matplotlib.pyplot as plt
+
+
+def make_label(text, filename, size=12, angle=0):
+ '''
+ Parameters:
+ -----------
+ text : string
+ Text to be displayed
+ filename : string
+ Path to a font
+ size : int
+ Font size in 1/64th points
+ angle : float
+ Text angle in degrees
+ '''
+ face = Face(filename)
+ face.set_char_size( size*64 )
+ angle = (angle/180.0)*math.pi
+ matrix = FT_Matrix( (int)( math.cos( angle ) * 0x10000L ),
+ (int)(-math.sin( angle ) * 0x10000L ),
+ (int)( math.sin( angle ) * 0x10000L ),
+ (int)( math.cos( angle ) * 0x10000L ))
+ flags = FT_LOAD_RENDER
+ pen = FT_Vector(0,0)
+ FT_Set_Transform( face._FT_Face, byref(matrix), byref(pen) )
+ previous = 0
+ xmin, xmax = 0, 0
+ ymin, ymax = 0, 0
+ for c in text:
+ face.load_char(c, flags)
+ kerning = face.get_kerning(previous, c)
+ previous = c
+ bitmap = face.glyph.bitmap
+ pitch = face.glyph.bitmap.pitch
+ width = face.glyph.bitmap.width
+ rows = face.glyph.bitmap.rows
+ top = face.glyph.bitmap_top
+ left = face.glyph.bitmap_left
+ pen.x += kerning.x
+ x0 = (pen.x >> 6) + left
+ x1 = x0 + width
+ y0 = (pen.y >> 6) - (rows - top)
+ y1 = y0 + rows
+ xmin, xmax = min(xmin, x0), max(xmax, x1)
+ ymin, ymax = min(ymin, y0), max(ymax, y1)
+ pen.x += face.glyph.advance.x
+ pen.y += face.glyph.advance.y
+
+ L = np.zeros((ymax-ymin, xmax-xmin),dtype=np.ubyte)
+ previous = 0
+ pen.x, pen.y = 0, 0
+ for c in text:
+ face.load_char(c, flags)
+ kerning = face.get_kerning(previous, c)
+ previous = c
+ bitmap = face.glyph.bitmap
+ pitch = face.glyph.bitmap.pitch
+ width = face.glyph.bitmap.width
+ rows = face.glyph.bitmap.rows
+ top = face.glyph.bitmap_top
+ left = face.glyph.bitmap_left
+ pen.x += kerning.x
+ x = (pen.x >> 6) - xmin + left
+ y = (pen.y >> 6) - ymin - (rows - top)
+ data = []
+ for j in range(rows):
+ data.extend(bitmap.buffer[j*pitch:j*pitch+width])
+ if len(data):
+ Z = np.array(data,dtype=np.ubyte).reshape(rows, width)
+ L[y:y+rows,x:x+width] |= Z[::-1,::1]
+ pen.x += face.glyph.advance.x
+ pen.y += face.glyph.advance.y
+
+ return L
+
+
+if __name__ == '__main__':
+ import Image
+
+ n_words = 100
+ H, W, dpi = 600, 800, 72.0
+ I = np.zeros((H, W, 3), dtype=np.ubyte)
+ S = np.random.normal(0,1,n_words)
+ S = (S-S.min())/(S.max()-S.min())
+ S = np.sort(1-np.sqrt(S))[::-1]
+ sizes = (12 + S*48).astype(int).tolist()
+
+ def spiral():
+ eccentricity = 1.5
+ radius = 8
+ step = 0.1
+ t = 0
+ while True:
+ t += step
+ yield eccentricity*radius*t*math.cos(t), radius*t*math.sin(t)
+
+ fails = 0
+ for size in sizes:
+ angle = np.random.randint(-25,25)
+ L = make_label('Hello', './Vera.ttf', size, angle=angle)
+ h,w = L.shape
+ if h < H and w < W:
+ x0 = W//2 + (np.random.uniform()-.1)*50
+ y0 = H//2 + (np.random.uniform()-.1)*50
+ for dx,dy in spiral():
+ c = .25+.75*np.random.random()
+ x = int(x0+dx)
+ y = int(y0+dy)
+ if x <= w//2 or y <= h//2 or x >= (W-w//2) or y >=
(H-h//2):
+ fails += 1
+ break
+ if (I[y-h//2:y-h//2+h, x-w//2:x-w//2+w,0] * L).sum() == 0:
+ I[y-h//2:y-h//2+h, x-w//2:x-w//2+w,0] |= (c *
L).astype(int)
+ I[y-h//2:y-h//2+h, x-w//2:x-w//2+w,1] |= (c *
L).astype(int)
+ I[y-h//2:y-h//2+h, x-w//2:x-w//2+w,2] |= (c *
L).astype(int)
+ break
+
+ print "Number of fails:", fails
+ fig = plt.figure(figsize=(W/dpi,H/dpi), dpi=dpi)
+ ax = fig.add_axes([0,0,1,1], frameon=False)
+ ax.imshow(I, interpolation='nearest', cmap=plt.cm.gray, origin='lower')
+ #plt.axis('off')
+ plt.show()
+ I = Image.fromarray(I[::-1,::1,::1], mode='RGB')
+ I.save('wordle.png')
+
=======================================
--- /trunk/freetype/ft_enums.py Tue Feb 1 14:08:01 2011
+++ /dev/null
@@ -1,1298 +0,0 @@
-#
-----------------------------------------------------------------------------
-#
-# FreeType high-level python API - Copyright 2011 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_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_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_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.
-'''
-
-#
-----------------------------------------------------------------------------
-# 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_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}
-for _item in FT_PIXEL_MODES.items():
- _name, _mode = _item
- globals()[_name] = _mode
-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
-
-
-
-#
-----------------------------------------------------------------------------
-# 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
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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.
-
-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
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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 }
-globals().update(FT_FACE_FLAGS)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-
-#
-----------------------------------------------------------------------------
-# A list of valid values for the ‘encoding_id’ for TT_PLATFORM_MACINTOSH
-# charmaps and name entries.
-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)
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-#
-----------------------------------------------------------------------------
-# 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)
-
-
-#
-----------------------------------------------------------------------------
-# 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_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,
***The diff for this file has been truncated for email.***
=======================================
--- /trunk/setup.py Tue Jun 26 06:24:11 2012
+++ /trunk/setup.py Thu Nov 8 23:36:08 2012
@@ -6,7 +6,7 @@
from distutils.core import setup

setup( name = 'freetype-py',
- version = '1.0',
+ version = '0.4',
description = 'Freetype python bindings',
author = 'Nicolas P. Rougier',
author_email='Nicolas...@inria.fr',
=======================================
--- /trunk/setup.py Tue Jun 26 06:24:11 2012
+++ /tags/release-0.4/setup.py Thu Nov 8 23:36:08 2012
@@ -6,7 +6,7 @@
from distutils.core import setup

setup( name = 'freetype-py',
- version = '1.0',
+ version = '0.4',
description = 'Freetype python bindings',
author = 'Nicolas P. Rougier',
author_email='Nicolas...@inria.fr',
Reply all
Reply to author
Forward
0 new messages