Class: Prawn::Text::Formatted::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/text/formatted/fragment.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, format_state, document) ⇒ Fragment

Returns a new instance of Fragment.



23
24
25
26
27
28
29
30
31
32
# File 'lib/prawn/text/formatted/fragment.rb', line 23

def initialize(text, format_state, document)
  @format_state = format_state
  @document = document
  @word_spacing = 0

  # keep the original value of "text", so we can reinitialize @text if formatting parameters
  #   like text direction are changed
  @original_text = text
  @text = process_text(@original_text)
end

Instance Attribute Details

#ascenderObject

Returns the value of attribute ascender.



20
21
22
# File 'lib/prawn/text/formatted/fragment.rb', line 20

def ascender
  @ascender
end

#baselineObject

Returns the value of attribute baseline.



21
22
23
# File 'lib/prawn/text/formatted/fragment.rb', line 21

def baseline
  @baseline
end

#descenderObject

Returns the value of attribute descender.



20
21
22
# File 'lib/prawn/text/formatted/fragment.rb', line 20

def descender
  @descender
end

#format_stateObject (readonly)

Returns the value of attribute format_state.



18
19
20
# File 'lib/prawn/text/formatted/fragment.rb', line 18

def format_state
  @format_state
end

#leftObject

Returns the value of attribute left.



21
22
23
# File 'lib/prawn/text/formatted/fragment.rb', line 21

def left
  @left
end

#line_heightObject

Returns the value of attribute line_height.



20
21
22
# File 'lib/prawn/text/formatted/fragment.rb', line 20

def line_height
  @line_height
end

#textObject (readonly)

Returns the value of attribute text.



18
19
20
# File 'lib/prawn/text/formatted/fragment.rb', line 18

def text
  @text
end

#widthObject



34
35
36
37
38
# File 'lib/prawn/text/formatted/fragment.rb', line 34

def width
  if @word_spacing == 0 then @width
  else @width + @word_spacing * space_count
  end
end

#word_spacingObject

Returns the value of attribute word_spacing.



21
22
23
# File 'lib/prawn/text/formatted/fragment.rb', line 21

def word_spacing
  @word_spacing
end

Instance Method Details

#absolute_bottomObject



186
187
188
# File 'lib/prawn/text/formatted/fragment.rb', line 186

def absolute_bottom
  absolute_bounding_box[1]
end

#absolute_bottom_leftObject



198
199
200
# File 'lib/prawn/text/formatted/fragment.rb', line 198

def absolute_bottom_left
  [absolute_left, absolute_bottom]
end

#absolute_bottom_rightObject



202
203
204
# File 'lib/prawn/text/formatted/fragment.rb', line 202

def absolute_bottom_right
  [absolute_right, absolute_bottom]
end

#absolute_bounding_boxObject



63
64
65
66
67
68
69
70
# File 'lib/prawn/text/formatted/fragment.rb', line 63

def absolute_bounding_box
  box = bounding_box
  box[0] += @document.bounds.absolute_left
  box[2] += @document.bounds.absolute_left
  box[1] += @document.bounds.absolute_bottom
  box[3] += @document.bounds.absolute_bottom
  box
end

#absolute_leftObject



174
175
176
# File 'lib/prawn/text/formatted/fragment.rb', line 174

def absolute_left
  absolute_bounding_box[0]
end

#absolute_rightObject



178
179
180
# File 'lib/prawn/text/formatted/fragment.rb', line 178

def absolute_right
  absolute_bounding_box[2]
end

#absolute_topObject



182
183
184
# File 'lib/prawn/text/formatted/fragment.rb', line 182

def absolute_top
  absolute_bounding_box[3]
end

#absolute_top_leftObject



190
191
192
# File 'lib/prawn/text/formatted/fragment.rb', line 190

def absolute_top_left
  [absolute_left, absolute_top]
end

#absolute_top_rightObject



194
195
196
# File 'lib/prawn/text/formatted/fragment.rb', line 194

def absolute_top_right
  [absolute_right, absolute_top]
end

#anchorObject



90
91
92
# File 'lib/prawn/text/formatted/fragment.rb', line 90

def anchor
  @format_state[:anchor]
end

#bottomObject



154
155
156
# File 'lib/prawn/text/formatted/fragment.rb', line 154

def bottom
  baseline - descender
end

#bottom_leftObject



170
171
172
# File 'lib/prawn/text/formatted/fragment.rb', line 170

def bottom_left
  [left, bottom]
end

#bottom_rightObject



166
167
168
# File 'lib/prawn/text/formatted/fragment.rb', line 166

def bottom_right
  [right, bottom]
end

#bounding_boxObject



59
60
61
# File 'lib/prawn/text/formatted/fragment.rb', line 59

def bounding_box
  [left, bottom, right, top]
end

#callback_objectsObject



135
136
137
138
139
140
141
142
143
144
# File 'lib/prawn/text/formatted/fragment.rb', line 135

def callback_objects
  callback = @format_state[:callback]
  if callback.nil?
    []
  elsif callback.is_a?(Array)
    callback
  else
    [callback]
  end
end

#character_spacingObject



110
111
112
113
# File 'lib/prawn/text/formatted/fragment.rb', line 110

def character_spacing
  @format_state[:character_spacing] ||
    @document.character_spacing
end

#colorObject



98
99
100
# File 'lib/prawn/text/formatted/fragment.rb', line 98

def color
  @format_state[:color]
end

#default_direction=(direction) ⇒ Object



119
120
121
122
123
124
# File 'lib/prawn/text/formatted/fragment.rb', line 119

def default_direction=(direction)
  unless @format_state[:direction]
    @format_state[:direction] = direction
    @text = process_text(@original_text)
  end
end

#directionObject



115
116
117
# File 'lib/prawn/text/formatted/fragment.rb', line 115

def direction
  @format_state[:direction]
end

#fontObject



102
103
104
# File 'lib/prawn/text/formatted/fragment.rb', line 102

def font
  @format_state[:font]
end

#heightObject



40
41
42
# File 'lib/prawn/text/formatted/fragment.rb', line 40

def height
  top - bottom
end

#include_trailing_white_space!Object



126
127
128
129
# File 'lib/prawn/text/formatted/fragment.rb', line 126

def include_trailing_white_space!
  @format_state.delete(:exclude_trailing_white_space)
  @text = process_text(@original_text)
end


86
87
88
# File 'lib/prawn/text/formatted/fragment.rb', line 86

def link
  @format_state[:link]
end

#localObject



94
95
96
# File 'lib/prawn/text/formatted/fragment.rb', line 94

def local
  @format_state[:local]
end

#rightObject



146
147
148
# File 'lib/prawn/text/formatted/fragment.rb', line 146

def right
  left + width
end

#sizeObject



106
107
108
# File 'lib/prawn/text/formatted/fragment.rb', line 106

def size
  @format_state[:size]
end

#space_countObject



131
132
133
# File 'lib/prawn/text/formatted/fragment.rb', line 131

def space_count
  @text.count(" ")
end

#strikethrough_pointsObject



77
78
79
80
# File 'lib/prawn/text/formatted/fragment.rb', line 77

def strikethrough_points
  y = baseline + ascender * 0.3
  [[left, y], [right, y]]
end

#stylesObject



82
83
84
# File 'lib/prawn/text/formatted/fragment.rb', line 82

def styles
  @format_state[:styles] || []
end

#subscript?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/prawn/text/formatted/fragment.rb', line 44

def subscript?
  styles.include?(:subscript)
end

#superscript?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/prawn/text/formatted/fragment.rb', line 48

def superscript?
  styles.include?(:superscript)
end

#topObject



150
151
152
# File 'lib/prawn/text/formatted/fragment.rb', line 150

def top
  baseline + ascender
end

#top_leftObject



158
159
160
# File 'lib/prawn/text/formatted/fragment.rb', line 158

def top_left
  [left, top]
end

#top_rightObject



162
163
164
# File 'lib/prawn/text/formatted/fragment.rb', line 162

def top_right
  [right, top]
end

#underline_pointsObject



72
73
74
75
# File 'lib/prawn/text/formatted/fragment.rb', line 72

def underline_points
  y = baseline - 1.25
  [[left, y], [right, y]]
end

#y_offsetObject



52
53
54
55
56
57
# File 'lib/prawn/text/formatted/fragment.rb', line 52

def y_offset
  if subscript? then -descender
  elsif superscript? then 0.85 * ascender
  else 0
  end
end