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,
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?
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
...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
Copy link to clipboard
Copied
really thanks for the help,
Copy link to clipboard
Copied
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.