ruby_svg_light 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/examples/shapes.rb CHANGED
@@ -9,6 +9,7 @@ canvas.circle(40,40,20)
9
9
  canvas.rectangle(80,20,40,40)
10
10
  canvas.line(20,80,100,0)
11
11
  canvas.line(20,105,100,0)
12
+ canvas.ellipse(200, 200, 20, 30)
12
13
 
13
14
  options = {:font_size=>'12px'}
14
15
  canvas.options(options)
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubySVGLight
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
 
5
5
  class Document
6
6
  attr_reader :body
@@ -26,10 +26,10 @@ module RubySVGLight
26
26
  text = %{<?xml version="1.0" encoding="UTF-8" standalone="no"?>
27
27
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
28
28
 
29
- <svg
29
+ <svg
30
30
  width="100%"
31
31
  height="100%"
32
- version="1.1"
32
+ version="1.1"
33
33
  xmlns="http://www.w3.org/2000/svg">
34
34
  }
35
35
  end
@@ -40,14 +40,14 @@ module RubySVGLight
40
40
 
41
41
 
42
42
 
43
- ## Drawing methodds
43
+ ## Drawing methodds
44
44
  def circle(x=0, y=0, radius=10, opts={})
45
45
  local_options = calc_local_options(opts)
46
46
  text = %{<circle
47
- cx="#{x}" cy="#{y}"
48
- r="#{radius}"
47
+ cx="#{x}" cy="#{y}"
48
+ r="#{radius}"
49
49
  stroke="#{local_options[:stroke]}"
50
- stroke-width="#{local_options[:stroke_width]}"
50
+ stroke-width="#{local_options[:stroke_width]}"
51
51
  fill="#{local_options[:fill]}"/>
52
52
  }
53
53
 
@@ -59,7 +59,7 @@ module RubySVGLight
59
59
  def line(x,y,w,h, opts={})
60
60
  local_options = calc_local_options(opts)
61
61
  text = %{<line
62
- x1="#{x}" y1="#{y}"
62
+ x1="#{x}" y1="#{y}"
63
63
  x2="#{x+w}" y2="#{y+h}"
64
64
  stroke="#{local_options[:stroke]}"
65
65
  stroke-width="#{local_options[:stroke_width]}"
@@ -85,6 +85,20 @@ module RubySVGLight
85
85
  @body << text
86
86
  end
87
87
 
88
+ def ellipse(x,y,rx,ry, opts={})
89
+ local_options = calc_local_options(opts)
90
+ text = %{<ellipse
91
+ cx="#{x}" cy="#{y}"
92
+ rx="#{rx}" ry="#{ry}"
93
+ fill="#{local_options[:fill]}"
94
+ stroke="#{local_options[:stroke]}"
95
+ stroke-width="#{local_options[:stroke_width]}"
96
+ />
97
+ }
98
+ update_size(x+rx, y+ry)
99
+ @body << text
100
+ end
101
+
88
102
  def text(x,y, input_text, opts={})
89
103
  centre_text = "text-anchor:middle; dominant-baseline:central;"
90
104
  local_options = calc_local_options(opts)
@@ -100,11 +114,11 @@ module RubySVGLight
100
114
  >#{input_text}
101
115
  </text>
102
116
  }
103
- #{centre_text}"
104
- # xml:space="preserve"
105
- #Do not know height or width of text only the anchor
106
- update_size(x, y)
107
- @body << text
117
+ #{centre_text}"
118
+ # xml:space="preserve"
119
+ #Do not know height or width of text only the anchor
120
+ update_size(x, y)
121
+ @body << text
108
122
  end
109
123
 
110
124
  def options(opts={})
@@ -112,7 +126,7 @@ module RubySVGLight
112
126
  @options[key] = value
113
127
  end
114
128
 
115
- #return
129
+ #return
116
130
  @options
117
131
  end
118
132
 
@@ -135,7 +149,7 @@ module RubySVGLight
135
149
 
136
150
 
137
151
  def components_only_to_s
138
- text = ""
152
+ text = ""
139
153
  @body.each do |section|
140
154
  text << section
141
155
  end
@@ -146,7 +160,7 @@ module RubySVGLight
146
160
 
147
161
  # To string includes header and footers
148
162
  def to_s
149
- text = ""
163
+ text = ""
150
164
  text << self.header
151
165
  @body.each do |section|
152
166
  text << section
@@ -1,12 +1,11 @@
1
-
2
- require File.join( '..', 'lib', 'ruby_svg_light')
1
+ require 'spec_helper'
3
2
 
4
3
  def check_width_height(svg, width, height)
5
4
  svg.width.should == width
6
5
  svg.height.should == height
7
6
  end
8
7
 
9
- describe RubySVGLight, "RubySVGLight" do
8
+ describe RubySVGLight do
10
9
  it "Check width calculations, objects from origin" do
11
10
  canvas = RubySVGLight::Document.new()
12
11
  check_width_height(canvas, 0, 0)
@@ -19,6 +18,9 @@ describe RubySVGLight, "RubySVGLight" do
19
18
 
20
19
  canvas.circle(0,0,100)
21
20
  check_width_height(canvas, 100, 100)
21
+
22
+ canvas.ellipse(0, 0, 300, 400)
23
+ check_width_height(canvas, 300, 400)
22
24
  end
23
25
 
24
26
  it "Smaller new component should not shrink size" do
@@ -34,6 +36,9 @@ describe RubySVGLight, "RubySVGLight" do
34
36
 
35
37
  canvas.rectangle(0,0,10,20)
36
38
  check_width_height(canvas, 100, 100)
39
+
40
+ canvas.ellipse(0, 0, 10, 20)
41
+ check_width_height(canvas, 100, 100)
37
42
  end
38
43
 
39
44
  it "Check width calculations, objects not on origin" do
@@ -48,6 +53,9 @@ describe RubySVGLight, "RubySVGLight" do
48
53
 
49
54
  canvas.circle(10,15,100)
50
55
  check_width_height(canvas, 110, 115)
56
+
57
+ canvas.ellipse(100, 200, 30, 50)
58
+ check_width_height(canvas, 130, 250)
51
59
  end
52
60
  end
53
61
 
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rspec'
4
+ require 'ruby_svg_light'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_svg_light
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morgan Prior
@@ -35,6 +35,7 @@ files:
35
35
  - lib/ruby_svg.rb.original
36
36
  - lib/ruby_svg_light.rb
37
37
  - spec/ruby_svg_light_width_spec.rb
38
+ - spec/spec_helper.rb
38
39
  has_rdoc: true
39
40
  homepage: http://amaras-tech.co.uk/software/RubySVGLight
40
41
  licenses: []