Skip to main content
Ka-Tja
Community Expert
Community Expert
February 24, 2021
Answered

How to find the top left point of tilted area text

  • February 24, 2021
  • 4 replies
  • 1198 views

Hello, I hope somebody can help 🙂
How can I define the top-left point in a TextType.AREATEXT, when it's tilted?

This topic has been closed for replies.
Correct answer CarlosCanto

the bounding box of an area text item is actually a pathItem, you can query any of their anchors position. 

Anchor[0] is not always the top/left most anchor though, it depends on how the area text was drawn. It's not always clockwise either. So any of the four anchors could be the one you're looking for.

one way to find out the top/left anchor even if it is upside down is to convert a copy of the item to PointText, then find out it's anchor position and compare to the corner anchors for proximity.

 

var idoc = app.activeDocument;
var sel = idoc.selection[0];

var points = sel.textPath.pathPoints;

for (var a=0; a<points.length; a++) {
    alert(points[a].anchor);
}

 

4 replies

femkeblanco
Legend
February 24, 2021

 

// calculate angle of rotation
var x = Math.acos( activeDocument.selection[0].matrix.mValueA ) / Math.PI  *  180;
if (activeDocument.selection[0].matrix.mValueB < 0) {
    x = x * (-1);
}
var points = [];
for (var i = 0; i < selection[0].textPath.pathPoints.length; i++) {
    points.push(selection[0].textPath.pathPoints[i]);
}
// depending on angle, point sought is either top-most, left-most, bottom-most or right-most
if (x > 0 && x <= 90) {
    points.sort(function(a, b) {return a.anchor[0] - b.anchor[0];})
} else if (x > 90 && x <= 180) {
    points.sort(function(a, b) {return a.anchor[1] - b.anchor[1];})
} else if (x > -180 && x <= -90) {
    points.sort(function(a, b) {return b.anchor[0] - a.anchor[0];})
} else {
    points.sort(function(a, b) {return b.anchor[1] - a.anchor[1];})
}
alert( points[0].anchor );

 

Ka-Tja
Community Expert
Ka-TjaCommunity ExpertAuthor
Community Expert
February 25, 2021

Thank you, it also can work, but I think, that Carlos have the easier solution to my issue 🙂

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
February 24, 2021

the bounding box of an area text item is actually a pathItem, you can query any of their anchors position. 

Anchor[0] is not always the top/left most anchor though, it depends on how the area text was drawn. It's not always clockwise either. So any of the four anchors could be the one you're looking for.

one way to find out the top/left anchor even if it is upside down is to convert a copy of the item to PointText, then find out it's anchor position and compare to the corner anchors for proximity.

 

var idoc = app.activeDocument;
var sel = idoc.selection[0];

var points = sel.textPath.pathPoints;

for (var a=0; a<points.length; a++) {
    alert(points[a].anchor);
}

 

Silly-V
Legend
February 24, 2021

💡

Silly-V
Legend
February 24, 2021

The images and area texts get a special 'tag' put on them by Illustrator when certain rotation methods are used.

 

When the item is rotated using the Rotate tool or rotate tool via menu-item (Transform > Scale, etc), the tag called "BBAccumRotation" is added with a value which you can use to calculate the point and know which one (top, bottom..) it is.
You can get this information using these scripting commands:

#target illustrator
function test () {
	/** @TyPe {Document} */
	var doc = app.activeDocument;
	/** @TyPe {TextFrame} */
	var s = doc.selection[0];
	var tags = s.tags;
	var tagName = tags[0].name;
	var tagValue = tags[0].value;
	alert("Name: " + tagName + "\nValue: " + tagValue);
};
test();

 

 

Note that an area type box which is rotated using the bounding box handles does not produce such a tag and all the text inside maintains its orientation.

 

The UI you see here with Tag Name and Value is a ScriptUI dialog I made which uses the same functions as in the example, but it writes them out in a list.

Ka-Tja
Community Expert
Ka-TjaCommunity ExpertAuthor
Community Expert
February 24, 2021

Thank you, Vasily,  I believe it can work 🙂

Charu Rajput
Community Expert
Community Expert
February 24, 2021

Hi,

You can use geometricBounds property to get to top-left coordinate. Select the object and run the following snippet

 

var a = app.selection[0];
var _geometricBounds = a.geometricBounds;
alert(_geometricBounds);
alert("Top -> " + _geometricBounds[0]);
alert("Left -> " + _geometricBounds[1]);

 

Best regards
Ka-Tja
Community Expert
Ka-TjaCommunity ExpertAuthor
Community Expert
February 24, 2021

Thanks, Charu,  I already tried it, but when a text is tiled, than geometricBounds are Bounding Box Bounds