rmagick 1.7.4 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rmagick might be problematic. Click here for more details.
- data/ChangeLog +10 -2
- data/README.html +284 -290
- data/README.txt +298 -307
- data/configure +180 -11
- data/configure.ac +18 -2
- data/doc/comtasks.html +1 -1
- data/doc/constants.html +15 -10
- data/doc/css/ref.css +67 -0
- data/doc/draw.html +1 -1
- data/doc/ex/InitialCoords.rb +24 -0
- data/doc/ex/NewCoordSys.rb +33 -0
- data/doc/ex/OrigCoordSys.rb +19 -0
- data/doc/ex/PreserveAspectRatio.rb +206 -0
- data/doc/ex/RotateScale.rb +38 -0
- data/doc/ex/Skew.rb +39 -0
- data/doc/ex/Use01.rb +17 -0
- data/doc/ex/Use02.rb +22 -0
- data/doc/ex/Use03.rb +17 -0
- data/doc/ex/ViewBox.rb +34 -0
- data/doc/ex/arcs01.rb +29 -0
- data/doc/ex/arcs02.rb +62 -0
- data/doc/ex/baseline_shift01.rb +19 -0
- data/doc/ex/bounding_box.rb +31 -37
- data/doc/ex/circle01.rb +18 -0
- data/doc/ex/cubic01.rb +46 -0
- data/doc/ex/cubic02.rb +95 -0
- data/doc/ex/drop_shadow.rb +1 -1
- data/doc/ex/ellipse01.rb +23 -0
- data/doc/ex/evenodd.rb +44 -0
- data/doc/ex/font_styles.rb +29 -0
- data/doc/ex/group.rb +27 -0
- data/doc/ex/image.rb +47 -0
- data/doc/ex/images/big-duck.gif +0 -0
- data/doc/ex/images/duck.gif +0 -0
- data/doc/ex/images/duck0.gif +0 -0
- data/doc/ex/images/duck1.gif +0 -0
- data/doc/ex/images/duck10.gif +0 -0
- data/doc/ex/images/duck11.gif +0 -0
- data/doc/ex/images/duck12.gif +0 -0
- data/doc/ex/images/duck13.gif +0 -0
- data/doc/ex/images/duck14.gif +0 -0
- data/doc/ex/images/duck15.gif +0 -0
- data/doc/ex/images/duck2.gif +0 -0
- data/doc/ex/images/duck3.gif +0 -0
- data/doc/ex/images/duck4.gif +0 -0
- data/doc/ex/images/duck5.gif +0 -0
- data/doc/ex/images/duck6.gif +0 -0
- data/doc/ex/images/duck7.gif +0 -0
- data/doc/ex/images/duck8.gif +0 -0
- data/doc/ex/images/duck9.gif +0 -0
- data/doc/ex/line01.rb +24 -0
- data/doc/ex/nested_rvg.rb +22 -0
- data/doc/ex/nonzero.rb +44 -0
- data/doc/ex/polygon01.rb +24 -0
- data/doc/ex/polyline01.rb +24 -0
- data/doc/ex/quad01.rb +37 -0
- data/doc/ex/rect01.rb +16 -0
- data/doc/ex/rect02.rb +23 -0
- data/doc/ex/rvg_clippath.rb +15 -0
- data/doc/ex/rvg_linecap.rb +44 -0
- data/doc/ex/rvg_linejoin.rb +42 -0
- data/doc/ex/rvg_opacity.rb +20 -0
- data/doc/ex/rvg_pattern.rb +27 -0
- data/doc/ex/rvg_stroke_dasharray.rb +13 -0
- data/doc/ex/sepiatone.rb +15 -0
- data/doc/ex/shadow.rb +37 -0
- data/doc/ex/smile.rb +9 -9
- data/doc/ex/stroke_fill.rb +12 -0
- data/doc/ex/text01.rb +18 -0
- data/doc/ex/text_styles.rb +22 -0
- data/doc/ex/texture_fill_to_border.rb +3 -3
- data/doc/ex/texture_floodfill.rb +3 -2
- data/doc/ex/tref01.rb +26 -0
- data/doc/ex/triangle01.rb +17 -0
- data/doc/ex/tspan01.rb +19 -0
- data/doc/ex/tspan02.rb +20 -0
- data/doc/ex/tspan03.rb +22 -0
- data/doc/ex/writing_mode01.rb +28 -0
- data/doc/ex/writing_mode02.rb +27 -0
- data/doc/ilist.html +1 -1
- data/doc/image1.html +66 -30
- data/doc/image2.html +1 -1
- data/doc/image3.html +274 -49
- data/doc/imageattrs.html +87 -10
- data/doc/imusage.html +1 -1
- data/doc/index.html +80 -39
- data/doc/info.html +149 -13
- data/doc/magick.html +1 -1
- data/doc/rvg.html +890 -0
- data/doc/rvgclip.html +249 -0
- data/doc/rvggroup.html +305 -0
- data/doc/rvgimage.html +288 -0
- data/doc/rvgpattern.html +456 -0
- data/doc/rvgshape.html +376 -0
- data/doc/rvgstyle.html +269 -0
- data/doc/rvgtext.html +464 -0
- data/doc/rvgtspan.html +237 -0
- data/doc/rvgtut.html +512 -0
- data/doc/rvguse.html +145 -0
- data/doc/rvgxform.html +294 -0
- data/doc/struct.html +9 -71
- data/doc/usage.html +22 -7
- data/ext/RMagick/MANIFEST +94 -2
- data/ext/RMagick/rmagick.h +10 -4
- data/ext/RMagick/rmagick_config.h.in +8 -2
- data/ext/RMagick/rmdraw.c +2 -2
- data/ext/RMagick/rmfill.c +2 -2
- data/ext/RMagick/rmilist.c +3 -3
- data/ext/RMagick/rmimage.c +152 -5
- data/ext/RMagick/rminfo.c +208 -2
- data/ext/RMagick/rmmain.c +14 -5
- data/ext/RMagick/rmutil.c +83 -22
- data/lib/RMagick.rb +2 -2
- data/lib/rvg/clippath.rb +46 -0
- data/lib/rvg/container.rb +129 -0
- data/lib/rvg/deep_equal.rb +54 -0
- data/lib/rvg/describable.rb +51 -0
- data/lib/rvg/embellishable.rb +395 -0
- data/lib/rvg/misc.rb +729 -0
- data/lib/rvg/paint.rb +48 -0
- data/lib/rvg/pathdata.rb +129 -0
- data/lib/rvg/rvg.rb +279 -0
- data/lib/rvg/stretchable.rb +150 -0
- data/lib/rvg/stylable.rb +116 -0
- data/lib/rvg/text.rb +185 -0
- data/lib/rvg/transformable.rb +131 -0
- data/lib/rvg/units.rb +64 -0
- data/rmagick.gemspec +1 -1
- data/uninstall.rb +3 -2
- metadata +96 -3
@@ -0,0 +1,150 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: stretchable.rb,v 1.1 2005/03/12 17:02:00 rmagick Exp $
|
3
|
+
# Copyright (C) 2005 Timothy P. Hunter
|
4
|
+
#++
|
5
|
+
|
6
|
+
class Magick::RVG
|
7
|
+
|
8
|
+
module PreserveAspectRatio
|
9
|
+
#--
|
10
|
+
# Included in Stretchable module and Image class
|
11
|
+
#++
|
12
|
+
# Specifies how the image within a viewport should be scaled.
|
13
|
+
# [+align+] a combination of 'xMin', 'xMid', or 'xMax', followed by
|
14
|
+
# 'YMin', 'YMid', or 'YMax'
|
15
|
+
# [+meet_or_slice+] one of 'meet' or 'slice'
|
16
|
+
def preserve_aspect_ratio(align, meet_or_slice='meet')
|
17
|
+
@align = align.to_s
|
18
|
+
if @align != 'none'
|
19
|
+
m = /\A(xMin|xMid|xMax)(YMin|YMid|YMax)\z/.match(@align)
|
20
|
+
raise(ArgumentError, "unknown alignment specifier: #{@align}") unless m
|
21
|
+
end
|
22
|
+
|
23
|
+
if meet_or_slice
|
24
|
+
meet_or_slice = meet_or_slice.to_s.downcase
|
25
|
+
if meet_or_slice == 'meet' || meet_or_slice == 'slice'
|
26
|
+
@meet_or_slice = meet_or_slice
|
27
|
+
else
|
28
|
+
raise(ArgumentError, "specifier must be `meet' or `slice' (got #{meet_or_slice})")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
yield(self) if block_given?
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end # module PreserveAspectRatio
|
35
|
+
|
36
|
+
|
37
|
+
# The methods in this module describe the user-coordinate space.
|
38
|
+
# Only RVG objects are stretchable.
|
39
|
+
module Stretchable
|
40
|
+
|
41
|
+
private
|
42
|
+
def set_viewbox_none(width, height)
|
43
|
+
sx, sy = 1.0, 1.0
|
44
|
+
tx, ty = @vbx_x, @vbx_y
|
45
|
+
|
46
|
+
if @vbx_width
|
47
|
+
sx = width / @vbx_width
|
48
|
+
end
|
49
|
+
if @vbx_height
|
50
|
+
sy = height / @vbx_height
|
51
|
+
end
|
52
|
+
|
53
|
+
return [tx, ty, sx, sy]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Use align attribute to compute x- and y-offset from viewport's upper-left corner.
|
57
|
+
def align_to_viewport(width, height, sx, sy)
|
58
|
+
tx, ty = @vbx_x, @vbx_y
|
59
|
+
tx += case @align
|
60
|
+
when /\AxMin/
|
61
|
+
0
|
62
|
+
when NilClass, /\AxMid/
|
63
|
+
(width - @vbx_width*sx) / 2.0
|
64
|
+
when /\AxMax/
|
65
|
+
width - @vbx_width*sx
|
66
|
+
end
|
67
|
+
|
68
|
+
ty += case @align
|
69
|
+
when /YMin\z/
|
70
|
+
0
|
71
|
+
when NilClass, /YMid\z/
|
72
|
+
(height - @vbx_height*sy) / 2.0
|
73
|
+
when /YMax\z/
|
74
|
+
height - @vbx_height*sy
|
75
|
+
end
|
76
|
+
return [tx, ty]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Scale to smaller viewbox dimension
|
80
|
+
def set_viewbox_meet(width, height)
|
81
|
+
sx = sy = [width / @vbx_width, height / @vbx_height].min
|
82
|
+
tx, ty = align_to_viewport(width, height, sx, sy)
|
83
|
+
return [tx, ty, sx, sy]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Scale to larger viewbox dimension
|
87
|
+
def set_viewbox_slice(width, height)
|
88
|
+
sx = sy = [width / @vbx_width, height / @vbx_height].max
|
89
|
+
tx, ty = align_to_viewport(width, height, sx, sy)
|
90
|
+
return [tx, ty, sx, sy]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Establish the viewbox as necessary
|
94
|
+
def add_viewbox_primitives(width, height, gc)
|
95
|
+
@vbx_width ||= width
|
96
|
+
@vbx_height ||= height
|
97
|
+
@vbx_x ||= 0.0
|
98
|
+
@vbx_y ||= 0.0
|
99
|
+
|
100
|
+
if @align == 'none'
|
101
|
+
tx, ty, sx, sy = set_viewbox_none(width, height)
|
102
|
+
elsif @meet_or_slice == 'meet'
|
103
|
+
tx, ty, sx, sy = set_viewbox_meet(width, height)
|
104
|
+
else
|
105
|
+
tx, ty, sx, sy = set_viewbox_slice(width, height)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Establish clipping path around the current viewport
|
109
|
+
name = __id__.to_s
|
110
|
+
gc.define_clip_path(name) do
|
111
|
+
gc.path("M0,0 l#{width},0 l0,#{height} l-#{width},0 l0,-#{height}z")
|
112
|
+
end
|
113
|
+
|
114
|
+
gc.clip_path(name)
|
115
|
+
gc.translate(tx, ty) if (tx.abs > 1.0e-10 || ty.abs > 1.0e-10)
|
116
|
+
gc.scale(sx, sy) if (sx != 1.0 || sy != 1.0)
|
117
|
+
end
|
118
|
+
|
119
|
+
def initialize(*args, &block)
|
120
|
+
super()
|
121
|
+
@vbx_x, @vbx_y, @vbx_width, @vbx_height = nil
|
122
|
+
@meet_or_slice = 'meet'
|
123
|
+
@align = nil
|
124
|
+
end
|
125
|
+
|
126
|
+
public
|
127
|
+
include PreserveAspectRatio
|
128
|
+
|
129
|
+
# Describe a user coordinate system to be imposed on the viewbox.
|
130
|
+
# The arguments must be numbers and the +width+ and +height+
|
131
|
+
# arguments must be positive.
|
132
|
+
def viewbox(x, y, width, height)
|
133
|
+
begin
|
134
|
+
@vbx_x = Float(x)
|
135
|
+
@vbx_y = Float(y)
|
136
|
+
@vbx_width = Float(width)
|
137
|
+
@vbx_height = Float(height)
|
138
|
+
rescue ArgumentError
|
139
|
+
raise ArgumentError, "arguments must be convertable to float (got #{x.class}, #{y.class}, #{width.class}, #{height.class})"
|
140
|
+
end
|
141
|
+
raise(ArgumentError, "viewbox width must be > 0 (#{width} given)") unless width >= 0
|
142
|
+
raise(ArgumentError, "viewbox height must be > 0 (#{height} given)") unless height >= 0
|
143
|
+
yield(self) if block_given?
|
144
|
+
self
|
145
|
+
end
|
146
|
+
|
147
|
+
end # module Stretchable
|
148
|
+
|
149
|
+
end # class Magick::RVG
|
150
|
+
|
data/lib/rvg/stylable.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: stylable.rb,v 1.1 2005/03/12 17:02:00 rmagick Exp $
|
3
|
+
# Copyright (C) 2005 Timothy P. Hunter
|
4
|
+
#++
|
5
|
+
|
6
|
+
class Magick::RVG
|
7
|
+
|
8
|
+
#:stopdoc:
|
9
|
+
STYLES = [:clip_path, :clip_rule, :fill, :fill_opacity, :fill_rule, :font,
|
10
|
+
:font_family, :font_size, :font_stretch, :font_style, :font_weight,
|
11
|
+
:opacity, :stroke, :stroke_dasharray, :stroke_dashoffset, :stroke_linecap,
|
12
|
+
:stroke_linejoin, :stroke_miterlimit, :stroke_opacity, :stroke_width,
|
13
|
+
:text_anchor, :text_decoration,
|
14
|
+
:glyph_orientation_vertical, :glyph_orientation_horizontal,
|
15
|
+
:letter_spacing, :word_spacing, :baseline_shift, :writing_mode]
|
16
|
+
|
17
|
+
Styles = Struct.new(*STYLES)
|
18
|
+
|
19
|
+
# Styles is a Struct class with a couple of extra methods
|
20
|
+
class Styles
|
21
|
+
|
22
|
+
def set(styles)
|
23
|
+
begin
|
24
|
+
styles.each_pair do |style, value|
|
25
|
+
begin
|
26
|
+
self[style] = value
|
27
|
+
rescue NoMethodError
|
28
|
+
raise ArgumentError, "unknown style `#{style}'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue NoMethodError
|
32
|
+
raise ArgumentError, "style arguments must be in the form `style => value'"
|
33
|
+
end
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# Iterate over the style names. Yield for each style that has a value.
|
38
|
+
def each_value
|
39
|
+
each_pair do |style, value|
|
40
|
+
yield(style, value) if value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# The "usual" deep_copy method doesn't copy a Struct correctly.
|
45
|
+
def deep_copy(h=nil)
|
46
|
+
copy = Styles.new
|
47
|
+
each_pair { |style, value| copy[style] = value }
|
48
|
+
return copy
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class Styles
|
52
|
+
|
53
|
+
#:startdoc:
|
54
|
+
|
55
|
+
# This module is mixed into classes that can have styles.
|
56
|
+
module Stylable
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# For each style that has a value, add a style primitive to the gc.
|
61
|
+
# Use splat to splat out Array arguments such as stroke_dasharray.
|
62
|
+
def add_style_primitives(gc)
|
63
|
+
@styles.each_value do |style, value|
|
64
|
+
if value.respond_to? :add_primitives
|
65
|
+
value.add_primitives(gc, style)
|
66
|
+
else
|
67
|
+
gc.__send__(style, *value)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def initialize
|
73
|
+
super
|
74
|
+
@styles = Styles.new
|
75
|
+
end
|
76
|
+
|
77
|
+
public
|
78
|
+
|
79
|
+
# This method can be used with any RVG, Group, Use, Text, or
|
80
|
+
# shape object. The argument is a hash. The style names are
|
81
|
+
# the hash keys. The style names and values are:
|
82
|
+
# [:clip_path] clipping path defined by clip_path
|
83
|
+
# [:clip_rule] 'evenodd' or 'nozero'
|
84
|
+
# [:fill] color name
|
85
|
+
# [:fill_opacity] the fill opacity, 0.0<=N<=1.0
|
86
|
+
# [:fill_rule] 'evenodd' or 'nozero'
|
87
|
+
# [:font] font name or font file name
|
88
|
+
# [:font_family] font family name, ex. 'serif'
|
89
|
+
# [:font_size] font size in points
|
90
|
+
# [:font_stretch] 'normal','ultra_condensed','extra_condensed',
|
91
|
+
# 'condensed','semi_condensed','semi_expanded',
|
92
|
+
# 'expanded','extra_expanded','ultra_expanded'
|
93
|
+
# [:font_style] 'normal','italic','oblique'
|
94
|
+
# [:font_weight] 'normal','bold','bolder','lighter', or
|
95
|
+
# a multiple of 100 between 100 and 900.
|
96
|
+
# [:opacity] both fill and stroke opacity, 0.0<=N<=1.0
|
97
|
+
# [:stroke] color name
|
98
|
+
# [:stroke_dasharray] dash pattern (Array)
|
99
|
+
# [:stroke_dashoffset] initial distance into dash pattern
|
100
|
+
# [:stroke_linecap] 'butt', 'round', 'square'
|
101
|
+
# [:stroke_linejoin] 'miter', 'round', 'bevel'
|
102
|
+
# [:stroke_miterlimit] miter length constraint
|
103
|
+
# [:stroke_opacity] the stroke opacity, 0.0<=N<=1.0
|
104
|
+
# [:stroke_width] stroke width
|
105
|
+
# [:text_anchor] 'start','middle','end'
|
106
|
+
# [:text_decoration] 'none','underline','overline','line_through'
|
107
|
+
def styles(styles)
|
108
|
+
@styles.set(styles)
|
109
|
+
yield(self) if block_given?
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
end # module Stylable
|
114
|
+
|
115
|
+
end # class Magick::RVG
|
116
|
+
|
data/lib/rvg/text.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
#--
|
2
|
+
# $Id: text.rb,v 1.2 2005/04/23 15:29:47 rmagick Exp $
|
3
|
+
# Copyright (C) 2005 Timothy P. Hunter
|
4
|
+
#++
|
5
|
+
# Text-related classes
|
6
|
+
|
7
|
+
class Magick::RVG
|
8
|
+
|
9
|
+
# Base class for Tspan, Tref and Text.
|
10
|
+
class TextBase
|
11
|
+
include Stylable
|
12
|
+
include Duplicatable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def initialize(text, &block) #:nodoc:
|
17
|
+
super()
|
18
|
+
@text = text.to_s if text
|
19
|
+
@dx = @dy = 0
|
20
|
+
@rotation = 0
|
21
|
+
@tspans = Content.new
|
22
|
+
yield(self) if block_given?
|
23
|
+
end
|
24
|
+
|
25
|
+
public
|
26
|
+
|
27
|
+
# Create a new text chunk. Each chunk can have its own initial position and styles.
|
28
|
+
# If <tt>x</tt> and <tt>y</tt> are omitted the text starts at the current text
|
29
|
+
# position.
|
30
|
+
def tspan(text, x=nil, y=nil)
|
31
|
+
tspan = Tspan.new(text, x, y)
|
32
|
+
tspan.parent = self
|
33
|
+
@tspans << tspan
|
34
|
+
return tspan
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add <tt>x</tt> and <tt>y</tt> to the current text position.
|
38
|
+
def d(x, y=0)
|
39
|
+
@dx, @dy = RVG.convert_to_float(x, y)
|
40
|
+
yield(self) if block_given?
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Rotate the text about the current text position.
|
45
|
+
def rotate(degrees)
|
46
|
+
@rotation = RVG.convert_to_float(degrees)[0]
|
47
|
+
yield(self) if block_given?
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# We do our own transformations.
|
52
|
+
def add_primitives(gc) #:nodoc:
|
53
|
+
if @text || @tspans.length > 0
|
54
|
+
gc.push
|
55
|
+
x = self.cx + @dx
|
56
|
+
y = self.cy + @dy
|
57
|
+
if @rotation != 0
|
58
|
+
gc.translate(x, y)
|
59
|
+
gc.rotate(@rotation)
|
60
|
+
gc.translate(-x, -y)
|
61
|
+
end
|
62
|
+
add_style_primitives(gc)
|
63
|
+
if @text
|
64
|
+
x2, y2 = gc.text(x, y, @text)
|
65
|
+
self.cx = x + x2
|
66
|
+
self.cy = y + y2
|
67
|
+
end
|
68
|
+
@tspans.each do |tspan|
|
69
|
+
tspan.add_primitives(gc)
|
70
|
+
end
|
71
|
+
gc.pop
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end # class TextBase
|
76
|
+
|
77
|
+
# Tspan and Tref shared methods - read/update @cx, @cy in parent Text object.
|
78
|
+
module TextLink #:nodoc:
|
79
|
+
|
80
|
+
def add_primitives(gc)
|
81
|
+
@parent.cx = @x if @x
|
82
|
+
@parent.cy = @y if @y
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
86
|
+
def cx()
|
87
|
+
@parent.cx
|
88
|
+
end
|
89
|
+
|
90
|
+
def cy()
|
91
|
+
@parent.cy
|
92
|
+
end
|
93
|
+
|
94
|
+
def cx=(x)
|
95
|
+
@parent.cx = x
|
96
|
+
end
|
97
|
+
|
98
|
+
def cy=(y)
|
99
|
+
@parent.cy = y
|
100
|
+
end
|
101
|
+
|
102
|
+
end # module TextLink
|
103
|
+
|
104
|
+
|
105
|
+
class Tref < TextBase #:nodoc:
|
106
|
+
include TextLink
|
107
|
+
|
108
|
+
def initialize(obj, x, y, parent)
|
109
|
+
@x, @y = RVG.convert_to_float(x, y, :allow_nil)
|
110
|
+
super(nil)
|
111
|
+
@tspans << obj
|
112
|
+
@parent = parent
|
113
|
+
end
|
114
|
+
|
115
|
+
end # class Tref
|
116
|
+
|
117
|
+
class Tspan < TextBase #:nodoc:
|
118
|
+
include TextLink
|
119
|
+
|
120
|
+
attr_accessor :parent
|
121
|
+
|
122
|
+
# Define a text segment starting at (<tt>x</tt>, <tt>y</tt>).
|
123
|
+
# If <tt>x</tt> and <tt>y</tt> are omitted the segment starts
|
124
|
+
# at the current text position.
|
125
|
+
#
|
126
|
+
# Tspan objects can contain Tspan objects.
|
127
|
+
def initialize(text=nil, x=nil, y=nil, &block)
|
128
|
+
@x, @y = RVG.convert_to_float(x, y, :allow_nil)
|
129
|
+
super(text, &block)
|
130
|
+
end
|
131
|
+
|
132
|
+
end # class Tspan
|
133
|
+
|
134
|
+
class Text < TextBase
|
135
|
+
|
136
|
+
attr_accessor :cx, :cy #:nodoc:
|
137
|
+
|
138
|
+
# Define a text string starting at [<tt>x</tt>, <tt>y</tt>].
|
139
|
+
# Use the RVG::TextConstructors#text method to create Text objects in a container.
|
140
|
+
#
|
141
|
+
# container.text(100, 100, "Simple text").styles(:font=>'Arial')
|
142
|
+
#
|
143
|
+
# Text objects can contain Tspan objects.
|
144
|
+
#
|
145
|
+
# container.text(100, 100).styles(:font=>'Arial') do |t|
|
146
|
+
# t.tspan("Red text").styles(:fill=>'red')
|
147
|
+
# t.tspan("Blue text").styles(:fill=>'blue')
|
148
|
+
# end
|
149
|
+
def initialize(x=0, y=0, text=nil, &block)
|
150
|
+
@cx, @cy = RVG.convert_to_float(x, y)
|
151
|
+
super(text, &block)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Reference a Tspan object. <tt>x</tt> and <tt>y</tt> are just
|
155
|
+
# like <tt>x</tt> and <tt>y</tt> in RVG::TextBase#tspan
|
156
|
+
def tref(obj, x=nil, y=nil)
|
157
|
+
if ! obj.kind_of?(Tspan)
|
158
|
+
raise ArgumentError, "wrong argument type #{obj.class} (expected Tspan)"
|
159
|
+
end
|
160
|
+
obj = obj.deep_copy
|
161
|
+
obj.parent = self
|
162
|
+
tref = Tref.new(obj, x, y, self)
|
163
|
+
@tspans << tref
|
164
|
+
return tref
|
165
|
+
end
|
166
|
+
|
167
|
+
end # class Text
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
# Methods that construct text objects within a container
|
172
|
+
module TextConstructors
|
173
|
+
|
174
|
+
# Draw a text string at (<tt>x</tt>,<tt>y</tt>). The string can
|
175
|
+
# be omitted. Optionally, define text chunks within the associated
|
176
|
+
# block.
|
177
|
+
def text(x=0, y=0, text=nil, &block)
|
178
|
+
t = Text.new(x, y, text, &block)
|
179
|
+
@content << t
|
180
|
+
return t
|
181
|
+
end
|
182
|
+
|
183
|
+
end # module TextConstructors
|
184
|
+
|
185
|
+
end
|