Example #1
0
def render_to_image(html_source, css_source, height, width, renderer):
	tree = html.parse(html_source)
	rules = css.parse(css_source)

	styled_tree = style.style(tree, rules)

	layout_tree = [layout.build_layout_tree(node) for node in styled_tree if layout.get_display(node) is not layout.Display.NONE]

	root = layout.Dimensions.default()
	root.content.width = width

	for node in layout_tree:
		node.layout(root)

	renderer = painting.Renderer(width, height, renderer)
	image = renderer.render(layout_tree)

	return image
Example #2
0
'''

css_text = '''
body {bg-color:white;}
div {bg-color:yellow;padding:5;border:1;}
section {padding:10;bg-color:cyan;height:20;border:1;}
span {display:inline;height:20;border:1;}
header {margin:10;color:black;height:30;border:1;}
'''

dom_tree = dom.parse(html_text)
css_tree = css.parse(css_text)

style_tree = style.get_style_tree(dom_tree, css_tree)

layout_tree = layout.build_layout_tree(style_tree)

window = layout.Rect()
window.width = 200
window.height = 0

layout_tree.layout_box(window)

print("LAYOUT TREE")
layout_tree.print_node()

dl = draw.get_draw_list(layout_tree)
print("DRAWING LIST")
print_list(dl)

display.CreateWindow(dl)