Class: Shellfie::Renderer
- Inherits:
-
Object
- Object
- Shellfie::Renderer
- Defined in:
- lib/shellfie/renderer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#font_resolver ⇒ Object
readonly
Returns the value of attribute font_resolver.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
- #estimate(scale: 1, shadow: true) ⇒ Object
- #font_info ⇒ Object
-
#initialize(config, chrome_cache: nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(output_path, scale: 1, shadow: true, transparent: false, format: nil, io: nil) ⇒ Object
Constructor Details
#initialize(config, chrome_cache: nil) ⇒ Renderer
Returns a new instance of Renderer.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/shellfie/renderer.rb', line 22 def initialize(config, chrome_cache: nil) @config = config @chrome_cache = chrome_cache @theme = ThemeRegistry.build(config) @ansi_parser = AnsiParser.new( state_mode: config.window[:ansi_state] || :persistent, tab_width: config.window[:tab_width], osc_policy: config.window[:osc_policy], graphics_policy: config.window[:graphics_policy] ) @font_resolver = FontResolver.new(-> { imagemagick_command }) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/shellfie/renderer.rb', line 20 def config @config end |
#font_resolver ⇒ Object (readonly)
Returns the value of attribute font_resolver.
20 21 22 |
# File 'lib/shellfie/renderer.rb', line 20 def font_resolver @font_resolver end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
20 21 22 |
# File 'lib/shellfie/renderer.rb', line 20 def theme @theme end |
Instance Method Details
#estimate(scale: 1, shadow: true) ⇒ Object
47 48 49 50 |
# File 'lib/shellfie/renderer.rb', line 47 def estimate(scale: 1, shadow: true) geometry = build_geometry(build_lines, scale: scale, shadow: shadow) geometry.slice(:canvas_width, :canvas_height, :scaled_width, :scaled_height, :logical_width, :logical_height, :scale) end |
#font_info ⇒ Object
52 53 54 |
# File 'lib/shellfie/renderer.rb', line 52 def font_info font_resolver.details(theme.font) end |
#render(output_path, scale: 1, shadow: true, transparent: false, format: nil, io: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/shellfie/renderer.rb', line 35 def render(output_path, scale: 1, shadow: true, transparent: false, format: nil, io: nil) extension = FormatResolver.resolve(output_path, explicit: format, default: "png") check_dependencies! unless %w[svg html].include?(extension) lines = build_lines OutputWriter.write(output_path, extension: extension, io: io) do |temporary_path| render_method = { "svg" => :create_svg_image, "svg-raster" => :create_svg_raster_image, "html" => :create_html }.fetch(extension, :create_image) send(render_method, lines, temporary_path, scale: scale, shadow: shadow, transparent: transparent) end rescue MiniMagick::Error => e raise RenderError.new("ImageMagick render failed: #{e.}", category: :render) end |