mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-04 03:27:00 -05: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.dialogs.choose_format import ChooseFormatDialog
 | 
				
			||||||
from libprs500.gui2 import qstring_to_unicode, error_dialog, \
 | 
					from libprs500.gui2 import qstring_to_unicode, error_dialog, \
 | 
				
			||||||
                           pixmap_to_data, choose_images
 | 
					                           pixmap_to_data, choose_images
 | 
				
			||||||
 | 
					from libprs500.gui2.widgets import FontFamilyModel
 | 
				
			||||||
from libprs500.ebooks.lrf import option_parser
 | 
					from libprs500.ebooks.lrf import option_parser
 | 
				
			||||||
from libprs500.ptempfile import PersistentTemporaryFile
 | 
					from libprs500.ptempfile import PersistentTemporaryFile
 | 
				
			||||||
from libprs500 import __appname__
 | 
					from libprs500 import __appname__
 | 
				
			||||||
@ -64,6 +65,11 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
 | 
				
			|||||||
        self.cover_changed = False
 | 
					        self.cover_changed = False
 | 
				
			||||||
        self.cpixmap = None
 | 
					        self.cpixmap = None
 | 
				
			||||||
        self.changed = False
 | 
					        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.read_saved_options()
 | 
				
			||||||
        self.initialize_metadata()
 | 
					        self.initialize_metadata()
 | 
				
			||||||
        formats = self.db.formats(self.row)
 | 
					        formats = self.db.formats(self.row)
 | 
				
			||||||
@ -118,6 +124,15 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
 | 
				
			|||||||
                    self.preprocess.setCurrentIndex(self.preprocess.findText(ops[2:]))
 | 
					                    self.preprocess.setCurrentIndex(self.preprocess.findText(ops[2:]))
 | 
				
			||||||
                    break
 | 
					                    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):
 | 
					    def select_cover(self, checked):
 | 
				
			||||||
        files = choose_images(self, 'change cover dialog', 
 | 
					        files = choose_images(self, 'change cover dialog', 
 | 
				
			||||||
@ -284,6 +299,17 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
 | 
				
			|||||||
        if text != 'No preprocessing':
 | 
					        if text != 'No preprocessing':
 | 
				
			||||||
            cmd.append(u'--'+text)
 | 
					            cmd.append(u'--'+text)
 | 
				
			||||||
        cmd.extend([u'--profile',  qstring_to_unicode(self.gui_profile.currentText())])
 | 
					        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        
 | 
					        return cmd        
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def title(self):
 | 
					    def title(self):
 | 
				
			||||||
@ -319,6 +345,7 @@ class LRFSingleDialog(QDialog, Ui_LRFSingleDialog):
 | 
				
			|||||||
            self.cover_file.write(cover)
 | 
					            self.cover_file.write(cover)
 | 
				
			||||||
            self.cover_file.close()
 | 
					            self.cover_file.close()
 | 
				
			||||||
        self.db.set_conversion_options(self.id, self.output_format.lower(), cmdline)
 | 
					        self.db.set_conversion_options(self.id, self.output_format.lower(), cmdline)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        if self.cover_file:
 | 
					        if self.cover_file:
 | 
				
			||||||
            cmdline.extend([u'--cover', self.cover_file.name])
 | 
					            cmdline.extend([u'--cover', self.cover_file.name])
 | 
				
			||||||
        self.cmdline = [unicode(i) for i in cmdline]
 | 
					        self.cmdline = [unicode(i) for i in cmdline]
 | 
				
			||||||
 | 
				
			|||||||
@ -146,7 +146,7 @@
 | 
				
			|||||||
          <item row="0" column="0" >
 | 
					          <item row="0" column="0" >
 | 
				
			||||||
           <widget class="QStackedWidget" name="stack" >
 | 
					           <widget class="QStackedWidget" name="stack" >
 | 
				
			||||||
            <property name="currentIndex" >
 | 
					            <property name="currentIndex" >
 | 
				
			||||||
             <number>0</number>
 | 
					             <number>1</number>
 | 
				
			||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
            <widget class="QWidget" name="metadata_page" >
 | 
					            <widget class="QWidget" name="metadata_page" >
 | 
				
			||||||
             <layout class="QHBoxLayout" >
 | 
					             <layout class="QHBoxLayout" >
 | 
				
			||||||
@ -469,7 +469,7 @@
 | 
				
			|||||||
            </widget>
 | 
					            </widget>
 | 
				
			||||||
            <widget class="QWidget" name="lookandfeel_page" >
 | 
					            <widget class="QWidget" name="lookandfeel_page" >
 | 
				
			||||||
             <layout class="QGridLayout" >
 | 
					             <layout class="QGridLayout" >
 | 
				
			||||||
              <item row="0" column="0" colspan="3" >
 | 
					              <item row="0" column="0" >
 | 
				
			||||||
               <widget class="QLabel" name="label_8" >
 | 
					               <widget class="QLabel" name="label_8" >
 | 
				
			||||||
                <property name="text" >
 | 
					                <property name="text" >
 | 
				
			||||||
                 <string>Base &font size:</string>
 | 
					                 <string>Base &font size:</string>
 | 
				
			||||||
@ -479,7 +479,7 @@
 | 
				
			|||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="0" column="2" >
 | 
					              <item row="0" column="1" colspan="2" >
 | 
				
			||||||
               <widget class="QDoubleSpinBox" name="gui_base_font_size" >
 | 
					               <widget class="QDoubleSpinBox" name="gui_base_font_size" >
 | 
				
			||||||
                <property name="buttonSymbols" >
 | 
					                <property name="buttonSymbols" >
 | 
				
			||||||
                 <enum>QAbstractSpinBox::PlusMinus</enum>
 | 
					                 <enum>QAbstractSpinBox::PlusMinus</enum>
 | 
				
			||||||
@ -504,7 +504,62 @@
 | 
				
			|||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </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" >
 | 
					               <widget class="QLabel" name="label_9" >
 | 
				
			||||||
                <property name="text" >
 | 
					                <property name="text" >
 | 
				
			||||||
                 <string>&Word spacing:</string>
 | 
					                 <string>&Word spacing:</string>
 | 
				
			||||||
@ -517,7 +572,7 @@
 | 
				
			|||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="1" column="2" >
 | 
					              <item row="1" column="1" colspan="2" >
 | 
				
			||||||
               <widget class="QDoubleSpinBox" name="gui_wordspace" >
 | 
					               <widget class="QDoubleSpinBox" name="gui_wordspace" >
 | 
				
			||||||
                <property name="buttonSymbols" >
 | 
					                <property name="buttonSymbols" >
 | 
				
			||||||
                 <enum>QAbstractSpinBox::PlusMinus</enum>
 | 
					                 <enum>QAbstractSpinBox::PlusMinus</enum>
 | 
				
			||||||
@ -542,7 +597,28 @@
 | 
				
			|||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </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" >
 | 
					               <widget class="QLabel" name="label_16" >
 | 
				
			||||||
                <property name="text" >
 | 
					                <property name="text" >
 | 
				
			||||||
                 <string>&Preprocess:</string>
 | 
					                 <string>&Preprocess:</string>
 | 
				
			||||||
@ -552,10 +628,10 @@
 | 
				
			|||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="2" column="1" colspan="2" >
 | 
					              <item row="5" column="3" colspan="3" >
 | 
				
			||||||
               <widget class="QComboBox" name="preprocess" />
 | 
					               <widget class="QComboBox" name="preprocess" />
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="3" column="0" colspan="4" >
 | 
					              <item row="6" column="0" colspan="6" >
 | 
				
			||||||
               <widget class="QGroupBox" name="groupBox_5" >
 | 
					               <widget class="QGroupBox" name="groupBox_5" >
 | 
				
			||||||
                <property name="sizePolicy" >
 | 
					                <property name="sizePolicy" >
 | 
				
			||||||
                 <sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
 | 
					                 <sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
 | 
				
			||||||
@ -590,35 +666,14 @@
 | 
				
			|||||||
                </layout>
 | 
					                </layout>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="4" column="0" colspan="3" >
 | 
					              <item row="7" column="0" colspan="2" >
 | 
				
			||||||
               <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" >
 | 
					 | 
				
			||||||
               <widget class="QLabel" name="label_21" >
 | 
					               <widget class="QLabel" name="label_21" >
 | 
				
			||||||
                <property name="text" >
 | 
					                <property name="text" >
 | 
				
			||||||
                 <string>Override<br>CSS</string>
 | 
					                 <string>Override<br>CSS</string>
 | 
				
			||||||
                </property>
 | 
					                </property>
 | 
				
			||||||
               </widget>
 | 
					               </widget>
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
              <item row="7" column="1" >
 | 
					              <item row="7" column="2" colspan="4" >
 | 
				
			||||||
               <widget class="QTextEdit" name="gui_override_css" />
 | 
					               <widget class="QTextEdit" name="gui_override_css" />
 | 
				
			||||||
              </item>
 | 
					              </item>
 | 
				
			||||||
             </layout>
 | 
					             </layout>
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,7 @@ from PyQt4.QtGui import QListView, QIcon, QFont, QLabel
 | 
				
			|||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject
 | 
					from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from libprs500.gui2 import human_readable, NONE, TableView
 | 
					from libprs500.gui2 import human_readable, NONE, TableView
 | 
				
			||||||
from libprs500 import fit_image
 | 
					from libprs500 import fit_image, get_font_families
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ImageView(QLabel):
 | 
					class ImageView(QLabel):
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -99,4 +99,38 @@ class LocationView(QListView):
 | 
				
			|||||||
class JobsView(TableView):
 | 
					class JobsView(TableView):
 | 
				
			||||||
    pass
 | 
					    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