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

Want know applied font family of the signle character not a word.

New Here ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

Hello,
I am trying to know the font family of the single character of the word using InDesign script.

 

ex. "United"
in this "United" word,

  1. the font family of  the "U" is "Calibri"
  2. the font family of the "n" is "Arial", with bold
  3. the font family of the "i" is "sans-serif"

I have tried but, currently, it returns me applied font-family is "Calibri" because the first char of the "United" is "Calibri".

 

my code,

var myDocument = app.activeDocument;
var pages = myDocument.pages
var words = null;
var wordCharacter = null;
$.write(pages)

for (var i = 0; i < pages.length; i++) {
    var myTextFrames = pages.item(i).textFrames
    $.write(myTextFrames)
    $.write(typeof myTextFrames)
    for (var j = 0; j < myTextFrames.length; j++) {

        if (myTextFrames.item(j).previousTextFrame == null) {


            words = myTextFrames.item(j).parentStory.words;

            for (var k = 0; k < words.length; k++) {

                wordCharacter = words.item(k);
                //var res = wordCharacter.split("");
                for (var eachChar = 0; eachChar < wordCharacter.length; eachChar++) {


                    var appliedFontName = wordCharacter.item(eachChar).appliedFont.name;


                    var strFontType = '';

                    strFontType = fontTypeDeterminator(appliedFontName);

                    //Replace Method for replacing char in Document
                    replacer(strFontType);


                } //end of word loop

            } //end of K loop


            //append all the char into word


        } //end of frame loop

    } //end of j loop
} //end of i loop

 


how can I get it?

TOPICS
How to , Scripting

Views

161

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 , Jan 26, 2021 Jan 26, 2021

Hi,

 

I think if you change the line -

 

var appliedFontName = wordCharacter.item(eachChar).appliedFont.name;

 

to

 

var appliedFontName = wordCharacter.characters[eachChar].appliedFont.fullName;

 

That should run correctly, although I have not changed the logic of how it runs, just made sure that it makes it through each character in the words.

 

I am not sure what you methods fontTypeDeterminator and replacer do, but you might be able to simplfy your code by using the everyItem() option, here

...

Votes

Translate

Translate
Community Expert ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

Hi,

 

I think if you change the line -

 

var appliedFontName = wordCharacter.item(eachChar).appliedFont.name;

 

to

 

var appliedFontName = wordCharacter.characters[eachChar].appliedFont.fullName;

 

That should run correctly, although I have not changed the logic of how it runs, just made sure that it makes it through each character in the words.

 

I am not sure what you methods fontTypeDeterminator and replacer do, but you might be able to simplfy your code by using the everyItem() option, here is an example - depending on the complexity of the document it may be easier.

 

var myDocument = app.activeDocument;
var words = myDocument.pages.everyItem().textFrames.everyItem().words.everyItem().getElements();
var wordCharacter = null;
$.write(words)

for (var k = 0; k < words.length; k++) {

    wordCharacter = words[k];
    for (var eachChar = 0; eachChar < wordCharacter.length; eachChar++) {
        var appliedFontName = wordCharacter.characters[eachChar].appliedFont.fullName;
        var strFontType = '';

        strFontType = fontTypeDeterminator(appliedFontName);

        //Replace Method for replacing char in Document
        replacer(strFontType);

    } //end of word loop

} //end of K loop

 

Hope this helps

 

Malcolm

 

 

 

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 ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

really thanks for the help,

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 ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

LATEST

FYI,
I have 80 or more books, that written in Gujarati and Hindi language(Indian language) in different-different fonts. now, I want to convert it into Unicode characters. so, we can use it at the global level.

ex: "ÐâÓÈ" to "ભારત" (this is in the Gujarati language)
If this script will run successfully, this script will save us lots of time otherwise we need to rewrite all books in Unicode.
and also we can translate those books into English or other languages.
have an Idea?
again thanks for the help.

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