Module: ODT2HTML::AnalyzeGraphics
- Included in:
- Base
- Defined in:
- lib/odt2html-nsi/analyze_graphics.rb
Instance Method Summary collapse
- #copy_image_file(pic_name, directory, filename) ⇒ Object
- #process_draw_frame(element, output_node) ⇒ Object
-
#process_draw_image(element, output_node) ⇒ Object
Copy an image into user-specified directory, and emit a corresponding
<img>
element.
Instance Method Details
#copy_image_file(pic_name, directory, filename) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/odt2html-nsi/analyze_graphics.rb', line 50 def copy_image_file( pic_name, directory, filename ) zipfile = Zip::ZipFile::open( @input_filename ) inStream = zipfile.get_entry( pic_name ) if (inStream != nil) then inStream = inStream.get_input_stream outStream = File.new("#{directory}#{File::SEPARATOR}#{filename}", "w") outStream.binmode buf = inStream.read outStream.print buf outStream.close inStream.close end zipfile.close rescue Exception => e # # Uncomment next line if you want error output # $stderr.puts "Could not find image #{pic_name}" end |
#process_draw_frame(element, output_node) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/odt2html-nsi/analyze_graphics.rb', line 4 def process_draw_frame( element, output_node ) style_name = register_style( element ); div = emit_element( output_node, "div", {"class" => style_name} ) attr = element.attribute("#{@svg_ns}:width") if (attr != nil) then modify_style_attribute( div, "width", attr.value ) end attr = element.attribute("#{@svg_ns}:height") if (attr != nil) then modify_style_attribute( div, "height", attr.value ) end process_children( element, div ) end |
#process_draw_image(element, output_node) ⇒ Object
Copy an image into user-specified directory, and emit a corresponding <img>
element.
If the user has not specified an image directory, then emit a <div>
containing the file name.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/odt2html-nsi/analyze_graphics.rb', line 25 def process_draw_image( element, output_node ) pic_name = element.attribute("#{@xlink_ns}:href").value if (@image_dir != nil) then img = emit_element( output_node, "img" ) img.attributes["alt"] = pic_name # Get rid of everything before the last / in the filename base_name = pic_name; if ((pos = base_name.rindex('/')) != nil) then base_name = base_name[pos + 1 .. -1] end copy_image_file( pic_name, @image_dir, base_name ) img.attributes["src"] = "#{@image_dir}/#{base_name}" width = element.parent.attribute("#{@svg_ns}:width") height= element.parent.attribute("#{@svg_ns}:height") if (width != nil && height != nil) then img.attributes["style"] = "width:#{width.value}; " + "height:#{height.value}" end else div = emit_element( output_node, "div" ) div.add_text( pic_name ) end end |