diff options
| author | Guillaume Grossetie <ggrossetie@gmail.com> | 2019-08-30 11:21:14 +0200 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2019-08-30 03:21:14 -0600 |
| commit | 4e6e5d9ca61748d974081c1596cfa68bb5d4ed51 (patch) | |
| tree | da2ded4b6f6b9d96479ed7054a187568150673d0 | |
| parent | 1e634a8de07aec3cae8b36cd9d29b7fe37aeab66 (diff) | |
resolves #1223 allow to define text background and border for phrase with custom role (PR #1239)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor-pdf/formatted_text/transform.rb | 8 | ||||
| -rw-r--r-- | spec/reference/text-formatter-inline-role-bg.pdf | 177 | ||||
| -rw-r--r-- | spec/text_formatter_spec.rb | 15 |
4 files changed, 201 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index b20f5a0b..4158dbd4 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -44,6 +44,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * allow attribute reference in running content to be escaped using a backslash * fix crash if source-highlighter attribute is defined outside the header (#1231) * fix crash when aligning line numbers of source highlighted with Pygments (#1233) +* allow theme to configure text background and border on marks elements (#1223) == 1.5.0.beta.2 (2019-07-30) - @mojavelinux diff --git a/lib/asciidoctor-pdf/formatted_text/transform.rb b/lib/asciidoctor-pdf/formatted_text/transform.rb index 88811ee5..6690c2b0 100644 --- a/lib/asciidoctor-pdf/formatted_text/transform.rb +++ b/lib/asciidoctor-pdf/formatted_text/transform.rb @@ -16,6 +16,11 @@ class Transform CharRefRx = /&(?:(#{CharEntityTable.keys.join ?|})|#(?:(\d\d\d{0,4})|x([a-f\d][a-f\d][a-f\d]{0,3})));/ TextDecorationTable = { 'underline' => :underline, 'line-through' => :strikethrough } ThemeKeyToFragmentProperty = { + 'background_color' => :background_color, + 'border_color' => :border_color, + 'border_offset' => :border_offset, + 'border_radius' => :border_radius, + 'border_width' => :border_width, 'font_color' => :color, 'font_family' => :font, 'font_size' => :size, @@ -321,6 +326,9 @@ class Transform styles << :strikethrough else fragment.update(@theme_settings[class_name]) {|k, oval, nval| k == :styles ? oval.merge(nval) : oval } if @theme_settings.key? class_name + if fragment[:background_color] || (fragment[:border_color] && fragment[:border_width]) + ((fragment[:callback] ||= []) << TextBackgroundAndBorderRenderer).uniq! + end end end if attrs.key?(:class) fragment.delete(:styles) if styles.empty? diff --git a/spec/reference/text-formatter-inline-role-bg.pdf b/spec/reference/text-formatter-inline-role-bg.pdf new file mode 100644 index 00000000..cffba8de --- /dev/null +++ b/spec/reference/text-formatter-inline-role-bg.pdf @@ -0,0 +1,177 @@ +%PDF-1.4 +%ÿÿÿÿ +1 0 obj +<< /Title (Untitled) +/Creator (Asciidoctor PDF 1.5.0.beta.3.dev, based on Prawn 2.2.2) +/Producer (Asciidoctor PDF 1.5.0.beta.3.dev, based on Prawn 2.2.2) +/ModDate (D:20190830090105+02'00') +/CreationDate (D:20190830090105+02'00') +>> +endobj +2 0 obj +<< /Type /Catalog +/Pages 3 0 R +/Names 9 0 R +/Outlines 12 0 R +/PageLabels 14 0 R +/PageMode /UseOutlines +/OpenAction [7 0 R /FitH 841.89] +/ViewerPreferences << /DisplayDocTitle true +>> +>> +endobj +3 0 obj +<< /Type /Pages +/Count 1 +/Kids [7 0 R] +>> +endobj +4 0 obj +<< /Length 2 +>> +stream +q + +endstream +endobj +5 0 obj +<< /Type /Page +/Parent 3 0 R +/MediaBox [0 0 595.28 841.89] +/CropBox [0 0 595.28 841.89] +/BleedBox [0 0 595.28 841.89] +/TrimBox [0 0 595.28 841.89] +/ArtBox [0 0 595.28 841.89] +/Contents 4 0 R +/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +>> +endobj +6 0 obj +<< /Length 762 +>> +stream +q +/DeviceRGB cs +1.0 1.0 1.0 scn +/DeviceRGB CS +1.0 1.0 1.0 SCN +0.8118 0.1608 0.4549 scn +48.99 806.39 m +89.49 806.39 l +90.5946 806.39 91.49 805.4946 91.49 804.39 c +91.49 798.03 l +91.49 796.9254 90.5946 796.03 89.49 796.03 c +48.99 796.03 l +47.8854 796.03 46.99 796.9254 46.99 798.03 c +46.99 804.39 l +46.99 805.4946 47.8854 806.39 48.99 806.39 c +h +f +1.0 1.0 1.0 scn +0.9294 0.2235 0.5412 SCN +1 w +48.99 806.39 m +89.49 806.39 l +90.5946 806.39 91.49 805.4946 91.49 804.39 c +91.49 798.03 l +91.49 796.9254 90.5946 796.03 89.49 796.03 c +48.99 796.03 l +47.8854 796.03 46.99 796.9254 46.99 798.03 c +46.99 804.39 l +46.99 805.4946 47.8854 806.39 48.99 806.39 c +h +S +1.0 1.0 1.0 SCN +1 w + +BT +48.24 798.85 Td +/F2.0 10 Tf +[<636f756e746572>] TJ +ET + +0.0 0.0 0.0 SCN +0.0 0.0 0.0 scn +Q + +endstream +endobj +7 0 obj +<< /Type /Page +/Parent 3 0 R +/MediaBox [0 0 595.28 841.89] +/CropBox [0 0 595.28 841.89] +/BleedBox [0 0 595.28 841.89] +/TrimBox [0 0 595.28 841.89] +/ArtBox [0 0 595.28 841.89] +/Contents 6 0 R +/Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +/Font << /F2.0 11 0 R +>> +>> +>> +endobj +8 0 obj +[7 0 R /XYZ 0 841.89 null] +endobj +9 0 obj +<< /Type /Names +/Dests 10 0 R +>> +endobj +10 0 obj +<< /Names [(__anchor-top) 8 0 R] +>> +endobj +11 0 obj +<< /Type /Font +/Subtype /Type1 +/BaseFont /Courier +/Encoding /WinAnsiEncoding +>> +endobj +12 0 obj +<< /Type /Outlines +/Count 1 +/First 13 0 R +/Last 13 0 R +>> +endobj +13 0 obj +<< /Title <feff0055006e007400690074006c00650064> +/Parent 12 0 R +/Count 0 +/Dest [7 0 R /XYZ 0 841.89 null] +>> +endobj +14 0 obj +<< /Nums [0 << /P (1) +>>] +>> +endobj +xref +0 15 +0000000000 65535 f +0000000015 00000 n +0000000262 00000 n +0000000463 00000 n +0000000520 00000 n +0000000571 00000 n +0000000843 00000 n +0000001656 00000 n +0000001953 00000 n +0000001995 00000 n +0000002043 00000 n +0000002095 00000 n +0000002191 00000 n +0000002265 00000 n +0000002390 00000 n +trailer +<< /Size 15 +/Root 2 0 R +/Info 1 0 R +>> +startxref +2435 +%%EOF diff --git a/spec/text_formatter_spec.rb b/spec/text_formatter_spec.rb index cedfc9f0..e90611b0 100644 --- a/spec/text_formatter_spec.rb +++ b/spec/text_formatter_spec.rb @@ -238,5 +238,20 @@ describe Asciidoctor::PDF::FormattedText::Formatter do (expect text[1][:font_size]).to eql 12 (expect text[2][:font_size].to_f.round 2).to eql 10.0 end + + it 'should allow theme to override background and border for custom role', integration: true do + theme_overrides = { + role_variable_font_family: 'Courier', + role_variable_font_size: 10, + role_variable_font_color: 'FFFFFF', + role_variable_background_color: 'CF2974', + role_variable_border_color: 'ED398A', + role_variable_border_offset: 1.25, + role_variable_border_radius: 2, + role_variable_border_width: 1 + } + to_file = to_pdf_file '[.variable]#counter#', 'text-formatter-inline-role-bg.pdf', pdf_theme: theme_overrides + (expect to_file).to visually_match 'text-formatter-inline-role-bg.pdf' + end end end |
