23 Replies Latest reply on Jul 24, 2011 7:43 AM by Dan Koch

    textFrame overflows for story continuity

    Dan Koch Level 1

      Hi.

       

      I'm creating a newspaper, and I need to print stories as columns in pages. This is working nicely.

       

      I'm using the information returned in textFrame.overflows to know if the story has been finished (then go to the next) or keep printing the same story in the new textFrame.

       

      But sometimes I got some stories with weird strings, like "=======" which the "text wrapper" can't handle.

       

      In these stories, the overflows property will be aways true (as I ever create new textFrames with the same width, defined in column). I get a infinite loop here, which I've skirted using it:

       

      if((/^\s+$/.test(textFrame.contents) || !textFrame.contents)

           overflows = false;

       

       

      But it is not very nice, once the text isn't displayed in the newspaper correctly.

       

      How can I handle these strings in Adobe Script?

       

      Thank you,

      Dan Koch

        • 1. Re: textFrame overflows for story continuity
          John Hawkinson Level 5

          Hi, Dan, I'm afraid I don't understand your question:

           

          But sometimes I got some stories with weird strings, like "=======" which the "text wrapper" can't handle.

          What is the "text wrapper"? Where does the "=======" come from, and what do you want to happen?

          Is InDesign not fitting the string in the textframe because...it does not fit your column width? Or something else?

           

          I'm not sure that the .overflows property is always up-to-date, sometimes InDesign may need to recompose... But I guess that's a tangential issue.

          • 2. Re: textFrame overflows for story continuity
            Dan Koch Level 1

            Hi John,

             

            These weird strings comes from my external articles, which were exported from docs using my ICML exporter.

             

            The text wrapper is who breaks the text to fit desired width (from ID engine).

             

            Theoretically, as I've seen, the TextFrame can have any width (where the ICML/Story is displayed), because the text wrap-per will break (like I've done in the wrapper word) the text to fit desired width.

             

            But when these weird strings appears in the text, this requires the width greater than that available for my TextFrame (and I'm using the column width as reference), because the wrapper can't deal with these strings (there isn't "====-\n===").

             

            Then overflows will be aways true. As the script creates new textFrame in the next column or page to article continuity, these next TextFrames will be aways blank, which I can stop printing using this regexp: /^\s+$/.test(textFrame.contents).

             

            I need to force to break the text, including these strings. What can I do?

             

            Thank you.

            • 3. Re: textFrame overflows for story continuity
              Dan Koch Level 1

              What is strange is that this does not happen when I create a textFrame directly in ID and put string "===" directly.

               

              Maybe this is a ICML issue.

               

                      <ParagraphStyleRange AppliedParagraphStyle="47618ee1-72a0-49f1-b904-3cea589eb3b3">
                          <CharacterStyleRange AppliedCharacterStyle="c19b75bb-48a7-41c5-92e4-31e818879fdd" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                              <Properties />
                              <Content><![CDATA[Adasf eee: ]]></Content>
                          </CharacterStyleRange>
                          <CharacterStyleRange AppliedCharacterStyle="ee1144c4-a301-43f1-8927-89afa18c2053" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                              <Properties />
                              <Content><![CDATA[Donec auctor lectus a lectus accumsan vulputate. Nulla tortor dui, commodo nec pretium sit amet, rutrum in massa. Quisque tortor lacus, tempus sed lacinia ut, dignissim ac neque. Integer gravida mollis urna a fringilla. ================================================Weird]]></Content>
                          </CharacterStyleRange>
                          <CharacterStyleRange AppliedCharacterStyle="ee1144c4-a301-43f1-8927-89afa18c2053" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                              <Properties />
                              <Content><![CDATA[ Etiam egestas ultrices nisi eu molestie. Donec vitae odio eu erat congue malesuada vitae non metus.]]></Content>
                          </CharacterStyleRange>
                          <Br />
                      </ParagraphStyleRange>  

               

              You can see two textFrames, but the text is hidden where "===" starts. The next textFrame will be blank and aways overflow.

               

               

              Capture1.PNG

              • 4. Re: textFrame overflows for story continuity
                John Hawkinson Level 5

                Hi, Dan.

                 

                I am still very confused, I'm afraid. And even knowing a bit more context about your project from your months-old post.

                You are placing ICML stories with the .place() method?

                 

                The normal term for what you are calling the "text wapper" is the "Composer," as in the Paragraph Composer, the Single-Line Composer, the World-Ready Composer, etc.

                 

                It is your own choice to insert long strings of equals signs, is it not? They will not break a line because InDesign's hyphenation rules do not permit them to do so. I am puzzled why you are doing this -- why use this form of in-band markup? Or are you deliberately doing to to make use of the fact that they are overset? This is not clear from your question.

                 

                 

                I need to force to break the text, including these strings. What can I do?

                Well, you can insert a carriage return at the point in the string of equals-signs where you would like the line to break. InDesign does not hyphenate strings of equals-signs.

                 

                I suspect this is not your question, but I am still very confused what you are asking.

                 

                What is strange is that this does not happen when I create a textFrame directly in ID and put string "===" directly.

                Now I'm even more confused. What happens when you do so "directly"? Is that what your picture is illustrating? It appears to me to show the problem you described above as I would have expected it.

                 

                        <ParagraphStyleRange AppliedParagraphStyle="47618ee1-72a0-49f1-b904-3cea589eb3b3">

                Please use >> Syntax Highlighting XML in the web interface, it makes it easier to read your XML and fixes weird linebreak problems.

                1 person found this helpful
                • 5. Re: textFrame overflows for story continuity
                  Dan Koch Level 1

                  Hi John,

                   

                  I am still very confused, I'm afraid. And even knowing a bit more context about your project from your months-old post.

                  You are placing ICML stories with the .place() method?

                   

                  Yes, I'm using textFrame.place(fileICML);

                   

                  The normal term for what you are calling the "text wapper" is the "Composer," as in the Paragraph Composer, the Single-Line Composer, the World-Ready Composer, etc.

                   

                  It is your own choice to insert long strings of equals signs, is it not? They will not break a line because InDesign's hyphenation rules do not permit them to do so. I am puzzled why you are doing this -- why use this form of in-band markup? Or are you deliberately doing to to make use of the fact that they are overset? This is not clear from your question.

                   

                  These strings has been found only in some articles. For now, this are simple samples where the customer (who will wrote the articles) insert some weird strings like it. This is just a sample to test the newspaper generator.

                   

                  Then InDesign's hyphenation/breaking rules isn't breaking it. It's so strange because when I'm putting "=" signs directly in InDesign (not in ICML), it breaks correctly.

                   

                  Sorry if I did not make this clear.

                   

                  Well, you can insert a carriage return at the point in the string of equals-signs where you would like the line to break. InDesign does not hyphenate strings of equals-signs.

                   

                  I suspect this is not your question, but I am still very confused what you are asking.

                   

                  That's the question! How to deal with these strings? I don't need to hyphenate these strings, but I need to break line (aways) to prevent the next textFrame to be blank (when using the same width).

                   

                  But how can I put this carriage return, if I don't know where the line ends?

                   

                  Are there options to force it in ICML? I've tried TextWrapPreference without success.

                   

                  Now I'm even more confused. What happens when you do so "directly"? Is that what your picture is illustrating? It appears to me to show the problem you described above as I would have expected it.

                   

                  Yes, in this image I'm inserting "=" directly in InDesign, without use of intermediate ICML file. Here the InDesign handles the line breaks, as I press the "=" key:

                   

                  Capture2.PNG

                   

                  Please check out the snippet:

                          <ParagraphStyleRange AppliedParagraphStyle="47618ee1-72a0-49f1-b904-3cea589eb3b3">
                              <CharacterStyleRange AppliedCharacterStyle="c19b75bb-48a7-41c5-92e4-31e818879fdd" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                                  <Properties />
                                  <Content><![CDATA[Adasf eee: ]]></Content>
                              </CharacterStyleRange>
                              <CharacterStyleRange AppliedCharacterStyle="ee1144c4-a301-43f1-8927-89afa18c2053" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                                  <Properties />
                                  <Content><![CDATA[Donec auctor lectus a lectus accumsan vulputate. Nulla tortor dui, commodo nec pretium sit amet, rutrum in massa. Quisque tortor lacus, tempus sed lacinia ut, dignissim ac neque. Integer gravida mollis urna a fringilla. ================================================Weird]]></Content>
                              </CharacterStyleRange>
                              <CharacterStyleRange AppliedCharacterStyle="ee1144c4-a301-43f1-8927-89afa18c2053" NumberingStartAt="1" NumberingContinue="true" NumberingApplyRestartPolicy="true" NumberingLevel="1">
                                  <Properties />
                                  <Content><![CDATA[ Etiam egestas ultrices nisi eu molestie. Donec vitae odio eu erat congue malesuada vitae non metus.]]></Content>
                              </CharacterStyleRange>
                              <Br />
                          </ParagraphStyleRange>
                  
                  

                   

                  Thank you.

                  Dan Koch

                  • 6. Re: textFrame overflows for story continuity
                    John Hawkinson Level 5
                    Then InDesign's hyphenation/breaking rules isn't breaking it. It's so strange because when I'm putting "=" signs directly in InDesign (not in ICML), it breaks correctly.

                     

                    Sorry if I did not make this clear.

                    Yes, in this image I'm inserting "=" directly in InDesign, without use of intermediate ICML file. Here the InDesign handles the line breaks, as I press the "=" key:

                     

                    Capture2.PNG

                     

                     

                    This does not happen for me. InDesign CS5 7.0.4:

                    1. Open a new document

                    2. Draw a textframe

                    3. Switch to the selection tool and from the control bar, set the width and height to 10p

                    4. Font is Minion Pro 12pt, the default (autoleading)

                    5. Double-click the box (active insertion point in the box)

                    6. Type 17 equals signs, they show up.

                    7. Type the 18th equals sign. All equals signs disappear and the text goes overset.

                     

                    This is the behavior I expect, and it does not seem broken to me.

                     

                    That's the question! How to deal with these strings? I don't need to hyphenate these strings, but I need to break line (aways) to prevent the next textFrame to be blank (when using the same width).

                     

                    But how can I put this carriage return, if I don't know where the line ends?

                     

                    However you like? I guess you can assume that the characters are roughly one em-width (most are!), take the em size of the type, divide it into the width of the box, and you have a number of characters. Subtract some margin (10%? 50%? It all depends) and break the line there. If it doesn't work, repeat?

                     

                    I still don't understand why you have long unbreakable characters in your ICML. It seems weird. I gather it is deliberate, but I don't know why.

                     

                    I'm also not sure what the snippet is demonstrating, other than that I can crash InDesign by trying to place it without a surrounding <Story/> tag (and probably others)?

                     

                    But seriously...I guess the snippet is just showing me what characters are in your ICML? OK. It does not seem weird to me.

                     

                    What am I missing?

                    1 person found this helpful
                    • 7. Re: textFrame overflows for story continuity
                      Dan Koch Level 1

                      Hi again,

                      7. Type the 18th equals sign. All equals signs disappear and the text goes overset.

                       

                      This is right!

                      But if you keep pressing "=", the text will appear in the next line.

                      However you like? I guess you can assume that the characters are roughly one em-width (most are!), take the em size of the type, divide it into the width of the box, and you have a number of characters. Subtract some margin (10%? 50%? It all depends) and break the line there. If it doesn't work, repeat?

                       

                      Maybe this solution can work. Can I do this parsing in Adobe Script?

                      I still don't understand why you have long unbreakable characters in your ICML. It seems weird. I gather it is deliberate, but I don't know why.

                       

                      I still don't understand why you have long unbreakable characters in your ICML. It seems weird. I gather it is deliberate, but I don't know why.

                       

                      I'm also not sure what the snippet is demonstrating, other than that I can crash InDesign by trying to place it without a surrounding <Story/> tag (and probably others)?

                       

                      But seriously...I guess the snippet is just showing me what characters are in your ICML? OK. It does not seem weird to me.

                       

                      What am I missing?

                       

                      Nothing.

                       

                      We're just testing the newspaper generator with some samples of articles that were used in previous pdf-only engine. I can't tell you why the customer (the final users) put sequences like "===" in the articles. But it happens and are breaking the final newspaper.

                       

                      The snippet here is just the Paragraph of ICML, not the entire file.

                       

                      Thanks

                      Dan Koch

                      • 8. Re: textFrame overflows for story continuity
                        Dan Koch Level 1

                        If this is the only way to prevent overset text in TextFrames, I'll put \n purposely in continuous strings.

                         

                        How can I loop through all words in Story (not the textFrame.contents, once it only returns the text which is displayed) ?

                         

                        Thank you,

                        Daniel Koch

                        • 9. Re: textFrame overflows for story continuity
                          Dan Koch Level 1

                          I also need to know when the Composer (or the "text wrapper") will not break the string.

                           

                          I've tried sequences of "----" and the text was overset too.

                           

                          But sequences of "aaa" doesn't overset.

                          • 10. Re: textFrame overflows for story continuity
                            John Hawkinson Level 5

                            But if you keep pressing "=", the text will appear in the next line.

                            Oh. That is interesting. I wonder why that happens?

                            But I don't think you should expect InDesign to be able to break words that are defined to be unbreakable and can't fit in the space you allot...

                             

                            However you like? I guess you can assume that the characters are roughly one em-width (most are!), take the em size of the type, divide it into the width of the box, and you have a number of characters. Subtract some margin (10%? 50%? It all depends) and break the line there. If it doesn't work, repeat?

                             

                            Maybe this solution can work. Can I do this parsing in Adobe Script?

                             

                            Sure. It's called ExtendScript, BTW, or you could just say JavaScript. No such thing as Adobe Script.

                             

                            Something like this:

                             

                            var
                                p=frame.parentStory,
                                st=p.characters[frame.characters[-1].index+1],
                                overset=p.texts.itemByRange(st,p.texts[0].characters[-1]),
                                pos = Math.round(
                                    (frame.geometricBounds[3]-frame.geometricBounds[1])
                                    *12/st.pointSize*0.9);
                            overset.insertionPoints[pos].contents=" ";
                            

                             

                            That is, assume that frame is the frame we are operating on, which is overset

                            Get the Character object that contains the cahracter after the last one in frame.

                            Then, get the range of text starting from that character to the last one in the story.

                            Then, take the width of the frame (geometricBounds is y1,x1,y2,x2), assuming the current measurement units are picas. Multiply it by 12 to get points, divide by the pointsize of the first characer, and multiply by 0.9 for the 10% margin. Insert a space at that point.

                             

                            There's a lot to tweak here but it seems to work.

                            • 11. Re: textFrame overflows for story continuity
                              Dan Koch Level 1

                              Okay,

                              I'll try with this code.

                               

                              Thanks a lot.

                               

                              Dan Koch

                              • 12. Re: textFrame overflows for story continuity
                                Dan Koch Level 1

                                Hi,

                                 

                                I'm getting this exception. Do you know why?

                                 

                                Error: Object is locked.

                                 

                                    try
                                    {
                                        var pos = Math.round( textFrameWidth / lastWord.pointSize );
                                        lastWord.insertionPoints[pos].contents = " ";
                                        
                                    } catch(e) {
                                        $.write(e);        
                                        return;
                                    }
                                

                                 

                                Thanks,

                                Dan Koch

                                • 13. Re: textFrame overflows for story continuity
                                  John Hawkinson Level 5

                                  At the risk of sounding obvious, is your textframe [or story?] locked?

                                   

                                  What's pos set to? What happens if you try to edit the insertionPoint contents by hand manually?

                                   

                                  Also, did you figure out the answers to your questions in posts #8 and #9 above? In re #8, you just loop over textFrame.parentStory's contents (or words or whatever). In re #9, 'aaa' doesn't overset because letters can be hyphenated...

                                  • 14. Re: textFrame overflows for story continuity
                                    Dan Koch Level 1

                                    Hi again,

                                     

                                    John Hawkinson wrote:

                                     

                                    At the risk of sounding obvious, is your textframe [or story?] locked?

                                     

                                    Fine! How can I check? How can I unlock? textFrame.locked is aways false.

                                     

                                    What's pos set to? What happens if you try to edit the insertionPoint contents by hand manually?

                                     

                                    I'm trying this:

                                     

                                    function helper_remove_overset(textFrame)
                                    {    
                                        var pS = textFrame.parentStory;
                                        var lastStoryChar = pS.characters.lastItem();
                                        var lastStoryCharI = lastStoryChar.index;
                                        
                                        var lastFrameChar = textFrame.characters.lastItem();
                                        
                                        try
                                        {
                                            if( !lastFrameChar.index )
                                                return;
                                        } catch(e) {
                                            return;
                                        }
                                        
                                        var nextFrameCharI = lastFrameChar.index + 1;
                                        
                                        if( nextFrameCharI >= lastStoryCharI )
                                            return;
                                        
                                        var nextFrameChar = pS.characters[ nextFrameCharI ];
                                        var nextText = pS.texts.itemByRange( nextFrameChar, lastStoryChar );
                                        var lastWord = nextText.words.firstItem();
                                        
                                        var textFrameWidth = textFrame.geometricBounds[3] - textFrame.geometricBounds[1];
                                        var wordSize = lastWord.pointSize * lastWord.length;
                                        
                                        if( textFrameWidth >= wordSize )
                                            return;
                                            
                                        try
                                        {
                                            var pos = Math.round( textFrameWidth / lastWord.pointSize );
                                            lastWord.insertionPoints[pos].contents = " ";
                                            
                                        } catch(e) {
                                            $.write(e);
                                            return;
                                        }
                                    }
                                    

                                     

                                    Also, did you figure out the answers to your questions in posts #8 and #9 above? In re #8, you just loop over textFrame.parentStory's contents (or words or whatever). In re #9, 'aaa' doesn't overset because letters can be hyphenated...

                                     

                                    Sure!

                                     

                                    But checking for wordSize > textFrameSize, I'm getting only the weird string (===).

                                     

                                    I think I can't know if the Hyphenizator will hyphenate it, but if  wordSize > textFrameSize, I'll put a blank space in some place of word.

                                     

                                    What do you think?

                                     

                                    How can I unlock this word?

                                     

                                    Thanks.

                                    Dan Koch

                                    • 15. Re: textFrame overflows for story continuity
                                      John Hawkinson Level 5

                                      Dan:

                                       

                                      Well, I guess you could look in the Layers panel for locked items? But I would think that attribute would be sufficient, so I am confused. What version of InDesign are you using?

                                       

                                      I'm trying this:

                                       

                                      function helper_remove_overset(textFrame)
                                      

                                      Oh, come on, be serious! Too long, too complicated, too much to read, and not testable without your input file.

                                      Like I said before:

                                       

                                      What's pos set to? What happens if you try to edit the insertionPoint contents by hand manually?

                                      Do those things interactively in the JavaScript console. Also use the ESTK's Data Browser. Also set breakpoints and single-step. You should be able to figure out what the problem is, or what the limits are, and narrow it down to a small test case. Either you're calculating wrong, or there is something else that prevents you from inserting a space there.

                                       

                                      Are your measurement units in points? If not, it looks like your code is going to have problems.

                                      • 16. Re: textFrame overflows for story continuity
                                        Dan Koch Level 1

                                        John!

                                         

                                        I think I'm getting closer to the end!

                                         

                                        My only trouble now is with this locked state. Let me explain.

                                         

                                        I'm using InDesign 6.0 / CS4. No way to upgrade to CS5, it is a customer's requirement.

                                         

                                        When script is running, both lastWord.insertionPoints[0].contents as lastWord.insertionPoints.middleItem().contents gets locked when setting new value (even if I check the limits with count()).


                                        But here happens the strange behavior: When using the breakpoint, and expanding the textFrame object in the Data Browser, the locked state is turned out and all things goes well.

                                         

                                        The textFrame.itemLayer.locked is false and textFrame.locked is false.

                                         

                                        Did you know why it happens on debug?

                                         

                                        Thanks again

                                        Dan Koch

                                        • 17. Re: textFrame overflows for story continuity
                                          John Hawkinson Level 5

                                          No, that's curious, I have no explanation.

                                          If you want to give me a small test case I can test

                                          it in CS5 and 5.5.

                                          • 18. Re: textFrame overflows for story continuity
                                            Dan Koch Level 1

                                            Thank you but this is impossible. There's no simple way to strip the code in small part to send to you test it.

                                             

                                            But even setting textFrame.contents or textFrame.parentStory.contents I get this Object is Locked at runtime. I don't know why.

                                             

                                            What can I check to be locked?

                                             

                                            Thanks

                                            • 19. Re: textFrame overflows for story continuity
                                              Dan Koch Level 1

                                              I get the same error trying it:

                                               

                                                  textFrame = page.textFrames.add();
                                                  textFrame.geometricBounds = cursor_bounds();
                                                  textFrame.place(fileICML);
                                                  textFrame.parentStory.contents = "adasdasf"; // LOCKED EXCEPTION!
                                              
                                              • 20. Re: textFrame overflows for story continuity
                                                Dan Koch Level 1

                                                But nothing when I don't use .place():

                                                 

                                                    textFrame = page.textFrames.add();
                                                    textFrame.geometricBounds = cursor_bounds();
                                                    //textFrame.place(fileICML);
                                                    textFrame.parentStory.contents = "adasfe man!"; // will run!
                                                
                                                • 21. Re: textFrame overflows for story continuity
                                                  Dan Koch Level 1

                                                  Hi!

                                                   

                                                  This makes no sense, but it works:

                                                   

                                                      //textFrame.place(fileICML);
                                                      textFrame.parentStory.contents = " ";
                                                      textFrame.parentStory.insertionPoints.firstItem().place(fileICML);

                                                   

                                                  while it don't:

                                                   

                                                      //textFrame.place(fileICML);
                                                      textFrame.parentStory.contents = ""; // this is empty.
                                                      textFrame.parentStory.insertionPoints.firstItem().place(fileICML);

                                                   

                                                  Do you know why?

                                                   

                                                  Dan Koch

                                                  • 22. Re: textFrame overflows for story continuity
                                                    John Hawkinson Level 5

                                                    Thank you but this is impossible. There's no simple way to strip the code in small part to send to you test it.

                                                    Sure there is, you simply construct a textFrame (one line!) and set up its contents and then find a place where you cannot modify the insertionPoints.

                                                    But apparently you've figured that out:

                                                     

                                                    This makes no sense, but it works:

                                                     

                                                        //textFrame.place(fileICML);
                                                        textFrame.parentStory.contents = " ";
                                                        textFrame.parentStory.insertionPoints.firstItem().place(fileICML);
                                                    

                                                     

                                                    while it don't:

                                                     

                                                    I suspect you should pay more attention to the InDesign UI. Do you see the same problem interactively?

                                                     

                                                    My guess is that InDesign wants you to "check out" the InCopy assignment before modifying it after you place it.

                                                    It's possible that it makes more sense for you to use IDMS instead of ICML if that's what's going on, but maybe not.

                                                    • 23. Re: textFrame overflows for story continuity
                                                      Dan Koch Level 1

                                                      Hi John,

                                                       

                                                      Sure there is, you simply construct a textFrame (one line!) and set up its contents and then find a place where you cannot modify the insertionPoints.

                                                      But apparently you've figured that out:

                                                       

                                                      Yes, and it is working well.

                                                      Thank very much for the help!

                                                       

                                                      My guess is that InDesign wants you to "check out" the InCopy assignment before modifying it after you place it.

                                                      It's possible that it makes more sense for you to use IDMS instead of ICML if that's what's going on, but maybe not.

                                                       

                                                      After "check out" I can change the text of Story, in textFrame (directly in UI) or in the Story Editor. I ran textFrame.checkOut() before attemp to change text.

                                                       

                                                      But now all things are ok.

                                                       

                                                      Thanks a lot.

                                                      Dan Koch