def findSizes(self,font): fontLogger.debug("font.key()=%s" % font.key()) fontDatabase = QFontDatabase() self.sizeCombo.blockSignals(True) self.sizeCombo.clear() self.sizeComboFs.blockSignals(True) self.sizeComboFs.clear() styleStr = fontDatabase.styleString(font) if fontDatabase.isSmoothlyScalable(font.family(),styleStr): for size in QFontDatabase.standardSizes(): self.sizeCombo.addItem(str(size)) self.sizeComboFs.addItem(str(size)) else: for size in fontDatabase.smoothSizes(font.family(),styleStr): self.sizeCombo.addItem(str(size)) self.sizeComboFs.addItem(str(size)) self.sizeCombo.blockSignals(False) self.sizeComboFs.blockSignals(False) currentSize = unicode(QSettings().value("worksheet/fontsize", QtReduceDefaults.FONTSIZE)) sizeIndex = self.sizeCombo.findText(currentSize) self.sizeCombo.setCurrentIndex(sizeIndex) currentSize = unicode(QSettings().value("worksheet/fontsizefs", QtReduceDefaults.FONTSIZEFS)) sizeIndex = self.sizeCombo.findText(currentSize) self.sizeComboFs.setCurrentIndex(sizeIndex)
def findSizes(self, font): fontDatabase = QFontDatabase() currentSize = self.sizeComboBox.currentText() with Lib.BlockSignals(self.sizeComboBox): self.sizeComboBox.clear() if fontDatabase.isSmoothlyScalable(font.family(), fontDatabase.styleString(font)): for size in QFontDatabase.standardSizes(): self.sizeComboBox.addItem(str(size)) else: for size in fontDatabase.smoothSizes( font.family(), fontDatabase.styleString(font)): self.sizeComboBox.addItem(str(size)) self.sizeComboBox.setEditable(False) sizeIndex = self.sizeComboBox.findText(currentSize) if sizeIndex == -1: self.sizeComboBox.setCurrentIndex( max(0, self.sizeComboBox.count() / 3)) else: self.sizeComboBox.setCurrentIndex(sizeIndex)
def __nextGoodFontSize(self, font, size, step): info = QFontInfo(font) family = info.family() fontDatabase = QFontDatabase() styleStr = fontDatabase.styleString(font) fontLogger.debug("family=%s, style=%s" % (family, styleStr)) if fontDatabase.isSmoothlyScalable(family, styleStr): sizes = QFontDatabase.standardSizes() else: sizes = fontDatabase.smoothSizes(family, styleStr) fontLogger.debug("looking for %s in %s step %d" % (size, sizes, step)) nSize = size while nSize not in sizes and sizes[0] <= nSize and nSize <= sizes[-1]: nSize += step if nSize < sizes[0]: fontLogger.debug("out of range - returning %s" % sizes[0]) return sizes[0] if sizes[-1] < nSize: fontLogger.debug("out of range - returning %s" % sizes[-1]) return sizes[-1] fontLogger.debug("found %s" % nSize) return nSize
def __nextGoodFontSize(self,font,size,step): info = QFontInfo(font) family = info.family() fontDatabase = QFontDatabase() styleStr = fontDatabase.styleString(font) fontLogger.debug("family=%s, style=%s" % (family,styleStr)) if fontDatabase.isSmoothlyScalable(family,styleStr): sizes = QFontDatabase.standardSizes() else: sizes = fontDatabase.smoothSizes(family,styleStr) fontLogger.debug("looking for %s in %s step %d" % (size,sizes,step)) nSize = size while nSize not in sizes and sizes[0] <= nSize and nSize <= sizes[-1]: nSize += step if nSize < sizes[0]: fontLogger.debug("out of range - returning %s" % sizes[0]) return sizes[0] if sizes[-1] < nSize: fontLogger.debug("out of range - returning %s" % sizes[-1]) return sizes[-1] fontLogger.debug("found %s" % nSize) return nSize
def __init__(self,parent=None): super(QtReduceFontComboBox,self).__init__() fdb = QFontDatabase() l = [] self.fontDict = {} for fam in fdb.families(QFontDatabase.Latin): for sty in fdb.styles(fam): if not fam in l and fdb.isFixedPitch(fam,sty) \ and not fdb.bold(fam,sty) and not fdb.italic(fam,sty) \ and self.__osxHack(fam): fontLogger.debug("family=%s, style=%s, isFixedPitch=%s" % (fam, sty, fdb.isFixedPitch(fam,sty))) sizes = fdb.smoothSizes(fam,sty) if sizes: font = fdb.font(fam,sty,sizes[0]) if not font.exactMatch(): fontLogger.debug("no exactMatch for %s %s %s" % (fam,sty,sizes[0])) l += [fam] self.fontDict.update({str(fam):font}) l.sort self.addItems(l) self.currentIndexChanged.connect(self.currentIndexChangedHandler)