Copy link to clipboard
Copied
Hi Everyone,
I am trying to get fontStyle for the characters through scripting by the below code,
but i am getting both 'book' fontStyle and 'Regular' for the different contents. I am using 'adobe caslon pro-regular' font.
I don't know what is wrong with the code or the font, file. Attached files for your reference.
Please help me to sort this issue.
Thanks,
SathishS
How bizarre. When you select the paragraph 'continental railroad . . . land' it shows as Regular.
The Find/Replace Font window doesn't see Caslon Book (it should be listed there in brackets to show it's there but doesn't exist -- existentially challenging but there you are.
And it should show up in the Find/Change dialog (again, in brackets), but it doesn't. But it's there in the document:
ranges = ...
for (i = 0; i < ranges.length; i++) {
$.writeln (ranges[i].appliedFont.name);
}
...
Copy link to clipboard
Copied
FindWhat = '.' will return whole texts and GREP is rather overkill?
If you want to find texts with specific formatting - you can use Text find but you still need to define what formatting you want to find.
I'm not JS guy so can't give you exact code.
Copy link to clipboard
Copied
FindWhat = '.' will return any single character.
Copy link to clipboard
Copied
Not exactly, without anything else - it will return all texts - not single characters - so it would be quicker to just iterate all Stories.
Copy link to clipboard
Copied
It's true that "." finds any single character -- but it's also true that it finds all characters, so your script writes every single character (apart from the paragraph break).
Better to use styleRanges, then write those font style of those ranges.
Copy link to clipboard
Copied
Hi @Peter Kahrel,
Thanks for responding... I am new to the scripting. Could you help me where to implement 'styleRanges' in above code.
-Sathish
Copy link to clipboard
Copied
You'd do something like this:
ranges = app.activeDocument
.stories.everyItem()
.textStyleRanges.everyItem().getElements();
for (i = 0; i < ranges.length; i++) {
if (ranges[i].appliedFont.name === 'Adobe Caslon Pro\tRegular') {
// Do something;
}
}
Copy link to clipboard
Copied
Great piece of code - as always.
But OP needs to remember about one thing - if consecutive pieces of text have the same font, but differ in something else - point size, color, etc. - each piece will be returned as a separate result - which may be a problem, when whole block of text should be processed.
Copy link to clipboard
Copied
True. But you'd have the same problem when looking for .+ and the font name+style.
Copy link to clipboard
Copied
No, you wouldn't:
Copy link to clipboard
Copied
Hi @Peter Kahrel,
Thanks for the Code!!!
As attached indesign file, everything is typeset in 'Adobe Caslon Pro', but when i am trying to evaluate the fontStyle of the characters, it returns 'Regular' fontStyle for second textframe and 'book' for first frame. Even there is no 'Book' fontstyle available in this font 'Adobe Caslon Pro'.
-Sathish
Copy link to clipboard
Copied
But the TextStyleRange can be as small as InsertionPoint - you need to check "type" as well.
Copy link to clipboard
Copied
How bizarre. When you select the paragraph 'continental railroad . . . land' it shows as Regular.
The Find/Replace Font window doesn't see Caslon Book (it should be listed there in brackets to show it's there but doesn't exist -- existentially challenging but there you are.
And it should show up in the Find/Change dialog (again, in brackets), but it doesn't. But it's there in the document:
ranges = ...
for (i = 0; i < ranges.length; i++) {
$.writeln (ranges[i].appliedFont.name);
}
And you can select it (or one of the instances) as follows, if only to show that your eyes don't deceive you:
ranges = ...
for (i = 0; i < ranges.length; i++) {
if (ranges[i].appliedFont.name === 'Adobe Caslon Pro\tBook') {
ranges[i].select();
exit();
}
}
And you can change it as follows:
ranges = ...
for (i = 0; i < ranges.length; i++) {
if (ranges[i].appliedFont.name === 'Adobe Caslon Pro\tBook') {
ranges[i].appliedFont = 'Adobe Caslon Pro\tRegular'
}
}
Maybe some mild corruption. I'd be careful with that document. Perhars it's a good idea to do an IDML roundtrip.
(Edit: Some duplication here, hadn't seen your and Robert's replies when I answered.)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
But after change everything that finds 'Book' to 'Regular', now it all returns as 'Regular' font style. But don't have any clue why it behaves like that.
Copy link to clipboard
Copied
> But don't have any clue why it behaves like that.
It's very strange indeed.
Copy link to clipboard
Copied
That's what I get:
And Find&Change from UI - even with ".*":
Copy link to clipboard
Copied
But as you can see on my 1st screenshot - not highlighted - ",?!." in the 2nd TextFrame have different formatting - Kerning set to "Optical"
Copy link to clipboard
Copied
And here is when combined with GREP Find results - ".*":
First Found - is EXACTLY the same as TextStyleRange and Paragraph - but 2nd Found - highlighted - is a whole 2nd TextFrame - ignores Kerning option.
And from here - there is only one small step to very advanced Text Preflight...