How to use the cairocffi.FONT_SLANT_NORMAL function in cairocffi

To help you get started, we’ve selected a few cairocffi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cubicool / cairou / tests / python-cffi / emboss.py View on Github external
def __draw_cairo(self, cr, w, h):
		text = "Cairo"

		cr.select_font_face("Droid Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
		cr.set_font_size(100)

		extents = cr.text_extents(text)

		cr.move_to(((w - extents[2]) / 2.0) - extents[0], (h - extents[1]) / 2.0)
		cr.show_text(text)
github cubicool / cairou / tests / python-cffi / basic-tests.py View on Github external
def test_emboss():
	text      = "Cairocks"
	text_size = 30
	w, h      = 200, 200
	s         = cairo.ImageSurface(cairo.FORMAT_A8, w, h)
	c         = cairo.Context(s)

	c.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
	c.set_font_size(text_size)

	extents = c.text_extents(text)

	c.move_to(((w - extents[2]) / 2.0) - extents[0], (h - extents[1]) / 2.0)
	c.show_text(text)

	emboss = cairocks.emboss_create(
		s,
		130.0 * (math.pi / 180.0),
		45.0 * (math.pi / 180.0),
		100.0,
		0.1,
		0.1
	)
github dcf21 / planisphere / graphics_context.py View on Github external
"""
        Sets the font style (i.e. bold or italic) used.
        :param italic:
            Boolean flag, indicating whether text should be italic. None indicates we preserve the existing setting.
        :param bold:
            Boolean flag, indicating whether text should be bold. None indicates we preserve the existing setting.
        :return:
            None
        """
        if italic is not None:
            self.font_italic = italic
        if bold is not None:
            self.font_bold = bold

        self.context.select_font_face(family="FreeSerif",
                                      slant=cairo.FONT_SLANT_ITALIC if self.font_italic else cairo.FONT_SLANT_NORMAL,
                                      weight=cairo.FONT_WEIGHT_BOLD if self.font_bold else cairo.FONT_SLANT_NORMAL
                                      )
github koonimaru / DeepGMAP / deepgmap / post_train_tools / kernel_visualizer.py View on Github external
#cr.arc(x, y, 0.001*height, 0, 2*math.pi)
                    cr.rectangle(x, y,nodew, nodeh)
                    coordinates["hidden"+str(i+2)].append([x,y])
                    cr.fill()
                
                last_conv_y=y+0.0018*height-upper_lim
                last_conv_shape=conv_shape[1]
        
             
        """drawing nodes as bars in fully-connected layers"""
        
        for i, fc in enumerate(fc_kernels):
            x+=x_interval
            cr.move_to(x, upper_lim-0.0018*height)
            cr.set_source_rgba(0.0,0.0,0.0,1.0)
            cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL,cairo.FONT_WEIGHT_NORMAL)
            font_mat=cairo.Matrix(xx=12.0,yx=0.0,xy=0.0,yy=12,x0=0.0,y0=0.0)
            cr.set_font_matrix(font_mat)
            cr.show_text("fc"+str(i+1))
            coordinates["fc"+str(i+1)]=[]
            fc_shape=fc.shape
            print(fc_shape)
            y=upper_lim
            #cr.move_to(width*0.1, height*0.1+0.0008*height*j)
            
            #cr.arc(x, y, 0.001*height, 0, 2*math.pi)
            cr.set_source_rgba(0.5,0.5,0.5,0.5)
            cr.rectangle(x, y,width*0.015, fc_shape[0]*last_conv_y/(float(last_seq_length)*last_conv_shape))
            coordinates["fc"+str(i+1)].append([x,y])
            cr.fill()
    
        fc2_hight=fc_shape[0]*last_conv_y/(float(last_seq_length)*last_conv_shape)
github pannous / tensorflow-ocr / train.py View on Github external
def paint_text(text, w, h, rotate=False, move=False, multi_fonts=False, background=False):
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
    with cairo.Context(surface) as context:
        context.set_source_rgb(1, 1, 1)  # White
        context.paint()
        if multi_fonts:
            # Calibri Century Comic Sans  Courier New Futura Georgia
            fonts = ['Century Schoolbook', 'Courier', 'Arial', 'STIX','Tahoma','Times New Roman','Trebuchet MS',
                     'Verdana','Wide Latin','Calibri','Century','Comic Sans','Courier','New Futura','Georgia',
                     'Lucida','Lucida Console','Magneto','Mistral','URW Chancery L', 'FreeMono','DejaVue Sans Mono']
            font_slant = np.random.choice([cairo.FONT_SLANT_NORMAL,cairo.FONT_SLANT_ITALIC,cairo.FONT_SLANT_OBLIQUE])
            font_weight = np.random.choice([cairo.FONT_WEIGHT_BOLD, cairo.FONT_WEIGHT_NORMAL, cairo.FONT_WEIGHT_NORMAL])
            context.select_font_face(np.random.choice(fonts), font_slant, font_weight)
        else:
            context.select_font_face('Courier', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
        # context.set_font_size(25)
        font_size = randint(12, 42)
        context.set_font_size(font_size)
        box = context.text_extents(text)
        border_w_h = (font_size/2, font_size/2)
        # if box[2] > (w - 2 * border_w_h[1]) or box[3] > (h - 2 * border_w_h[0]):
        #     raise IOError('Could not fit string into image. Max char count is too large for given image width.')

        # teach the RNN translational invariance by
        # fitting text box randomly on canvas, with some room to rotate
        min_x = 0 #font_size/4
        min_y = 0# font_size/4
        max_shift_x = w - box[2] - border_w_h[0]
        max_shift_y = h - box[3] - border_w_h[1]

        if max_shift_x <= min_x :
github zhourunlai / learning / Keras / image_ocr.py View on Github external
def paint_text(text, w, h, rotate=False, ud=False, multi_fonts=False):
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
    with cairo.Context(surface) as context:
        context.set_source_rgb(1, 1, 1)  # White
        context.paint()
        # this font list works in Centos 7
        if multi_fonts:
            fonts = ['Century Schoolbook', 'Courier', 'STIX', 'URW Chancery L', 'FreeMono']
            context.select_font_face(np.random.choice(fonts), cairo.FONT_SLANT_NORMAL,
                                     np.random.choice([cairo.FONT_WEIGHT_BOLD, cairo.FONT_WEIGHT_NORMAL]))
        else:
            context.select_font_face('Courier', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
        context.set_font_size(25)
        box = context.text_extents(text)
        border_w_h = (4, 4)
        if box[2] > (w - 2 * border_w_h[1]) or box[3] > (h - 2 * border_w_h[0]):
            raise IOError('Could not fit string into image. Max char count is too large for given image width.')

        # teach the RNN translational invariance by
        # fitting text box randomly on canvas, with some room to rotate
        max_shift_x = w - box[2] - border_w_h[0]
        max_shift_y = h - box[3] - border_w_h[1]
        top_left_x = np.random.randint(0, int(max_shift_x))
        if ud:
            top_left_y = np.random.randint(0, int(max_shift_y))
github dcf21 / planisphere / graphics_context.py View on Github external
Sets the font style (i.e. bold or italic) used.
        :param italic:
            Boolean flag, indicating whether text should be italic. None indicates we preserve the existing setting.
        :param bold:
            Boolean flag, indicating whether text should be bold. None indicates we preserve the existing setting.
        :return:
            None
        """
        if italic is not None:
            self.font_italic = italic
        if bold is not None:
            self.font_bold = bold

        self.context.select_font_face(family="FreeSerif",
                                      slant=cairo.FONT_SLANT_ITALIC if self.font_italic else cairo.FONT_SLANT_NORMAL,
                                      weight=cairo.FONT_WEIGHT_BOLD if self.font_bold else cairo.FONT_SLANT_NORMAL
                                      )
github keras-team / keras / examples / image_ocr.py View on Github external
def paint_text(text, w, h, rotate=False, ud=False, multi_fonts=False):
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
    with cairo.Context(surface) as context:
        context.set_source_rgb(1, 1, 1)  # White
        context.paint()
        # this font list works in CentOS 7
        if multi_fonts:
            fonts = [
                'Century Schoolbook', 'Courier', 'STIX',
                'URW Chancery L', 'FreeMono']
            context.select_font_face(
                np.random.choice(fonts),
                cairo.FONT_SLANT_NORMAL,
                np.random.choice([cairo.FONT_WEIGHT_BOLD, cairo.FONT_WEIGHT_NORMAL]))
        else:
            context.select_font_face('Courier',
                                     cairo.FONT_SLANT_NORMAL,
                                     cairo.FONT_WEIGHT_BOLD)
        context.set_font_size(25)
        box = context.text_extents(text)
        border_w_h = (4, 4)
        if box[2] > (w - 2 * border_w_h[1]) or box[3] > (h - 2 * border_w_h[0]):
            raise IOError(('Could not fit string into image.'
                           'Max char count is too large for given image width.'))

        # teach the RNN translational invariance by
        # fitting text box randomly on canvas, with some room to rotate
        max_shift_x = w - box[2] - border_w_h[0]
        max_shift_y = h - box[3] - border_w_h[1]
github neozhaoliang / pywonderland / src / uniform-tilings / tiling.py View on Github external
ctx.set_line_width(line_width)
                ctx.move_to(*pts[0])
                for p in pts[1:]:
                    ctx.line_to(*p)
                ctx.close_path()
                ctx.set_source_rgb(0.2, 0.2, 0.2)
                ctx.stroke()

                bar.update(1)

        bar.close()

        if show_vertices_labels:
            ctx.set_source_rgb(*Color("papayawhip").rgb)
            ctx.select_font_face("Serif", cairo.FONT_SLANT_NORMAL,
                                 cairo.FONT_WEIGHT_BOLD)
            ctx.set_font_size(0.7)
            for i, p in enumerate(self.vertices_coords[:1000]):
                x, y = self.project(p)
                _, _, w, h, _, _ = ctx.text_extents(str(i))
                ctx.move_to(x - w / 2, y + h / 2)
                ctx.show_text(str(i))

        print("saving to svg...")
        surface.finish()
        size = os.path.getsize(output) >> 10
        print("{}KB svg file has been written to disk".format(size))
        print("=" * 40)
github koonimaru / DeepGMAP / deepgmap / post_train_tools / kernel_visualizer2.py View on Github external
#cr.move_to(50, 100)
        #cr.line_to(50, 412)
        cr.set_line_width(2)
        cr.stroke()
        cr.move_to(width*0.1, y_center)
        cr.line_to(width*0.1, y_center-120)
        cr.set_line_width(2)
        cr.stroke()
        cr.move_to(width*0.1, y_center-60)
        cr.line_to(width*0.08, y_center-60)
        cr.set_line_width(2)
        cr.stroke()
        cr.move_to(width*0.075, y_center-60+4*10)
        cr.rotate(-90*math.pi/180.0)
        #cr.set_line_width(2)
        cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL,cairo.FONT_WEIGHT_NORMAL)
        font_mat=cairo.Matrix(xx=32.0,yx=0.0,xy=0.0,yy=32,x0=0.0,y0=0.0)
        cr.set_font_matrix(font_mat)
        cr.show_text("2 bit")
        cr.rotate(90*math.pi/180.0)
        font_mat=cairo.Matrix(xx=12.0,yx=0.0,xy=0.0,yy=12,x0=0.0,y0=0.0)
        cr.move_to(width*0.5, hight)
        cr.show_text("k"+str(k))
        #print y_center
            
        AGCT={}
        #values=[]
        #print reconstruct[k]
        
        #reconstruct[k]=reconstruct[k]*50
        #mean=np.mean(reconstruct[k])
        #stdv=np.std(reconstruct[k])