text2path 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +11 -1
- data/lib/text2path/glyph.rb +1 -3
- data/lib/text2path/svg_font.rb +13 -3
- data/lib/text2path/version.rb +1 -1
- metadata +2 -47
- data/lib/ext/savage/LICENSE +0 -20
- data/lib/ext/savage/README.rdoc +0 -108
- data/lib/ext/savage/Rakefile +0 -39
- data/lib/ext/savage/VERSION +0 -1
- data/lib/ext/savage/lib/savage.rb +0 -3
- data/lib/ext/savage/lib/savage/direction.rb +0 -42
- data/lib/ext/savage/lib/savage/direction_proxy.rb +0 -19
- data/lib/ext/savage/lib/savage/directions/arc_to.rb +0 -29
- data/lib/ext/savage/lib/savage/directions/close_path.rb +0 -18
- data/lib/ext/savage/lib/savage/directions/coordinate_target.rb +0 -17
- data/lib/ext/savage/lib/savage/directions/cubic_curve_to.rb +0 -40
- data/lib/ext/savage/lib/savage/directions/horizontal_to.rb +0 -19
- data/lib/ext/savage/lib/savage/directions/line_to.rb +0 -15
- data/lib/ext/savage/lib/savage/directions/move_to.rb +0 -15
- data/lib/ext/savage/lib/savage/directions/point_target.rb +0 -17
- data/lib/ext/savage/lib/savage/directions/quadratic_curve_to.rb +0 -44
- data/lib/ext/savage/lib/savage/directions/vertical_to.rb +0 -19
- data/lib/ext/savage/lib/savage/parser.rb +0 -108
- data/lib/ext/savage/lib/savage/path.rb +0 -50
- data/lib/ext/savage/lib/savage/sub_path.rb +0 -54
- data/lib/ext/savage/lib/savage/transformable.rb +0 -48
- data/lib/ext/savage/lib/savage/utils.rb +0 -7
- data/lib/ext/savage/savage.gemspec +0 -80
- data/lib/ext/savage/spec/savage/directions/arc_to_spec.rb +0 -97
- data/lib/ext/savage/spec/savage/directions/close_path_spec.rb +0 -30
- data/lib/ext/savage/spec/savage/directions/cubic_curve_to_spec.rb +0 -146
- data/lib/ext/savage/spec/savage/directions/horizontal_to_spec.rb +0 -10
- data/lib/ext/savage/spec/savage/directions/line_to_spec.rb +0 -10
- data/lib/ext/savage/spec/savage/directions/move_to_spec.rb +0 -10
- data/lib/ext/savage/spec/savage/directions/point_spec.rb +0 -12
- data/lib/ext/savage/spec/savage/directions/quadratic_curve_spec.rb +0 -123
- data/lib/ext/savage/spec/savage/directions/vertical_to_spec.rb +0 -10
- data/lib/ext/savage/spec/savage/parser_spec.rb +0 -250
- data/lib/ext/savage/spec/savage/path_spec.rb +0 -105
- data/lib/ext/savage/spec/savage/sub_path_spec.rb +0 -195
- data/lib/ext/savage/spec/savage/transformable_spec.rb +0 -62
- data/lib/ext/savage/spec/savage_spec.rb +0 -5
- data/lib/ext/savage/spec/shared/command.rb +0 -13
- data/lib/ext/savage/spec/shared/coordinate_target.rb +0 -36
- data/lib/ext/savage/spec/shared/direction.rb +0 -29
- data/lib/ext/savage/spec/shared/point_target.rb +0 -45
- data/lib/ext/savage/spec/spec_helper.rb +0 -36
- data/libpeerconnection.log +0 -0
- data/out.svg +0 -1
- data/test.rb +0 -6
@@ -1,17 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class CoordinateTarget < Direction
|
4
|
-
|
5
|
-
attr_accessor :target
|
6
|
-
|
7
|
-
def initialize(target, absolute=true)
|
8
|
-
@target = target
|
9
|
-
super(absolute)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_a
|
13
|
-
[command_code, @target]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class CubicCurveTo < QuadraticCurveTo
|
4
|
-
attr_accessor :control_1
|
5
|
-
|
6
|
-
def initialize(*args)
|
7
|
-
raise ArgumentError if args.length < 4
|
8
|
-
case args.length
|
9
|
-
when 4
|
10
|
-
super(args[0],args[1],args[2],args[3],true)
|
11
|
-
when 5
|
12
|
-
raise ArgumentError if args[4].kind_of?(Numeric)
|
13
|
-
super(args[0],args[1],args[2],args[3],args[4])
|
14
|
-
when 6
|
15
|
-
@control_1 = Point.new(args[0],args[1])
|
16
|
-
super(args[2],args[3],args[4],args[5],true)
|
17
|
-
when 7
|
18
|
-
@control_1 = Point.new(args[0],args[1])
|
19
|
-
super(args[2],args[3],args[4],args[5],args[6])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_a
|
24
|
-
if @control_1
|
25
|
-
[command_code, @control_1.x, @control_1.y, @control.x, @control.y, @target.x, @target.y]
|
26
|
-
else
|
27
|
-
[command_code, @control.x, @control.y, @target.x, @target.y]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def control_2; @control; end
|
32
|
-
def control_2=(value); @control = value; end
|
33
|
-
|
34
|
-
def command_code
|
35
|
-
return (absolute?) ? 'C' : 'c' if @control_1
|
36
|
-
(absolute?) ? 'S' : 's'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class HorizontalTo < CoordinateTarget
|
4
|
-
def command_code
|
5
|
-
(absolute?) ? 'H' : 'h'
|
6
|
-
end
|
7
|
-
|
8
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
9
|
-
|
10
|
-
unless skew_y.zero?
|
11
|
-
raise 'rotating or skewing (in Y axis) an "horizontal_to" direction is not supported yet.'
|
12
|
-
end
|
13
|
-
|
14
|
-
self.target *= scale_x
|
15
|
-
self.target += tx if absolute?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class LineTo < PointTarget
|
4
|
-
def command_code
|
5
|
-
(absolute?) ? 'L' : 'l'
|
6
|
-
end
|
7
|
-
|
8
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
9
|
-
# relative line_to dont't need to be tranlated
|
10
|
-
tx = ty = 0 if relative?
|
11
|
-
transform_dot( target, scale_x, skew_x, skew_y, scale_y, tx, ty)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class MoveTo < PointTarget
|
4
|
-
def command_code
|
5
|
-
(absolute?) ? 'M' : 'm'
|
6
|
-
end
|
7
|
-
|
8
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
9
|
-
# relative move_to dont't need to be tranlated
|
10
|
-
tx = ty = 0 if relative?
|
11
|
-
transform_dot( target, scale_x, skew_x, skew_y, scale_y, tx, ty )
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class PointTarget < Direction
|
4
|
-
|
5
|
-
attr_accessor :target
|
6
|
-
|
7
|
-
def initialize(x, y, absolute=true)
|
8
|
-
@target = Point.new(x,y)
|
9
|
-
super(absolute)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_a
|
13
|
-
[command_code, @target.x, @target.y]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class QuadraticCurveTo < PointTarget
|
4
|
-
attr_accessor :control
|
5
|
-
|
6
|
-
def initialize(*args)
|
7
|
-
raise ArgumentError if args.length < 2
|
8
|
-
case args.length
|
9
|
-
when 2
|
10
|
-
super(args[0],args[1],true)
|
11
|
-
when 3
|
12
|
-
raise ArgumentError if args[2].kind_of?(Numeric)
|
13
|
-
super(args[0],args[1],args[2])
|
14
|
-
when 4
|
15
|
-
@control = Point.new(args[0],args[1])
|
16
|
-
super(args[2],args[3],true)
|
17
|
-
when 5
|
18
|
-
@control = Point.new(args[0],args[1])
|
19
|
-
super(args[2],args[3],args[4])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_a
|
24
|
-
if @control
|
25
|
-
[command_code, @control.x, @control.y, @target.x, @target.y]
|
26
|
-
else
|
27
|
-
[command_code, @target.x, @target.y]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def command_code
|
32
|
-
return (absolute?) ? 'Q' : 'q' if @control
|
33
|
-
(absolute?) ? 'T' : 't'
|
34
|
-
end
|
35
|
-
|
36
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
37
|
-
# relative line_to dont't need to be tranlated
|
38
|
-
tx = ty = 0 if relative?
|
39
|
-
transform_dot( target, scale_x, skew_x, skew_y, scale_y, tx, ty)
|
40
|
-
transform_dot( control, scale_x, skew_x, skew_y, scale_y, tx, ty)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
module Directions
|
3
|
-
class VerticalTo < CoordinateTarget
|
4
|
-
def command_code
|
5
|
-
(absolute?) ? 'V' : 'v'
|
6
|
-
end
|
7
|
-
|
8
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
9
|
-
|
10
|
-
unless skew_x.zero?
|
11
|
-
raise 'rotating or skewing (in X axis) an "vertical_to" direction is not supported yet.'
|
12
|
-
end
|
13
|
-
|
14
|
-
self.target *= scale_y
|
15
|
-
self.target += ty if absolute?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
class Parser
|
3
|
-
DIRECTIONS = {
|
4
|
-
:m => {:class => Directions::MoveTo,
|
5
|
-
:args => 2},
|
6
|
-
:l => {:class => Directions::LineTo,
|
7
|
-
:args => 2},
|
8
|
-
:h => {:class => Directions::HorizontalTo,
|
9
|
-
:args => 1},
|
10
|
-
:v => {:class => Directions::VerticalTo,
|
11
|
-
:args => 1},
|
12
|
-
:c => {:class => Directions::CubicCurveTo,
|
13
|
-
:args => 6},
|
14
|
-
:s => {:class => Directions::CubicCurveTo,
|
15
|
-
:args => 4},
|
16
|
-
:q => {:class => Directions::QuadraticCurveTo,
|
17
|
-
:args => 4},
|
18
|
-
:t => {:class => Directions::QuadraticCurveTo,
|
19
|
-
:args => 2},
|
20
|
-
:a => {:class => Directions::ArcTo,
|
21
|
-
:args => 7}
|
22
|
-
}
|
23
|
-
|
24
|
-
class << self
|
25
|
-
def parse(parsable)
|
26
|
-
raise TypeError if parsable.class != String
|
27
|
-
subpaths = extract_subpaths parsable
|
28
|
-
raise TypeError if (subpaths.empty?)
|
29
|
-
path = Path.new
|
30
|
-
path.subpaths = []
|
31
|
-
subpaths.each_with_index do |subpath, i|
|
32
|
-
path.subpaths << parse_subpath(subpath, i == 0)
|
33
|
-
end
|
34
|
-
path
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def extract_subpaths(parsable)
|
39
|
-
subpaths = []
|
40
|
-
if move_index = parsable.index(/[Mm]/)
|
41
|
-
subpaths << parsable[0...move_index] if move_index > 0
|
42
|
-
parsable.scan(/[Mm](?:\d|[eE.,+-]|[LlHhVvQqCcTtSsAaZz]|\W)+/m) do |match_group|
|
43
|
-
subpaths << $&
|
44
|
-
end
|
45
|
-
else
|
46
|
-
subpaths << parsable
|
47
|
-
end
|
48
|
-
subpaths
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_subpath(parsable, force_absolute=false)
|
52
|
-
subpath = SubPath.new
|
53
|
-
subpath.directions = extract_directions parsable, force_absolute
|
54
|
-
subpath
|
55
|
-
end
|
56
|
-
|
57
|
-
def extract_directions(parsable, force_absolute=false)
|
58
|
-
directions = []
|
59
|
-
i = 0
|
60
|
-
parsable.scan(/[MmLlHhVvQqCcTtSsAaZz](?:\d|[eE.,+-]|\W)*/m) do |match_group|
|
61
|
-
direction = build_direction $&, force_absolute && i == 0
|
62
|
-
if direction.kind_of?(Array)
|
63
|
-
directions.concat direction
|
64
|
-
else
|
65
|
-
directions << direction
|
66
|
-
end
|
67
|
-
i += 1
|
68
|
-
end
|
69
|
-
directions
|
70
|
-
end
|
71
|
-
|
72
|
-
def build_direction(parsable, force_absolute=false)
|
73
|
-
directions = []
|
74
|
-
@coordinates = extract_coordinates parsable
|
75
|
-
recurse_code = parsable[0,1]
|
76
|
-
first_absolute = force_absolute
|
77
|
-
|
78
|
-
# we need to handle this separately, since ClosePath doesn't take any coordinates
|
79
|
-
if @coordinates.empty? && recurse_code =~ /[Zz]/
|
80
|
-
directions << Directions::ClosePath.new(parsable[0,1] == parsable[0,1].upcase)
|
81
|
-
end
|
82
|
-
|
83
|
-
until @coordinates.empty?
|
84
|
-
absolute = (first_absolute || parsable[0,1] == parsable[0,1].upcase)
|
85
|
-
directions << construct_direction(recurse_code.strip[0].downcase.intern, absolute)
|
86
|
-
recurse_code = 'L' if recurse_code.downcase =~ /m/
|
87
|
-
first_absolute = false
|
88
|
-
end
|
89
|
-
|
90
|
-
directions
|
91
|
-
end
|
92
|
-
|
93
|
-
def construct_direction(recurse_code, absolute)
|
94
|
-
args = @coordinates.shift DIRECTIONS[recurse_code][:args]
|
95
|
-
raise TypeError if args.any?(&:nil?)
|
96
|
-
DIRECTIONS[recurse_code][:class].new(*args, absolute)
|
97
|
-
end
|
98
|
-
|
99
|
-
def extract_coordinates(command_string)
|
100
|
-
coordinates = []
|
101
|
-
command_string.scan(/-?\d+(\.\d+)?([eE][+-]?\d+)?/) do |match_group|
|
102
|
-
coordinates << $&.to_f
|
103
|
-
end
|
104
|
-
coordinates
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
class Path
|
3
|
-
require File.dirname(__FILE__) + "/direction_proxy"
|
4
|
-
require File.dirname(__FILE__) + "/sub_path"
|
5
|
-
|
6
|
-
include Utils
|
7
|
-
include DirectionProxy
|
8
|
-
include Transformable
|
9
|
-
|
10
|
-
attr_accessor :subpaths
|
11
|
-
|
12
|
-
define_proxies do |sym,const|
|
13
|
-
define_method(sym) do |*args|
|
14
|
-
@subpaths.last.send(sym,*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(*args)
|
19
|
-
@subpaths = [SubPath.new]
|
20
|
-
@subpaths.last.move_to(*args) if (2..3).include?(*args.length)
|
21
|
-
yield self if block_given?
|
22
|
-
end
|
23
|
-
|
24
|
-
def directions
|
25
|
-
directions = []
|
26
|
-
@subpaths.each { |subpath| directions.concat(subpath.directions) }
|
27
|
-
directions
|
28
|
-
end
|
29
|
-
|
30
|
-
def move_to(*args)
|
31
|
-
unless (@subpaths.last.directions.empty?)
|
32
|
-
(@subpaths << SubPath.new(*args)).last
|
33
|
-
else
|
34
|
-
@subpaths.last.move_to(*args)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def closed?
|
39
|
-
@subpaths.last.closed?
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_command
|
43
|
-
@subpaths.collect { |subpath| subpath.to_command }.join
|
44
|
-
end
|
45
|
-
|
46
|
-
def transform(*args)
|
47
|
-
@subpaths.each {|subpath| subpath.transform *args }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Savage
|
2
|
-
class SubPath
|
3
|
-
include Utils
|
4
|
-
include DirectionProxy
|
5
|
-
include Transformable
|
6
|
-
|
7
|
-
define_proxies do |sym,const|
|
8
|
-
define_method(sym) do |*args|
|
9
|
-
raise TypeError if const == "QuadraticCurveTo" && @directions.last.class != Directions::QuadraticCurveTo && [2,3].include?(args.length)
|
10
|
-
raise TypeError if const == "CubicCurveTo" && @directions.last.class != Directions::CubicCurveTo && [4,5].include?(args.length)
|
11
|
-
(@directions << Savage::Directions.const_get(const).new(*args)).last
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_accessor :directions
|
16
|
-
|
17
|
-
def move_to(*args)
|
18
|
-
return nil unless @directions.empty?
|
19
|
-
(@directions << Directions::MoveTo.new(*args)).last
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(*args)
|
23
|
-
@directions = []
|
24
|
-
move_to(*args) if (2..3).include?(args.length)
|
25
|
-
yield self if block_given?
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_command
|
29
|
-
@directions.to_enum(:each_with_index).collect { |dir, i|
|
30
|
-
command_string = dir.to_command
|
31
|
-
if i > 0
|
32
|
-
prev_command_code = @directions[i-1].command_code
|
33
|
-
if dir.command_code == prev_command_code || (prev_command_code.match(/^[Mm]$/) && dir.command_code == 'L')
|
34
|
-
command_string.gsub!(/^[A-Za-z]/,'')
|
35
|
-
command_string.insert(0,' ') unless command_string.match(/^-/)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
command_string
|
39
|
-
}.join
|
40
|
-
end
|
41
|
-
|
42
|
-
def commands
|
43
|
-
@directions
|
44
|
-
end
|
45
|
-
|
46
|
-
def closed?
|
47
|
-
@directions.last.kind_of? Directions::ClosePath
|
48
|
-
end
|
49
|
-
|
50
|
-
def transform(*args)
|
51
|
-
directions.each { |dir| dir.transform *args }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'bigdecimal'
|
2
|
-
require 'bigdecimal/util'
|
3
|
-
|
4
|
-
module Savage
|
5
|
-
|
6
|
-
module Transformable
|
7
|
-
|
8
|
-
# Matrix:
|
9
|
-
def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
|
10
|
-
end
|
11
|
-
|
12
|
-
def translate(tx, ty=0)
|
13
|
-
transform( 1, 0, 0, 1, tx, ty )
|
14
|
-
end
|
15
|
-
|
16
|
-
def scale(sx, sy=sx)
|
17
|
-
transform( sx, 0, 0, sy, 0, 0 )
|
18
|
-
end
|
19
|
-
|
20
|
-
# TODO:
|
21
|
-
# make cx, cy be origin center
|
22
|
-
def rotate( angle, cx=0, cy=0 )
|
23
|
-
a = (angle.to_f/180).to_d * Math::PI
|
24
|
-
translate( cx, cy )
|
25
|
-
transform( Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0)
|
26
|
-
translate( -cx, -cy )
|
27
|
-
end
|
28
|
-
|
29
|
-
def skew_x( angle )
|
30
|
-
a = angle.to_f/180 * Math::PI
|
31
|
-
transform( 1, 0, Math.tan(a), 1, 0, 0 )
|
32
|
-
end
|
33
|
-
|
34
|
-
def skew_y( angle )
|
35
|
-
a = angle.to_f/180 * Math::PI
|
36
|
-
transform( 1, Math.tan(a), 0, 1, 0, 0 )
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def transform_dot( dot, scale_x, skew_x, skew_y, scale_y, tx, ty )
|
42
|
-
x, y = dot.x, dot.y
|
43
|
-
dot.x = x*scale_x + y*skew_x + tx
|
44
|
-
dot.y = x*skew_y + y*scale_y + ty
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|