6 Replies Latest reply on Jul 5, 2009 8:08 AM by spacecowboyuk

    Equal height columns, and text frame overflow detection

    spacecowboyuk

      I'm trying to write some Javascript that will shrink a 4 column TextFrame to the minimum height required to fit all the text.

       

       

      while(!bodyTextFrame.overflows) {

           var bounds = bodyTextFrame.geometricBounds;

           bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2] - gridHeight, bounds[3]];

      }

       


       

      var bounds = bodyTextFrame.geometricBounds;

      bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2] + (1 *gridHeight), bounds[3]];

       

       

      We break out of the while loop when the bodyTextFrame has just overflowed, so afterwards we add one more line back, and it shouldn't overflow.

       

      What actually happens is that it overshoots the desired result, making the TextFrame smaller than is necessary, often by about 10 lines.

       

      I've noticed something similar with overflow detection in other situations, such as just after applying a ParagraphStyle to the entire TextFrame. It seems to have a delay in detecting the overflow - like it's issued the command but behind the scenes the UI hasn't refreshed before moving onto the next line. If I come back to the TextFrame in question in a later part of the script it can detect that it has overflowed completely fine.

       

      Is there anything I'm missing here? Can I force it to wait to ensure that the bodyTextFrame has completely refreshed before moving onto the next line/loop?

       

      Thanks a lot!

        • 1. Re: Equal height columns, and text frame overflow detection
          Harbs. Level 6

          Something is odd there. I've never seen what you're describing.

           

          I'd say there's probably something else at play, but you can try 

          (although you might want to put in a clause to prevent an endless loop):

          while(!bodyTextFrame.overflows) {
               var bounds = bodyTextFrame.geometricBounds;
               bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2]  
          - gridHeight, bounds[3]];
          }
          
          while(bodyTextFrame.overflows) {
              var bounds = bodyTextFrame.geometricBounds;
              bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2] +  
          gridHeight, bounds[3]];
          }

           

          Harbs

          • 2. Re: Equal height columns, and text frame overflow detection
            spacecowboyuk Level 1

            Thanks Harbs, I've tried that, and also tried decrementing the height of the TextFrame by 1 instead of gridHeight (which is 11pt in my case). It shrinks until a certain point, then it does one pass of the second while loop, and exits.

             

            The same script in InDesign Desktop (altered slightly to use the currently selected TextFrame) works fine.

             

            A similar problem also occurs after placing XML into a TextFrame and then detecting whether that text has caused an overflow. If I check for the overflow directly after placeXML(), it always returns false, but if I check for the overflow at a later part of the script, it detects it correctly.

             

            It's a bit like there's a delay in calculating whether the text overflows, but it carries on through the script regardless until the overflow property is updated on the TextFrame.

             

            Is there a way of forcing the script to wait until the overflow property has been updated? Or setting the mode of the script to wait for the refresh?

            • 3. Re: Equal height columns, and text frame overflow detection
              Harbs. Level 6

              You can try recompose() although I doubt it'll help...

               

              Does the script behave the same way in ID Desktop?

               

              Harbs

              • 4. Re: Equal height columns, and text frame overflow detection
                spacecowboyuk Level 1

                No, it works perfectly on the desktop! Recompose had no effect. Are there any alternative ways of detecting overflows that I could use? It's driving me slightly mad... Thanks again.

                • 5. Re: Equal height columns, and text frame overflow detection
                  Harbs. Level 6

                  Try determining if it's overflown manually.

                  Something like this...

                  if( ! textFrame.nextTextFrame &&  
                  textFrame 
                  .characters[-1].index<textFrame.parentStory.characters[-1].index){
                  //it's overflown
                  }

                   

                  You're going to need some more error checking, etc. but this general 

                  idea should work.

                   

                  I'd be interested in knowing if it helps...

                   

                  Harbs

                  • 6. Re: Equal height columns, and text frame overflow detection
                    spacecowboyuk Level 1

                    Harbs, it turns out I solved it.

                     

                    It was being caused by a side effect of how my XML was structured. The XML I was applying to the TextFrame contained a number of <p> tags which seemed to confuse the layout engine when assessing the overflows. I ran my XML through a script to replace the tags with &#x2029;(the paragraph separator character) and it works fine now.

                     

                    I'd argue that this is a bug. How should I file a report for Adobe?

                     

                    Thanks a lot for all your help.