-
1. Re: CS3 JS fonts example script
Dave Saunders May 19, 2009 7:28 PM (in response to John.Kordas)It looks like myString is a JavaScript string. That means it doesn't have an appliedFont property.
But JavaScript lets you add a property in just the way you're doing except that the meaning of the property is completely arbitrary and not something that gets carried into the text when you set the story contents.
You need to use appliedFont in relation to text in the document not strings in JavaScript space.
Dave
-
2. Re: CS3 JS fonts example script
John.Kordas May 19, 2009 7:34 PM (in response to Dave Saunders)Hi Dave,
Hope you are well. Could I do a search for text then change the character style of that text?
Something like:
app.findTextPreferences.findWhat = "911 Porscha Regular";
var myTextChange = app.documents.item(0).findText();
myTextChange.appliedFont = app.fonts.itemByName(myFontNames[0]);
Cheers, John.
-
3. Re: CS3 JS fonts example script
Dave Saunders May 19, 2009 7:54 PM (in response to John.Kordas)Something like that. But don't forget that a search returns an array, even if there's only one hit.
Dave
-
4. Re: CS3 JS fonts example script
John.Kordas May 19, 2009 8:30 PM (in response to Dave Saunders)I was trying
app.findTextPreferences.findWhat = "911 Porscha Regular";
var myTextChange = app.documents.item(0).findText();
$.write (myTextChange.length)myTextChange.appliedFont = app.fonts.itemByName(myFontNames[0]);
And the console was returning 1 which did not make scene untill I tried:
$.write (myTextChange.constructor.name) which rerturned Array.
Then I used
$.write (myTextChange[0].length) which returns 19 but how do I return the value because myTextChange[0].value or .name does not work.
Cheers John.
-
5. Re: CS3 JS fonts example script
Dave Saunders May 19, 2009 8:40 PM (in response to John.Kordas)What value? You mean the contents of the text?
Remember, the result of a find is an array of text references.
So, when you asked for the length of the first found item, it told you there were 19 characters.
Dave
-
6. Re: CS3 JS fonts example script
John.Kordas May 19, 2009 9:00 PM (in response to Dave Saunders)Ok I might be going about this the wrong way.
I ran the FontCollections.jsx which is in the SDK and I get a page with a textFrame and a list of the application fonts. The textFrame uses the default Time Roman typeface. The first font in my list is "911 Porscha Regular"
In my first post I thought that I might be able to apply the font type to each entry but I don't think this will work as it is a string.So is it possible to select the text in the textFrame app.findTextPreferences.findWhat = "911 Porscha Regular"; Then change the type face to match the description?
Can this be done?
John.
I think this might do it myTextChange[0].appliedFont = app.fonts.itemByName(myFontNames[0]);
Message was edited by: John Kordas
-
7. Re: CS3 JS fonts example script
John.Kordas May 20, 2009 7:00 AM (in response to John.Kordas)I found a slight problem with some fonts. I'm get an error undefined is not an object. I've also worked out that if I use myTextChange[0].contents the font name will be returned in the instance it is a problem font myTextChange[0].contents does not return anything I just get the error message.
Is there a way to skip the loop so if it can not determine the contents just go the the next count?
For example I've tried
for (myCounter = 0; myCounter < myFontNames.length; myCounter++) {
app.findTextPreferences.findWhat = myFontNames[myCounter];
var myTextChange = app.documents.item(0).findText();if(myTextChange[0].contents == null)
continuemyTextChange[0].appliedFont = app.fonts.itemByName(myFontNames[myCounter]);
but it's not working.
-
8. Re: CS3 JS fonts example script
Dave Saunders May 20, 2009 7:12 AM (in response to John.Kordas)John,
You're assuming by referring to myTextChange[0] that you always get a hit. Chances are that the error is indicating that nothing was found.
Dave
-
9. Re: CS3 JS fonts example script
John.Kordas May 20, 2009 7:22 AM (in response to Dave Saunders)Thanks once again Dave,
the answer was
if(myTextChange[0] != null){
myTextChange[0].appliedFont = app.fonts.itemByName(myFontNames[myCounter]);
}Much appreciated.
Cheers John.
-
10. Re: CS3 JS fonts example script
John.Kordas May 20, 2009 7:56 PM (in response to John.Kordas)Some of the fonts being display in the document are showing up as squares and highlighted pink. I'm gathering that this is because the font does not have any character's for that letter being displayed. I have noticed that I can select the text and right click to select Clear All Overrides which will show the name of the font in the default document text.
Would I be able to script this process?
Select any text that is flagged/highlighted and Clear All Overrides and then change the text color to red.
Cheers, John.
-
11. Re: CS3 JS fonts example script
Dave Saunders May 20, 2009 8:08 PM (in response to John.Kordas)John,
Look in the Object Model Viewer for Text object methods.
Dave
-
12. Re: CS3 JS fonts example script
John.Kordas May 20, 2009 8:20 PM (in response to Dave Saunders)Hi Dave,
Working my way through I found clearOverrides() under the TextStyleRange classes but I'm not sure how I would first check for it.
Is there a way to check the font first before the font is substituted and highlighted?Should I run the appliedFont process and then look for fonts substituted?
John
-
13. Re: CS3 JS fonts example script
John.Kordas May 20, 2009 11:27 PM (in response to John.Kordas)I realized I was going about it the wrong way. I needed to go back to the beginning.
So using:
var myApplicationFonts = app.fonts;
var myFontNames = myApplicationFonts.everyItem().nameI will get an array of all the fonts. If I use myApplicationFonts.itemByName("font name here") I can access font details.
I'm working through the Font class but have not found any method to check the characters
$.write (myApplicationFonts.itemByName(myFontNames[631]).version)
Is there a way to check if the font has a full set of characters?
Cheers, John.
-
14. Re: CS3 JS fonts example script
Dave Saunders May 21, 2009 4:04 AM (in response to John.Kordas)>Is there a way to check if the font has a full set of characters?
Only very slow, convoluted ways. For example, iterate through all possible unicodes and attempt to convert the character to outlines. If successful, there is a character at that code. If not, there isn't.
Dave
-
15. Re: CS3 JS fonts example script
John.Kordas May 21, 2009 7:17 AM (in response to Dave Saunders)Are there any examples of how to iterate through all possible unicodes?
The font that does not seem to display correctly is Estrangelo Edessa Regular I've opened the Glyphs panel in InDesign and the font looks fine but in the textFrame in my document it's just showing squares and highlighted in pink.
John.
-
16. Re: CS3 JS fonts example script
Dave Saunders May 21, 2009 8:18 AM (in response to John.Kordas)What's the largest unicode? Is it 65535? If so:
for (var j = 0; 65536 > j; j++) {
will do it. Although you might want to start with j = 32.
But that's going to take a long time and come up empty way more often than otherwise.
Look at the text in the text frame with the Info box. Note the unicode values.
Now place some glyphs from the font into the frame using the Glyphs panel. Look at those unicodes.
Sounds like this font has a different encoding from the norm.
Dave
-
-
18. Re: CS3 JS fonts example script
Harbs. May 21, 2009 1:56 PM (in response to sstanleyau)Shane,
Your message was blank...
Harbs
-
19. Re: CS3 JS fonts example script
sstanleyau May 21, 2009 2:01 PM (in response to Harbs.)Thanks, Harbs -- foru software strikes again. Let me try here:
> What's the largest unicode? Is it 65535?
No. From a Unicode FAQ: "The Unicode Standard encodes characters in the range U+0000..U+10FFFF, which is roughly a 21-bit code space." Keep that repeat running :-)
-
20. Re: CS3 JS fonts example script
John.Kordas May 22, 2009 6:48 AM (in response to sstanleyau)I've expanded the list to include the A-Z characters. I can select the font type line using
myTextChange[0].lines.item(0).select()
but the characters are on the next line and using
myTextChange[0].lines.nextItem(0).select()
does not work. I've looked at the properties for nextItem(obj) but not sure what the Assigned Story (obj) is.
John
-
21. Re: CS3 JS fonts example script
Dave Saunders May 22, 2009 7:11 AM (in response to John.Kordas)The nextItem() method requires an object. You need something like:
var myStory = app.selection[0].parentStory;
var myLine = myStory.lines[0];
var nextLine = myStory.lines.nextItem(myLine).select();Dave
-
22. Re: CS3 JS fonts example script
John.Kordas May 22, 2009 7:38 AM (in response to Dave Saunders)Thanks Dave that makes sense now. I also tried this before I saw your example which worked for me in a way.
var chgLetter = myDocument.textFrames.item(0)
chgLetter.parentStory.paragraphs.item(myCounter).appliedFont = app.fonts.itemByName(myFontNames[myCounter]);
For a script that I thought will be simple and should only take a couple of days tops I've hit one problem after another. I can now change the second line which has the A-Z character to the font description on the line above. What I did not count on it that once you change the font style the line length changes so what I was plaining on being on every second line now might be on the 8th and 9th line. I think I'll try paragraphs instead.
Cheers John.




