1 module renderer;
2 
3 import printed.canvas : IRenderingContext2D;
4 import common : RenderState;
5 
6 private void renderTo(RenderState[] log, IRenderingContext2D ctx)
7 {
8 	import printed.canvas;
9 	with (ctx)
10 	{
11 		const k = pageWidth / cast(float) log[0].area.w;
12 		lineWidth(k);
13 
14 		foreach(rs; log) with (rs.area) 
15 		{
16 			switch (rs.misc)
17 			{
18 				case 1:
19 					strokeStyle = brush("#00ff00");
20 					fillStyle = brush("#eee");
21 					fillRect(x*k, y*k, w*k, h*k);
22 					beginPath(x*k, y*k);
23 					lineTo((x+w)*k, y*k);
24 					lineTo((x+w)*k, (y+h)*k);
25 					lineTo(x*k, (y+h)*k);
26 					lineTo(x*k, y*k);
27 					closePath;
28 					fillAndStroke;
29 				break;
30 				case 2:
31 					fillStyle = brush("#ddd");
32 					fillRect(x*k, y*k, w*k, h*k);
33 				break;
34 				case 3:
35 					fillStyle = brush("#ccc");
36 					fillRect(x*k, y*k, w*k, h*k);
37 				break;
38 				default:
39 			}
40 		}
41 	}
42 }
43 
44 void render(RenderState[] log, string filename)
45 {
46 	import std.typecons : Tuple, tuple;
47 	import std.file;
48 	import printed.canvas : PDFDocument, HTMLDocument, SVGDocument;
49 	
50 	{
51 		auto pdf = new PDFDocument (210, 297);
52 		log.renderTo(pdf);
53 		std.file.write(filename ~ ".pdf", pdf.bytes);
54 	}
55 	
56 	{
57 		auto svg = new SVGDocument (210, 297);
58 		log.renderTo(svg);
59 		std.file.write(filename ~ ".svg", svg.bytes);
60 	}
61 	
62 	{
63 		auto html = new HTMLDocument (210, 297);
64 		log.renderTo(html);
65 		std.file.write(filename ~ ".html", html.bytes);
66 	}
67 }