1 #!/usr/bin/env dub
2 /+ dub.sdl:
3     dependency "printed:canvas" version="~>1.1.2"
4     dependency "printed:font"   version="~>1.1.2"
5     dependency "printed-text"   path="../.."
6 +/
7 module printed.text.examples.multi_column;
8 
9 import printed.canvas;
10 import printed.text;
11 import std..string;
12 
13 enum fontFace = "Arial";
14 enum fontSize = 12f;
15 enum headerFontSize = 2f*fontSize;
16 enum pageWidth = 140f;
17 enum pageHeight = 210f;
18 enum pagePadding = 10f;
19 enum columnGap = 10f;
20 enum numColumns = 2;
21 enum headerMarginBottom = 8f;
22 enum paragraphMarginVertical = 12f;
23 
24 void main()
25 {
26     //printExample();
27     assert(0, "implement!");
28 }
29 
30 void printExample(IRenderingContext2D renderer, ITextLayouter textLayouter)
31 {
32     //renderer.pageWidth = pageWidth;
33     //renderer.pageHeight = pageHeight;
34 
35     with (textLayouter)
36     {
37         // basic configuration
38         textWidth = pageWidth - 2f*pagePadding;
39         fontFace = .fontFace;
40         fontSize = .fontSize;
41 
42         save();
43             fontSize = .headerFontSize;
44             fontWeight = FontWeight.bold;
45             write("Lorem Ipsum");
46             auto headerBlock = layout()[0];
47             clear();
48         restore();
49 
50         const columnWidth = (textWidth - (numColumns - 1)*columnGap) / numColumns;
51         const columnHeight = pageHeight - 2f*pagePadding - headerBlock.filledHeight;
52 
53         textWidth = columnWidth;
54         textHeight = columnHeight;
55 
56         textLayouter.group({
57             fontStyle = FontStyle.italic;
58             write("Lorem ipsum dolor sit amet");
59         });
60         write(", consectetur adipisici elit, sed eiusmod tempor incidunt ut ");
61         write("labore et dolore magna aliqua. Ut enim ad minim veniam, quis ");
62         write("nostrud exercitation ullamco laboris nisi ut aliquid ex ea ");
63         write("commodi consequat. Quis aute iure reprehenderit in voluptate ");
64         write("velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ");
65         write("sint obcaecat cupiditat non proident, sunt in culpa qui ");
66         write("officia deserunt mollit anim id est laborum.");
67         endParagraph();
68 
69         write("Duis autem vel eum ");
70         save();
71             fontWeight = FontWeight.bold;
72             write("iriure");
73         restore();
74         write(" dolor in hendrerit in vulputate velit esse molestie ");
75         write("consequat, vel illum dolore eu feugiat nulla facilisis at ");
76         write("vero eros et accumsan et iusto odio dignissim qui blandit ");
77         write("praesent luptatum zzril delenit augue duis dolore te feugait ");
78         write("nulla facilisi. Lorem ipsum dolor sit amet, consectetuer ");
79         write("adipiscing elit, sed diam nonummy nibh euismod tincidunt ut ");
80         write("laoreet dolore magna aliquam erat volutpat.");
81         endParagraph();
82         write(`
83             Ut wisi enim ad minim veniam, quis nostrud exerci tation ut
84             aliquip ex ea commodo. eum iriure dolor in hendrerit in
85             molestie consequat, illum dolore eu feugiat nulla facilisis
86             at vero eros et accumsan et iusto odio dignissim qui blandit
87             praesent luptatum zzril delenit augue duis dolore te feugait
88             nulla facilisi.
89         `.stripLeft("\n").stripRight.outdent);
90         endParagraph();
91 
92         write("Duis autem vel eum iriure dolor in hendrerit in vulputate ");
93         write("velit esse molestie consequat, vel illum dolore eu feugiat.");
94         endParagraph();
95 
96         write(q"EOS
97 Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
98 et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et
99 justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
100 sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
101 sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et.
102 EOS".replace("\n", " "));
103 
104         auto columns = layout();
105         assert(columns.length == 2);
106 
107         renderer.save();
108             renderer.translate(pagePadding, pagePadding);
109             headerBlock.renderWith(renderer);
110 
111             auto columnOffsetX = 0f;
112             const columnOffsetY = headerBlock.filledHeight + headerMarginBottom;
113             foreach (column; columns)
114             {
115                 column.renderWith(renderer, columnOffsetX, columnOffsetY);
116                 columnOffsetX += column.filledWidth + columnGap;
117             }
118         renderer.restore();
119     }
120 }