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

Font listing script

Explorer ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Hi,
I would like to list the appearance of fonts in different variations.
I found the script http://kasyan.ho.ua/indesign/font/make_font_catalog.html, which I based on, but it fails.

I wanted to make a sample page the way

xtFrame = doc.spreads[0].textFrames.add
(
    {
        geometricBounds : [12,13,32,126],
        strokeWidth : 0,
        fillColor : "None",
        contents : "Typografie",
        parentStory : 
            {
                justification : Justification.LEFT_ALIGN ,
                pointSize : 60 ,
                //leftIndent : "5 mm" ,
                //rightIndent : "2 mm"
            } ,
    }
);

var textFrame1 = doc.spreads[0].textFrames.add
(
    {
        geometricBounds : [34.925,12.7,68.792000,197.300000],
        strokeWidth : 0,
        fillColor : "None",
        contents : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"\n"+"abcdefghijklmnopqrstuvwxyz"+"\n"+"¿?¡!&@‘’“”«»%*^#$£€¢/()[]{}.,®©",
        parentStory : 
            {
                justification : Justification.FULLY_JUSTIFIED ,
                pointSize : 24 ,
            } ,
    }
);

var textFrame3 = doc.spreads[0].textFrames.add
(
    {
        geometricBounds : [164.198,12.7,176.369000,197.300000],
        strokeWidth : 0,
        fillColor : "None",
        contents : "ÁáČčĎďÉéĚěÍíŇňÓóŘřŠšŤťÚúŮůÝýŽž",
        parentStory : 
            {
                justification : Justification.FULLY_JUSTIFIED ,
                pointSize : 30 ,
            } ,
    }
);


and then create a page with the fonts, that's not working.

Then I don't know if it is possible to load only fonts from a certain folder of uninstalled fonts.
But if it would only run from the ones installed in windows10, that would be fine too.

 

Any advice? Can you point me in the right direction?

Thanks

Jirka

 

TOPICS
Scripting

Views

395

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

correct answers 1 Correct answer

Community Expert , Oct 14, 2022 Oct 14, 2022

Not sure how much scripting you’ve done, but I think constucting text frames for each paragraph will be difficult. Another approach would be running text with paragraph styles applied. This gets a range of application fonts and creates styled running text :

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

//new document preset non facing pages with primary frames
var dp = makeDocPreset("Temp");
dp.properties = {facingPages:false, pageHeight:11, pageWidth:8.5, pageOrientation:P
...

Votes

Translate

Translate
Community Expert ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Hi @jirik79416729 , You can get a collection of fonts available to InDesign, or a collection of fonts used by a document:

 

var doc = app.activeDocument;
var dList = doc.fonts
var aList = app.fonts

alert("This document uses " + dList.length + " fonts.\r There are " + aList.length + " fonts active in InDesign.")


//get the names of fonts available from the InDesign application
for (var i = 0; i < aList.length; i++){
    //$.writeln(aList[i].name)
};

//get the names of fonts used by the active document
for (var j = 0; j < dList.length; j++){
    //$.writeln(dList[j].name)
};

 

Screen Shot 20.png

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
Explorer ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Thank you, simple, but somehow I didn't buy it, that will do.
I didn't find anywhere a simple help/options - e.g. Justification.LEFT_ALIGN etc.

Thanks again

Jirka

 

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
Community Expert ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

You can find the InDesign API here:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

Here are the properties for a story:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Story.html

 

I would think it would be easier to set this up a single story with styled paragraphs for each item rather than creating text frames that need to be aligned.

 

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
Explorer ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Thank you
I was there, but the search didn't find "LEFT_ALIGN".
Otherwise it looks good already, I'm still looking for inserting the sample page "doc.pages.add();"
I'm not English/American, I don't think in English ;-).

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
Community Expert ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Search for paragraph or paragraphStyle—justification is a paragraph property:

 

Screen Shot 21.png

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
Community Expert ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Not sure how much scripting you’ve done, but I think constucting text frames for each paragraph will be difficult. Another approach would be running text with paragraph styles applied. This gets a range of application fonts and creates styled running text :

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

//new document preset non facing pages with primary frames
var dp = makeDocPreset("Temp");
dp.properties = {facingPages:false, pageHeight:11, pageWidth:8.5, pageOrientation:PageOrientation.PORTRAIT, top:72, bottom:110, left:72, right:72, startPageNumber:1, createPrimaryTextFrame:true}

//make the font document
var doc = app.documents.add(true, dp);
//set the text flow preferences so the font text auto flows
doc.textPreferences.properties = {smartTextReflow:true, smartTextReflowSync:true, limitToMasterTextFrames:true, deleteEmptyPages:true};
dp.remove();

//make a swatch color for the head
var hc = makeSwatch(doc, "GGS");
hc.properties = {space:ColorSpace.LAB, colorValue:[45,60,40]}

//paragraph styles for the text
var fn = makeParaStyle(doc, "FontName");
fn.properties = {appliedFont:"Myriad Pro	Book", fillColor:hc, pointSize:16, spaceAfter:4, justification:Justification.LEFT_ALIGN, keepWithPrevious:false, keepWithNext:3};
var uc = makeParaStyle(doc, "UpperCase");
uc.properties = {pointSize:12, justification:Justification.LEFT_ALIGN, keepWithPrevious:true, keepWithNext:2};
var lc = makeParaStyle(doc, "LowerCase");
lc.properties = {pointSize:12,justification:Justification.LEFT_ALIGN, keepWithPrevious:true, keepWithNext:1};
var gl = makeParaStyle(doc, "Glyphs");
gl.properties = {pointSize:12, spaceAfter:24, justification:Justification.LEFT_ALIGN, keepWithPrevious:true, keepWithNext:0};
var sList = [fn, uc, lc, gl];

//list of fonts to get
var aList = app.fonts.itemByRange(500,700).getElements();

//set the text contents
var c = "";
for (var i = 0; i < aList.length; i++){
    c += aList[i].name + "\r" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"\r"+"abcdefghijklmnopqrstuvwxyz"+"\r"+"¿?¡!&@‘’“”«»%*^#$£€¢/()[]{}.,®©"+"\r"
};

//add the text
var ptf = doc.pages[0].textFrames[0].parentStory;
ptf.contents = c;

//apply paragraph styles
var sp = ptf.paragraphs;
var sc = 0;
var fc = -1;
var af;
for (var j = 0; j < sp.length; j++){
    if (getFirst(j)) {
        sc = 0;
        fc++;
        sp[j].appliedParagraphStyle = sList[sc];
        //sp[j].appliedFont = aList[fc];
    }
    sp[j].appliedParagraphStyle = sList[sc++];
    //$.writeln(sc + "   " + sp[j].appliedParagraphStyle.name)
    

    if (sc > 1) {
        sp[j].appliedFont = aList[fc];
    } 
};   


/**
* Makes a new document preset 
* @ param preset name name 
* @ return the new preset 
*/

function makeDocPreset(n){
    if (app.documentPresets.itemByName(n).isValid) {
        return app.documentPresets.itemByName(n);
    } else {
        return app.documentPresets.add({name:n});
    }
}


/**
* Makes a new named ParagraphStyle 
* @ param the document to add the style to 
* @ param style name 
* @ return the new paragraph style 
*/

function makeParaStyle(d, n){
    if (d.paragraphStyles.itemByName(n).isValid) {
        return d.paragraphStyles.itemByName(n);
    } else {
        return d.paragraphStyles.add({name:n});
    }
}


/**
* Check for first line 
* @ param the number to check 
* @ return true for multiples of 4
* 
*/
function getFirst(n){
    if (n%4 == 0) {
        return true
    } else {
        return false
    }   
}



/**
* Makes a new named Swatch 
* @ param the document to add the color to 
* @ param color name 
* @ return the new swatch 
*/

function makeSwatch(d, n){
    if (d.colors.itemByName(n).isValid) {
        return d.colors.itemByName(n);
    } else {
        return d.colors.add({name:n});
    }
}

 

Sample output:

 

Screen Shot 22.png

 

 

 

 

 

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
Explorer ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

LATEST

Thank you, great.

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