Skip to content

Commit ff4e70e

Browse files
committed
resolves #2547 allow value of base-font-size-min and <category>-font-size-min theme keys to be relative
1 parent 54f2cd5 commit ff4e70e

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

CHANGELOG.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Improvements::
3838
* drop support for the unmaintained payment font (`pf`) for use in font-based icons
3939
* refactor formatted text transform to simplify how inner space is collapsed; verify only inner hard breaks are preserved
4040
* allow relative font size for sub and sup to be set independently; support combined setting for backwards compatibility
41+
* allow value of `base-font-size-min` and `<category>-font-size-min` theme keys to be relative (e.g., 0.75em) (#2547)
4142
* upgrade prawn-svg to 0.36 to fix dependencies, improve gradient support, and support additional properties; disable experimental warnings when requiring prawn-svg on Ruby 2.7 (#2551)
4243

4344
Bug Fixes::

docs/modules/theme/pages/base.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ base:
5959
font-size: 10.5
6060

6161
|font-size-min
62-
|xref:language.adoc#values[Number] +
62+
|xref:text.adoc#font-size[Font size] +
6363
(default: `6`)
6464
|[source]
6565
base:
66-
font-size-min: $base-font-size * 0.75
66+
font-size-min: 0.75rem
6767

6868
|font-style
6969
|xref:text.adoc#font-style[Font style] +

lib/asciidoctor/pdf/converter.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -4836,14 +4836,27 @@ def compute_autofit_font_size fragments, category
48364836
padding = expand_padding_value @theme[%(#{category}_padding)]
48374837
if actual_width > (available_width = bounds.width - padding[3].to_f - padding[1].to_f)
48384838
adjusted_font_size = ((available_width * font_size).to_f / actual_width).truncate 4
4839-
if (min = @theme[%(#{category}_font_size_min)] || @theme.base_font_size_min) && adjusted_font_size < min
4839+
if (min = @theme[%(#{category}_font_size_min)] || @theme.base_font_size_min) && adjusted_font_size < (min = resolve_font_size min)
48404840
min
48414841
else
48424842
adjusted_font_size
48434843
end
48444844
end
48454845
end
48464846

4847+
def resolve_font_size value
4848+
return value unless ::String === value
4849+
if value.end_with? 'rem'
4850+
@root_font_size * value.to_f
4851+
elsif value.end_with? 'em'
4852+
font_size * value.to_f
4853+
elsif value.end_with? '%'
4854+
font_size * (value.to_f / 100)
4855+
else
4856+
value.to_f
4857+
end
4858+
end
4859+
48474860
def consolidate_ranges nums
48484861
if nums.size > 1
48494862
prev = nil

spec/listing_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,30 @@
358358
end
359359
end
360360

361+
it 'should allow base minimum font size to be specified relative to base font size' do
362+
pdf = to_pdf <<~'END', pdf_theme: { base_font_size: 12, base_font_size_min: '0.5rem' }, analyze: true
363+
[%autofit]
364+
----
365+
play_symbol = (node.document.attr? 'icons', 'font') ? %(<font name="fas">#{(icon_font_data 'fas').unicode 'play'}</font>) : RightPointer
366+
----
367+
END
368+
369+
(expect pdf.text).to have_size 1
370+
(expect pdf.text[0][:font_size].floor).to be 7
371+
end
372+
373+
it 'should allow base minimum font size to be specified relative to current font size' do
374+
pdf = to_pdf <<~'END', pdf_theme: { base_font_size: 15, code_font_size: 12, base_font_size_min: '0.5em' }, analyze: true
375+
[%autofit]
376+
----
377+
play_symbol = (node.document.attr? 'icons', 'font') ? %(<font name="fas">#{(icon_font_data 'fas').unicode 'play'}</font>) : RightPointer
378+
----
379+
END
380+
381+
(expect pdf.text).to have_size 1
382+
(expect pdf.text[0][:font_size].floor).to be 7
383+
end
384+
361385
it 'should use base font color if font color is not specified' do
362386
pdf = to_pdf <<~'END', pdf_theme: { base_font_color: 'AA0000', code_font_color: nil }, analyze: true
363387
before

0 commit comments

Comments
 (0)