Class Magick::RVG::Utility::TextStrategy
In: lib/rvg/misc.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/units.rb Magick Module: Magick

Methods

Public Class methods

[Source]

    # File lib/rvg/misc.rb, line 78
78:         def initialize(context)
79:             @ctx = context
80:             @ctx.shadow.affine = @ctx.text_attrs.affine
81:         end

Public Instance methods

[Source]

     # File lib/rvg/misc.rb, line 83
 83:         def enquote(text)
 84:             if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
 85:                 return text
 86:             elsif !text['\'']
 87:                 text = '\''+text+'\''
 88:                 return text
 89:             elsif !text['"']
 90:                 text = '"'+text+'"'
 91:                 return text
 92:             elsif !(text['{'] || text['}'])
 93:                 text = '{'+text+'}'
 94:                 return text
 95:             end
 96: 
 97:             # escape existing braces, surround with braces
 98:             text.gsub!(/[}]/) { |b| '\\' + b }
 99:             return '{' +  text + '}'
100:         end

[Source]

     # File lib/rvg/misc.rb, line 102
102:         def glyph_metrics(glyph_orientation, glyph)
103:             glyph_metrics = @ctx.shadow.get_type_metrics(glyph)
104:             h = glyph_metrics.ascent - glyph_metrics.descent
105:             w = glyph_metrics.width
106:             if glyph_orientation == 0 || glyph_orientation == 180
107:                 [w, h]
108:             else
109:                 [h, w]
110:             end
111:         end

[Source]

     # File lib/rvg/misc.rb, line 157
157:         def render_glyph(glyph_orientation, x, y, glyph)
158:             if glyph_orientation == 0
159:                 @ctx.gc.text(x, y, enquote(glyph))
160:             else
161:                 @ctx.gc.push
162:                 @ctx.gc.translate(x, y)
163:                 @ctx.gc.rotate(glyph_orientation)
164:                 @ctx.gc.translate(-x, -y)
165:                 @ctx.gc.text(x, y, enquote(glyph))
166:                 @ctx.gc.pop
167:             end
168:         end

[Source]

     # File lib/rvg/misc.rb, line 134
134:         def shift_baseline(glyph_orientation, glyph)
135:             glyph_dimensions = @ctx.shadow.get_type_metrics(glyph)
136:             if glyph_orientation == 0 || glyph_orientation == 180
137:                 x = glyph_dimensions.width
138:             else
139:                 x = glyph_dimensions.ascent - glyph_dimensions.descent
140:             end
141:             case @ctx.text_attrs.baseline_shift
142:                 when :baseline
143:                     x = 0
144:                 when :sub
145:                     ;
146:                 when :super
147:                     x = -x
148:                 when /[-+]?(\d+)%/
149:                     m = $1 == '-' ? -1.0 : 1.0
150:                     x = (m * x * $1.to_f / 100.0)
151:                 else
152:                     x = -@ctx.text_attrs.baseline_shift
153:             end
154:             return x
155:         end

[Source]

     # File lib/rvg/misc.rb, line 113
113:         def text_rel_coords(text)
114:             y_rel_coords = []
115:             x_rel_coords = []
116:             first_word = true
117:             words = text.split(::Magick::RVG::WORD_SEP)
118:             words.each do |word|
119:                 unless first_word
120:                     wx, wy = get_word_spacing()
121:                     x_rel_coords << wx
122:                     y_rel_coords << wy
123:                 end
124:                 first_word = false
125:                 word.split('').each do |glyph|
126:                     wx, wy = get_letter_spacing(glyph)
127:                     x_rel_coords << wx
128:                     y_rel_coords << wy
129:                 end
130:             end
131:             [x_rel_coords, y_rel_coords]
132:         end

[Validate]