1 Reply Latest reply on Sep 22, 2012 8:44 AM by Laubender

    How to fit frame to content when content contains anchored text box?

    Graham vdR Level 1

      Hi there

       

      I am creating a series of inline text frames within a text frame. Each of these inline frames contains text which includes an anchored text frame. If I tell my inline frames to fit to content they seem to ignore the anchored frames contained therein. Is there any way I can get them to consider the anchored frames they contain when they fit to content?

       

      I tried checking the geometric bounds of my anchored frame before and after its parent frame has fitted to content. Even when there has been no change in position the bounds after fitting to content seem to give numbers way off. I thought I might be able to reset the geometric bounds of the containing frame manually if the anchored frame therein had moved with the fit frame to content.

       

      Here is a snippet of my code:

       

      var anchoredBounds = anchoredFrame.geometricBounds;
      mainFrame.fit(FitOptions.FRAME_TO_CONTENT);
      mainFrame.texts.item(0).recompose;
      var newAnchoredBounds = anchoredFrame.geometricBounds;
      alert(anchoredBounds[0] + "; " + newAnchoredBounds[0]);
      

       

      So “mainFrame” is the text frame containing text and the anchored frame, “anchoredFrame”. “anchoredBounds[0]” seems to correlate with the top edge of the frame when I check it manually after the script has finished (when it hasn’t move with the fit to content). “newAnchorBounds[0]”, however, always gives numbers that are way off every time. Any ideas why this would be the case?

       

      And most importantly, can anyone suggest how I can get my “mainFrame” to consider the “anchoredFrame” contained in it when it fits to content?

       

      I’m using CS4 on a PC. Let me know if it would help to post more code, or if I haven’t explained myself clearly enough.

        • 1. Re: How to fit frame to content when content contains anchored text box?
          Laubender Adobe Community Professional & MVP

          Is there any way I can get them to consider the anchored frames they contain when they fit to content?

           

          @Graham – as long as ALL the anchored text frames are "inline" text frames,

           

          mainFrame.fit(FitOptions.FRAME_TO_CONTENT);
          

           

          should work as expected or at least sort of *.

          Without calculating anything at all.

          Just tested in InDesign CS5.5 (v7.5.3).

           

          Could it be that CS4 will fail on that?

           

          Of course, you can only rely on this, if the main text frame contains any "real" text at all. Not only the  special characters representations of the "inline" text frames. In that case the fit() method will do nothing at all.

           

           

          * it's debatable, if the fit() method yields desirable output.

          It depends on your expectations.


          See the following examples:

           

          1. Case 1:
          Text frame before fitting:

           

          Case1_beforeFit.png

           

          2. Case 1:

          After fitting with the UI command, context menu: "fit frame to contents"
          (note the gap between the last baseline of the text and the text frame; note also  the new width)

          Is that the result you would expect? I guess not.

          Case1_afterFit.png

           

          3. Case 1:

          After fitting  programmatically with myTextframe.fit(FitOptions.FRAME_TO_CONTENT);

          Case1_afterFitProgrammatically.png

           

           

           

          4. Case 2:
          Before fitting

          same text frame as in #1, but different height

          Case2_beforeFit.png

           

           

          5. Case 2:

          After fitting with the UI command, context menu: "fit frame to contents"

          A different width than in #2 and a gap at the bottom of the text frame!

          Not the desired result, I'd say…

          Case2_afterFit_UI.png

           

          6. Case 2:

          After fitting  programmatically with myTextframe.fit(FitOptions.FRAME_TO_CONTENT);

          Same result as in #3
          So with scripting we could, at least, get consistent results.

          Case2_afterFitProgrammatically.png

           

          Of course, you could get the same results in the UI, if you double-click on the bottom center control point…

           

           

          Maybe it helps, if you are showing us some screen grabs:

          1. Your starting point
          2. The desired result

           

          Uwe