squib 0.0.3 → 0.0.4

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 -7
  5. data/CHANGELOG.md +19 -0
  6. data/Gemfile +2 -2
  7. data/LICENSE.txt +22 -22
  8. data/README.md +256 -244
  9. data/Rakefile +11 -11
  10. data/bin/squib +18 -18
  11. data/lib/squib.rb +31 -31
  12. data/lib/squib/api/background.rb +18 -18
  13. data/lib/squib/api/data.rb +52 -52
  14. data/lib/squib/api/image.rb +66 -66
  15. data/lib/squib/api/save.rb +43 -43
  16. data/lib/squib/api/settings.rb +37 -38
  17. data/lib/squib/api/shapes.rb +116 -116
  18. data/lib/squib/api/text.rb +53 -50
  19. data/lib/squib/api/units.rb +16 -16
  20. data/lib/squib/card.rb +41 -41
  21. data/lib/squib/commands/new.rb +43 -43
  22. data/lib/squib/constants.rb +108 -104
  23. data/lib/squib/deck.rb +170 -116
  24. data/lib/squib/graphics/background.rb +13 -13
  25. data/lib/squib/graphics/image.rb +47 -47
  26. data/lib/squib/graphics/save_doc.rb +54 -54
  27. data/lib/squib/graphics/save_images.rb +32 -32
  28. data/lib/squib/graphics/shapes.rb +59 -59
  29. data/lib/squib/graphics/text.rb +116 -113
  30. data/lib/squib/input_helpers.rb +193 -193
  31. data/lib/squib/progress.rb +37 -37
  32. data/lib/squib/project_template/.gitignore +4 -4
  33. data/lib/squib/project_template/ABOUT.md +19 -19
  34. data/lib/squib/project_template/Gemfile +2 -2
  35. data/lib/squib/project_template/PNP NOTES.md +3 -3
  36. data/lib/squib/project_template/config.yml +19 -19
  37. data/lib/squib/project_template/deck.rb +5 -5
  38. data/lib/squib/version.rb +6 -6
  39. data/samples/autoscale_font.rb +27 -0
  40. data/samples/basic.rb +19 -19
  41. data/samples/colors.rb +15 -15
  42. data/samples/custom-config.yml +5 -5
  43. data/samples/custom-layout.yml +59 -39
  44. data/samples/custom_config.rb +18 -18
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -91
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/hello_world.rb +6 -6
  49. data/samples/load_images.rb +29 -29
  50. data/samples/offset.svg +71 -71
  51. data/samples/portrait-landscape.rb +22 -22
  52. data/samples/ranges.rb +55 -55
  53. data/samples/save_pdf.rb +14 -14
  54. data/samples/spanner.svg +91 -91
  55. data/samples/text_options.rb +67 -60
  56. data/samples/tgc_proofs.rb +19 -19
  57. data/samples/units.rb +12 -12
  58. data/samples/use_layout.rb +33 -28
  59. data/spec/api/api_text_spec.rb +43 -43
  60. data/spec/commands/new_spec.rb +47 -47
  61. data/spec/data/easy-circular-extends.yml +6 -0
  62. data/spec/data/hard-circular-extends.yml +9 -0
  63. data/spec/data/multi-extends-single-entry.yml +14 -13
  64. data/spec/data/multi-level-extends.yml +9 -9
  65. data/spec/data/no-extends.yml +5 -5
  66. data/spec/data/pre-extends.yml +7 -0
  67. data/spec/data/self-circular-extends.yml +3 -0
  68. data/spec/data/single-extends.yml +7 -7
  69. data/spec/data/single-level-multi-extends.yml +11 -11
  70. data/spec/deck_spec.rb +188 -147
  71. data/spec/input_helpers_spec.rb +116 -116
  72. data/spec/samples_run_spec.rb +19 -19
  73. data/squib.gemspec +46 -46
  74. metadata +17 -7
@@ -1,38 +1,37 @@
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
+ 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
11
+ #
12
+ # @param [String] text the color of the text hint. To turn off use :off. @see README.md
13
+ # @return [nil] Returns nothing
14
+ # @api public
15
+ def hint(text: :off)
16
+ @text_hint = text
17
+ end
18
+
19
+ # Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
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
+ # @option opts img_dir: the default directory to READ images from. Default is `.`. Useful for switching from bw to color images.
28
+ # @return [nil] Returns nothing
29
+ # @api public
30
+ def set(opts = {})
31
+ opts = needs(opts, [:font, :img_dir])
32
+ @font = opts[:font][0] #was expanded - just need the first
33
+ @img_dir = opts[:img_dir]
34
+ end
35
+
36
+ end
37
+ end
@@ -1,117 +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
- # 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
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
117
117
  end
@@ -1,51 +1,54 @@
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
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 font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string
23
+ # @option opts x [Integer] (0) the x-coordinate to place
24
+ # @option opts y [Integer] (0) the y-coordinate to place
25
+ # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}
26
+ # @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).
27
+ # @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
28
+ # @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
29
+ # @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}
30
+ # @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. #
31
+ # Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
32
+ # @option opts spacing [Integer] (0) Adjust the spacing when the text is multiple lines. No effect when the text does not wrap.
33
+ # @option opts align [:left, right, :center] (:left) The alignment of the text
34
+ # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
35
+ # @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text.
36
+ # @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`
37
+ # @option opts angle [FixNum] (0) Rotation of the text in radians.
38
+ # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
39
+ # @return [nil] Returns nothing
40
+ # @api public
41
+ def text(opts = {})
42
+ opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
43
+ :align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout, :angle])
44
+ opts[:range].each do |i|
45
+ @cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
46
+ opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
47
+ opts[:markup][i], opts[:justify][i], opts[:wrap][i],
48
+ opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
49
+ opts[:valign][i], opts[:hint][i], opts[:angle][i])
50
+ end
51
+ end
52
+
53
+ end
51
54
  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,42 +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
- 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
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
42
  end