savage 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +79 -7
  2. data/VERSION +1 -1
  3. data/savage.gemspec +2 -2
  4. metadata +3 -3
data/README.rdoc CHANGED
@@ -1,16 +1,88 @@
1
1
  = Savage
2
2
 
3
- A little gem for extracting and manipulating SVG vector path data.
3
+ A little gem for extracting and manipulating SVG vector path data, Savage will make your life easier when it comes time to dynamically draw new and manipulate existing SVG paths. No more wacky regex to capture those cryptic path data strings; just pass the whole "d" attribute into Savage's parser, et voilá: You'll be given an instance of Savage::Path, replete with an array of subpaths split on the "move to" commands (to better help with those pesky winding issues). In turn, each subpath contains its own array of directions that can be swapped around, reconfigured, and otherwise manipulated to your heart's content in a truly human-readable way.
4
+
5
+ == Usage
6
+
7
+ <b>Parsing existing data</b>
8
+
9
+ Easy-peasy Japanesey. Just take a look at the below:
10
+
11
+ path = Savage::Parser.parse my_path_data_string
12
+ path.subpaths # [subpath_1, subpath_2, ... subpath_n]
13
+ path.subpaths.last.directions # [direction_1, direction_2, ... direction_n]
14
+
15
+ Once extracted, you can manipulate, add, and remove the subpaths and directions as you see fit. See below for instructions on using the various direction types
16
+
17
+ <b>Creating from scratch</b>
18
+
19
+ What if you want to roll your own from the get-go? No problem:
20
+
21
+ path = Savage::Path.new do |p|
22
+ p.move_to 100, 200
23
+ p.line_to 300, 400
24
+ p.horizontal_to 500
25
+ p.close_path
26
+ end
27
+
28
+ We'll learn more about the actual drawing methods here shortly, but suffice it to say they are provided both as methods on the constructor block parameter for the sake of your visual organization, and the path itself after construction, as below:
29
+
30
+ path = Savage::Path.new
31
+ path.move_to 100, 200
32
+ path.line_to 300, 400
33
+ path.horizontal_to 500
34
+ path.close_path
35
+
36
+ <b>Drawing with Savage</b>
37
+
38
+ So what are the different directions we can give our virtual pen? Here I'll refer you first to the SVG 1.1 specification by our friends down at the W3C, as they can describe all the specifics much better than I: http://www.w3.org/TR/SVG/paths.html#PathData. Each "command" listed in that section has an analog method on the Savage::SubPath class as well as the Savage::Path class (calling one of the methods on an instance of the Savage::Path class actually just delegates the call to the last SubPath in that path's selection of subpaths). Every parameter of these methods is expected to be a Numeric except where noted otherwise. The methods are as follows:
39
+
40
+ * <b>path.move_to(target_x, target_y)</b> - Move the 'pen' to the specified coordinates on the 'canvas' without drawing anything. Note that you can only call this method on a subpath if it's otherwise empty. Most of the time, just call this on an instance of the Path class, which will actually create a new subpath for you to continue drawing into
41
+ * <b>path.close_path()</b> - Draw a straight line from the current position to the coordinates of the start of the current subpath
42
+ * <b>path.line_to(target_x, target_y)</b> - Draw a straight line from the current position to the specified coordinates
43
+ * <b>path.horizontal_to(target_x)</b> - Draw a straight horizontal line to the provided x coordinate
44
+ * <b>path.vertical_to(target_y)</b> - Draw a straight vertical line to the provided y coordinate
45
+ * <b>path.cubic_curve_to(control_1_x, control_1_y, control_2_x, control_2_y, target_x, target_y)</b> - Draw a cubic Bézier curve from the current position to the target coordinates (target_x/y) using the control points specified - see the SVG specification referred to above for more info
46
+ * <b>path.cubic_curve_to(control_2_x, control_2_y, target_x, target_y)</b> - Shorthand cubic Bézier curve; assumes continuation of previous curve. See SVG specification
47
+ * <b>path.quadratic_curve_to(control_x, control_y, target_x, target_y)</b> - Draw a quadratic Bézier curve from the current position to the target coordinates (target_x/y) using the control point specified - see the SVG specification referred to above for more info
48
+ * <b>path.quadratic_curve_to(target_x, target_y)</b> - Shorthand quadratic Bézier curve; assumes continuation of previous curve. See SVG specification
49
+ * <b>path.arc_to(radius_x,radius_y,rotation,large_arc_flag,sweep_flag,target_x,target_y)</b> - This is a doozy and complicated as sin to explain, so we'll let the W3C do it for us - see the spec. Otherwise, be aware that the large_arc_flag and sweep_flag arguments are expected to be boolean values, not Numeric.
50
+
51
+ There you have it, pretty much right out of the book. One thing to keep in mind is that all of these methods use ABSOLUTE coordinates by default; if you want to use relative coordinates (based on the current position of the 'pen'), just pass false as the final argument to any of them:
52
+
53
+ path.line_to 100, 200, false
54
+
55
+ Each of these commands just creates a new instance of the appropriate subclass of the Savage::Direction class and pushes it onto the end of the directions list in question. Don't necessarily want to draw onto the end? Just create your own instance using the standard constructor and insert it wherever it butters your biscuit so to do:
56
+
57
+ direction = Savage::Directions::LineTo.new(100,200)
58
+ subpath.directions.insert(3,direction)
59
+
60
+ Did you mess up before and need to change a directions coordinates after you drew it (or, more likely, after you parsed it out of some pre-existing data)? No problem:
61
+
62
+ direction = Savage::Directions::LineTo.new(100,200)
63
+ direction.target.x = 234
64
+
65
+ As you may have guessed, Savage::Path#subpaths and Savage::SubPath#directions are both just good old-fashioned arrays, so you can fiddle with them using all your favorite Enumerable tricks as always.
66
+
67
+ <b>Turning it back into a path data string</b>
68
+
69
+ Bang!:
70
+
71
+ path.to_command # => 'M100 200-342 43.5Q-34.88 123.9 13-532' or whatever...
72
+
73
+ Note that the #to_command method exists on Savage::Path, Savage::SubPath, and each subclass of Savage::Direction, so you can be as fine-grained with it as needed.
74
+
75
+ == Issues / Feature Requests
76
+
77
+ I have no doubt that will be some problems with this thing, as well as features missing that some of you fine folks might want. Please, please, please check Github's issue-tracking system to see if a ticket for the problem has already been submitted, or create a new one if not. I'll check the issues listed therein regularly, but you email me directly at your own risk (and by risk, I mean risk of not receiving a reply). :)
4
78
 
5
79
  == Note on Patches/Pull Requests
6
80
 
7
81
  * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add specs for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
82
+ * Make your feature addition or bug fix. I very much prefer feature-specific branches.
83
+ * Add specs for it. This is important so I don't break it in a future version unintentionally, which I can guarantee I will do.
84
+ * Commit. Do not mess with rakefile, version, or history, please.
85
+ * Send me a pull request - again, bonus points for topic branches.
14
86
 
15
87
  == Copyright
16
88
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
data/savage.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{savage}
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Holland"]
12
- s.date = %q{2010-05-02}
12
+ s.date = %q{2010-05-03}
13
13
  s.description = %q{A little gem for extracting and manipulating SVG vector path data.}
14
14
  s.email = %q{jeremy@jeremypholland.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -3,10 +3,10 @@ name: savage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 2
8
8
  - 0
9
- version: 0.2.0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremy Holland
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-02 00:00:00 -05:00
17
+ date: 2010-05-03 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency