10 Replies Latest reply on Jan 29, 2013 10:35 PM by SureshRaji

# Ascent/Descent position of selected character

How can I find that selected character lies in ascender line or descender line?

• ###### 1. Re: Ascent/Descent position of selected character

I would do this like so:

```Main();

function Main() {
var outlines, gb;

if (app.selection.length > 0 && app.selection[0].constructor.name == "Character") {
outlines = app.selection[0].createOutlines(false)[0];
gb = outlines.geometricBounds;
outlines.remove();
alert("Ascender line = " + RoundString(gb[0], 1) + ", Descender  line = " + RoundString(gb[2], 1));
}
0
}

function RoundString(numVal, decimals) {
var retVal = Math.round(numVal * Math.pow(10,decimals)) + "";
retVal = retVal.substring(0,retVal.length-decimals) + "." + retVal.substring(retVal.length-decimals);
return retVal;
}
```
• ###### 2. Re: Ascent/Descent position of selected character

That's not really going to work. For descenders, you need a character that actually has one (i.e. j.) For ascenders, you'd need one that has one of those (i.e. k.)

Harbs

• ###### 3. Re: Ascent/Descent position of selected character

Aha, I see now.

• ###### 4. Re: Ascent/Descent position of selected character

```Main();

function Main() {
var sel, outlines, gb, ascender, descender,
doc = app.activeDocument;

if (app.selection.length > 0 && app.selection[0].constructor.name == "Character") {
sel = app.selection[0];

sel.contents = "k";
outlines = sel.createOutlines(false)[0];
gb = outlines.geometricBounds;
ascender = RoundString(gb[0], 1);
doc.undo();
doc.undo();

sel.contents = "j";
outlines = sel.createOutlines(false)[0];
gb = outlines.geometricBounds;
descender = RoundString(gb[2], 1);
doc.undo();
doc.undo();

alert("Ascender line = " + ascender + ", Descender  line = " + descender);
}
}

function RoundString(numVal, decimals) {
var retVal = Math.round(numVal * Math.pow(10,decimals)) + "";
retVal = retVal.substring(0,retVal.length-decimals) + "." + retVal.substring(retVal.length-decimals);
return retVal;
}
```
• ###### 5. Re: Ascent/Descent position of selected character

Kasyan, why not use ascent and descent values from characters?

http://tomaxxi.com/2010/08/round-selected-text-with-polygon/

--

Marijan (tomaxxi)

http://tomaxxi.com

• ###### 6. Re: Ascent/Descent position of selected character

O-o-o-ops! I didn't think the properties were already there. Thanks for pointing this out.

• ###### 7. Re: Ascent/Descent position of selected character

Why do things the easy way when you can do it the hard way?

FWIW, I once needed the caps height which is not available, and the convert to outlines was the way to go for that...

• ###### 8. Re: Ascent/Descent position of selected character

Hi,

Marijan Tompa wrote:

Kasyan, why not use ascent and descent values from characters?

I am afraid ascent/descent properties won't work in this case... since they are "The maximum ascent/descent of any character in the text".

So "aaa".ascent is same as "dddjjj".ascent even if, i.e., a baseline shift or superscript is used.

But it will change if you change a font or its pointSize.

Agree?

• ###### 9. Re: Ascent/Descent position of selected character

No. Ascent and Descent is a line defined by the font, not a specific character. Of course we don't know what the OP needs to do...

• ###### 10. Re: Ascent/Descent position of selected character

Thanks. I have got the output.