diff options
| author | Adrien Tétar | 2015-11-07 12:33:02 +0100 | 
|---|---|---|
| committer | Adrien Tétar | 2015-11-07 18:52:51 +0100 | 
| commit | 9b2bc47a73a1e453aed95df907b1b120bd32b7b4 (patch) | |
| tree | 78160fa57f08865d08204097e938d16eb47e8455 /Lib | |
| parent | d648e2cb3f0a7bf7644dd2b2e610804e6e943a46 (diff) | |
| download | trufont-9b2bc47a73a1e453aed95df907b1b120bd32b7b4.tar.bz2 | |
meta: add custom glyphList support
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/defconQt/__main__.py | 8 | ||||
| -rw-r--r-- | Lib/defconQt/fontView.py | 54 | ||||
| -rw-r--r-- | Lib/defconQt/objects/defcon.py | 12 | ||||
| -rw-r--r-- | Lib/defconQt/util/glyphList.py | 21 | 
4 files changed, 81 insertions, 14 deletions
| diff --git a/Lib/defconQt/__main__.py b/Lib/defconQt/__main__.py index 270764d..79fa2cf 100644 --- a/Lib/defconQt/__main__.py +++ b/Lib/defconQt/__main__.py @@ -1,9 +1,10 @@ -from defconQt.objects.defcon import TFont  from defconQt import representationFactories  from defconQt import icons_db  # noqa  from defconQt.fontView import Application, MainWindow +from defconQt.objects.defcon import TFont  import sys  import os +from PyQt5.QtCore import QSettings  from PyQt5.QtGui import QIcon @@ -21,6 +22,11 @@ def main():      app.setOrganizationDomain("trufont.github.io")      app.setApplicationName("TruFont")      app.setWindowIcon(QIcon(":/resources/app.png")) +    settings = QSettings() +    glyphListPath = settings.value("settings/glyphListPath", type=str) +    if glyphListPath and os.path.exists(glyphListPath): +        from defconQt.util import glyphList +        app.GL2UV = glyphList.parseGlyphList(glyphListPath)      window = MainWindow(font)      window.show()      sys.exit(app.exec_()) diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py index 7def24d..0a6435f 100644 --- a/Lib/defconQt/fontView.py +++ b/Lib/defconQt/fontView.py @@ -17,8 +17,8 @@ from PyQt5.QtGui import (      QRegularExpressionValidator, QTextCursor)  from PyQt5.QtWidgets import (      QAbstractItemView, QAction, QApplication, QCheckBox, QComboBox, QDialog, -    QDialogButtonBox, QFileDialog, QGridLayout, QGroupBox, QLabel, QLineEdit, -    QListWidget, QListWidgetItem, QMainWindow, QMenu, QMessageBox, +    QDialogButtonBox, QFileDialog, QGridLayout, QGroupBox, QHBoxLayout, QLabel, +    QLineEdit, QListWidget, QListWidgetItem, QMainWindow, QMenu, QMessageBox,      QPlainTextEdit, QPushButton, QRadioButton, QSlider, QSplitter, QTabWidget,      QTextEdit, QToolTip, QVBoxLayout, QWidget)  from collections import OrderedDict @@ -72,6 +72,7 @@ class Application(QApplication):          super(Application, self).__init__(*args, **kwargs)          self._currentGlyph = None          self._currentMainWindow = None +        self.GL2UV = None      def allFonts(self):          fonts = [] @@ -1338,17 +1339,36 @@ class GlyphSetTab(QWidget):          importMenu.addAction("Import from current font",                               self.importFromCurrentFont)          self.importButton.setMenu(importMenu) - -        mainLayout = QGridLayout() +        glyphListPath = settings.value("settings/glyphListPath", type=str) +        self.glyphListBox = QCheckBox("Glyph list path:", self) +        self.glyphListBox.setChecked(bool(glyphListPath)) +        self.glyphListEdit = QLineEdit(glyphListPath, self) +        self.glyphListEdit.setEnabled(bool(glyphListPath)) +        self.glyphListEdit.setReadOnly(True) +        self.glyphListButton = QPushButton("Browse…", self) +        self.glyphListButton.setEnabled(bool(glyphListPath)) +        self.glyphListButton.pressed.connect(self.getGlyphList) +        self.glyphListButton.setFixedWidth(72) +        self.glyphListBox.toggled.connect(self.glyphListEdit.setEnabled) +        self.glyphListBox.toggled.connect(self.glyphListButton.setEnabled) + +        firstLayout = QGridLayout()          l = 0 -        mainLayout.addWidget(self.defaultGlyphSetBox, l, 0, 1, 2) -        mainLayout.addWidget(self.defaultGlyphSetDrop, l, 3, 1, 3) +        firstLayout.addWidget(self.defaultGlyphSetBox, l, 0, 1, 2) +        firstLayout.addWidget(self.defaultGlyphSetDrop, l, 3, 1, 3)          l += 1 -        mainLayout.addWidget(splitter, l, 0, 1, 6) +        firstLayout.addWidget(splitter, l, 0, 1, 6)          l += 1 -        mainLayout.addWidget(self.addGlyphSetButton, l, 0) -        mainLayout.addWidget(self.removeGlyphSetButton, l, 1) -        mainLayout.addWidget(self.importButton, l, 2) +        firstLayout.addWidget(self.addGlyphSetButton, l, 0) +        firstLayout.addWidget(self.removeGlyphSetButton, l, 1) +        firstLayout.addWidget(self.importButton, l, 2) +        secondLayout = QHBoxLayout() +        secondLayout.addWidget(self.glyphListBox, 0) +        secondLayout.addWidget(self.glyphListEdit, 1) +        secondLayout.addWidget(self.glyphListButton, 2) +        mainLayout = QVBoxLayout() +        mainLayout.addLayout(firstLayout) +        mainLayout.addLayout(secondLayout)          self.setLayout(mainLayout)      def addGlyphSet(self, glyphNames=[], glyphSetName="New glyph set"): @@ -1415,6 +1435,17 @@ class GlyphSetTab(QWidget):              index += 1          settings.endArray() +    def getGlyphList(self): +        fileFormats = ( +            "Text file (*.txt)", +            "All files (*.*)", +        ) +        path, _ = QFileDialog.getOpenFileName( +            self, "Open File", '', ";;".join(fileFormats) +        ) +        if path: +            self.glyphListEdit.setText(path) +      def writeValues(self):          # store content of the textEdit in the glyphSet dict          glyphNames = self.glyphSetContents.toPlainText().split() @@ -1429,6 +1460,9 @@ class GlyphSetTab(QWidget):              defaultGlyphSet = self.defaultGlyphSetDrop.currentText()              if defaultGlyphSet != latinDefault.name:                  settings.setValue("settings/defaultGlyphSet", defaultGlyphSet) +        glyphListPath = self.glyphListEdit.text() +        if glyphListPath: +            settings.setValue("settings/glyphListPath", glyphListPath)  class MetricsWindowTab(QTabWidget): diff --git a/Lib/defconQt/objects/defcon.py b/Lib/defconQt/objects/defcon.py index bb1336b..48de173 100644 --- a/Lib/defconQt/objects/defcon.py +++ b/Lib/defconQt/objects/defcon.py @@ -1,6 +1,7 @@  from defcon import Font, Contour, Glyph, Point  from defcon.objects.base import BaseObject -from fontTools.agl import AGL2UV +from PyQt5.QtWidgets import QApplication +import fontTools  class TFont(Font): @@ -59,10 +60,15 @@ class TGlyph(Glyph):      dirty = property(BaseObject._get_dirty, _set_dirty)      def autoUnicodes(self): +        app = QApplication.instance() +        if app.GL2UV is not None: +            GL2UV = app.GL2UV +        else: +            GL2UV = fontTools.agl.AGL2UV          hexes = "ABCDEF0123456789"          name = self.name -        if name in AGL2UV: -            uni = AGL2UV[name] +        if name in GL2UV: +            uni = GL2UV[name]          elif (name.startswith("uni") and len(name) == 7 and                all(c in hexes for c in name[3:])):              uni = int(name[3:], 16) diff --git a/Lib/defconQt/util/glyphList.py b/Lib/defconQt/util/glyphList.py new file mode 100644 index 0000000..7c16268 --- /dev/null +++ b/Lib/defconQt/util/glyphList.py @@ -0,0 +1,21 @@ +import re + +_parseGL_RE = re.compile("([A-Za-z_0-9.]+);([0-9A-F]{4})") + + +def parseGlyphList(path): +    GL2UV = {} +    with open(path) as file: +        for line in file: +            if not line or line[:1] == '#': +                continue +            m = _parseGL_RE.match(line) +            if not m: +                print("warning: syntax error in glyphlist: %s".format( +                    repr(line[:20]))) +            glyphName = m.group(1) +            if glyphName in GL2UV: +                print("warning: glyphName redefined in glyphList: {}".format( +                    glyphName)) +            GL2UV[glyphName] = int(m.group(2), 16) +    return GL2UV | 
