Tidy up hbtestfont and add README
This commit is contained in:
parent
70ae332fe6
commit
e5bed0a37f
|
@ -0,0 +1,10 @@
|
||||||
|
This contains a wrapping of harfbuzz into python. The module is dependent on pyrex. To build, type:
|
||||||
|
|
||||||
|
python setup.py build
|
||||||
|
|
||||||
|
In addition there is a test application, hbtestfont. It has GTK based gui output and for this, python modules for gtk, gobject and cairo are needed. The application may be run without gui output using the --nogui option.
|
||||||
|
|
||||||
|
Applications may be executed in the build context, without needing to install any modules or libraries, using the runpy script from the contrib/python directory. Thus one might type:
|
||||||
|
|
||||||
|
./runpy script/hbtestfont -f "Charis SIL" 0048 0069 0303
|
||||||
|
|
|
@ -3,57 +3,6 @@
|
||||||
import harfbuzz, optparse
|
import harfbuzz, optparse
|
||||||
from fontconfig import fcPattern
|
from fontconfig import fcPattern
|
||||||
|
|
||||||
try:
|
|
||||||
import gtk
|
|
||||||
import gobject
|
|
||||||
import cairo
|
|
||||||
from gtk import gdk
|
|
||||||
except :
|
|
||||||
raise SystemExit
|
|
||||||
import pygtk
|
|
||||||
|
|
||||||
if gtk.pygtk_version < (2, 8) :
|
|
||||||
print "PyGtk 2.8 or later required"
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
class GlyphsWindow (gtk.Widget) :
|
|
||||||
def __init__(self, fontname, bold, italic, size, glyphs) :
|
|
||||||
gtk.Widget.__init__(self)
|
|
||||||
self.fontname = fontname
|
|
||||||
self.size = size
|
|
||||||
self.glyphs = glyphs
|
|
||||||
self.bold = bold
|
|
||||||
self.italic = italic
|
|
||||||
|
|
||||||
def do_realize(self) :
|
|
||||||
self.set_flags(gtk.REALIZED)
|
|
||||||
self.window = gdk.Window(
|
|
||||||
self.get_parent_window(),
|
|
||||||
width = self.allocation.width,
|
|
||||||
height = self.allocation.height,
|
|
||||||
window_type = gdk.WINDOW_CHILD,
|
|
||||||
wclass = gdk.INPUT_OUTPUT,
|
|
||||||
event_mask = self.get_events() | gdk.EXPOSURE_MASK)
|
|
||||||
self.window.set_user_data(self)
|
|
||||||
self.style.attach(self.window)
|
|
||||||
self.style.set_background(self.window, gtk.STATE_NORMAL)
|
|
||||||
self.window.move_resize(*self.allocation)
|
|
||||||
|
|
||||||
def do_unrealize(self) :
|
|
||||||
self.window.destroy()
|
|
||||||
|
|
||||||
def do_expose_event(self, event) :
|
|
||||||
cr = self.window.cairo_create()
|
|
||||||
cr.set_matrix(cairo.Matrix(1, 0, 0, 1, 0, 2 * self.size))
|
|
||||||
cr.set_font_face(cairo.ToyFontFace(self.fontname, cairo.FONT_SLANT_ITALIC if self.italic else cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD if self.bold else cairo.FONT_WEIGHT_NORMAL))
|
|
||||||
cr.set_font_size(self.size)
|
|
||||||
cr.show_glyphs(self.glyphs) # [(gid, originx, originy)]
|
|
||||||
|
|
||||||
buffer = None
|
|
||||||
|
|
||||||
def tracefn(ft, aType, index) :
|
|
||||||
print aType + "(" + str(index) + "): " + str(buffer.get_info())
|
|
||||||
|
|
||||||
usage = '''usage: %prog [options] codepoints
|
usage = '''usage: %prog [options] codepoints
|
||||||
Generates output of glyphs and positions. Each entry is of the form:
|
Generates output of glyphs and positions. Each entry is of the form:
|
||||||
glyphid>cluster@(offsetx,offsety)+(advancex,advancey)
|
glyphid>cluster@(offsetx,offsety)+(advancex,advancey)
|
||||||
|
@ -68,15 +17,18 @@ p.add_option('-f', '--font', help='Font to use to render glyphs. My be a font fi
|
||||||
p.add_option('-b', '--bold', help='Choose bold fonts', action='store_true')
|
p.add_option('-b', '--bold', help='Choose bold fonts', action='store_true')
|
||||||
p.add_option('-i', '--italic', help='Choose italic fonts', action='store_true')
|
p.add_option('-i', '--italic', help='Choose italic fonts', action='store_true')
|
||||||
p.add_option('-d', '--debug', action='store_true', help="Output trace info")
|
p.add_option('-d', '--debug', action='store_true', help="Output trace info")
|
||||||
|
p.add_option('--nogui', action='store_true', help="Don't display a gui")
|
||||||
(opts, args) = p.parse_args()
|
(opts, args) = p.parse_args()
|
||||||
|
|
||||||
fpat = opts.font + ":weight="
|
fpat = opts.font + ":weight="
|
||||||
fpat += "bold" if opts.bold else "medium"
|
fpat += "bold" if opts.bold else "medium"
|
||||||
|
fpat += ":slant="
|
||||||
fpat += "italic" if opts.italic else "roman"
|
fpat += "italic" if opts.italic else "roman"
|
||||||
pat = fcPattern(fpat)
|
pat = fcPattern(fpat)
|
||||||
fname = pat.getString("file", 0)
|
fname = pat.getString("file", 0)
|
||||||
family = pat.getString("family", 0)
|
family = pat.getString("family", 0)
|
||||||
print "Processing: " + fname
|
print "Processing: " + fname
|
||||||
|
|
||||||
ft = harfbuzz.ft(fname, opts.size)
|
ft = harfbuzz.ft(fname, opts.size)
|
||||||
text = "".join(unichr(int(c, 16)) for c in args)
|
text = "".join(unichr(int(c, 16)) for c in args)
|
||||||
bytes = text.encode('utf_8')
|
bytes = text.encode('utf_8')
|
||||||
|
@ -91,19 +43,67 @@ ft.shape(buffer, features = features)
|
||||||
res = buffer.get_info(64) # scale for 26.6
|
res = buffer.get_info(64) # scale for 26.6
|
||||||
print res
|
print res
|
||||||
|
|
||||||
glyphs = []
|
if not opts.nogui :
|
||||||
org = [0, 0]
|
try:
|
||||||
for g in res :
|
import gtk
|
||||||
glyphs.append((g.gid, org[0] + g.offset[0], org[1] + g.offset[1]))
|
import gobject
|
||||||
org[0] += g.advance[0]
|
import cairo
|
||||||
org[1] += g.advance[1]
|
from gtk import gdk
|
||||||
gobject.type_register(GlyphsWindow)
|
except :
|
||||||
win = gtk.Window()
|
raise SystemExit
|
||||||
win.resize(org[0] + 10, 3 * opts.size + 40)
|
import pygtk
|
||||||
win.connect('delete-event', gtk.main_quit)
|
|
||||||
frame = gtk.Frame("glyphs")
|
if gtk.pygtk_version < (2, 8) :
|
||||||
win.add(frame)
|
print "PyGtk 2.8 or later required"
|
||||||
w = GlyphsWindow(family, opts.bold, opts.italic, opts.size, glyphs)
|
raise SystemExit
|
||||||
frame.add(w)
|
|
||||||
win.show_all()
|
class GlyphsWindow (gtk.Widget) :
|
||||||
gtk.main()
|
def __init__(self, fontname, bold, italic, size, glyphs) :
|
||||||
|
gtk.Widget.__init__(self)
|
||||||
|
self.fontname = fontname
|
||||||
|
self.size = size
|
||||||
|
self.glyphs = glyphs
|
||||||
|
self.bold = bold
|
||||||
|
self.italic = italic
|
||||||
|
|
||||||
|
def do_realize(self) :
|
||||||
|
self.set_flags(gtk.REALIZED)
|
||||||
|
self.window = gdk.Window(
|
||||||
|
self.get_parent_window(),
|
||||||
|
width = self.allocation.width,
|
||||||
|
height = self.allocation.height,
|
||||||
|
window_type = gdk.WINDOW_CHILD,
|
||||||
|
wclass = gdk.INPUT_OUTPUT,
|
||||||
|
event_mask = self.get_events() | gdk.EXPOSURE_MASK)
|
||||||
|
self.window.set_user_data(self)
|
||||||
|
self.style.attach(self.window)
|
||||||
|
self.style.set_background(self.window, gtk.STATE_NORMAL)
|
||||||
|
self.window.move_resize(*self.allocation)
|
||||||
|
|
||||||
|
def do_unrealize(self) :
|
||||||
|
self.window.destroy()
|
||||||
|
|
||||||
|
def do_expose_event(self, event) :
|
||||||
|
cr = self.window.cairo_create()
|
||||||
|
cr.set_matrix(cairo.Matrix(1, 0, 0, 1, 0, 1.5 * self.size))
|
||||||
|
cr.set_font_face(cairo.ToyFontFace(self.fontname, cairo.FONT_SLANT_ITALIC if self.italic else cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD if self.bold else cairo.FONT_WEIGHT_NORMAL))
|
||||||
|
cr.set_font_size(self.size)
|
||||||
|
cr.show_glyphs(self.glyphs) # [(gid, originx, originy)]
|
||||||
|
|
||||||
|
glyphs = []
|
||||||
|
org = [0, 0]
|
||||||
|
for g in res :
|
||||||
|
glyphs.append((g.gid, org[0] + g.offset[0], org[1] + g.offset[1]))
|
||||||
|
org[0] += g.advance[0]
|
||||||
|
org[1] += g.advance[1]
|
||||||
|
|
||||||
|
gobject.type_register(GlyphsWindow)
|
||||||
|
win = gtk.Window()
|
||||||
|
win.resize(org[0] + 10, 2 * opts.size + 40)
|
||||||
|
win.connect('delete-event', gtk.main_quit)
|
||||||
|
frame = gtk.Frame("glyphs")
|
||||||
|
win.add(frame)
|
||||||
|
w = GlyphsWindow(family, opts.bold, opts.italic, opts.size, glyphs)
|
||||||
|
frame.add(w)
|
||||||
|
win.show_all()
|
||||||
|
gtk.main()
|
||||||
|
|
Loading…
Reference in New Issue