Class: ZPNG::Chunk::ITXT

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

Instance Attribute Summary collapse

Attributes inherited from TextChunk

#keyword, #text

Attributes inherited from ZPNG::Chunk

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

Instance Method Summary collapse

Methods inherited from TextChunk

#inspect

Methods inherited from ZPNG::Chunk

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

Methods included from DeepCopyable

#deep_copy

Constructor Details

#initialize(*args) ⇒ ITXT

Returns a new instance of ITXT.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/zpng/text_chunk.rb', line 51

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



49
50
51
# File 'lib/zpng/text_chunk.rb', line 49

def cflag
  @cflag
end

#cmethodObject

compression flag & method



49
50
51
# File 'lib/zpng/text_chunk.rb', line 49

def cmethod
  @cmethod
end

#languageObject

Returns the value of attribute language.



50
51
52
# File 'lib/zpng/text_chunk.rb', line 50

def language
  @language
end

#translated_keywordObject

Returns the value of attribute translated_keyword.



50
51
52
# File 'lib/zpng/text_chunk.rb', line 50

def translated_keyword
  @translated_keyword
end

Instance Method Details

#to_hashObject



67
68
69
70
71
72
# File 'lib/zpng/text_chunk.rb', line 67

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