aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrien Tétar2015-10-11 12:25:11 +0200
committerAdrien Tétar2015-10-11 12:25:11 +0200
commita80988874c5d621a2b11c75f5af31b23d3008ee7 (patch)
treeebfab62995527dd24924ffbec0ab349072ddabb9
parentea6b465a799c397227c74c4da74d7cf636a088e4 (diff)
downloadtrufont-a80988874c5d621a2b11c75f5af31b23d3008ee7.tar.bz2
meta: default to empty font, fixture
-rw-r--r--Lib/defconQt/fontView.py78
-rw-r--r--Lib/defconQt/glyphCollectionView.py2
-rw-r--r--Lib/defconQt/glyphView.py19
-rw-r--r--Lib/defconQt/groupsView.py5
4 files changed, 69 insertions, 35 deletions
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py
index 9f010a9..3e43bcb 100644
--- a/Lib/defconQt/fontView.py
+++ b/Lib/defconQt/fontView.py
@@ -258,27 +258,26 @@ class InspectorWindow(QWidget):
def updateGlyphAttributes(self, notification=None):
if self._blocked: return
- name = self._glyph.name if self._glyph is not None else None
+ colorStr = "white"
+ if self._glyph is not None:
+ name = self._glyph.name
+ unicodes = " ".join("%06X" % u if u > 0xFFFF else "%04X" % u for u in self._glyph.unicodes)
+ width = str(int(self._glyph.width)) if self._glyph.width else None
+ leftSideBearing = str(int(self._glyph.leftMargin)) if self._glyph.leftMargin is not None else None
+ rightSideBearing = str(int(self._glyph.rightMargin)) if self._glyph.rightMargin is not None else None
+ if self._glyph.markColor is not None:
+ colorStr = QColor.fromRgbF(*tuple(self._glyph.markColor)).name()
+ else:
+ name = None
+ unicodes = None
+ width = None
+ leftSideBearing = None
+ rightSideBearing = None
self.nameEdit.setText(name)
- unicodes = " ".join("%06X" % u if u > 0xFFFF else "%04X" % u for u in self._glyph.unicodes) if self._glyph is not None else None
self.unicodesEdit.setText(unicodes)
- width = str(int(self._glyph.width)) if self._glyph is not None else None
self.widthEdit.setText(width)
- leftSideBearing = str(int(self._glyph.leftMargin)) if self._glyph is not None else None
self.leftSideBearingEdit.setText(leftSideBearing)
- rightSideBearing = str(int(self._glyph.rightMargin)) if self._glyph is not None else None
self.rightSideBearingEdit.setText(rightSideBearing)
- colorStr = "white"
- if self._glyph is not None and "public.markColor" in self._glyph.lib:
- # XXX: cleanup duplication with glyphCollectionView
- # TODO: might well be possible to write this in a nicer way...
- colors = self._glyph.lib["public.markColor"].split(",")
- if len(colors) == 4:
- comp = []
- for c in colors:
- comp.append(float(c.strip()))
- markColor = QColor.fromRgbF(*comp)
- colorStr = markColor.name()
self.markColorButton.setStyleSheet("background-color: {}; \
border: 1px solid black;".format(colorStr))
@@ -543,14 +542,15 @@ class MainWindow(QMainWindow):
def __init__(self, font):
super(MainWindow, self).__init__()
self.setAttribute(Qt.WA_DeleteOnClose)
- if font is None:
- font = TFont()
squareSize = 56
self.collectionWidget = GlyphCollectionWidget(self)
self._font = None
self._sortDescriptor = None
- self.font = font
+ if font is None:
+ self.newFile(True)
+ else:
+ self.font = font
self.collectionWidget.glyphSelectedCallback = self._selectionChanged
self.collectionWidget.doubleClickCallback = self._glyphOpened
# TODO: should default be True or False?
@@ -644,20 +644,36 @@ class MainWindow(QMainWindow):
self.setCentralWidget(self.collectionWidget.scrollArea())
self.resize(605, 430)
- self.setCurrentFile(font.path)
+ if font is not None:
+ self.setCurrentFile(font.path)
self.setWindowTitle()
- def newFile(self):
- ok = self.maybeSaveBeforeExit()
- if not ok: return
- self.font = TFont()
- self.font.info.unitsPerEm = 1000
- self.font.info.ascender = 750
- self.font.info.descender = -250
- self.font.info.capHeight = 750
- self.font.info.xHeight = 500
- self.setWindowTitle("Untitled.ufo")
- self.sortDescriptor = latinDefault
+ def newFile(self, stickToSelf=False):
+ font = TFont()
+ font.info.unitsPerEm = 1000
+ font.info.ascender = 750
+ font.info.descender = -250
+ font.info.capHeight = 750
+ font.info.xHeight = 500
+ defaultGlyphSet = QSettings().value("settings/defaultGlyphSet",
+ latinDefault.name, type=str)
+ if defaultGlyphSet:
+ glyphNames = None
+ if defaultGlyphSet == latinDefault.name:
+ glyphNames = latinDefault.glyphNames
+ else:
+ glyphSets = readGlyphSets()
+ if defaultGlyphSet in glyphSets:
+ glyphNames = glyphSets[defaultGlyphSet]
+ if glyphNames is not None:
+ for name in glyphNames:
+ font.newStandardGlyph(name, asTemplate=True)
+ font.dirty = False
+ if not stickToSelf:
+ window = MainWindow(font)
+ window.show()
+ else:
+ self.font = font
def openFile(self, path=None):
if not path:
diff --git a/Lib/defconQt/glyphCollectionView.py b/Lib/defconQt/glyphCollectionView.py
index 81d35f9..37edb45 100644
--- a/Lib/defconQt/glyphCollectionView.py
+++ b/Lib/defconQt/glyphCollectionView.py
@@ -359,7 +359,7 @@ class GlyphCollectionWidget(QWidget):
if event.button() == Qt.LeftButton:
event.accept()
index = self._findEventIndex(event)
- if self.doubleClickCallback is not None:
+ if index is not None and self.doubleClickCallback is not None:
self.doubleClickCallback(self._glyphs[index])
else:
super(GlyphCollectionWidget, self).mousePressEvent(event)
diff --git a/Lib/defconQt/glyphView.py b/Lib/defconQt/glyphView.py
index 02a6994..a3a6d46 100644
--- a/Lib/defconQt/glyphView.py
+++ b/Lib/defconQt/glyphView.py
@@ -1413,11 +1413,16 @@ class GlyphView(QGraphicsView):
scene = self.scene()
font = self._glyph.getParent()
width = self._glyph.width
+ if width is None: width = 0
item = scene.addRect(-1000, -1000, 3000, 3000, QPen(Qt.black), QBrush(Qt.gray))
item.setZValue(-1000)
scene._widthItem = scene.addRect(0, -1000, width, 3000, QPen(Qt.NoPen), QBrush(backgroundColor))
scene._widthItem.setZValue(-999)
- self.centerOn(width/2, font.info.descender+font.info.unitsPerEm/2)
+ descender = font.info.descender
+ if descender is None: descender = -250
+ unitsPerEm = font.info.unitsPerEm
+ if unitsPerEm is None: unitsPerEm = 1000
+ self.centerOn(width/2, descender+unitsPerEm/2)
def addBlues(self):
scene = self.scene()
@@ -1448,10 +1453,12 @@ class GlyphView(QGraphicsView):
("Baseline", 0),
("x-height", font.info.xHeight),
("Cap height", font.info.capHeight),
- ("Ascender", font.info.ascender)
+ ("Ascender", font.info.ascender),
]
positions = {}
for name, position in toDraw:
+ if position is None:
+ continue
if position not in positions:
positions[position] = []
positions[position].append(name)
@@ -1674,7 +1681,13 @@ class GlyphView(QGraphicsView):
def showEvent(self, event):
super(GlyphView, self).showEvent(event)
font = self._glyph.getParent()
- self.fitInView(0, font.info.descender, self._glyph.width, font.info.unitsPerEm, Qt.KeepAspectRatio)
+ # TODO: we should have an app-wide mechanism to handle default metrics
+ # values (that are applied to new fonts as well)
+ descender = font.info.descender
+ if descender is None: descender = -250
+ unitsPerEm = font.info.unitsPerEm
+ if unitsPerEm is None: unitsPerEm = 1000
+ self.fitInView(0, descender, self._glyph.width, unitsPerEm, Qt.KeepAspectRatio)
def mousePressEvent(self, event):
if (event.button() == Qt.MidButton):
diff --git a/Lib/defconQt/groupsView.py b/Lib/defconQt/groupsView.py
index a1600b8..6a15541 100644
--- a/Lib/defconQt/groupsView.py
+++ b/Lib/defconQt/groupsView.py
@@ -34,9 +34,11 @@ class GroupStackWidget(QWidget):
def __init__(self, font, glyphs=[], parent=None):
super(GroupStackWidget, self).__init__(parent)
self.ascender = font.info.ascender
+ if self.ascender is None: self.ascender = 750
self.glyphs = glyphs
self.maxWidth = max(glyph.width for glyph in self.glyphs) if len(self.glyphs) else 300
self.upm = font.info.unitsPerEm
+ if self.upm is None: self.upm = 1000
self.padding = 10
self.alignRight = False
@@ -238,6 +240,9 @@ class GroupsWindow(QWidget):
currentGroup = currentGroup.text()
glyphNames = event.mimeData().text().split(" ")
for gName in glyphNames:
+ # TODO: should we accept template glyphs here?
+ if self.font[gName].template:
+ continue
# Due to defcon limitations, we must fetch and update for the
# notification to pass through
currentGroupList = self.font.groups[currentGroup]