From 36623f13d922461c897fe0ae1ff550a073385329 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 13 Jan 2015 08:50:27 -0800 Subject: Add FreeType python bindings to third_party. --- third_party/freetype-py/examples/glyph-lcd.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 third_party/freetype-py/examples/glyph-lcd.py (limited to 'third_party/freetype-py/examples/glyph-lcd.py') diff --git a/third_party/freetype-py/examples/glyph-lcd.py b/third_party/freetype-py/examples/glyph-lcd.py new file mode 100644 index 0000000..5992c12 --- /dev/null +++ b/third_party/freetype-py/examples/glyph-lcd.py @@ -0,0 +1,32 @@ +#!/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 bitmap monochrome rendring +''' +from freetype import * + +if __name__ == '__main__': + import numpy + import matplotlib.pyplot as plt + + face = Face('./Vera.ttf') + face.set_char_size( 48*64 ) + face.load_char('S', FT_LOAD_RENDER | + FT_LOAD_TARGET_LCD ) + 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/3, 3) + plt.imshow(Z, interpolation='nearest', origin='lower') + plt.show() -- cgit v1.2.3