squib 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +29 -29
- data/.travis.yml +6 -6
- data/.yardopts +7 -5
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +245 -92
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -18
- data/lib/squib/api/background.rb +18 -16
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -48
- data/lib/squib/api/save.rb +43 -37
- data/lib/squib/api/settings.rb +38 -35
- data/lib/squib/api/shapes.rb +116 -106
- data/lib/squib/api/text.rb +50 -45
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +42 -36
- data/lib/squib/commands/new.rb +43 -39
- data/lib/squib/constants.rb +104 -39
- data/lib/squib/deck.rb +116 -113
- data/lib/squib/graphics/background.rb +13 -12
- data/lib/squib/graphics/image.rb +47 -28
- data/lib/squib/graphics/save_doc.rb +54 -50
- data/lib/squib/graphics/save_images.rb +32 -10
- data/lib/squib/graphics/shapes.rb +59 -55
- data/lib/squib/graphics/text.rb +113 -107
- data/lib/squib/input_helpers.rb +193 -139
- data/lib/squib/progress.rb +38 -0
- data/lib/squib/project_template/.gitignore +4 -3
- data/lib/squib/project_template/ABOUT.md +19 -19
- data/lib/squib/project_template/Gemfile +2 -2
- data/lib/squib/project_template/PNP NOTES.md +3 -3
- data/lib/squib/project_template/config.yml +20 -2
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/ball.png +0 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -16
- data/samples/custom-config.yml +6 -1
- data/samples/custom-layout.yml +39 -34
- data/samples/custom_config.rb +18 -5
- data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
- data/samples/customconfig-imgdir/spanner2.svg +91 -0
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/grit.png +0 -0
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -19
- data/samples/offset.svg +71 -0
- data/samples/portrait-landscape.rb +23 -0
- data/samples/ranges.rb +55 -47
- data/samples/save_pdf.rb +14 -14
- data/samples/shiny-purse.png +0 -0
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +60 -58
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +28 -28
- data/spec/api/api_text_spec.rb +42 -36
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/multi-extends-single-entry.yml +13 -0
- data/spec/data/multi-level-extends.yml +10 -0
- data/spec/data/no-extends.yml +5 -0
- data/spec/data/single-extends.yml +7 -0
- data/spec/data/single-level-multi-extends.yml +12 -0
- data/spec/deck_spec.rb +147 -49
- data/spec/input_helpers_spec.rb +117 -0
- data/spec/samples_run_spec.rb +19 -14
- data/spec/spec_helper.rb +3 -0
- data/squib.gemspec +46 -42
- metadata +78 -4
- data/API.md +0 -59
@@ -1,13 +1,14 @@
|
|
1
|
-
module Squib
|
2
|
-
class Card
|
3
|
-
|
4
|
-
# :nodoc:
|
5
|
-
# @api private
|
6
|
-
def background(color)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module Squib
|
2
|
+
class Card
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
# @api private
|
6
|
+
def background(color)
|
7
|
+
use_cairo do |cc|
|
8
|
+
cc.set_source_color(color)
|
9
|
+
cc.paint
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
13
14
|
end
|
data/lib/squib/graphics/image.rb
CHANGED
@@ -1,28 +1,47 @@
|
|
1
|
-
module Squib
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
module Squib
|
2
|
+
|
3
|
+
# Cache all pngs we've already loaded
|
4
|
+
#
|
5
|
+
# :nodoc:
|
6
|
+
# @api private
|
7
|
+
def cache_load_image(file)
|
8
|
+
@img_cache ||= {}
|
9
|
+
@img_cache[file] || @img_cache[file] = Cairo::ImageSurface.from_png(file)
|
10
|
+
end
|
11
|
+
module_function :cache_load_image
|
12
|
+
|
13
|
+
class Card
|
14
|
+
|
15
|
+
# :nodoc:
|
16
|
+
# @api private
|
17
|
+
def png(file, x, y, alpha, blend)
|
18
|
+
return if file.nil? or file.eql? ''
|
19
|
+
png = Squib.cache_load_image(file)
|
20
|
+
use_cairo do |cc|
|
21
|
+
cc.set_source(png, x, y)
|
22
|
+
cc.operator = blend unless blend == :none
|
23
|
+
cc.paint(alpha)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# :nodoc:
|
28
|
+
# @api private
|
29
|
+
def svg(file, id, x, y, width, height, alpha, blend)
|
30
|
+
Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"}
|
31
|
+
return if file.nil? or file.eql? ''
|
32
|
+
svg = RSVG::Handle.new_from_file(file)
|
33
|
+
width = svg.width if width == :native
|
34
|
+
height = svg.height if height == :native
|
35
|
+
tmp = Cairo::ImageSurface.new(width, height)
|
36
|
+
tmp_cc = Cairo::Context.new(tmp)
|
37
|
+
tmp_cc.scale(width.to_f / svg.width.to_f, height.to_f / svg.height.to_f)
|
38
|
+
tmp_cc.render_rsvg_handle(svg, id)
|
39
|
+
use_cairo do |cc|
|
40
|
+
cc.set_source(tmp, x, y)
|
41
|
+
cc.operator = blend unless blend == :none
|
42
|
+
cc.paint(alpha)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -1,51 +1,55 @@
|
|
1
|
-
module Squib
|
2
|
-
class Deck
|
3
|
-
|
4
|
-
# Lays out the cards in range and renders a PDF
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# save_pdf file: 'deck.pdf', margin: 75, gap: 5, trim: 37
|
8
|
-
#
|
9
|
-
# @option opts file [String] the name of the PDF file to save.
|
10
|
-
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
|
11
|
-
# @option opts margin [Integer] (75) the margin around the outside of the page
|
12
|
-
# @option opts gap [Integer] (0) the space in pixels between the cards
|
13
|
-
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
|
14
|
-
# @return [nil]
|
15
|
-
# @api public
|
16
|
-
def save_pdf(opts = {})
|
17
|
-
p = needs(opts, [:file_to_save, :creatable_dir, :margin, :gap, :trim])
|
18
|
-
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too
|
19
|
-
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height))
|
20
|
-
x = p[:margin] ; y = p[:margin]
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
if
|
30
|
-
x = p[:margin]
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
1
|
+
module Squib
|
2
|
+
class Deck
|
3
|
+
|
4
|
+
# Lays out the cards in range and renders a PDF
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# save_pdf file: 'deck.pdf', margin: 75, gap: 5, trim: 37
|
8
|
+
#
|
9
|
+
# @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
|
10
|
+
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
|
11
|
+
# @option opts margin [Integer] (75) the margin around the outside of the page
|
12
|
+
# @option opts gap [Integer] (0) the space in pixels between the cards
|
13
|
+
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
|
14
|
+
# @return [nil]
|
15
|
+
# @api public
|
16
|
+
def save_pdf(opts = {})
|
17
|
+
p = needs(opts, [:file_to_save, :creatable_dir, :margin, :gap, :trim])
|
18
|
+
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too
|
19
|
+
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height))
|
20
|
+
x = p[:margin] ; y = p[:margin]
|
21
|
+
|
22
|
+
@progress_bar.start("Saving PDF to #{p[:dir]}/#{p[:file]}", p[:range].size) do |bar|
|
23
|
+
@cards.each_with_index do |card, i|
|
24
|
+
surface = trim(card.cairo_surface, p[:trim], @width, @height)
|
25
|
+
cc.set_source(surface, x, y)
|
26
|
+
cc.paint
|
27
|
+
bar.increment
|
28
|
+
x += surface.width + p[:gap]
|
29
|
+
if x > (width - surface.width - p[:margin])
|
30
|
+
x = p[:margin]
|
31
|
+
y += surface.height + p[:gap]
|
32
|
+
if y > (height - surface.height - p[:margin])
|
33
|
+
x = p[:margin] ; y = p[:margin]
|
34
|
+
cc.show_page #next page
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# :nodoc:
|
42
|
+
# @api private
|
43
|
+
def trim(surface, trim, width, height)
|
44
|
+
if trim > 0
|
45
|
+
tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim)
|
46
|
+
cc = Cairo::Context.new(tmp)
|
47
|
+
cc.set_source(surface,-1*trim, -1*trim)
|
48
|
+
cc.paint
|
49
|
+
surface = tmp
|
50
|
+
end
|
51
|
+
surface
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
51
55
|
end
|
@@ -1,11 +1,33 @@
|
|
1
|
-
module Squib
|
2
|
-
class Card
|
3
|
-
|
4
|
-
# :nodoc:
|
5
|
-
# @api private
|
6
|
-
def save_png(i, dir, prefix)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Squib
|
2
|
+
class Card
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
# @api private
|
6
|
+
def save_png(i, dir, prefix, do_rotate, angle)
|
7
|
+
if [true, :clockwise, :counterclockwise].include?(do_rotate)
|
8
|
+
surface = rotated_image(angle)
|
9
|
+
else
|
10
|
+
surface = @cairo_surface
|
11
|
+
end
|
12
|
+
write_png(surface, i, dir, prefix)
|
13
|
+
end
|
14
|
+
|
15
|
+
# :nodoc:
|
16
|
+
# @api private
|
17
|
+
def rotated_image(angle)
|
18
|
+
rotated_cc = Cairo::Context.new(Cairo::ImageSurface.new(@height, @width) )
|
19
|
+
rotated_cc.translate(@height * 0.5, @width * 0.5)
|
20
|
+
rotated_cc.rotate(angle)
|
21
|
+
rotated_cc.translate(@width * -0.5, @height * -0.5)
|
22
|
+
rotated_cc.set_source(@cairo_surface)
|
23
|
+
rotated_cc.paint
|
24
|
+
rotated_cc.target
|
25
|
+
end
|
26
|
+
# :nodoc:
|
27
|
+
# @api private
|
28
|
+
def write_png(surface, i, dir, prefix)
|
29
|
+
surface.write_to_png("#{dir}/#{prefix}#{i}.png")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
11
33
|
end
|
@@ -1,56 +1,60 @@
|
|
1
|
-
module Squib
|
2
|
-
class Card
|
3
|
-
|
4
|
-
# :nodoc:
|
5
|
-
# @api private
|
6
|
-
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
|
7
|
-
width=@width if width==:native; height=@height if height==:native
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
cc
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
cc
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
module Squib
|
2
|
+
class Card
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
# @api private
|
6
|
+
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
|
7
|
+
width=@width if width==:native; height=@height if height==:native
|
8
|
+
use_cairo do |cc|
|
9
|
+
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
10
|
+
cc.set_source_color(stroke_color)
|
11
|
+
cc.set_line_width(stroke_width)
|
12
|
+
cc.stroke
|
13
|
+
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
|
14
|
+
cc.set_source_color(fill_color)
|
15
|
+
cc.fill
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# :nodoc:
|
20
|
+
# @api private
|
21
|
+
def circle(x, y, radius, fill_color, stroke_color, stroke_width)
|
22
|
+
use_cairo do |cc|
|
23
|
+
cc.circle(x, y, radius)
|
24
|
+
cc.set_source_color(stroke_color)
|
25
|
+
cc.set_line_width(stroke_width)
|
26
|
+
cc.stroke
|
27
|
+
cc.circle(x, y, radius)
|
28
|
+
cc.set_source_color(fill_color)
|
29
|
+
cc.fill
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# :nodoc:
|
34
|
+
# @api private
|
35
|
+
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)
|
36
|
+
use_cairo do |cc|
|
37
|
+
cc.triangle(x1, y1, x2, y2, x3, y3)
|
38
|
+
cc.set_source_color(stroke_color)
|
39
|
+
cc.set_line_width(stroke_width)
|
40
|
+
cc.stroke
|
41
|
+
cc.triangle(x1, y1, x2, y2, x3, y3)
|
42
|
+
cc.set_source_color(fill_color)
|
43
|
+
cc.fill
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# :nodoc:
|
48
|
+
# @api private
|
49
|
+
def line(x1, y1, x2, y2, stroke_color, stroke_width)
|
50
|
+
use_cairo do |cc|
|
51
|
+
cc.move_to(x1, y1)
|
52
|
+
cc.line_to(x2, y2)
|
53
|
+
cc.set_source_color(stroke_color)
|
54
|
+
cc.set_line_width(stroke_width)
|
55
|
+
cc.stroke
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
56
60
|
end
|
data/lib/squib/graphics/text.rb
CHANGED
@@ -1,108 +1,114 @@
|
|
1
|
-
require 'pango'
|
2
|
-
|
3
|
-
module Squib
|
4
|
-
class Card
|
5
|
-
|
6
|
-
# :nodoc:
|
7
|
-
# @api private
|
8
|
-
def draw_text_hint(x,y,layout, color)
|
9
|
-
|
10
|
-
|
11
|
-
# when w,h < 0, it was never set. extents[
|
12
|
-
w = layout.width / Pango::SCALE
|
13
|
-
w = layout.extents[1].width / Pango::SCALE if w < 0
|
14
|
-
h = layout.height / Pango::SCALE
|
15
|
-
h = layout.extents[1].height / Pango::SCALE if h < 0
|
16
|
-
rect(x,y,w,h,0,0,'#0000',color, 2.0)
|
17
|
-
end
|
18
|
-
|
19
|
-
# :nodoc:
|
20
|
-
# @api private
|
21
|
-
def ellipsize(layout,
|
22
|
-
unless
|
23
|
-
h = { :none => Pango::Layout::ELLIPSIZE_NONE,
|
24
|
-
:start => Pango::Layout::ELLIPSIZE_START,
|
25
|
-
:middle => Pango::Layout::ELLIPSIZE_MIDDLE,
|
26
|
-
:end => Pango::Layout::ELLIPSIZE_END,
|
27
|
-
true => Pango::Layout::ELLIPSIZE_END,
|
28
|
-
false => Pango::Layout::ELLIPSIZE_NONE
|
29
|
-
}
|
30
|
-
layout.ellipsize = h[
|
31
|
-
end
|
32
|
-
layout
|
33
|
-
end
|
34
|
-
|
35
|
-
# :nodoc:
|
36
|
-
# @api private
|
37
|
-
def wrap(layout,
|
38
|
-
unless
|
39
|
-
h = { :word => Pango::Layout::WRAP_WORD,
|
40
|
-
:char => Pango::Layout::WRAP_CHAR,
|
41
|
-
:word_char => Pango::Layout::WRAP_WORD_CHAR,
|
42
|
-
true => Pango::Layout::WRAP_WORD_CHAR,
|
43
|
-
false => nil,
|
44
|
-
:none => nil
|
45
|
-
}
|
46
|
-
layout.wrap = h[
|
47
|
-
end
|
48
|
-
layout
|
49
|
-
end
|
50
|
-
|
51
|
-
# :nodoc:
|
52
|
-
# @api private
|
53
|
-
def align(layout,
|
54
|
-
unless
|
55
|
-
h = { :left => Pango::ALIGN_LEFT,
|
56
|
-
:right => Pango::ALIGN_RIGHT,
|
57
|
-
:center => Pango::ALIGN_CENTER
|
58
|
-
}
|
59
|
-
layout.alignment = h[
|
60
|
-
end
|
61
|
-
layout
|
62
|
-
end
|
63
|
-
|
64
|
-
# :nodoc:
|
65
|
-
# @api private
|
66
|
-
def valign(cc, layout, x, y, valign)
|
67
|
-
if layout.height > 0
|
68
|
-
ink_extents = layout.extents[1]
|
69
|
-
case valign
|
70
|
-
when :middle
|
71
|
-
cc.move_to(x, y + (layout.height - ink_extents.height) / (2 * Pango::SCALE))
|
72
|
-
when :bottom
|
73
|
-
cc.move_to(x, y + (layout.height - ink_extents.height) / Pango::SCALE)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# :nodoc:
|
79
|
-
# @api private
|
80
|
-
def setwh(layout,
|
81
|
-
layout.width =
|
82
|
-
layout.height =
|
83
|
-
layout
|
84
|
-
end
|
85
|
-
|
86
|
-
# :nodoc:
|
87
|
-
# @api private
|
88
|
-
def text(str, font,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
1
|
+
require 'pango'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
class Card
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
# @api private
|
8
|
+
def draw_text_hint(x,y,layout, color)
|
9
|
+
color ||= @deck.text_hint
|
10
|
+
return if color.to_s.eql? 'off'
|
11
|
+
# when w,h < 0, it was never set. extents[1] are ink extents
|
12
|
+
w = layout.width / Pango::SCALE
|
13
|
+
w = layout.extents[1].width / Pango::SCALE if w < 0
|
14
|
+
h = layout.height / Pango::SCALE
|
15
|
+
h = layout.extents[1].height / Pango::SCALE if h < 0
|
16
|
+
rect(x,y,w,h,0,0,'#0000',color, 2.0)
|
17
|
+
end
|
18
|
+
|
19
|
+
# :nodoc:
|
20
|
+
# @api private
|
21
|
+
def ellipsize(layout, ellipsize)
|
22
|
+
unless ellipsize.nil?
|
23
|
+
h = { :none => Pango::Layout::ELLIPSIZE_NONE,
|
24
|
+
:start => Pango::Layout::ELLIPSIZE_START,
|
25
|
+
:middle => Pango::Layout::ELLIPSIZE_MIDDLE,
|
26
|
+
:end => Pango::Layout::ELLIPSIZE_END,
|
27
|
+
true => Pango::Layout::ELLIPSIZE_END,
|
28
|
+
false => Pango::Layout::ELLIPSIZE_NONE
|
29
|
+
}
|
30
|
+
layout.ellipsize = h[ellipsize]
|
31
|
+
end
|
32
|
+
layout
|
33
|
+
end
|
34
|
+
|
35
|
+
# :nodoc:
|
36
|
+
# @api private
|
37
|
+
def wrap(layout, wrap)
|
38
|
+
unless wrap.nil?
|
39
|
+
h = { :word => Pango::Layout::WRAP_WORD,
|
40
|
+
:char => Pango::Layout::WRAP_CHAR,
|
41
|
+
:word_char => Pango::Layout::WRAP_WORD_CHAR,
|
42
|
+
true => Pango::Layout::WRAP_WORD_CHAR,
|
43
|
+
false => nil,
|
44
|
+
:none => nil
|
45
|
+
}
|
46
|
+
layout.wrap = h[wrap]
|
47
|
+
end
|
48
|
+
layout
|
49
|
+
end
|
50
|
+
|
51
|
+
# :nodoc:
|
52
|
+
# @api private
|
53
|
+
def align(layout, align)
|
54
|
+
unless align.nil?
|
55
|
+
h = { :left => Pango::ALIGN_LEFT,
|
56
|
+
:right => Pango::ALIGN_RIGHT,
|
57
|
+
:center => Pango::ALIGN_CENTER
|
58
|
+
}
|
59
|
+
layout.alignment = h[align]
|
60
|
+
end
|
61
|
+
layout
|
62
|
+
end
|
63
|
+
|
64
|
+
# :nodoc:
|
65
|
+
# @api private
|
66
|
+
def valign(cc, layout, x, y, valign)
|
67
|
+
if layout.height > 0
|
68
|
+
ink_extents = layout.extents[1]
|
69
|
+
case valign
|
70
|
+
when :middle
|
71
|
+
cc.move_to(x, y + (layout.height - ink_extents.height) / (2 * Pango::SCALE))
|
72
|
+
when :bottom
|
73
|
+
cc.move_to(x, y + (layout.height - ink_extents.height) / Pango::SCALE)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# :nodoc:
|
79
|
+
# @api private
|
80
|
+
def setwh(layout, width, height)
|
81
|
+
layout.width = width * Pango::SCALE unless width.nil? || width == :native
|
82
|
+
layout.height = height * Pango::SCALE unless height.nil? || height == :native
|
83
|
+
layout
|
84
|
+
end
|
85
|
+
|
86
|
+
# :nodoc:
|
87
|
+
# @api private
|
88
|
+
def text(str, font, color,
|
89
|
+
x, y, width, height,
|
90
|
+
markup, justify, wrap, ellipsize,
|
91
|
+
spacing, align, valign, hint)
|
92
|
+
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc."}
|
93
|
+
use_cairo do |cc|
|
94
|
+
cc.set_source_color(color)
|
95
|
+
cc.move_to(x,y)
|
96
|
+
layout = cc.create_pango_layout
|
97
|
+
layout.font_description = Pango::FontDescription.new(font)
|
98
|
+
layout.text = str.to_s
|
99
|
+
layout.markup = str.to_s if markup
|
100
|
+
layout = setwh(layout, width, height)
|
101
|
+
layout = wrap(layout, wrap)
|
102
|
+
layout = ellipsize(layout, ellipsize)
|
103
|
+
layout = align(layout, align)
|
104
|
+
layout.justify = justify unless justify.nil?
|
105
|
+
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
106
|
+
cc.update_pango_layout(layout)
|
107
|
+
valign(cc, layout, x,y, valign)
|
108
|
+
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
|
109
|
+
draw_text_hint(x,y,layout,hint)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
108
114
|
end
|