squib 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +5 -4
  4. data/CHANGELOG.md +12 -2
  5. data/Gemfile +2 -0
  6. data/README.md +177 -31
  7. data/Rakefile +1 -0
  8. data/lib/squib/api/shapes.rb +25 -0
  9. data/lib/squib/api/text.rb +9 -3
  10. data/lib/squib/api/text_embed.rb +64 -0
  11. data/lib/squib/args/typographer.rb +112 -0
  12. data/lib/squib/args/unit_conversion.rb +4 -0
  13. data/lib/squib/card.rb +2 -1
  14. data/lib/squib/constants.rb +32 -1
  15. data/lib/squib/deck.rb +6 -1
  16. data/lib/squib/graphics/cairo_context_wrapper.rb +9 -1
  17. data/lib/squib/graphics/save_doc.rb +1 -1
  18. data/lib/squib/graphics/shapes.rb +16 -0
  19. data/lib/squib/graphics/showcase.rb +2 -0
  20. data/lib/squib/graphics/text.rb +105 -23
  21. data/lib/squib/project_template/config.yml +13 -0
  22. data/lib/squib/version.rb +1 -1
  23. data/samples/config_disable_quotes.yml +3 -0
  24. data/samples/config_text_markup.rb +20 -0
  25. data/samples/config_text_markup.yml +9 -0
  26. data/samples/draw_shapes.rb +5 -0
  27. data/samples/embed_text.rb +90 -0
  28. data/samples/text_options.rb +21 -7
  29. data/spec/api/api_text_spec.rb +3 -3
  30. data/spec/args/typographer_spec.rb +71 -0
  31. data/spec/data/samples/autoscale_font.rb.txt +9 -9
  32. data/spec/data/samples/basic.rb.txt +12 -12
  33. data/spec/data/samples/config_text_markup.rb.txt +75 -0
  34. data/spec/data/samples/csv_import.rb.txt +12 -12
  35. data/spec/data/samples/custom_config.rb.txt +2 -6
  36. data/spec/data/samples/draw_shapes.rb.txt +11 -0
  37. data/spec/data/samples/embed_text.rb.txt +295 -0
  38. data/spec/data/samples/excel.rb.txt +18 -18
  39. data/spec/data/samples/gradients.rb.txt +2 -2
  40. data/spec/data/samples/hello_world.rb.txt +2 -2
  41. data/spec/data/samples/portrait-landscape.rb.txt +2 -2
  42. data/spec/data/samples/ranges.rb.txt +48 -48
  43. data/spec/data/samples/saves.rb.txt +32 -32
  44. data/spec/data/samples/showcase.rb.txt +8 -8
  45. data/spec/data/samples/text_options.rb.txt +162 -120
  46. data/spec/data/samples/tgc_proofs.rb.txt +4 -4
  47. data/spec/graphics/graphics_text_spec.rb +13 -11
  48. data/spec/samples/samples_regression_spec.rb +2 -0
  49. data/spec/spec_helper.rb +22 -5
  50. data/squib.gemspec +1 -1
  51. data/squib.sublime-project +49 -0
  52. metadata +17 -16
@@ -25,8 +25,7 @@ cairo: save([])
25
25
  cairo: set_source_color([:black])
26
26
  cairo: translate([220, 78])
27
27
  cairo: rotate([0])
28
- cairo: translate([-220, -78])
29
- cairo: move_to([220, 78])
28
+ cairo: move_to([0, 0])
30
29
  pango: font_description=([MockDouble])
31
30
  pango: text=(["Mastermind"])
32
31
  pango: wrap=([#<Pango::Layout::WrapMode word-char>])
@@ -35,6 +34,7 @@ pango: alignment=([#<Pango::Layout::Alignment left>])
35
34
  pango: justify=([false])
36
35
  pango: spacing=([0])
37
36
  cairo: update_pango_layout([MockDouble])
37
+ cairo: move_to([0, 0])
38
38
  cairo: update_pango_layout([MockDouble])
39
39
  cairo: show_pango_layout([MockDouble])
40
40
  cairo: restore([])
@@ -42,8 +42,7 @@ cairo: save([])
42
42
  cairo: set_source_color([:black])
43
43
  cairo: translate([75, 85])
44
44
  cairo: rotate([0])
45
- cairo: translate([-75, -85])
46
- cairo: move_to([75, 85])
45
+ cairo: move_to([0, 0])
47
46
  pango: font_description=([MockDouble])
48
47
  pango: text=(["3"])
49
48
  pango: width=([131072])
@@ -53,6 +52,7 @@ pango: alignment=([#<Pango::Layout::Alignment center>])
53
52
  pango: justify=([false])
54
53
  pango: spacing=([0])
55
54
  cairo: update_pango_layout([MockDouble])
55
+ cairo: move_to([0, 0])
56
56
  cairo: update_pango_layout([MockDouble])
57
57
  cairo: show_pango_layout([MockDouble])
58
58
  cairo: restore([])
@@ -8,6 +8,7 @@ describe Squib::Card, '#text' do
8
8
  let(:context) { double(Cairo::Context) }
9
9
  let(:layout) { double(Pango::Layout) }
10
10
  let(:font_desc) { double(Pango::FontDescription) }
11
+ let(:pango_cxt) { double(Pango::Context) }
11
12
 
12
13
  before(:each) do
13
14
  allow(Cairo::Context).to receive(:new).and_return(context)
@@ -15,6 +16,7 @@ describe Squib::Card, '#text' do
15
16
  allow(deck).to receive(:count_format).and_return('%02d')
16
17
  allow(deck).to receive(:prefix).and_return('card_')
17
18
  allow(deck).to receive(:antialias).and_return('best')
19
+ allow(layout).to receive(:context).and_return(pango_cxt)
18
20
  end
19
21
 
20
22
  it 'make all the expected calls on a smoke test' do
@@ -23,8 +25,7 @@ describe Squib::Card, '#text' do
23
25
  expect(context).to receive(:antialias=).with('subpixel').once
24
26
  expect(context).to receive(:save).once
25
27
  expect(context).to receive(:set_source_color).once
26
- expect(context).to receive(:move_to).with(10, 15).once
27
- expect(context).to receive(:translate).with(-10, -15).once
28
+ expect(context).to receive(:move_to).with(0, 0).twice
28
29
  expect(context).to receive(:rotate).with(0.0).once
29
30
  expect(context).to receive(:translate).with(10, 15).once
30
31
  expect(context).to receive(:create_pango_layout).once.and_return(layout)
@@ -35,6 +36,7 @@ describe Squib::Card, '#text' do
35
36
  expect(layout ).to receive(:height=).with(25 * Pango::SCALE).once
36
37
  expect(layout ).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_NONE).once
37
38
  expect(layout ).to receive(:alignment=).with(Pango::Layout::ALIGN_LEFT).once
39
+ expect(pango_cxt).to receive(:font_options=).once
38
40
  expect(layout ).to receive(:justify=).with(false).once
39
41
  expect(layout ).to receive(:spacing=).with(1.0 * Pango::SCALE).once
40
42
  expect(context).to receive(:update_pango_layout).once
@@ -49,7 +51,7 @@ describe Squib::Card, '#text' do
49
51
  # x, y, width, height,
50
52
  # markup, justify, wrap, ellipsize,
51
53
  # spacing, align, valign, hint, angle)
52
- ret = card.text('foo', 'Sans 12', nil, '#abc',
54
+ ret = card.text(Squib::TextEmbed.new,'foo', 'Sans 12', nil, '#abc',
53
55
  10, 15, 20, 25,
54
56
  nil, false, false, false,
55
57
  1.0, :left, :top, nil, 0.0)
@@ -75,7 +77,7 @@ describe Squib::Card, '#text' do
75
77
  it 'aligns right with strings' do
76
78
  card = Squib::Card.new(deck, 100, 150)
77
79
  expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
78
- card.text('foo', 'Sans 12', nil, '#abc',
80
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
79
81
  10, 15, 20, 50,
80
82
  nil, false, false, false,
81
83
  1.0, 'right', :top, nil, 0.0)
@@ -84,7 +86,7 @@ describe Squib::Card, '#text' do
84
86
  it 'aligns center with strings' do
85
87
  card = Squib::Card.new(deck, 100, 150)
86
88
  expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
87
- card.text('foo', 'Sans 12', nil, '#abc',
89
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
88
90
  10, 15, 20, 50,
89
91
  nil, false, false, false,
90
92
  1.0, 'center', :top, nil, 0.0)
@@ -93,7 +95,7 @@ describe Squib::Card, '#text' do
93
95
  it 'sets wrap to char with string char' do
94
96
  card = Squib::Card.new(deck, 100, 150)
95
97
  expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
96
- card.text('foo', 'Sans 12', nil, '#abc',
98
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
97
99
  10, 15, 20, 50,
98
100
  nil, false, 'char', false,
99
101
  1.0, :left, :top, nil, 0.0)
@@ -102,7 +104,7 @@ describe Squib::Card, '#text' do
102
104
  it 'sets wrap to word with word string' do
103
105
  card = Squib::Card.new(deck, 100, 150)
104
106
  expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
105
- card.text('foo', 'Sans 12', nil, '#abc',
107
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
106
108
  10, 15, 20, 50,
107
109
  nil, false, 'word', false,
108
110
  1.0, :left, :top, nil, 0.0)
@@ -111,7 +113,7 @@ describe Squib::Card, '#text' do
111
113
  it 'sets wrap to word_char with symbol word_char' do
112
114
  card = Squib::Card.new(deck, 100, 150)
113
115
  expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
114
- card.text('foo', 'Sans 12', nil, '#abc',
116
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
115
117
  10, 15, 20, 50,
116
118
  nil, false, :word_char, false,
117
119
  1.0, :left, :top, nil, 0.0)
@@ -120,7 +122,7 @@ describe Squib::Card, '#text' do
120
122
  it 'sets wrap to word_char with true' do
121
123
  card = Squib::Card.new(deck, 100, 150)
122
124
  expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
123
- card.text('foo', 'Sans 12', nil, '#abc',
125
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
124
126
  10, 15, 20, 50,
125
127
  nil, false, true, false,
126
128
  1.0, :left, :top, nil, 0.0)
@@ -129,7 +131,7 @@ describe Squib::Card, '#text' do
129
131
  it 'sets ellipsize to start properly' do
130
132
  card = Squib::Card.new(deck, 100, 150)
131
133
  expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
132
- card.text('foo', 'Sans 12', nil, '#abc',
134
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
133
135
  10, 15, 20, 50,
134
136
  nil, false, true, :start,
135
137
  1.0, :left, :top, nil, 0.0)
@@ -138,7 +140,7 @@ describe Squib::Card, '#text' do
138
140
  it 'sets ellipsize to middle properly' do
139
141
  card = Squib::Card.new(deck, 100, 150)
140
142
  expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
141
- card.text('foo', 'Sans 12', nil, '#abc',
143
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
142
144
  10, 15, 20, 50,
143
145
  nil, false, true, 'middle',
144
146
  1.0, :left, :top, nil, 0.0)
@@ -51,8 +51,10 @@ describe "Squib samples" do
51
51
  basic.rb
52
52
  cairo_access.rb
53
53
  csv_import.rb
54
+ config_text_markup.rb
54
55
  custom_config.rb
55
56
  draw_shapes.rb
57
+ embed_text.rb
56
58
  excel.rb
57
59
  gradients.rb
58
60
  hello_world.rb
data/spec/spec_helper.rb CHANGED
@@ -55,10 +55,13 @@ end
55
55
  # Build a mock cairo instance that allows basically any method
56
56
  # and logs that call to the string buffer
57
57
  def mock_cairo(strio)
58
- cxt = double(Cairo::Context)
59
- surface = double(Cairo::ImageSurface)
60
- pango = double(Pango::Layout)
61
- font = double(Pango::FontDescription)
58
+ cxt = double(Cairo::Context)
59
+ surface = double(Cairo::ImageSurface)
60
+ pango = double(Pango::Layout)
61
+
62
+ font = double(Pango::FontDescription)
63
+ iter = double('pango_iter')
64
+ pango_cxt = double('pango_cxt')
62
65
  allow(Squib.logger).to receive(:warn) {}
63
66
  allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
64
67
  allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
@@ -67,9 +70,19 @@ def mock_cairo(strio)
67
70
  allow(Cairo::Context).to receive(:new).and_return(cxt)
68
71
  allow(cxt).to receive(:create_pango_layout).and_return(pango)
69
72
  allow(cxt).to receive(:target).and_return(surface)
73
+ allow(cxt).to receive(:matrix).and_return(Cairo::Matrix.new(1,0,0,1,0,0))
70
74
  allow(pango).to receive(:height).and_return(25)
71
75
  allow(pango).to receive(:width).and_return(25)
76
+ allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0,0,0,0))
72
77
  allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0,0,0,0)]*2)
78
+ allow(pango).to receive(:iter).and_return(iter)
79
+ allow(pango).to receive(:alignment).and_return(Pango::Layout::Alignment::LEFT)
80
+ allow(pango).to receive(:text).and_return("foo")
81
+ allow(pango).to receive(:context).and_return(pango_cxt)
82
+ allow(pango_cxt).to receive(:font_options=)
83
+ allow(iter).to receive(:next_char!).and_return(false)
84
+ allow(iter).to receive(:char_extents).and_return(Pango::Rectangle.new(5,5,5,5))
85
+ allow(iter).to receive(:index).and_return(1000)
73
86
  allow(Pango::FontDescription).to receive(:new).and_return(font)
74
87
  allow(Cairo::PDFSurface).to receive(:new).and_return(nil)
75
88
 
@@ -77,7 +90,7 @@ def mock_cairo(strio)
77
90
  update_pango_layout width height show_pango_layout rounded_rectangle
78
91
  set_line_width stroke fill set_source scale render_rsvg_handle circle
79
92
  triangle line_to operator= show_page clip transform mask rectangle
80
- reset_clip antialias=).each do |m|
93
+ reset_clip antialias= curve_to matrix=).each do |m|
81
94
  allow(cxt).to receive(m) { |*args| strio << scrub_hex("cairo: #{m}(#{args})\n") }
82
95
  end
83
96
 
@@ -94,6 +107,10 @@ def mock_cairo(strio)
94
107
  allow(surface).to receive(m) { |*args| strio << scrub_hex("surface: #{m}(#{args})\n") }
95
108
  end
96
109
 
110
+ %w(next_char!).each do |m|
111
+ allow(iter).to receive(m) { |*args| strio << scrub_hex("pango_iter: #{m}(#{args})\n") }
112
+ end
113
+
97
114
  end
98
115
 
99
116
  # Refine Squib to allow setting the logger and progress bar
data/squib.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'rspec', '~> 3.2'
40
40
  spec.add_development_dependency 'redcarpet', '~> 3.1'
41
41
  spec.add_development_dependency 'github-markup', '~> 1.3'
42
- spec.add_development_dependency 'yard', '~> 0.8'
42
+ # spec.add_development_dependency 'yard', '~> 0.8'
43
43
  spec.add_development_dependency 'coveralls'
44
44
  spec.add_development_dependency 'byebug'
45
45
 
@@ -0,0 +1,49 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "follow_symlinks": true,
6
+ "path": "."
7
+ }
8
+ ],
9
+ "build_systems":
10
+ [
11
+ {
12
+ "name": "rake",
13
+ "shell_cmd": "rake",
14
+ },
15
+ {
16
+ "name": "rake run[text_options]",
17
+ "shell_cmd": "rake run[text_options]",
18
+ },
19
+ {
20
+ "name": "rake run[embed_text]",
21
+ "shell_cmd": "rake run[embed_text]",
22
+ },
23
+ {
24
+ "name": "rake run[draw_shapes]",
25
+ "shell_cmd": "rake run[draw_shapes]",
26
+ },
27
+ {
28
+ "name": "rake run[config_text_markup]",
29
+ "shell_cmd": "rake run[config_text_markup]",
30
+ },
31
+ {
32
+ "name": "rspec spec/samples/samples_regression_spec.rb",
33
+ "shell_cmd": "rspec spec/samples/samples_regression_spec.rb",
34
+ "working_dir": "${project_path:${folder}}"
35
+ },
36
+ {
37
+ "name": "rspec spec/args/typographer_spec.rb",
38
+ "shell_cmd": "rspec spec/args/typographer_spec.rb",
39
+ "working_dir": "${project_path:${folder}}"
40
+ },
41
+ {
42
+ "name": "rspec spec/graphics/graphics_text_spec.rb",
43
+ "shell_cmd": "rspec spec/graphics/graphics_text_spec.rb",
44
+ "working_dir": "${project_path:${folder}}"
45
+ },
46
+
47
+ ],
48
+
49
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Meneely
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cairo
@@ -164,20 +164,6 @@ dependencies:
164
164
  - - ~>
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.3'
167
- - !ruby/object:Gem::Dependency
168
- name: yard
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ~>
172
- - !ruby/object:Gem::Version
173
- version: '0.8'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ~>
179
- - !ruby/object:Gem::Version
180
- version: '0.8'
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: coveralls
183
169
  requirement: !ruby/object:Gem::Requirement
@@ -218,9 +204,11 @@ extra_rdoc_files:
218
204
  - samples/basic.rb
219
205
  - samples/cairo_access.rb
220
206
  - samples/colors.rb
207
+ - samples/config_text_markup.rb
221
208
  - samples/csv_import.rb
222
209
  - samples/custom_config.rb
223
210
  - samples/draw_shapes.rb
211
+ - samples/embed_text.rb
224
212
  - samples/excel.rb
225
213
  - samples/gradients.rb
226
214
  - samples/hello_world.rb
@@ -265,7 +253,9 @@ files:
265
253
  - lib/squib/api/settings.rb
266
254
  - lib/squib/api/shapes.rb
267
255
  - lib/squib/api/text.rb
256
+ - lib/squib/api/text_embed.rb
268
257
  - lib/squib/api/units.rb
258
+ - lib/squib/args/typographer.rb
269
259
  - lib/squib/args/unit_conversion.rb
270
260
  - lib/squib/card.rb
271
261
  - lib/squib/commands/new.rb
@@ -303,6 +293,9 @@ files:
303
293
  - samples/basic.rb
304
294
  - samples/cairo_access.rb
305
295
  - samples/colors.rb
296
+ - samples/config_disable_quotes.yml
297
+ - samples/config_text_markup.rb
298
+ - samples/config_text_markup.yml
306
299
  - samples/csv_import.rb
307
300
  - samples/custom-config.yml
308
301
  - samples/custom-layout.yml
@@ -311,6 +304,7 @@ files:
311
304
  - samples/customconfig-imgdir/shiny-purse2.png
312
305
  - samples/customconfig-imgdir/spanner2.svg
313
306
  - samples/draw_shapes.rb
307
+ - samples/embed_text.rb
314
308
  - samples/excel.rb
315
309
  - samples/glass-heart.svg
316
310
  - samples/gradients.rb
@@ -335,6 +329,7 @@ files:
335
329
  - spec/api/api_data_spec.rb
336
330
  - spec/api/api_image_spec.rb
337
331
  - spec/api/api_text_spec.rb
332
+ - spec/args/typographer_spec.rb
338
333
  - spec/args/unit_conversion_spec.rb
339
334
  - spec/commands/new_spec.rb
340
335
  - spec/data/csv/basic.csv
@@ -359,9 +354,11 @@ files:
359
354
  - spec/data/samples/autoscale_font.rb.txt
360
355
  - spec/data/samples/basic.rb.txt
361
356
  - spec/data/samples/cairo_access.rb.txt
357
+ - spec/data/samples/config_text_markup.rb.txt
362
358
  - spec/data/samples/csv_import.rb.txt
363
359
  - spec/data/samples/custom_config.rb.txt
364
360
  - spec/data/samples/draw_shapes.rb.txt
361
+ - spec/data/samples/embed_text.rb.txt
365
362
  - spec/data/samples/excel.rb.txt
366
363
  - spec/data/samples/gradients.rb.txt
367
364
  - spec/data/samples/hello_world.rb.txt
@@ -387,6 +384,7 @@ files:
387
384
  - spec/samples/samples_regression_spec.rb
388
385
  - spec/spec_helper.rb
389
386
  - squib.gemspec
387
+ - squib.sublime-project
390
388
  homepage: https://github.com/andymeneely/squib
391
389
  licenses:
392
390
  - MIT
@@ -416,6 +414,7 @@ test_files:
416
414
  - spec/api/api_data_spec.rb
417
415
  - spec/api/api_image_spec.rb
418
416
  - spec/api/api_text_spec.rb
417
+ - spec/args/typographer_spec.rb
419
418
  - spec/args/unit_conversion_spec.rb
420
419
  - spec/commands/new_spec.rb
421
420
  - spec/data/csv/basic.csv
@@ -440,9 +439,11 @@ test_files:
440
439
  - spec/data/samples/autoscale_font.rb.txt
441
440
  - spec/data/samples/basic.rb.txt
442
441
  - spec/data/samples/cairo_access.rb.txt
442
+ - spec/data/samples/config_text_markup.rb.txt
443
443
  - spec/data/samples/csv_import.rb.txt
444
444
  - spec/data/samples/custom_config.rb.txt
445
445
  - spec/data/samples/draw_shapes.rb.txt
446
+ - spec/data/samples/embed_text.rb.txt
446
447
  - spec/data/samples/excel.rb.txt
447
448
  - spec/data/samples/gradients.rb.txt
448
449
  - spec/data/samples/hello_world.rb.txt