Use ems not pts for dynammic rescaling

This commit is contained in:
Kovid Goyal 2009-05-08 21:18:26 -07:00
parent 0ba01714d2
commit e58c5eb50f
15 changed files with 897 additions and 752 deletions

View File

@ -222,8 +222,8 @@ class CSSFlattener(object):
if dyn_rescale is not None:
fsize = self.fmap[_sbase]
fsize *= dyn_rescale
cssdict['font-size'] = '%0.5fem'%(fsize/psize)
psize = fsize
cssdict['font-size'] = '%0.5fpt'%(fsize)
elif 'font-size' in cssdict or tag == 'body':
fsize = self.fmap[style['font-size']]
cssdict['font-size'] = "%0.5fem" % (fsize / psize)

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.gui2.convert.pdf_output_ui import Ui_Form
from calibre.gui2.convert import Widget
from calibre.ebooks.pdf.pageoptions import PAPER_SIZES, ORIENTATIONS
from calibre.gui2.widgets import BasicComboModel
paper_size_model = None
orientation_model = None
class PluginWidget(Widget, Ui_Form):
TITLE = _('PDF Output')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'pdf_output', ['paper_size', 'orientation'])
self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id)
default_paper_size = self.opt_paper_size.currentText()
default_orientation = self.opt_orientation.currentText()
global paper_size_model
if paper_size_model is None:
paper_size_model = BasicComboModel(PAPER_SIZES.keys())
self.paper_size_model = paper_size_model
self.opt_paper_size.setModel(self.paper_size_model)
default_index = self.opt_paper_size.findText(default_paper_size)
self.opt_paper_size.setCurrentIndex(default_index if default_index != -1 else 0)
global orientation_model
if orientation_model is None:
orientation_model = BasicComboModel(ORIENTATIONS.keys())
self.orientation_model = orientation_model
self.opt_orientation.setModel(self.orientation_model)
default_index = self.opt_orientation.findText(default_orientation)
self.opt_orientation.setCurrentIndex(default_index if default_index != -1 else 0)

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Paper Size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="opt_paper_size"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Orientation:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="opt_orientation"/>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>213</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from calibre.gui2.convert.txt_output_ui import Ui_Form
from calibre.gui2.convert import Widget
from calibre.ebooks.txt.writer import TxtNewlines
from calibre.gui2.widgets import BasicComboModel
newline_model = None
class PluginWidget(Widget, Ui_Form):
TITLE = _('TXT Output')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'txt_output', ['newline'])
self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id)
default = self.opt_newline.currentText()
global newline_model
if newline_model is None:
newline_model = BasicComboModel(TxtNewlines.NEWLINE_TYPES.keys())
self.newline_model = newline_model
self.opt_newline.setModel(self.newline_model)
default_index = self.opt_newline.findText(default)
self.opt_newline.setCurrentIndex(default_index if default_index != -1 else 0)

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Newline Type:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="opt_newline"/>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>246</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -25,7 +25,7 @@ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin
disable_plugin, customize_plugin, \
plugin_customization, add_plugin, \
remove_plugin, input_format_plugins, \
output_format_plugins
output_format_plugins, available_output_formats
from calibre.utils.smtp import config as smtp_prefs
from calibre.gui2.convert.look_and_feel import LookAndFeelWidget
from calibre.gui2.convert.page_setup import PageSetupWidget
@ -392,6 +392,13 @@ class ConfigDialog(QDialog, Ui_Dialog):
self.toolbar_button_size.setCurrentIndex(0 if icons == self.ICON_SIZES[0] else 1 if icons == self.ICON_SIZES[1] else 2)
self.show_toolbar_text.setChecked(config['show_text_in_toolbar'])
output_formats = sorted(available_output_formats())
output_formats.remove('oeb')
for f in output_formats:
self.output_format.addItem(f)
default_index = self.output_format.findText(prefs['output_format'])
self.output_format.setCurrentIndex(default_index if default_index != -1 else 0)
self.book_exts = sorted(BOOK_EXTENSIONS)
for ext in self.book_exts:
self.single_format.addItem(ext.upper(), QVariant(ext))
@ -760,6 +767,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
p = {0:'normal', 1:'high', 2:'low'}[self.priority.currentIndex()]
prefs['worker_process_priority'] = p
prefs['read_file_metadata'] = bool(self.pdf_metadata.isChecked())
prefs['output_format'] = self.output_format.currentText()
config['save_to_disk_single_format'] = self.book_exts[self.single_format.currentIndex()]
config['cover_flow_queue_length'] = self.cover_browse.value()
prefs['language'] = str(self.language.itemData(self.language.currentIndex()).toString())

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Kovid Goyal</author>
<class>Dialog</class>
@ -23,7 +24,7 @@
<item>
<widget class="QListView" name="category_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="MinimumExpanding" >
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -69,7 +70,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -145,7 +146,7 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" >
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Format for &amp;single file save:</string>
@ -155,10 +156,10 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<item row="1" column="1">
<widget class="QComboBox" name="single_format"/>
</item>
<item row="1" column="0" >
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default network &amp;timeout:</string>
@ -168,7 +169,7 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="2" column="1">
<widget class="QSpinBox" name="timeout">
<property name="toolTip">
<string>Set the default timeout for network fetches (i.e. anytime we go out to the internet to get information)</string>
@ -187,10 +188,10 @@
</property>
</widget>
</item>
<item row="2" column="1" >
<item row="3" column="1">
<widget class="QComboBox" name="language"/>
</item>
<item row="2" column="0" >
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Choose &amp;language (requires restart):</string>
@ -200,7 +201,7 @@
</property>
</widget>
</item>
<item row="3" column="1" >
<item row="4" column="1">
<widget class="QComboBox" name="priority">
<item>
<property name="text">
@ -219,7 +220,7 @@
</item>
</widget>
</item>
<item row="3" column="0" >
<item row="4" column="0">
<widget class="QLabel" name="priority_label">
<property name="text">
<string>Job &amp;priority:</string>
@ -229,6 +230,16 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Output Format:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="output_format"/>
</item>
</layout>
</item>
<item>
@ -565,7 +576,7 @@
<item>
<widget class="QLineEdit" name="email_from">
<property name="toolTip">
<string>&lt;p>This is what will be present in the From: field of emails sent by calibre.&lt;br> Set it to your email address</string>
<string>&lt;p&gt;This is what will be present in the From: field of emails sent by calibre.&lt;br&gt; Set it to your email address</string>
</property>
</widget>
</item>
@ -642,7 +653,7 @@
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox_5">
<property name="toolTip">
<string>&lt;p>A mail server is useful if the service you are sending mail to only accepts email from well know mail services.</string>
<string>&lt;p&gt;A mail server is useful if the service you are sending mail to only accepts email from well know mail services.</string>
</property>
<property name="title">
<string>Mail &amp;Server</string>
@ -651,7 +662,7 @@
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_16">
<property name="text">
<string>calibre can &lt;b>optionally&lt;/b> use a server to send mail</string>
<string>calibre can &lt;b&gt;optionally&lt;/b&gt; use a server to send mail</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -136,14 +136,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
SIGNAL('location_selected(PyQt_PyObject)'),
self.location_selected)
self.output_formats = sorted(['EPUB', 'MOBI', 'LRF'])
for f in self.output_formats:
self.output_format.addItem(f)
self.output_format.setCurrentIndex(self.output_formats.index(
prefs['output_format']))
self.connect(self.output_format, SIGNAL('currentIndexChanged(QString)'),
self.change_output_format, Qt.QueuedConnection)
####################### Vanity ########################
self.vanity_template = _('<p>For help visit <a href="http://%s.'
'kovidgoyal.net/user_manual">%s.kovidgoyal.net</a>'
@ -266,8 +258,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
setPopupMode(QToolButton.MenuButtonPopup)
self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu)
QObject.connect(self.config_button,
SIGNAL('clicked(bool)'), self.do_config)
self.connect(self.preferences_action, SIGNAL('triggered(bool)'),
self.do_config)
self.connect(self.action_preferences, SIGNAL('triggered(bool)'),
@ -452,12 +442,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
window.show()
setattr(window, '__systray_minimized', False)
def change_output_format(self, x):
of = unicode(x).strip()
if of != prefs['output_format']:
prefs.set('output_format', of)
def test_server(self, *args):
if self.content_server.exception is not None:
error_dialog(self, _('Failed to start content server'),
@ -1057,7 +1041,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
rows = [x.row() for x in \
self.library_view.selectionModel().selectedRows()]
jobs, changed, bad = convert_bulk_ebook(self,
self.library_view.model().db, row_ids)
self.library_view.model().db, row_ids, out_format=prefs['output_format'])
for func, args, desc, fmt, id, temp_files in jobs:
if id not in bad:
job = self.job_manager.run_job(Dispatcher(self.book_converted),
@ -1076,7 +1060,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
rows = [x.row() for x in \
self.library_view.selectionModel().selectedRows()]
jobs, changed, bad = convert_single_ebook(self,
self.library_view.model().db, row_ids)
self.library_view.model().db, row_ids, out_format=prefs['output_format'])
for func, args, desc, fmt, id, temp_files in jobs:
if id not in bad:
job = self.job_manager.run_job(Dispatcher(self.book_converted),

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>Kovid Goyal</author>
<class>MainWindow</class>
@ -11,7 +12,7 @@
</rect>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -33,7 +34,7 @@
<item>
<widget class="LocationView" name="location_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -119,7 +120,7 @@
<item>
<widget class="QLabel" name="vanity">
<property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -141,24 +142,6 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Output:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="output_format" >
<property name="toolTip" >
<string>Set the output format that is used when converting ebooks and downloading news</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@ -204,7 +187,7 @@
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -213,10 +196,10 @@
<bool>false</bool>
</property>
<property name="toolTip">
<string>Search the list of books by title or author&lt;br>&lt;br>Words separated by spaces are ANDed</string>
<string>Search the list of books by title or author&lt;br&gt;&lt;br&gt;Words separated by spaces are ANDed</string>
</property>
<property name="whatsThis">
<string>Search the list of books by title, author, publisher, tags and comments&lt;br>&lt;br>Words separated by spaces are ANDed</string>
<string>Search the list of books by title, author, publisher, tags and comments&lt;br&gt;&lt;br&gt;Words separated by spaces are ANDed</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
@ -243,46 +226,12 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="config_button" >
<property name="toolTip" >
<string>Configuration</string>
</property>
<property name="text" >
<string>...</string>
</property>
<property name="icon" >
<iconset resource="images.qrc" >
<normaloff>:/images/config.svg</normaloff>:/images/config.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QStackedWidget" name="stack">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>100</verstretch>
</sizepolicy>
@ -344,7 +293,7 @@
<item>
<widget class="BooksView" name="library_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
@ -384,7 +333,7 @@
<item row="0" column="0">
<widget class="DeviceBooksView" name="memory_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>100</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
@ -422,7 +371,7 @@
<item row="0" column="0">
<widget class="DeviceBooksView" name="card_a_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>10</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
@ -460,7 +409,7 @@
<item row="0" column="0">
<widget class="DeviceBooksView" name="card_b_view">
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>10</horstretch>
<verstretch>10</verstretch>
</sizepolicy>

View File

@ -72,7 +72,7 @@ def convert_single_ebook(parent, db, book_ids, auto_conversion=False, out_format
return jobs, changed, bad
def convert_bulk_ebook(parent, db, book_ids):
def convert_bulk_ebook(parent, db, book_ids, out_format=None):
changed = False
jobs = []
bad = []
@ -82,7 +82,7 @@ def convert_bulk_ebook(parent, db, book_ids):
return None, None, None
parent.status_bar.showMessage(_('Starting conversion of %d books') % total, 2000)
d = BulkConfig(parent, db)
d = BulkConfig(parent, db, out_format)
if d.exec_() != QDialog.Accepted:
return jobs, changed, bad

View File

@ -18,9 +18,13 @@ class RecipeInput(InputFormatPlugin):
file_types = set(['recipe'])
recommendations = set([
('chapter_mark', 'none', OptionRecommendation.HIGH),
('chapter', None, OptionRecommendation.HIGH),
('dont_split_on_page_breaks', True, OptionRecommendation.HIGH),
('use_auto_toc', False, OptionRecommendation.HIGH),
('input_encoding', None, OptionRecommendation.HIGH),
('input_profile', 'default', OptionRecommendation.HIGH),
('page_breaks_before', None, OptionRecommendation.HIGH),
('insert_metadata', False, OptionRecommendation.HIGH),
])
options = set([

View File

@ -579,8 +579,9 @@ class BasicNewsRecipe(Recipe):
def feeds2index(self, feeds):
templ = templates.IndexTemplate()
css = self.template_css + '\n\n' +(self.extra_css if self.extra_css else '')
return templ.generate(self.title, self.timefmt, feeds,
extra_css=self.extra_css).render(doctype='xhtml')
extra_css=css).render(doctype='xhtml')
@classmethod
def description_limiter(cls, src):
@ -631,8 +632,9 @@ class BasicNewsRecipe(Recipe):
templ = templates.FeedTemplate()
css = self.template_css + '\n\n' +(self.extra_css if self.extra_css else '')
return templ.generate(feed, self.description_limiter,
extra_css=self.extra_css).render(doctype='xhtml')
extra_css=css).render(doctype='xhtml')
def _fetch_article(self, url, dir, f, a, num_of_feeds):

View File

@ -10,6 +10,7 @@ class DNAIndia(BasicNewsRecipe):
description = 'Mumbai news, India news, World news, breaking news'
__author__ = 'Kovid Goyal'
language = _('English')
encoding = 'cp1252'
feeds = [
('Top News', 'http://www.dnaindia.com/syndication/rss_topnews.xml'),

View File

@ -5,7 +5,6 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import re, string, time
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup
class Newsweek(BasicNewsRecipe):
@ -15,7 +14,12 @@ class Newsweek(BasicNewsRecipe):
no_stylesheets = True
language = _('English')
extra_css = '#content { font:serif 12pt; }\n.story {font:12pt}\n.HorizontalHeader {font:18pt}\n.deck {font:16pt}'
extra_css = '''
#content { font-size:normal; font-family: serif }
.story { font-size:normal }
.HorizontalHeader {font-size:xx-large}
.deck {font-size:x-large}
'''
keep_only_tags = [dict(name='div', id='content')]
remove_tags = [

View File

@ -53,9 +53,15 @@ def save_soup(soup, target):
ns = BeautifulSoup('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />')
nm = ns.find('meta')
metas = soup.findAll('meta', content=True)
added = False
for meta in metas:
if 'charset' in meta.get('content', '').lower():
meta.replaceWith(nm)
added = True
if not added:
head = soup.find('head')
if head is not None:
head.insert(0, nm)
selfdir = os.path.dirname(target)
@ -67,6 +73,7 @@ def save_soup(soup, target):
html = unicode(soup)
with open(target, 'wb') as f:
idx = html.find('hoping')
f.write(html.encode('utf-8'))
class response(str):