OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / if / ruby / demo / ext_gstater_demo.rb
1 #
2 # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb
3 #
4 # http://libharu.org/
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
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 pdf.save_to_file($0 + ".pdf")
166