Class: Hokusai::Clamping

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/font.rb

Defined Under Namespace

Classes: Char, Group, Segment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, markdown: false) ⇒ Clamping

Returns a new instance of Clamping.



198
199
200
201
# File 'ui/src/hokusai/font.rb', line 198

def initialize(raw, markdown: false)
  @markdown = markdown
  @raw = raw
end

Instance Attribute Details

#markdownObject (readonly)

Returns the value of attribute markdown.



196
197
198
# File 'ui/src/hokusai/font.rb', line 196

def markdown
  @markdown
end

#rawObject (readonly)

Returns the value of attribute raw.



196
197
198
# File 'ui/src/hokusai/font.rb', line 196

def raw
  @raw
end

Instance Method Details

#[](offset, size) ⇒ Object



235
236
237
# File 'ui/src/hokusai/font.rb', line 235

def [](offset, size)
  raw[:text][offset, size]
end

#debugObject



214
215
216
# File 'ui/src/hokusai/font.rb', line 214

def debug
  LibHokusai.hoku_text_clamp_debug(raw)
end

#each_segmentObject



218
219
220
221
222
223
224
225
226
227
228
229
# File 'ui/src/hokusai/font.rb', line 218

def each_segment
  segment = raw[:segments]
  i = 0

  until segment.null?
    yield Segment.new(segment), i
    i += 1


    segment = segment[:next_segment]
  end
end

#segmentsObject



203
204
205
206
207
208
209
210
211
212
# File 'ui/src/hokusai/font.rb', line 203

def segments
  return @segments unless @segments.nil?

  @segments = []
  each_segment do |segment|
    @segments << segment
  end

  @segments
end

#text(segment) ⇒ Object



231
232
233
# File 'ui/src/hokusai/font.rb', line 231

def text(segment)
  raw[:text][segment.offset, segment.size]
end

#to_aObject



239
240
241
242
243
# File 'ui/src/hokusai/font.rb', line 239

def to_a
  segments.map do |segment|
    text(segment)
  end
end