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 #CGITB_DOMAINS = ('203.97.236.46', '202.78.240.7')
42 #bookland is used to make isbn barcodes
43 BOOKLAND
= 'bookland/bookland'
45 # how many pages to number in one pdfedit process (which has
46 # exponential memory leak)
47 PDFEDIT_MAX_PAGES
= 40
49 #keep book lists around for this time without refetching
50 BOOK_LIST_CACHE
= 3600 * 2
51 BOOK_LIST_CACHE_DIR
= 'cache'
53 TOC_URL
= "http://%s/pub/%s/_index/TOC.txt"
54 BOOK_URL
= "http://%s/bin/view/%s/_all?skin=text"
55 PUBLISH_URL
= "/books/"
57 #leave out vowels so as to avoid accidental words, and punctuation for bidi consistency
58 CHAPTER_COOKIE_CHARS
= 'BCDFGHJKLMNPQRSTVWXYZ'
60 DEFAULT_SERVER
= 'en.flossmanuals.net'
61 DEFAULT_SIZE
= 'COMICBOOK'
62 DEFAULT_ENGINE
= 'webkit'
65 RTL_SCRIPTS
= ['persian', 'arabic', 'hebrew', 'urdu']
67 USE_TAGS_FOR_CONTENTS
= False
69 TRY_BOOK_CLEANUP_ON_DEL
= False
72 'en.flossmanuals.net': {
73 'css-book': 'static/en.flossmanuals.net.css',
74 'css-web': 'static/en.flossmanuals.net-web.css',
75 'css-newspaper': 'static/en.flossmanuals.net-newspaper.css',
79 'fr.flossmanuals.net': {
80 'css-book': 'static/fr.flossmanuals.net.css',
81 'css-web': 'static/fr.flossmanuals.net.css',
82 'css-newspaper': 'static/fr.flossmanuals.net.css',
83 'css': 'static/fr.flossmanuals.net.css',
87 'translate.flossmanuals.net': {
88 'css-book': 'static/translate.flossmanuals.net.css',
89 'css-web': 'static/translate.flossmanuals.net.css',
90 'css-newspaper': 'static/translate.flossmanuals.net.css',
91 'css': 'static/translate.flossmanuals.net.css',
95 'nl.flossmanuals.net': {
96 'css-book': 'static/nl.flossmanuals.net.css',
97 'css-web': 'static/nl.flossmanuals.net.css',
98 'css-newspaper': 'static/nl.flossmanuals.net.css',
99 'css': 'static/nl.flossmanuals.net.css',
103 'bn.flossmanuals.net': {
104 'css-book': 'static/bn.flossmanuals.net.css',
105 'css-web': 'static/bn.flossmanuals.net.css',
106 'css-newspaper': 'static/bn.flossmanuals.net.css',
107 'css': 'static/bn.flossmanuals.net.css',
111 'fa.flossmanuals.net': {
112 'css-book': 'static/fa.flossmanuals.net.css',
113 'css-web': 'static/fa.flossmanuals.net.css',
114 'css-newspaper': 'static/fa.flossmanuals.net.css',
115 'css': 'static/fa.flossmanuals.net.css',
121 # uncomment a debug mode to get messages about that topic.
131 #convert all sizes to points
132 PAPER_SIZES
= [(s
, x
* MM_2_POINT
, y
* MM_2_POINT
) for s
, x
, y
in (
147 # margins are BASE_MARGIN + PROPORTIONAL_MARGIN * min(width, height)
149 PROPORTIONAL_MARGIN
= 0.04
150 # gutter is BASE_GUTTER + PROPORTIONAL_GUTTER * width
152 PROPORTIONAL_GUTTER
= 0.011
155 'page_width': (1, 3000, MM_2_POINT
),
156 'page_height': (1, 3000, MM_2_POINT
),
157 'gutter': (-1000, 1000, MM_2_POINT
),
158 'top_margin': (0, 1500, MM_2_POINT
),
159 'side_margin': (0, 1500, MM_2_POINT
),
160 'bottom_margin': (0, 1500, MM_2_POINT
),
161 "columns": (1, 20, 1),
162 "column_margin": (0, 1000, MM_2_POINT
),
165 PAGE_NUMBER_SIZE
= 11 #XXX this is not used by pdfedit! (ie, it is a guess)
168 'COMICBOOK': {'pointsize': ((6.625 * 72), (10.25 * 72)), 'class': "lulu"},
169 "POCKET": {'pointsize': (4.25 * 72, 6.875 * 72), 'class': "lulu"},
171 "USLETTER": {'pointsize': (8.5 * 72, 11 * 72), 'class': "lulu"},
172 "USTRADE": {'pointsize': (6 * 72, 9 * 72), 'class': "lulu"},
173 "LANDSCAPE9x7": {'pointsize': (9 * 72, 7 * 72), 'class': "lulu"},
174 "SQUARE7.5": {'pointsize': (7.5 * 72, 7.5 * 72), 'class': "lulu"},
175 "ROYAL": {'pointsize': (6.139 * 72, 9.21 * 72), 'class': "lulu"},
176 "CROWNQUARTO": {'pointsize': (7.444 * 72, 9.681 * 72), 'class': "lulu"},
177 "SQUARE8.5": {'pointsize': (8.5 * 72, 8.5 * 72), 'class': "lulu"},
179 "A5": {'pointsize': (148 * MM_2_POINT
, 210 * MM_2_POINT
), 'class': "lulu iso"},
180 "A4": {'pointsize': (210 * MM_2_POINT
, 297 * MM_2_POINT
), 'class': "lulu iso"},
181 "A3 (NZ Tabloid)": {'pointsize': (297 * MM_2_POINT
, 420 * MM_2_POINT
), 'class': 'iso newspaper'},
182 "A2 (NZ Broadsheet)": {'pointsize': (420 * MM_2_POINT
, 594 * MM_2_POINT
), 'class': 'iso newspaper'},
183 "A1": {'pointsize': (594 * MM_2_POINT
, 841 * MM_2_POINT
), 'class': 'iso'},
184 "B4": {'pointsize': (250 * MM_2_POINT
, 353 * MM_2_POINT
), 'class': 'iso'},
185 "B3": {'pointsize': (353 * MM_2_POINT
, 500 * MM_2_POINT
), 'class': 'iso'},
186 "B2": {'pointsize': (500 * MM_2_POINT
, 707 * MM_2_POINT
), 'class': 'iso'},
187 "B1": {'pointsize': (707 * MM_2_POINT
, 1000 * MM_2_POINT
), 'class': 'iso'},
189 "UK Tabloid": {'pointsize': (11 * INCH_2_POINT
, 17 * INCH_2_POINT
), 'class': 'newspaper'},
190 "UK Broadsheet": {'pointsize': (18 * INCH_2_POINT
, 24 * INCH_2_POINT
), 'class': 'newspaper'},
191 "US Broadsheet": {'pointsize': (15 * INCH_2_POINT
, 22.75 * INCH_2_POINT
), 'class': 'newspaper'},
192 "Berliner" : {'pointsize': (315 * MM_2_POINT
, 470 * MM_2_POINT
), 'class': 'newspaper'},
193 "Foolscap (F4)": {'pointsize': (210 * MM_2_POINT
, 330 * MM_2_POINT
)},
194 #"Foolscap Folio": {'pointsize': (8.5 * INCH_2_POINT, 13.5 * INCH_2_POINT)},
196 "custom": {'class': "custom"},
199 PAGE_MIN_SIZE
= (1.0, 1.0)
200 PAGE_MAX_SIZE
= (3000.0, 3000.0)
207 INSIDE_FRONT_COVER_TEMPLATE
= 'templates/inside-front-cover.%s.html'
208 END_MATTER_TEMPLATE
= 'templates/end_matter.%s.html'
210 FONT_LIST_INCLUDE
= 'cache/font-list.inc'
211 FONT_LIST_URL
= '/font-list.cgi.pdf'
212 FONT_EXAMPLE_SCRIPT_DIR
= 'templates/font-list'
214 # for the license field, with a view to making it a drop down.
215 LICENSES
= ('GPL', 'GPLv2', 'GPLv2+', 'GPLv3', 'GPLv3+', 'LGPL', 'LGPLv2.1',
216 'BSD', 'public domain', 'MIT', 'Artistic', 'CC-BY', 'CC-BY-SA')
218 DEFAULT_LICENSE
= 'GPLv2+'
220 CGI_MODES
= { # arguments are: (publication, )
222 'newspaper': (True,),
224 #'openoffice': (True,),
225 'booklist': (False,),
230 DEFAULT_MODE
= 'book'
234 ("server", "FLOSS Manuals server", "select", "server_options", "", ""),
235 ("book", "Manual", "select", "book_options", "", ""),
236 ("title", "Book title", "input[type=text]", None, "", ""),
237 ("license", "License", "select", "licenses", "", ""),
239 ("isbn", "ISBN", "input[type=text]", None, "advanced", "(13 digits)"),
240 ("mode", "Document type", "select", "pdf_types", "advanced", ""),
242 ("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>)'),
243 ("page_width", "Page width", "input[type=text]", None, "advanced booksize numeric-field", ""),
244 ("page_height", "Page height", "input[type=text]", None, "advanced booksize numeric-field", ""),
246 ("top_margin", "Top margin", "input[type=text]", None, "advanced margins numeric-field", ""),
247 ("side_margin", "Side margin", "input[type=text]", None, "advanced margins numeric-field", ""),
248 ("bottom_margin", "Bottom margin", "input[type=text]", None, "advanced margins numeric-field", ""),
249 ("gutter", "Gutter", "input[type=text]", None, "advanced margins numeric-field", ""),
251 ("columns", "Columns", "input[type=text]", None, "advanced columns numeric-field", ""),
252 ("column_margin", "Column margin", "input[type=text]", None, "advanced columns numeric-field", ""),
254 #("css_customise", "Customise CSS", "input[type=checkbox]", None, "advanced", "Enter a URL or "),
255 ("css-url", "CSS URL", "input[type=text][disabled]", "css_url", "advanced css-url", ""),
256 ("font_list", "Available fonts", "ul", "font_list", "advanced css-custom", ""),
257 ("font_links", "Font examples", "ul", "font_links", "advanced css-custom", ""),
258 ("css", "CSS", "textarea", "css", "advanced css-custom", ""),
260 ("rotate", "Rotate pages for binding", "input[type=checkbox]", None, "advanced", "(for RTL books on LTR printing presses, and vice versa)."),
261 ("engine", "Layout engine", "select", "engines", "advanced", ""),
262 #("header", "Header Text", "input[type=text]", None, "advanced", ""),
265 FORM_ELEMENT_TYPES
= {
266 'input[type=text]' : '<input type="text" id="%(id)s" name="%(id)s" value="%(val)s" />',
267 'input[type=text][disabled]' : '<input type="text" disabled="disabled" id="%(id)s" name="%(id)s" value="%(val)s" />',
268 'input[type=checkbox]' : '<input type="checkbox" id="%(id)s" name="%(id)s" value="%(val)s" />',
269 'textarea' : '<textarea id="%(id)s" name="%(id)s">%(val)s</textarea>',
270 'select': '<select id="%(id)s" name="%(id)s">%(val)s</select>',
271 'ul': '<ul id="%(id)s">%(val)s</ul>',
275 ("__init__", "Initialise the book", ('book', 'newspaper', 'web')),
276 ("load_book", "Fetch the book", ('book', 'newspaper', 'web')),
277 ("load_toc", "Fetch TOC metadata", ('book', 'newspaper', 'web')),
278 ("add_css", "Add css", ('book', 'newspaper', 'web')),
279 ("add_section_titles", "Add section titles", ('book', 'newspaper', 'web')),
280 ("generate_pdf", "Generate the main pdf", ('book', 'newspaper', 'web')),
281 ("reshape_pdf", "Cut pages to size", ('book', 'newspaper',)),
282 #('make_body_pdf', "Generate the main pdf", ('book', 'newspaper', 'web')),
283 ("number_pdf", "Number pages", ('book', 'newspaper',)),
284 ("make_contents", "Calculate Table of Contents", ('book',)),
285 ("make_preamble_pdf", "Generate preamble pdf", ('book',)),
286 ('make_end_matter_pdf', "Generate end matter pdf", ('book',)),
287 ("concatenated_pdfs", "concatenate the pdfs", ('book',)),
288 #("publish_pdf", "Publish the pdf", ('book', 'newspaper', 'web')),
289 ("finished", "Finished!", ('book', 'newspaper', 'web')),
292 if __name__
== '__main__':
293 print ', '.join(x
for x
in globals().keys() if not x
.startswith('_'))