• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Collecting Fonts For Output

New Here ,
Jul 12, 2013 Jul 12, 2013

Copy link to clipboard

Copied

I've got this bit of code from user moluapple - he was incredibly helpful in getting me started, but isn't going to continue working on this and I was wondering if anyone else would be willing to help further this bit of code.

The code works to collect fonts in an open Illustrator document. The issue I am having is that it only collects one font. Or sometimes it will collect a whole font family. But I haven't been able to get it to collect all of the fonts in the document.

I was hoping someone could put their finger on what I'm doing wrong.

function getUsedFonts (doc){

     var xmlString = new XML(doc.XMPString),

     fontFamily = xmlString.descendants("stFnt:fontFamily"),

     fontFace = xmlString.descendants("stFnt:fontFace"),

     ln = fontFace.length(), i = 0, arr = [];

     for (; i<ln; i++){arr.push(fontFamily + '\t' + fontFace)};

     return arr;

}

alert(getUsedFonts(activeDocument));

function main() {

          var

                    doc = app.activeDocument,

                    docPath = doc.path,

                    arr = getUsedFonts (doc),

                    oFolder = new Folder(docPath + '/DocumentFonts'),

                    btMsg,

                    PackageFonts = function (string, oFolder) {

                              var arr = string.split(','), oPath, oFile, oName, i;

                              for (i=0; i<arr.length; i++){

                                        oPath = app.fonts.itemByName(arr).location;

                                        oFile = File(oPath);

                                        oName = oFolder + '/' + arr.replace ('          ', ' ').replace(' Regular', '') +

                                                  oPath.substring(oPath.lastIndexOf('.'), oPath.length);

                                        oFile.copy(File(oName), true);

                              }

                    };

          oFolder.create();

          btMsg = new BridgeTalk();

          btMsg.target = "indesign";

          btMsg.body = PackageFonts.toSource() + '("' + arr +'", "' + oFolder + '")';

          btMsg.onResult = function (resultMsg) {

                    $.writeln("Result = " + resultMsg.body);

          }

          btMsg.onError = function (errorMsg) {

                    $.writeln("Error = " + errorMsg.body);

          }

          btMsg.send();

}

main();

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2013 Jul 26, 2013

Copy link to clipboard

Copied

LATEST

Woah. You're amazing. This is almost perfect! I'm bowing down to your skillz

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines