Adobe 65009333 Scripting Guide - Page 38
Formatting text, Setting text defaults
UPC - 883919155852
View all Adobe 65009333 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 38 highlights
Text and Type Formatting text 38 //Shows the correct way to iterate through text. var myDocument = app.documents.add(); var myString = "Paragraph 1.\rDelete this paragraph.\rParagraph 2.\rParagraph 3.\rParagraph 4.\rParagraph 5.\rDelete this paragraph.\rParagraph 6.\r"; var myStory = myDocument.stories.item(0); myStory.contents = myString; //The following for loop will format all of the paragraphs by iterating //backwards through the paragraphs in the story. for(var myParagraphCounter = myStory.paragraphs.length-1; myParagraphCounter >= 0; myParagraphCounter --){ if(myStory.paragraphs.item(myParagraphCounter).words.item(0).contents == "Delete"){ myStory.paragraphs.item(myParagraphCounter).remove(); } else{ myStory.paragraphs.item(myParagraphCounter).pointSize = 24; } } Formatting text In the previous sections of this chapter, we added text to a document and worked with stories and text objects. In this section, we apply formatting to text. All the typesetting capabilities of InCopy are available to scripting. Setting text defaults You can set text defaults for both the application and each document. Text defaults for the application determine the text defaults in all new documents. Text defaults for a document set the formatting of all new text objects in that document. (For the complete script, see TextDefaults.) //Sets the text defaults of the application, which set the default formatting //for all new documents. Existing text frames are unaffected. //Set the measurement units to points. app.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; app.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points; //To set the text formatting defaults for a document, replace "app" //in the following lines with a reference to a document. with(app.textDefaults){ alignToBaseline = true; //Because the font might not be available, it's usually best //to apply the font within a try...catch structure. Fill in the //name of a font on your system. try{ appliedFont = app.fonts.item("Minion Pro"); } catch(e){} //Because the font style might not be available, it's usually best //to apply the font style within a try...catch structure. try{ fontStyle = "Regular"; } catch(e){} //Because the language might not be available, it's usually best //to apply the language within a try...catch structure.