squib 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +29 -29
  3. data/.travis.yml +6 -6
  4. data/.yardopts +7 -5
  5. data/Gemfile +2 -2
  6. data/LICENSE.txt +22 -22
  7. data/README.md +245 -92
  8. data/Rakefile +11 -11
  9. data/bin/squib +18 -18
  10. data/lib/squib.rb +31 -18
  11. data/lib/squib/api/background.rb +18 -16
  12. data/lib/squib/api/data.rb +52 -52
  13. data/lib/squib/api/image.rb +66 -48
  14. data/lib/squib/api/save.rb +43 -37
  15. data/lib/squib/api/settings.rb +38 -35
  16. data/lib/squib/api/shapes.rb +116 -106
  17. data/lib/squib/api/text.rb +50 -45
  18. data/lib/squib/api/units.rb +16 -16
  19. data/lib/squib/card.rb +42 -36
  20. data/lib/squib/commands/new.rb +43 -39
  21. data/lib/squib/constants.rb +104 -39
  22. data/lib/squib/deck.rb +116 -113
  23. data/lib/squib/graphics/background.rb +13 -12
  24. data/lib/squib/graphics/image.rb +47 -28
  25. data/lib/squib/graphics/save_doc.rb +54 -50
  26. data/lib/squib/graphics/save_images.rb +32 -10
  27. data/lib/squib/graphics/shapes.rb +59 -55
  28. data/lib/squib/graphics/text.rb +113 -107
  29. data/lib/squib/input_helpers.rb +193 -139
  30. data/lib/squib/progress.rb +38 -0
  31. data/lib/squib/project_template/.gitignore +4 -3
  32. data/lib/squib/project_template/ABOUT.md +19 -19
  33. data/lib/squib/project_template/Gemfile +2 -2
  34. data/lib/squib/project_template/PNP NOTES.md +3 -3
  35. data/lib/squib/project_template/config.yml +20 -2
  36. data/lib/squib/project_template/deck.rb +5 -5
  37. data/lib/squib/version.rb +6 -6
  38. data/samples/ball.png +0 -0
  39. data/samples/basic.rb +19 -19
  40. data/samples/colors.rb +15 -16
  41. data/samples/custom-config.yml +6 -1
  42. data/samples/custom-layout.yml +39 -34
  43. data/samples/custom_config.rb +18 -5
  44. data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -0
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/grit.png +0 -0
  49. data/samples/hello_world.rb +6 -6
  50. data/samples/load_images.rb +29 -19
  51. data/samples/offset.svg +71 -0
  52. data/samples/portrait-landscape.rb +23 -0
  53. data/samples/ranges.rb +55 -47
  54. data/samples/save_pdf.rb +14 -14
  55. data/samples/shiny-purse.png +0 -0
  56. data/samples/spanner.svg +91 -91
  57. data/samples/text_options.rb +60 -58
  58. data/samples/tgc_proofs.rb +19 -19
  59. data/samples/units.rb +12 -12
  60. data/samples/use_layout.rb +28 -28
  61. data/spec/api/api_text_spec.rb +42 -36
  62. data/spec/commands/new_spec.rb +47 -47
  63. data/spec/data/multi-extends-single-entry.yml +13 -0
  64. data/spec/data/multi-level-extends.yml +10 -0
  65. data/spec/data/no-extends.yml +5 -0
  66. data/spec/data/single-extends.yml +7 -0
  67. data/spec/data/single-level-multi-extends.yml +12 -0
  68. data/spec/deck_spec.rb +147 -49
  69. data/spec/input_helpers_spec.rb +117 -0
  70. data/spec/samples_run_spec.rb +19 -14
  71. data/spec/spec_helper.rb +3 -0
  72. data/squib.gemspec +46 -42
  73. metadata +78 -4
  74. data/API.md +0 -59
@@ -1,35 +1,38 @@
1
- module Squib
2
- class Deck
3
-
4
- # Toggle hints globally.
5
- #
6
- # Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
7
- # Setting a hint to nil or to :off will disable hints. @see samples/text.rb
8
- # @example
9
- # hint text:cyan
10
- #
11
- # @param [String] text the color of the text hint. To turn off use nil or :off. @see API.md
12
- # @return [nil] Returns nothing
13
- # @api public
14
- def hint(text: nil)
15
- text = nil if text == :off
16
- @text_hint = text
17
- end
18
-
19
- # Sets various defaults for this deck. Defaults can be overriden by the commands themselves
20
- # @example
21
- # set font: 'Arial 26'
22
- # text 'blah' # in Arial 26
23
- # text 'blah24', font: 'Arial 24' # in Arial 24
24
- # set font: :default # Back to Squib-wide default
25
- #
26
- # @option opts font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
27
- # @return [nil] Returns nothing
28
- # @api public
29
- def set(opts = {})
30
- opts = needs(opts, [:font])
31
- @font = opts[:font]
32
- end
33
-
34
- end
35
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Toggle hints globally.
5
+ #
6
+ # Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
7
+ # Setting a hint to nil or to :off will disable hints. @see samples/text.rb
8
+ # @example
9
+ # hint text: :cyan
10
+ # hint text: :cyan, progress_bar: true
11
+ #
12
+ # @param [String] text the color of the text hint. To turn off use :off. @see README.md
13
+ # @param [Boolean] progress_bar enable progress bars on long-running operations
14
+ # @return [nil] Returns nothing
15
+ # @api public
16
+ def hint(text: :off)
17
+ @text_hint = text
18
+ end
19
+
20
+ # Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
21
+ # @example
22
+ # set font: 'Arial 26'
23
+ # text 'blah' # in Arial 26
24
+ # text 'blah24', font: 'Arial 24' # in Arial 24
25
+ # set font: :default # Back to Squib-wide default
26
+ #
27
+ # @option opts font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
28
+ # @option opts img_dir: the default directory to READ images from. Default is `.`. Useful for switching from bw to color images.
29
+ # @return [nil] Returns nothing
30
+ # @api public
31
+ def set(opts = {})
32
+ opts = needs(opts, [:font, :img_dir])
33
+ @font = opts[:font][0] #was expanded - just need the first
34
+ @img_dir = opts[:img_dir]
35
+ end
36
+
37
+ end
38
+ end
@@ -1,107 +1,117 @@
1
- module Squib
2
- class Deck
3
-
4
- # Draw a rounded rectangle
5
- #
6
- # @example
7
- # rect x: 0, y: 0, width: 825, height: 1125, radius: 25
8
- #
9
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
10
- # @option opts x [Integer] (0) the x-coordinate to place
11
- # @option opts y [Integer] (0) the y-coordinate to place
12
- # @option opts width [Integer] the width of the rectangle.
13
- # @option opts height [Integer] the height of the rectangle.
14
- # @option opts x_radius [Integer] (0) the radius of the rounded corner horiztonally. Zero is a non-rounded corner.
15
- # @option opts y_radius [Integer] (0) the radius of the rounded corner vertically. Zero is a non-rounded corner.
16
- # @option opts radius [Integer] (nil) when set, overrides both x_radius and y_radius
17
- # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
18
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
19
- # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
20
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
21
- # @return [nil] intended to be void
22
- # @api public
23
- def rect(opts = {})
24
- opts = needs(opts, [:range, :x, :y, :width, :height, :radius,
25
- :fill_color, :stroke_color, :stroke_width, :layout])
26
- opts[:range].each do |i|
27
- @cards[i].rect(opts[:x], opts[:y], opts[:width], opts[:height],
28
- opts[:x_radius], opts[:y_radius],
29
- opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
30
- end
31
- end
32
-
33
- # Draw a circle centered at the given coordinates
34
- #
35
- # @example
36
- # circle x: 0, y: 0, radius: 100
37
- #
38
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
39
- # @option opts x [Integer] (0) the x-coordinate to place
40
- # @option opts y [Integer] (0) the y-coordinate to place
41
- # @option opts radius [Integer] (100) radius of the circle
42
- # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
43
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
44
- # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
45
- # @return [nil] intended to be void
46
- # @api public
47
- def circle(opts = {})
48
- opts = {radius: 100}.merge(opts)
49
- opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
50
- :fill_color, :stroke_color, :stroke_width])
51
- opts[:range].each do |i|
52
- @cards[i].circle(opts[:x], opts[:y], opts[:radius],
53
- opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
54
- end
55
- end
56
-
57
- # Draw a triangle using the given coordinates
58
- #
59
- # @example
60
- # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50
61
- #
62
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
63
- # @option opts x1 [Integer] (0) the x-coordinate to place
64
- # @option opts y1 [Integer] (0) the y-coordinate to place
65
- # @option opts x2 [Integer] (50) the x-coordinate to place
66
- # @option opts y2 [Integer] (50) the y-coordinate to place
67
- # @option opts x3 [Integer] (0) the x-coordinate to place
68
- # @option opts y3 [Integer] (50) the y-coordinate to place
69
- # @option opts fill_color [String] ('#0000') the color with which to fill the triangle
70
- # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle
71
- # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
72
- # @return [nil] intended to be void
73
- # @api public
74
- def triangle(opts = {})
75
- opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout,
76
- :fill_color, :stroke_color, :stroke_width])
77
- opts[:range].each do |i|
78
- @cards[i].triangle(opts[:x1], opts[:y1], opts[:x2], opts[:y2],opts[:x3], opts[:y3],
79
- opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
80
- end
81
- end
82
-
83
- # Draw a line using the given coordinates
84
- #
85
- # @example
86
- # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50
87
- #
88
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
89
- # @option opts x1 [Integer] (0) the x-coordinate to place
90
- # @option opts y1 [Integer] (0) the y-coordinate to place
91
- # @option opts x2 [Integer] (50) the x-coordinate to place
92
- # @option opts y2 [Integer] (50) the y-coordinate to place
93
- # @option opts stroke_color [String] (:black) the color with which to stroke the line
94
- # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
95
- # @return [nil] intended to be void
96
- # @api public
97
- def line(opts = {})
98
- opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :layout,
99
- :stroke_color, :stroke_width])
100
- opts[:range].each do |i|
101
- @cards[i].line(opts[:x1], opts[:y1], opts[:x2], opts[:y2],
102
- opts[:stroke_color], opts[:stroke_width])
103
- end
104
- end
105
-
106
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Draw a rounded rectangle
5
+ #
6
+ # @example
7
+ # rect x: 0, y: 0, width: 825, height: 1125, radius: 25
8
+ #
9
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
10
+ #
11
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
12
+ # @option opts x [Integer] (0) the x-coordinate to place
13
+ # @option opts y [Integer] (0) the y-coordinate to place
14
+ # @option opts width [Integer] the width of the rectangle.
15
+ # @option opts height [Integer] the height of the rectangle.
16
+ # @option opts x_radius [Integer] (0) the radius of the rounded corner horiztonally. Zero is a non-rounded corner.
17
+ # @option opts y_radius [Integer] (0) the radius of the rounded corner vertically. Zero is a non-rounded corner.
18
+ # @option opts radius [Integer] (nil) when set, overrides both x_radius and y_radius
19
+ # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
20
+ # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
21
+ # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
22
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
23
+ # @return [nil] intended to be void
24
+ # @api public
25
+ def rect(opts = {})
26
+ opts = needs(opts, [:range, :x, :y, :width, :height, :rect_radius, :x_radius, :y_radius,
27
+ :fill_color, :stroke_color, :stroke_width, :layout])
28
+ opts[:range].each do |i|
29
+ @cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
30
+ opts[:x_radius][i], opts[:y_radius][i],
31
+ opts[:fill_color][i], opts[:stroke_color][i],
32
+ opts[:stroke_width][i])
33
+ end
34
+ end
35
+
36
+ # Draw a circle centered at the given coordinates
37
+ #
38
+ # @example
39
+ # circle x: 0, y: 0, radius: 100
40
+ #
41
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
42
+ #
43
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
44
+ # @option opts x [Integer] (0) the x-coordinate to place
45
+ # @option opts y [Integer] (0) the y-coordinate to place
46
+ # @option opts radius [Integer] (100) radius of the circle
47
+ # @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
48
+ # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
49
+ # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
50
+ # @return [nil] intended to be void
51
+ # @api public
52
+ def circle(opts = {})
53
+ opts = {radius: 100}.merge(opts)
54
+ opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
55
+ :fill_color, :stroke_color, :stroke_width])
56
+ opts[:range].each do |i|
57
+ @cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i],
58
+ opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i])
59
+ end
60
+ end
61
+
62
+ # Draw a triangle using the given coordinates
63
+ #
64
+ # @example
65
+ # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50
66
+ #
67
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
68
+ #
69
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
70
+ # @option opts x1 [Integer] (0) the x-coordinate to place
71
+ # @option opts y1 [Integer] (0) the y-coordinate to place
72
+ # @option opts x2 [Integer] (50) the x-coordinate to place
73
+ # @option opts y2 [Integer] (50) the y-coordinate to place
74
+ # @option opts x3 [Integer] (0) the x-coordinate to place
75
+ # @option opts y3 [Integer] (50) the y-coordinate to place
76
+ # @option opts fill_color [String] ('#0000') the color with which to fill the triangle
77
+ # @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle
78
+ # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
79
+ # @return [nil] intended to be void
80
+ # @api public
81
+ def triangle(opts = {})
82
+ opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout,
83
+ :fill_color, :stroke_color, :stroke_width])
84
+ opts[:range].each do |i|
85
+ @cards[i].triangle(opts[:x1][i], opts[:y1][i],
86
+ opts[:x2][i], opts[:y2][i],
87
+ opts[:x3][i], opts[:y3][i],
88
+ opts[:fill_color][i], opts[:stroke_color][i],
89
+ opts[:stroke_width][i])
90
+ end
91
+ end
92
+
93
+ # Draw a line using the given coordinates
94
+ #
95
+ # @example
96
+ # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50
97
+ #
98
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
99
+ # @option opts x1 [Integer] (0) the x-coordinate to place
100
+ # @option opts y1 [Integer] (0) the y-coordinate to place
101
+ # @option opts x2 [Integer] (50) the x-coordinate to place
102
+ # @option opts y2 [Integer] (50) the y-coordinate to place
103
+ # @option opts stroke_color [String] (:black) the color with which to stroke the line
104
+ # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
105
+ # @return [nil] intended to be void
106
+ # @api public
107
+ def line(opts = {})
108
+ opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :layout,
109
+ :stroke_color, :stroke_width])
110
+ opts[:range].each do |i|
111
+ @cards[i].line(opts[:x1][i], opts[:y1][i], opts[:x2][i], opts[:y2][i],
112
+ opts[:stroke_color][i], opts[:stroke_width][i])
113
+ end
114
+ end
115
+
116
+ end
107
117
  end
@@ -1,46 +1,51 @@
1
- module Squib
2
- class Deck
3
-
4
- # Renders a string at a given location, width, alignment, font, etc.
5
- #
6
- # Unix-like newlines are interpreted even on Windows.
7
- # See the {file:samples/text-options.rb samples/text.rb} for a lengthy example.
8
- #
9
- # @example
10
- # text str: 'hello'
11
- # text str: 'hello', x: 50, y:50, align: center
12
- #
13
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
14
- # @option opts str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards.
15
- # @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size.
16
- # (e.g. `'Arial bold italic 12'`)
17
- # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
18
- # This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
19
- # See the {file:samples/text-options.rb samples/text.rb} as well.
20
- # @option opts x [Integer] (0) the x-coordinate to place
21
- # @option opts y [Integer] (0) the y-coordinate to place
22
- # @option opts color [String] (:black) the color the font will render to. See {file:API.md#label-Specifying+Colors Specifying Colors}
23
- # @option opts markup: [Boolean] (false) Enable markup parsing of `str` using the HTML-like Pango Markup syntax, defined [here](http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup) and [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html).
24
- # @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
25
- # @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
26
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
27
- # @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
28
- # Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
29
- # @option opts align [:left, right, :center] (:left) The alignment of the text
30
- # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
31
- # @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the logical extents of the text.
32
- # @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end`
33
- # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
34
- # @return [nil] Returns nothing
35
- # @api public
36
- def text(opts = {})
37
- opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :text_color, :wrap,
38
- :align, :justify, :valign, :ellipsize, :hint, :layout])
39
- opts[:str] = [opts[:str]] * @cards.size unless opts[:str].respond_to? :each
40
- opts[:range].each do |i|
41
- @cards[i].text(opts[:str][i], opts[:font], opts[:x], opts[:y], opts[:color], opts)
42
- end
43
- end
44
-
45
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Renders a string at a given location, width, alignment, font, etc.
5
+ #
6
+ # Unix-like newlines are interpreted even on Windows.
7
+ # See the {file:samples/text-options.rb samples/text.rb} for a lengthy example.
8
+ #
9
+ # @example
10
+ # text str: 'hello'
11
+ # text str: 'hello', x: 50, y:50, align: center
12
+ #
13
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
14
+ #
15
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
16
+ # @option opts str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards.
17
+ # @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size.
18
+ # (e.g. `'Arial bold italic 12'`)
19
+ # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
20
+ # This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
21
+ # See the {file:samples/text-options.rb samples/text.rb} as well.
22
+ # @option opts x [Integer] (0) the x-coordinate to place
23
+ # @option opts y [Integer] (0) the y-coordinate to place
24
+ # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}
25
+ # @option opts markup: [Boolean] (false) Enable markup parsing of `str` using the HTML-like Pango Markup syntax, defined [here](http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup) and [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html).
26
+ # @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
27
+ # @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
28
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
29
+ # @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
30
+ # Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
31
+ # @option opts align [:left, right, :center] (:left) The alignment of the text
32
+ # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
33
+ # @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the logical extents of the text.
34
+ # @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end`
35
+ # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
36
+ # @return [nil] Returns nothing
37
+ # @api public
38
+ def text(opts = {})
39
+ opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :color, :wrap,
40
+ :align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout])
41
+ opts[:range].each do |i|
42
+ @cards[i].text(opts[:str][i], opts[:font][i], opts[:color][i],
43
+ opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
44
+ opts[:markup][i], opts[:justify][i], opts[:wrap][i],
45
+ opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
46
+ opts[:valign][i], opts[:hint][i])
47
+ end
48
+ end
49
+
50
+ end
46
51
  end
@@ -1,17 +1,17 @@
1
- module Squib
2
- class Deck
3
-
4
- # Given inches, returns the number of pixels according to the deck's DPI.
5
- #
6
- # @example
7
- # inches(2.5) # 750 (for default Deck::dpi of 300)
8
- #
9
- # @param [Decimal] n, the number of inches
10
- # @return [Decimal] the number of pixels, according to the deck's DPI
11
- # @api public
12
- def inches(n)
13
- @dpi * n
14
- end
15
-
16
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Given inches, returns the number of pixels according to the deck's DPI.
5
+ #
6
+ # @example
7
+ # inches(2.5) # 750 (for default Deck::dpi of 300)
8
+ #
9
+ # @param [Decimal] n, the number of inches
10
+ # @return [Decimal] the number of pixels, according to the deck's DPI
11
+ # @api public
12
+ def inches(n)
13
+ @dpi * n
14
+ end
15
+
16
+ end
17
17
  end
@@ -1,36 +1,42 @@
1
- require 'cairo'
2
- require 'squib/input_helpers'
3
-
4
- module Squib
5
- # Back end graphics. Private.
6
- class Card
7
- include Squib::InputHelpers
8
-
9
- # :nodoc:
10
- # @api private
11
- attr_reader :width, :height
12
-
13
- # :nodoc:
14
- # @api private
15
- attr_accessor :cairo_surface, :cairo_context
16
-
17
- # :nodoc:
18
- # @api private
19
- def initialize(deck, width, height)
20
- @deck=deck; @width=width; @height=height
21
- @cairo_surface = Cairo::ImageSurface.new(width,height)
22
- @cairo_context = Cairo::Context.new(@cairo_surface)
23
- end
24
-
25
- ########################
26
- ### BACKEND GRAPHICS ###
27
- ########################
28
- require 'squib/graphics/background'
29
- require 'squib/graphics/image'
30
- require 'squib/graphics/save_doc'
31
- require 'squib/graphics/save_images'
32
- require 'squib/graphics/shapes'
33
- require 'squib/graphics/text'
34
-
35
- end
36
- end
1
+ require 'cairo'
2
+ require 'squib/input_helpers'
3
+
4
+ module Squib
5
+ # Back end graphics. Private.
6
+ class Card
7
+ include Squib::InputHelpers
8
+
9
+ # :nodoc:
10
+ # @api private
11
+ attr_reader :width, :height
12
+
13
+ # :nodoc:
14
+ # @api private
15
+ attr_accessor :cairo_surface, :cairo_context
16
+
17
+ # :nodoc:
18
+ # @api private
19
+ def initialize(deck, width, height)
20
+ @deck=deck; @width=width; @height=height
21
+ @cairo_surface = Cairo::ImageSurface.new(width,height)
22
+ @cairo_context = Cairo::Context.new(@cairo_surface)
23
+ end
24
+
25
+ def use_cairo(&block)
26
+ @cairo_context.save
27
+ block.yield(@cairo_context)
28
+ @cairo_context.restore
29
+ end
30
+
31
+ ########################
32
+ ### BACKEND GRAPHICS ###
33
+ ########################
34
+ require 'squib/graphics/background'
35
+ require 'squib/graphics/image'
36
+ require 'squib/graphics/save_doc'
37
+ require 'squib/graphics/save_images'
38
+ require 'squib/graphics/shapes'
39
+ require 'squib/graphics/text'
40
+
41
+ end
42
+ end