Пример #1
0
def load_builtin_fonts():
    import glob
    from PyQt4.Qt import QFontDatabase
    base = P('fonts/liberation/*.ttf')
    for f in glob.glob(base):
        QFontDatabase.addApplicationFont(f)
    return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'
Пример #2
0
def writing_system_for_font(font):
    has_latin = True
    systems = QFontDatabase().writingSystems(font.family())

    # this just confuses the algorithm below. Vietnamese is Latin with lots of
    # special chars
    try:
        systems.remove(QFontDatabase.Vietnamese)
    except ValueError:
        pass

    system = QFontDatabase.Any

    if QFontDatabase.Latin not in systems:
        has_latin = False
        # we need to show something
        if systems:
            system = systems[-1]
    else:
        systems.remove(QFontDatabase.Latin)

    if not systems:
        return system, has_latin

    if len(systems) == 1 and systems[0] > QFontDatabase.Cyrillic:
        return systems[0], has_latin

    if len(systems) <= 2 and systems[-1] > QFontDatabase.Armenian and systems[-1] < QFontDatabase.Vietnamese:
        return systems[-1], has_latin

    if len(systems) <= 5 and systems[-1] >= QFontDatabase.SimplifiedChinese and systems[-1] <= QFontDatabase.Korean:
        system = systems[-1]

    return system, has_latin
Пример #3
0
 def read_font_fule(self, basedir, css):
     from PyQt4.Qt import QFontDatabase
     import cssutils
     cssutils.log.setLevel(logging.ERROR)
     try:
         sheet = cssutils.parseString(css, validate=False)
     except:
         return
     for rule in sheet.cssRules:
         try:
             s = rule.style
             src = s.getProperty('src').propertyValue[0].uri
             font_family = s.getProperty('font-family').propertyValue[0].value
         except:
             continue
         if not src or not font_family:
             continue
         font_file = os.path.normcase(os.path.abspath(os.path.join(basedir,
             src)))
         if font_file not in self.added_fonts:
             self.added_fonts.add(font_file)
             if os.path.exists(font_file):
                 with open(font_file, 'rb') as f:
                     idx = QFontDatabase.addApplicationFontFromData(f.read())
                 if idx > -1:
                     family = map(unicode,
                         QFontDatabase.applicationFontFamilies(idx)).next()
                     self.log('Extracted embedded font:', family, 'from',
                             os.path.basename(font_file))
                     if (family and family != font_family and
                             family not in self.replace_map):
                         self.log('Replacing font family value:',
                                 font_family, 'with', family)
                         self.replace_map[font_family.encode('utf-8')] = \
                                 family.encode('utf-8')
Пример #4
0
 def add_font(self, data):
     existing = None
     for font_id, entry in self.cache.iteritems():
         if entry.size == len(data) and entry.hash == hash(data):
             existing = entry
             break
     if existing is None:
         font_id = QFontDatabase.addApplicationFontFromData(data)
         if font_id > -1:
             families = frozenset(map(lambda x:icu_lower(unicode(x)), QFontDatabase.applicationFontFamilies(font_id)))
             self.cache[font_id] = self.entry(len(data), hash(data), families)
Пример #5
0
 def add_font(self, data):
     existing = None
     for font_id, entry in self.cache.iteritems():
         if entry.size == len(data) and entry.hash == hash(data):
             existing = entry
             break
     if existing is None:
         font_id = QFontDatabase.addApplicationFontFromData(data)
         if font_id > -1:
             families = frozenset(map(lambda x:icu_lower(unicode(x)), QFontDatabase.applicationFontFamilies(font_id)))
             self.cache[font_id] = self.entry(len(data), hash(data), families)
Пример #6
0
def rating_font():
    global _rating_font
    if _rating_font is None:
        from PyQt4.Qt import QFontDatabase
        _rating_font = 'Arial Unicode MS' if iswindows else 'sans-serif'
        fontid = QFontDatabase.addApplicationFont(
            #P('fonts/liberation/LiberationSerif-Regular.ttf')
            P('fonts/calibreSymbols.otf'))
        if fontid > -1:
            try:
                _rating_font = unicode(
                    list(QFontDatabase.applicationFontFamilies(fontid))[0])
            except:
                pass
    return _rating_font
Пример #7
0
def rating_font():
    global _rating_font
    if _rating_font is None:
        from PyQt4.Qt import QFontDatabase
        _rating_font = 'Arial Unicode MS' if iswindows else 'sans-serif'
        fontid = QFontDatabase.addApplicationFont(
                #P('fonts/liberation/LiberationSerif-Regular.ttf')
                P('fonts/calibreSymbols.otf')
                )
        if fontid > -1:
            try:
                _rating_font = unicode(list(
                    QFontDatabase.applicationFontFamilies(fontid))[0])
            except:
                pass
    return _rating_font
Пример #8
0
def load_builtin_fonts():
    global _rating_font
    # Load the builtin fonts and any fonts added to calibre by the user to
    # Qt
    for ff in glob.glob(P('fonts/liberation/*.?tf')) + \
            [P('fonts/calibreSymbols.otf')] + \
            glob.glob(os.path.join(config_dir, 'fonts', '*.?tf')):
        if ff.rpartition('.')[-1].lower() in {'ttf', 'otf'}:
            with open(ff, 'rb') as s:
                # Windows requires font files to be executable for them to be
                # loaded successfully, so we use the in memory loader
                fid = QFontDatabase.addApplicationFontFromData(s.read())
                if fid > -1:
                    fam = QFontDatabase.applicationFontFamilies(fid)
                    fam = set(map(unicode, fam))
                    if u'calibre Symbols' in fam:
                        _rating_font = u'calibre Symbols'
Пример #9
0
def load_builtin_fonts():
    global _rating_font
    # Load the builtin fonts and any fonts added to calibre by the user to
    # Qt
    for ff in glob.glob(P('fonts/liberation/*.?tf')) + \
            [P('fonts/calibreSymbols.otf')] + \
            glob.glob(os.path.join(config_dir, 'fonts', '*.?tf')):
        if ff.rpartition('.')[-1].lower() in {'ttf', 'otf'}:
            with open(ff, 'rb') as s:
                # Windows requires font files to be executable for them to be
                # loaded successfully, so we use the in memory loader
                fid = QFontDatabase.addApplicationFontFromData(s.read())
                if fid > -1:
                    fam = QFontDatabase.applicationFontFamilies(fid)
                    fam = set(map(unicode, fam))
                    if u'calibre Symbols' in fam:
                        _rating_font = u'calibre Symbols'
Пример #10
0
def load_builtin_fonts():
    global _rating_font
    # Load the builtin fonts and any fonts added to calibre by the user to
    # Qt
    for ff in (
        glob.glob(P("fonts/liberation/*.?tf"))
        + [P("fonts/calibreSymbols.otf")]
        + glob.glob(os.path.join(config_dir, "fonts", "*.?tf"))
    ):
        if ff.rpartition(".")[-1].lower() in {"ttf", "otf"}:
            with open(ff, "rb") as s:
                # Windows requires font files to be executable for them to be
                # loaded successfully, so we use the in memory loader
                fid = QFontDatabase.addApplicationFontFromData(s.read())
                if fid > -1:
                    fam = QFontDatabase.applicationFontFamilies(fid)
                    fam = set(map(unicode, fam))
                    if u"calibre Symbols" in fam:
                        _rating_font = u"calibre Symbols"
Пример #11
0
def default_font_family():
    global _dff
    if _dff is None:
        families = set(map(unicode, QFontDatabase().families()))
        for x in ('Ubuntu Mono', 'Consolas', 'Liberation Mono'):
            if x in families:
                _dff = x
                break
        if _dff is None:
            _dff = 'Courier New'
    return _dff
Пример #12
0
 def read_font_fule(self, basedir, css):
     from PyQt4.Qt import QFontDatabase
     import cssutils
     cssutils.log.setLevel(logging.ERROR)
     try:
         sheet = cssutils.parseString(css, validate=False)
     except:
         return
     for rule in sheet.cssRules:
         try:
             s = rule.style
             src = s.getProperty('src').propertyValue[0].uri
             font_family = s.getProperty(
                 'font-family').propertyValue[0].value
         except:
             continue
         if not src or not font_family:
             continue
         font_file = os.path.normcase(
             os.path.abspath(os.path.join(basedir, src)))
         if font_file not in self.added_fonts:
             self.added_fonts.add(font_file)
             if os.path.exists(font_file):
                 with open(font_file, 'rb') as f:
                     idx = QFontDatabase.addApplicationFontFromData(
                         f.read())
                 if idx > -1:
                     family = map(
                         unicode,
                         QFontDatabase.applicationFontFamilies(idx)).next()
                     self.log('Extracted embedded font:', family, 'from',
                              os.path.basename(font_file))
                     if (family and family != font_family
                             and family not in self.replace_map):
                         self.log('Replacing font family value:',
                                  font_family, 'with', family)
                         self.replace_map[font_family.encode('utf-8')] = \
                                 family.encode('utf-8')
Пример #13
0
def initialiseFonts():
    fonts = [("NotCourierSans", "ncs.otf"), ('Inconsolata', 'inconsolata.otf'),
             ('BPmono', 'bpmono.ttf'), ('Liberation Mono', 'liberation.otf'),
             ('Oxygen Mono', 'oxygen.otf'), ('Open Sans', 'opensans.ttf'),
             ('Montserrat', 'montserrat.ttf'), ('Noto Sans', 'notosans.ttf'),
             ('PT Sans', 'ptsans.ttf'), ('Raleway', 'roboto.ttf'),
             ('Roboto', 'raleway.ttf')]
    for fontName, fontFile in fonts:
        if QFontDatabase.addApplicationFont(":/fonts/" + fontFile) == -1:
            print fontName
        else:
            font = QFont(fontName)
            Data.FontOptions.FontOptions.addFont(fontName, font)
            Data.FontOptions.FontOptions.addFont(fontName, font)
Пример #14
0
 def __init__(self, *args):
     QAbstractListModel.__init__(self, *args)
     from calibre.utils.fonts import fontconfig
     try:
         self.families = fontconfig.find_font_families()
     except:
         self.families = []
         print 'WARNING: Could not load fonts'
         traceback.print_exc()
     # Restrict to Qt families as Qt tends to crash
     qt_families = set([unicode(x) for x in QFontDatabase().families()])
     self.families = list(qt_families.intersection(set(self.families)))
     self.families.sort()
     self.families[:0] = [_('None')]
     self.font = QFont('Verdana' if iswindows else 'sansserif')
Пример #15
0
def initialiseFonts():
    fonts = [("NotCourierSans", "ncs.otf"),
             ('Inconsolata', 'inconsolata.otf'),
             ('BPmono', 'bpmono.ttf'),
             ('Liberation Mono', 'liberation.otf'),
             ('Oxygen Mono', 'oxygen.otf'),
             ('Open Sans', 'opensans.ttf'),
             ('Montserrat', 'montserrat.ttf'),
             ('Noto Sans', 'notosans.ttf'),
             ('PT Sans', 'ptsans.ttf'),
             ('Raleway', 'roboto.ttf'),
             ('Roboto', 'raleway.ttf')]
    for fontName, fontFile in fonts:
        if QFontDatabase.addApplicationFont(":/fonts/" + fontFile) == -1:
            print fontName
        else:
            font = QFont(fontName)
            Data.FontOptions.FontOptions.addFont(fontName, font)
            Data.FontOptions.FontOptions.addFont(fontName, font)
Пример #16
0
    def do_paint(self, painter, option, index):
        text = unicode(index.data(Qt.DisplayRole).toString())
        font = QFont(option.font)
        font.setPointSize(QFontInfo(font).pointSize() * 1.5)
        font2 = QFont(font)
        font2.setFamily(text)

        system, has_latin = writing_system_for_font(font2)
        if has_latin:
            font = font2

        r = option.rect

        if option.state & QStyle.State_Selected:
            painter.setPen(QPen(option.palette.highlightedText(), 0))

        if (option.direction == Qt.RightToLeft):
            r.setRight(r.right() - 4)
        else:
            r.setLeft(r.left() + 4)

        painter.setFont(font)
        painter.drawText(r,
                         Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine,
                         text)

        if (system != QFontDatabase.Any):
            w = painter.fontMetrics().width(text + "  ")
            painter.setFont(font2)
            sample = QFontDatabase().writingSystemSample(system)
            if (option.direction == Qt.RightToLeft):
                r.setRight(r.right() - w)
            else:
                r.setLeft(r.left() + w)
            painter.drawText(
                r, Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine,
                sample)
Пример #17
0
def writing_system_for_font(font):
    has_latin = True
    systems = QFontDatabase().writingSystems(font.family())

    # this just confuses the algorithm below. Vietnamese is Latin with lots of
    # special chars
    try:
        systems.remove(QFontDatabase.Vietnamese)
    except ValueError:
        pass

    system = QFontDatabase.Any

    if (QFontDatabase.Latin not in systems):
        has_latin = False
        # we need to show something
        if systems:
            system = systems[-1]
    else:
        systems.remove(QFontDatabase.Latin)

    if not systems:
        return system, has_latin

    if (len(systems) == 1 and systems[0] > QFontDatabase.Cyrillic):
        return systems[0], has_latin

    if (len(systems) <= 2 and systems[-1] > QFontDatabase.Armenian
            and systems[-1] < QFontDatabase.Vietnamese):
        return systems[-1], has_latin

    if (len(systems) <= 5 and systems[-1] >= QFontDatabase.SimplifiedChinese
            and systems[-1] <= QFontDatabase.Korean):
        system = systems[-1]

    return system, has_latin
Пример #18
0
    def handle_embedded_fonts(self):
        '''
        Because of QtWebKit's inability to handle embedded fonts correctly, we
        remove the embedded fonts and make them available system wide instead.
        If you ever move to Qt WebKit 2.3+ then this will be unnecessary.
        '''
        from calibre.ebooks.oeb.base import urlnormalize
        from calibre.utils.fonts.utils import remove_embed_restriction
        from PyQt4.Qt import QFontDatabase, QByteArray, QRawFont, QFont

        # First find all @font-face rules and remove them, adding the embedded
        # fonts to Qt
        family_map = {}
        for item in list(self.oeb.manifest):
            if not hasattr(item.data, 'cssRules'): continue
            remove = set()
            for i, rule in enumerate(item.data.cssRules):
                if rule.type == rule.FONT_FACE_RULE:
                    remove.add(i)
                    try:
                        s = rule.style
                        src = s.getProperty('src').propertyValue[0].uri
                        font_family = s.getProperty('font-family').propertyValue[0].value
                    except:
                        continue
                    path = item.abshref(src)
                    ff = self.oeb.manifest.hrefs.get(urlnormalize(path), None)
                    if ff is None:
                        continue

                    raw = ff.data
                    self.oeb.manifest.remove(ff)
                    try:
                        raw = remove_embed_restriction(raw)
                    except:
                        continue
                    fid = QFontDatabase.addApplicationFontFromData(QByteArray(raw))
                    family_name = None
                    if fid > -1:
                        try:
                            family_name = unicode(QFontDatabase.applicationFontFamilies(fid)[0])
                        except (IndexError, KeyError):
                            pass
                    if family_name:
                        family_map[icu_lower(font_family)] = family_name

            for i in sorted(remove, reverse=True):
                item.data.cssRules.pop(i)

        # Now map the font family name specified in the css to the actual
        # family name of the embedded font (they may be different in general).
        font_warnings = set()
        for item in self.oeb.manifest:
            if not hasattr(item.data, 'cssRules'): continue
            for i, rule in enumerate(item.data.cssRules):
                if rule.type != rule.STYLE_RULE: continue
                ff = rule.style.getProperty('font-family')
                if ff is None: continue
                val = ff.propertyValue
                for i in xrange(val.length):
                    try:
                        k = icu_lower(val[i].value)
                    except (AttributeError, TypeError):
                        val[i].value = k = 'times'
                    if k in family_map:
                        val[i].value = family_map[k]
                if iswindows:
                    # On windows, Qt uses GDI which does not support OpenType
                    # (CFF) fonts, so we need to nuke references to OpenType
                    # fonts. Note that you could compile QT with configure
                    # -directwrite, but that requires atleast Vista SP2
                    for i in xrange(val.length):
                        family = val[i].value
                        if family:
                            f = QRawFont.fromFont(QFont(family))
                            if len(f.fontTable('head')) == 0:
                                if family not in font_warnings:
                                    self.log.warn('Ignoring unsupported font: %s'
                                                %family)
                                    font_warnings.add(family)
                                # Either a bitmap or (more likely) a CFF font
                                val[i].value = 'times'
Пример #19
0
 def setupUi(self, MainWindow):
     MainWindow.setObjectName(_fromUtf8("MainWindow"))
     MainWindow.resize(399, 653)
     palette = QtGui.QPalette()
     brush = QtGui.QBrush(QtGui.QColor(40, 175, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
     brush = QtGui.QBrush(QtGui.QColor(100, 100, 100))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(40, 175, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(80, 80, 80))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
     brush = QtGui.QBrush(QtGui.QColor(40, 175, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
     brush = QtGui.QBrush(QtGui.QColor(100, 100, 100))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(40, 175, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(80, 80, 80))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
     brush = QtGui.QBrush(QtGui.QColor(144, 141, 139))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
     brush = QtGui.QBrush(QtGui.QColor(100, 100, 100))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(150, 147, 145))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
     brush = QtGui.QBrush(QtGui.QColor(80, 80, 80))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(80, 80, 80))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
     MainWindow.setPalette(palette)
     self.centralwidget = QtGui.QWidget(MainWindow)
     self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
     self.groupBox = QtGui.QGroupBox(self.centralwidget)
     self.groupBox.setGeometry(QtCore.QRect(70, 60, 291, 381))
     self.groupBox.setObjectName(_fromUtf8("groupBox"))
     self.listFonts = QtGui.QListWidget(self.groupBox)
     self.listFonts.setGeometry(QtCore.QRect(20, 30, 251, 331))
     self.listFonts.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
     self.listFonts.setObjectName(_fromUtf8("listFonts"))
     self.label_2 = QtGui.QLabel(self.centralwidget)
     self.label_2.setGeometry(QtCore.QRect(10, 460, 91, 61))
     self.label_2.setObjectName(_fromUtf8("label_2"))
     self.lineTempFolder = QtGui.QLineEdit(self.centralwidget)
     self.lineTempFolder.setGeometry(QtCore.QRect(120, 480, 271, 21))
     self.lineTempFolder.setObjectName(_fromUtf8("lineTempFolder"))
     self.pushQuery = QtGui.QPushButton(self.centralwidget)
     self.pushQuery.setGeometry(QtCore.QRect(150, 570, 99, 41))
     font = QtGui.QFont()
     font.setBold(True)
     font.setWeight(75)
     self.pushQuery.setFont(font)
     self.pushQuery.setObjectName(_fromUtf8("pushQuery"))
     self.label = QtGui.QLabel(self.centralwidget)
     self.label.setGeometry(QtCore.QRect(20, 10, 91, 51))
     self.label.setObjectName(_fromUtf8("label"))
     self.labPaint = QtGui.QLabel(self.centralwidget)
     self.labPaint.setGeometry(QtCore.QRect(20, 20, 591, 471))
     palette = QtGui.QPalette()
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
     brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
     brush.setStyle(QtCore.Qt.SolidPattern)
     palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
     self.labPaint.setPalette(palette)
     font = QtGui.QFont()
     font.setPointSize(18)
     self.labPaint.setFont(font)
     self.labPaint.setAlignment(QtCore.Qt.AlignJustify|QtCore.Qt.AlignTop)
     self.labPaint.setMargin(55)
     self.labPaint.setObjectName(_fromUtf8("labPaint"))
     self.lineWordList = QtGui.QLineEdit(self.centralwidget)
     self.lineWordList.setGeometry(QtCore.QRect(90, 20, 271, 21))
     self.lineWordList.setObjectName(_fromUtf8("lineWordList"))
     self.label_3 = QtGui.QLabel(self.centralwidget)
     self.label_3.setGeometry(QtCore.QRect(10, 520, 91, 61))
     self.label_3.setObjectName(_fromUtf8("label_3"))
     self.lineFolder = QtGui.QLineEdit(self.centralwidget)
     self.lineFolder.setGeometry(QtCore.QRect(120, 540, 271, 21))
     self.lineFolder.setObjectName(_fromUtf8("lineFolder"))
     MainWindow.setCentralWidget(self.centralwidget)
     self.retranslateUi(MainWindow)
     QtCore.QMetaObject.connectSlotsByName(MainWindow)
     
     
     #my code
     self.labPaint.setVisible(False)
     self.lineWordList.setText('/home/phoenix/Desktop/handcraft/lexeis.txt')
     self.lineFolder.setText("/home/phoenix/Desktop/noscale/")
     self.lineTempFolder.setText('/tmp/')
     #get installed fonts
     fontdb=QFontDatabase()
     for font in fontdb.families():
         f=QtGui.QFont(font)
         f.setPointSize(12)
         f.setPixelSize(12)
         it=QtGui.QListWidgetItem()
         it.setFont(f)
         it.setText(font)
         self.listFonts.addItem(it)
         
     
     
     #SLOTS
     QtCore.QObject.connect(self.pushQuery,QtCore.SIGNAL('clicked()'),self.GenerateSynthetic)
Пример #20
0
 def remove_fonts(self):
     for font_id in self.cache:
         QFontDatabase.removeApplicationFont(font_id)
     self.cache.clear()
Пример #21
0
    def handle_embedded_fonts(self):
        '''
        Because of QtWebKit's inability to handle embedded fonts correctly, we
        remove the embedded fonts and make them available system wide instead.
        If you ever move to Qt WebKit 2.3+ then this will be unnecessary.
        '''
        from calibre.ebooks.oeb.base import urlnormalize
        from calibre.gui2 import must_use_qt
        from calibre.utils.fonts.utils import get_font_names, remove_embed_restriction
        from PyQt4.Qt import QFontDatabase, QByteArray

        # First find all @font-face rules and remove them, adding the embedded
        # fonts to Qt
        family_map = {}
        for item in list(self.oeb.manifest):
            if not hasattr(item.data, 'cssRules'): continue
            remove = set()
            for i, rule in enumerate(item.data.cssRules):
                if rule.type == rule.FONT_FACE_RULE:
                    remove.add(i)
                    try:
                        s = rule.style
                        src = s.getProperty('src').propertyValue[0].uri
                        font_family = s.getProperty('font-family').propertyValue[0].value
                    except:
                        continue
                    path = item.abshref(src)
                    ff = self.oeb.manifest.hrefs.get(urlnormalize(path), None)
                    if ff is None:
                        continue

                    raw = ff.data
                    self.oeb.manifest.remove(ff)
                    try:
                        raw = remove_embed_restriction(raw)
                    except:
                        continue
                    must_use_qt()
                    QFontDatabase.addApplicationFontFromData(QByteArray(raw))
                    try:
                        family_name = get_font_names(raw)[0]
                    except:
                        family_name = None
                    if family_name:
                        family_map[icu_lower(font_family)] = family_name

            for i in sorted(remove, reverse=True):
                item.data.cssRules.pop(i)

        # Now map the font family name specified in the css to the actual
        # family name of the embedded font (they may be different in general).
        for item in self.oeb.manifest:
            if not hasattr(item.data, 'cssRules'): continue
            for i, rule in enumerate(item.data.cssRules):
                if rule.type != rule.STYLE_RULE: continue
                ff = rule.style.getProperty('font-family')
                if ff is None: continue
                val = ff.propertyValue
                for i in xrange(val.length):
                    k = icu_lower(val[i].value)
                    if k in family_map:
                        val[i].value = family_map[k]
Пример #22
0
    def handle_embedded_fonts(self):
        '''
        Because of QtWebKit's inability to handle embedded fonts correctly, we
        remove the embedded fonts and make them available system wide instead.
        If you ever move to Qt WebKit 2.3+ then this will be unnecessary.
        '''
        from calibre.ebooks.oeb.base import urlnormalize
        from calibre.utils.fonts.utils import remove_embed_restriction
        from PyQt4.Qt import QFontDatabase, QByteArray, QRawFont, QFont

        # First find all @font-face rules and remove them, adding the embedded
        # fonts to Qt
        family_map = {}
        for item in list(self.oeb.manifest):
            if not hasattr(item.data, 'cssRules'):
                continue
            remove = set()
            for i, rule in enumerate(item.data.cssRules):
                if rule.type == rule.FONT_FACE_RULE:
                    remove.add(i)
                    try:
                        s = rule.style
                        src = s.getProperty('src').propertyValue[0].uri
                        font_family = s.getProperty(
                            'font-family').propertyValue[0].value
                    except:
                        continue
                    path = item.abshref(src)
                    ff = self.oeb.manifest.hrefs.get(urlnormalize(path), None)
                    if ff is None:
                        continue

                    raw = ff.data
                    self.oeb.manifest.remove(ff)
                    try:
                        raw = remove_embed_restriction(raw)
                    except:
                        continue
                    fid = QFontDatabase.addApplicationFontFromData(
                        QByteArray(raw))
                    family_name = None
                    if fid > -1:
                        try:
                            family_name = unicode(
                                QFontDatabase.applicationFontFamilies(fid)[0])
                        except (IndexError, KeyError):
                            pass
                    if family_name:
                        family_map[icu_lower(font_family)] = family_name

            for i in sorted(remove, reverse=True):
                item.data.cssRules.pop(i)

        # Now map the font family name specified in the css to the actual
        # family name of the embedded font (they may be different in general).
        font_warnings = set()
        for item in self.oeb.manifest:
            if not hasattr(item.data, 'cssRules'):
                continue
            for i, rule in enumerate(item.data.cssRules):
                if rule.type != rule.STYLE_RULE:
                    continue
                ff = rule.style.getProperty('font-family')
                if ff is None:
                    continue
                val = ff.propertyValue
                for i in xrange(val.length):
                    try:
                        k = icu_lower(val[i].value)
                    except (AttributeError, TypeError):
                        val[i].value = k = 'times'
                    if k in family_map:
                        val[i].value = family_map[k]
                if iswindows:
                    # On windows, Qt uses GDI which does not support OpenType
                    # (CFF) fonts, so we need to nuke references to OpenType
                    # fonts. Note that you could compile QT with configure
                    # -directwrite, but that requires atleast Vista SP2
                    for i in xrange(val.length):
                        family = val[i].value
                        if family:
                            f = QRawFont.fromFont(QFont(family))
                            if len(f.fontTable('head')) == 0:
                                if family not in font_warnings:
                                    self.log.warn(
                                        'Ignoring unsupported font: %s' %
                                        family)
                                    font_warnings.add(family)
                                # Either a bitmap or (more likely) a CFF font
                                val[i].value = 'times'
Пример #23
0
 def remove_fonts(self):
     for font_id in self.cache:
         QFontDatabase.removeApplicationFont(font_id)
     self.cache.clear()
Пример #24
0
def load_builtin_fonts():
    base = P('fonts/liberation/*.ttf')
    for f in glob.glob(base):
        QFontDatabase.addApplicationFont(f)
    return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'