In Files

Parent

Class Index [+]

Quicksearch

Magick::RVG::Utility::TextStrategy

Public Class Methods

new(context) click to toggle source
    # File lib/rvg/misc.rb, line 82
82:                 def initialize(context)
83:                     @ctx = context
84:                     @ctx.shadow.affine = @ctx.text_attrs.affine
85:                 end

Public Instance Methods

enquote(text) click to toggle source
     # File lib/rvg/misc.rb, line 87
 87:                 def enquote(text)
 88:                     if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
 89:                         return text
 90:                     elsif !text['\']
 91:                         text = '\'+text+'\'
 92:                         return text
 93:                     elsif !text['"']
 94:                         text = '"'+text+'"'
 95:                         return text
 96:                     elsif !(text['{'] || text['}'])
 97:                         text = '{'+text+'}'
 98:                         return text
 99:                     end
100: 
101:                     # escape existing braces, surround with braces
102:                     text.gsub!(/[}]/) { |b| '\' + b }
103:                     return '{' +  text + '}'
104:                 end
glyph_metrics(glyph_orientation, glyph) click to toggle source
     # File lib/rvg/misc.rb, line 106
106:                 def glyph_metrics(glyph_orientation, glyph)
107:                     gm = @ctx.shadow.get_type_metrics("a" + glyph + "a")
108:                     gm2 = @ctx.shadow.get_type_metrics("aa")
109:                     h = (gm.ascent - gm.descent + 0.5 ).to_i
110:                     w = gm.width - gm2.width
111:                     if glyph_orientation == 0 || glyph_orientation == 180
112:                         [w, h]
113:                     else
114:                         [h, w]
115:                     end
116:                 end
render_glyph(glyph_orientation, x, y, glyph) click to toggle source
     # File lib/rvg/misc.rb, line 162
162:                 def render_glyph(glyph_orientation, x, y, glyph)
163:                     if glyph_orientation == 0
164:                         @ctx.gc.text(x, y, enquote(glyph))
165:                     else
166:                         @ctx.gc.push
167:                         @ctx.gc.translate(x, y)
168:                         @ctx.gc.rotate(glyph_orientation)
169:                         @ctx.gc.translate(-x, -y)
170:                         @ctx.gc.text(x, y, enquote(glyph))
171:                         @ctx.gc.pop
172:                     end
173:                 end
shift_baseline(glyph_orientation, glyph) click to toggle source
     # File lib/rvg/misc.rb, line 139
139:                 def shift_baseline(glyph_orientation, glyph)
140:                     glyph_dimensions = @ctx.shadow.get_type_metrics(glyph)
141:                     if glyph_orientation == 0 || glyph_orientation == 180
142:                         x = glyph_dimensions.width
143:                     else
144:                         x = glyph_dimensions.ascent - glyph_dimensions.descent
145:                     end
146:                     case @ctx.text_attrs.baseline_shift
147:                         when :baseline
148:                             x = 0
149:                         when :sub
150:                             ;
151:                         when :super
152:                             x = -x
153:                         when /[-+]?(\d+)%/
154:                             m = $1 == '-' ? 1.0 : 1.0
155:                             x = (m * x * $1.to_f / 100.0)
156:                         else
157:                             x = -@ctx.text_attrs.baseline_shift
158:                     end
159:                     return x
160:                 end
text_rel_coords(text) click to toggle source
     # File lib/rvg/misc.rb, line 118
118:                 def text_rel_coords(text)
119:                     y_rel_coords = []
120:                     x_rel_coords = []
121:                     first_word = true
122:                     words = text.split(::Magick::RVG::WORD_SEP)
123:                     words.each do |word|
124:                         unless first_word
125:                             wx, wy = get_word_spacing()
126:                             x_rel_coords << wx
127:                             y_rel_coords << wy
128:                         end
129:                         first_word = false
130:                         word.split('').each do |glyph|
131:                             wx, wy = get_letter_spacing(glyph)
132:                             x_rel_coords << wx
133:                             y_rel_coords << wy
134:                         end
135:                     end
136:                     [x_rel_coords, y_rel_coords]
137:                 end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.