1 /** 2 HTML Renderer. 3 4 Copyright: Guillaume Piolat 2018. 5 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) 6 */ 7 module printed.canvas.htmlrender; 8 9 import std.string; 10 import printed.canvas.irenderer; 11 import printed.canvas.svgrender; 12 13 14 /// Renders 2D commands in a HTML file. 15 /// This simply embed a SVG inside. 16 class HTMLDocument : SVGDocument 17 { 18 public: 19 this(int pageWidthMm = 210, int pageHeightMm = 297, RenderOptions options = defaultRenderOptions) 20 { 21 super(pageWidthMm, pageHeightMm, options); 22 } 23 24 override const(ubyte)[] bytes() 25 { 26 auto svgBytes = super.bytes(); 27 auto htmlHeader = cast(const(ubyte)[])( getHTMLHeader() ); 28 auto htmlFooter = cast(const(ubyte)[])( getHTMLFooter() ); 29 30 return htmlHeader ~ svgBytes ~ htmlFooter; 31 } 32 33 void setTitle(string title) 34 { 35 _title = title; 36 } 37 38 protected: 39 override string getXMLHeader() 40 { 41 return ""; 42 } 43 44 private: 45 46 string _title = null; 47 48 string getHTMLHeader() 49 { 50 string header = 51 `<!doctype html>` 52 ~ `<html>` 53 ~ `<head>` 54 ~ `<meta charset="utf-8">`; 55 56 if (_title) 57 header ~= format(`<title>%s</title>`, _title); 58 59 header ~= `</head>` 60 ~ `<body>`; 61 return header; 62 } 63 64 string getHTMLFooter() 65 { 66 return "</body></html>"; 67 } 68 }