@@ -36,20 +36,20 @@ def start_new_chapter chapter
3636 end
3737
3838 def layout_chapter_title node , title , opts = { }
39- puts node . id + ': ' + title
39+ # puts node.id + ': ' + title
4040
4141 if ( sect_id = node . id ) == '_dedication' || sect_id == 'acknowledgements'
4242 layout_heading_custom title , align : :center
4343 elsif sect_id == 'colophon'
44- puts 'Processing.. ' + node . sectname + '...'
44+ # puts 'Processing.. ' + node.sectname + '...'
4545 if node . document . attr? 'media' , 'prepress'
4646 move_down 225
4747 else
4848 move_down 360
4949 end
5050 layout_heading title , size : @theme . base_font_size
5151 elsif sect_id . include? 'chapter' # chapters
52- puts 'Processing ' + sect_id + '...'
52+ # puts 'Processing ' + sect_id + '...'
5353
5454 blue = [ 91 , 54 , 8 , 13 ]
5555 green = [ 42 , 1 , 83 , 1 ]
@@ -108,7 +108,7 @@ def layout_chapter_title node, title, opts = {}
108108 end
109109
110110 def layout_heading_custom string , opts = { }
111- puts "layout_heading_custom: #{ string } "
111+ # puts "layout_heading_custom: #{string}"
112112
113113 move_down 100
114114 typeset_text string , calc_line_metrics ( ( opts . delete :line_height ) || @theme . heading_line_height ) , {
@@ -133,6 +133,56 @@ def layout_heading_custom string, opts = {}
133133 } . merge ( opts )
134134 move_down 20
135135 end
136+
137+ # Override default section call
138+ # This adds a new page for chapter level 2 (not implemented yet, but still here for future reference)
139+ def convert_section sect , opts = { }
140+ # puts "convert_section: #{sect.level} #{sect.title} | #{sect.numbered_title} | part_or_chapter: #{sect.part_or_chapter?}"
141+
142+ if sect . sectname == 'abstract'
143+ # HACK cheat a bit to hide this section from TOC; TOC should filter these sections
144+ sect . context = :open
145+ return convert_abstract sect
146+ end
147+
148+ theme_font :heading , level : ( hlevel = sect . level + 1 ) do
149+ title = sect . numbered_title formal : true
150+ align = ( @theme [ %(heading_h#{ hlevel } _align) ] || @theme . heading_align || @base_align ) . to_sym
151+ type = nil
152+ if sect . part_or_chapter?
153+ if sect . chapter?
154+ type = :chapter
155+ start_new_chapter sect
156+ else
157+ type = :part
158+ start_new_part sect
159+ end
160+ else
161+ # FIXME smarter calculation here!!
162+ # puts "level = #{sect.level}, at_page_top?= #{at_page_top?}, calc=#{cursor > (height_of title) + @theme.heading_margin_top + @theme.heading_margin_bottom + (@theme.base_line_height_length * 1.5)}"
163+ start_new_page unless at_page_top? || #(
164+ cursor > ( height_of title ) + @theme . heading_margin_top + @theme . heading_margin_bottom + ( @theme . base_line_height_length * 1.5 ) #&&
165+ # sect.level != 2)
166+ end
167+ # QUESTION should we store pdf-page-start, pdf-anchor & pdf-destination in internal map?
168+ sect . set_attr 'pdf-page-start' , ( start_pgnum = page_number )
169+ # QUESTION should we just assign the section this generated id?
170+ # NOTE section must have pdf-anchor in order to be listed in the TOC
171+ sect . set_attr 'pdf-anchor' , ( sect_anchor = derive_anchor_from_id sect . id , %(#{ start_pgnum } -#{ y . ceil } ) )
172+ add_dest_for_block sect , sect_anchor
173+ if type == :part
174+ layout_part_title sect , title , align : align
175+ elsif type == :chapter
176+ layout_chapter_title sect , title , align : align
177+ else
178+ layout_heading title , align : align
179+ end
180+ end
181+
182+ sect . sectname == 'index' ? ( convert_index_section sect ) : ( convert_content_for_block sect )
183+ sect . set_attr 'pdf-page-end' , page_number
184+ end
185+
136186end
137187
138188Asciidoctor ::Pdf ::Converter . prepend AsciidoctorPdfExtensions
0 commit comments