Highlighted

script for creating a text outline and hence find the geometric bound of text

New Here ,
May 30, 2020

Copy link to clipboard

Copied

i want a help in js codde in extendscript to crate a text outline and hence find the geometric bound of text within a text frame

Topics

Scripting

Views

494

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

script for creating a text outline and hence find the geometric bound of text

New Here ,
May 30, 2020

Copy link to clipboard

Copied

i want a help in js codde in extendscript to crate a text outline and hence find the geometric bound of text within a text frame

Topics

Scripting

Views

495

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Guru ,
May 30, 2020

Copy link to clipboard

Copied

Here's an example: a snippet from this script:

sourceText = source.sourceText;  
page = sourceText.parentTextFrames[0].parentPage;  
arr = sourceText.createOutlines(false);  
outlinedText = arr[0];  
gb = outlinedText.geometricBounds;  
outlinedText.remove();              

The text is temporarily converted to outlines to get geometric bounds to build a rectangle of the same size and location as the text.

Hope it helps!

— Kas

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 30, 2020

Copy link to clipboard

Copied

thanks a lot for your answer.but how do i give source .i want to create outline of a text in textframe so how should i initialise my source

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
May 30, 2020

Copy link to clipboard

Copied

Also, if there were some reason you don’t want to convert to outlines, you can use the baseline+ascent or descent to get a word’s Y1 and Y2 coordinate, and the horizontal offset and end horizontal offset to get its X1 & X2 coordinates.

 

This would get the bounds of the selection if it is a word or single line. For multiple lines you could test for the longest line and get the Y2 from the end of that line, and the X2 from the lastline baseline + descent.

 

 

 

var sel = app.selection[0];
$.writeln("Selected Text Bounds: " + getTextBounds(sel));


function getTextBounds(t){
    var y1, x1, y2, x2
    y1 = t.baseline - sel.ascent;
    x1 = t.horizontalOffset
    y2 = t.baseline + sel.descent;
    x2 = t.endHorizontalOffset
    return [y1,x1,y2,x2]
}

Also, 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 30, 2020

Copy link to clipboard

Copied

 

var docRef = app.documents.add();
   with (docRef.documentPreferences) {
      pageHeight = "3 in";
      pageWidth = "2 in";
      pagesPerDocument = 1;
      facingPages=false;
   }
   var pageRef = docRef.pages.item(0);   
      var frameRef = pageRef.textFrames.add();
      frameRef.geometricBounds = myGetBounds(pageRef,docRef);
      frameRef.contents = "hey";
      alert("hello");
      frameRef.contents="vaishuu";
      var sel = app.selection[0];
$.writeln("Selected Text Bounds: " + getTextBounds(sel));

      function getTextBounds(t){
        var y1, x1, y2, x2
        y1 = t.baseline - sel.ascent;
        x1 = t.horizontalOffset
        y2 = t.baseline + sel.descent;
        x2 = t.endHorizontalOffset
        return [y1,x1,y2,x2]
    }
this is giving me error in line y1 = t.baseline - sel.ascent;
Runtime Error:Object does not support the property or method 'baseline'

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
May 30, 2020

Copy link to clipboard

Copied

thanks a lot for helping but have one more doubt as i have posted below

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
rob day LATEST
Adobe Community Professional ,
May 31, 2020

Copy link to clipboard

Copied

The code you posted doesn’t include a selection, so my sel variable is not defined. Also there’s no myGetBounds() function.

 

Try this:

var docRef = app.documents.add();
   with (docRef.documentPreferences) {
      pageHeight = "6 in";
      pageWidth = "6 in";
      pagesPerDocument = 1;
      facingPages=false;
   }
   var pageRef = docRef.pages.item(0);   
      var frameRef = pageRef.textFrames.add();
      frameRef.geometricBounds = [1,1,4,4];
      frameRef.contents = "hey";
      //alert("hello");
      frameRef.contents="vaishuu";
      frameRef.parentStory.texts[0].select();
      var sel = app.selection[0];
       $.writeln("Selected Text Bounds: " + getTextBounds(sel));

      function getTextBounds(t){
        var y1, x1, y2, x2
        y1 = t.baseline - sel.ascent;
        x1 = t.horizontalOffset
        y2 = t.baseline + sel.descent;
        x2 = t.endHorizontalOffset
        return [y1,x1,y2,x2]
    }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
May 30, 2020

Copy link to clipboard

Copied

Using the ascent and descent gets the entire font bounds, so outlining would be better if you needed the visible bounds. My script does this when the selection isn’t mixed case:

 

Screen Shot 10.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...