class Xlsxrb::Ooxml::Reader::DrawingImagesListener
SAX2 listener for parsing drawing XML to extract image information.
Attributes
Public Class Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 4233 def initialize @images = [] @current_image = nil @inside_anchor = false @inside_pic = false @inside_from = false @inside_to = false @current_field = nil @text_buffer = +"" @anchor_from = {} @anchor_to = {} @inside_ln = false @inside_solid_fill = false end
Public Instance Methods
Source
# File lib/xlsxrb/ooxml/reader.rb, line 4323 def characters(text) @text_buffer << text if @current_field end
# File lib/xlsxrb/ooxml/reader.rb, line 4327 def end_element(_uri, local_name, qname) name = element_name(local_name, qname) case name when "pic" if @current_image && !@current_image.empty? @anchor_from.each { |k, v| @current_image[:"from_#{k}"] = v } @anchor_to.each { |k, v| @current_image[:"to_#{k}"] = v } @current_image[:edit_as] = @anchor_edit_as if @anchor_edit_as @images << @current_image end @current_image = nil @inside_pic = false when "twoCellAnchor", "oneCellAnchor" @images.last[:locks_with_sheet] = @anchor_locks_with_sheet == "1" if @anchor_locks_with_sheet && !@images.empty? @images.last[:prints_with_sheet] = @anchor_prints_with_sheet == "1" if @anchor_prints_with_sheet && !@images.empty? @images.last[:published] = true if @anchor_published && !@images.empty? @inside_anchor = false @anchor_from = {} @anchor_to = {} @anchor_locks_with_sheet = nil @anchor_prints_with_sheet = nil @anchor_published = false when "from" @inside_from = false when "to" @inside_to = false when "ln" @inside_ln = false when "solidFill" @inside_solid_fill = false when "col", "colOff", "row", "rowOff" if @current_field val = @text_buffer.to_i if @inside_from @anchor_from[@current_field] = val elsif @inside_to @anchor_to[@current_field] = val end end @current_field = nil end end
# File lib/xlsxrb/ooxml/reader.rb, line 4248 def start_element(_uri, local_name, qname, attributes) name = element_name(local_name, qname) case name when "twoCellAnchor", "oneCellAnchor" @inside_anchor = true @anchor_from = {} @anchor_to = {} @anchor_edit_as = attributes["editAs"] @anchor_published = %w[1 true].include?(attributes["fPublished"]) when "pic" @inside_pic = true @current_image = {} @current_image[:macro] = attributes["macro"] if attributes["macro"] && !attributes["macro"].empty? when "cNvPr" if @inside_pic && @current_image @current_image[:name] = attributes["name"] if attributes["name"] @current_image[:id] = attributes["id"]&.to_i @current_image[:description] = attributes["descr"] if attributes["descr"] @current_image[:title] = attributes["title"] if attributes["title"] @current_image[:hidden] = %w[1 true].include?(attributes["hidden"]) if attributes["hidden"] end when "blip" rid = attributes["r:embed"] || attributes["embed"] @current_image[:embed_rid] = rid if @inside_pic && @current_image && rid when "alphaModFix" @current_image[:alpha_mod_fix] = attributes["amt"].to_i if @inside_pic && @current_image && attributes["amt"] when "srcRect" if @inside_pic && @current_image sr = {} sr[:top] = attributes["t"].to_i if attributes["t"] sr[:bottom] = attributes["b"].to_i if attributes["b"] sr[:left] = attributes["l"].to_i if attributes["l"] sr[:right] = attributes["r"].to_i if attributes["r"] @current_image[:src_rect] = sr unless sr.empty? end when "picLocks" if @inside_pic && @current_image @current_image[:no_change_aspect] = true if %w[1 true].include?(attributes["noChangeAspect"]) @current_image[:no_crop] = true if %w[1 true].include?(attributes["noCrop"]) end when "ln" if @inside_pic && @current_image @inside_ln = true @current_image[:line_width] = attributes["w"].to_i if attributes["w"] end when "solidFill" @inside_solid_fill = true if @inside_pic when "srgbClr" @current_image[:line_color] = attributes["val"] if @inside_pic && @current_image && @inside_solid_fill && @inside_ln && attributes["val"] when "schemeClr" @current_image[:line_color] = { scheme: attributes["val"] } if @inside_pic && @current_image && @inside_solid_fill && @inside_ln && attributes["val"] when "xfrm" @current_image[:rotation] = attributes["rot"].to_i if @inside_pic && @current_image && attributes["rot"] when "from" @inside_from = true if @inside_anchor when "to" @inside_to = true if @inside_anchor when "ext" if @inside_pic && @current_image cx = attributes["cx"] cy = attributes["cy"] @current_image[:cx] = cx.to_i if cx @current_image[:cy] = cy.to_i if cy end when "col", "colOff", "row", "rowOff" @current_field = name @text_buffer = +"" when "clientData" if @inside_anchor @anchor_locks_with_sheet = attributes["fLocksWithSheet"] @anchor_prints_with_sheet = attributes["fPrintsWithSheet"] end end end