Various improvements in the PDF rendering. More efficient build
This commit is contained in:
parent
4f1a3a5e3b
commit
ae13870226
32
build.py
32
build.py
@ -354,7 +354,7 @@ def BuildOnePageSidebar(fs):
|
|||||||
levelNums = [0]*3
|
levelNums = [0]*3
|
||||||
|
|
||||||
for i in range(len(fs)):
|
for i in range(len(fs)):
|
||||||
# Handle Part/Chapter/subchapter/section/subsection numbering
|
# Handle Part/Chapter/subchapter numbering
|
||||||
level = fs[i]['level']
|
level = fs[i]['level']
|
||||||
if level < 2:
|
if level < 2:
|
||||||
levelNums[2] = 0
|
levelNums[2] = 0
|
||||||
@ -515,22 +515,22 @@ for header in fileStruct:
|
|||||||
|
|
||||||
print(header['title'])
|
print(header['title'])
|
||||||
|
|
||||||
# Handle TOC scriblings and one-page titles...
|
# Handle TOC scriblings...
|
||||||
|
if level == 0:
|
||||||
|
toc = toc + '<h2>Part ' + num2roman(levelNums[level]) + ': ' + header['title'] + '</h2>\n';
|
||||||
|
elif level == 1:
|
||||||
|
toc = toc + '\t<p class="chapter">Ch. ' + str(levelNums[level]) + ': <a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
|
||||||
|
elif level == 2:
|
||||||
|
toc = toc + '\t\t<p class="subchapter"><a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
|
||||||
|
|
||||||
|
# Handle one-page and PDF titles...
|
||||||
opl = ''
|
opl = ''
|
||||||
if 'link' in header:
|
if 'link' in header:
|
||||||
opl = ' id="' + header['link'] + '"'
|
opl = ' id="' + header['link'] + '"'
|
||||||
else:
|
else:
|
||||||
opl = ' id="' + header['filename'] + '"'
|
opl = ' id="' + header['filename'] + '"'
|
||||||
|
oph = '<h' + str(level+1) + ' class="clear"' + opl +'>' + header['title'] + '</h' + str(level+1) + '>\n';
|
||||||
|
|
||||||
if level == 0:
|
|
||||||
toc = toc + '<h2>Part ' + num2roman(levelNums[level]) + ': ' + header['title'] + '</h2>\n';
|
|
||||||
oph = '<h1 class="clear"' + opl +'>Part ' + num2roman(levelNums[level]) + ' - ' + header['title'] + '</h1>\n';
|
|
||||||
elif level == 1:
|
|
||||||
toc = toc + '\t<p class="chapter">Ch. ' + str(levelNums[level]) + ': <a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
|
|
||||||
oph = '<h2 class="clear"' + opl +'>' + str(levelNums[level]) + ' - ' + header['title'] + '</h3>\n';
|
|
||||||
elif level == 2:
|
|
||||||
toc = toc + '\t\t<p class="subchapter"><a href="/' + header['filename'] + '/">' + header['title'] + '</a></p>\n'
|
|
||||||
oph = '<h3 class="clear"' + opl +'>' + str(levelNums[level-1]) + '.' + str(levelNums[level]) + ' - ' + header['title'] + '</h3>\n';
|
|
||||||
|
|
||||||
# Make the 'this thing contains...' stuff
|
# Make the 'this thing contains...' stuff
|
||||||
if HaveChildren(fileStruct, pageNumber):
|
if HaveChildren(fileStruct, pageNumber):
|
||||||
@ -680,17 +680,21 @@ if not nopdf:
|
|||||||
print('Generating the PDF...')
|
print('Generating the PDF...')
|
||||||
|
|
||||||
# Create the PDF version of the documentation
|
# Create the PDF version of the documentation
|
||||||
pdfpageFile = open(global_site_dir + 'pdf.html', 'w')
|
|
||||||
pdfpage = pdfpage.replace('{% tree %}', opsidebar) # create the TOC
|
pdfpage = pdfpage.replace('{% tree %}', opsidebar) # create the TOC
|
||||||
pdfpage = pdfpage.replace('{{ content }}', '') # cleans up the last spaceholder
|
pdfpage = pdfpage.replace('{{ content }}', '') # cleans up the last spaceholder
|
||||||
pdfpage = pdfpage.replace('src="/images/', 'src="images/') # makes images links relative
|
pdfpage = pdfpage.replace('src="/images/', 'src="images/') # makes images links relative
|
||||||
pdfpage = pdfpage.replace('url(\'/images/', 'url(\'images/') # CSS images links relative
|
pdfpage = pdfpage.replace('url(\'/images/', 'url(\'images/') # CSS images links relative
|
||||||
|
# Write it to disk (optional, can be removed)
|
||||||
|
pdfpageFile = open(global_site_dir + 'pdf.html', 'w')
|
||||||
pdfpageFile.write(pdfpage)
|
pdfpageFile.write(pdfpage)
|
||||||
pdfpageFile.close()
|
pdfpageFile.close()
|
||||||
|
|
||||||
|
# Generating the actual PDF with weasyprint (https://weasyprint.org/)
|
||||||
from weasyprint import HTML
|
from weasyprint import HTML
|
||||||
doc = HTML(filename = global_site_dir + 'pdf.html')
|
#from weasyprint.fonts import FontConfiguration
|
||||||
doc.write_pdf(global_site_dir + 'manual.pdf')
|
#html_font_config = FontConfiguration()
|
||||||
|
doc = HTML(string = pdfpage, base_url = global_site_dir)
|
||||||
|
doc.write_pdf(global_site_dir + 'manual.pdf')#, font_config = html_font_config)
|
||||||
|
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print('Processed ' + str(fileCount) + ' files.')
|
print('Processed ' + str(fileCount) + ' files.')
|
||||||
|
@ -14,13 +14,12 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="frontcover">
|
<div class="frontcover">
|
||||||
|
<img src="images/ardour_logo.svg" alt="Ardour logo">
|
||||||
|
<p>The Ardour Manual</p>
|
||||||
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="contents">
|
<div class="contents">
|
||||||
<h1>Table of contents</h1>
|
<h1 id="toc">Table of contents</h1>
|
||||||
|
|
||||||
{% tree %}
|
{% tree %}
|
||||||
|
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'junge-regular';
|
||||||
|
src: url('junge-regular-webfont.woff') format('woff'),
|
||||||
|
url('junge-regular-webfont.ttf') format('truetype');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'junge-regular';
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 2ex;
|
||||||
|
}
|
||||||
|
|
||||||
kbd {
|
kbd {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: 1em;
|
min-width: 1em;
|
||||||
|
@ -5,26 +5,23 @@
|
|||||||
margin: 1.5cm 1.5cm 1.5cm 1.5cm;
|
margin: 1.5cm 1.5cm 1.5cm 1.5cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@page :first {
|
|
||||||
size: A4;
|
|
||||||
margin: 1.5cm 1.5cm 1.5cm 1.5cm;
|
|
||||||
background: url("../images/ardour_logo.svg") no-repeat center;
|
|
||||||
background-size: contain;
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
img {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.frontcover {
|
div.frontcover {
|
||||||
page-break-after: always;
|
page-break-after: always;
|
||||||
|
margin: auto;
|
||||||
|
width: 80%;
|
||||||
|
font-size: 4em;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* styles for the right hand spread
|
/* styles for the right hand spread
|
||||||
Bottom left we display the title of the book, bottom right the page using a CSS
|
Bottom left we display the title of the book, bottom right the page using a CSS
|
||||||
counter, top right the content of the current chapter
|
counter, top right the content of the current chapter
|
||||||
*/
|
*/
|
||||||
@page:right {
|
@page :right {
|
||||||
@bottom-left {
|
@bottom-left {
|
||||||
margin: 10pt 0 30pt 0;
|
margin: 10pt 0 30pt 0;
|
||||||
/*border-top: .25pt solid #666;*/
|
/*border-top: .25pt solid #666;*/
|
||||||
@ -49,7 +46,7 @@ div.frontcover {
|
|||||||
/* styles for the left hand spread
|
/* styles for the left hand spread
|
||||||
Bottom right book title, bottom left current page
|
Bottom right book title, bottom left current page
|
||||||
*/
|
*/
|
||||||
@page:left {
|
@page :left {
|
||||||
@bottom-right {
|
@bottom-right {
|
||||||
margin: 10pt 0 30pt 0;
|
margin: 10pt 0 30pt 0;
|
||||||
/*border-top: .25pt solid #666;*/
|
/*border-top: .25pt solid #666;*/
|
||||||
@ -66,7 +63,7 @@ div.frontcover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* first page */
|
/* first page */
|
||||||
@page:first {
|
@page :first {
|
||||||
@bottom-right {
|
@bottom-right {
|
||||||
content: normal;
|
content: normal;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -78,39 +75,57 @@ div.frontcover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset chapter and figure counters on the body */
|
|
||||||
body {
|
body {
|
||||||
counter-reset: chapternum figurenum;
|
counter-reset: partnum chapternum subchapternum figurenum; /* resets all counters */
|
||||||
font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;
|
/*font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;*/
|
||||||
line-height: 1.2;
|
font-size: 10pt;
|
||||||
font-size: 9pt;
|
line-height: 1.25em;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the title of the current chapter - this will be the content of the h1
|
|
||||||
reset figure counter as figures start from 1 in each chapter */
|
|
||||||
h1 {
|
h1 {
|
||||||
string-set: doctitle content();
|
string-set: doctitle content(); /* get the title of the current chapter */
|
||||||
page-break-before: always;
|
page-break-before: always;
|
||||||
counter-reset: figurenum;
|
|
||||||
line-height: 1.3;
|
|
||||||
counter-increment: chapternum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1:first-of-type { /* the ToC should not count...*/
|
#toc::before { /* the ToC should not count...*/
|
||||||
content: none;
|
content: none;
|
||||||
counter-reset: chapternum;
|
counter-reset: partnum;
|
||||||
|
/*counter-increment: partnum -1;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* increment and display figure counter */
|
h1::before { /* parts */
|
||||||
figcaption:before {
|
counter-increment: partnum;
|
||||||
counter-increment: figurenum;
|
content: "Part " counter(partnum) " - ";
|
||||||
content: counter(chapternum) "-" counter(figurenum) ". ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h2::before { /* chapter */
|
||||||
|
counter-increment: chapternum;
|
||||||
|
content: "Chapter " counter(chapternum) " - ";
|
||||||
|
}
|
||||||
|
|
||||||
|
h3::before { /* subchapter */
|
||||||
|
counter-increment: subchapternum;
|
||||||
|
content: counter(chapternum) "." counter(subchapternum) " - " ;
|
||||||
|
}
|
||||||
|
|
||||||
|
figcaption::before {
|
||||||
|
counter-increment: figurenum;
|
||||||
|
content: "Fig. " counter(chapternum) "." counter(figurenum) " - ";
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 { font-size: 3em; }
|
||||||
|
h2 { font-size: 2.25em; counter-reset: subchapternum figurenum; }
|
||||||
|
h3 { font-size: 1.75em; }
|
||||||
|
h4 { font-size: 1.4em; }
|
||||||
|
h5 { font-size: 1.2em; }
|
||||||
|
h6 { font-size: 1.1em; }
|
||||||
|
|
||||||
h1,h2,h3,h4,h5 {
|
h1,h2,h3,h4,h5 {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
page-break-after: avoid;
|
page-break-after: avoid;
|
||||||
page-break-inside:avoid;
|
page-break-inside:avoid;
|
||||||
|
line-height: 1.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1+p, h2+p, h3+p {
|
h1+p, h2+p, h3+p {
|
||||||
@ -154,6 +169,6 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add page number to cross references */
|
/* add page number to cross references */
|
||||||
a.xref:after {
|
a.xref::after {
|
||||||
content: " (page " target-counter(attr(href, url), page) ")";
|
content: " (page " target-counter(attr(href, url), page) ")";
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,3 @@
|
|||||||
@font-face {
|
|
||||||
font-family: 'junge-regular';
|
|
||||||
src: url('junge-regular-webfont.woff2') format('woff2'),
|
|
||||||
url('junge-regular-webfont.woff') format('woff'),
|
|
||||||
url('junge-regular-webfont.ttf') format('truetype');
|
|
||||||
font-weight: normal;
|
|
||||||
font-style: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: 'junge-regular';
|
|
||||||
font-size: 16px;
|
|
||||||
line-height: 2ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clear {
|
.clear {
|
||||||
clear:both;
|
clear:both;
|
||||||
|
Loading…
Reference in New Issue
Block a user