diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2019-09-01 23:54:31 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-01 23:54:31 -0600 |
| commit | e94c85b0121e60c89b1dc4c4e67670d15bff1af3 (patch) | |
| tree | 1a87150003a716f68d4b353f7fbf5989319ea7b4 | |
| parent | b473ddfa4d83214adb32b0d27f41564ebaf108d5 (diff) | |
resolves #1243 allow font catalog and font fallbacks to be defined as flat keys in theme file (PR #1245)
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | lib/asciidoctor-pdf/theme_loader.rb | 35 | ||||
| -rw-r--r-- | spec/theme_loader_spec.rb | 18 |
3 files changed, 38 insertions, 19 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index cc9e5642..14a8acea 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -5,6 +5,10 @@ This document provides a high-level view of the changes to the {project-name} by release. For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub. +== Unreleased + +* allow font catalog and font fallbacks to be defined as flat keys in the theme file (#1243) + == 1.5.0.beta.3 (2019-08-30) - @mojavelinux * allow multiple font dirs to be specified using the pdf-fontsdir attribute (#80) diff --git a/lib/asciidoctor-pdf/theme_loader.rb b/lib/asciidoctor-pdf/theme_loader.rb index 0a23e31d..070674ce 100644 --- a/lib/asciidoctor-pdf/theme_loader.rb +++ b/lib/asciidoctor-pdf/theme_loader.rb @@ -122,29 +122,26 @@ class ThemeLoader key = key.tr '-', '_' if key.include? '-' if key == 'font' val.each do |subkey, subval| - if subkey == 'catalog' && ::Hash === subval - subval = subval.reduce({}) do |accum, (name, styles)| - if ::Hash === styles - accum[name] = styles.reduce({}) do |subaccum, (style, path)| - if (path.start_with? 'GEM_FONTS_DIR') && (sep = path[13]) - path = %(#{FontsDir}#{sep}#{path.slice 14, path.length}) - end - subaccum[style] = expand_vars path, data - subaccum - end - else - accum[name] = styles - end - accum + process_entry %(#{key}_#{subkey}), subval, data if subkey == 'catalog' || subkey == 'fallbacks' + end if ::Hash === val + elsif key == 'font_catalog' + data[key] = ::Hash === val ? val.reduce({}) {|accum, (name, styles)| + accum[name] = styles.reduce({}) do |subaccum, (style, path)| + if (path.start_with? 'GEM_FONTS_DIR') && (sep = path[13]) + path = %(#{FontsDir}#{sep}#{path.slice 14, path.length}) end - end - data[%(font_#{subkey})] = subval - end + subaccum[style] = expand_vars path, data + subaccum + end if ::Hash === styles + accum + } : {} + elsif key == 'font_fallbacks' + data[key] = ::Array === val ? val.map {|name| expand_vars name.to_s, data } : [] elsif key.start_with? 'admonition_icon_' - data[key] = (val || {}).map do |(key2, val2)| + data[key] = val ? val.map {|(key2, val2)| key2 = key2.tr '-', '_' if key2.include? '-' [key2.to_sym, (key2.end_with? '_color') ? to_color(evaluate val2, data) : (evaluate val2, data)] - end.to_h + }.to_h : {} elsif ::Hash === val val.each {|subkey, subval| process_entry %(#{key}_#{subkey}), subval, data } elsif key.end_with? '_color' diff --git a/spec/theme_loader_spec.rb b/spec/theme_loader_spec.rb index f3ffaef0..5a10ab8b 100644 --- a/spec/theme_loader_spec.rb +++ b/spec/theme_loader_spec.rb @@ -79,6 +79,24 @@ describe Asciidoctor::PDF::ThemeLoader do (expect theme.ulist_marker_disc_content).to eql '0' (expect theme.footer_recto_left_content).to eql 'true' end + + it 'should allow font catalog and font fallbacks to be defined as flat keys' do + theme_data = SafeYAML.load <<~EOS + font_catalog: + Serif: + normal: /path/to/serif-font.ttf + Fallback: + normal: /path/to/fallback-font.ttf + font_fallbacks: + - Fallback + EOS + theme = subject.new.load theme_data + (expect theme.font_catalog).to be_a Hash + (expect theme.font_catalog['Serif']).to be_a Hash + (expect theme.font_catalog['Serif']['normal']).to eql '/path/to/serif-font.ttf' + (expect theme.font_fallbacks).to be_a Array + (expect theme.font_fallbacks).to eql ['Fallback'] + end end context '.load_file' do |
