Class: ZIMG::PNG::Chunk::ITXT
- Inherits:
-
TextChunk
- Object
- Chunk
- ZIMG::PNG::Chunk
- TextChunk
- ZIMG::PNG::Chunk::ITXT
- Defined in:
- lib/zimg/png/text_chunks.rb
Constant Summary
Constants inherited from TextChunk
Constants inherited from ZIMG::PNG::Chunk
Instance Attribute Summary collapse
-
#cflag ⇒ Object
compression flag & method.
-
#cmethod ⇒ Object
compression flag & method.
-
#language ⇒ Object
compression flag & method.
-
#translated_keyword ⇒ Object
compression flag & method.
Attributes inherited from TextChunk
Attributes inherited from ZIMG::PNG::Chunk
#crc, #data, #idx, #offset, #size, #type
Instance Method Summary collapse
-
#initialize(*args) ⇒ ITXT
constructor
A new instance of ITXT.
- #to_hash ⇒ Object
Methods inherited from TextChunk
Methods inherited from ZIMG::PNG::Chunk
#check, #crc_ok?, #export, #export_data, #fix_crc!, from_stream, #inspect, #valid?
Methods included from DeepCopyable
Methods inherited from Chunk
Constructor Details
#initialize(*args) ⇒ ITXT
Returns a new instance of ITXT.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/zimg/png/text_chunks.rb', line 58 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*") @text = Zlib::Inflate.inflate(@text) if @cflag == 1 && @cmethod == 0 if @text begin @text.force_encoding("utf-8") rescue StandardError nil end end return unless @translated_keyword begin @translated_keyword.force_encoding("utf-8") rescue StandardError nil end end |
Instance Attribute Details
#cflag ⇒ Object
compression flag & method
56 57 58 |
# File 'lib/zimg/png/text_chunks.rb', line 56 def cflag @cflag end |
#cmethod ⇒ Object
compression flag & method
56 57 58 |
# File 'lib/zimg/png/text_chunks.rb', line 56 def cmethod @cmethod end |
#language ⇒ Object
compression flag & method
56 57 58 |
# File 'lib/zimg/png/text_chunks.rb', line 56 def language @language end |
#translated_keyword ⇒ Object
compression flag & method
56 57 58 |
# File 'lib/zimg/png/text_chunks.rb', line 56 def translated_keyword @translated_keyword end |
Instance Method Details
#to_hash ⇒ Object
80 81 82 83 84 85 |
# File 'lib/zimg/png/text_chunks.rb', line 80 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 |