diff --git a/src/calibre/gui2/convert/font_key.py b/src/calibre/gui2/convert/font_key.py new file mode 100644 index 0000000000..82d72d7e6d --- /dev/null +++ b/src/calibre/gui2/convert/font_key.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import with_statement + +__license__ = 'GPL v3' +__copyright__ = '2009, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from PyQt4.Qt import QDialog, SIGNAL + +from calibre.gui2.convert.font_key_ui import Ui_Dialog + +class FontKeyChooser(QDialog, Ui_Dialog): + + def __init__(self, parent=None, base_font_size=0.0, font_key=None): + QDialog.__init__(self, parent) + self.setupUi(self) + + self.default_font_key = font_key + self.default_base_font_size = base_font_size + self.connect(self.buttonBox, SIGNAL('clicked(QAbstractButton*)'), + self.button_clicked) + self.connect(self.button_use_default, SIGNAL('clicked()'), + self.use_default) + + for x in ('input_base_font_size', 'input_font_size', + 'output_base_font_size'): + self.connect(getattr(self, x), SIGNAL('valueChanged(double)'), + self.calculate) + self.connect(self.font_size_key, SIGNAL('textChanged(QString)'), + self.calculate) + + self.initialize() + + def initialize(self): + self.input_base_font_size.setValue(12.0) + self.input_font_size.setValue(12.0) + self.input_mapped_font_size.setText('0.0 pt') + self.output_base_font_size.setValue(self.default_base_font_size) + if self.default_font_key: + self.font_size_key.setText(self.default_font_key) + else: + self.font_size_key.setText('') + self.calculate() + + def button_clicked(self, button): + if button is self.buttonBox.button(self.buttonBox.RestoreDefaults): + self.output_base_font_size.setValue(0.0) + self.font_size_key.setText('') + self.calculate() + + def get_profile_values(self): + from calibre.ebooks.conversion.config import load_defaults + recs = load_defaults('page_setup') + pfname = recs.get('output_profile', 'default') + from calibre.customize.ui import output_profiles + for profile in output_profiles(): + if profile.short_name == pfname: + break + dbase = profile.fbase + fsizes = profile.fkey + return dbase, fsizes + + @property + def fsizes(self): + key = unicode(self.font_size_key.text()).strip() + return [float(x.strip()) for x in key.split(',') if x.strip()] + + @property + def dbase(self): + return self.output_base_font_size.value() + + def calculate(self, *args): + sbase = self.input_base_font_size.value() + dbase = self.dbase + fsize = self.input_font_size.value() + try: + fsizes = self.fsizes + except: + return + + if dbase == 0.0 or not fsizes: + pd, pfs = self.get_profile_values() + if dbase == 0.0: + dbase = pd + if not fsizes: + fsizes = pfs + + from calibre.ebooks.oeb.transforms.flatcss import KeyMapper + mapper = KeyMapper(sbase, dbase, fsizes) + msize = mapper[fsize] + self.input_mapped_font_size.setText('%.1f pt'%msize) + + def use_default(self): + dbase, fsizes = self.get_profile_values() + self.output_base_font_size.setValue(dbase) + self.font_size_key.setText(', '.join(['%.1f'%x for x in fsizes])) + + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + QApplication([]) + d = FontKeyChooser() + d.exec_() diff --git a/src/calibre/gui2/convert/font_key.ui b/src/calibre/gui2/convert/font_key.ui new file mode 100644 index 0000000000..13daeb360d --- /dev/null +++ b/src/calibre/gui2/convert/font_key.ui @@ -0,0 +1,226 @@ + + + Dialog + + + + 0 + 0 + 536 + 554 + + + + Font rescaling wizard + + + + :/images/wizard.svg:/images/wizard.svg + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + + + + + <p>This wizard will help you choose an appropriate font size key for your needs. Just enter the base font size of the input document and then enter an input font size. The wizard will display what font size it will be mapped to, by the font rescaling algorithm. You can adjust the algorithm by adjusting the output base font size and font key below. When you find values suitable for you, click OK.</p> +<p>By default, if the output base font size is zero and/or no font size key is specified, calibre will use the values from the current Output Profile. </p> +<p>See the <a href="http://calibre.kovidgoyal.net/user_manual/conversion.html#font-size-rescaling">User Manual</a> for a discussion of how font size rescaling works.</p> + + + true + + + true + + + + + + + &Output document + + + + + + &Base font size: + + + output_base_font_size + + + + + + + Font size &key: + + + font_size_key + + + + + + + + + + pt + + + 1 + + + + + + + Use &default values + + + + + + + + + + &Input document + + + + + + &Base font size: + + + input_base_font_size + + + + + + + pt + + + 1 + + + + + + + + + &Font size: + + + input_font_size + + + + + + + + 1 + 0 + + + + + 130 + 16777215 + + + + pt + + + 1 + + + + + + + will map to size: + + + + + + + 0.0 pt + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/calibre/gui2/convert/look_and_feel.py b/src/calibre/gui2/convert/look_and_feel.py index cbb24d9964..a10a410b67 100644 --- a/src/calibre/gui2/convert/look_and_feel.py +++ b/src/calibre/gui2/convert/look_and_feel.py @@ -6,6 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from PyQt4.Qt import SIGNAL from calibre.gui2.convert.look_and_feel_ui import Ui_Form from calibre.gui2.convert import Widget @@ -29,4 +30,16 @@ class LookAndFeelWidget(Widget, Ui_Form): self.initialize_options(get_option, get_help, db, book_id) self.opt_disable_font_rescaling.toggle() self.opt_disable_font_rescaling.toggle() + self.connect(self.button_font_key, SIGNAL('clicked()'), + self.font_key_wizard) + + def font_key_wizard(self): + from calibre.gui2.convert.font_key import FontKeyChooser + d = FontKeyChooser(self, self.opt_base_font_size.value(), + unicode(self.opt_font_size_mapping.text()).strip()) + if d.exec_() == d.Accepted: + self.opt_font_size_mapping.setText(', '.join(['%.1f'%x for x in + d.fsizes])) + self.opt_base_font_size.setValue(d.dbase) + diff --git a/src/calibre/gui2/convert/look_and_feel.ui b/src/calibre/gui2/convert/look_and_feel.ui index de0001bb3e..afa29bdd11 100644 --- a/src/calibre/gui2/convert/look_and_feel.ui +++ b/src/calibre/gui2/convert/look_and_feel.ui @@ -13,132 +13,150 @@ Form - - - - - + + + + + &Disable font size rescaling + + + + + + + Base &font size: + + + opt_base_font_size + + + + + + + pt + + + 1 + + + 0.000000000000000 + + + 30.000000000000000 + + + 1.000000000000000 + + + 15.000000000000000 + + + + + + + Font size &key: + + + opt_font_size_mapping + + + + + + + + + + 0 + 0 + + + + + + + + Wizard to help you choose an appropriate font size key + - Base &font size: + ... - - opt_base_font_size - - - - - - - pt - - - 1 - - - 0.000000000000000 - - - 30.000000000000000 - - - 1.000000000000000 - - - 15.000000000000000 - - - - - - - Line &height: - - - opt_line_height - - - - - - - pt - - - 1 - - - - - - - Remove &spacing between paragraphs - - - - - - - No text &justification - - - - - - - &Linearize tables - - - - - - - &Transliterate unicode characters to ASCII. - - - - - - - Font size &key: - - - opt_font_size_mapping - - - - - - - - - - Input character &encoding - - - opt_input_encoding - - - - - - - - - - &Disable font size rescaling - - - - - - - Insert &blank line + + + :/images/wizard.svg:/images/wizard.svg - + + + + Line &height: + + + opt_line_height + + + + + + + pt + + + 1 + + + + + + + Input character &encoding: + + + opt_input_encoding + + + + + + + Remove &spacing between paragraphs + + + + + + + Insert &blank line + + + + + + + No text &justification + + + + + + + &Linearize tables + + + + + + + &Transliterate unicode characters to ASCII. + + + + Extra &CSS @@ -150,6 +168,9 @@ + + +