summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2015-07-22 00:56:54 -0600
committerDan Allen <dan.j.allen@gmail.com>2015-07-22 01:11:41 -0600
commit800e2139376a7d5cc087e637671c5dccd5ebd5cc (patch)
tree026aef2600a9d0846414e8a20f491d5a2b83d96e
parent470cab26a6e0160c482487e76f8ff661a369cd7d (diff)
resolves #274 make line height in running header/footer configurable
- allow header_line_height & footer_line_height to be specified in theme - properly calculate the height and placement of running content - placement of image in running content should respect padding settings - document header_line_height & footer_line_height in theme guide - update default theme to use new settings
-rw-r--r--data/themes/default-theme.yml1
-rw-r--r--docs/theming-guide.adoc12
-rw-r--r--lib/asciidoctor-pdf/converter.rb28
3 files changed, 30 insertions, 11 deletions
diff --git a/data/themes/default-theme.yml b/data/themes/default-theme.yml
index 21b11852..bd4ba74e 100644
--- a/data/themes/default-theme.yml
+++ b/data/themes/default-theme.yml
@@ -214,6 +214,7 @@ footer:
border_color: dddddd
border_width: 0.25
height: $base_line_height_length * 2.5
+ line_height: 1
padding: [$base_line_height_length / 2, 1, 0, 1]
vertical_align: top
#image_vertical_align: <alignment> or <number>
diff --git a/docs/theming-guide.adoc b/docs/theming-guide.adoc
index 9cc57324..7353cf7e 100644
--- a/docs/theming-guide.adoc
+++ b/docs/theming-guide.adoc
@@ -1418,6 +1418,11 @@ Block styles are applied to the following block types:
|<<measurement-units,measurement>>
|height: 0.75in
+|header_line_height
+|<<values,number>> +
+(default: $base_line_height)
+|height: 1.2
+
|header_padding
|<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
|padding: [0, 3, 0, 3]
@@ -1471,6 +1476,11 @@ Block styles are applied to the following block types:
|<<measurement-units,measurement>>
|height: 0.75in
+|footer_line_height
+|<<values,number>> +
+(default: $base_line_height)
+|height: 1.2
+
|footer_padding
|<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
|padding: [0, 3, 0, 3]
@@ -1514,6 +1524,7 @@ Here's an example that shows how these attributes can be used in the running foo
----
footer:
height: 0.75in
+ line_height: 1
recto_content:
right: '{section-or-chapter-title} | *{page-number}*'
verso_content:
@@ -1528,6 +1539,7 @@ To force a hard line break in the output, add [x-]+{space}{plus}+ to the end of
----
footer:
height: 0.75in
+ line_height: 1.2
recto_content:
right: |
Section Title - Page Number +
diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb
index 4be500a5..7db6d0b3 100644
--- a/lib/asciidoctor-pdf/converter.rb
+++ b/lib/asciidoctor-pdf/converter.rb
@@ -1833,15 +1833,12 @@ class Converter < ::Prawn::Document
acc
end
- # QUESTION should we support footer_line_height?
- #trim_line_metrics = calc_line_metrics @theme.base_line_height
- trim_line_metrics = calc_line_metrics
if position == :header
+ trim_line_metrics = calc_line_metrics(@theme.header_line_height || @theme.base_line_height)
trim_top = page_height
# NOTE height is required atm
trim_height = @theme.header_height || page_margin_top
trim_padding = @theme.header_padding || [0, 0, 0, 0]
- trim_content_height = trim_height - trim_padding[0] - trim_padding[2] - trim_line_metrics.padding_top
trim_left = page_margin_left
trim_width = page_width - trim_left - page_margin_right
trim_font_color = @theme.header_font_color || @font_color
@@ -1852,10 +1849,10 @@ class Converter < ::Prawn::Document
trim_valign = (@theme.header_vertical_align || :middle).to_sym
trim_img_valign = @theme.header_image_vertical_align
else
+ trim_line_metrics = calc_line_metrics(@theme.footer_line_height || @theme.base_line_height)
# NOTE height is required atm
trim_top = trim_height = @theme.footer_height || page_margin_bottom
trim_padding = @theme.footer_padding || [0, 0, 0, 0]
- trim_content_height = trim_height - trim_padding[0] - trim_padding[2] - trim_line_metrics.padding_top
trim_left = page_margin_left
trim_width = page_width - trim_left - page_margin_right
trim_font_color = @theme.footer_font_color || @font_color
@@ -1869,6 +1866,7 @@ class Converter < ::Prawn::Document
trim_stamp = %(#{position})
trim_content_left = trim_left + trim_padding[3]
+ trim_content_height = trim_height - trim_padding[0] - trim_padding[2] - trim_line_metrics.padding_top - trim_line_metrics.padding_bottom
trim_content_width = trim_width - trim_padding[3] - trim_padding[1]
trim_border_color = nil if trim_border_width == 0
trim_valign = :center if trim_valign == :middle
@@ -1927,16 +1925,24 @@ class Converter < ::Prawn::Document
# FIXME we need to have a content setting for chapter pages
case (content = content_by_alignment[align])
when ::Hash
- # FIXME prevent image from overflowing the page
- float do
- # FIXME padding doesn't work when vposition is specified; how will padding bottom work?
- #move_down trim_padding[0]
- image content[:path], vposition: trim_img_valign, position: align, width: content[:width]
+ # NOTE image placement respects padding; use negative image_vertical_align value to revert
+ if (trim_v_padding = trim_padding[0] + trim_padding[2]) > 0
+ bounding_box [0, cursor - trim_padding[0]], width: bounds.width, height: (bounds.height - trim_v_padding) do
+ # FIXME prevent image from overflowing the page
+ float do
+ image content[:path], vposition: trim_img_valign, position: align, width: content[:width]
+ end
+ end
+ else
+ # FIXME prevent image from overflowing the page
+ float do
+ image content[:path], vposition: trim_img_valign, position: align, width: content[:width]
+ end
end
when ::String
content = (content == '{page-number}' ? %(#{visual_pgnum}) : (doc.apply_subs content))
formatted_text_box parse_text(content, color: trim_font_color, inline_format: [normalize: true]),
- at: [0, trim_content_height + trim_padding[2]],
+ at: [0, trim_content_height + trim_padding[2] + trim_line_metrics.padding_bottom],
height: trim_content_height,
align: align,
valign: trim_valign,