Parent

Prawn::Text::Formatted::Fragment

Prawn::Text::Formatted::Fragment is a state store for a formatted text fragment. It does not render anything.

Attributes

format_state[R]
width[W]
line_height[RW]
descender[RW]
ascender[RW]
word_spacing[RW]
left[RW]
baseline[RW]

Public Class Methods

new(text, format_state, document) click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 23
23:         def initialize(text, format_state, document)
24:           @text = text
25:           @format_state = format_state
26:           @document = document
27:           @word_spacing = 0
28:         end

Public Instance Methods

absolute_bottom() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 193
193:         def absolute_bottom
194:           absolute_bounding_box[1]
195:         end
absolute_bottom_left() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 205
205:         def absolute_bottom_left
206:           [absolute_left, absolute_bottom]
207:         end
absolute_bottom_right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 209
209:         def absolute_bottom_right
210:           [absolute_right, absolute_bottom]
211:         end
absolute_bounding_box() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 77
77:         def absolute_bounding_box
78:           box = bounding_box
79:           box[0] += @document.bounds.absolute_left
80:           box[2] += @document.bounds.absolute_left
81:           box[1] += @document.bounds.absolute_bottom
82:           box[3] += @document.bounds.absolute_bottom
83:           box
84:         end
absolute_left() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 181
181:         def absolute_left
182:           absolute_bounding_box[0]
183:         end
absolute_right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 185
185:         def absolute_right
186:           absolute_bounding_box[2]
187:         end
absolute_top() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 189
189:         def absolute_top
190:           absolute_bounding_box[3]
191:         end
absolute_top_left() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 197
197:         def absolute_top_left
198:           [absolute_left, absolute_top]
199:         end
absolute_top_right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 201
201:         def absolute_top_right
202:           [absolute_right, absolute_top]
203:         end
anchor() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 104
104:         def anchor
105:           @format_state[:anchor]
106:         end
bottom() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 161
161:         def bottom
162:           baseline - descender
163:         end
bottom_left() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 177
177:         def bottom_left
178:           [left, bottom]
179:         end
bottom_right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 173
173:         def bottom_right
174:           [right, bottom]
175:         end
bounding_box() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 73
73:         def bounding_box
74:           [left, bottom, right, top]
75:         end
callback_objects() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 142
142:         def callback_objects
143:           callback = @format_state[:callback]
144:           if callback.nil?
145:             []
146:           elsif callback.is_a?(Array)
147:             callback
148:           else
149:             [callback]
150:           end
151:         end
character_spacing() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 120
120:         def character_spacing
121:           @format_state[:character_spacing] ||
122:             @document.character_spacing
123:         end
color() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 108
108:         def color
109:           @format_state[:color]
110:         end
default_direction=(direction) click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 129
129:         def default_direction=(direction)
130:           @format_state[:direction] = direction unless @format_state[:direction]
131:         end
direction() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 125
125:         def direction
126:           @format_state[:direction]
127:         end
font() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 112
112:         def font
113:           @format_state[:font]
114:         end
height() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 54
54:         def height
55:           top - bottom
56:         end
include_trailing_white_space!() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 133
133:         def include_trailing_white_space!
134:           @format_state.delete(:exclude_trailing_white_space)
135:         end
right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 153
153:         def right
154:           left + width
155:         end
size() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 116
116:         def size
117:           @format_state[:size]
118:         end
space_count() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 137
137:         def space_count
138:           string = exclude_trailing_white_space? ? @text.rstrip : @text
139:           string.count(" ")
140:         end
strikethrough_points() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 91
91:         def strikethrough_points
92:           y = baseline + ascender * 0.3
93:           [[left, y], [right, y]]
94:         end
styles() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 96
96:         def styles
97:           @format_state[:styles] || []
98:         end
subscript?() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 58
58:         def subscript?
59:           styles.include?(:subscript)
60:         end
superscript?() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 62
62:         def superscript?
63:           styles.include?(:superscript)
64:         end
text() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 30
30:         def text
31:           string = strip_zero_width_spaces(@text)
32:           if exclude_trailing_white_space?
33:             string = string.rstrip
34:             string = process_soft_hyphens(string)
35:           end
36:           case direction
37:           when :rtl
38:             if ruby_18 { true }
39:               string.scan(/./u).reverse.join
40:             else
41:               string.reverse
42:             end
43:           else
44:             string
45:           end
46:         end
top() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 157
157:         def top
158:           baseline + ascender
159:         end
top_left() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 165
165:         def top_left
166:           [left, top]
167:         end
top_right() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 169
169:         def top_right
170:           [right, top]
171:         end
underline_points() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 86
86:         def underline_points
87:           y = baseline - 1.25
88:           [[left, y], [right, y]]
89:         end
width() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 48
48:         def width
49:           if @word_spacing == 0 then @width
50:           else @width + @word_spacing * space_count
51:           end
52:         end
y_offset() click to toggle source
    # File lib/prawn/text/formatted/fragment.rb, line 66
66:         def y_offset
67:           if subscript? then -descender
68:           elsif superscript? then 0.85 * ascender
69:           else 0
70:           end
71:         end

Private Instance Methods

exclude_trailing_white_space?() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 215
215:         def exclude_trailing_white_space?
216:           @format_state[:exclude_trailing_white_space]
217:         end
normalized_soft_hyphen() click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 219
219:         def normalized_soft_hyphen
220:           @format_state[:normalized_soft_hyphen]
221:         end
process_soft_hyphens(string) click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 223
223:         def process_soft_hyphens(string)
224:           if string.length > 0 && normalized_soft_hyphen
225:             string[0..2].gsub(normalized_soft_hyphen, "") + string[1..1]
226:           else
227:             string
228:           end
229:         end
strip_zero_width_spaces(string) click to toggle source
     # File lib/prawn/text/formatted/fragment.rb, line 231
231:         def strip_zero_width_spaces(string)
232:           if !"".respond_to?(:encoding) || string.encoding.to_s == "UTF-8"
233:             string.gsub(Prawn::Text::ZWSP, "")
234:           else
235:             string
236:           end
237:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.