Add support for images

This commit is contained in:
2025-12-02 11:43:25 +01:00
parent 15493da657
commit 980192253f
15 changed files with 481 additions and 6 deletions

View File

@@ -21,6 +21,7 @@ module Ezdoc
@current_table = nil
@current_row = nil
@num_id_counter = 0
@images = {}
end
def save(path)
@@ -30,5 +31,26 @@ module Ezdoc
def lists
@nodes.select { |n| n.is_a?(Nodes::List) }
end
def images
@images.values
end
def register_image(path, width: nil, height: nil)
return @images[path] if @images[path]
rid = next_image_rid
width_emu, height_emu = ImageDimensions.calculate_emus(path, width: width, height: height)
image = Nodes::Image.new(path, rid: rid, width_emu: width_emu, height_emu: height_emu)
@images[path] = image
image
end
private
def next_image_rid
base = lists.any? ? 2 : 1
"rId#{base + @images.size}"
end
end
end