Get the position and width of each textFrame line

Hello!

I have a file of a designer with a layout of text that has a block of copy centered with lots of kerning adjustments and line breaks. I want to loop through the lines and find the position of Center, left and top (in pixels) of each line of the textFrame. Is there a way to do this in JS?

Thank you!

-kc

Hmm, try this script and see if it works.

#target illustrator

function test(){
  function newCMYKColor(arr){
      var c = new CMYKColor();
      c.cyan = arr[0];
      c.magenta = arr[1];
      c.yellow = arr[2];
      c.black = arr[3];
      return c;
  }
  function marker(xy, clr){
      var doc = app.activeDocument;
      var p = doc.pathItems.ellipse(xy[1] + 2, xy[0] - 2, 4, 4);
      p.stroked = false;
      p.filled = true;
      p.fillColor = clr || newCMYKColor([0,100,100,0]);
      return p;
  }
  function gridize(pageItems, buffer){
      var tempArr;
      tempArr = pageItems.slice(0).sort(function(a,b){return b.top - a.top;});
      var buffer = buffer || 10;
      /* buffer is the max variance expected between separate rows */
      var vBnds = [];
      for(var i=0; i-1; j--){
              if(temp[j][1] + buffer >= currentRowYMarker[1] && temp[j][1] - buffer <= currentRowYMarker[1]){
                  currentRowY.push(temp[j]);
                  temp.splice(j,1);
              }
          }
          if(currentRowY.length > 0){
              sortedVBnds.push(currentRowY.sort(function(a,b){return a[0] - b[0];}));
          }
      }
      sortedVBnds.sort(function(a,b){return b[0][1] - a[0][1];});
      return sortedVBnds;
  }
  function getRowTop(row){
      var num = 0;
      for (var i = 0; i < row.length; i++) {
          var vb = row[i];
          var top = vb[1];
          if(top > num){
              num = top;
          }
      };
      return num;
  }
  function getRowBottom(row){
      var num = row[0][3];
      for (var i = 0; i < row.length; i++) {
          var vb = row[i];
          var btm = vb[3];
          if(btm < num){
              num = btm;
          }
      };
      return num;
  }
  function getRowRight(row){
      var num = row[0][2];
      for (var i = 0; i < row.length; i++) {
          var vb = row[i];
          var right = vb[2];
          if(right > num){
              num = right;
          }
      };
      return num;
  }
  function getRowBounds(row){
      var arr = [];
      var left = row[0][0];
      var right = getRowRight(row);
      var top = getRowTop(row);
      var bottom = getRowBottom(row);

      return [left, top, right, bottom];
  }
  function getRowCenter(rowBounds){
  var r = rowBounds;
  return [r[0] + ((r[2] - r[0]) / 2) , r[3] - ((r[3] - r[1]) / 2)];
  }

//================================================== MAIN =================================================//
  if(app.documents.length > 0){
  var doc = app.activeDocument;
  doc.rulerOrigin = [0,0];
  if(doc.selection.length > 0 && doc.selection[0].typename == "TextFrame"){
  var s = doc.selection[0];
  var dupeText = s.duplicate(s, ElementPlacement.PLACEAFTER);
  var dupeTextOutlines = dupeText.createOutline();
  dupeText = null;
  var myArray = [];
  for (var i = 0; i < dupeTextOutlines.compoundPathItems.length; i++) {
  var thisComp = dupeTextOutlines.compoundPathItems[i];
  myArray.push(thisComp);
  };
  var allLines = gridize(myArray);
  for(var i=0; i 
         

Tags: Illustrator

Similar Questions

  • Get the height and width of an image

    I have therefore some images in my program that I'm loading. These images are much longer than the size of the screen. So I put in a ScrollView. My question is how can I get the height and width of an image. The image.width and image.height doesn't return the correct values.

    //add the image
    private function addImage():Container {
        var sp1:Container = new Container();
        sp1.sizeUnit = SizeUnit.PIXELS;
        sp1.debugColor = 0xFFFFFF;
        sp1.margins = Vector.([1,0,0,0]);
        sp1.align =ContainerAlign.NEAR;
        //sp1.setSize(650, 800);
    
        var myPattern:RegExp = / /g;
        var fileName:String = "./com/swiz/img1.png";
        var icon:Image = new Image();
        icon.setImage(File.applicationDirectory.resolvePath(fileName).url);
        //icon.setPosition(0,0);
        //icon.setSize(320,800);
        sp1.addChild(icon);
        sp1.setSize(650, icon.height);
    
        return sp1;
    }
    

    and my code scrollview is

    //add to the scrollView
    var scroller:ScrollPane = new ScrollPane();
    scroller.width = 650;
    scroller.height = 505;
    scroller.y = 0;
    scroller.addScrollContent(addImage());
    addChild(scroller);
    

    Thanks in advance!

    Hey shethab,

    in order to retrieve the height and width of your image, you must use use the an event listener on your image and check for the Event.COMPLETE event. What is happening because the image you upload is not built, it takes time to load into your application using the setImage() method. and when you check the width height after the setImage method, the image was not loaded and has no height and width to this second. If you use the event listener, you can retrieve the height and width as it was finally loaded.

    Try the following code:

    import flash.events.Event;
    
    //add the image
    private function addImage():Container {
        var sp1:Container = new Container();
        sp1.sizeUnit = SizeUnit.PIXELS;
        sp1.debugColor = 0xFFFFFF;
        sp1.margins = Vector.([1,0,0,0]);
        sp1.align =ContainerAlign.NEAR;
        //sp1.setSize(650, 800);
    
        var myPattern:RegExp = / /g;
        var fileName:String = "./com/swiz/img1.png";
        var icon:Image = new Image();
        icon.setImage(File.applicationDirectory.resolvePath(fileName).url);
        icon.addEventListener(Event.COMPLETE, onImageLoaded);
        //icon.setPosition(0,0);
        //icon.setSize(320,800);
        sp1.addChild(icon);
        sp1.setSize(650, icon.height);
    
        return sp1;
    }
    
    private function onImageLoaded(e:Event):void
    {
        trace("image height: " + e.target.height + " image width: " + e.target.width);
    }
    

    hope that somethings brightened. Good luck!

  • Get the height and width of the jpg or png of bitmap without loading the file

    Is there a way to get the height and width of a bitmap, such as jpg or png file, without loading the complete file of the image first.

    Thank you!

    Hi JamesColeman,

    While you can't get the width and height of the jpg or png without access to the file, you can get this information without access to the entire file. A PNG for example (in raw hex) indicates the width and height of the image it contains. The first 21 bytes contain the file-specific information such as name, etc, but just after the IHDR header 4 bytes indicate the width and the other 4 bytes indicate height. If enough for you to read the first 29 bytes of the PNG to be able to get its dimensions, which, while it still requires access to the file is much easier.

    I have the code to read this information here and if you want to learn more about the specifications you can find information on this site.

    Best wishes

    André

  • get the height and width of the screen in QML?

    How to get the height and width of the screen in QML?

    Please search the forums before you make a new post. This post is still on the first page... http://supportforums.BlackBerry.com/T5/Cascades-development/correct-way-to-get-display-width-height-...

  • Get the length and width of a rectangle

    I use sdo_sam.tiiled_bins in rectangles of bursting into different sections. I need to divide the rectangle along the x axis depending on if there is longer or wider. I checked the documentation and I couldn't find a way to get the length and width of a rectangle encompassing minimum. Is there any built-in feature to get the length and width of a rectangle or do I have to create my own? Database is 11 GR 2.

    Thank you
    Rob

    Rob,

    You can use SDO_GEOM. SDO_MIN_MBR_ORDINATE and SDO_GEOM. SDO_MAX_MBR_ORDINATE to calculate the length and width of a mbr.

    References:

    [SDO_GEOM. SDO_MIN_MBR_ORDINATE | http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_objgeom.htm#i866250]

    [SDO_GEOM. SDO_MAX_MBR_ORDINATE | http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_objgeom.htm#i866249]

    Kind regards
    Noel

  • Get the height and width of the object of a threshold

    Hey guys,.

    I am currently working on the extraction of the human sillouhette. Currently, I am trying to retrieve the height and the width of a human sillhouhette for further analysis. Are there any screws for this? Or if any of you can recommend a method? I really need help. The 2 images below should illustrate what I'm talking about. Note that I have several images (various) to analyze a video.... Help is really appreciated. Thank you.

    Concerning

    This task could be run with IMAQ particle analysis Report.vi.

    Please note that this VI is installed with the Vision Development Module.

  • How to get the height and width of the exact text in TextLayout framework

    Hello fellow developers,.

    I'm starting to work with TLF when there are three different CFC now, I work with unique CFCS with flex 4 and a lot of things are changed as

    I use calculateHeight (), calculateWidth () now these methods are not available.

    If someone knows the replacement of these methods then do let me know.

    Thank you

    If the text exceeds the container, what can happen in a container to scroll where you have to scroll to see some of the text, then returns getContentBounds values are estimated values. It is because we do not want to force the text to recompose all the way at the end of a very long TextFlow in order to return a value. However, if you want to get the exact amount and is not afraid to take the time to redial, call textFlow.flowComposer.composeToPosition (), before calling getContentBounds. This forces all text redial at the end, and then getContentBounds displays the calculated value entirely instead of her estimate.

  • How to get the height and width of the screen of the blackberry device?

    Can someone tellme how to get details of the screen of the blackberry device?

    Display.getWidth () and Display.getHeight ().  If this isn't what you want, let us know.

  • How can I design square wave which has a positive and negative values equal to the other and separated from each other by controlled time or distance

    How can I design square wave which has a positive and negative values equal to the other and separated from each other by controlled time or distance, as indicated in the figure below. and enter this signal in a data acquisition.

    At the time wherever you go for the beautiful diadram, you could have done the vi

    Your DAQ would like a waveform (table of values and dt ak 1/sampling rate)

    If you set the sampling rate you know the length of the array, create a matrix of zeros and set the values of the two amplitudes...

    Because I don't want to connect other duties here are some photos

    And it does have a few drawbacks leaves to be desired in my solution, just think... rounding errors and what might happen if the tables are becoming more...

  • Get the position of the control in the window of the façade

    Hello

    I have the window façade divided with dispatchers on several components. On a glass, I have a button (and an overlay window) I want to move programmatically at run time. I would like to get the position of the button according to the coordinate system of façade, but to my knowledge, no such property exists. I know that I can calculate the position if I calculate the position of each knife (or component) that is between the origin of the façade and the button, but it takes a lot of time if you have many such cases.

    Any ideas are appreciated.

    Andrej

    Try this

  • get the Position of dynamically placed childs

    Hello adobe community

    Maybe someone has had the same problem before... I create children symbols on stage, give the child a x and y startposition and tell them to float left. It works very well.
    but now I would like to get the x and position there of each child object in order to move it to another position. is there a function to get the real coordinates x and y of a symbol on the stage?

    see you soon

    You should use css ('left') and ('top').

    example:

    var elementLeft = sym.$('Ellipse').css ('left');

    var elementTop = sym.$('Ellipse').css ('top');

    Alert ("the ellipse is at" + elementLeft + ' from left to right and ' + elementTop + ' at the top.) ») ;

    She returns the left and top position with regard to the example 234px and 20px. So it you have to use the number as just an integer, you will need to analyze.

    or you can use position():

    var positionT is sym. $('Ellipse') risk () .top;

    Var position = sym. $('Ellipse') risk () .top;

    Alert (positionT + "and" + position);

    This returns integers without the px so no need to analyze.

  • Get the position of the text (inside or outside a nightclub?)

    Hi all

    I use simple Ruby to access the contents of a PDF file. This help PDF Reader of yob of GitHub.

    Now, I've come a long way, but still have a question that remains! How to get the position of a text object (this object area)?

    I read the PDF reference, he told me all sorts of things on the text area, space glyph and user... As English is not my mother tongue, there is a lot to take... I currently have a Community trade mark, a matrix of text and text rendering matrix. I have also all the boxes on the page (media, trim, culture etc..)

    For an Image object, I use the values of e and f CTM as x and y. It works perfectly, but when it comes to text, seems to be missing something...

    Example:

    CTM: Matrix]

    [1, 0, 0].

    [0, -1, 0],

    [-0.0, 640.346, 1]

    ]

    Text matrix = > array]

    [10.0, 0.0, 0].

    [0.0, 10.0, 0].

    [2062769.1732, 42.6732, 1]

    ] == You need to convert the text in user/device space space!

    TRM: Matrix]

    [1000.0, 0.0, 0.0],

    [- 10.0, 0.0, 0.0].

    [2062769.1732, 597.6728, 1.0]

    ]

    I can count the lines and calc a displacement of multipling that number by police in size (e.g. 12 pt), but how can I get the box of you text_object? If I have the box, I can make you whether he fits in a box...

    Please help with what I might hurt, or even better if you can help me to find the position of the text!

    They are NOT the starting point of the text box.   It is the basic position of the pen, taking the place of drawing the text.  The 'box' versus relies on measures of fonts - what you need to get the widths, leader, etc.  There's a picture of this in the ISO 32000-1 standard (section 9.2.4, I think).  In fact, the entire section text will make this clearer.

  • How to find the Maxima and Minima for each column of a 2D array?

    Hello

    I have a 2D chart and I would find the maxima and minima of each column of the 2-D table. Even though I know how to get maxima and minima for the whole picture but don't know how columnwise? Any ideas please?

    Thank you

    Rohit

    Hello

    @Smercurio-What you said is true, I should have shown using automatic indexing enabled which is really excellent choice. I just tried to show in a very simple way.

    Anyway, here's the best way

  • Get the position of Caption Annotation

    Hello

    How can I me caption annotation position?

    Hello

    To get the location of the legend of Annotation in graph coordinates, you must get the which and YPosition of the annotation, and then use ScatterPlot.MapDataPoint to convert these coordinated positions of the device and add the CaptionAlignment.XOffset and none of these two values.  You can then return to graph using InverseMapDataPoint coordinates.

    NickB

    National Instruments

  • How to get the position of a ring in a tree control?

    Okay, this is probably a stupid question, but how can we get the position of a ring within a tree control?  I have a tree with two columns, with rings in the second column.  I can set the position using SetTreeCellRingValueFromIndex(), but how do you get the position once the user has changed the control?  I found the functions GetTreeCellRingIndexFromValue() and GetTreeCellRingValueFromIndex(), but I have not found a way to get the Index or the value of the ring (I'm looking for is the index, but if I can get the value I can from there).  Thanks in advance!

    You can get the value of the cell in the tree of GetTreeCellAttribute (ATTR_LABEL_TEXT). Then, as you noted, you can use GetTreeCellRingIndexFromValue() to get the index.

    I hope this helps.

    -jared

Maybe you are looking for