Class | Magick::RVG::Utility::TextStrategy |
In: |
lib/rvg/misc.rb
|
Parent: | Object |
# File lib/rvg/misc.rb, line 82 82: def initialize(context) 83: @ctx = context 84: @ctx.shadow.affine = @ctx.text_attrs.affine 85: end
# 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
# File lib/rvg/misc.rb, line 106 106: def glyph_metrics(glyph_orientation, glyph) 107: glyph_metrics = @ctx.shadow.get_type_metrics(glyph) 108: h = glyph_metrics.ascent - glyph_metrics.descent 109: w = glyph_metrics.width 110: if glyph_orientation == 0 || glyph_orientation == 180 111: [w, h] 112: else 113: [h, w] 114: end 115: end
# File lib/rvg/misc.rb, line 161 161: def render_glyph(glyph_orientation, x, y, glyph) 162: if glyph_orientation == 0 163: @ctx.gc.text(x, y, enquote(glyph)) 164: else 165: @ctx.gc.push 166: @ctx.gc.translate(x, y) 167: @ctx.gc.rotate(glyph_orientation) 168: @ctx.gc.translate(-x, -y) 169: @ctx.gc.text(x, y, enquote(glyph)) 170: @ctx.gc.pop 171: end 172: end
# File lib/rvg/misc.rb, line 138 138: def shift_baseline(glyph_orientation, glyph) 139: glyph_dimensions = @ctx.shadow.get_type_metrics(glyph) 140: if glyph_orientation == 0 || glyph_orientation == 180 141: x = glyph_dimensions.width 142: else 143: x = glyph_dimensions.ascent - glyph_dimensions.descent 144: end 145: case @ctx.text_attrs.baseline_shift 146: when :baseline 147: x = 0 148: when :sub 149: ; 150: when :super 151: x = -x 152: when /[-+]?(\d+)%/ 153: m = $1 == '-' ? -1.0 : 1.0 154: x = (m * x * $1.to_f / 100.0) 155: else 156: x = -@ctx.text_attrs.baseline_shift 157: end 158: return x 159: end
# File lib/rvg/misc.rb, line 117 117: def text_rel_coords(text) 118: y_rel_coords = [] 119: x_rel_coords = [] 120: first_word = true 121: words = text.split(::Magick::RVG::WORD_SEP) 122: words.each do |word| 123: unless first_word 124: wx, wy = get_word_spacing() 125: x_rel_coords << wx 126: y_rel_coords << wy 127: end 128: first_word = false 129: word.split('').each do |glyph| 130: wx, wy = get_letter_spacing(glyph) 131: x_rel_coords << wx 132: y_rel_coords << wy 133: end 134: end 135: [x_rel_coords, y_rel_coords] 136: end