Last active
August 3, 2023 02:43
-
-
Save ryanbugden/326ba693da025634e8f80c22e4d53eb9 to your computer and use it in GitHub Desktop.
RF start-up scripts for moving SVGs to and from Figma (or other apps) via pasteboard.
This file contains 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
# menuTitle: Accept SVGs from Figma (Start-up script) | |
''' | |
An RF start-up script that allows inbound SVG data from Figma via pasteboard. | |
Should work on simple shapes, might not work for others. | |
Ryan Bugden | |
''' | |
import AppKit | |
from mojo.events import addObserver, removeObserver | |
from fontTools.svgLib.path import SVGPath | |
class AcceptFigmaSVG(): | |
def __init__(self): | |
addObserver(self, "convert_svg", "paste") | |
def convert_svg(self, notification): | |
pasteboard = AppKit.NSPasteboard.generalPasteboard() | |
data = pasteboard.dataForType_(AppKit.NSPasteboardTypeString) | |
text = data.decode() | |
if text[0:4] == "<svg": | |
## Add preceding tag that currently works for RoboFont (doesn't seem to be necessarily with fontTools) | |
# text = '<?xml version="1.0" encoding="UTF-8"?>\n' + text | |
# Paste the new svg content... | |
# Instantiate an empty glyph object, and draw the svg to it. | |
hold_g = RGlyph() | |
pen = hold_g.getPen() | |
svg = SVGPath.fromstring(text, transform=(1, 0, 0, -1, 0, 0)) | |
svg.draw(pen) | |
# Move the glyph to (0,0), and add it to the current glyph | |
CurrentGlyph().appendGlyph(hold_g, offset=(-hold_g.bounds[0], -hold_g.bounds[1])) | |
print("Successfully pasted SVG!") | |
AcceptFigmaSVG() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment