mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added support for headers to LRF convertors
This commit is contained in:
parent
7dcfcf7518
commit
144b3a16f5
@ -20,6 +20,7 @@ At the time fo writing, this package only supports reading and writing LRF meat
|
||||
from optparse import OptionParser
|
||||
|
||||
from libprs500.lrf.pylrs.pylrs import Book as _Book
|
||||
from libprs500.lrf.pylrs.pylrs import TextBlock, Header, PutObj, Paragraph, TextStyle
|
||||
from libprs500 import __version__ as VERSION
|
||||
|
||||
__docformat__ = "epytext"
|
||||
@ -30,6 +31,8 @@ class ConversionError(Exception):
|
||||
|
||||
def option_parser(usage):
|
||||
parser = OptionParser(usage=usage, version='libprs500 '+VERSION)
|
||||
parser.add_option('--header', action='store_true', default=False, dest='header',
|
||||
help='Add a header to all the pages with title and author.')
|
||||
parser.add_option("-t", "--title", action="store", type="string", \
|
||||
dest="title", help="Set the title")
|
||||
parser.add_option("-a", "--author", action="store", type="string", \
|
||||
@ -42,7 +45,17 @@ def option_parser(usage):
|
||||
help='Output file name. Default is derived from input filename')
|
||||
return parser
|
||||
|
||||
def Book(font_delta=0, **settings):
|
||||
def Book(font_delta=0, header=None, **settings):
|
||||
ps = dict(textwidth=575, textheight=747)
|
||||
if header:
|
||||
hdr = Header()
|
||||
hb = TextBlock(TextStyle(align='foot', fontsize=50))
|
||||
hb.append(header)
|
||||
hdr.PutObj(hb)
|
||||
ps['headheight'] = 30
|
||||
ps['header'] = header
|
||||
ps['header'] = hdr
|
||||
ps['topmargin'] = 10
|
||||
return _Book(textstyledefault=dict(fontsize=100+font_delta*20), \
|
||||
pagestyledefault=dict(textwidth=575, textheight=747), \
|
||||
pagestyledefault=ps, \
|
||||
**settings)
|
@ -31,7 +31,7 @@ from operator import itemgetter
|
||||
from libprs500.lrf.html.BeautifulSoup import BeautifulSoup, Comment, Tag, \
|
||||
NavigableString, Declaration
|
||||
from libprs500.lrf.pylrs.pylrs import Paragraph, CR, Italic, ImageStream, TextBlock, \
|
||||
ImageBlock, JumpButton, CharButton, Page, BlockStyle
|
||||
ImageBlock, JumpButton, CharButton, Page, Bold
|
||||
from libprs500.lrf.pylrs.pylrs import Span as _Span
|
||||
from libprs500.lrf import ConversionError, option_parser, Book
|
||||
from libprs500 import extract
|
||||
@ -618,7 +618,13 @@ def process_file(path, options):
|
||||
freetext=options.freetext, category=options.category)
|
||||
if tpath:
|
||||
args['thumbnail'] = tpath
|
||||
book = Book(**args)
|
||||
header = None
|
||||
if options.header:
|
||||
header = Paragraph()
|
||||
header.append(Bold(options.title))
|
||||
header.append(' by ')
|
||||
header.append(Italic(options.author))
|
||||
book = Book(header=header, **args)
|
||||
conv = HTMLConverter(book, path, font_delta=options.font_delta, cover=cpath)
|
||||
conv.process_links()
|
||||
oname = options.output
|
||||
|
@ -1034,7 +1034,7 @@ class LrsStyle(LrsObject, LrsAttributes, LrsContainer):
|
||||
def setDefaults(selfClass, settings):
|
||||
for name, value in settings.items():
|
||||
if name not in selfClass.validSettings:
|
||||
raise LrsError, "default setting %s not recognized"
|
||||
raise LrsError, "default setting %s not recognized" % name
|
||||
selfClass.defaults[name] = value
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ import os, sys
|
||||
|
||||
from libprs500.lrf import ConversionError, option_parser
|
||||
from libprs500.lrf import Book
|
||||
from libprs500.lrf.pylrs.pylrs import Paragraph, Italic, Bold
|
||||
|
||||
|
||||
def main():
|
||||
@ -57,6 +58,12 @@ def convert_txt(path, options):
|
||||
the text in C{path}.)
|
||||
"""
|
||||
import fileinput
|
||||
header = None
|
||||
if options.header:
|
||||
header = Paragraph()
|
||||
header.append(Italic(options.title))
|
||||
header.append(' by ')
|
||||
header.append(Bold(options.author))
|
||||
book = Book(title=options.title, author=options.author, \
|
||||
sourceencoding=options.encoding, freetext=options.freetext, \
|
||||
category=options.category)
|
||||
|
Loading…
x
Reference in New Issue
Block a user