mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add a wizard to make customizing the font rescaling algorithm easier
This commit is contained in:
parent
dc9aa69508
commit
d70d42f900
104
src/calibre/gui2/convert/font_key.py
Normal file
104
src/calibre/gui2/convert/font_key.py
Normal file
@ -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 <kovid@kovidgoyal.net>'
|
||||
__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_()
|
226
src/calibre/gui2/convert/font_key.ui
Normal file
226
src/calibre/gui2/convert/font_key.ui
Normal file
@ -0,0 +1,226 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>536</width>
|
||||
<height>554</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Font rescaling wizard</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/wizard.svg</normaloff>:/images/wizard.svg</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="1" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>&Output document</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>&Base font size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>output_base_font_size</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Font size &key:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>font_size_key</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="font_size_key"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QDoubleSpinBox" name="output_base_font_size">
|
||||
<property name="suffix">
|
||||
<string> pt</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QPushButton" name="button_use_default">
|
||||
<property name="text">
|
||||
<string>Use &default values</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>&Input document</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>&Base font size:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>input_base_font_size</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="input_base_font_size">
|
||||
<property name="suffix">
|
||||
<string> pt</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>&Font size: </string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>input_font_size</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="input_font_size">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string> pt</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string> will map to size: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="input_mapped_font_size">
|
||||
<property name="text">
|
||||
<string>0.0 pt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../../resources/images.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -6,6 +6,7 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__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)
|
||||
|
||||
|
||||
|
@ -13,10 +13,15 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_disable_font_rescaling">
|
||||
<property name="text">
|
||||
<string>&Disable font size rescaling</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_18">
|
||||
<property name="text">
|
||||
<string>Base &font size:</string>
|
||||
@ -26,7 +31,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="1" column="3">
|
||||
<widget class="QDoubleSpinBox" name="opt_base_font_size">
|
||||
<property name="suffix">
|
||||
<string> pt</string>
|
||||
@ -48,7 +53,45 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Font size &key:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_font_size_mapping</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="opt_font_size_mapping">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="button_font_key">
|
||||
<property name="toolTip">
|
||||
<string>Wizard to help you choose an appropriate font size key</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/wizard.svg</normaloff>:/images/wizard.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Line &height:</string>
|
||||
@ -58,7 +101,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<item row="3" column="3">
|
||||
<widget class="QDoubleSpinBox" name="opt_line_height">
|
||||
<property name="suffix">
|
||||
<string> pt</string>
|
||||
@ -68,6 +111,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Input character &encoding:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_input_encoding</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="opt_remove_paragraph_spacing">
|
||||
<property name="text">
|
||||
@ -75,14 +128,21 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="3">
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="opt_insert_blank_line">
|
||||
<property name="text">
|
||||
<string>Insert &blank line</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="opt_dont_justify">
|
||||
<property name="text">
|
||||
<string>No text &justification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="3">
|
||||
<item row="8" column="0">
|
||||
<widget class="QCheckBox" name="opt_linearize_tables">
|
||||
<property name="text">
|
||||
<string>&Linearize tables</string>
|
||||
@ -96,49 +156,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Font size &key:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_font_size_mapping</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="opt_font_size_mapping"/>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Input character &encoding</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_input_encoding</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLineEdit" name="opt_input_encoding"/>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="opt_disable_font_rescaling">
|
||||
<property name="text">
|
||||
<string>&Disable font size rescaling</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="opt_insert_blank_line">
|
||||
<property name="text">
|
||||
<string>Insert &blank line</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<item row="10" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Extra &CSS</string>
|
||||
@ -150,6 +168,9 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" colspan="2">
|
||||
<widget class="QLineEdit" name="opt_input_encoding"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user