1 # Part of Objavi2, which makes pdf versions of FLOSSManuals books.
2 # This python module contains or encapsulates configuration and
5 # Copyright (C) 2009 Douglas Bagnall
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 """This module contains constant values used to produce books.
23 #XXX eventually, read in a real config file.
24 #XXX Some of these values should be editable via an admin cgi script
26 #Not really configurable (72 pt per inch / 25.4 mm per inch)
27 POINT_2_MM
= 25.4 / 72.0
28 MM_2_POINT
= 72.0 / 25.4
35 WKHTMLTOPDF
= '/usr/local/bin/wkhtmltopdf-static'
36 WKHTMLTOPDF_EXTRA_COMMANDS
= []
37 #WKHTMLTOPDF_EXTRA_COMMANDS = ['--outline', '-t']
39 #bookland is used to make isbn barcodes
40 BOOKLAND
= 'bookland/bookland'
42 # how many pages to number in one pdfedit process (which has
43 # exponential memory leak)
44 PDFEDIT_MAX_PAGES
= 40
46 #keep book lists around for this time without refetching
47 BOOK_LIST_CACHE
= 3600 * 2
48 BOOK_LIST_CACHE_DIR
= 'cache'
50 TOC_URL
= "http://%s/pub/%s/_index/TOC.txt"
51 BOOK_URL
= "http://%s/bin/view/%s/_all?skin=text"
52 PUBLISH_URL
= "/books/"
54 #leave out vowels so as to avoid accidental words, and punctuation for bidi consistency
55 CHAPTER_COOKIE_CHARS
= 'BCDFGHJKLMNPQRSTVWXYZ'
57 DEFAULT_SERVER
= 'en.flossmanuals.net'
58 DEFAULT_SIZE
= 'COMICBOOK'
59 DEFAULT_ENGINE
= 'webkit'
62 RTL_SCRIPTS
= ['persian', 'arabic', 'hebrew', 'urdu']
65 'en.flossmanuals.net': {
66 'css-book': 'static/en.flossmanuals.net.css',
67 'css-web': 'static/en.flossmanuals.net-web.css',
68 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
72 'fr.flossmanuals.net': {
73 'css-book': 'static/fr.flossmanuals.net.css',
74 'css-web': 'static/fr.flossmanuals.net.css',
75 'css-newspaper': 'static/fr.flossmanuals.net.css',
76 'css': 'static/fr.flossmanuals.net.css',
80 'translate.flossmanuals.net': {
81 'css-book': 'static/translate.flossmanuals.net.css',
82 'css-web': 'static/translate.flossmanuals.net.css',
83 'css-newspaper': 'static/translate.flossmanuals.net.css',
84 'css': 'static/translate.flossmanuals.net.css',
88 'nl.flossmanuals.net': {
89 'css-book': 'static/nl.flossmanuals.net.css',
90 'css-web': 'static/nl.flossmanuals.net.css',
91 'css-newspaper': 'static/nl.flossmanuals.net.css',
92 'css': 'static/nl.flossmanuals.net.css',
96 'bn.flossmanuals.net': {
97 'css-book': 'static/bn.flossmanuals.net.css',
98 'css-web': 'static/bn.flossmanuals.net.css',
99 'css-newspaper': 'static/bn.flossmanuals.net.css',
100 'css': 'static/bn.flossmanuals.net.css',
104 'fa.flossmanuals.net': {
105 'css-book': 'static/fa.flossmanuals.net.css',
106 'css-web': 'static/fa.flossmanuals.net.css',
107 'css-newspaper': 'static/fa.flossmanuals.net.css',
108 'css': 'static/fa.flossmanuals.net.css',
114 # uncomment a debug mode to get messages about that topic.
124 #convert all sizes to points
125 PAPER_SIZES
= [(s
, x
* MM_2_POINT
, y
* MM_2_POINT
) for s
, x
, y
in (
140 # margins are BASE_MARGIN + PROPORTIONAL_MARGIN * min(width, height)
142 PROPORTIONAL_MARGIN
= 0.04
143 # gutter is BASE_GUTTER + PROPORTIONAL_GUTTER * width
145 PROPORTIONAL_GUTTER
= 0.011
148 'page_width': (1, 3000, MM_2_POINT
),
149 'page_height': (1, 3000, MM_2_POINT
),
150 'gutter': (-1000, 1000, MM_2_POINT
),
151 'top_margin': (0, 1500, MM_2_POINT
),
152 'side_margin': (0, 1500, MM_2_POINT
),
153 'bottom_margin': (0, 1500, MM_2_POINT
),
154 "columns": (1, 20, 1),
155 "column_margin": (0, 1000, MM_2_POINT
),
158 PAGE_NUMBER_SIZE
= 11 #XXX this is not used by pdfedit! (ie, it is a guess)
161 'COMICBOOK': {'pointsize': ((6.625 * 72), (10.25 * 72)), 'class': "lulu"},
162 "POCKET": {'pointsize': (4.25 * 72, 6.875 * 72), 'class': "lulu"},
164 "USLETTER": {'pointsize': (8.5 * 72, 11 * 72), 'class': "lulu"},
165 "USTRADE": {'pointsize': (6 * 72, 9 * 72), 'class': "lulu"},
166 "LANDSCAPE9x7": {'pointsize': (9 * 72, 7 * 72), 'class': "lulu"},
167 "SQUARE7.5": {'pointsize': (7.5 * 72, 7.5 * 72), 'class': "lulu"},
168 "ROYAL": {'pointsize': (6.139 * 72, 9.21 * 72), 'class': "lulu"},
169 "CROWNQUARTO": {'pointsize': (7.444 * 72, 9.681 * 72), 'class': "lulu"},
170 "SQUARE8.5": {'pointsize': (8.5 * 72, 8.5 * 72), 'class': "lulu"},
172 "A5": {'pointsize': (148 * MM_2_POINT
, 210 * MM_2_POINT
), 'class': "lulu iso"},
173 "A4": {'pointsize': (210 * MM_2_POINT
, 297 * MM_2_POINT
), 'class': "lulu iso"},
174 "A3 (NZ Tabloid)": {'pointsize': (297 * MM_2_POINT
, 420 * MM_2_POINT
), 'class': 'iso newspaper'},
175 "A2 (NZ Broadsheet)": {'pointsize': (420 * MM_2_POINT
, 594 * MM_2_POINT
), 'class': 'iso newspaper'},
176 "A1": {'pointsize': (594 * MM_2_POINT
, 841 * MM_2_POINT
), 'class': 'iso'},
177 "B4": {'pointsize': (250 * MM_2_POINT
, 353 * MM_2_POINT
), 'class': 'iso'},
178 "B3": {'pointsize': (353 * MM_2_POINT
, 500 * MM_2_POINT
), 'class': 'iso'},
179 "B2": {'pointsize': (500 * MM_2_POINT
, 707 * MM_2_POINT
), 'class': 'iso'},
180 "B1": {'pointsize': (707 * MM_2_POINT
, 1000 * MM_2_POINT
), 'class': 'iso'},
182 "UK Tabloid": {'pointsize': (11 * INCH_2_POINT
, 17 * INCH_2_POINT
), 'class': 'newspaper'},
183 "UK Broadsheet": {'pointsize': (18 * INCH_2_POINT
, 24 * INCH_2_POINT
), 'class': 'newspaper'},
184 "US Broadsheet": {'pointsize': (15 * INCH_2_POINT
, 22.75 * INCH_2_POINT
), 'class': 'newspaper'},
185 "Berliner" : {'pointsize': (315 * MM_2_POINT
, 470 * MM_2_POINT
), 'class': 'newspaper'},
186 "Foolscap (F4)": {'pointsize': (210 * MM_2_POINT
, 330 * MM_2_POINT
)},
187 #"Foolscap Folio": {'pointsize': (8.5 * INCH_2_POINT, 13.5 * INCH_2_POINT)},
189 "custom": {'class': "custom"},
192 PAGE_MIN_SIZE
= (1.0, 1.0)
193 PAGE_MAX_SIZE
= (3000.0, 3000.0)
200 INSIDE_FRONT_COVER_TEMPLATE
= 'templates/inside-front-cover.%s.html'
201 END_MATTER_TEMPLATE
= 'templates/end_matter.%s.html'
203 FONT_LIST_INCLUDE
= 'cache/font-list.inc'
204 FONT_LIST_URL
= '/font-list.cgi.pdf'
205 FONT_EXAMPLE_SCRIPT_DIR
= 'templates/font-list'
207 # for the license field, with a view to making it a drop down.
208 LICENSES
= ('GPL', 'GPLv2', 'GPLv2+', 'GPLv3', 'GPLv3+', 'LGPL', 'LGPLv2.1',
209 'BSD', 'public domain', 'MIT', 'Artistic', 'CC-BY', 'CC-BY-SA')
211 DEFAULT_LICENSE
= 'GPLv2+'
213 CGI_MODES
= { # arguments are: (publication, )
215 'newspaper': (True,),
217 #'openoffice': (True,),
218 'booklist': (False,),
223 DEFAULT_MODE
= 'book'
227 ("server", "FLOSS Manuals server", "select", "server_options", "", ""),
228 ("book", "Manual", "select", "book_options", "", ""),
229 ("title", "Book title", "input[type=text]", None, "", ""),
230 ("license", "License", "select", "licenses", "", ""),
232 ("isbn", "ISBN", "input[type=text]", None, "advanced", "(13 digits)"),
233 ("mode", "Document type", "select", "pdf_types", "advanced", ""),
235 ("booksize", "Page size", "select", "size_options", "advanced", '(Size compatibility: <span class="lulu">Lulu</span>, <span class="newspaper">newspapers</span>, <span class="iso">ISO standards</span>)'),
236 ("page_width", "Page width", "input[type=text]", None, "advanced booksize numeric-field", ""),
237 ("page_height", "Page height", "input[type=text]", None, "advanced booksize numeric-field", ""),
239 ("top_margin", "Top margin", "input[type=text]", None, "advanced margins numeric-field", ""),
240 ("side_margin", "Side margin", "input[type=text]", None, "advanced margins numeric-field", ""),
241 ("bottom_margin", "Bottom margin", "input[type=text]", None, "advanced margins numeric-field", ""),
242 ("gutter", "Gutter", "input[type=text]", None, "advanced margins numeric-field", ""),
244 ("columns", "Columns", "input[type=text]", None, "advanced columns numeric-field", ""),
245 ("column_margin", "Column margin", "input[type=text]", None, "advanced columns numeric-field", ""),
247 #("css_customise", "Customise CSS", "input[type=checkbox]", None, "advanced", "Enter a URL or "),
248 ("css-url", "CSS URL", "input[type=text][disabled]", "css_url", "advanced css-url", ""),
249 ("font_list", "Available fonts", "ul", "font_list", "advanced css-custom", ""),
250 ("font_links", "Font examples", "ul", "font_links", "advanced css-custom", ""),
251 ("css", "CSS", "textarea", "css", "advanced css-custom", ""),
253 ("rotate", "Rotate pages for binding", "input[type=checkbox]", None, "advanced", "(for RTL books on LTR printing presses, and vice versa)."),
254 ("engine", "Layout engine", "select", "engines", "advanced", ""),
255 #("header", "Header Text", "input[type=text]", None, "advanced", ""),
258 FORM_ELEMENT_TYPES
= {
259 'input[type=text]' : '<input type="text" id="%(id)s" name="%(id)s" value="%(val)s" />',
260 'input[type=text][disabled]' : '<input type="text" disabled="disabled" id="%(id)s" name="%(id)s" value="%(val)s" />',
261 'input[type=checkbox]' : '<input type="checkbox" id="%(id)s" name="%(id)s" value="%(val)s" />',
262 'textarea' : '<textarea id="%(id)s" name="%(id)s">%(val)s</textarea>',
263 'select': '<select id="%(id)s" name="%(id)s">%(val)s</select>',
264 'ul': '<ul id="%(id)s">%(val)s</ul>',
268 ("__init__", "Initialise the book", ('book', 'newspaper', 'web')),
269 ("load_book", "Fetch the book", ('book', 'newspaper', 'web')),
270 ("load_toc", "Fetch TOC metadata", ('book', 'newspaper', 'web')),
271 ("add_css", "Add css", ('book', 'newspaper', 'web')),
272 ("add_section_titles", "Add section titles", ('book', 'newspaper', 'web')),
273 ("generate_pdf", "Generate the main pdf", ('book', 'newspaper', 'web')),
274 ("reshape_pdf", "Cut pages to size", ('book', 'newspaper',)),
275 #('make_body_pdf', "Generate the main pdf", ('book', 'newspaper', 'web')),
276 ("number_pdf", "Number pages", ('book', 'newspaper',)),
277 ("make_contents", "Calculate Table of Contents", ('book',)),
278 ("make_preamble_pdf", "Generate preamble pdf", ('book',)),
279 ('make_end_matter_pdf', "Generate end matter pdf", ('book',)),
280 ("concatenated_pdfs", "concatenate the pdfs", ('book',)),
281 #("publish_pdf", "Publish the pdf", ('book', 'newspaper', 'web')),
282 ("finished", "Finished!", ('book', 'newspaper', 'web')),
285 if __name__
== '__main__':
286 print ', '.join(x
for x
in globals().keys() if not x
.startswith('_'))