diff options
Diffstat (limited to 'Lib/defconQt/fontView.py')
| -rw-r--r-- | Lib/defconQt/fontView.py | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py index 068b29b..a53dadf 100644 --- a/Lib/defconQt/fontView.py +++ b/Lib/defconQt/fontView.py @@ -7,7 +7,6 @@ from defconQt.scriptingWindow import MainScriptingWindow from defconQt.objects.defcon import CharacterSet, TFont, TGlyph from defcon import Component from defconQt.spaceCenter import MainSpaceWindow -from fontTools.agl import AGL2UV # TODO: remove globs when things start to stabilize from PyQt5.QtCore import * from PyQt5.QtGui import * @@ -328,20 +327,26 @@ class AddGlyphDialog(QDialog): self.addGlyphEdit = QPlainTextEdit(self) self.addGlyphEdit.setFocus(True) + self.addUnicodeBox = QCheckBox("Add Unicode", self) + self.addUnicodeBox.setChecked(True) + self.addAsTemplateBox = QCheckBox("Add as template", self) + self.addAsTemplateBox.setChecked(True) self.sortFontBox = QCheckBox("Sort font", self) - self.overwriteBox = QCheckBox("Override", self) + self.overrideBox = QCheckBox("Override", self) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject) l = 0 - layout.addWidget(self.importCharDrop, l, 3) + layout.addWidget(self.importCharDrop, l, 3, 1, 2) l += 1 - layout.addWidget(self.addGlyphEdit, l, 0, 1, 4) + layout.addWidget(self.addGlyphEdit, l, 0, 1, 5) l += 1 - layout.addWidget(self.sortFontBox, l, 0) - layout.addWidget(self.overwriteBox, l, 1) - layout.addWidget(buttonBox, l, 3) + layout.addWidget(self.addUnicodeBox, l, 0) + layout.addWidget(self.addAsTemplateBox, l, 1) + layout.addWidget(self.sortFontBox, l, 2) + layout.addWidget(self.overrideBox, l, 3) + layout.addWidget(buttonBox, l, 4) self.setLayout(layout) @classmethod @@ -349,6 +354,12 @@ class AddGlyphDialog(QDialog): dialog = cls(currentGlyphs, parent) result = dialog.exec_() sortFont = False + params = dict( + addUnicode = dialog.addUnicodeBox.isChecked(), + asTemplate = dialog.addAsTemplateBox.isChecked(), + override = dialog.overrideBox.isChecked(), + sortFont = dialog.sortFontBox.isChecked(), + ) newGlyphNames = [] for name in dialog.addGlyphEdit.toPlainText().split(): if name not in dialog.currentGlyphNames: @@ -357,7 +368,7 @@ class AddGlyphDialog(QDialog): # XXX: if we get here with previous sort being by character set, # should it just stick? sortFont = True - return (newGlyphNames, sortFont, result) + return (newGlyphNames, params, result) def importCharacters(self, index): if index == 0: return @@ -666,6 +677,8 @@ class MainWindow(QMainWindow): if path is None and self.font.path is None: self.saveFileAs() else: + if path is None: + path = self.font.path glyphs = self.collectionWidget.glyphs # TODO: save sortDescriptor somewhere in lib as well glyphNames = [] @@ -783,22 +796,16 @@ class MainWindow(QMainWindow): def _set_sortDescriptor(self, desc): if isinstance(desc, CharacterSet): - cnt = 0 glyphs = [] for glyphName in desc.glyphNames: - if not glyphName in self._font: - # create a template glyph - self.newStandardGlyph(glyphName) - self._font[glyphName].template = True - else: - cnt += 1 - glyphs.append(self._font[glyphName]) - if cnt < len(self._font): - # somehow some glyphs in the font are not present in the glyph - # order, loop again to add these at the end + if glyphName in self._font: + glyphs.append(self._font[glyphName]) + if len(glyphs) < len(self._font): + # if some glyphs in the font are not present in the glyph + # order, loop again to add them at the end for glyph in self._font: - if not glyph in glyphs: - glyphs.append(glyph) + if glyph not in glyphs: + glyphs.append(glyph) else: glyphs = [self._font[k] for k in self._font.unicodeData .sortGlyphNames(self._font.keys(), desc)] @@ -817,7 +824,7 @@ class MainWindow(QMainWindow): selection = self.collectionWidget.selection pickled = [] for index in sorted(self.collectionWidget.selection): - pickled.append(glyphs[index].serializeForUndo(False)) + pickled.append(glyphs[index].serialize()) clipboard = QApplication.clipboard() mimeData = QMimeData() mimeData.setData("application/x-defconQt-glyph-data", pickle.dumps(pickled)) @@ -834,7 +841,7 @@ class MainWindow(QMainWindow): component = Component() component.baseGlyph = glyph.name componentGlyph.appendComponent(component) - pickled.append(componentGlyph.serializeForUndo(False)) + pickled.append(componentGlyph.serialize()) clipboard = QApplication.clipboard() mimeData = QMimeData() mimeData.setData("application/x-defconQt-glyph-data", pickle.dumps(pickled)) @@ -850,7 +857,7 @@ class MainWindow(QMainWindow): for pickled, glyph in zip(data, glyphs): name = glyph.name uni = glyph.unicode - glyph.deserializeFromUndo(pickled) + glyph.deserialize(pickled) # XXX: after upgrade to ufo3, write a more flexible # serialization system glyph.name = name @@ -871,14 +878,6 @@ class MainWindow(QMainWindow): else: glyph.lib["public.markColor"] = ",".join(str(c) for c in color.getRgbF()) - # TODO: maybe store this in TFont - def newStandardGlyph(self, name): - self.font.newGlyph(name) - self.font[name].width = 500 - # TODO: we should not force-add unicode, also list ought to be - # changeable from AGL2UV - if name in AGL2UV: self.font[name].unicode = AGL2UV[name] - def _fontChanged(self, notification): self.collectionWidget.update() self.setWindowModified(True) @@ -995,16 +994,18 @@ class MainWindow(QMainWindow): def addGlyph(self): glyphs = self.collectionWidget.glyphs - newGlyphNames, sortFont, ok = AddGlyphDialog.getNewGlyphNames(self, glyphs) + newGlyphNames, params, ok = AddGlyphDialog.getNewGlyphNames(self, glyphs) if ok: + sortFont = params.pop("sortFont") for name in newGlyphNames: - self.newStandardGlyph(name) - glyph = self.font[name] - # XXX: consider making this parametrizable in the dialog - glyph.template = True - glyphs.append(glyph) + glyph = self.font.newStandardGlyph(name, **params) + if glyph is not None: + glyphs.append(glyph) self.collectionWidget.glyphs = glyphs if sortFont: + # TODO: when the user add chars from a charset and no others, + # should we try to sort according to that charset? + # The above would probably warrant some rearchitecturing. # kick-in the sort mechanism self.sortDescriptor = self.sortDescriptor |
