diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-08-21 23:40:07 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-21 23:40:07 -0600 |
| commit | e899f364a4e48679d1fa4adb2a10dfe4e9e764f4 (patch) | |
| tree | 5005d93279f6bc6a0f2080bef5cebe10d68d7edf /lib | |
| parent | a2c637f931c091a0950b12f21a597ef1db1b3e87 (diff) | |
resolves #2318 allow theme to specify width for image-based admonition icons (PR #2319)
* introduce scale theme key for admonition icon to scale down icon without affecting layout
* introduce width theme key for admonition icon to control width of image-based icon
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 8492f667..bf0d5c33 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -40,12 +40,12 @@ module Asciidoctor OptimizerRequirePath = ::File.join __dir__, 'optimizer' AdmonitionIcons = { - caution: { name: 'fas-fire', stroke_color: 'BF3400', size: 24 }, - important: { name: 'fas-exclamation-circle', stroke_color: 'BF0000', size: 24 }, - note: { name: 'fas-info-circle', stroke_color: '19407C', size: 24 }, - tip: { name: 'far-lightbulb', stroke_color: '111111', size: 24 }, - warning: { name: 'fas-exclamation-triangle', stroke_color: 'BF6900', size: 24 }, - } + caution: { name: 'fas-fire', stroke_color: 'BF3400' }, + important: { name: 'fas-exclamation-circle', stroke_color: 'BF0000' }, + note: { name: 'fas-info-circle', stroke_color: '19407C' }, + tip: { name: 'far-lightbulb', stroke_color: '111111' }, + warning: { name: 'fas-exclamation-triangle', stroke_color: 'BF6900' }, + }.transform_values {|val| val.merge size: 36 } TextAlignmentNames = { 'justify' => true, 'left' => true, 'center' => true, 'right' => true } IndentableTextAlignments = { justify: true, left: true } TextAlignmentRoles = { 'text-justify' => true, 'text-left' => true, 'text-center' => true, 'text-right' => true } @@ -882,15 +882,16 @@ module Asciidoctor if !(has_icon = node.attr? 'icon') && (doc.attr 'icons') == 'font' icons = 'font' icon_data = admonition_icon_data type.to_sym - icon_size = icon_data[:size] || 24 - label_width = label_min_width || (icon_size * 1.5) + icon_size = (label_width = icon_data[:size] || 36) * (icon_data[:scale] || 2/3r).to_f + label_width = label_min_width if label_min_width && label_min_width > label_width elsif (icon_path = has_icon || !(icon_path = (@theme[%(admonition_icon_#{type})] || {})[:image]) ? (get_icon_image_path node, type) : (ThemeLoader.resolve_theme_asset (apply_subs_discretely doc, icon_path, subs: [:attributes], imagesdir: @themesdir), @themesdir)) && (::File.readable? icon_path) icons = true - # TODO: introduce @theme.admonition_image_width? or use size key from admonition_icon_<name>? - label_width = label_min_width || 36.0 + icon_data = admonition_icon_data type.to_sym + icon_width = (label_width = icon_data[:width] || 36) * (icon_data[:scale] || 2/3r).to_f + label_width = label_min_width if label_min_width && label_min_width > label_width else log :warn, %(admonition icon image#{has_icon ? '' : ' for ' + type.upcase} not found or not readable: #{icon_path || (get_icon_image_path node, type, false)}) end @@ -949,7 +950,7 @@ module Asciidoctor svg_obj = ::Prawn::SVG::Interface.new (::File.read icon_path, mode: 'r:UTF-8'), self, position: label_text_align, vposition: label_valign, - width: label_width, + width: icon_width, height: label_height, fallback_font_name: fallback_svg_font_name, enable_web_requests: allow_uri_read ? (method :load_open_uri).to_proc : false, @@ -969,7 +970,7 @@ module Asciidoctor image_obj, image_info = ::File.open(icon_path, 'rb') {|fd| build_image_object fd } icon_aspect_ratio = image_info.width.fdiv image_info.height # NOTE: don't scale image up if smaller than label_width - icon_width = [(to_pt image_info.width, :px), label_width].min + #icon_width = [(to_pt image_info.width, :px), icon_width].min if (icon_height = icon_width * (1 / icon_aspect_ratio)) > label_height icon_width *= label_height / icon_height end |
