From df159349172f69c7217612cffef06207b8d59ffa Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Wed, 17 Feb 2021 14:34:35 +0000 Subject: [PATCH] Allow choosing CoreText shaper --- Lib/fontgoggles/font/baseFont.py | 5 +++-- Lib/fontgoggles/mac/mainWindow.py | 18 +++++++++++++++++- Lib/fontgoggles/misc/hbShape.py | 4 ++-- Lib/fontgoggles/project.py | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Lib/fontgoggles/font/baseFont.py b/Lib/fontgoggles/font/baseFont.py index 198a06df..f0caf2a1 100644 --- a/Lib/fontgoggles/font/baseFont.py +++ b/Lib/fontgoggles/font/baseFont.py @@ -131,10 +131,11 @@ def getGlyphRunFromTextInfo(self, textInfo, colorPalettesIndex=0, **kwargs): def getGlyphRun(self, text, *, features=None, varLocation=None, direction=None, language=None, script=None, - colorLayers=False): + colorLayers=False, shaper="ot"): self.setVarLocation(varLocation) glyphInfo = self.shaper.shape(text, features=features, varLocation=varLocation, - direction=direction, language=language, script=script) + direction=direction, language=language, script=script, + shaper=shaper) glyphNames = (gi.name for gi in glyphInfo) for glyph, glyphDrawing in zip(glyphInfo, self.getGlyphDrawings(glyphNames, colorLayers)): glyph.glyphDrawing = glyphDrawing diff --git a/Lib/fontgoggles/mac/mainWindow.py b/Lib/fontgoggles/mac/mainWindow.py index 2e01917b..efcb4b6b 100644 --- a/Lib/fontgoggles/mac/mainWindow.py +++ b/Lib/fontgoggles/mac/mainWindow.py @@ -59,6 +59,8 @@ feaVarTabLabels = ["Features", "Variations", "Options"] feaVarTabValues = [v.lower() for v in feaVarTabLabels] +shaperOptions = ["HarfBuzz", "CoreText"] +shaperValues = ["ot", "coretext"] class FGMainWindowController(AppKit.NSWindowController, metaclass=ClassNameIncrementer): @@ -375,6 +377,14 @@ def setupGeneralSettingsGroup(self): group.languagesPopup = self.languagesPopup y += 50 + self.shaperPopup = LabeledView( + (10, y, -10, 40), "Shaper:", + PopUpButton, shaperOptions, + callback=self.shaperChangedCallback, + ) + group.shaperPopup = self.shaperPopup + y += 50 + group.setPosSize((0, 0, 0, y)) self.setLanguagesFromScript() return group @@ -640,7 +650,8 @@ def setFontItemText(self, fontItemInfo, fontItem): glyphs = font.getGlyphRunFromTextInfo(self.textInfo, features=self.project.textSettings.features, varLocation=self.project.textSettings.varLocation, - colorLayers=self.project.textSettings.enableColor) + colorLayers=self.project.textSettings.enableColor, + shaper=self.project.textSettings.shaper) stderr = stderr.getvalue() if stderr: fontItem.writeCompileOutput(stderr) @@ -934,6 +945,11 @@ def languagesPopupCallback(self, sender): self.project.textSettings.language = tag self.textEntryChangedCallback(self.textEntry, updateCharacterList=False) + @objc.python_method + def shaperChangedCallback(self, sender): + self.project.textSettings.shaper = shaperValues[sender.get()] + self.textEntryChangedCallback(self.textEntry, updateCharacterList=True) + @objc.python_method def featuresChanged(self, sender): self.project.textSettings.features = self.featuresGroup.get() diff --git a/Lib/fontgoggles/misc/hbShape.py b/Lib/fontgoggles/misc/hbShape.py index 419235eb..e37c0426 100644 --- a/Lib/fontgoggles/misc/hbShape.py +++ b/Lib/fontgoggles/misc/hbShape.py @@ -154,7 +154,7 @@ def getGlyphID(self, glyphName, default=0): return default def shape(self, text, *, features=None, varLocation=None, - direction=None, language=None, script=None): + direction=None, language=None, script=None, shaper="ot"): if features is None: features = {} if varLocation is None: @@ -178,7 +178,7 @@ def shape(self, text, *, features=None, varLocation=None, if script is not None: buf.set_script_from_ot_tag(script) - hb.shape(self.font, buf, features) + hb.shape(self.font, buf, features, shapers=[shaper]) glyphOrder = self.glyphOrder infos = [] diff --git a/Lib/fontgoggles/project.py b/Lib/fontgoggles/project.py index 1e0ca8de..e3e6724d 100644 --- a/Lib/fontgoggles/project.py +++ b/Lib/fontgoggles/project.py @@ -208,6 +208,7 @@ class TextSettings: relativeVBaseline: float = 0.5 relativeMargin: float = 0.1 enableColor: bool = True + shaper: str = "ot" @dataclass