[render_text] Move all glyphs to the left...
[wikipediardware.git] / benchmarking / rendering / webkit / render_text.py
blobb78018754e5cd2ffea5501e9849ddff30c7f59d6
1 #!/usr/bin/env python
4 # Copyright (C) 2008 Openmoko Inc.
6 # Execute the drawing commands.... put that onto a canvas
7 import cairo, os
10 # Load everything into ram...
11 max_height = 0
12 glyph_data = []
14 input = open("render_text.blib")
15 for line in input:
17 # We do not need these markers
18 if line.startswith("0,0,0,0"):
19 continue
21 split = line.strip().split(',')
22 glyph = { 'x' : int(split[0]),
23 'y' : int(split[1]),
24 'font' : split[2],
25 'glyph' : split[3] }
27 glyph_data.append(glyph)
29 if max_height < glyph['y']:
30 max_height = glyph['y']
33 # Assume the highest font has 60 pixels
34 max_height = max_height + 60
37 destination_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 240, max_height)
38 context = cairo.Context(destination_surface)
39 context.rectangle(0, 0, 640, max_height)
40 context.fill()
42 for glyph in glyph_data:
43 base_path = os.path.join("fonts", glyph['font'], glyph['glyph'])
45 try:
46 path = os.path.join(base_path, 'bitmap.png')
47 glyph_image = cairo.ImageSurface.create_from_png(path)
48 except IOError, e:
49 print "Issue with", path, glyph, e
50 continue
52 x = glyph['x'] - 7#+ int(open(os.path.join(base_path, 'bitmap_left_bearing')).readline().strip())
53 y = glyph['y'] #- int(open(os.path.join(base_path, 'bitmap_top_bearing')).readline().strip())
55 context.translate(x, y)
56 context.set_source_surface(glyph_image)
57 context.paint()
58 context.translate(-x, -y)
60 destination_surface.write_to_png("rendered_result.png")