Adobe 65009333 Scripting Guide - Page 43
Changing text color, Creating and applying styles, between the formatted text and the style
UPC - 883919155852
View all Adobe 65009333 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 43 highlights
Text and Type Formatting text 43 Changing text color You can apply colors to the fill and stroke of text characters, as shown in the following script fragment (from the TextColors tutorial script): //Given two colors "myColorA" and "myColorB"... var myStory = myDocument.stories.item(0); //Enter text in the text frame. myStory.contents = "Text\rColor" var myText = myStory.paragraphs.item(0) myText.pointSize = 72; myText.justification = Justification.centerAlign; //Apply a color to the fill of the text. myText.fillColor = myColorA; //Use the itemByRange method to apply the color to the stroke of the text. myText.strokeColor = myColorB; var myText = myStory.paragraphs.item(1) myText.strokeWeight = 3; myText.pointSize = 144; myText.justification = Justification.centerAlign; myText.fillColor = myColorB; myText.strokeColor = myColorA; myText.strokeWeight = 3; Creating and applying styles While you can use scripting to apply local formatting-as in some of the examples earlier in this chapter- you probably will want to use character and paragraph styles to format your text. Using styles creates a link between the formatted text and the style, which makes it easier to redefine the style, collect the text formatted with a given style, or find and/or change the text. Paragraph and character styles are key to text-formatting productivity and should be a central part of any script that applies text formatting. The following script fragment shows how to create and apply paragraph and character styles (for the complete script, see CreateStyles): //Shows how to create and apply a paragraph style and a character style. var myParagraphStyle, myCharacterStyle, myColor, myName; //Create an example document. var myDocument = app.documents.add(); //Create a color for use by one of the paragraph styles we'll create. try{ myColor = myDocument.colors.item("Red"); //If the color does not exist, trying to get its name generates an error. myName = myColor.name; } catch (myError){ //The color style did not exist, so create it. myColor = myDocument.colors.add({name:"Red", model:ColorModel.process, colorValue:[0, 100, 100, 0]}); } var myStory = myDocument.stories.item(0); //Fill the text frame with placeholder text. myStory.textContainers[0].contents = "Normal text. Text with a character style applied to it. More normal text."; //Create a character style named "myCharacterStyle" if //no style by that name already exists.