2 * << Haru Free PDF Library 2.0.5 >> -- LineDemo.cs
4 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation.
11 * It is provided "as is" without express or implied warranty.
20 public class LineDemo {
21 private static void DrawLine(HPdfPage page, float x, float y, string label) {
23 page.MoveTextPos(x, y - 10);
27 page.MoveTo(x, y - 15);
28 page.LineTo(x + 220, y - 15);
32 private static void DrawLine2(HPdfPage page, float x, float y, string label) {
34 page.MoveTextPos(x, y);
38 page.MoveTo(x + 30, y - 25);
39 page.LineTo(x + 160, y - 25);
43 private static void DrawRect(HPdfPage page, float x, float y, string label) {
45 page.MoveTextPos(x, y - 10);
49 page.Rectangle(x, y - 40, 220, 25);
52 public static void Main() {
53 Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());
56 const string page_title = "LineDemo";
58 HPdfDoc pdf = new HPdfDoc();
60 /* create default-font */
61 HPdfFont font = pdf.GetFont ("Helvetica", null);
63 /* add a new page object. */
64 HPdfPage page = pdf.AddPage();
66 /* print the lines of the page. */
68 page.Rectangle(50, 50, page.GetWidth() - 100,
69 page.GetHeight() - 110);
72 /* print the title of the page (with positioning center). */
73 page.SetFontAndSize(font, 24);
74 float tw = page.TextWidth(page_title);
76 page.MoveTextPos ((page.GetWidth() - tw) / 2,
77 page.GetHeight() - 50);
78 page.ShowText(page_title);
81 page.SetFontAndSize(font, 10);
83 /* Draw verious widths of lines. */
85 DrawLine(page, 60, 770, "line width = 0");
87 page.SetLineWidth(1.0f);
88 DrawLine(page, 60, 740, "line width = 1.0");
90 page.SetLineWidth(2.0f);
91 DrawLine(page, 60, 710, "line width = 2.0");
93 /* Line dash pattern */
94 ushort[] dash_mode1 = new ushort[] {3};
95 ushort[] dash_mode2 = new ushort[] {3, 7};
96 ushort[] dash_mode3 = new ushort[] {8, 7, 2, 7};
98 page.SetLineWidth(1.0f);
100 page.SetDash(dash_mode1, 1);
101 DrawLine(page, 60, 680, "dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...");
103 Console.Error.WriteLine("001");
104 page.SetDash(dash_mode2, 2);
105 DrawLine(page, 60, 650, "dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,...");
107 page.SetDash(dash_mode3, 0);
108 DrawLine(page, 60, 620, "dash_ptn=[8, 7, 2, 7], phase=0");
110 page.SetDash(null, 0);
112 page.SetLineWidth(30);
113 page.SetRGBStroke(0.0f, 0.5f, 0.0f);
116 page.SetLineCap(HPdfLineCap.HPDF_BUTT_END);
117 DrawLine2(page, 60, 570, "HPDF_BUTT_END");
119 page.SetLineCap(HPdfLineCap.HPDF_ROUND_END);
120 DrawLine2(page, 60, 505, "HPDF_ROUND_END");
122 page.SetLineCap(HPdfLineCap.HPDF_PROJECTING_SCUARE_END);
123 DrawLine2(page, 60, 440, "HPDF_PROJECTING_SCUARE_END");
125 /* Line Join Style */
126 page.SetLineWidth(30);
127 page.SetRGBStroke(0.0f, 0.0f, 0.5f);
129 page.SetLineJoin(HPdfLineJoin.HPDF_MITER_JOIN);
130 page.MoveTo(120, 300);
131 page.LineTo(160, 340);
132 page.LineTo(200, 300);
136 page.MoveTextPos(60, 360);
137 page.ShowText("HPDF_MITER_JOIN");
140 page.SetLineJoin(HPdfLineJoin.HPDF_ROUND_JOIN);
141 page.MoveTo(120, 195);
142 page.LineTo(160, 235);
143 page.LineTo(200, 195);
147 page.MoveTextPos(60, 255);
148 page.ShowText("HPDF_ROUND_JOIN");
151 page.SetLineJoin(HPdfLineJoin.HPDF_BEVEL_JOIN);
152 page.MoveTo(120, 90);
153 page.LineTo(160, 130);
154 page.LineTo(200, 90);
158 page.MoveTextPos(60, 150);
159 page.ShowText("HPDF_BEVEL_JOIN");
163 page.SetLineWidth(2);
164 page.SetRGBStroke(0, 0, 0);
165 page.SetRGBFill(0.75f, 0.0f, 0.0f);
167 DrawRect(page, 300, 770, "Stroke");
170 DrawRect(page, 300, 720, "Fill");
173 DrawRect(page, 300, 670, "Fill then Stroke");
177 page.GSave(); /* Save the current graphic state */
178 DrawRect(page, 300, 620, "Clip Rectangle");
181 page.SetFontAndSize(font, 13);
184 page.MoveTextPos(290, 600);
185 page.SetTextLeading(12);
186 page.ShowText("Clip Clip Clip Clip Clip Clipi Clip Clip Clip");
187 page.ShowTextNextLine("Clip Clip Clip Clip Clip Clip Clip Clip Clip");
188 page.ShowTextNextLine("Clip Clip Clip Clip Clip Clip Clip Clip Clip");
192 /* Curve Example(CurveTo2) */
202 page.SetRGBFill(0, 0, 0);
205 page.MoveTextPos(300, 540);
206 page.ShowText("CurveTo2(x1, y1, x2. y2)");
210 page.MoveTextPos(x + 5, y - 5);
211 page.ShowText("Current point");
212 page.MoveTextPos(x1 - x, y1 - y);
213 page.ShowText("(x1, y1)");
214 page.MoveTextPos(x2 - x1, y2 - y1);
215 page.ShowText("(x2, y2)");
218 page.SetDash(dash_mode1, 0);
220 page.SetLineWidth(0.5f);
225 page.SetDash(null, 0);
227 page.SetLineWidth(1.5f);
230 page.CurveTo2(x1, y1, x2, y2);
233 /* Curve Example(CurveTo3) */
239 page.MoveTextPos(300, 390);
240 page.ShowText("CurveTo3(x1, y1, x2. y2)");
244 page.MoveTextPos(x + 5, y - 5);
245 page.ShowText("Current point");
246 page.MoveTextPos(x1 - x, y1 - y);
247 page.ShowText("(x1, y1)");
248 page.MoveTextPos(x2 - x1, y2 - y1);
249 page.ShowText("(x2, y2)");
252 page.SetDash(dash_mode1, 0);
254 page.SetLineWidth(0.5f);
259 page.SetDash(null, 0);
261 page.SetLineWidth(1.5f);
263 page.CurveTo3(x1, y1, x2, y2);
266 /* Curve Example(CurveTo) */
273 page.MoveTextPos(300, 240);
274 page.ShowText("CurveTo(x1, y1, x2. y2, x3, y3)");
278 page.MoveTextPos(x + 5, y - 5);
279 page.ShowText("Current point");
280 page.MoveTextPos(x1 - x, y1 - y);
281 page.ShowText("(x1, y1)");
282 page.MoveTextPos(x2 - x1, y2 - y1);
283 page.ShowText("(x2, y2)");
284 page.MoveTextPos(x3 - x2, y3 - y2);
285 page.ShowText("(x3, y3)");
288 page.SetDash(dash_mode1, 0);
290 page.SetLineWidth(0.5f);
298 page.SetDash(null, 0);
300 page.SetLineWidth(1.5f);
302 page.CurveTo(x1, y1, x2, y2, x3, y3);
305 pdf.SaveToFile("LineDemo.pdf");
306 } catch (Exception e) {
307 Console.Error.WriteLine(e.Message);