Skip to content

Commit

Permalink
allow relative font size for sub and sup to be set independently; sup…
Browse files Browse the repository at this point in the history
…port combined setting for backwards compatibility
  • Loading branch information
mojavelinux committed Feb 11, 2024
1 parent 7d47b69 commit 1890840
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Improvements::
* process `pre-wrap` role in text formatter
* drop support for the unmaintained payment font (`pf`) for use in font-based icons
* refactor formatted text transform to simplify how inner space is collapsed; verify only inner hard breaks are preserved
* allow relative font size for sub and sup to be set independently; support combined setting for backwards compatibility

Bug Fixes::

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/theme/pages/text.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ However, you can adjust them in a Prawn patch by requiring the following Ruby sc
Prawn::Text::Formatted::Arranger.prepend (Module.new do
def initialize(*)
super
@sub_and_sup_relative_size = 0.75
@sup_relative_size = 0.75
end
end)

Expand Down
13 changes: 9 additions & 4 deletions lib/asciidoctor/pdf/ext/prawn/formatted_text/arranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize *_args
super
@dummy_text = ?\u0000
@normalize_line_height = false
@sub_and_sup_relative_size = 0.583
@sub_relative_size = @sup_relative_size = 0.583
end

def format_array= array
Expand Down Expand Up @@ -38,13 +38,18 @@ def preview_joined_string
end

def apply_font_size size, styles
if (subscript? styles) || (superscript? styles)
if (sub = subscript? styles) || (superscript? styles)
size ||= @document.font_size
if instance_variable_defined? :@sub_and_sup_relative_size
relative_size = @sub_and_sup_relative_size
else
relative_size = sub ? @sub_relative_size : @sup_relative_size
end
if String === size
units = (size.end_with? 'em', '%') ? ((size.end_with? '%') ? '%' : 'em') : ''
size = %(#{size.to_f * @sub_and_sup_relative_size}#{units})
size = %(#{size.to_f * relative_size}#{units})
else
size *= @sub_and_sup_relative_size
size *= relative_size
end
@document.font_size(size) { yield }
elsif size
Expand Down

0 comments on commit 1890840

Please sign in to comment.