4 # Copyright (C) 2008 Openmoko Inc.
6 # Execute the drawing commands.... put that onto a canvas
10 # Load everything into ram...
14 input = open("render_text.blib")
17 # We do not need these markers
18 if line
.startswith("0,0,0,0"):
21 split
= line
.strip().split(',')
22 glyph
= { 'x' : int(split
[0]),
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
)
42 for glyph
in glyph_data
:
43 base_path
= os
.path
.join("fonts", glyph
['font'], glyph
['glyph'])
46 path
= os
.path
.join(base_path
, 'bitmap.png')
47 glyph_image
= cairo
.ImageSurface
.create_from_png(path
)
49 print "Issue with", path
, glyph
, e
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
)
58 context
.translate(-x
, -y
)
60 destination_surface
.write_to_png("rendered_result.png")