示例#1
0
def runGraphite(fontname, text, debugname, feats = {}, rtl = 0, lang = None, size = 16, expand = 100) :
    (major, minor, debug) = grversion()
    grface = gr2.gr_make_file_face(fontname, 0)
    
    lang = strtolong(lang)
    
    grfeats = gr2.gr_face_featureval_for_lang(grface, lang)
    for f, v in feats.items() :
        if v is None : continue
        id = gr2.gr_str_to_tag(f)
        fref = gr2.gr_face_find_fref(grface, id)
        gr2.gr_fref_set_feature_value(fref, int(v), grfeats)
    grfont = gr2.gr_make_font(size, grface)
    
    if major > 1 or minor > 1 :
        gr2.gr_start_logging(grface, debugname)
    else :
        debugfile = open(debugname, "w+")
        fd = c(debugfile.fileno(), "w+")
        gr2.graphite_start_logging(fd, 0xFF)
        
    ###print "text=",text  ####
    text_utf8 = text.encode('utf_8')  ####
    ###print "utf8=",text_utf8  ####
    seg = gr2.gr_make_seg(grfont, grface, 0, grfeats, 1, text_utf8, len(text), rtl)
    width = gr2.gr_seg_advance_X(seg)
    
    if expand != 100 :
        width = width * expand / 100
        width = gr2.gr_seg_justify(seg, gr2.gr_seg_first_slot(seg), grfont, width, 0, 0, 0)
        
    if major > 1 or minor > 1 :
        gr2.gr_stop_logging(grface)
    else:
        gr2.graphite_stop_logging()
        debugfile.close()
        
    return width
示例#2
0
def makeFontAndFace(fontname, size) :
    grface = gr2.gr_make_file_face(fontname, 0)
    grfont = gr2.gr_make_font(size, grface)
    return (grface, grfont)