Adobe 65009333 Scripting Guide - Page 42

Applying a font, Changing text properties, script fragment

Page 42 highlights

Text and Type Formatting text 42 Applying a font To apply a local font change to a range of text, use the appliedFont property, as shown in the following script fragment (from the ApplyFont tutorial script): //Given a font name "myFontName" and a text object "myText" myText.appliedFont = app.fonts.item(myFontName); You also can apply a font by specifying the font-family name and font style, as shown in the following script fragment: myText.appliedFont = app.fonts.item("Adobe Caslon Pro"); myText.fontStyle = "Semibold Italic"; Changing text properties Text objects in InCopy have literally dozens of properties corresponding to their formatting attributes. Even a single insertion point features properties that affect the formatting of text-up to and including properties of the paragraph containing the insertion point. The SetTextProperties tutorial script shows how to set every property of a text object. A fragment of the script follows: //Shows how to set all read/write properties of a text object. var myDocument = app.documents.add(); var myStory = myDocument.stories.item(0); myStory.contents = "x"; var myTextObject = myStory.characters.item(0); myTextObject.alignToBaseline = false; myTextObject.appliedCharacterStyle = myDocument.characterStyles.item("[None]"); myTextObject.appliedFont = app.fonts.item("Minion ProRegular"); myTextObject.appliedLanguage = app.languagesWithVendors.item("English: USA"); myTextObject.appliedNumberingList = myDocument.numberingLists.item("[Default]"); myTextObject.appliedParagraphStyle = myDocument.paragraphStyles.item("[No Paragraph Style]"); myTextObject.autoLeading = 120; myTextObject.balanceRaggedLines = BalanceLinesStyle.noBalancing; myTextObject.baselineShift = 0; myTextObject.bulletsAlignment = ListAlignment.leftAlign; myTextObject.bulletsAndNumberingListType = ListType.noList; myTextObject.bulletsCharacterStyle = myDocument.characterStyles.item("[None]"); myTextObject.bulletsTextAfter = "^t"; myTextObject.capitalization = Capitalization.normal; myTextObject.composer = "Adobe &Paragraph Composer"; myTextObject.desiredGlyphScaling = 100; myTextObject.desiredLetterSpacing = 0; myTextObject.desiredWordSpacing = 100; myTextObject.dropCapCharacters = 0; myTextObject.dropCapLines = 0; myTextObject.dropCapStyle = myDocument.characterStyles.item("[None]"); myTextObject.dropcapDetail = 0; //More text properties in the tutorial script.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

Text and Type
Formatting text
42
Applying a font
To apply a local font change to a range of text, use the
appliedFont
property, as shown in the following
script fragment (from the ApplyFont tutorial script):
//Given a font name "myFontName" and a text object "myText"
myText.appliedFont = app.fonts.item(myFontName);
You also can apply a font by specifying the font-family name and font style, as shown in the following
script fragment:
myText.appliedFont = app.fonts.item("Adobe Caslon Pro");
myText.fontStyle = "Semibold Italic";
Changing text properties
Text objects in InCopy have literally dozens of properties corresponding to their formatting attributes.
Even a single insertion point features properties that affect the formatting of text—up to and including
properties of the paragraph containing the insertion point. The SetTextProperties tutorial script shows
how to set every property of a text object. A fragment of the script follows:
//Shows how to set all read/write properties of a text object.
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "x";
var myTextObject = myStory.characters.item(0);
myTextObject.alignToBaseline = false;
myTextObject.appliedCharacterStyle = myDocument.characterStyles.item("[None]");
myTextObject.appliedFont = app.fonts.item("Minion ProRegular");
myTextObject.appliedLanguage = app.languagesWithVendors.item("English: USA");
myTextObject.appliedNumberingList = myDocument.numberingLists.item("[Default]");
myTextObject.appliedParagraphStyle = myDocument.paragraphStyles.item("[No Paragraph
Style]");
myTextObject.autoLeading = 120;
myTextObject.balanceRaggedLines = BalanceLinesStyle.noBalancing;
myTextObject.baselineShift = 0;
myTextObject.bulletsAlignment = ListAlignment.leftAlign;
myTextObject.bulletsAndNumberingListType = ListType.noList;
myTextObject.bulletsCharacterStyle = myDocument.characterStyles.item("[None]");
myTextObject.bulletsTextAfter = "^t";
myTextObject.capitalization = Capitalization.normal;
myTextObject.composer = "Adobe &Paragraph Composer";
myTextObject.desiredGlyphScaling = 100;
myTextObject.desiredLetterSpacing = 0;
myTextObject.desiredWordSpacing = 100;
myTextObject.dropCapCharacters = 0;
myTextObject.dropCapLines = 0;
myTextObject.dropCapStyle = myDocument.characterStyles.item("[None]");
myTextObject.dropcapDetail = 0;
//More text properties in the tutorial script.