SOLVED Clipboard content for multiple glyphs



  • Thank you this is much more useful. Now we can access the clipboard content much easier!



  • hello @bahman,

    the latest beta includes the new observers fontOverviewCopy and fontOverviewPaste, please give them a try…

    thanks!


  • admin

    Make you own copy paste:

    copy:

    import AppKit
    import json
    
    # get the pasteboard
    pasteBoard = AppKit.NSPasteboard.generalPasteboard()
    # get the font (maybe check if there is a font)
    font = CurrentFont()
    # create your pasteboard type
    bahmanPasteBoardType = "Bahman.special.copy.paste"
    # collect data
    data = []
    for glyphName in font.selectedGlyphNames:
        glyph = font[glyphName]    
        anchorData = [dict(glyphName=glyph.name, x=anchor.x, y=anchor.y, name=anchor.name) for anchor in glyph.anchors]        
        data.append(anchorData)
    # write it to the pastboard
    pasteBoard.setString_forType_(json.dumps(data), bahmanPasteBoardType)
    

    paste:

    import AppKit
    import json
    # get the pasteboard
    pasteBoard = AppKit.NSPasteboard.generalPasteboard()
    # print out all the availabe types
    print(pasteBoard.types())
    # create your pasteboard type
    bahmanPasteBoardType = "Bahman.special.copy.paste"
    # get the paste board string for type
    data = pasteBoard.stringForType_(bahmanPasteBoardType)
    # its None when there no such paste board type
    if data:
        data = json.loads(data)
        # do something with this data    
    

    good luck!!



  • @frederik Yes, it works, I know! And I'm wondering how RF gets the clipboard content for these multiple glyphs because I'm trying to make a paste special script that only would paste anchors or contours when I use it on selected glyphs. The current behavior replaces the whole glyphs on paste. I guess I'm just gonna wait for those notifications you mentioned. Thank you for your patience.


  • admin

    copy multiple glyphs and pasting in an font overview with the same amount of selected glyphs, already works :) see https://robofont.com/documentation/workspace/font-overview/#actions

    Or am I misreading your request...



  • Thank you, those notifications will help. I wanted to avoid redoing what RF already does. I thought RF already copies multiple glyph contents to the clipboard. Please consider doing this:

    1- Open a font which contains glyphs with outlines.
    2- Select some glyphs and hit CMD-C.
    3- Open an empty font, select similar glyphs (same glyph names) and hit CMD-V.

    Now the glyph contents are also pasted on multiple glyphs. If this data exists and can be accessed easily then I can avoid making it myself.


  • admin

    in the upcoming release and public beta there is a notification when copy pasting in a collection view:

    fontOverviewPaste and fontOverviewCopy which has a key glyphs a list of glyphs.

    would this work?



  • Currently, RF has the following behaviors:

    • cmd-c with single glyph selected: whole glyph (XML) is copied
    • cmd-c with multiple glyphs selected: literal characters are copied (based on Unicode value, if they exist. Otherwise it’s glyph names)
    • cmd-option-c with multiple glyphs selected: glyph names are copied

    Probably you’d need to re-think step 1 of your workflow, to copy RGlyphs (or XMLs) for the current selection. You could assign something like cmd-shift-c?



  • Thank you Frank. It's for a different purpose. I want to make a paste special for multiple glyphs. For example, I have selected multiple glyphs, then hit copy. Then selected another font then hit paste. Now I want to show a window where the user can choose what type of data is pasted in the new font. Anchors, contours, etc. And I want to do it for multiple glyphs not just one glyph.



  • What is the reason for using the OS clipboard in this case – why don’t you just create RGlyphs (and drop them where you need them)?
    If you really need the XML, you could use g.writeGlyphToString().