Text
Text is a fundamental element of an OmniGraffle document. Most documents contain some amount of text, if only labels for objects and drawings. This section details how to create and manipulate text in an OmniGraffle document.
A Basic Text Container
Here’s an example script that creates a graphic containing text. It uses the addText() method of the Canvas class to create a solid shape with no background, shadow, or border, in which the provided text is placed. Note that the script incorporates many of the text-related properties to define the look of the instance:
addText(textString, graphicOrigin) (Solid) • Create a new shape containing text (with no stroke or shadow) and place it on the first visible layer.
Create a Text Label | ||
01 | cnvs = document.windows[0].selection.canvas | |
02 | textShape = cnvs.addText('HOW NOW BROWN COW',Point.zero) | |
03 | textShape.autosizing = TextAutosizing.Full | |
04 | textShape.fontName = 'MarkerFelt-Wide' | |
05 | textShape.textSize = 36 | |
06 | textShape.textHorizontalAlignment = HorizontalTextAlignment.Center | |
07 | textShape.textVerticalPlacement = VerticalTextPlacement.Middle | |
08 | textShape.textHorizontalPadding = 0 | |
09 | textShape.textVerticalPadding = 0 | |
10 | // adjust position | |
11 | aRect = textShape.geometry | |
12 | aRect.origin = Point.zero | |
13 | textShape.geometry = aRect | |
14 |
TIP: The postion of the text box is indicated by a Point. In the above case, the Point class property of zero was used to indicate the coordinates of {0, 0} on the canvas.
Text-Related Properties
Since the text in an OmniGraffle document is actually text contained within Shapes, the following text-related properties are a subset of properties of the Solid class.
autosizing (TextAutosizing) • Autosizing behavior of the graphic when the text size changes.
fontName (String) • Font of text in this graphic. This is the Font’s “Postscript name”, as displayed in the Font Book application’s Font Info pane on the Mac. Where there are multiple fonts, this returns the first character’s font. Setting this value sets it for all text in the graphic.
text (String) • Text contents of this graphic.
textColor (Color) • Color of the text in this graphic. Where there are multiple colors, this returns the first character’s color. Setting this value sets it for all text in the graphic.
textGeometry (Rect r/o) • Drawing bounds of the text in canvas coordinates.
textHorizontalAlignment (HorizontalTextAlignment) • Alignment of the text in this graphic horizontally. HorizontalTextAlignment.Center, HorizontalTextAlignment.Justify, HorizontalTextAlignment.Left, HorizontalTextAlignment.Right
textHorizontalPadding (Number) • Horizontal padding between the edge of the graphic’s bounds and the edge of the text area where text is drawn.
textRotation (Number) • Rotation of the text.
textRotationIsRelative (boolean) • Whether the text rotation is relative to the existing rotation of the graphic itself, or whether it is constant compared to the canvas.
textSize (Number) • Font size of text in this graphic. Where there are multiple fonts, this returns the first character’s font size. Setting this value sets it for all text in the graphic.
textUnitRect (Rect) • Size and position of the graphics’ text area as a unit square. I.e. The x and y are in terms of proportion of graphic size from the graphic bounds (so 0,0 is the graphic origin, (1,1) originates at the graphic’s lower-righthand corner, and the width and height are the scale of the text area in proportion to the graphic, so (1,1) is the same size as the graphic bounds, (2,2) would be twice as large, etc.
textVerticalPadding (Number) • Vertical padding between the edge of the graphic’s bounds and the edge of the text area where text is drawn.
textVerticalPlacement (VerticalTextPlacement) • Alignment of the text in this graphic vertically. VerticalAlignment.Bottom, VerticalAlignment.Center, VerticalAlignment.Top
Text Autosizing
The TextAutosizing properties are the value for the autosizing property of the Solid class:
TextAutosizing | ||
01 | graphic = document.windows[0].selection.graphics[0] | |
02 | graphic.autosizing = TextAutosizing.Vertical |
Clip (TextAutosizing 3) • Clip.
Full (TextAutosizing 1) • Full.
Overflow (TextAutosizing 0) • Overflow.
Vertical (TextAutosizing 2) • Vertical.
Horizontal Text Alignment
The HorizontalTextAlignment props are the value for the textHorizontalAlignment property of the Solid class:
Horizontal Text Alignment | ||
01 | graphic = document.windows[0].selection.graphics[0] | |
02 | graphic.textHorizontalAlignment = HorizontalTextAlignment.Left |
Center (HorizontalTextAlignment 1) • Centered horizontally.
Justify (HorizontalTextAlignment 3) • Spacing adjusted to fill available horizontal space.
Left (HorizontalTextAlignment 0) • Aligned left.
Right (HorizontalTextAlignment 2) • Aligned right.
Vertical Text Placement
The VerticalTextPlacement props are the value for the textVerticalPlacement property of the Solid class:
Vertical Text Placement | ||
01 | graphic = document.windows[0].selection.graphics[0] | |
02 | graphic.textVerticalPlacement = VerticalTextPlacement.Bottom |
Top (VerticalTextPlacement 0) • Aligned to the top of the shape.
Middle (VerticalTextPlacement 1) • Centered in the vertical middle of the shape.
Bottom (VerticalTextPlacement 2) • Aligned to the bottom of the shape.
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.