Class: ZPNG::Chunk::ITXT

Inherits:
TextChunk show all
Defined in:
lib/zpng/text_chunk.rb

Constant Summary

Constants inherited from TextChunk

TextChunk::INTEGER_CLASS

Constants inherited from ZPNG::Chunk

KNOWN_TYPES, VALID_SIZE_RANGE

Instance Attribute Summary collapse

Attributes inherited from TextChunk

#keyword, #text

Attributes inherited from ZPNG::Chunk

#crc, #data, #idx, #offset, #size, #type

Instance Method Summary collapse

Methods inherited from TextChunk

#inspect

Methods inherited from ZPNG::Chunk

#check, #crc_ok?, #export, #export_data, #fix_crc!, from_stream, #inspect, #valid?

Methods included from DeepCopyable

#deep_copy

Constructor Details

#initialize(*args) ⇒ ITXT

Returns a new instance of ITXT.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zpng/text_chunk.rb', line 57

def initialize *args
  super
  # The text, unlike the other strings, is not null-terminated; its length is implied by the chunk length.
  # http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.iTXt
  @keyword, @cflag, @cmethod, @language, @translated_keyword, @text = data.unpack('Z*CCZ*Z*a*')
  if @cflag == 1 && @cmethod == 0
    @text = Zlib::Inflate.inflate(@text)
  end
  if @text
    @text.force_encoding('utf-8') rescue nil
  end
  if @translated_keyword
    @translated_keyword.force_encoding('utf-8') rescue nil
  end
end

Instance Attribute Details

#cflagObject

compression flag & method



55
56
57
# File 'lib/zpng/text_chunk.rb', line 55

def cflag
  @cflag
end

#cmethodObject

compression flag & method



55
56
57
# File 'lib/zpng/text_chunk.rb', line 55

def cmethod
  @cmethod
end

#languageObject

Returns the value of attribute language.



56
57
58
# File 'lib/zpng/text_chunk.rb', line 56

def language
  @language
end

#translated_keywordObject

Returns the value of attribute translated_keyword.



56
57
58
# File 'lib/zpng/text_chunk.rb', line 56

def translated_keyword
  @translated_keyword
end

Instance Method Details

#to_hashObject



73
74
75
76
77
78
# File 'lib/zpng/text_chunk.rb', line 73

def to_hash
  super.tap do |h|
    h[:language] = @language if @language || !@language.empty?
    h[:translated_keyword] = @translated_keyword if @translated_keyword || !@translated_keyword.empty?
  end
end