mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Implement #239
This commit is contained in:
parent
9eee4a67b6
commit
e35e673f44
@ -125,6 +125,8 @@ def option_parser(usage):
|
||||
help='Add a header to all the pages with title and author.')
|
||||
laf.add_option('--headerformat', default="%t by %a", dest='headerformat', type='string',
|
||||
help='Set the format of the header. %a is replaced by the author and %t by the title. Default is %default')
|
||||
laf.add_option('--override-css', default=None, dest='_override_css', type='string',
|
||||
help='Override the CSS. Can be either a path to a CSS stylesheet or a string. If it is a string it is interpreted as CSS.')
|
||||
|
||||
page = parser.add_option_group('PAGE OPTIONS')
|
||||
profiles = profile_map.keys()
|
||||
|
@ -48,6 +48,13 @@ from libprs500.ebooks.metadata.opf import OPFReader
|
||||
from libprs500.devices.interface import Device
|
||||
from libprs500.ebooks.lrf.html.color_map import lrs_color
|
||||
|
||||
def update_css(ncss, ocss):
|
||||
for key in ncss.keys():
|
||||
if ocss.has_key(key):
|
||||
ocss[key].update(ncss[key])
|
||||
else:
|
||||
ocss[key] = ncss[key]
|
||||
|
||||
class HTMLConverter(object):
|
||||
SELECTOR_PAT = re.compile(r"([A-Za-z0-9\-\_\:\.]+[A-Za-z0-9\-\_\:\.\s\,]*)\s*\{([^\}]*)\}")
|
||||
PAGE_BREAK_PAT = re.compile(r'page-break-(?:after|before)\s*:\s*(\w+)', re.IGNORECASE)
|
||||
@ -199,6 +206,23 @@ class HTMLConverter(object):
|
||||
self.list_counter = 1
|
||||
|
||||
self.book = book #: The Book object representing a BBeB book
|
||||
|
||||
self.override_css = {}
|
||||
self.override_pcss = {}
|
||||
if self._override_css is not None:
|
||||
if os.access(self._override_css, os.R_OK):
|
||||
src = open(self._override_css, 'rb').read()
|
||||
else:
|
||||
src = self._override_css
|
||||
match = self.PAGE_BREAK_PAT.search(src)
|
||||
if match and not re.match('avoid', match.group(1), re.IGNORECASE):
|
||||
self.page_break_found = True
|
||||
ncss, npcss = self.parse_css(src)
|
||||
if ncss:
|
||||
update_css(ncss, self.override_css)
|
||||
if npcss:
|
||||
update_css(npcss, self.override_pcss)
|
||||
|
||||
self.start_on_file(path, is_root=True)
|
||||
|
||||
def is_baen(self, soup):
|
||||
@ -1236,12 +1260,6 @@ class HTMLConverter(object):
|
||||
else:
|
||||
self.logger.debug("Failed to process: %s", str(tag))
|
||||
elif tagname in ['style', 'link']:
|
||||
def update_css(ncss, ocss):
|
||||
for key in ncss.keys():
|
||||
if ocss.has_key(key):
|
||||
ocss[key].update(ncss[key])
|
||||
else:
|
||||
ocss[key] = ncss[key]
|
||||
ncss, npcss = {}, {}
|
||||
if tagname == 'style':
|
||||
for c in tag.contents:
|
||||
@ -1265,8 +1283,10 @@ class HTMLConverter(object):
|
||||
pass
|
||||
if ncss:
|
||||
update_css(ncss, self.css)
|
||||
self.css.update(self.override_css)
|
||||
if npcss:
|
||||
update_css(npcss, self.pseudo_css)
|
||||
self.pseudo_css.update(self.override_pcss)
|
||||
elif tagname == 'pre':
|
||||
self.end_current_para()
|
||||
self.end_current_block()
|
||||
|
@ -15,7 +15,8 @@
|
||||
import os
|
||||
|
||||
from PyQt4.QtCore import QObject, SIGNAL, Qt
|
||||
from PyQt4.QtGui import QAbstractSpinBox, QLineEdit, QCheckBox, QDialog, QPixmap
|
||||
from PyQt4.QtGui import QAbstractSpinBox, QLineEdit, QCheckBox, QDialog, \
|
||||
QPixmap, QTextEdit
|
||||
|
||||
from libprs500.gui2.dialogs.lrf_single_ui import Ui_LRFSingleDialog
|
||||
from libprs500.gui2.dialogs.choose_format import ChooseFormatDialog
|
||||
@ -108,6 +109,8 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
obj.setValue(cmdline[i+1])
|
||||
elif isinstance(obj, QLineEdit):
|
||||
obj.setText(cmdline[i+1])
|
||||
elif isinstance(obj, QTextEdit):
|
||||
obj.setPlainText(cmdline[i+1])
|
||||
profile = cmdline[cmdline.index('--profile')+1]
|
||||
self.gui_profile.setCurrentIndex(self.gui_profile.findText(profile))
|
||||
for prepro in self.PREPROCESS_OPTIONS:
|
||||
@ -197,6 +200,8 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
obj.setValue(default)
|
||||
elif isinstance(obj, QLineEdit) and default:
|
||||
obj.setText(default)
|
||||
elif isinstance(obj, QTextEdit) and default:
|
||||
obj.setPlainText(default)
|
||||
elif isinstance(obj, QCheckBox):
|
||||
state = Qt.Checked if default else Qt.Unchecked
|
||||
obj.setCheckState(state)
|
||||
@ -266,6 +271,10 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
val = qstring_to_unicode(obj.text())
|
||||
if val:
|
||||
cmd.extend([opt, val])
|
||||
elif isinstance(obj, QTextEdit):
|
||||
val = qstring_to_unicode(obj.toPlainText())
|
||||
if val:
|
||||
cmd.extend([opt, val])
|
||||
elif isinstance(obj, QCheckBox):
|
||||
if obj.checkState() == Qt.Checked:
|
||||
cmd.append(opt)
|
||||
|
@ -468,7 +468,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" >
|
||||
<item row="0" column="2" >
|
||||
<widget class="QDoubleSpinBox" name="gui_font_delta" >
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
@ -503,7 +503,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3" >
|
||||
<item row="1" column="2" >
|
||||
<widget class="QDoubleSpinBox" name="gui_wordspace" >
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
@ -538,7 +538,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2" >
|
||||
<item row="2" column="1" colspan="2" >
|
||||
<widget class="QComboBox" name="preprocess" />
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4" >
|
||||
@ -597,18 +597,15 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" >
|
||||
<widget class="QLabel" name="label_21" >
|
||||
<property name="text" >
|
||||
<string>Override<br>CSS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>41</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QTextEdit" name="gui_override_css" />
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user