From: Martin Hosken Date: Fri, 21 May 2010 23:56:40 +0000 (+0100) Subject: Add graphical output to hbtestfont X-Git-Tag: submit/master/20120920.151126~7^2~594^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1432ab15c163eb0b5be3de66a4cb3df15ad73500;p=framework%2Fuifw%2Fharfbuzz.git Add graphical output to hbtestfont --- diff --git a/contrib/python/lib/harfbuzz.pyx b/contrib/python/lib/harfbuzz.pyx index 2a97c6c..139d3ea 100644 --- a/contrib/python/lib/harfbuzz.pyx +++ b/contrib/python/lib/harfbuzz.pyx @@ -33,103 +33,7 @@ cdef extern from "hb-common.h" : cdef extern from "hb-unicode.h" : # there must be a better way of syncing this list with the true source ctypedef enum hb_script_t : - HB_SCRIPT_INVALID_CODE = -1, - HB_SCRIPT_COMMON = 0, - HB_SCRIPT_INHERITED, - HB_SCRIPT_ARABIC, - HB_SCRIPT_ARMENIAN, - HB_SCRIPT_BENGALI, - HB_SCRIPT_BOPOMOFO, - HB_SCRIPT_CHEROKEE, - HB_SCRIPT_DESERET, - HB_SCRIPT_DEVANAGARI, - HB_SCRIPT_ETHIOPIC, - HB_SCRIPT_GEORGIAN, - HB_SCRIPT_GOTHIC, - HB_SCRIPT_GREEK, - HB_SCRIPT_GUJARATI, - HB_SCRIPT_GURMUKHI, - HB_SCRIPT_HAN, - HB_SCRIPT_HANGUL, - HB_SCRIPT_HEBREW, - HB_SCRIPT_HIRAGANA, - HB_SCRIPT_KANNADA, - HB_SCRIPT_KATAKANA, - HB_SCRIPT_KHMER, - HB_SCRIPT_LAO, - HB_SCRIPT_LATIN, - HB_SCRIPT_MALAYALAM, - HB_SCRIPT_MONGOLIAN, - HB_SCRIPT_MYANMAR, - HB_SCRIPT_OGHAM, - HB_SCRIPT_OLD_ITALIC, - HB_SCRIPT_ORIYA, - HB_SCRIPT_RUNIC, - HB_SCRIPT_SINHALA, - HB_SCRIPT_SYRIAC, - HB_SCRIPT_TAMIL, - HB_SCRIPT_TELUGU, - HB_SCRIPT_THAANA, - HB_SCRIPT_THAI, - HB_SCRIPT_TIBETAN, - HB_SCRIPT_CANADIAN_ABORIGINAL, - HB_SCRIPT_YI, - HB_SCRIPT_TAGALOG, - HB_SCRIPT_HANUNDO, - HB_SCRIPT_BUHID, - HB_SCRIPT_TAGBANWA, -# Unicode 4.0 - HB_SCRIPT_BRAILLE, - HB_SCRIPT_CYPRIOT, - HB_SCRIPT_LIMBU, - HB_SCRIPT_OSMANYA, - HB_SCRIPT_SHAVIAN, - HB_SCRIPT_LINEAR_B, - HB_SCRIPT_TAI_LE, - HB_SCRIPT_UGARITIC, -# Unicode 4.1 - HB_SCRIPT_NEW_TAI_LUE, - HB_SCRIPT_BUGINESE, - HB_SCRIPT_GLAGOLITIC, - HB_SCRIPT_TIFINAGH, - HB_SCRIPT_SYLOTI_NAGRI, - HB_SCRIPT_OLD_PERSIAN, - HB_SCRIPT_KHAROSHTHI, -# Unicode 5.0 - HB_SCRIPT_UNKNOWN, - HB_SCRIPT_BALINESE, - HB_SCRIPT_CUNEIFORM, - HB_SCRIPT_PHOENICIAN, - HB_SCRIPT_PHAGS_PA, - HB_SCRIPT_NKO, -# Unicode 5.1 - HB_SCRIPT_KAYAH_LI, - HB_SCRIPT_LEPCHA, - HB_SCRIPT_REJANG, - HB_SCRIPT_SUNDANESE, - HB_SCRIPT_SAURASHTRA, - HB_SCRIPT_CHAM, - HB_SCRIPT_OL_CHIKI, - HB_SCRIPT_VAI, - HB_SCRIPT_CARIAN, - HB_SCRIPT_LYCIAN, - HB_SCRIPT_LYDIAN -# Unicode-5.2 - HB_SCRIPT_AVESTAN - HB_SCRIPT_BAMUM - HB_SCRIPT_EGYPTIAN_HIEROGLYPHS - HB_SCRIPT_IMPERIAL_ARAMAIC - HB_SCRIPT_INSCRIPTIONAL_PAHLAVI - HB_SCRIPT_INSCRIPTIONAL_PARTHIAN - HB_SCRIPT_JAVANESE - HB_SCRIPT_KAITHI - HB_SCRIPT_LISU - HB_SCRIPT_MEITEI_MAYEK - HB_SCRIPT_OLD_SOUTH_ARABIAN - HB_SCRIPT_OLD_TURKIC - HB_SCRIPT_SAMARITAN - HB_SCRIPT_TAI_THAM - HB_SCRIPT_TAI_VIET + HB_SCRIPT_COMMON = 0 cdef extern from "hb-language.h" : ctypedef void *hb_language_t @@ -279,7 +183,7 @@ cdef class ft : self.engine = engine cdef FT_Face face FT_New_Face(engine, fname, 0, &face) - FT_Set_Char_Size(face, size << 6, size << 6, 144, 144) + FT_Set_Char_Size(face, size << 6, size << 6, 72, 72) self.face = face self.hbface = hb_ft_face_create(face, hb_face_destroy) self.hbfont = hb_ft_font_create(face, hb_font_destroy) diff --git a/contrib/python/scripts/hbtestfont b/contrib/python/scripts/hbtestfont index 4d1134d..30110e6 100755 --- a/contrib/python/scripts/hbtestfont +++ b/contrib/python/scripts/hbtestfont @@ -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() diff --git a/src/Makefile.am b/src/Makefile.am index 810083a..5f50f12 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,7 +52,7 @@ HBSOURCES += \ HBHEADERS += \ hb-ot.h \ hb-ot-layout.h \ - hb-ot-shape.h \ + hb-ot-shape-private.hh \ hb-ot-tag.h \ $(NULL) diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 3d8966c..8776a35 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -24,7 +24,7 @@ * Red Hat Author(s): Behdad Esfahbod */ -#include "hb-ot-shape.h" +#include "hb-ot-shape-private.hh" #include "hb-buffer-private.hh" diff --git a/src/hb-ot.h b/src/hb-ot.h index 91992b8..f14a7ee 100644 --- a/src/hb-ot.h +++ b/src/hb-ot.h @@ -30,7 +30,7 @@ #include "hb.h" #include "hb-ot-layout.h" -#include "hb-ot-shape.h" +#include "hb-ot-shape-private.hh" #include "hb-ot-tag.h" #endif /* HB_OT_H */ diff --git a/src/hb-shape.cc b/src/hb-shape.cc index af93fc9..4f39cf9 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -30,7 +30,7 @@ #include "hb-buffer-private.hh" -#include "hb-ot-shape.h" +#include "hb-ot-shape-private.hh" #ifdef HAVE_GRAPHITE #include "hb-graphite.h"