6 Replies Latest reply on Apr 28, 2016 5:50 AM by Laubender

    Last insertion point of a line is ignored. Why?

    tusharde Level 1

      I am writing a script that takes a multiline paragraph and scales down the pointSize to fit all the text on one lines that matches the width of the text frame.

       

      Screen Shot 2013-08-27 at 12.33.55 PM.png

       

      Here's how i calculate it.

      - I add up the length of each line to get the total width.

      - calculate the scaling percentage by diving the text frame width with the total width.

      - multiple current point size with pecentage.

       

      Pretty simple stuff.

       

      The issue i am facing is that indesign makes the last character as the last insertion point of each line. IT IGNORES THE SPACE AFTER IT. Which shoul technically be the last inseriton point. So since that space doesnt get calculated, it throw off my entire scaling.

       

      Screen Shot 2013-08-27 at 12.34.09 PM.png

       

      Am i doing something wrong. Any help would be appreciated.

       

      my code:

       

       

      var frameWidth = app.selection[0].geometricBounds[3] - app.selection[0].geometricBounds[1];
      var numOfLines = app.selection[0].lines.length;
      var totalWidth = 0;
      
      
      for (var j = numOfLines - 1; j>-1; j--) {
            if(j == numOfLines-1) {
                  totalWidth = totalWidth + (app.selection[0].lines[j].insertionPoints[-1].horizontalOffset - app.selection[0].lines[j].insertionPoints[0].horizontalOffset);
            } else {
                  totalWidth = totalWidth + (app.selection[0].lines[j].characters[-1].horizontalOffset - app.selection[0].lines[j].characters[0].horizontalOffset);
            }
      }
      
      
      var percentage = frameWidth / totalWidth;
      
      
      app.selection[0].paragraphs[0].pointSize = app.selection[0].paragraphs[0].pointSize * percentage + "pt";
      
      
        • 1. Re: Last insertion point of a line is ignored. Why?
          DaveSofTypefi Level 2

          Use the endHorizontalOffset property instead.

           

          One of the issues with text objects (which can be a blessing or a curse depending on what you happen to want at any particular moment) is a principle I call "The last shall be first." That's because the last insertion point of any particular text object is the same insertion point as the first of the next similar text item.

           

          So, for example,

           

          nextPara = thisPara.insertionPoint[-1].paragraphs[0]

           

          A consequence of this is that the last insertionPoint of a line has two different positions, the end of one line and the start of the next.

           

          Even the UI is confused by this. Click at the end of a story that ends in a paragraph mark and place a graphic. You'll see that the cursor marker stays at the same insertion point, but whereas before placing it is at the left of the line to which you've just added the graphic now it is at the end of the previous line.

           

          This is very weird behavior that has freaked me out for over a decade now.

           

          Dave

          1 person found this helpful
          • 2. Re: Last insertion point of a line is ignored. Why?
            tusharde Level 1

            Amazing. Thank you. That did it. Appreciate your help.

            • 3. Re: Last insertion point of a line is ignored. Why?
              Laubender Adobe Community Professional & MVP

              Hi Dave,

              one should note here, that the position of endHorizontalOffset is calculated wrong, if a word is hyphenated.

              I think, we already had this discussion, but by using endHorizontalOffset and its couner part endBaseline I finally found a reliable way to calculate the position of an endBracket in a textPath:

               

              I temporarily set the justification of the text to Justification.FULLY_JUSTIFIED and did not allow hyphenation.

              Note: The position of endBaseline is very unreliable with a hyphenated word.

               

              As we can see here in this example where I placed the guides in the found and x and y positions endHorizontalOffset and endBaseline were suggesting:

               

              The text at the textPath on top is formatted with FULLY_JUSTIFIED and hyphenation off.
              The three text paths below, that are threaded to a single story are just FULLY_JUSTIFIED:

              CalculatingPositionOf-endBracket-TextOnPath.png

               

              Here a close-up of the situation with the hyphenated words:

               

              CalculatingPositionOf-endBracket-TextOnPath-Hyphenation.png

               

              I still did not find out why the distance of the y positions with the red guide and the green differ so much.

              At least I found a solution for my problem with the endBracket position…

               

              Uwe

              • 4. Re: Last insertion point of a line is ignored. Why?
                Laubender Adobe Community Professional & MVP

                My only explanation for the wrong y positions calculated with endBaseline and hyphenation is, that the insertion point between the "c" and the "h" at the top example was read out. Respectively the insertionPoint between the "u" and the "l" on the path below. Each time one character too soon ( the automatic hyphen ignored at all).

                 

                Uwe

                • 5. Re: Last insertion point of a line is ignored. Why?
                  Laubender Adobe Community Professional & MVP

                  And compared to a text frame, that is rotated, it seems, that text on path has this bug exclusively:

                   

                  endBaseline-WrongPosition-TextFrame-vs-TextOnPath.png

                   

                  Uwe

                  • 6. Re: Last insertion point of a line is ignored. Why?
                    Laubender Adobe Community Professional & MVP

                    And the position of endBaseline does not resemble the y-position of an insertion point in the following case.
                    So my assumption two posts ago was wrong. It's calculation is simply wrong, if text on a path is hyphenated:

                     

                    endBaseline-NotThePositionOfAnInsertionPoint.png

                     

                    Where the magenta line meets the text path there is no insertion point.

                     

                    Uwe