mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Add support for adjusting margins.
This commit is contained in:
parent
23b177889f
commit
97b51d8693
248
prs-500.e4p
248
prs-500.e4p
@ -1,248 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-4.0.dtd">
|
||||
<!-- eric4 project file for project prs-500 -->
|
||||
<!-- Saved: 2007-01-03, 23:14:45 -->
|
||||
<!-- Copyright (C) 2007 Kovid Goyal, kovid@kovidgoyal.net -->
|
||||
<Project version="4.0">
|
||||
<ProgLanguage mixed="0">Python</ProgLanguage>
|
||||
<UIType>Qt4</UIType>
|
||||
<Description>Library to communicate with the Sony Reader PRS-500 via USB</Description>
|
||||
<Version></Version>
|
||||
<Author>Kovid Goyal</Author>
|
||||
<Email>kovid@kovidgoyal.net</Email>
|
||||
<Sources>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>communicate.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>prstypes.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>errors.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>__init__.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Name>setup.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>cli</Dir>
|
||||
<Name>terminfo.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>cli</Dir>
|
||||
<Name>main.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>cli</Dir>
|
||||
<Name>__init__.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>main.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>__init__.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>lrf</Dir>
|
||||
<Name>meta.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>lrf</Dir>
|
||||
<Name>__init__.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>database.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>editbook.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>books.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>widgets.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>lrf</Dir>
|
||||
<Name>makelrf.py</Name>
|
||||
</Source>
|
||||
<Source>
|
||||
<Dir>libprs500</Dir>
|
||||
<Name>ptempfile.py</Name>
|
||||
</Source>
|
||||
</Sources>
|
||||
<Forms>
|
||||
<Form>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>main.ui</Name>
|
||||
</Form>
|
||||
<Form>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>editbook.ui</Name>
|
||||
</Form>
|
||||
</Forms>
|
||||
<Translations>
|
||||
</Translations>
|
||||
<Resources>
|
||||
</Resources>
|
||||
<Interfaces>
|
||||
</Interfaces>
|
||||
<Others>
|
||||
<Other>
|
||||
<Name>epydoc.conf</Name>
|
||||
</Other>
|
||||
<Other>
|
||||
<Name>epydoc-pdf.conf</Name>
|
||||
</Other>
|
||||
</Others>
|
||||
<MainScript>
|
||||
<Dir>libprs500</Dir>
|
||||
<Dir>gui</Dir>
|
||||
<Name>main.py</Name>
|
||||
</MainScript>
|
||||
<Vcs>
|
||||
<VcsType>Subversion</VcsType>
|
||||
<VcsOptions>
|
||||
<dict>
|
||||
<key>
|
||||
<string>status</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>log</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>global</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>update</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>remove</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>add</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>tag</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>export</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>commit</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>diff</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>checkout</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>history</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string></string>
|
||||
</list>
|
||||
</value>
|
||||
</dict>
|
||||
</VcsOptions>
|
||||
<VcsOtherData>
|
||||
<dict>
|
||||
<key>
|
||||
<string>standardLayout</string>
|
||||
</key>
|
||||
<value>
|
||||
<bool>True</bool>
|
||||
</value>
|
||||
</dict>
|
||||
</VcsOtherData>
|
||||
</Vcs>
|
||||
<FiletypeAssociations>
|
||||
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
||||
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
||||
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
||||
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
||||
</FiletypeAssociations>
|
||||
</Project>
|
7
setup.py
7
setup.py
@ -38,7 +38,7 @@ if sys.argv[1] == 'py2exe':
|
||||
windows = [{'script' : 'src/libprs500/gui/main.py', 'dest_base':'prs500-gui',
|
||||
'icon_resources':[(1,'icons/library.ico')]}]
|
||||
excludes = ["Tkconstants", "Tkinter", "tcl", "_imagingtk",
|
||||
"ImageTk", "FixTk"]
|
||||
"ImageTk", "FixTk", 'pydoc']
|
||||
options = { 'py2exe' : {'includes' : ['sip', 'pkg_resources'],
|
||||
'dist_dir' : py2exe_dir,
|
||||
'packages' : ['PIL'],
|
||||
@ -87,7 +87,6 @@ Var MUI_TEMP
|
||||
!define PY2EXE_DIR "C:\libprs500"
|
||||
!define LIBUSB_DIR "C:\libusb-prs500"
|
||||
!define LIBUNRAR_DIR "C:\Program Files\UnrarDLL"
|
||||
!define QT_DIR "C:\Qt\4.2.3\bin"
|
||||
|
||||
;------------------------------------------------------------------------------------------------------
|
||||
;General
|
||||
@ -155,9 +154,7 @@ Section "libprs500" Seclibprs500
|
||||
|
||||
;ADD YOUR OWN FILES HERE...
|
||||
File /r "${PY2EXE_DIR}\*"
|
||||
; The next line can be commented out once py2exe starts including QtSvg.dll
|
||||
File "${QT_DIR}\QtSvg4.dll"
|
||||
|
||||
|
||||
SetOutPath "$INSTDIR\driver"
|
||||
File "${LIBUSB_DIR}\*.dll"
|
||||
File "${LIBUSB_DIR}\*.sys"
|
||||
|
@ -13,7 +13,7 @@
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
''' E-book management software'''
|
||||
__version__ = "0.3.45"
|
||||
__version__ = "0.3.46"
|
||||
__docformat__ = "epytext"
|
||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
|
||||
|
@ -29,11 +29,10 @@ __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
|
||||
class PRS500_PROFILE(object):
|
||||
screen_width = 600
|
||||
screen_height = 800
|
||||
page_width = 575
|
||||
page_height = 747
|
||||
screen_height = 775
|
||||
dpi = 166
|
||||
|
||||
|
||||
def profile_from_string(option, opt_str, value, parser):
|
||||
if value == 'prs500':
|
||||
setattr(parser.values, option.dest, PRS500_PROFILE)
|
||||
@ -66,11 +65,21 @@ def option_parser(usage):
|
||||
profiles=['prs500']
|
||||
parser.add_option('-o', '--output', action='store', default=None, \
|
||||
help='Output file name. Default is derived from input filename')
|
||||
parser.add_option('-p', '--profile', default=PRS500_PROFILE, dest='profile', type='choice',
|
||||
page = parser.add_option_group('PAGE OPTIONS')
|
||||
page.add_option('-p', '--profile', default=PRS500_PROFILE, dest='profile', type='choice',
|
||||
choices=profiles, action='callback', callback=profile_from_string,
|
||||
help='''Profile of the target device for which this LRF is '''
|
||||
'''being generated. Default: ''' + profiles[0] + \
|
||||
''' Supported profiles: '''+', '.join(profiles))
|
||||
page.add_option('--left-margin', default=20, dest='left_margin', type='int',
|
||||
help='''Left margin of page. Default is %default px.''')
|
||||
page.add_option('--right-margin', default=5, dest='right_margin', type='int',
|
||||
help='''Right margin of page. Default is %default px.''')
|
||||
page.add_option('--top-margin', default=10, dest='top_margin', type='int',
|
||||
help='''Top margin of page. Default is %default px.''')
|
||||
page.add_option('--bottom-margin', default=10, dest='bottom_margin', type='int',
|
||||
help='''Bottom margin of page. Default is %default px.''')
|
||||
|
||||
debug = parser.add_option_group('DEBUG OPTIONS')
|
||||
debug.add_option('--verbose', dest='verbose', action='store_true', default=False,
|
||||
help='''Be verbose while processing''')
|
||||
@ -78,9 +87,14 @@ def option_parser(usage):
|
||||
help='Convert to LRS', default=False)
|
||||
return parser
|
||||
|
||||
def Book(font_delta=0, header=None, profile=PRS500_PROFILE, **settings):
|
||||
ps = dict(textwidth=profile.page_width,
|
||||
textheight=profile.page_height)
|
||||
def Book(options, font_delta=0, header=None,
|
||||
profile=PRS500_PROFILE, **settings):
|
||||
ps = {}
|
||||
ps['topmargin'] = options.top_margin
|
||||
ps['evensidemargin'] = options.left_margin
|
||||
ps['oddsidemargin'] = options.left_margin
|
||||
ps['textwidth'] = profile.screen_width - (options.left_margin + options.right_margin)
|
||||
ps['textheight'] = profile.screen_height - (options.top_margin + options.bottom_margin)
|
||||
if header:
|
||||
hdr = Header()
|
||||
hb = TextBlock(textStyle=TextStyle(align='foot', fontsize=60))
|
||||
@ -89,6 +103,8 @@ def Book(font_delta=0, header=None, profile=PRS500_PROFILE, **settings):
|
||||
ps['headheight'] = 30
|
||||
ps['header'] = hdr
|
||||
ps['topmargin'] = 10
|
||||
if ps['textheight'] + ps['topmargin'] > profile.screen_height:
|
||||
ps['textheight'] = profile.screen_height - ps['topmargin']
|
||||
baselineskip = (12 + 2*font_delta)*10
|
||||
return _Book(textstyledefault=dict(fontsize=100+font_delta*20,
|
||||
parindent=80, linespace=12,
|
||||
|
@ -740,7 +740,10 @@ class HTMLConverter(object):
|
||||
self.scaled_images[path] = pt
|
||||
return pt.name
|
||||
|
||||
if not self.disable_autorotation and width > self.profile.page_width and width > height:
|
||||
pheight = int(self.current_page.pageStyle.attrs['textheight'])
|
||||
pwidth = int(self.current_page.pageStyle.attrs['textwidth'])
|
||||
|
||||
if not self.disable_autorotation and width > pwidth and width > height:
|
||||
pt = PersistentTemporaryFile(suffix='.jpeg')
|
||||
im = im.rotate(90)
|
||||
im.convert('RGB').save(pt, 'JPEG')
|
||||
@ -749,19 +752,20 @@ class HTMLConverter(object):
|
||||
self.rotated_images[path] = pt
|
||||
width, height = im.size
|
||||
|
||||
if height > self.profile.page_height:
|
||||
corrf = self.profile.page_height/(1.*height)
|
||||
width, height = floor(corrf*width), self.profile.page_height-1
|
||||
if width > self.profile.page_width:
|
||||
corrf = (self.profile.page_width)/(1.*width)
|
||||
width, height = self.profile.page_width-1, floor(corrf*height)
|
||||
|
||||
if height > pheight:
|
||||
corrf = pheight/(1.*height)
|
||||
width, height = floor(corrf*width), pheight-1
|
||||
if width > pwidth:
|
||||
corrf = (pwidth)/(1.*width)
|
||||
width, height = pwidth-1, floor(corrf*height)
|
||||
path = scale_image(width, height)
|
||||
if width > self.profile.page_width:
|
||||
corrf = self.profile.page_width/(1.*width)
|
||||
width, height = self.profile.page_width-1, floor(corrf*height)
|
||||
if height > self.profile.page_height:
|
||||
corrf = (self.profile.page_height)/(1.*height)
|
||||
width, height = floor(corrf*width), self.profile.page_height-1
|
||||
if width > pwidth:
|
||||
corrf = pwidth/(1.*width)
|
||||
width, height = pwidth-1, floor(corrf*height)
|
||||
if height > pheight:
|
||||
corrf = (pheight)/(1.*height)
|
||||
width, height = floor(corrf*width), pheight-1
|
||||
path = scale_image(width, height)
|
||||
width, height = int(width), int(height)
|
||||
|
||||
@ -774,11 +778,10 @@ class HTMLConverter(object):
|
||||
|
||||
self.process_alignment(tag_css)
|
||||
|
||||
if max(width, height) <= min(self.profile.page_width,
|
||||
self.profile.page_height)/5.:
|
||||
if max(width, height) <= min(pwidth, pheight)/5.:
|
||||
self.current_para.append(Plot(im, xsize=ceil(width*factor),
|
||||
ysize=ceil(height*factor)))
|
||||
elif height <= int(floor((2/3.)*self.profile.page_height)):
|
||||
elif height <= int(floor((2/3.)*pheight)):
|
||||
pb = self.current_block
|
||||
self.end_current_para()
|
||||
self.process_alignment(tag_css)
|
||||
@ -792,11 +795,14 @@ class HTMLConverter(object):
|
||||
self.current_para = Paragraph()
|
||||
else:
|
||||
self.end_page()
|
||||
self.current_page.append(Canvas(width=self.profile.page_width,
|
||||
self.current_page.append(Canvas(width=pwidth,
|
||||
height=height))
|
||||
left = int(floor((self.profile.page_width - width)/2.))
|
||||
self.current_page.contents[-1].put_object(ImageBlock(self.images[path]),
|
||||
left, 0)
|
||||
left = int(floor((pwidth - width)/2.))
|
||||
self.current_page.contents[-1].put_object(
|
||||
ImageBlock(self.images[path], xsize=pwidth,
|
||||
ysize=pheight, x1=pwidth, y1=pheight,
|
||||
blockwidth=pwidth, blockheight=pheight),
|
||||
left, 0)
|
||||
|
||||
def parse_tag(self, tag, parent_css):
|
||||
try:
|
||||
@ -1039,7 +1045,7 @@ class HTMLConverter(object):
|
||||
self.end_current_para()
|
||||
self.current_block.append(CR())
|
||||
self.end_current_block()
|
||||
self.current_page.RuledLine(linelength=self.profile.page_width)
|
||||
self.current_page.RuledLine(linelength=int(self.current_page.pageStyle.attrs['textwidth']))
|
||||
elif tagname == 'td': # Needed for nested tables
|
||||
self.current_para.append(" ")
|
||||
self.process_children(tag, tag_css)
|
||||
@ -1056,9 +1062,9 @@ class HTMLConverter(object):
|
||||
colpad = 10
|
||||
table = Table(self, tag, tag_css, rowpad=10, colpad=10)
|
||||
canvases = []
|
||||
for block, xpos, ypos, delta in table.blocks(self.profile.page_width):
|
||||
for block, xpos, ypos, delta in table.blocks(int(self.current_page.pageStyle.attrs['textwidth'])):
|
||||
if not block:
|
||||
canvases.append(Canvas(self.profile.page_width, ypos+colpad,
|
||||
canvases.append(Canvas(int(self.current_page.pageStyle.attrs['textwidth']), ypos+colpad,
|
||||
blockrule='block-fixed'))
|
||||
else:
|
||||
canvases[-1].put_object(block, xpos + int(delta/2.), 0)
|
||||
@ -1133,7 +1139,7 @@ def process_file(path, options):
|
||||
header.append(Bold(options.title))
|
||||
header.append(' by ')
|
||||
header.append(Italic(options.author+" "))
|
||||
book = Book(header=header, **args)
|
||||
book = Book(options, header=header, **args)
|
||||
le = re.compile(options.link_exclude) if options.link_exclude else \
|
||||
re.compile('$')
|
||||
pb = re.compile(options.page_break, re.IGNORECASE) if options.page_break else \
|
||||
|
@ -73,7 +73,7 @@ def convert_txt(path, options):
|
||||
header.append(Italic(options.author))
|
||||
title = (options.title, options.title_sort)
|
||||
author = (options.author, options.author_sort)
|
||||
book = Book(header=header, title=title, author=author, \
|
||||
book = Book(options, header=header, title=title, author=author, \
|
||||
publisher=options.publisher,
|
||||
sourceencoding=options.encoding, freetext=options.freetext, \
|
||||
category=options.category, booksetting=BookSetting
|
||||
|
Loading…
x
Reference in New Issue
Block a user