Last active
October 25, 2021 07:13
-
-
Save arialcrime/67e09fd5b392520fc6a0050fd73cf6cd to your computer and use it in GitHub Desktop.
Paints the background of the glyph window when you are not in the foreground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber, unregisterGlyphEditorSubscriber | |
| class ShowLayerColorInBackground(Subscriber): | |
| debug = True | |
| def build(self): | |
| glyphEditor = self.getGlyphEditor() | |
| container = glyphEditor.extensionContainer( | |
| identifier="com.arialcrime.ShowLayerColorInBackground", | |
| location="background", | |
| clear=True | |
| ) | |
| self.backgroundLayer = container.appendRectangleSublayer( | |
| opacity=0.55, | |
| visible=False | |
| ) | |
| def roboFontDidSwitchCurrentGlyph(self, info): | |
| g = info["glyph"] | |
| if g is not None: | |
| font = g.font | |
| layer = g.layer | |
| with self.backgroundLayer.propertyGroup(): | |
| self.backgroundLayer.addSkewTransformation(-(font.info.italicAngle or 0)) | |
| self.backgroundLayer.setPosition((font.lib.get("com.typemytype.robofont.italicSlantOffset", 0), font.info.descender)) | |
| self.backgroundLayer.setSize((g.width, font.info.unitsPerEm)) | |
| self.backgroundLayer.setFillColor(g.layer.color) | |
| self.backgroundLayer.setVisible(g.font.defaultLayer != g.layer) | |
| def glyphEditorLayerDidChangeColor(self, info): | |
| layer = info["layer"] | |
| self.backgroundLayer.setBackgroundColor(layer.color) | |
| def glyphEditorGlyphDidChangeMetrics(self, info): | |
| g = info["glyph"] | |
| font = g.font | |
| self.backgroundLayer.setSize((g.width, font.info.unitsPerEm)) | |
| registerGlyphEditorSubscriber(ShowLayerColorInBackground) |
Author
Oh wow, thanks for the edits. That is indeed much cleaner. ๐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dont check default layer by its order in the
glyph.layerssome adjustments, mainly to make a lot easier :)