mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Add support for embedding fonts to the GUI
This commit is contained in:
parent
f982a7ce7e
commit
cb09be5d4a
@ -22,6 +22,7 @@ from libprs500.gui2.dialogs.lrf_single_ui import Ui_LRFSingleDialog
|
||||
from libprs500.gui2.dialogs.choose_format import ChooseFormatDialog
|
||||
from libprs500.gui2 import qstring_to_unicode, error_dialog, \
|
||||
pixmap_to_data, choose_images
|
||||
from libprs500.gui2.widgets import FontFamilyModel
|
||||
from libprs500.ebooks.lrf import option_parser
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
from libprs500 import __appname__
|
||||
@ -64,6 +65,11 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
self.cover_changed = False
|
||||
self.cpixmap = None
|
||||
self.changed = False
|
||||
self.font_family_model = FontFamilyModel()
|
||||
self.gui_serif_family.setModel(self.font_family_model)
|
||||
self.gui_sans_family.setModel(self.font_family_model)
|
||||
self.gui_mono_family.setModel(self.font_family_model)
|
||||
|
||||
self.read_saved_options()
|
||||
self.initialize_metadata()
|
||||
formats = self.db.formats(self.row)
|
||||
@ -118,6 +124,15 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
self.preprocess.setCurrentIndex(self.preprocess.findText(ops[2:]))
|
||||
break
|
||||
|
||||
for opt in ('--serif-family', '--sans-family', '--mono-family'):
|
||||
if opt in cmdline:
|
||||
print 'in'
|
||||
family = cmdline[cmdline.index(opt)+1].split(',')[1].strip()
|
||||
obj = getattr(self, 'gui_'+opt[2:].replace('-', '_'))
|
||||
try:
|
||||
obj.setCurrentIndex(self.font_family_model.index_of(family))
|
||||
except:
|
||||
continue
|
||||
|
||||
def select_cover(self, checked):
|
||||
files = choose_images(self, 'change cover dialog',
|
||||
@ -284,6 +299,17 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
if text != 'No preprocessing':
|
||||
cmd.append(u'--'+text)
|
||||
cmd.extend([u'--profile', qstring_to_unicode(self.gui_profile.currentText())])
|
||||
|
||||
for opt in ('--serif-family', '--sans-family', '--mono-family'):
|
||||
obj = getattr(self, 'gui_'+opt[2:].replace('-', '_'))
|
||||
family = qstring_to_unicode(obj.itemText(obj.currentIndex())).strip()
|
||||
try:
|
||||
path = self.font_family_model.path_of(family)
|
||||
except KeyError:
|
||||
continue
|
||||
if path:
|
||||
cmd.extend([opt, os.path.dirname(path)+', '+family])
|
||||
|
||||
return cmd
|
||||
|
||||
def title(self):
|
||||
@ -319,6 +345,7 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
|
||||
self.cover_file.write(cover)
|
||||
self.cover_file.close()
|
||||
self.db.set_conversion_options(self.id, self.output_format.lower(), cmdline)
|
||||
|
||||
if self.cover_file:
|
||||
cmdline.extend([u'--cover', self.cover_file.name])
|
||||
self.cmdline = [unicode(i) for i in cmdline]
|
||||
|
@ -146,7 +146,7 @@
|
||||
<item row="0" column="0" >
|
||||
<widget class="QStackedWidget" name="stack" >
|
||||
<property name="currentIndex" >
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="metadata_page" >
|
||||
<layout class="QHBoxLayout" >
|
||||
@ -469,7 +469,7 @@
|
||||
</widget>
|
||||
<widget class="QWidget" name="lookandfeel_page" >
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" colspan="3" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label_8" >
|
||||
<property name="text" >
|
||||
<string>Base &font size:</string>
|
||||
@ -479,7 +479,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" >
|
||||
<item row="0" column="1" colspan="2" >
|
||||
<widget class="QDoubleSpinBox" name="gui_base_font_size" >
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
@ -504,7 +504,62 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3" >
|
||||
<item rowspan="5" row="0" column="4" >
|
||||
<widget class="QGroupBox" name="groupBox_8" >
|
||||
<property name="title" >
|
||||
<string>Embedded Fonts</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" colspan="2" >
|
||||
<widget class="QLabel" name="label_22" >
|
||||
<property name="text" >
|
||||
<string>&Serif:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>gui_serif_family</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" >
|
||||
<widget class="QComboBox" name="gui_serif_family" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_23" >
|
||||
<property name="text" >
|
||||
<string>S&ans-serif:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>gui_sans_family</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2" >
|
||||
<widget class="QComboBox" name="gui_sans_family" />
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QLabel" name="label_24" >
|
||||
<property name="text" >
|
||||
<string>&Monospace:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>gui_mono_family</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2" >
|
||||
<widget class="QComboBox" name="gui_mono_family" />
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_9" >
|
||||
<property name="text" >
|
||||
<string>&Word spacing:</string>
|
||||
@ -517,7 +572,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2" >
|
||||
<item row="1" column="1" colspan="2" >
|
||||
<widget class="QDoubleSpinBox" name="gui_wordspace" >
|
||||
<property name="buttonSymbols" >
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
@ -542,7 +597,28 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<item row="2" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="gui_autorotation" >
|
||||
<property name="text" >
|
||||
<string>Enable auto &rotation of images</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="gui_blank_after_para" >
|
||||
<property name="text" >
|
||||
<string>Insert &blank lines between paragraphs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="gui_ignore_tables" >
|
||||
<property name="text" >
|
||||
<string>Ignore &tables</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2" >
|
||||
<widget class="QLabel" name="label_16" >
|
||||
<property name="text" >
|
||||
<string>&Preprocess:</string>
|
||||
@ -552,10 +628,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2" >
|
||||
<item row="5" column="3" colspan="3" >
|
||||
<widget class="QComboBox" name="preprocess" />
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4" >
|
||||
<item row="6" column="0" colspan="6" >
|
||||
<widget class="QGroupBox" name="groupBox_5" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
|
||||
@ -590,35 +666,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="3" >
|
||||
<widget class="QCheckBox" name="gui_autorotation" >
|
||||
<property name="text" >
|
||||
<string>Enable auto &rotation of images</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="3" >
|
||||
<widget class="QCheckBox" name="gui_blank_after_para" >
|
||||
<property name="text" >
|
||||
<string>Insert &blank lines between paragraphs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="3" >
|
||||
<widget class="QCheckBox" name="gui_ignore_tables" >
|
||||
<property name="text" >
|
||||
<string>Ignore &tables</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" >
|
||||
<item row="7" column="0" colspan="2" >
|
||||
<widget class="QLabel" name="label_21" >
|
||||
<property name="text" >
|
||||
<string>Override<br>CSS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" >
|
||||
<item row="7" column="2" colspan="4" >
|
||||
<widget class="QTextEdit" name="gui_override_css" />
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -19,7 +19,7 @@ from PyQt4.QtGui import QListView, QIcon, QFont, QLabel
|
||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject
|
||||
|
||||
from libprs500.gui2 import human_readable, NONE, TableView
|
||||
from libprs500 import fit_image
|
||||
from libprs500 import fit_image, get_font_families
|
||||
|
||||
class ImageView(QLabel):
|
||||
|
||||
@ -99,4 +99,38 @@ class LocationView(QListView):
|
||||
class JobsView(TableView):
|
||||
pass
|
||||
|
||||
class FontFamilyModel(QAbstractListModel):
|
||||
|
||||
def __init__(self, *args):
|
||||
QAbstractListModel.__init__(self, *args)
|
||||
self.family_map = get_font_families()
|
||||
self.families = self.family_map.keys()
|
||||
self.families.sort()
|
||||
self.families[:0] = ['None']
|
||||
|
||||
def rowCount(self, *args):
|
||||
return len(self.families)
|
||||
|
||||
def data(self, index, role):
|
||||
try:
|
||||
family = self.families[index.row()]
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return NONE
|
||||
if role == Qt.DisplayRole:
|
||||
return QVariant(family)
|
||||
if role == Qt.FontRole:
|
||||
return QVariant(QFont(family))
|
||||
return NONE
|
||||
|
||||
def path_of(self, family):
|
||||
if family != None:
|
||||
return self.family_map[family]
|
||||
return None
|
||||
|
||||
def index_of(self, family):
|
||||
return self.families.index(family.strip())
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user