Python cairo 模块,FONT_SLANT_NORMAL 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用cairo.FONT_SLANT_NORMAL

项目:pedro    作者:saandial    | 项目源码 | 文件源码
def draw_text(self, ctx):
        ctx.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL,
                cairo.FONT_WEIGHT_NORMAL)
        ctx.set_font_size(TXT_SIZE)
        ctx.move_to(0.01*SIZE, 1.5*TXT_SIZE)
        ctx.show_text(' Forearm: ' + str(int(degrees(forearm))))
        ctx.move_to(0.01*SIZE, 3.5*TXT_SIZE)
        ctx.show_text(' Hand: '+ str(int(degrees(-hand))))
        if outOfReach:
            ctx.set_source_rgb(1, 0, 0)
            ctx.move_to(0.01*SIZE, 4*TXT_SIZE)
            #ctx.show_text('OUT OF REACH !!!')

    # ---------------------------------
    # mouse_pressed
    # ---------------------------------
项目:pedro    作者:saandial    | 项目源码 | 文件源码
def draw_text(ctx):
    ctx.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL, 
            cairo.FONT_WEIGHT_NORMAL)
    ctx.set_font_size(TXT_SIZE)
    ctx.move_to(0.01*SIZE, TXT_SIZE)
    ctx.show_text('Base: ' + str(int(degrees(base))))
    ctx.move_to(0.01*SIZE, 2*TXT_SIZE)
    ctx.show_text('Forearm: '+ str(int(degrees(forearm))))
    ctx.move_to(0.01*SIZE, 3*TXT_SIZE)
    ctx.show_text('Hand: '+ str(int(degrees(hand))))
    if outOfReach:        
        ctx.set_source_rgb(1, 0, 0) 
        ctx.move_to(0.01*SIZE, 4*TXT_SIZE)
        #ctx.move_to(-3*TXT_SIZE + Width/2, 0.5*SIZE + Height/2)
        ctx.show_text('OUT OF REACH !!!')

# ---------------------------------
# mouse_pressed
# ---------------------------------
项目:TMDLang    作者:aguai    | 项目源码 | 文件源码
def barCoord(n):
    '''
    returns ((x-left-top, y-left-top),
            (x-left-buttom, y-right-buttom),
            (x-right-top, y-right-top),
            (x-right-buttom, y-right-buttom))
            coordinate of a bar area   
    '''
    return ((100 + (n % 6) * 380, 430 + (n // 6) * 331),                # left x-axis 100pt for margin blank    
            (100 + (n % 6) * 380, 430 + (n // 6) * 331 + 252),          # top  y-axis 430pt for title
            (100 + (n % 6) * 380 + 380, 430 + (n // 6) * 331),          # 252 is 1.5em for chord 1em * 3 for melody 56pt per em
            (100 + (n % 6) * 380 + 380, 430 + (n // 6) * 331 + 252))


# ctx = cairo.Context(cairo.PDFSurface("haha.pdf", 2480.0, 3508.0))
# ctx.set_font_size(30)
# ctx.select_font_face("FreeSerif", cairo.FONT_SLANT_NORMAL,
#                     cairo.FONT_WEIGHT_NORMAL)
项目:TMDLang    作者:aguai    | 项目源码 | 文件源码
def main():

    ps = cairo.PDFSurface("pdffile.pdf", 504, 648)
    cr = cairo.Context(ps)

    cr.set_source_rgb(0, 0, 0)
    cr.select_font_face("FreeSerif", cairo.FONT_SLANT_NORMAL,
                        cairo.FONT_WEIGHT_NORMAL)
    cr.set_font_size(40)
    cr.move_to(10, 50)
    cr.show_text(chr(119046) +'1 2 3 4 5' + chr(119047) )
    cr.set_line_width(11)
    cr.move_to(100, 100)
    cr.line_to(20, 300)

    cr.show_page()
项目:TMDLang    作者:aguai    | 项目源码 | 文件源码
def DrawChord(ThisPageChordList, CSF):
    CSF.move_to(0, 0)
    CSF.select_font_face("FreeSerif", cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    CSF.move_to(100, 100)
    CSF.set_font_size(80)
    for i in ThisPageChordList:
        CSF.show_text(i)

    CSF.show_page()
项目:TikZ    作者:ellisk42    | 项目源码 | 文件源码
def draw(self,context):
        context.set_source_rgb(256,256,256)
        context.select_font_face("Courier", cairo.FONT_SLANT_NORMAL, 
                                 cairo.FONT_WEIGHT_BOLD)
        context.set_font_size(FONTSIZE)
        (x, y, width, height, dx, dy) = context.text_extents(self.c)
        context.move_to(self.p.x*16 - width/2, self.p.y*16 - height/2)
        context.scale(1,-1)
        context.show_text(self.c)
        context.scale(1,-1)
        context.stroke()
项目:SegmentationService    作者:jingchaoluan    | 项目源码 | 文件源码
def cairo_render_at(s,loc=None,shape=None,
                    fontname=None,fontfile=None,size=None,
                    slant=cairo.FONT_SLANT_NORMAL,
                    weight=cairo.FONT_WEIGHT_NORMAL,
                    bg=(0.0,0.0,0.0),fg=(0.9,0.9,0.9)):
    """Render a string using Cairo and the Cairo text rendering interface.  Fonts can either be given
    as a fontfile or as a fontname.  Size should be in pixels (?).  You can specify a background and
    foreground color as RGB floating point triples.  Images are padded by pad pixels on all sides."""
    assert loc is not None
    assert shape is not None
    assert size is not None
    w,h = shape
    x,y = loc
    face = None
    if fontfile is not None:
        # "/usr/share/fonts/truetype/msttcorefonts/comic.ttf"
        if fontfile in facecache:
            face = facecache[fontfile]
        else:
            face = create_cairo_font_face_for_file(fontfile,0)
            facecache[fontfile] = face

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h)
    cr = cairo.Context(surface)
    if face is not None:
        cr.set_font_face(face)
    else:
        if fontname is None: fontname = "Helvetica"
        if type(slant)==str:
            if slant[0]=="i": slant = cairo.FONT_SLANT_ITALIC
            elif slant[0]=="o": slant = cairo.FONT_SLANT_OBLIQUE
            elif slant[0]=="n": slant = cairo.FONT_SLANT_NORMAL
            else: raise Exception("bad font slant specification (use n/i/o)")
        if type(weight)==str:
            if weight[0]=="b": weight = cairo.FONT_WEIGHT_BOLD
            elif weight[0]=="n": weight = cairo.FONT_WEIGHT_NORMAL
            else: raise Exception("bad font weight specification (use b/n)")
        cr.select_font_face(fontname,slant,weight)
    if size is not None:
        cr.set_font_size(size)
    cr.set_source_rgb(*bg)
    cr.rectangle(0,0,w,h)
    cr.fill()
    cr.move_to(x,y)
    cr.set_source_rgb(*fg)
    cr.show_text(s)
    data = surface.get_data()
    data = bytearray(data)
    a = array(data,'B')
    a.shape = (h,w,4)
    a = a[:,:,:3]
    a = a[:,:,::-1]
    return a
项目:BinarizationService    作者:jingchaoluan    | 项目源码 | 文件源码
def cairo_render_at(s,loc=None,shape=None,
                    fontname=None,fontfile=None,size=None,
                    slant=cairo.FONT_SLANT_NORMAL,
                    weight=cairo.FONT_WEIGHT_NORMAL,
                    bg=(0.0,0.0,0.0),fg=(0.9,0.9,0.9)):
    """Render a string using Cairo and the Cairo text rendering interface.  Fonts can either be given
    as a fontfile or as a fontname.  Size should be in pixels (?).  You can specify a background and
    foreground color as RGB floating point triples.  Images are padded by pad pixels on all sides."""
    assert loc is not None
    assert shape is not None
    assert size is not None
    w,h = shape
    x,y = loc
    face = None
    if fontfile is not None:
        # "/usr/share/fonts/truetype/msttcorefonts/comic.ttf"
        if fontfile in facecache:
            face = facecache[fontfile]
        else:
            face = create_cairo_font_face_for_file(fontfile,0)
            facecache[fontfile] = face

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h)
    cr = cairo.Context(surface)
    if face is not None:
        cr.set_font_face(face)
    else:
        if fontname is None: fontname = "Helvetica"
        if type(slant)==str:
            if slant[0]=="i": slant = cairo.FONT_SLANT_ITALIC
            elif slant[0]=="o": slant = cairo.FONT_SLANT_OBLIQUE
            elif slant[0]=="n": slant = cairo.FONT_SLANT_NORMAL
            else: raise Exception("bad font slant specification (use n/i/o)")
        if type(weight)==str:
            if weight[0]=="b": weight = cairo.FONT_WEIGHT_BOLD
            elif weight[0]=="n": weight = cairo.FONT_WEIGHT_NORMAL
            else: raise Exception("bad font weight specification (use b/n)")
        cr.select_font_face(fontname,slant,weight)
    if size is not None:
        cr.set_font_size(size)
    cr.set_source_rgb(*bg)
    cr.rectangle(0,0,w,h)
    cr.fill()
    cr.move_to(x,y)
    cr.set_source_rgb(*fg)
    cr.show_text(s)
    data = surface.get_data()
    data = bytearray(data)
    a = array(data,'B')
    a.shape = (h,w,4)
    a = a[:,:,:3]
    a = a[:,:,::-1]
    return a
项目:deep_ocr    作者:JinpengLI    | 项目源码 | 文件源码
def cairo_render_at(s,loc=None,shape=None,
                    fontname=None,fontfile=None,size=None,
                    slant=cairo.FONT_SLANT_NORMAL,
                    weight=cairo.FONT_WEIGHT_NORMAL,
                    bg=(0.0,0.0,0.0),fg=(0.9,0.9,0.9)):
    """Render a string using Cairo and the Cairo text rendering interface.  Fonts can either be given
    as a fontfile or as a fontname.  Size should be in pixels (?).  You can specify a background and
    foreground color as RGB floating point triples.  Images are padded by pad pixels on all sides."""
    assert loc is not None
    assert shape is not None
    assert size is not None
    w,h = shape
    x,y = loc
    face = None
    if fontfile is not None:
        # "/usr/share/fonts/truetype/msttcorefonts/comic.ttf"
        if fontfile in facecache:
            face = facecache[fontfile]
        else:
            face = create_cairo_font_face_for_file(fontfile,0)
            facecache[fontfile] = face

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h)
    cr = cairo.Context(surface)
    if face is not None:
        cr.set_font_face(face)
    else:
        if fontname is None: fontname = "Helvetica"
        if type(slant)==str:
            if slant[0]=="i": slant = cairo.FONT_SLANT_ITALIC
            elif slant[0]=="o": slant = cairo.FONT_SLANT_OBLIQUE
            elif slant[0]=="n": slant = cairo.FONT_SLANT_NORMAL
            else: raise Exception("bad font slant specification (use n/i/o)")
        if type(weight)==str:
            if weight[0]=="b": weight = cairo.FONT_WEIGHT_BOLD
            elif weight[0]=="n": weight = cairo.FONT_WEIGHT_NORMAL
            else: raise Exception("bad font weight specification (use b/n)")
        cr.select_font_face(fontname,slant,weight)
    if size is not None:
        cr.set_font_size(size)
    cr.set_source_rgb(*bg)
    cr.rectangle(0,0,w,h)
    cr.fill()
    cr.move_to(x,y)
    cr.set_source_rgb(*fg)
    cr.show_text(s)
    data = surface.get_data()
    data = bytearray(data)
    a = array(data,'B')
    a.shape = (h,w,4)
    a = a[:,:,:3]
    a = a[:,:,::-1]
    return a