Skip to content

Commit

Permalink
use base_align as default alignment for headings (PR #544)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux authored Sep 9, 2016
1 parent 12a3b49 commit 6b91540
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/themes/default-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ literal:
font_family: M+ 1mn
menu_caret_content: " <font size=\"1.15em\"><color rgb=\"b12146\">\u203a</color></font> "
heading:
align: left
#font_color: 181818
font_color: $base_font_color
font_family: $base_font_family
Expand Down
20 changes: 10 additions & 10 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def build_pdf_info doc
end

def convert_section sect, opts = {}
theme_font :heading, level: (h_level = sect.level + 1) do
theme_font :heading, level: (hlevel = sect.level + 1) do
title = sect.numbered_title formal: true
align = (@theme[%(heading_h#{h_level}_align)] || @theme.heading_align || :left).to_sym
align = (@theme[%(heading_h#{hlevel}_align)] || @theme.heading_align || @theme.base_align).to_sym
type = nil
if sect.part_or_chapter?
if sect.chapter?
Expand Down Expand Up @@ -347,8 +347,8 @@ def convert_section sect, opts = {}
def convert_floating_title node
add_dest_for_block node if node.id
# QUESTION should we decouple styles from section titles?
theme_font :heading, level: (h_level = node.level + 1) do
layout_heading node.title, align: (@theme[%(heading_h#{h_level}_align)] || @theme.heading_align || :left).to_sym
theme_font :heading, level: (hlevel = node.level + 1) do
layout_heading node.title, align: (@theme[%(heading_h#{hlevel}_align)] || @theme.heading_align || @theme.base_align).to_sym
end
end

Expand Down Expand Up @@ -571,7 +571,7 @@ def convert_sidebar node
if node.title?
theme_font :sidebar_title do
# QUESTION should we allow margins of sidebar title to be customized?
layout_heading node.title, align: @theme.sidebar_title_align.to_sym, margin_top: 0
layout_heading node.title, align: (@theme.sidebar_title_align || @theme.base_align).to_sym, margin_top: 0
end
end
theme_font :sidebar do
Expand Down Expand Up @@ -1632,7 +1632,7 @@ def layout_title_page doc
font @theme.base_font_family, size: @theme.base_font_size

# QUESTION allow aligment per element on title page?
title_align = @theme.title_page_align.to_sym
title_align = (@theme.title_page_align || @theme.base_align).to_sym

# TODO disallow .pdf as image type
if (logo_image_path = (doc.attr 'title-logo-image', @theme.title_page_logo_image))
Expand Down Expand Up @@ -1765,7 +1765,7 @@ def layout_heading string, opts = {}
typeset_text string, calc_line_metrics((opts.delete :line_height) || @theme.heading_line_height), {
color: @font_color,
inline_format: true,
align: :left
align: @theme.base_align.to_sym
}.merge(opts)
margin_bottom bot_margin
end
Expand Down Expand Up @@ -1818,7 +1818,7 @@ def layout_caption subject, opts = {}
layout_prose string, {
margin_top: margin[:top],
margin_bottom: margin[:bottom],
align: @theme.caption_align.to_sym,
align: (@theme.caption_align || @theme.base_align).to_sym,
normalize: false
}.merge(opts)
if side == :top && @theme.caption_border_bottom_color
Expand Down Expand Up @@ -1851,7 +1851,7 @@ def layout_toc doc, num_levels = 2, toc_page_number = 2, num_front_matter_pages
go_to_page toc_page_number unless (page_number == toc_page_number) || scratch?
start_page_number = page_number
theme_font :heading, level: 2 do
layout_heading((doc.attr 'toc-title'), align: (@theme.toc_title_align || :left).to_sym)
layout_heading((doc.attr 'toc-title'), align: (@theme.toc_title_align || @theme.base_align).to_sym)
end
# QUESTION shouldn't we skip this whole method if num_levels == 0?
if num_levels > 0
Expand Down Expand Up @@ -1895,7 +1895,7 @@ def layout_toc_level sections, num_levels, line_metrics, dot_width, num_front_ma
# FIXME dots don't line up if width of page numbers differ
typeset_formatted_text [
{ text: %(#{(@theme.toc_dot_leader_content || DotLeaderDefault) * num_dots}), color: toc_dot_color },
# FIXME this spacing doesn't always work out
# FIXME this spacing doesn't always work out; should we use graphics instead?
{ text: NoBreakSpace, size: (@font_size * 0.5) },
{ text: sect_page_num.to_s, anchor: sect_anchor, color: @font_color }], line_metrics, align: :right
go_to_page end_page_number if start_page_number != end_page_number
Expand Down
1 change: 1 addition & 0 deletions lib/asciidoctor-pdf/theme_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def load hash, theme_data = nil
end
end
end
theme_data.base_align ||= 'left'
# QUESTION should we do any other post-load calculations or defaults?
theme_data
end
Expand Down

0 comments on commit 6b91540

Please sign in to comment.