Class: PrawndownExt::Interface::CommandInterface
- Inherits:
-
Object
- Object
- PrawndownExt::Interface::CommandInterface
- Defined in:
- lib/prawndown-ext.rb
Constant Summary collapse
- COMMAND =
{ "text" => -> (args, pdf, ) { cl_text(args, pdf, ) }, "img" => -> (args, pdf, ) { cl_img(args, pdf, ) }, "quote" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header1" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header2" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header3" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header4" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header5" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header6" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "newpage" => -> (args,pdf, ) { cl_newline(args, pdf, ) } }
Class Method Summary collapse
- .cl_img(args, pdf, options) ⇒ Object
- .cl_newline(args, pdf, options) ⇒ Object
- .cl_text(args, pdf, options) ⇒ Object
- .cl_text_box(args, pdf, options) ⇒ Object
Instance Method Summary collapse
Class Method Details
.cl_img(args, pdf, options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/prawndown-ext.rb', line 55 def self.cl_img args, pdf, if .key?("no_image") if ["no_image"] return end end width = nil height = nil if .key?("image_width") width = ["image_width"].to_i end if .key?("image_height") height = ["image_height"].to_i end if width.nil? && height.nil? width = pdf.bounds.width end if !width.nil? width = [pdf.bounds.width, width].min end if args["path"][0] == "/" args["path"] = args["path"][1..-1] end file = ["image_dir"] + "/" + args["path"] if !File.file?(file) file = "." + ["image_dir"] + "/" + args["path"] end if File.extname(file) != ".gif" if !(height.nil? && width.nil?) if !.key?("image_pad") ["image_pad"] = 0 end pdf.pad ["image_pad"] do if height.nil? && !width.nil? pdf.image(file, width: [pdf.bounds.width, width].min, position: :center) elsif !height.nil? && width.nil? pdf.image(file, height: height, position: :center) else pdf.image(file, width: [pdf.bounds.width, width].min, height: height, position: :center) end end end end end |
.cl_newline(args, pdf, options) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/prawndown-ext.rb', line 119 def self.cl_newline args, pdf, if pdf.bounds.instance_of? Prawn::Document::ColumnBox pdf.bounds.move_past_bottom else pdf.start_new_page end end |
.cl_text(args, pdf, options) ⇒ Object
25 26 27 28 29 |
# File 'lib/prawndown-ext.rb', line 25 def self.cl_text args, pdf, pdf.text args["text"], inline_format: true, leading: ["default_line_spacing"].to_f end |
.cl_text_box(args, pdf, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/prawndown-ext.rb', line 31 def self.cl_text_box args, pdf, if !.key?(args["command"] + "_line_spacing") [args["command"] + "_line_spacing"] = 0 end if !.key?(args["command"] + "_horizontal_margin") [args["command"] + "_horizontal_margin"] = 0 end if !.key?(args["command"] + "_vertical_margin") [args["command"] + "_vertical_margin"] = 0 end margin = ([args["command"] + "_horizontal_margin"] * 0.5).floor half_margin = ([args["command"] + "_vertical_margin"] * 0.5).floor pdf.pad half_margin do pdf.indent margin, margin do pdf.text args["text"], inline_format: true, leading: [args["command"] + "_line_spacing"].to_f end end end |