Skip to content

Instantly share code, notes, and snippets.

@adrientetar
Created October 15, 2015 17:25
Show Gist options
  • Save adrientetar/6f3875da84896a0f3415 to your computer and use it in GitHub Desktop.
Save adrientetar/6f3875da84896a0f3415 to your computer and use it in GitHub Desktop.
From 6cbf38f1ba18c08bc41b07deb036773f6ab80618 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20T=C3=A9tar?= <adri-from-59@hotmail.fr>
Date: Wed, 30 Sep 2015 23:40:44 +0200
Subject: [PATCH] fontInfo: add OS/2 table (wip)
---
Lib/defconQt/fontInfo.py | 301 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 298 insertions(+), 3 deletions(-)
diff --git a/Lib/defconQt/fontInfo.py b/Lib/defconQt/fontInfo.py
index 4625eec..2b172d5 100644
--- a/Lib/defconQt/fontInfo.py
+++ b/Lib/defconQt/fontInfo.py
@@ -15,10 +15,16 @@ class TabDialog(QDialog):
self.tabWidget.addNamedTab(GeneralTab(self.font))
self.tabWidget.addNamedTab(MetricsTab(self.font))
self.tabWidget.addNamedTab(OpenTypeTab(self.font))
+ #scrollArea = QScrollArea(self)
+ #scrollArea.setFrameShape(QFrame.NoFrame)
+ #scrollArea.setStyleSheet("QScrollArea { background: transparent; } \
+ #QScrollArea > QWidget > QWidget { background: transparent; }")
+ #scrollArea.setWidget(OS2Tab(self.font))
+ #self.tabWidget.addTab(scrollArea, "OS/2")
+ self.tabWidget.addNamedTab(OS2Tab(self.font))
self.tabWidget.addNamedTab(PostScriptTab(self.font))
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
-
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
@@ -457,7 +463,7 @@ class OpenTypeTab(QWidget):
version = self.versionEdit.text()
font.info.openTypeNameVersion = version if version != '' else None
uniqueID = self.uniqueIDEdit.text()
- font.info.openTypeNameUniqueID = int(uniqueID) if uniqueID != '' else None
+ font.info.openTypeNameUniqueID = uniqueID if uniqueID != '' else None
description = self.descriptionEdit.text()
font.info.openTypeNameDescription = description if description != '' else None
sampleText = self.sampleTextEdit.text()
@@ -487,6 +493,295 @@ class OpenTypeTab(QWidget):
vheaCaretOffset = self.vheaCaretOffsetEdit.text()
font.info.openTypeVheaCaretOffset = int(vheaCaretOffset) if vheaCaretOffset != '' else None
+class OS2Tab(QWidget):
+ name = "OS/2"
+
+ def __init__(self, font, parent=None):
+ super(OS2Tab, self).__init__(parent)
+
+ #OS2Group = QGroupBox("OS/2 table", self)
+ #OS2Group.setFlat(True)
+ OS2Layout = QGridLayout(self)
+
+ usWidthClassLabel = QLabel("usWidthClass:", self)
+ self.usWidthClassDrop = QComboBox(self)
+ items = ["None", "Ultra-condensed", "Extra-condensed", "Condensed",
+ "Semi-Condensed", "Medium (normal)", "Semi-expanded", "Expanded",
+ "Extra-expanded", "Ultra-expanded"]
+ self.usWidthClassDrop.insertItems(0, items)
+ if font.info.openTypeOS2WidthClass is not None:
+ self.usWidthClassDrop.setCurrentIndex(font.info.openTypeOS2WidthClass)
+
+ usWeightClassLabel = QLabel("usWeightClass:", self)
+ usWeightClass = str(font.info.openTypeOS2WeightClass) if font.info.openTypeOS2WeightClass is not None else ''
+ self.usWeightClassEdit = QLineEdit(usWeightClass, self)
+ positiveValidator = QIntValidator(self)
+ positiveValidator.setBottom(0)
+ self.usWeightClassEdit.setValidator(positiveValidator)
+
+ fsSelectionLabel = QLabel("fsSelection:", self)
+ fsSelection = font.info.openTypeOS2Selection
+ self.fsSelectionList = QListView(self)
+ items = ["1 UNDERSCORE", "2 NEGATIVE", "3 OUTLINED", "4 STRIKEOUT",
+ "7 USE_TYPO_METRICS", "8 WWS", "9 OBLIQUE"]
+ # http://stackoverflow.com/a/26613163
+ model = QStandardItemModel(7, 1)
+ for index, elem in enumerate(items):
+ item = QStandardItem()
+ item.setText(elem)
+ item.setCheckable(True)
+ bit = index+1
+ if fsSelection is not None and bit in fsSelection:
+ item.setCheckState(Qt.Checked) # maybe default setting? if so, unneeded
+ else:
+ item.setCheckState(Qt.Unchecked)
+ model.setItem(index, item)
+ self.fsSelectionList.setModel(model)
+
+ achVendorIDLabel = QLabel("achVendorID:", self)
+ self.achVendorIDEdit = QLineEdit(font.info.openTypeOS2VendorID, self)
+ self.achVendorIDEdit.setMaxLength(4)
+
+ fsTypeLabel = QLabel("fsType:", self)
+ fsType = font.info.openTypeOS2Type
+ self.fsTypeDrop = QComboBox(self)
+ items = ["No embedding restrictions", "Restricted embedding",
+ "Preview and print embedding allowed", "Editable embedding allowed"]
+ self.allowSubsettingBox = QCheckBox("Allow subsetting", self)
+ self.allowBitmapEmbeddingBox = QCheckBox("Allow only bitmap embedding", self)
+ self.fsTypeDrop.currentIndexChanged[int].connect(self._updateFsTypeVisibility)
+ self.fsTypeDrop.insertItems(0, items)
+ if fsType is not None:
+ for i in range(1, 4):
+ if i in fsType:
+ self.fsTypeDrop.setCurrentIndex(i)
+ break
+ self.allowSubsettingBox.setChecked(not 8 in fsType)
+ self.allowBitmapEmbeddingBox.setChecked(9 in fsType)
+
+ # XXX: ulUnicodeRange
+
+ # XXX: ulCodePageRange
+
+ sTypoAscenderLabel = QLabel("sTypoAscender:", self)
+ sTypoAscender = str(font.info.openTypeOS2TypoAscender) if font.info.openTypeOS2TypoAscender is not None else ''
+ self.sTypoAscenderEdit = QLineEdit(sTypoAscender, self)
+ self.sTypoAscenderEdit.setValidator(QIntValidator(self))
+
+ sTypoDescenderLabel = QLabel("sTypoDescender:", self)
+ sTypoDescender = str(font.info.openTypeOS2TypoDescender) if font.info.openTypeOS2TypoDescender is not None else ''
+ self.sTypoDescenderEdit = QLineEdit(sTypoDescender, self)
+ negativeValidator = QIntValidator(self)
+ negativeValidator.setTop(0)
+ self.sTypoDescenderEdit.setValidator(negativeValidator)
+
+ sTypoLineGapLabel = QLabel("sTypoLineGap:", self)
+ sTypoLineGap = str(font.info.openTypeOS2TypoLineGap) if font.info.openTypeOS2TypoLineGap is not None else ''
+ self.sTypoLineGapEdit = QLineEdit(sTypoLineGap, self)
+ self.sTypoLineGapEdit.setValidator(QIntValidator(self))
+
+ usWinAscentLabel = QLabel("usWinAscent:", self)
+ usWinAscent = str(font.info.openTypeOS2WinAscent) if font.info.openTypeOS2WinAscent is not None else ''
+ self.usWinAscentEdit = QLineEdit(usWinAscent, self)
+ self.usWinAscentEdit.setValidator(QIntValidator(self))
+
+ usWinDescentLabel = QLabel("usWinDescent:", self)
+ usWinDescent = str(font.info.openTypeOS2WinDescent) if font.info.openTypeOS2WinDescent is not None else ''
+ self.usWinDescentEdit = QLineEdit(usWinDescent, self)
+ positiveValidator = QIntValidator(self)
+ positiveValidator.setBottom(0)
+ self.usWinDescentEdit.setValidator(positiveValidator)
+
+ ySubscriptXSizeLabel = QLabel("ySubscriptXSize:", self)
+ ySubscriptXSize = str(font.info.openTypeOS2SubscriptXSize) if font.info.openTypeOS2SubscriptXSize is not None else ''
+ self.ySubscriptXSizeEdit = QLineEdit(ySubscriptXSize, self)
+ self.ySubscriptXSizeEdit.setValidator(QIntValidator(self))
+
+ ySubscriptYSizeLabel = QLabel("ySubscriptYSize:", self)
+ ySubscriptYSize = str(font.info.openTypeOS2SubscriptYSize) if font.info.openTypeOS2SubscriptYSize is not None else ''
+ self.ySubscriptYSizeEdit = QLineEdit(ySubscriptYSize, self)
+ self.ySubscriptYSizeEdit.setValidator(QIntValidator(self))
+
+ ySubscriptXOffsetLabel = QLabel("ySubscriptXOffset:", self)
+ ySubscriptXOffset = str(font.info.openTypeOS2SubscriptXOffset) if font.info.openTypeOS2SubscriptXOffset is not None else ''
+ self.ySubscriptXOffsetEdit = QLineEdit(ySubscriptXOffset, self)
+ self.ySubscriptXOffsetEdit.setValidator(QIntValidator(self))
+
+ ySubscriptYOffsetLabel = QLabel("ySubscriptYOffset:", self)
+ ySubscriptYOffset = str(font.info.openTypeOS2SubscriptYOffset) if font.info.openTypeOS2SubscriptYOffset is not None else ''
+ self.ySubscriptYOffsetEdit = QLineEdit(ySubscriptYOffset, self)
+ self.ySubscriptYOffsetEdit.setValidator(QIntValidator(self))
+
+ ySuperscriptXSizeLabel = QLabel("ySuperscriptXSize:", self)
+ ySuperscriptXSize = str(font.info.openTypeOS2SuperscriptXSize) if font.info.openTypeOS2SuperscriptXSize is not None else ''
+ self.ySuperscriptXSizeEdit = QLineEdit(ySuperscriptXSize, self)
+ self.ySuperscriptXSizeEdit.setValidator(QIntValidator(self))
+
+ ySuperscriptYSizeLabel = QLabel("ySuperscriptYSize:", self)
+ ySuperscriptYSize = str(font.info.openTypeOS2SuperscriptYSize) if font.info.openTypeOS2SuperscriptYSize is not None else ''
+ self.ySuperscriptYSizeEdit = QLineEdit(ySuperscriptYSize, self)
+ self.ySuperscriptYSizeEdit.setValidator(QIntValidator(self))
+
+ ySuperscriptXOffsetLabel = QLabel("ySuperscriptXOffset:", self)
+ ySuperscriptXOffset = str(font.info.openTypeOS2SuperscriptXOffset) if font.info.openTypeOS2SuperscriptXOffset is not None else ''
+ self.ySuperscriptXOffsetEdit = QLineEdit(ySuperscriptXOffset, self)
+ self.ySuperscriptXOffsetEdit.setValidator(QIntValidator(self))
+
+ ySuperscriptYOffsetLabel = QLabel("ySuperscriptYOffset:", self)
+ ySuperscriptYOffset = str(font.info.openTypeOS2SuperscriptYOffset) if font.info.openTypeOS2SuperscriptYOffset is not None else ''
+ self.ySuperscriptYOffsetEdit = QLineEdit(ySuperscriptYOffset, self)
+ self.ySuperscriptYOffsetEdit.setValidator(QIntValidator(self))
+
+ yStrikeoutSizeLabel = QLabel("yStrikeoutSize:", self)
+ yStrikeoutSize = str(font.info.openTypeOS2StrikeoutSize) if font.info.openTypeOS2StrikeoutSize is not None else ''
+ self.yStrikeoutSizeEdit = QLineEdit(yStrikeoutSize, self)
+ self.yStrikeoutSizeEdit.setValidator(QIntValidator(self))
+
+ yStrikeoutPositionLabel = QLabel("yStrikeoutPosition:", self)
+ yStrikeoutPosition = str(font.info.openTypeOS2StrikeoutPosition) if font.info.openTypeOS2StrikeoutPosition is not None else ''
+ self.yStrikeoutPositionEdit = QLineEdit(yStrikeoutPosition, self)
+ self.yStrikeoutPositionEdit.setValidator(QIntValidator(self))
+
+ # XXX: panose
+
+ l = 0
+ OS2Layout.addWidget(usWidthClassLabel, l, 0)
+ OS2Layout.addWidget(self.usWidthClassDrop, l, 1, 1, 2)
+ OS2Layout.addWidget(achVendorIDLabel, l, 3)
+ OS2Layout.addWidget(self.achVendorIDEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(usWeightClassLabel, l, 0)
+ OS2Layout.addWidget(self.usWeightClassEdit, l, 1, 1, 2)
+ l += 1
+ OS2Layout.addWidget(fsSelectionLabel, l, 0, 3, 1)
+ OS2Layout.addWidget(self.fsSelectionList, l, 1, 3, 2)
+ OS2Layout.addWidget(fsTypeLabel, l, 3, 3, 1)
+ OS2Layout.addWidget(self.fsTypeDrop, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(self.allowSubsettingBox, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(self.allowBitmapEmbeddingBox, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(sTypoAscenderLabel, l, 0)
+ OS2Layout.addWidget(self.sTypoAscenderEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(usWinAscentLabel, l, 3)
+ OS2Layout.addWidget(self.usWinAscentEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(sTypoDescenderLabel, l, 0)
+ OS2Layout.addWidget(self.sTypoDescenderEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(usWinDescentLabel, l, 3)
+ OS2Layout.addWidget(self.usWinDescentEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(sTypoLineGapLabel, l, 0)
+ OS2Layout.addWidget(self.sTypoLineGapEdit, l, 1, 1, 2)
+ l += 1
+ OS2Layout.addWidget(ySubscriptXSizeLabel, l, 0)
+ OS2Layout.addWidget(self.ySubscriptXSizeEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(ySubscriptXOffsetLabel, l, 3)
+ OS2Layout.addWidget(self.ySubscriptXOffsetEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(ySubscriptYSizeLabel, l, 0)
+ OS2Layout.addWidget(self.ySubscriptYSizeEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(ySubscriptYOffsetLabel, l, 3)
+ OS2Layout.addWidget(self.ySubscriptYOffsetEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(ySuperscriptXSizeLabel, l, 0)
+ OS2Layout.addWidget(self.ySuperscriptXSizeEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(ySuperscriptXOffsetLabel, l, 3)
+ OS2Layout.addWidget(self.ySuperscriptXOffsetEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(ySuperscriptYSizeLabel, l, 0)
+ OS2Layout.addWidget(self.ySuperscriptYSizeEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(ySuperscriptYOffsetLabel, l, 3)
+ OS2Layout.addWidget(self.ySuperscriptYOffsetEdit, l, 4, 1, 2)
+ l += 1
+ OS2Layout.addWidget(yStrikeoutSizeLabel, l, 0)
+ OS2Layout.addWidget(self.yStrikeoutSizeEdit, l, 1, 1, 2)
+ OS2Layout.addWidget(yStrikeoutPositionLabel, l, 3)
+ OS2Layout.addWidget(self.yStrikeoutPositionEdit, l, 4, 1, 2)
+ #OS2Group.setLayout(OS2Layout)
+ self.setLayout(OS2Layout)
+
+ def _updateFsTypeVisibility(self, index):
+ if index == 0:
+ # TODO: maybe uncheck as well?
+ self.allowSubsettingBox.setEnabled(False)
+ self.allowBitmapEmbeddingBox.setEnabled(False)
+ else:
+ self.allowSubsettingBox.setEnabled(True)
+ self.allowBitmapEmbeddingBox.setEnabled(True)
+
+ def writeValues(self, font):
+ usWidthClass = self.usWidthClassDrop.currentIndex()
+ font.info.openTypeOS2WidthClass = usWidthClass if usWidthClass != 0 else None
+ usWeightClass = self.usWeightClassEdit.text()
+ font.info.openTypeOS2WeightClass = int(usWeightClass) if usWeightClass != '' else None
+
+ fsSelectionModel = self.fsSelectionList.model()
+ fsSelection = []
+ for i in range(7):
+ item = fsSelectionModel.item(i)
+ if item.checkState() == Qt.Checked:
+ fsSelection.append(i)
+ if len(fsSelection):
+ font.info.openTypeOS2Selection = fsSelection
+ else:
+ font.info.openTypeOS2Selection = None # XXX: None or empty array? should distinct those cases
+
+ fsTypeIndex = self.fsTypeDrop.currentIndex()
+ fsType = []
+ if fsTypeIndex > 0:
+ fsType.append(fsTypeIndex)
+ if not self.allowSubsettingBox.isChecked():
+ fsType.append(8)
+ if self.allowBitmapEmbeddingBox.isChecked():
+ fsType.append(9)
+ font.info.openTypeOS2Type = fsType # TODO: provide a way to represent None w this?
+
+ # TODO: see if data needs to be padded to 4 chars. I think that this is to be deferred to ufo2fdk(?)
+ font.info.openTypeOS2VendorID = self.achVendorIDEdit.text()
+
+ # XXX: ulUnicodeRange
+
+ # XXX: ulCodePageRange
+
+ sTypoAscender = self.sTypoAscenderEdit.text()
+ font.info.openTypeOS2TypoAscender = int(sTypoAscender) if sTypoAscender != '' else None
+ sTypoDescender = self.sTypoDescenderEdit.text()
+ font.info.openTypeOS2TypoDescender = int(sTypoDescender) if sTypoDescender != '' else None
+ sTypoLineGap = self.sTypoLineGapEdit.text()
+ font.info.openTypeOS2TypoLineGap = int(sTypoLineGap) if sTypoLineGap != '' else None
+
+ usWinAscent = self.usWinAscentEdit.text()
+ font.info.openTypeOS2WinAscent = int(usWinAscent) if usWinAscent != '' else None
+ usWinDescent = self.usWinDescentEdit.text()
+ font.info.openTypeOS2WinDescent = int(usWinDescent) if usWinDescent != '' else None
+
+ ySubscriptXSize = self.ySubscriptXSizeEdit.text()
+ font.info.openTypeOS2SubscriptXSize = int(ySubscriptXSize) if ySubscriptXSize != '' else None
+ ySubscriptYSize = self.ySubscriptYSizeEdit.text()
+ font.info.openTypeOS2SubscriptYSize = int(ySubscriptYSize) if ySubscriptYSize != '' else None
+ ySubscriptXOffset = self.ySubscriptXOffsetEdit.text()
+ font.info.openTypeOS2SubscriptXOffset = int(ySubscriptXOffset) if ySubscriptXOffset != '' else None
+ ySubscriptYOffset = self.ySubscriptYOffsetEdit.text()
+ font.info.openTypeOS2SubscriptYOffset = int(ySubscriptYOffset) if ySubscriptYOffset != '' else None
+
+ ySuperscriptXSize = self.ySuperscriptXSizeEdit.text()
+ font.info.openTypeOS2SuperscriptXSize = int(ySuperscriptXSize) if ySuperscriptXSize != '' else None
+ ySuperscriptYSize = self.ySuperscriptYSizeEdit.text()
+ font.info.openTypeOS2SuperscriptYSize = int(ySuperscriptYSize) if ySuperscriptYSize != '' else None
+ ySuperscriptXOffset = self.ySuperscriptXOffsetEdit.text()
+ font.info.openTypeOS2SuperscriptXOffset = int(ySuperscriptXOffset) if ySuperscriptXOffset != '' else None
+ ySuperscriptYOffset = self.ySuperscriptYOffsetEdit.text()
+ font.info.openTypeOS2SuperscriptYOffset = int(ySuperscriptYOffset) if ySuperscriptYOffset != '' else None
+
+ yStrikeoutSize = self.yStrikeoutSizeEdit.text()
+ font.info.openTypeOS2StrikeoutSize = int(yStrikeoutSize) if yStrikeoutSize != '' else None
+ yStrikeoutPosition = self.yStrikeoutPositionEdit.text()
+ font.info.openTypeOS2StrikeoutPosition = int(yStrikeoutPosition) if yStrikeoutPosition != '' else None
+
+ # XXX: panose
+
class PostScriptTab(QWidget):
name = "Postscript"
@@ -779,4 +1074,4 @@ class PostScriptTab(QWidget):
if windowsCharacterSet == 0:
font.info.postscriptWindowsCharacterSet = None
else:
- font.info.postscriptWindowsCharacterSet = windowsCharacterSet
\ No newline at end of file
+ font.info.postscriptWindowsCharacterSet = windowsCharacterSet
--
2.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment