|
|
|
@ -1,6 +1,48 @@ |
|
|
|
|
#!/usr/bin/python |
|
|
|
|
|
|
|
|
|
import harfbuzz, optparse |
|
|
|
|
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, size, glyphs) : |
|
|
|
|
gtk.Widget.__init__(self) |
|
|
|
|
self.fontname = fontname |
|
|
|
|
self.size = size |
|
|
|
|
self.glyphs = glyphs |
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
cr.set_font_size(self.size) |
|
|
|
|
cr.show_glyphs(self.glyphs) # [(gid, originx, originy)] |
|
|
|
|
|
|
|
|
|
buffer = None |
|
|
|
|
|
|
|
|
@ -17,10 +59,11 @@ p.add_option('-s', '--size', default=12, type="int", help="point size") |
|
|
|
|
p.add_option('-l', '--lang', help="language code") |
|
|
|
|
p.add_option('-c', '--script', help="script code") |
|
|
|
|
p.add_option('-f', '--feature', action='append', help="define a feature key=val") |
|
|
|
|
p.add_option('-n', '--fontname', help='Font to use to render glyphs') |
|
|
|
|
p.add_option('-d', '--debug', action='store_true', help="Output trace info") |
|
|
|
|
(opts, args) = p.parse_args() |
|
|
|
|
|
|
|
|
|
ft = harfbuzz.ft(args[0], opts.size, trace = tracefn if opts.debug else None) |
|
|
|
|
ft = harfbuzz.ft(args[0], opts.size) |
|
|
|
|
text = "".join(unichr(int(c, 16)) for c in args[1].split(" ")) |
|
|
|
|
bytes = text.encode('utf_8') |
|
|
|
|
buffer = harfbuzz.buffer(bytes, len(text)) |
|
|
|
@ -33,3 +76,20 @@ if opts.feature : |
|
|
|
|
ft.shape(buffer, features = features) |
|
|
|
|
res = buffer.get_info(64) # scale for 26.6 |
|
|
|
|
print res |
|
|
|
|
if opts.fontname : |
|
|
|
|
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, 3 * opts.size + 40) |
|
|
|
|
win.connect('delete-event', gtk.main_quit) |
|
|
|
|
frame = gtk.Frame("glyphs") |
|
|
|
|
win.add(frame) |
|
|
|
|
w = GlyphsWindow(opts.fontname, opts.size, glyphs) |
|
|
|
|
frame.add(w) |
|
|
|
|
win.show_all() |
|
|
|
|
gtk.main() |
|
|
|
|