Skip to content

Commit

Permalink
resolves asciidoctor#1414 allow theme to set base text decoration width
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Dec 10, 2019
1 parent 75d26a1 commit a619d98
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* expose theme as property on converter
* add support for unbreakable option on open blocks (#1407) *@mogztter*
* don't add mailto: prefix to revealed mailto URI when hide-uri-scheme is set (#920)
* allow theme to set base text decoration width (#1414)

== 1.5.0.beta.8 (2019-11-23) - @mojavelinux

Expand Down
6 changes: 6 additions & 0 deletions docs/theming-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,12 @@ NOTE: While it's common to define additional keys in this category (e.g., `base-
line-height: >
$base-line-height-length /
$base-font-size

|text-decoration-width
|<<values,Number>> +
(default: 1)
|base:
text-decoration-width: 0.5
|===

. The `text-transform` key cannot be set globally.
Expand Down
3 changes: 3 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Converter < ::Prawn::Document

attr_reader :theme

attr_reader :text_decoration_width

# NOTE require_library doesn't support require_relative and we don't modify the load path for this gem
CodeRayRequirePath = ::File.join __dir__, 'ext/prawn/coderay_encoder'
RougeRequirePath = ::File.join __dir__, 'ext/rouge'
Expand Down Expand Up @@ -346,6 +348,7 @@ def init_pdf doc
@page_bg_color = resolve_theme_color :page_background_color, 'FFFFFF'
@root_font_size = theme.base_font_size || 12
@font_color = theme.base_font_color || '000000'
@text_decoration_width = theme.base_text_decoration_width
@base_align = (align = doc.attr 'text-align') && (TextAlignmentNames.include? align) ? align : theme.base_align
@cjk_line_breaks = doc.attr? 'scripts', 'cjk'
if (hyphen_lang = doc.attr 'hyphens') &&
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def draw_fragment_overlay_styles fragment
if (underline = (styles = fragment.styles).include? :underline) || (styles.include? :strikethrough)
(doc = fragment.document).save_graphics_state do
if (text_decoration_width = (fs = fragment.format_state)[:text_decoration_width])
if (text_decoration_width = (fs = fragment.format_state)[:text_decoration_width] || doc.text_decoration_width)
doc.line_width = text_decoration_width
end
if (text_decoration_color = fs[:text_decoration_color])
Expand Down
13 changes: 13 additions & 0 deletions spec/formatted_text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@
(expect lines[1][:width]).to be 2
end

it 'should allow theme to set base text decoration width' do
pdf_theme = {
base_text_decoration_width: 0.5,
role_underline_text_decoration_color: '0000AA',
}
input = '[.underline]#underline#'
pdf = to_pdf input, pdf_theme: pdf_theme, analyze: :line
lines = pdf.lines
(expect lines).to have_size 1
(expect lines[0][:color]).to eql '0000AA'
(expect lines[0][:width]).to eql 0.5
end

it 'should support size roles (big and small) in default theme' do
pdf_theme = build_pdf_theme
(expect pdf_theme.role_big_font_size).to be 13
Expand Down

0 comments on commit a619d98

Please sign in to comment.