lib/rabbit/renderer/base.rb in rabbit-2.2.1 vs lib/rabbit/renderer/base.rb in rabbit-3.0.0
- old
+ new
@@ -1,5 +1,21 @@
+# Copyright (C) 2004-2019 Kouhei Sutou <kou@cozmixng.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
require "forwardable"
require "erb"
require "rabbit/gtk"
require "rabbit/rabbit"
@@ -16,10 +32,12 @@
include DirtyCount
def_delegators(:@canvas, :reload_source)
attr_reader :x_dpi, :y_dpi
+ attr_accessor :base_width
+ attr_accessor :base_height
attr_accessor :paper_width, :paper_height, :slides_per_page
attr_accessor :margin_left, :margin_right
attr_accessor :margin_top, :margin_bottom
attr_accessor :progress_foreground
attr_accessor :progress_background
@@ -32,13 +50,15 @@
def initialize(canvas)
super()
@canvas = canvas
@font_families = nil
+ @base_width = nil
+ @base_height = nil
@paper_width = nil
@paper_height = nil
- @slides_per_page = nil
+ @slides_per_page = 1
@margin_left = nil
@margin_right = nil
@margin_top = nil
@margin_bottom = nil
@page_margin_left = nil
@@ -154,20 +174,10 @@
end
def setup_event(area)
end
- def to_attrs(hash)
- hash.collect do |key, value|
- if value
- "#{h key}='#{h value}'"
- else
- nil
- end
- end.compact.join(" ")
- end
-
def clean
dirty_count_clean
end
def clean_if_dirty
@@ -288,29 +298,34 @@
canvas.toggle_index_mode if @canvas.index_mode?
canvas
end
def make_canvas_with_printable_renderer
- renderer = Renderer.printable_renderer(@canvas.slides_per_page)
+ renderer = Renderer::Printer
make_canvas_with_renderer(renderer) do |canvas|
canvas.filename = @canvas.filename
+ setup_size(canvas)
setup_margin(canvas)
setup_page_margin(canvas)
setup_paper_size(canvas)
setup_3d(canvas)
canvas.slides_per_page = @canvas.slides_per_page
end
end
def make_canvas_with_offscreen_renderer
make_canvas_with_renderer(Offscreen) do |canvas|
- canvas.width = @canvas.width
- canvas.height = @canvas.height
+ setup_size(canvas)
setup_3d(canvas)
end
end
+ def setup_size(canvas)
+ canvas.width = @canvas.width
+ canvas.height = @canvas.height
+ end
+
def setup_margin(canvas)
canvas.margin_left = @canvas.margin_left
canvas.margin_right = @canvas.margin_right
canvas.margin_top = @canvas.margin_top
canvas.margin_bottom = @canvas.margin_bottom
@@ -322,56 +337,15 @@
canvas.page_margin_top = @canvas.page_margin_top
canvas.page_margin_bottom = @canvas.page_margin_bottom
end
def setup_paper_size(canvas)
- if @canvas.paper_width and @canvas.paper_height
- canvas.paper_width = @canvas.paper_width
- canvas.paper_height = @canvas.paper_height
- else
- canvas.paper_width = @canvas.width
- canvas.paper_height = @canvas.height
- end
+ canvas.paper_width = @canvas.paper_width
+ canvas.paper_height = @canvas.paper_height
end
def setup_3d(canvas)
canvas.use_gl = @canvas.use_gl?
- end
-
- def setup_flag_params(pole_height, default_flag_width_ratio, params)
- params = params.dup
-
- text = params["text"]
- text_attrs = params["text_attributes"] || {}
- if text
- markupped_text = "<span #{to_attrs(text_attrs)}>#{text}</span>"
- layout = make_layout(markupped_text)
- text_width, text_height = layout.pixel_size
- params["layout"] = layout
- params["text_width"] = text_width
- params["text_height"] = text_height
- flag_width_default = [
- text_width * default_flag_width_ratio,
- pole_height / 2
- ].max
- flag_height_default = [text_height, flag_width_default].max
- else
- params["layout"] = nil
- flag_width_default = flag_height_default = nil
- end
-
- params["pole_width"] = params["pole_width"] || 2
- params["pole_color"] ||= "black"
- flag_height = params["flag_height"] ||
- flag_height_default || pole_height / 2
- flag_height = [flag_height, pole_height].min
- params["flag_height"] = flag_height
- params["flag_width"] ||= flag_width_default || flag_height
- params["flag_color"] ||= "red"
- params["flag_frame_width"] ||= params["pole_width"]
- params["flag_frame_color"] ||= params["pole_color"]
-
- params
end
def not_support_method(name)
format = _("%s does not support: %s")
msg = format % [self.class.name, name]