hpdf 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/History +57 -0
  2. data/License +25 -0
  3. data/README +165 -0
  4. data/examples/arc_demo.rb +82 -0
  5. data/examples/demo.rb +92 -0
  6. data/examples/encryption.rb +41 -0
  7. data/examples/ext_gstater_demo.rb +171 -0
  8. data/examples/font_demo.rb +67 -0
  9. data/examples/jpfont_demo.rb +122 -0
  10. data/examples/line_demo.rb +301 -0
  11. data/examples/slide_show_demo.rb +139 -0
  12. data/examples/text_demo2.rb +189 -0
  13. data/examples/ttfont_demo.rb +106 -0
  14. data/ext/extconf.rb +6 -0
  15. data/ext/hpdf.c +3779 -0
  16. data/ext/hpdf_annotation.c +415 -0
  17. data/ext/hpdf_array.c +344 -0
  18. data/ext/hpdf_binary.c +117 -0
  19. data/ext/hpdf_boolean.c +47 -0
  20. data/ext/hpdf_catalog.c +354 -0
  21. data/ext/hpdf_destination.c +339 -0
  22. data/ext/hpdf_dict.c +488 -0
  23. data/ext/hpdf_doc.c +2020 -0
  24. data/ext/hpdf_doc_png.c +137 -0
  25. data/ext/hpdf_encoder.c +2991 -0
  26. data/ext/hpdf_encoder_cns.c +36359 -0
  27. data/ext/hpdf_encoder_cnt.c +15307 -0
  28. data/ext/hpdf_encoder_jp.c +16125 -0
  29. data/ext/hpdf_encoder_kr.c +27978 -0
  30. data/ext/hpdf_encrypt.c +632 -0
  31. data/ext/hpdf_encryptdict.c +240 -0
  32. data/ext/hpdf_error.c +114 -0
  33. data/ext/hpdf_ext_gstate.c +150 -0
  34. data/ext/hpdf_font.c +229 -0
  35. data/ext/hpdf_font_cid.c +1030 -0
  36. data/ext/hpdf_font_tt.c +406 -0
  37. data/ext/hpdf_font_type1.c +391 -0
  38. data/ext/hpdf_fontdef.c +56 -0
  39. data/ext/hpdf_fontdef_base14.c +4506 -0
  40. data/ext/hpdf_fontdef_cid.c +194 -0
  41. data/ext/hpdf_fontdef_cns.c +471 -0
  42. data/ext/hpdf_fontdef_cnt.c +250 -0
  43. data/ext/hpdf_fontdef_jp.c +1904 -0
  44. data/ext/hpdf_fontdef_kr.c +1572 -0
  45. data/ext/hpdf_fontdef_tt.c +2230 -0
  46. data/ext/hpdf_fontdef_type1.c +524 -0
  47. data/ext/hpdf_gstate.c +119 -0
  48. data/ext/hpdf_image.c +568 -0
  49. data/ext/hpdf_image_png.c +424 -0
  50. data/ext/hpdf_info.c +164 -0
  51. data/ext/hpdf_list.c +333 -0
  52. data/ext/hpdf_mmgr.c +243 -0
  53. data/ext/hpdf_name.c +71 -0
  54. data/ext/hpdf_null.c +31 -0
  55. data/ext/hpdf_number.c +49 -0
  56. data/ext/hpdf_objects.c +172 -0
  57. data/ext/hpdf_outline.c +329 -0
  58. data/ext/hpdf_page_label.c +74 -0
  59. data/ext/hpdf_page_operator.c +2764 -0
  60. data/ext/hpdf_pages.c +1508 -0
  61. data/ext/hpdf_real.c +61 -0
  62. data/ext/hpdf_streams.c +1435 -0
  63. data/ext/hpdf_string.c +189 -0
  64. data/ext/hpdf_utils.c +438 -0
  65. data/ext/hpdf_xref.c +348 -0
  66. data/ext/include/hpdf.h +1227 -0
  67. data/ext/include/hpdf_annotation.h +74 -0
  68. data/ext/include/hpdf_catalog.h +81 -0
  69. data/ext/include/hpdf_conf.h +76 -0
  70. data/ext/include/hpdf_consts.h +549 -0
  71. data/ext/include/hpdf_destination.h +41 -0
  72. data/ext/include/hpdf_doc.h +159 -0
  73. data/ext/include/hpdf_encoder.h +311 -0
  74. data/ext/include/hpdf_encrypt.h +156 -0
  75. data/ext/include/hpdf_encryptdict.h +66 -0
  76. data/ext/include/hpdf_error.h +201 -0
  77. data/ext/include/hpdf_ext_gstate.h +38 -0
  78. data/ext/include/hpdf_font.h +112 -0
  79. data/ext/include/hpdf_fontdef.h +403 -0
  80. data/ext/include/hpdf_gstate.h +80 -0
  81. data/ext/include/hpdf_image.h +72 -0
  82. data/ext/include/hpdf_info.h +48 -0
  83. data/ext/include/hpdf_list.h +85 -0
  84. data/ext/include/hpdf_mmgr.h +82 -0
  85. data/ext/include/hpdf_objects.h +587 -0
  86. data/ext/include/hpdf_outline.h +74 -0
  87. data/ext/include/hpdf_page_label.h +35 -0
  88. data/ext/include/hpdf_pages.h +128 -0
  89. data/ext/include/hpdf_streams.h +276 -0
  90. data/ext/include/hpdf_types.h +488 -0
  91. data/ext/include/hpdf_utils.h +161 -0
  92. data/tests/arc_demo.rb +82 -0
  93. data/tests/demo.rb +91 -0
  94. data/tests/encryption.rb +41 -0
  95. data/tests/ext_gstater_demo.rb +171 -0
  96. data/tests/font_demo.rb +67 -0
  97. data/tests/line_demo.rb +301 -0
  98. data/tests/slide_show_demo.rb +139 -0
  99. data/tests/test_all_examples.rb +31 -0
  100. data/tests/text_demo2.rb +189 -0
  101. metadata +147 -0
@@ -0,0 +1,171 @@
1
+ #
2
+ # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb
3
+ #
4
+ # http://libharu.sourceforge.net/
5
+ #
6
+ # Copyright (c) 1999-2006 Takeshi Kanno
7
+ #
8
+ # Permission to use, copy, modify, distribute and sell this software
9
+ # and its documentation for any purpose is hereby granted without fee,
10
+ # provided that the above copyright notice appear in all copies and
11
+ # that both that copyright notice and this permission notice appear
12
+ # in supporting documentation.
13
+ # It is provided "as is" without express or implied warranty.
14
+ #
15
+ require 'rubygems'
16
+ require "hpdf"
17
+
18
+ def draw_circles(page, description, x, y)
19
+ page.set_line_width(1)
20
+ page.set_rgb_stroke(0, 0, 0)
21
+
22
+ page.set_rgb_fill(1, 0, 0)
23
+ page.circle(x + 40, y + 40, 40)
24
+ page.close_path_fill_stroke()
25
+
26
+ page.set_rgb_fill(0, 1, 0)
27
+ page.circle(x + 100, y + 40, 40)
28
+ page.close_path_fill_stroke()
29
+
30
+ page.set_rgb_fill(0, 0, 1)
31
+ page.circle(x + 70, y + 74.64, 40)
32
+ page.close_path_fill_stroke()
33
+
34
+ page.set_rgb_fill(0, 0, 0)
35
+ page.begin_text()
36
+ page.text_out(x + 0.0, y + 130.0, description)
37
+ page.end_text()
38
+ end
39
+
40
+ pdf = HPDFDoc.new
41
+
42
+ PAGE_WIDTH = 600
43
+ PAGE_HEIGHT = 900
44
+
45
+ # add a new page object. #
46
+ page = pdf.add_page
47
+ page.set_height(PAGE_HEIGHT)
48
+ page.set_width(PAGE_WIDTH)
49
+
50
+ font = pdf.get_font("Helvetica-Bold", nil)
51
+
52
+ page.set_font_and_size(font, 10)
53
+
54
+ # normal
55
+ page.gsave()
56
+ draw_circles(page, "normal", 40, PAGE_HEIGHT - 170)
57
+ page.grestore()
58
+
59
+ # transparency (0.8)
60
+ page.gsave()
61
+ gstate = pdf.create_ext_gstate()
62
+ gstate.set_alpha_fill(0.8)
63
+ gstate.set_alpha_stroke(0.8)
64
+ page.set_ext_gstate(gstate)
65
+ draw_circles(page, "alpha fill = 0.8", 230, PAGE_HEIGHT - 170)
66
+ page.grestore()
67
+
68
+ # transparency (0.4)
69
+ page.gsave()
70
+ gstate = pdf.create_ext_gstate()
71
+ gstate.set_alpha_fill(0.4)
72
+ gstate.set_alpha_stroke(0.4)
73
+ page.set_ext_gstate(gstate)
74
+ draw_circles(page, "alpha fill = 0.4", 420, PAGE_HEIGHT - 170)
75
+ page.grestore()
76
+
77
+ # blend-mode=HPDF_BM_MULTIPLY
78
+ page.gsave()
79
+ gstate = pdf.create_ext_gstate()
80
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_MULTIPLY)
81
+ page.set_ext_gstate(gstate)
82
+ draw_circles(page, "HPDF_BM_MULTIPLY", 40, PAGE_HEIGHT - 340)
83
+ page.grestore()
84
+
85
+ # blend-mode=HPDF_BM_SCREEN
86
+ page.gsave()
87
+ gstate = pdf.create_ext_gstate()
88
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_SCREEN)
89
+ page.set_ext_gstate(gstate)
90
+ draw_circles(page, "HPDF_BM_SCREEN", 230, PAGE_HEIGHT - 340)
91
+ page.grestore()
92
+
93
+ # blend-mode=HPDF_BM_OVERLAY
94
+ page.gsave()
95
+ gstate = pdf.create_ext_gstate()
96
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_OVERLAY)
97
+ page.set_ext_gstate(gstate)
98
+ draw_circles(page, "HPDF_BM_OVERLAY", 420, PAGE_HEIGHT - 340)
99
+ page.grestore()
100
+
101
+ # blend-mode=HPDF_BM_DARKEN
102
+ page.gsave()
103
+ gstate = pdf.create_ext_gstate()
104
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_DARKEN)
105
+ page.set_ext_gstate(gstate)
106
+ draw_circles(page, "HPDF_BM_DARKEN", 40, PAGE_HEIGHT - 510)
107
+ page.grestore()
108
+
109
+ # blend-mode=HPDF_BM_LIGHTEN
110
+ page.gsave()
111
+ gstate = pdf.create_ext_gstate()
112
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_LIGHTEN)
113
+ page.set_ext_gstate(gstate)
114
+ draw_circles(page, "HPDF_BM_LIGHTEN", 230, PAGE_HEIGHT - 510)
115
+ page.grestore()
116
+
117
+ # blend-mode=HPDF_BM_COLOR_DODGE
118
+ page.gsave()
119
+ gstate = pdf.create_ext_gstate()
120
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_COLOR_DODGE)
121
+ page.set_ext_gstate(gstate)
122
+ draw_circles(page, "HPDF_BM_COLOR_DODGE", 420, PAGE_HEIGHT - 510)
123
+ page.grestore()
124
+
125
+ # blend-mode=HPDF_BM_COLOR_BUM
126
+ page.gsave()
127
+ gstate = pdf.create_ext_gstate()
128
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_COLOR_BUM)
129
+ page.set_ext_gstate(gstate)
130
+ draw_circles(page, "HPDF_BM_COLOR_BUM", 40, PAGE_HEIGHT - 680)
131
+ page.grestore()
132
+
133
+ # blend-mode=HPDF_BM_HARD_LIGHT
134
+ page.gsave()
135
+ gstate = pdf.create_ext_gstate()
136
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_HARD_LIGHT)
137
+ page.set_ext_gstate(gstate)
138
+ draw_circles(page, "HPDF_BM_HARD_LIGHT", 230, PAGE_HEIGHT - 680)
139
+ page.grestore()
140
+
141
+ # blend-mode=HPDF_BM_SOFT_LIGHT
142
+ page.gsave()
143
+ gstate = pdf.create_ext_gstate()
144
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_SOFT_LIGHT)
145
+ page.set_ext_gstate(gstate)
146
+ draw_circles(page, "HPDF_BM_SOFT_LIGHT", 420, PAGE_HEIGHT - 680)
147
+ page.grestore()
148
+
149
+ # blend-mode=HPDF_BM_DIFFERENCE
150
+ page.gsave()
151
+ gstate = pdf.create_ext_gstate()
152
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_DIFFERENCE)
153
+ page.set_ext_gstate(gstate)
154
+ draw_circles(page, "HPDF_BM_DIFFERENCE", 40, PAGE_HEIGHT - 850)
155
+ page.grestore()
156
+
157
+ # blend-mode=HPDF_BM_EXCLUSHON
158
+ page.gsave()
159
+ gstate = pdf.create_ext_gstate()
160
+ gstate.set_blend_mode(HPDFDoc::HPDF_BM_EXCLUSHON)
161
+ page.set_ext_gstate(gstate)
162
+ draw_circles(page, "HPDF_BM_EXCLUSHON", 230, PAGE_HEIGHT - 850)
163
+ page.grestore()
164
+
165
+ if $demo_output_filename
166
+ file_name= $demo_output_filename
167
+ else
168
+ file_name= $0 + ".pdf"
169
+ end
170
+
171
+ pdf.save_to_file(file_name)
@@ -0,0 +1,67 @@
1
+ #
2
+ # << Haru Free PDF Library 2.0.0 >> -- font_example.rb
3
+ #
4
+ # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5
+ #
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.
12
+ #
13
+ require 'rubygems'
14
+ require "hpdf"
15
+
16
+ font_list = ["Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique", "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", "Symbol", "ZapfDingbats", nil]
17
+
18
+ pdf = HPDFDoc.new
19
+
20
+ page = pdf.add_page
21
+ height = page.get_height
22
+ width = page.get_width
23
+
24
+ page.set_line_width(1.0)
25
+ page.rectangle(50.0, 50.0, width - 100.0, height - 110.0)
26
+ page.stroke
27
+
28
+ font1 = pdf.get_font("Helvetica", nil)
29
+
30
+ title = "Font Example"
31
+ page.set_font_and_size(font1, 24.0)
32
+ tw = page.text_width(title)
33
+ page.begin_text
34
+ page.text_out((width - tw) / 2, height - 50.0, title)
35
+ page.set_font_and_size(font1, 16.0)
36
+ page.text_out(60.0, height - 80.0, "<Standerd Type1 fonts samples>")
37
+ page.end_text
38
+
39
+ samp_text = "abcdefgABCDEFG12345!#$\%&+-@?"
40
+
41
+ page.begin_text
42
+ page.move_text_pos(60.0, height - 105.0)
43
+
44
+ i = 0
45
+ while font_list[i]
46
+ font2 = pdf.get_font(font_list[i], nil)
47
+
48
+ page.set_font_and_size(font1, 9.0)
49
+ page.show_text(font_list[i])
50
+ page.move_text_pos(0.0, -18.0)
51
+
52
+ page.set_font_and_size(font2, 20.0)
53
+ page.show_text(samp_text)
54
+ page.move_text_pos(0.0, -20.0)
55
+
56
+ i = i + 1
57
+ end
58
+
59
+ page.end_text
60
+
61
+ if $demo_output_filename
62
+ file_name= $demo_output_filename
63
+ else
64
+ file_name= $0 + ".pdf"
65
+ end
66
+
67
+ pdf.save_to_file(file_name)
@@ -0,0 +1,122 @@
1
+ #
2
+ # << Alternative PDF Library 1.0.0 >> -- font_example.rb
3
+ #
4
+ # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5
+ #
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.
12
+ #
13
+ require 'rubygems'
14
+ require "hpdf"
15
+
16
+ SAMP_TEXT1 = "abcdefgABCDEFG123!#$\%&+-@?"
17
+ SAMP_TEXT2 = "�A�����{�Ԃ��Ȃ����������B�������ɏ��G�r�����悢�ł�B"
18
+
19
+ pdf = HPDFDoc.new
20
+
21
+ pdf.set_compression_mode(HPDFDoc::HPDF_COMP_ALL)
22
+ pdf.use_jp_fonts
23
+ pdf.use_jp_encodings
24
+
25
+ title_font = pdf.get_font("Helvetica", nil)
26
+
27
+ font = Array.new(16)
28
+
29
+ font[0] = pdf.get_font("MS-Mincyo", "90ms-RKSJ-H")
30
+ font[1] = pdf.get_font("MS-Mincyo,Bold", "90ms-RKSJ-H")
31
+ font[2] = pdf.get_font("MS-Mincyo,Italic", "90ms-RKSJ-H")
32
+ font[3] = pdf.get_font("MS-Mincyo,BoldItalic", "90ms-RKSJ-H")
33
+ font[4] = pdf.get_font("MS-PMincyo", "90msp-RKSJ-H")
34
+ font[5] = pdf.get_font("MS-PMincyo,Bold", "90msp-RKSJ-H")
35
+ font[6] = pdf.get_font("MS-PMincyo,Italic", "90msp-RKSJ-H")
36
+ font[7] = pdf.get_font("MS-PMincyo,BoldItalic", "90msp-RKSJ-H")
37
+ font[8] = pdf.get_font("MS-Gothic", "90ms-RKSJ-H")
38
+ font[9] = pdf.get_font("MS-Gothic,Bold", "90ms-RKSJ-H")
39
+ font[10] = pdf.get_font("MS-Gothic,Italic", "90ms-RKSJ-H")
40
+ font[11] = pdf.get_font("MS-Gothic,BoldItalic", "90ms-RKSJ-H")
41
+ font[12] = pdf.get_font("MS-PGothic", "90msp-RKSJ-H")
42
+ font[13] = pdf.get_font("MS-PGothic,Bold", "90msp-RKSJ-H")
43
+ font[14] = pdf.get_font("MS-PGothic,Italic", "90msp-RKSJ-H")
44
+ font[15] = pdf.get_font("MS-PGothic,BoldItalic","90msp-RKSJ-H")
45
+
46
+ # set page mode to use outlines.
47
+ pdf.set_page_mode(HPDFDoc::HPDF_PAGE_MODE_USE_OUTLINE)
48
+
49
+ encoder = pdf.get_encoder("90ms-RKSJ-H")
50
+
51
+ # create outline root.
52
+ root = pdf.create_outline(nil, "���{��t�H���g", encoder);
53
+
54
+ i = 0
55
+ while font[i]
56
+ print font[i].get_font_name, "\n"
57
+ page = pdf.add_page
58
+
59
+ outline = pdf.create_outline(root, font[i].get_font_name, nil)
60
+ dst = page.create_destination
61
+ outline.set_destination(dst)
62
+
63
+ page.set_font_and_size(title_font, 10.0)
64
+
65
+ page.begin_text
66
+ page.move_text_pos(10.0, 190.0)
67
+ page.show_text(font[i].get_font_name)
68
+
69
+ page.set_font_and_size(font[i], 15.0)
70
+ page.move_text_pos(10.0, -20.0)
71
+ page.show_text("abcdefghijklmnopqrstuvwxyz")
72
+ page.move_text_pos(0.0, -20.0)
73
+ page.show_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
74
+ page.move_text_pos(0.0, -20.0)
75
+ page.show_text("1234567890")
76
+ page.move_text_pos(0.0, -20.0)
77
+
78
+ page.set_font_and_size(font[i], 10.0);
79
+ page.show_text(SAMP_TEXT2)
80
+ page.move_text_pos(0.0, -18.0)
81
+
82
+ page.set_font_and_size(font[i], 16.0);
83
+ page.show_text(SAMP_TEXT2)
84
+ page.move_text_pos(0.0, -27.0)
85
+
86
+ page.set_font_and_size(font[i], 23.0);
87
+ page.show_text(SAMP_TEXT2)
88
+ page.move_text_pos(0.0, -36.0)
89
+
90
+ page.set_font_and_size(font[i], 30.0);
91
+ page.show_text(SAMP_TEXT2)
92
+
93
+ p = page.get_current_text_pos
94
+ page.end_text
95
+
96
+ page.set_width(p[0] + 20)
97
+ page.set_height(210.0)
98
+
99
+ page.set_line_width(0.5)
100
+
101
+ page.move_to(10.0, 185.0)
102
+ page.line_to(p[0] + 10.0, 185.0)
103
+ page.stroke
104
+
105
+ page.move_to(10.0, 125.0)
106
+ page.line_to(p[0] + 10.0, 125.0)
107
+ page.stroke
108
+
109
+ page.move_to(10.0, p[1] - 12.0)
110
+ page.line_to(p[0] + 10.0, p[1] - 12)
111
+ page.stroke
112
+
113
+ i = i + 1
114
+ end
115
+
116
+ if $demo_output_filename
117
+ file_name= $demo_output_filename
118
+ else
119
+ file_name= $0 + ".pdf"
120
+ end
121
+
122
+ pdf.save_to_file(file_name)
@@ -0,0 +1,301 @@
1
+ #
2
+ # << Haru Free PDF Library 2.0.2 >> -- line_demo.rb
3
+ #
4
+ # http://libharu.sourceforge.net/
5
+ #
6
+ # Copyright (c) 1999-2006 Takeshi Kanno
7
+ #
8
+ # Permission to use, copy, modify, distribute and sell this software
9
+ # and its documentation for any purpose is hereby granted without fee,
10
+ # provided that the above copyright notice appear in all copies and
11
+ # that both that copyright notice and this permission notice appear
12
+ # in supporting documentation.
13
+ # It is provided "as is" without express or implied warranty.
14
+ #
15
+ require 'rubygems'
16
+ require "hpdf"
17
+
18
+ def draw_line(page, x, y, text)
19
+ page.begin_text
20
+ page.move_text_pos(x, y - 10)
21
+ page.show_text(text)
22
+ page.end_text
23
+
24
+ page.move_to(x, y - 15)
25
+ page.line_to(x + 220, y - 15)
26
+ page.stroke
27
+ end
28
+
29
+ def draw_line2(page, x, y, text)
30
+ page.begin_text
31
+ page.move_text_pos(x, y)
32
+ page.show_text(text)
33
+ page.end_text
34
+
35
+ page.move_to(x + 30, y - 25)
36
+ page.line_to(x + 160, y - 25)
37
+ page.stroke
38
+ end
39
+
40
+ def draw_rect(page, x, y, text)
41
+ page.begin_text
42
+ page.move_text_pos(x, y - 10)
43
+ page.show_text(text)
44
+ page.end_text
45
+
46
+ page.rectangle(x, y - 40, 220, 25)
47
+ end
48
+
49
+ pdf = HPDFDoc.new
50
+
51
+ pdf.set_compression_mode(HPDFDoc::HPDF_COMP_ALL)
52
+
53
+ font = pdf.get_font("Helvetica", nil)
54
+
55
+ page = pdf.add_page
56
+
57
+ #print the lines of the page.#
58
+ page.set_line_width(1)
59
+ x = page.get_width - 100
60
+ y = page.get_height - 110
61
+ page.rectangle(50, 50, x, y)
62
+ page.stroke
63
+
64
+ #print the title of the page (with positioning center).#
65
+ page.set_font_and_size(font, 24)
66
+ tw = page.text_width('Line Demo')
67
+ page.begin_text
68
+
69
+ x =(page.get_width - tw) / 2
70
+ y = page.get_height - 50
71
+ page.move_text_pos(x, y)
72
+
73
+ page.show_text('Line Demo')
74
+ page.end_text
75
+
76
+ page.set_font_and_size(font, 10)
77
+
78
+ #Draw verious widths of lines.#
79
+ page.set_line_width(0)
80
+ draw_line(page, 60, 770, 'line width = 0')
81
+
82
+ page.set_line_width(1.0)
83
+ draw_line(page, 60, 740, 'line width = 1.0')
84
+
85
+ page.set_line_width(2.0)
86
+ draw_line(page, 60, 710, 'line width = 2.0')
87
+
88
+ #Line dash pattern#
89
+ page.set_line_width(1.0)
90
+
91
+ page.set_dash([3], 1)
92
+ draw_line(page, 60, 680, 'dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on...')
93
+
94
+ page.set_dash([7, 3], 2)
95
+ draw_line(page, 60, 650, 'dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,...')
96
+
97
+ page.set_dash([8, 7, 2, 7], 0)
98
+ draw_line(page, 60, 620, 'dash_ptn=[8, 7, 2, 7], phase=0')
99
+
100
+ page.set_dash([], 0)
101
+
102
+ page.set_line_width(30)
103
+ page.set_rgb_stroke(0.0, 0.5, 0.0)
104
+
105
+ #Line Cap Style#
106
+ page.set_line_cap(HPDFDoc::HPDF_BUTT_END)
107
+ draw_line2(page, 60, 570, 'HPDF_BUTT_END')
108
+
109
+ page.set_line_cap(HPDFDoc::HPDF_ROUND_END)
110
+ draw_line2(page, 60, 505, 'HPDF_ROUND_END')
111
+
112
+ page.set_line_cap(HPDFDoc::HPDF_PROJECTING_SCUARE_END)
113
+ draw_line2(page, 60, 440, 'HPDF_PROJECTING_SCUARE_END')
114
+
115
+ #Line Join Style#
116
+ page.set_line_width(30)
117
+ page.set_rgb_stroke(0.0, 0.0, 0.5)
118
+
119
+ page.set_line_join(HPDFDoc::HPDF_MITER_JOIN)
120
+ page.move_to(120, 300)
121
+ page.line_to(160, 340)
122
+ page.line_to(200, 300)
123
+ page.stroke
124
+
125
+ page.begin_text
126
+ page.move_text_pos(60, 360)
127
+ page.show_text('HPDF_MITER_JOIN')
128
+ page.end_text
129
+
130
+ page.set_line_join(HPDFDoc::HPDF_ROUND_JOIN)
131
+ page.move_to(120, 195)
132
+ page.line_to(160, 235)
133
+ page.line_to(200, 195)
134
+ page.stroke
135
+
136
+ page.begin_text
137
+ page.move_text_pos(60, 255)
138
+ page.show_text('HPDF_ROUND_JOIN')
139
+ page.end_text
140
+
141
+ page.set_line_join(HPDFDoc::HPDF_BEVEL_JOIN)
142
+ page.move_to(120, 90)
143
+ page.line_to(160, 130)
144
+ page.line_to(200, 90)
145
+ page.stroke
146
+
147
+ page.begin_text
148
+ page.move_text_pos(60, 150)
149
+ page.show_text('HPDF_BEVEL_JOIN')
150
+ page.end_text
151
+
152
+ # Draw rectangle #
153
+ page.set_line_width(2)
154
+ page.set_rgb_stroke(0, 0, 0)
155
+ page.set_rgb_fill(0.75, 0.0, 0.0)
156
+
157
+ draw_rect(page, 300, 770, 'stroke')
158
+ page.stroke
159
+
160
+ draw_rect(page, 300, 720, 'Fill')
161
+ page.fill
162
+
163
+ draw_rect(page, 300, 670, 'Fill then stroke')
164
+ page.fill_stroke
165
+
166
+ #clip Rect#
167
+ page.gsave # Save the current graphic state#
168
+ draw_rect(page, 300, 620, 'Clip rectangle')
169
+ page.clip
170
+ page.stroke
171
+ page.set_font_and_size(font, 13)
172
+
173
+ page.begin_text
174
+ page.move_text_pos(290, 600)
175
+ page.set_text_leading(12)
176
+ page.show_text('Clip Clip Clip Clip Clip Clipi Clip Clip Clip')
177
+ page.show_text_next_line('Clip Clip Clip Clip Clip Clip Clip Clip Clip')
178
+ page.show_text_next_line('Clip Clip Clip Clip Clip Clip Clip Clip Clip')
179
+ page.end_text
180
+ page.grestore
181
+
182
+ x0 = 330
183
+ y0 = 440
184
+ x1 = 430
185
+ y1 = 530
186
+ x2 = 480
187
+ y2 = 470
188
+ x3 = 480
189
+ y3 = 90
190
+
191
+ #Curve Example(curve_to2)#
192
+ page.set_rgb_fill(0, 0, 0)
193
+
194
+ page.begin_text
195
+ page.move_text_pos(300, 540)
196
+ page.show_text('curve_to2(x1, y1, x2. y2)')
197
+ page.end_text
198
+
199
+ page.begin_text
200
+ page.move_text_pos(x0 + 5, y0 - 5)
201
+ page.show_text('Current point')
202
+ page.move_text_pos(x1 - x0, y1 - y0)
203
+ page.show_text('(x1, y1)')
204
+ page.move_text_pos(x2 - x1, y2 - y1)
205
+ page.show_text('(x2, y2)')
206
+ page.end_text
207
+
208
+ page.set_dash([], 0)
209
+
210
+ page.set_line_width(0.5)
211
+ page.move_to(x1, y1)
212
+ page.line_to(x2, y2)
213
+ page.stroke
214
+
215
+ page.set_dash([], 0)
216
+
217
+ page.set_line_width(1.5)
218
+
219
+ page.move_to(x0, y0)
220
+ page.curve_to2(x1, y1, x2, y2)
221
+ page.stroke
222
+
223
+ #Curve Example(curve_to3)#
224
+ y0 = y0 - 150
225
+ y1 = y1 - 150
226
+ y2 = y2 - 150
227
+
228
+ page.begin_text
229
+ page.move_text_pos(300, 390)
230
+ page.show_text('curve_to3(x1, y1, x2. y2)')
231
+ page.end_text
232
+
233
+ page.begin_text
234
+ page.move_text_pos(x0 + 5, y0 - 5)
235
+ page.show_text('Current point')
236
+ page.move_text_pos(x1 - x0, y1 - y0)
237
+ page.show_text('(x1, y1)')
238
+ page.move_text_pos(x2 - x1, y2 - y1)
239
+ page.show_text('(x2, y2)')
240
+ page.end_text
241
+
242
+ page.set_dash([3], 1)
243
+
244
+ page.set_line_width(0.5)
245
+ page.move_to(x0, y0)
246
+ page.line_to(x1, y1)
247
+ page.stroke
248
+
249
+ page.set_dash([], 0)
250
+
251
+ page.set_line_width(1.5)
252
+ page.move_to(x0, y0)
253
+ page.curve_to3(x1, y1, x2, y2)
254
+ page.stroke
255
+
256
+ # Curve Example(curve_to)
257
+ y0 = y0 - 150
258
+ y1 = y1 - 160
259
+ y2 = y2 - 130
260
+ x2 = x2 + 10
261
+
262
+ page.begin_text
263
+ page.move_text_pos(300, 240)
264
+ page.show_text('curve_to(x1, y1, x2. y2, x3, y3)')
265
+ page.end_text
266
+
267
+ page.begin_text
268
+ page.move_text_pos(x0 + 5, y0 - 5)
269
+ page.show_text('Current point')
270
+ page.move_text_pos(x1 - x0, y1 - y0)
271
+ page.show_text('(x1, y1)')
272
+ page.move_text_pos(x2 - x1, y2 - y1)
273
+ page.show_text('(x2, y2)')
274
+ page.move_text_pos(x3 - x2, y3 - y2)
275
+ page.show_text('(x3, y3)')
276
+ page.end_text
277
+
278
+ page.set_dash([3], 1)
279
+
280
+ page.set_line_width(0.5)
281
+ page.move_to(x0, y0)
282
+ page.line_to(x1, y1)
283
+ page.stroke
284
+ page.move_to(x2, y2)
285
+ page.line_to(x3, y3)
286
+ page.stroke
287
+
288
+ page.set_dash([], 0)
289
+
290
+ page.set_line_width(1.5)
291
+ page.move_to(x0, y0)
292
+ page.curve_to(x1, y1, x2, y2, x3, y3)
293
+ page.stroke
294
+
295
+ if $demo_output_filename
296
+ file_name= $demo_output_filename
297
+ else
298
+ file_name= $0 + ".pdf"
299
+ end
300
+
301
+ pdf.save_to_file(file_name)