Adobe 0046100128056 Scripting Guide - Page 97
Changing text color, Creating and applying styles
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 97 highlights
CHAPTER 6: Text and Type Formatting Text 97 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): var myColorA, myColorB, myName; //Access the active document and page. var myDocument = app.activeDocument; var myPage = app.activeWindow.activePage; //Create a color. try{ myColorA = myDocument.colors.item("DGC1_664a"); //If the color does not exist, trying to get its name will generate an error. myName = myColorA.name; } catch (myError){ //The color style did not exist, so create it. myColorA = myDocument.colors.add({name:"DGC1_664a", model:ColorModel.process, colorValue:[90, 100, 70, 0]}); } //Create another color. try{ myColorB = myDocument.colors.item("DGC1_664b"); //If the color does not exist, trying to get its name will generate an error. myName = myColorB.name; } catch (myError){ //The color style did not exist, so create it. myColorB = myDocument.colors.add({name:"DGC1_664b", model:ColorModel.process, colorValue:[70, 0, 30, 50]}); } //Create a text frame on the active page. var myTextFrame = myPage.textFrames.add(); //Set the bounds of the text frame. myTextFrame.geometricBounds = myGetBounds(myDocument, myPage); //Enter text in the text frame. myTextFrame.contents = "Text\rColor" var myText = myTextFrame.parentStory.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 = myTextFrame.parentStory.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