hershey 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b66efface3022d72fefa4018088205dac320f54
4
- data.tar.gz: 44954d2d7e45d07e1e336b308edf6f90e6964e46
3
+ metadata.gz: c9c688d14b0bd9107c74e8769d6768d34f636c71
4
+ data.tar.gz: 44f04e9cae8c79a34905e9625c404fbd80148d63
5
5
  SHA512:
6
- metadata.gz: b956249989149548c9fcd40c1c04d56039484527766385489e0a90122f74372d2821d80d368b4d9c5e0f4f87c0d0caec48143c440cfe4b69e8b768457955fb9b
7
- data.tar.gz: 400c6362d3ed6ae09c09237c9cb4225904123fd48303eb6af941bdf4a8ed88cbb83cef3d2ccb3eff7b5d3c8a46a9fd37e778167257e94cc6d2678fcd23a52cb5
6
+ metadata.gz: 8a34513f559fd08ccaede631da951339af6e4088e3d59caffca460fc6e69e4d391fab62b088b3bc55fa2aad252f1aba348bc149df1684794e244933176e071dd
7
+ data.tar.gz: 1e3b71b4557c0be9c62a65d24739e8934c025bb357df63a409fece7a22039ffd1840705cc74ffaa38b411a6d0e26eaedf04272187616ef5c19d879cf6cc27dac
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order rand
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
data/bin/hershey CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'hershey'
4
4
 
5
5
  file = ARGV.shift
6
- width = ARGV.shift
6
+ width = ARGV.shift.to_i
7
7
  text = ARGV.join(' ')
8
8
 
9
9
  open(file, 'w') {|f| f.write(Hershey.svg(text, width: width))}
data/hershey.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", '~> 3.1.0'
23
+ spec.add_development_dependency "rspec", '~> 3.1'
24
24
 
25
25
  spec.required_ruby_version = '>= 2.0.0'
26
26
  end
@@ -24,9 +24,21 @@ module Hershey
24
24
  end
25
25
 
26
26
  def <<(text)
27
- text.split(' ').each do |word|
28
- @words << Word.new(word, font: @font)
27
+ word = ""
28
+ text.each_char do |c|
29
+ if c == " "
30
+ @words << :space
31
+ @words << Word.new(word, font: @font)
32
+ word = ''
33
+ elsif c == "\n"
34
+ @words << :break
35
+ @words << Word.new(word, font: @font)
36
+ word = ''
37
+ else
38
+ word << c
39
+ end
29
40
  end
41
+ @words << Word.new(word, font: @font) unless word == ''
30
42
  end
31
43
 
32
44
  alias_method :write, :<<
@@ -44,13 +56,21 @@ module Hershey
44
56
  current_offset = SIDE
45
57
  @svg << %Q{<g transform="translate(#{SIDE},#{@line})">}
46
58
  @words.each do |word|
47
- if word.spacing + current_offset > @width
59
+ if word.is_a?(Word)
60
+ if word.spacing + current_offset > @width
61
+ @line += BUFFER * 2
62
+ current_offset = SIDE
63
+ @svg << %Q{</g><g transform="translate(#{SIDE},#{@line})">}
64
+ end
65
+ @svg << word.to_path(current_offset)
66
+ current_offset += word.spacing
67
+ elsif word == :space
68
+ current_offset += space
69
+ elsif word == :break
48
70
  @line += BUFFER * 2
49
71
  current_offset = SIDE
50
72
  @svg << %Q{</g><g transform="translate(#{SIDE},#{@line})">}
51
73
  end
52
- @svg << word.to_path(current_offset)
53
- current_offset += word.spacing + space
54
74
  end
55
75
  @svg << "</g></svg>"
56
76
  @svg.gsub!(HEIGHT_STRING, (@line + BUFFER).to_s)
@@ -1,3 +1,3 @@
1
1
  module Hershey
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hershey::Character do
4
+ let (:a) {Hershey::Character.new('a', font: :futural)}
5
+
6
+ describe "path" do
7
+ it "should be predictable" do
8
+ a.to_path(0).should == "<path stroke=\"black\" fill=\"none\" d=\"M6 -5 L6 9 M6 -2 L4 -4 L2 -5 L-1 -5 L-3 -4 L-5 -2 L-6 1 L-6 3 L-5 6 L-3 8 L-1 9 L2 9 L4 8 L6 6\" transform=\"translate(9,0)\"></path>"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hershey::Document do
4
+ it "should produce same output" do
5
+ Hershey.svg("It's all OKAY!", font: :futural, width: 500).should == File.read("spec/ex.svg")
6
+ end
7
+ end
data/spec/ex.svg ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg width="500" height="40" version="1.1"
5
+ xmlns="http://www.w3.org/2000/svg">
6
+ <g transform="translate(10,20)"><g transform="translate(26,0)"><path stroke="black" fill="none" d="M0 -12 L0 9" transform="translate(4,0)"></path><path stroke="black" fill="none" d="M0 -12 L0 5 L1 8 L3 9 L5 9 M-3 -5 L4 -5" transform="translate(13,0)"></path><path stroke="black" fill="none" d="M0 -10 L-1 -11 L0 -12 L1 -11 L1 -9 L0 -7 L-1 -6" transform="translate(25,0)"></path><path stroke="black" fill="none" d="M6 -2 L5 -4 L2 -5 L-1 -5 L-4 -4 L-5 -2 L-4 0 L-2 1 L3 2 L5 3 L6 5 L6 6 L5 8 L2 9 L-1 9 L-4 8 L-5 6" transform="translate(38,0)"></path></g><g transform="translate(89,0)"><path stroke="black" fill="none" d="M6 -5 L6 9 M6 -2 L4 -4 L2 -5 L-1 -5 L-3 -4 L-5 -2 L-6 1 L-6 3 L-5 6 L-3 8 L-1 9 L2 9 L4 8 L6 6" transform="translate(9,0)"></path><path stroke="black" fill="none" d="M0 -12 L0 9" transform="translate(23,0)"></path><path stroke="black" fill="none" d="M0 -12 L0 9" transform="translate(31,0)"></path></g><g transform="translate(124,0)"><path stroke="black" fill="none" d="M-2 -12 L-4 -11 L-6 -9 L-7 -7 L-8 -4 L-8 1 L-7 4 L-6 6 L-4 8 L-2 9 L2 9 L4 8 L6 6 L7 4 L8 1 L8 -4 L7 -7 L6 -9 L4 -11 L2 -12 L-2 -12" transform="translate(11,0)"></path><path stroke="black" fill="none" d="M-7 -12 L-7 9 M7 -12 L-7 2 M-2 -3 L7 9" transform="translate(33,0)"></path><path stroke="black" fill="none" d="M0 -12 L-8 9 M0 -12 L8 9 M-5 2 L5 2" transform="translate(52,0)"></path><path stroke="black" fill="none" d="M-8 -12 L0 -2 L0 9 M8 -12 L0 -2" transform="translate(70,0)"></path><path stroke="black" fill="none" d="M0 -12 L0 2 M0 7 L-1 8 L0 9 L1 8 L0 7" transform="translate(84,0)"></path></g></g></svg>
data/spec/font_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ describe Hershey::FONTS do
2
+ it "should have all the keys" do
3
+ Hershey::FONTS.keys.sort.should == [:astrology, :cursive, :cyrillic,
4
+ :futural, :futuram, :gothiceng, :gothicger, :gothicita, :greek,
5
+ :japanese, :markers, :mathlow, :mathupp, :meteorology, :music, :scriptc,
6
+ :scripts, :symbolic, :timesg, :timesi, :timesib, :timesr, :timesrb
7
+ ]
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hershey do
4
+ it "should create the same output as a normal call" do
5
+ doc = Hershey::Document.new
6
+ doc.write("hi")
7
+ Hershey.svg("hi").should == doc.svg
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'hershey' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |c|
8
+ c.syntax = :should
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hershey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winston Durand
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0
47
+ version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.0
54
+ version: '3.1'
55
55
  description:
56
56
  email:
57
57
  - me@winstondurand.com
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
+ - ".rspec"
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -74,6 +75,12 @@ files:
74
75
  - lib/hershey/page.rb
75
76
  - lib/hershey/version.rb
76
77
  - lib/hershey/word.rb
78
+ - spec/character_spec.rb
79
+ - spec/document_spec.rb
80
+ - spec/ex.svg
81
+ - spec/font_spec.rb
82
+ - spec/hershey_spec.rb
83
+ - spec/spec_helper.rb
77
84
  homepage: https://github.com/R167/hershey
78
85
  licenses:
79
86
  - MIT
@@ -98,4 +105,10 @@ rubygems_version: 2.2.2
98
105
  signing_key:
99
106
  specification_version: 4
100
107
  summary: Generates an SVG with text using the Hershey Vector Font
101
- test_files: []
108
+ test_files:
109
+ - spec/character_spec.rb
110
+ - spec/document_spec.rb
111
+ - spec/ex.svg
112
+ - spec/font_spec.rb
113
+ - spec/hershey_spec.rb
114
+ - spec/spec_helper.rb