2 # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb
6 # Copyright (c) 1999-2006 Takeshi Kanno
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.
18 def draw_circles(page, description, x, y)
19 page.set_line_width(1)
20 page.set_rgb_stroke(0, 0, 0)
22 page.set_rgb_fill(1, 0, 0)
23 page.circle(x + 40, y + 40, 40)
24 page.close_path_fill_stroke()
26 page.set_rgb_fill(0, 1, 0)
27 page.circle(x + 100, y + 40, 40)
28 page.close_path_fill_stroke()
30 page.set_rgb_fill(0, 0, 1)
31 page.circle(x + 70, y + 74.64, 40)
32 page.close_path_fill_stroke()
34 page.set_rgb_fill(0, 0, 0)
36 page.text_out(x + 0.0, y + 130.0, description)
45 # add a new page object. #
47 page.set_height(PAGE_HEIGHT)
48 page.set_width(PAGE_WIDTH)
50 font = pdf.get_font("Helvetica-Bold", nil)
52 page.set_font_and_size(font, 10)
56 draw_circles(page, "normal", 40, PAGE_HEIGHT - 170)
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)
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)
77 # blend-mode=HPDF_BM_MULTIPLY
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)
85 # blend-mode=HPDF_BM_SCREEN
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)
93 # blend-mode=HPDF_BM_OVERLAY
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)
101 # blend-mode=HPDF_BM_DARKEN
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)
109 # blend-mode=HPDF_BM_LIGHTEN
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)
117 # blend-mode=HPDF_BM_COLOR_DODGE
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)
125 # blend-mode=HPDF_BM_COLOR_BUM
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)
133 # blend-mode=HPDF_BM_HARD_LIGHT
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)
141 # blend-mode=HPDF_BM_SOFT_LIGHT
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)
149 # blend-mode=HPDF_BM_DIFFERENCE
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)
157 # blend-mode=HPDF_BM_EXCLUSHON
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)
165 pdf.save_to_file($0 + ".pdf")