4 Replies Latest reply on Sep 20, 2010 9:48 PM by csm_phil

    Get line width?

    Pontus Uggla Level 1

      I would like to place a logotype to the right of the first lines text, where the X is:

       

      Lorem ipsum X

      dolor sit amet

       

      Is it posible without copying the text to a box and resize it and check the box size?

        • 1. Re: Get line width?
          [Jongware] Most Valuable Participant

          horizontalOffset is your friend here. Use in conjuction with baseline to get the position of any character:

           

          alert (app.selection[0].insertionPoints[-1].horizontalOffset + " "+app.selection[0].insertionPoints[-1].baseline);
          

           

          (Click the text cursor anywhere in the text to see the result.)

          You can read these properties for any text position "the usual way", i.e., referring to lines, words, and characters:

           

          alert (app.selection[0].paragraphs[0].lines[0].characters[-1].horizontalOffset);

           

          for example.

           

          (I'm omitting Javascript formatting here because man! what's up with those scroll bars!?)

          • 2. Re: Get line width?
            csm_phil Level 4

            Hi Pontus,

             

            i think you expected this, may be like this.

             

            alert ((app.selection[0].insertionPoints[-1].horizontalOffset - app.selection[0].insertionPoints[0].horizontalOffset).toFixed (3));


            regards

            CSM_Phil@};-

             

            • 3. Re: Get line width?
              Harbs. Level 6

              That's not a safe way to do it because the last insertionPoint might be the beginning of the next line...

               

              If you are dealing with r-t-l text it gets much more complicated as well...

               

              You want to use line.characters.item(-1).endHorizontalOffset (as long as it's limited to l-t-r text).

               

              Harbs

              • 4. Re: Get line width?
                csm_phil Level 4

                Hi Harbs,

                 

                Okay i will understand your answers, But i have one doubt i given selection option text only, so the value comes exact i will used this script lines in my jobs its working fine.

                 

                 

                this is ok harbs shall i use this lines. please suggest me.

                 

                alert  ((app.selection[0].characters[-1].horizontalOffset -  app.selection[0].characters[0].horizontalOffset).toFixed (3));

                 

                Regards

                CSM_Phil