12 Replies Latest reply on Oct 21, 2010 7:28 PM by Dave Saunders

    Detecting Permanent Overset

    Level 1
      For years, I've used a RunPages function to flow overset text. One thing that such a function must do is detect a permanent overset condition and stop. The test I have in the function is to test to see (a) if the frame is still overset and (b) if the frame contains no characters.

      I don't know why it has taken me this long to realize that this is an inadequate test. A text frame that contains only a part of a long table also has no characters. So, if my function were used to flow a story that contained such a long table it would fail because it would erroneously decide that the story was permanently overset the moment it got to a text frame in the middle of a long table.

      Has anyone else run into this? And if so, did you find a solution?

      I've posted the text of my function before, but I'll put it here again in the first reply for easy reference. I think were I writing it today I'd probably break it down into more function calls but on the principle that it wasn't broke I haven't done that. Only now I realize that it is broke.
        • 1. Re: Detecting Permanent Overset
          Level 1
          Here's the function:
          function runPages(theDoc, theStory) {
            var uRuler = theDoc.viewPreferences.rulerOrigin;
            theDoc.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;
            while (theStory.textContainers[theStory.textContainers.length-1].overflows) {
              theDoc.documentPreferences.pagesPerDocument = theDoc.documentPreferences.pagesPerDocument + 1;
              var backPage = theDoc.pages[-1];
              app.activeWindow.activePage = backPage;
              backPage.appliedMaster = theDoc.pages[-2].appliedMaster;
              var myPbounds = backPage.bounds;
              var myNewTF = backPage.textFrames.add();
              if ((backPage.name % 2 == 1) || (!theDoc.documentPreferences.facingPages)) {
                myNewTF.geometricBounds =
                  [myPbounds[0] + backPage.marginPreferences.top,
                    myPbounds[1] + backPage.marginPreferences.left,
                    myPbounds[2] - backPage.marginPreferences.bottom,
                    myPbounds[3] - backPage.marginPreferences.right];
              } else {
                myNewTF.geometricBounds =
                  [myPbounds[0] + backPage.marginPreferences.top,
                    myPbounds[1] + backPage.marginPreferences.right,
                    myPbounds[2] - backPage.marginPreferences.bottom,
                    myPbounds[3] - backPage.marginPreferences.left];
              myNewTF.itemLayer = theStory.textContainers[theStory.textContainers.length-1].itemLayer;
              myNewTF.previousTextFrame = theStory.textContainers[theStory.textContainers.length-1];
              myNewTF.textFramePreferences.textColumnCount = backPage.marginPreferences.columnCount;
              myNewTF.textFramePreferences.textColumnGutter = backPage.marginPreferences.columnGutter;
              if (myNewTF.characters.length == 0){
                theDoc.viewPreferences.rulerOrigin = uRuler;
                throw ("Permanently overset"); // This indicates a permanent overset condition so break out of loop
            theDoc.viewPreferences.rulerOrigin = uRuler;
          And indeed, it throws the error if you try to use it to run pages for a story that consists (or includes) a table long enough that one frame in the originally overset material consists only of a part of the table.


          • 2. Re: Detecting Permanent Overset
            Level 1
            What I'm hoping for is a mechanism that avoids having to check for the specific causes of permanently overset text. The fact that one of the possible causes is a row of a table that is taller than the text frame would mean having to search through the last non-overset table (the one contained by the character in the parent story of the overset frame whose index matches the index of the one insertion point in the overset frame) to see if that particular condition applies.

            Now I think about it, there's another possibility for a frame with zero characters: This would happen if a paragraph had the Start on Next Even/Odd Page activated.


            Perhaps I should try to forget all this and return to my ignorance is bliss state.

            • 3. Re: Detecting Permanent Overset
              Harbs. Level 6
              Hi Dave,

              Yes. I've dealt with this.

              There's a few of problems here:

              1) Next odd/even page keeps options. You can get an empty frame because
              of that. I require the last two page frames to be empty to make it
              permanently overset.
              2) Continued tables (like you said).
              3) Continued footnotes. The text frame will likewise have no characters
              if a footnote continues and there's no main text. (Yes. It can happen.)

              If have functions to check for all of these. I'll be happy to send them
              to you if you write to me on the private...

              What we really should have is properties to identify continued table
              cells/rows and continued footnote text. I've been meaning to write this
              up as a feature request for some time now...

              • 4. Re: Detecting Permanent Overset
                Level 1
                Hi Harbs,

                Thanks for the offer. I guess I was just trying to confirm that I wasn't missing something obvious. For now, I'll live with what I have -- the two-in-a-row test is a good one, though.

                You are clearly much more into footnotes than I've ever been!

                • 5. Re: Detecting Permanent Overset
                  Harbs. Level 6
                  Dave_Saunders@adobeforums.com wrote:
                  > You are clearly much more into footnotes than I've ever been!

                  Probably, but I could say the same thing regarding you and tables! ;)

                  Here's the basic idea for getting empty frames (as you can see, my
                  functions all rely upon each other):

                  function IsEmptyTextFrame(textFrame){
                  if(textFrame.characters.length>0){return false}
                  if(HasTables (textFrame)){return false}
                  if(HasFootnotes (textFrame)){return false}
                  return true;

                  function HasFootnotes(textFrame){
                  if(textFrame.footnotes.length>0){return true}
                  var footnote = GetLastPlacedFootnote(textFrame.parentStory);
                  if(! footnote){return false}
                  var footnoteFrames = AsArray(footnote.parentTextFrames);
                  if(GetItemIndex(footnoteFrames,textFrame)!=null){return true}
                  return false;
                  function HasTables(textFrame){
                  if(textFrame.tables.length>0){return true}
                  if(textFrame.lines.length==0){return false}
                  if(textFrame.lines[0].characters.length==0){return true}
                  return false;

                  • 6. Re: Detecting Permanent Overset
                    Level 1
                    Very nice. Thanks.

                    • 7. Re: Detecting Permanent Overset
                      Dave Saunders Level 4

                      I guess I started this discussion a long time ago when my name was in parentheses. Now I'm struggling with a related issue:


                      How to tell the difference between a row in a table where all the cells are overset and a row in the table that is overset because that part of the table hasn't hit the page yet?






                      gives you an empty array in both situations.


                      The problem is that contrary to the discussion we had back in 2009, you simply can't tell the difference between a text frame that is populated by part of a table and another that isn't populated because the part of the table that should be there won't fit in the text frame. Everything I can think of gives the same result in all cases:


                      1 insertion point

                      1 line

                      0 characters (in the frame)

                      1 character in the line (now that's weird)

                      0 text columns

                      baselines (and other properties) not valid in the circumstances.


                      All I can think of is to try to compare the row number of the last non-overset row in the table. And that brings me to the issue how to tell the difference between a genuinely overset row and a row where every cell is overset?


                      Has anyone tackled this?



                      • 8. Re: Detecting Permanent Overset
                        [Jongware] Most Valuable Participant

                        Hi Dave!


                        Just checking: I bet you already thought of checking if (a) the parent story of the table overflows, in combination with (b) the table is the last visible item in that story? I know, it's not conclusive ...


                        (GRRR! Table doesn't have an 'overflows' property, but Row does! Unfortunately, it doesn't appear to do what I thought ... I always get 'false', no matter what's in it or where the row is.)

                        • 9. Re: Detecting Permanent Overset
                          Dave Saunders Level 4

                          Thanks Jongware.


                          I'm operating in the Typefi environment where my script gets kicked off at every page.start event. This means that the Typefi engine has prepared the next page for composition but hasn't yet done much with it. The script looks to see if there are any elements (in contrast to the main story) on the previous page that are overset. If so, it extends the element by a page.


                          If that results in the element no longer being overset then all is well, but if it doesn't, I just set things up so that at the next page.start, the script will just extend again by another page.


                          So, the challenge is to find a way of checking if the element is a table that some progress was made from one page to the next. If not, then we have the permanent overset condition I'm seeking. But the challenge is how to determine which rows are actually on the page versus overset. As long as I don't run into a row where all the cells are overset, this is fairly easy and can be quite efficient. At each run of the script, I can label the table with the row index of the last non-overset row and if that doesn't change from one run to the next, I have a permanent overset.


                          That's the thrust of my question.


                          I didn't realize that rows have an overflows property. I'll look into that.



                          • 10. Re: Detecting Permanent Overset
                            Peter Kahrel Adobe Community Professional & MVP



                            myRow.overflows is true if all cells in the row are overset.



                            • 11. Re: Detecting Permanent Overset
                              Dave Saunders Level 4



                              Thank you. That just might be enough information to sort this mess out. I think I might still be in a bit of trouble if the first overset row also happens to have cells that are all overset. And of course there's the really ridiculous case where the whole table has every cell overset, but I think I can ignore that possibility.



                              • 12. Re: Detecting Permanent Overset
                                Dave Saunders Level 4

                                An update on this:


                                Row.overflows is also true if a row is overset, no matter the state of the cells in the row, so we're back to getting the same result whether a row is overset or all the cells in the row are overset (although, if the cells are not completely overset, you can check the parentTextFrames property of the first insertion points).


                                But, if the first cell in a row is vertically merged with a cell above it, attempting to get Row.overflows for that row fails with an error. Still, you can trap for that error and then ignore it because whatever state the row above is in, this row must be in the same state because of the merge.