The following examples detail the use of text in OmniGraffle documents.
Overlaid Image Caption
By default, graphics have an overlaid text layer than is vertically centered in the middle of the bounding box of the graphic (see left image). You can use the standard text properties to manipulate this text area and to alter the properties of the containing text. The following script is useful as an action for quickly setting up entered or pasted text as an overlaid caption (see right image). Simply select the graphic and run the script.
if (document.windows[0].selection.graphics.length != 1){
title = "SELECTION ERROR"
message = "Please select a single graphic."
new Alert(title, message).show(function(result){})
} else {
cnvs = document.windows[0].selection.canvas
graphic = document.windows[0].selection.graphics[0]
if (graphic.image instanceof ImageReference){
var alert = new Alert("TEXT COLOR", "Should the text be colored white or black?")
alert.addOption("White")
alert.addOption("Black")
alert.addOption("Cancel")
alert.show(function(result){
if (result == 0){
chosenColor = Color.white
} else if (result == 1){
chosenColor = Color.black
} else {
throw new Error('script cancelled')
}
graphic.textVerticalPlacement = VerticalTextPlacement.Bottom
graphic.textHorizontalPadding = 24
graphic.textVerticalPadding = 24
graphic.textHorizontalAlignment = HorizontalTextAlignment.Left
graphic.fontName = 'Helvetica'
graphic.textSize = 18
graphic.textColor = chosenColor
})
} else {
title = "NO IMAGE"
message = "The graphic does not contain an image."
new Alert(title, message).show(function(result){})
}
}
message = "The graphic does not contain an image."
32
newAlert(title, message).show(function(result){})
33
}
34
}
You can alter the previous example script to include the ability to extract the notes of the image and use them as the caption by adding this line to the processing code:
/*{
"type": "action",
"targets": ["omnigraffle"],
"author": "Otto Automator",
"identifier": "com.omni-automation.overlay-image-notes",
"description": "This action will set the text of the selected image graphic to the notes of the graphic.",
"label": "Overlay Graphic Notes",
"shortLabel": "Overlay Notes"
}*/
var _ = function(){
var action = new PlugIn.Action(function(selection, sender){
// action code
// selection options: canvas, document, graphics, lines, solids, view
var graphic = selection.graphics[0]
var alert = new Alert("TEXT COLOR", "Should the text be colored white or black?")
alert.addOption("White")
alert.addOption("Black")
alert.addOption("Cancel")
alert.show(function(result){
if (result == 0){
chosenColor = Color.white
} else if (result == 1){
chosenColor = Color.black
} else {
throw new Error('script cancelled')
}
graphic.text = graphic.notes
graphic.textVerticalPlacement = VerticalTextPlacement.Bottom
graphic.textHorizontalPadding = 24
graphic.textVerticalPadding = 24
graphic.textHorizontalAlignment = HorizontalTextAlignment.Left
graphic.fontName = 'Helvetica'
graphic.textSize = 18
graphic.textColor = chosenColor
})
});
action.validate = function(selection, sender){
// validation code
// selection options: canvas, document, graphics, lines, solids, view
if(selection.graphics.length === 1){
if (selection.graphics[0].image instanceof ImageReference){
return true
} else {
return false
}
} else {
return false
}
};
return action;
}();
_;
if (selection.graphics[0].imageinstanceofImageReference){
43
returntrue
44
} else {
45
returnfalse
46
}
47
} else {
48
returnfalse
49
}
50
};
51
52
returnaction;
53
}();
54
_;
Size Text to Fit Shape
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
function fitTextFontToShapeSize(solid){
// store the current geometry of the shape
var startRect = solid.geometry
// examine autosizing property of solid
var startingSizing = solid.autosizing
if (startingSizing == TextAutosizing.Full || startingSizing == TextAutosizing.Vertical) {
return // already autosizing, so already fitting
}
// set the font size parameters
var lowest = 5 // min font size to use
var highest = 100 // max font size to use
// enable vertical autosizing
solid.autosizing = TextAutosizing.Vertical
// adjust the size of the solid until the height or width matches the stored geometry
while ((highest - lowest) > 1) {
if ((solid.geometry.width > startRect.width) || (solid.geometry.height > startRect.height)) {
highest = solid.textSize
} else {
lowest = solid.textSize
}
solid.textSize = lowest + Math.floor((highest - lowest) / 2)
}
// restore the original geometry and autosizing
solid.autosizing = startingSizing
solid.geometry = startRect
}
if (document.windows[0].selection.solids.length != 1){
title = "SELECTION ERROR"
message = "Please select a single solid."
new Alert(title, message).show(function(result){})
} else {
cnvs = document.windows[0].selection.canvas
shape = document.windows[0].selection.solids[0]
fitTextFontToShapeSize(shape)
}
if (document.windows[0].selection.solids.length != 1){
title = "SELECTION ERROR"
message = "Please select a single solid."
new Alert(title, message).show(function(result){})
} else {
cnvs = document.windows[0].selection.canvas
shape = document.windows[0].selection.solids[0]
fitTextFontToShapeSize(shape)
}
if (document.windows[0].selection.solids.length != 1){
28
title = "SELECTION ERROR"
29
message = "Please select a single solid."
30
newAlert(title, message).show(function(result){})
31
} else {
32
cnvs = document.windows[0].selection.canvas
33
shape = document.windows[0].selection.solids[0]
34
fitTextFontToShapeSize(shape)
35
}
The Basic Business Letter
OmniGraffle is an incredibly versatile application. It can be used for diagraming, charting, and other forms of data visualization. But it can also be used for basic text processing as well, with complete type control and spell checking!
Here’s a script that will convert the current canvas into a basic business letter, following conventions outlined by the Purdue Online Writing Lab.