[Python-modules-commits] [freetype-py] 01/06: Imported Upstream version 1.0.2
Daniel Glassey
wdg at moszumanska.debian.org
Thu Nov 12 18:33:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
wdg pushed a commit to branch master
in repository freetype-py.
commit d9a145f9a4e18db65512e83adc0a0162fc3c6eed
Author: Daniel Glassey <wdg at debian.org>
Date: Thu Nov 12 16:05:22 2015 +0000
Imported Upstream version 1.0.2
---
LICENSE.txt | 30 +
MANIFEST.in | 10 +
PKG-INFO | 81 +
README.rst | 94 ++
examples/Vera-gamma(1.2)-hinting(0,1)-lcd(1).png | Bin 0 -> 102430 bytes
examples/Vera.ttf | Bin 0 -> 65932 bytes
examples/VeraMono.ttf | Bin 0 -> 49224 bytes
examples/agg-trick.py | 72 +
examples/ascii.py | 120 ++
examples/example_1.py | 100 ++
examples/font-info.py | 44 +
examples/ftdump.py | 297 ++++
examples/glyph-alpha.py | 31 +
examples/glyph-color.py | 94 ++
examples/glyph-lcd.py | 32 +
examples/glyph-metrics.pdf | Bin 0 -> 17224 bytes
examples/glyph-metrics.py | 233 +++
examples/glyph-monochrome.py | 43 +
examples/glyph-outline.py | 37 +
examples/glyph-vector-2.py | 98 ++
examples/glyph-vector.py | 90 +
examples/hello-world.py | 54 +
examples/opengl.py | 122 ++
examples/sfnt-names.py | 64 +
examples/shader.py | 163 ++
examples/shader.pyc | Bin 0 -> 4698 bytes
examples/subpixel-positioning.py | 236 +++
examples/texture_font.py | 421 +++++
examples/texture_font.pyc | Bin 0 -> 11806 bytes
examples/wordle.png | Bin 0 -> 137513 bytes
examples/wordle.py | 137 ++
freetype/__init__.py | 1907 ++++++++++++++++++++++
freetype/ft_enums/__init__.py | 120 ++
freetype/ft_enums/ft_encodings.py | 107 ++
freetype/ft_enums/ft_face_flags.py | 132 ++
freetype/ft_enums/ft_fstypes.py | 64 +
freetype/ft_enums/ft_glyph_bbox_modes.py | 36 +
freetype/ft_enums/ft_glyph_formats.py | 57 +
freetype/ft_enums/ft_kerning_modes.py | 30 +
freetype/ft_enums/ft_lcd_filters.py | 48 +
freetype/ft_enums/ft_load_flags.py | 153 ++
freetype/ft_enums/ft_load_targets.py | 68 +
freetype/ft_enums/ft_open_modes.py | 42 +
freetype/ft_enums/ft_outline_flags.py | 84 +
freetype/ft_enums/ft_pixel_modes.py | 75 +
freetype/ft_enums/ft_render_modes.py | 56 +
freetype/ft_enums/ft_stroker_borders.py | 35 +
freetype/ft_enums/ft_stroker_linecaps.py | 31 +
freetype/ft_enums/ft_stroker_linejoins.py | 33 +
freetype/ft_enums/ft_style_flags.py | 24 +
freetype/ft_enums/tt_adobe_ids.py | 37 +
freetype/ft_enums/tt_apple_ids.py | 50 +
freetype/ft_enums/tt_mac_ids.py | 116 ++
freetype/ft_enums/tt_mac_langids.py | 373 +++++
freetype/ft_enums/tt_ms_ids.py | 65 +
freetype/ft_enums/tt_ms_langids.py | 749 +++++++++
freetype/ft_enums/tt_name_ids.py | 91 ++
freetype/ft_enums/tt_platforms.py | 61 +
freetype/ft_errors.py | 104 ++
freetype/ft_structs.py | 944 +++++++++++
freetype/ft_types.py | 155 ++
freetype/raw.py | 128 ++
freetype_py.egg-info/PKG-INFO | 81 +
freetype_py.egg-info/SOURCES.txt | 66 +
freetype_py.egg-info/dependency_links.txt | 1 +
freetype_py.egg-info/top_level.txt | 1 +
setup.cfg | 5 +
setup.py | 94 ++
68 files changed, 8926 insertions(+)
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..e3d4181
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,30 @@
+freetype-py is licensed under the terms of the new or revised BSD license, as
+follows:
+
+Copyright (c) 2011-2014, Nicolas P. Rougier
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this
+list of conditions and the following disclaimer in the documentation and/or
+other materials provided with the distribution.
+
+Neither the name of the freetype-py Development Team nor the names of its
+contributors may be used to endorse or promote products derived from this
+software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..0c0387e
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,10 @@
+# -----------------------------------------------------------------------------
+#
+# FreeType high-level python API - copyright 2011 Nicolas P. Rougier
+# Distributed under the terms of the new BSD license.
+#
+# -----------------------------------------------------------------------------
+recursive-include examples *
+include MANIFEST.in
+include LICENSE.txt
+include README.rst
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..07710a8
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,81 @@
+Metadata-Version: 1.1
+Name: freetype-py
+Version: 1.0.2
+Summary: Freetype python bindings
+Home-page: https://github.com/rougier/freetype-py
+Author: Nicolas P. Rougier
+Author-email: Nicolas.Rougier at inria.fr
+License: UNKNOWN
+Description:
+ FreeType high-level python API
+ ==============================
+
+ Freetype python provides bindings for the FreeType library. Only the high-level API is bound.
+
+ Documentation available at: http://freetype-py.readthedocs.org/en/latest/
+
+ Installation
+ ============
+
+ To be able to use freetype python, you need the freetype library version 2
+ installed on your system.
+
+ Mac users
+ ---------
+
+ Freetype should be already installed on your system. If not, either install it
+ using `homebrew <http://brew.sh>`_ or compile it and place the library binary
+ file in '/usr/local/lib'.
+
+ Linux users
+ -----------
+
+ Freetype should be already installed on your system. If not, either install
+ relevant package from your package manager or compile from sources and place
+ the library binary file in '/usr/local/lib'.
+
+ Window users
+ ------------
+
+ You can try to install a window binaries available from the Freetype site or
+ you can compile it from sources. In such a case, make sure the resulting
+ library binaries is named 'Freetype.dll' (and not something like
+ Freetype245.dll) and make sure to place a copy in Windows/System32 directory.
+
+ Usage example
+ =============
+
+ .. code:: python
+
+ import freetype
+ face = freetype.Face("Vera.ttf")
+ face.set_char_size( 48*64 )
+ face.load_char('S')
+ bitmap = face.glyph.bitmap
+ print bitmap.buffer
+
+ Contributors
+ ============
+
+ * Titusz Pan (bug report)
+ * Ekkehard.Blanz (bug report)
+ * Jānis Lībeks (bug report)
+ * Frantisek Malina (typo)
+ * Tillmann Karras (bug report & fix)
+ * Matthew Sitton (bug report & fix)
+ * Tao Gong (bug report)
+ * Matthew Sitton (Remove raw interfaces from the __init__.py file)
+
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: X11 Applications
+Classifier: Environment :: MacOS X
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: GNU General Public License (GPL)
+Classifier: Operating System :: MacOS
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: Unix
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Multimedia :: Graphics
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..b8c9ed7
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,94 @@
+FreeType high-level python API
+==============================
+
+Freetype python provides bindings for the FreeType library. Only the high-level API is bound.
+
+Documentation available at: http://freetype-py.readthedocs.org/en/latest/
+
+Installation
+============
+
+To be able to use freetype python, you need the freetype library version 2
+installed on your system.
+
+Mac users
+---------
+
+Freetype should be already installed on your system. If not, either install it
+using `homebrew <http://brew.sh>`_ or compile it and place the library binary
+file in '/usr/local/lib'.
+
+Linux users
+-----------
+
+Freetype should be already installed on your system. If not, either install
+relevant package from your package manager or compile from sources and place
+the library binary file in '/usr/local/lib'.
+
+Window users
+------------
+
+You can try to install a window binaries available from the Freetype site or
+you can compile it from sources. In such a case, make sure the resulting
+library binaries is named 'Freetype.dll' (and not something like
+Freetype245.dll) and make sure to place a copy in Windows/System32 directory.
+
+Usage example
+=============
+
+.. code:: python
+
+ import freetype
+ face = freetype.Face("Vera.ttf")
+ face.set_char_size( 48*64 )
+ face.load_char('S')
+ bitmap = face.glyph.bitmap
+ print bitmap.buffer
+
+Screenshots
+===========
+
+Screenshot below comes from the wordle.py example. No clever tricks here, just
+brute force.
+
+.. image:: doc/_static/wordle.png
+
+Screenshots below comes from the glyph-vector.py and glyph-vectopr-2.py
+examples showing how to access a glyph outline information and use it to draw
+the glyph. Rendering (with Bézier curves) is done using matplotlib.
+
+.. image:: doc/_static/S.png
+.. image:: doc/_static/G.png
+
+
+Screenshot below comes from the glyph-color.py showing how to draw and combine
+a glyph outline with the regular glyph.
+
+.. image:: doc/_static/outline.png
+
+The screenshot below comes from the hello-world.py example showing how to draw
+text in a bitmap (that has been zoomed in to show antialiasing).
+
+.. image:: doc/_static/hello-world.png
+
+
+The screenshot below comes from the agg-trick.py example showing an
+implementation of ideas from the `Texts Rasterization Exposures
+<http://agg.sourceforge.net/antigrain.com/research/font_rasterization/>`_ by
+Maxim Shemarev.
+
+.. image:: doc/_static/agg-trick.png
+
+
+Contributors
+============
+
+* Titusz Pan (bug report)
+* Ekkehard.Blanz (bug report)
+* Jānis Lībeks (bug report)
+* Frantisek Malina (typo)
+* Tillmann Karras (bug report & fix)
+* Matthew Sitton (bug report & fix)
+* Tao Gong (bug report)
+* Matthew Sitton (Remove raw interfaces from the __init__.py file)
+* Daniel McCloy (Adde glyph_name function)
diff --git a/examples/Vera-gamma(1.2)-hinting(0,1)-lcd(1).png b/examples/Vera-gamma(1.2)-hinting(0,1)-lcd(1).png
new file mode 100644
index 0000000..8148129
Binary files /dev/null and b/examples/Vera-gamma(1.2)-hinting(0,1)-lcd(1).png differ
diff --git a/examples/Vera.ttf b/examples/Vera.ttf
new file mode 100644
index 0000000..58cd6b5
Binary files /dev/null and b/examples/Vera.ttf differ
diff --git a/examples/VeraMono.ttf b/examples/VeraMono.ttf
new file mode 100644
index 0000000..139f0b4
Binary files /dev/null and b/examples/VeraMono.ttf differ
diff --git a/examples/agg-trick.py b/examples/agg-trick.py
new file mode 100644
index 0000000..87f4736
--- /dev/null
+++ b/examples/agg-trick.py
@@ -0,0 +1,72 @@
+#!/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.
+#
+# -----------------------------------------------------------------------------
+from freetype import *
+import numpy as np
+from PIL import Image
+
+
+def render(filename = "Vera.ttf", hinting = (False,False), gamma = 1.5, lcd=False):
+ text = "A Quick Brown Fox Jumps Over The Lazy Dog 0123456789"
+
+ W,H,D = 680, 280, 1
+ Z = np.zeros( (H,W), dtype=np.ubyte )
+ face = Face(filename)
+ pen = Vector(5*64, (H-10)*64)
+
+ flags = FT_LOAD_RENDER
+ if hinting[1]: flags |= FT_LOAD_FORCE_AUTOHINT
+ else: flags |= FT_LOAD_NO_HINTING
+ if hinting[0]: hres, hscale = 72, 1.0
+ else: hres, hscale = 72*10, 0.1
+ if lcd:
+ flags |= FT_LOAD_TARGET_LCD
+ Z = np.zeros( (H,W,3), dtype=np.ubyte )
+ set_lcd_filter( FT_LCD_FILTER_DEFAULT )
+
+
+ for size in range(9,23):
+ face.set_char_size( size * 64, 0, hres, 72 )
+ matrix = Matrix( int((hscale) * 0x10000), int((0.0) * 0x10000),
+ int((0.0) * 0x10000), int((1.0) * 0x10000) )
+ previous = 0
+ pen.x = 5*64
+ for current in text:
+ face.set_transform( matrix, pen )
+ face.load_char( current, flags)
+ kerning = face.get_kerning( previous, current, FT_KERNING_UNSCALED )
+ pen.x += kerning.x
+ glyph = face.glyph
+ bitmap = glyph.bitmap
+ x, y = glyph.bitmap_left, glyph.bitmap_top
+ w, h, p = bitmap.width, bitmap.rows, bitmap.pitch
+ buff = np.array(bitmap.buffer, dtype=np.ubyte).reshape((h,p))
+ if lcd:
+ Z[H-y:H-y+h,x:x+w/3].flat |= buff[:,:w].flatten()
+ else:
+ Z[H-y:H-y+h,x:x+w].flat |= buff[:,:w].flatten()
+ pen.x += glyph.advance.x
+ previous = current
+ pen.y -= (size+4)*64
+
+ # Gamma correction
+ Z = (Z/255.0)**(gamma)
+ Z = ((1-Z)*255).astype(np.ubyte)
+ if lcd:
+ I = Image.fromarray(Z, mode='RGB')
+ else:
+ I = Image.fromarray(Z, mode='L')
+
+ name = filename.split('.')[0]
+ filename = '%s-gamma(%.1f)-hinting(%d,%d)-lcd(%d).png' % (name,gamma,hinting[0],hinting[1],lcd)
+ I.save(filename)
+
+
+
+if __name__ == '__main__':
+ render('Vera.ttf', (0,1), 1.25, True)
diff --git a/examples/ascii.py b/examples/ascii.py
new file mode 100644
index 0000000..c39be01
--- /dev/null
+++ b/examples/ascii.py
@@ -0,0 +1,120 @@
+#!/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.
+#
+# -----------------------------------------------------------------------------
+import numpy
+import os, sys
+from freetype import *
+
+
+class ColorMap:
+ ''' A colormap is used to map scalar values to colors. It is build by
+ adding couples of (value,color) where value must be between 0 and 1.
+ The 'scale' method allows to specify the range of the colormap and
+ the 'color' method then returns a color for any value. '''
+
+ def __init__ (self, colors):
+ self.colors = colors
+ self.min = 0
+ self.max = 1
+
+ def scale (self, min, max):
+ self.min, self.max = min,max
+
+ def color (self, value):
+ ''' Return the color corresponding to value. '''
+ if not len(self.colors):
+ return (0,0,0)
+ elif len(self.colors) == 1:
+ return self.colors[0][1]
+ elif value < self.min:
+ return self.colors[0][1]
+ elif value > self.max:
+ return self.colors[-1][1]
+ value = (value-self.min)/(self.max-self.min)
+ sup_color = self.colors[0]
+ inf_color = self.colors[-1]
+ for i in range (len(self.colors)-1):
+ if value < self.colors[i+1][0]:
+ inf_color = self.colors[i]
+ sup_color = self.colors[i+1]
+ break
+ r = (value-inf_color[0]) / (sup_color[0] - inf_color[0])
+ if r < 0: r = -r
+ color = [sup_color[1][0]*r + inf_color[1][0]*(1-r),
+ sup_color[1][1]*r + inf_color[1][1]*(1-r),
+ sup_color[1][2]*r + inf_color[1][2]*(1-r)]
+ return color
+
+# Some colormaps
+CM_IceAndFire = ColorMap([(0.00, (0.0, 0.0, 1.0)),
+ (0.25, (0.0, 0.5, 1.0)),
+ (0.50, (1.0, 1.0, 1.0)),
+ (0.75, (1.0, 1.0, 0.0)),
+ (1.00, (1.0, 0.0, 0.0))])
+CM_Ice = ColorMap([(0.00, (0.0, 0.0, 1.0)),
+ (0.50, (0.5, 0.5, 1.0)),
+ (1.00, (1.0, 1.0, 1.0))])
+CM_Fire = ColorMap([(0.00, (1.0, 1.0, 1.0)),
+ (0.50, (1.0, 1.0, 0.0)),
+ (1.00, (1.0, 0.0, 0.0))])
+CM_Hot = ColorMap([(0.00, (0.0, 0.0, 0.0)),
+ (0.33, (1.0, 0.0, 0.0)),
+ (0.66, (1.0, 1.0, 0.0)),
+ (1.00, (1.0, 1.0, 1.0))])
+CM_Grey = ColorMap([(0.00, (0.0, 0.0, 0.0)),
+ (1.00, (1.0, 1.0, 1.0))])
+
+
+
+def imshow (Z, vmin=None, vmax=None, cmap=CM_Hot, show_cmap=False):
+ ''' Show a 2D numpy array using terminal colors '''
+
+ if len(Z.shape) != 2:
+ print ("Cannot display non 2D array")
+ return
+
+ vmin = vmin or Z.min()
+ vmax = vmax or Z.max()
+ cmap.scale (vmin, vmax)
+
+ # Build initialization string that setup terminal colors
+ init = ''
+ for i in range(240):
+ v = cmap.min + (i/240.0)* (cmap.max - cmap.min)
+ r,g,b = cmap.color (v)
+ init += "\x1b]4;%d;rgb:%02x/%02x/%02x\x1b\\" % (16+i, int(r*255),int(g*255),int(b*255))
+
+ # Build array data string
+ data = ''
+ for i in range(Z.shape[0]):
+ for j in range(Z.shape[1]):
+ c = 16 + int( ((Z[Z.shape[0]-i-1,j]-cmap.min) / (cmap.max-cmap.min))*239)
+ if (c < 16):
+ c=16
+ elif (c > 255):
+ c=255
+ data += "\x1b[48;5;%dm " % c
+ u = cmap.max - (i/float(Z.shape[0]-1)) * ((cmap.max-cmap.min))
+ if show_cmap:
+ data += "\x1b[0m "
+ data += "\x1b[48;5;%dm " % (16 + (1-i/float(Z.shape[0]))*239)
+ data += "\x1b[0m %+.2f" % u
+ data += "\x1b[0m\n"
+ print (init+data[:-1]+'\x1b[0m')
+
+
+if __name__ == '__main__':
+ face = Face('./Vera.ttf')
+ face.set_char_size( 32*64 )
+ face.load_glyph(face.get_char_index('S'))
+ slot = face.glyph
+ bitmap = slot.bitmap
+ data, rows, width = bitmap.buffer, bitmap.rows, bitmap.width
+ Z = numpy.array(data,dtype=float).reshape(rows,width)
+ Z = Z[::-1,:]
+ imshow (Z, cmap=CM_Grey)
diff --git a/examples/example_1.py b/examples/example_1.py
new file mode 100644
index 0000000..79960c1
--- /dev/null
+++ b/examples/example_1.py
@@ -0,0 +1,100 @@
+#!/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.
+#
+# -----------------------------------------------------------------------------
+#
+# Direct translation of example 1 from the freetype tutorial:
+# http://www.freetype.org/freetype2/docs/tutorial/step1.html
+#
+import math
+
+import matplotlib.pyplot as plt
+from freetype.raw import *
+from PIL import Image
+
+WIDTH, HEIGHT = 640, 480
+image = Image.new('L', (WIDTH,HEIGHT))
+
+def to_c_str(text):
+ ''' Convert python strings to null terminated c strings. '''
+ cStr = create_string_buffer(text.encode(encoding='UTF-8'))
+ return cast(pointer(cStr), POINTER(c_char))
+
+def draw_bitmap( bitmap, x, y):
+ global image
+
+ x_max = x + bitmap.width
+ y_max = y + bitmap.rows
+ p = 0
+ for p,i in enumerate(range(x,x_max)):
+ for q,j in enumerate(range(y,y_max)):
+ if i < 0 or j < 0 or i >= WIDTH or j >= HEIGHT:
+ continue;
+ pixel = image.getpixel((i,j))
+ pixel |= int(bitmap.buffer[q * bitmap.width + p]);
+ image.putpixel((i,j), pixel)
+
+def main():
+
+ library = FT_Library()
+ matrix = FT_Matrix()
+ face = FT_Face()
+ pen = FT_Vector()
+ filename= 'Vera.ttf'
+ text = 'Hello World !'
+ num_chars = len(text)
+ angle = ( 25.0 / 360 ) * 3.14159 * 2
+
+ # initialize library, error handling omitted
+ error = FT_Init_FreeType( byref(library) )
+
+ # create face object, error handling omitted
+ error = FT_New_Face( library, to_c_str(filename), 0, byref(face) )
+
+
+ # set character size: 50pt at 100dpi, error handling omitted
+ error = FT_Set_Char_Size( face, 50 * 64, 0, 100, 0 )
+ slot = face.contents.glyph
+
+ # set up matrix
+ matrix.xx = (int)( math.cos( angle ) * 0x10000 )
+ matrix.xy = (int)(-math.sin( angle ) * 0x10000 )
+ matrix.yx = (int)( math.sin( angle ) * 0x10000 )
+ matrix.yy = (int)( math.cos( angle ) * 0x10000 )
+
+ # the pen position in 26.6 cartesian space coordinates; */
+ # start at (300,200) relative to the upper left corner */
+ pen.x = 200 * 64;
+ pen.y = ( HEIGHT - 300 ) * 64
+
+ for n in range(num_chars):
+ # set transformation
+ FT_Set_Transform( face, byref(matrix), byref(pen) )
+
+ # load glyph image into the slot (erase previous one)
+ charcode = ord(text[n])
+ index = FT_Get_Char_Index( face, charcode )
+ FT_Load_Glyph( face, index, FT_LOAD_RENDER )
+
+ # now, draw to our target surface (convert position)
+ draw_bitmap( slot.contents.bitmap,
+ slot.contents.bitmap_left,
+ HEIGHT - slot.contents.bitmap_top )
+
+ # increment pen position
+ pen.x += slot.contents.advance.x
+ pen.y += slot.contents.advance.y
+
+ FT_Done_Face(face)
+ FT_Done_FreeType(library)
+
+ plt.imshow(image, origin='lower',
+ interpolation='nearest', cmap=plt.cm.gray)
+ plt.show()
+
+if __name__ == '__main__':
+ main()
diff --git a/examples/font-info.py b/examples/font-info.py
new file mode 100644
index 0000000..d362f87
--- /dev/null
+++ b/examples/font-info.py
@@ -0,0 +1,44 @@
+#!/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.
+#
+# -----------------------------------------------------------------------------
+from freetype import *
+
+if __name__ == '__main__':
+ import sys
+
+ if len(sys.argv) < 2:
+ print("Usage: %s font_filename" % sys.argv[0])
+ sys.exit()
+
+ face = Face(sys.argv[1])
+
+ print ('Family name: {}'.format(face.family_name))
+ print ('Style name: {}'.format(face.style_name))
+ print ('Charmaps: {}'.format([charmap.encoding_name for charmap in face.charmaps]))
+ print ('')
+ print ('Face number: {}'.format(face.num_faces))
+ print ('Glyph number: {}'.format(face.num_glyphs))
+ print ('Available sizes: {}'.format(face.available_sizes))
+ print ('')
+ print ('units per em: {}'.format(face.units_per_EM))
+ print ('ascender: {}'.format(face.ascender))
+ print ('descender: {}'.format(face.descender))
+ print ('height: {}'.format(face.height))
+ print ('')
+ print ('max_advance_width: {}'.format(face.max_advance_width))
+ print ('max_advance_height: {}'.format(face.max_advance_height))
+ print ('')
+ print ('underline_position: {}'.format(face.underline_position))
+ print ('underline_thickness: {}'.format(face.underline_thickness))
+ print ('')
+ print ('Has horizontal: {}'.format(face.has_horizontal))
+ print ('Has vertical: {}'.format(face.has_vertical))
+ print ('Has kerning: {}'.format(face.has_kerning))
+ print ('Is fixed width: {}'.format(face.is_fixed_width))
+ print ('Is scalable: {}'.format(face.is_scalable))
+ print ('')
diff --git a/examples/ftdump.py b/examples/ftdump.py
new file mode 100644
index 0000000..893d979
--- /dev/null
+++ b/examples/ftdump.py
@@ -0,0 +1,297 @@
+#!/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.
+#
+# -----------------------------------------------------------------------------
+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:
+ 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 )
diff --git a/examples/glyph-alpha.py b/examples/glyph-alpha.py
new file mode 100644
index 0000000..8a95807
--- /dev/null
+++ b/examples/glyph-alpha.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# -----------------------------------------------------------------------------
+#
... 8397 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/freetype-py.git
More information about the Python-modules-commits
mailing list