Class: Przn::PdfExporter
- Inherits:
-
Object
- Object
- Przn::PdfExporter
- Defined in:
- lib/przn/pdf_exporter.rb
Constant Summary collapse
- PAGE_WIDTH =
960- PAGE_HEIGHT =
540- DEFAULT_FONT_SIZE =
18- DEFAULT_SCALE_TO_PT =
{ 1 => 10, 2 => 18, 3 => 24, 4 => 32, 5 => 40, 6 => 48, 7 => 56, }.freeze
- DEFAULT_SCALE =
Renderer::DEFAULT_SCALE
- COLOR_MAP =
{ 'red' => 'FF5555', 'green' => '50FA7B', 'yellow' => 'F1FA8C', 'blue' => '6272A4', 'magenta' => 'FF79C6', 'cyan' => '8BE9FD', 'white' => 'F8F8F2', 'bright_red' => 'FF6E6E', 'bright_green' => '69FF94', 'bright_yellow' => 'FFFFA5', 'bright_blue' => 'D6ACFF', 'bright_magenta' => 'FF92DF', 'bright_cyan' => 'A4FFFF', 'bright_white' => 'FFFFFF', }.freeze
- FONT_SEARCH_PATHS =
Fallback font paths when fc-match is not available. Prawn’s ttfunk requires TrueType outlines (glyf table), not CFF-based fonts.
[ -> { File.join(Dir.home, 'Library/Fonts/NotoSansJP-Regular.ttf') }, -> { Dir.glob('/usr/share/fonts/**/NotoSansCJK-Regular.ttc').first }, -> { Dir.glob('/usr/share/fonts/**/NotoSansJP-Regular.ttf').first }, -> { File.join(Dir.home, 'Library/Fonts/HackGen-Regular.ttf') }, -> { '/Library/Fonts/Arial Unicode.ttf' }, -> { '/System/Library/Fonts/Supplemental/Arial Unicode.ttf' }, ].freeze
- FALLBACK_FONT_FAMILIES =
%w[NotoSansCJK NotoSansJP HackGen].freeze
Instance Method Summary collapse
- #export(output_path) ⇒ Object
-
#initialize(presentation, base_dir: '.', theme: nil) ⇒ PdfExporter
constructor
A new instance of PdfExporter.
Constructor Details
#initialize(presentation, base_dir: '.', theme: nil) ⇒ PdfExporter
Returns a new instance of PdfExporter.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/przn/pdf_exporter.rb', line 54 def initialize(presentation, base_dir: '.', theme: nil) @presentation = presentation @base_dir = base_dir @theme = theme || Theme.default @bg_color = @theme.colors[:background] @fg_color = @theme.colors[:foreground] @code_bg = @theme.colors[:code_bg] @dim_color = @theme.colors[:dim] @inline_code_color = @theme.colors[:inline_code] @heading_color = @theme.colors[:heading] || @fg_color base = (@theme.font[:size] || DEFAULT_FONT_SIZE).to_f ratio = base / DEFAULT_FONT_SIZE @scale_to_pt = DEFAULT_SCALE_TO_PT.transform_values { |v| v * ratio } end |
Instance Method Details
#export(output_path) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/przn/pdf_exporter.rb', line 82 def export(output_path) require 'prawn' Prawn::Text::Formatted::LineWrap.prepend(PrawnCJKLineWrap) unless Prawn::Text::Formatted::LineWrap < PrawnCJKLineWrap pdf = Prawn::Document.new( page_size: [PAGE_WIDTH, PAGE_HEIGHT], margin: 0, ) register_fonts(pdf) @presentation..each_with_index do |, si| pdf.start_new_page unless si == 0 (pdf, , si) end pdf.render_file(output_path) end |