Пример #1
0
 def draw_page(self, operation, context, page_number):
     cr = context.get_cairo_context()
     cr.set_source_rgb(0, 0, 0)
     start_line = page_number * self.lines_per_page
     if page_number + 1 != operation.props.n_pages:
         end_line = start_line + self.lines_per_page
     else:
         end_line = self.layout.get_line_count()
     cr.move_to(0, 0)
     iter = self.layout.get_iter()
     i = 0
     while 1:
         if i > start_line:
             # Must be get_line_readonly
             line = iter.get_line_readonly()
             cr.rel_move_to(0, self.font_size / 2)
             PangoCairo.show_layout_line(cr, line)
         i += 1
         if not (i < end_line and iter.next_line()):
             break
Пример #2
0
	def draw_page (self, operation, context, page_number):
		cr = context.get_cairo_context()
		cr.set_source_rgb(0, 0, 0)
		start_line = page_number * self.lines_per_page
		if page_number + 1 != operation.props.n_pages:
			end_line = start_line + self.lines_per_page
		else:
			end_line = self.layout.get_line_count()
		cr.move_to(0, 0)
		iter = self.layout.get_iter()
		i=0
		while 1:
			if i > start_line:
				#Must be get_line_readonly
				line = iter.get_line_readonly()
				cr.rel_move_to(0, self.font_size/2)
				PangoCairo.show_layout_line(cr,line)
			i += 1
			if not (i < end_line and iter.next_line()):
				break
Пример #3
0
 def show_line(context):
     """Draw the given ``line`` to the Cairo ``context``."""
     PangoCairo.update_layout(context, self.layout)
     PangoCairo.show_layout_line(context, first_line)
Пример #4
0
 def show_first_line(cairo_context, pango_layout, hinting):
     """Draw the given ``line`` to the Cairo ``context``."""
     if hinting:
         PangoCairo.update_layout(cairo_context, pango_layout)
     lines = pango_layout.get_lines_readonly()
     PangoCairo.show_layout_line(cairo_context, lines[0])
Пример #5
0
def cairo_text(cr, node):
    boundary = [float(i) for i in node.attr['Boundary'].split(' ')]
    ctm = None
    if 'CTM' in node.attr:
        ctm = [float(i) for i in node.attr['CTM'].split(' ')]
    font_id = node.attr['Font']
    font_family = get_font_from_id(font_id).get_font_family()
    font_size = float(node.attr['Size']) / 1.3
    fillColor = [0, 0, 0]
    if 'FillColor' in node:
        fillColor = [
            float(i) / 255. for i in node['FillColor'].attr['Value'].split(' ')
        ]

    strokeColor = [0, 0, 0]
    if 'StrokeColor' in node:
        strokeColor = [
            float(i) / 255.
            for i in node['StrokeColor'].attr['Value'].split(' ')
        ]

    TextCode = node['TextCode']
    text = TextCode.text
    # print(f'cario text {text}, {font_id}')

    deltaX = None
    deltaY = None
    if 'DeltaX' in TextCode.attr:
        deltaX = _trans_Delta(TextCode.attr['DeltaX'].split(' '), scale=1)
    if deltaX and len(deltaX) + 1 != len(text):
        # raise Exception('TextCode DeltaX 与字符个数不符')
        deltaX = deltaX[:len(text) - 1]

    if 'DeltaY' in TextCode.attr:
        deltaY = _trans_Delta(TextCode.attr['DeltaY'].split(' '), scale=1)
    if deltaY and len(deltaY) + 1 != len(text):
        # raise Exception('TextCode DeltaY 与字符个数不符')
        deltaY = deltaY[:len(text) - 1]

    X = float(TextCode.attr['X'])
    Y = float(TextCode.attr['Y'])
    for idx, rune in enumerate(text):
        cr.save()
        # cr.identity_matrix()
        # cr.scale(SCALE_128, SCALE_128)
        layout = PangoCairo.create_layout(cr)
        layout.set_text(rune, -1)
        # print(font_family, rune)
        desc = Pango.FontDescription.from_string(f"{font_family} {font_size}")
        layout.set_font_description(desc)

        ink_rect, logical_rect = layout.get_pixel_extents()
        r_w, r_h = layout.get_size()
        baseline = layout.get_baseline() / Pango.SCALE
        # print(f'{rune}, baseline: {baseline}, X:{X}, Y:{Y} Boundary:{boundary}')

        offset_x = sum(deltaX[:idx]) if deltaX else 0
        offset_y = sum(deltaY[:idx]) if deltaY else 0
        # cr.move_to(boundary[0] + offset_x, boundary[1] + offset_y)
        cr.move_to(boundary[0], boundary[1])
        if ctm:
            matrix = cr.get_matrix().multiply(cairo.Matrix(*ctm))
            cr.set_matrix(matrix)
        cr.rel_move_to(X + offset_x, Y + offset_y)

        cr.set_source_rgb(*fillColor)
        # PangoCairo.show_layout(cr, layout)
        PangoCairo.show_layout_line(cr, layout.get_line(0))
        cr.restore()
    pass
Пример #6
0
 def show_first_line(cairo_context, pango_layout, hinting):
     """Draw the given ``line`` to the Cairo ``context``."""
     if hinting:
         PangoCairo.update_layout(cairo_context, pango_layout)
     lines = pango_layout.get_lines_readonly()
     PangoCairo.show_layout_line(cairo_context, lines[0])