Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow choosing CoreText shaper #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/fontgoggles/font/baseFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion Lib/fontgoggles/mac/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontgoggles/misc/hbShape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = []
Expand Down
1 change: 1 addition & 0 deletions Lib/fontgoggles/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class TextSettings:
relativeVBaseline: float = 0.5
relativeMargin: float = 0.1
enableColor: bool = True
shaper: str = "ot"


@dataclass
Expand Down