Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Font extensions mising

Return to Member Forum

  • Author
    Posts
    • #65850

      I am writing a script for our studio that will automatically save all used fonts into a document fonts folder whenever the document is saved. This way we can be sure that whichever mac a document is opened on, the fonts will always be loaded.

      I have managed to get as far as saving the fonts but they are minus their extension names such as .otf to .ttf so the mac sees them all as text files. I am using the copy method with the “fullName” property. Could anyone please tell me where I am going wrong?

    • #65851

      That string (and most of the others in a Font object) is just the font name as text. These texts are read out of the font *file*, but the filename can be just about *anything*. For example, I have a Stempel Garamond: fontFamily “Stempel Garamond LT”, fontStyleName “Roman”, fullName “Stempel Garamond LT Roman” — but the file itself is called “lt50277.pfb”.

      What you are looking for is ‘location’: https://jongware.mit.edu/idcs6js/pc_Font.html#location (“The full path to the Font”).

      • #65853

        Thanks Jongware, I have used ‘location instead of ‘fullName’ but the fonts are no longer saving. The original code is as follows:

        function copyFontsToFolder(){
        var fonts = [];
        var fontPath = []
        var fontName = []
        for (i=0; i<fontsUsed.length; i++){
        fontPath[i] = (fontsUsed[i].location) + “”;
        fontName[i] = (fontsUsed[i].fullName);
        fonts.push(fontsUsed[i]);
        alert (fonts[i].fullName);
        }
        for (i=0; i<fontsUsed.length; i++){
        File(fontPath[i]).copy (targetPath + “/Document Fonts/” + fontName[i]);
        }
        }

        This works but does not include the extension so the OS does not recognise the filetype.

      • #65855

        That’s exactly the behavior as described for ‘copy’: “Copies this object’s referenced file to the specified target location”. You are using “fontName” as new filename, and the file extension is no part of that. ‘location’ is way better: you get the ORIGINAL file name plus the ORIGINAL extension (your system will fail with ‘weird’ characters in the font name). On the downside, though, is that the ‘location’ also includes the entire path; and you somehow have to get rid of that.

        Try this line (untested, but hopefully you get the idea):

        fontName[i] = File(fontsUsed[i].location).name;

        — it uses a dirty trick to get just the file name, but it should work.

      • #65860

        Thanks Jongware, that’s a huge help and I now have it working.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads