6 Replies Latest reply on Oct 6, 2014 5:48 AM by rob day

    Applying full justification automatically when the last line is almost the width of the frame

    Till Ulen

      In a novel that I am setting the text will be justified. The last lines of every paragraph will be left-aligned (Left Justify).

       

      Some paragraphs have a long last line that almost touches the right edge of the frame. I would like those paragraphs to become full-justified, so that the last line uses the full width, like all the previous lines.

       

      I can go over all paragraphs in the book manually one by one (which is tedious), or I can write a script to do that (which will require learning some new APIs, testing and debugging). Is there any simple solution that I'm overlooking?

       

      For example, the frame width is 300 points. If the width of the last line is under 288 points, it will remain left-aligned, as usual. If its width is greater than 288 points, apply Full Justify to the whole paragraph (and possibly reflow it) and make the effective width of the last line exactly 300 points.

       

      Alexander

        • 1. Re: Applying full justification automatically when the last line is almost the width of the frame
          Derek Cross Level 6

          I wouldn't bother myself, it could be slightly irritating for the reader and it might cause reflow issues if you change some words in a sentence.

          More important would be to implement Optical Margin Alignment:

          Select the paragraph(s), then from the menu select: Type > Story - select the typesize and tick the checkbox.

          • 2. Re: Applying full justification automatically when the last line is almost the width of the frame
            rob day Adobe Community Professional & MVP

            I don't think there's away to do it in the GUI. If you are using OSX try this AppleScript. You would have to be careful with reflows after running this because the changed paragraphs would remain fully justified even if they shouldn't be

             

            ---------------------------------------------------

             

            --adjust this to desired percentage. Any last line that's wider than 90% of the column width gets justified

            set zone to 0.90

             

            tell application "Adobe InDesign CS6"

                set paras to object reference of every paragraph of every story of active document

               

                --check the length of each last line

                repeat with x in paras

                    --get the full column width of the paragraph

                    set i to horizontal offset of first character of line -2 of x

                    set j to horizontal offset of last character of line -2 of x

                    set colw to j - i

                   

                    --get the last line width

                    set a to horizontal offset of first character of line -1 of x

                    set b to horizontal offset of last character of line -1 of x

                    set lastw to b - a

                   

                    --if the last line percentage is greater than zone number justify

                    if lastw / colw is greater than zone then

                        set justification of x to fully justified

                    end if

                end repeat

            end tell

            • 3. Re: Applying full justification automatically when the last line is almost the width of the frame
              rob day Adobe Community Professional & MVP

              More important would be to implement Optical Margin Alignment:

               

              Optical Margin Alignment wouldn't affect something like the paragraph on the left, which I think is what Alexander wants to adjust:

               

              Screen Shot 2014-10-05 at 6.04.46 PM.png

              • 4. Re: Applying full justification automatically when the last line is almost the width of the frame
                Till Ulen Level 1

                Thanks Rob. That's exactly what I want to achieve. Unfortunately I use Windows, so I'll probably have to write some JavaScript to automate that. Looking at your script, that doesn't seem as hard as I initially thought.

                • 5. Re: Applying full justification automatically when the last line is almost the width of the frame
                  Derek Cross Level 6

                  Rob - I appreciate that Optical Margin Alignment wouldn't do what Alexander wants, I was merely suggesting that if he's interested in good typographic practice for his novel he might implement this feature.

                  Derek

                  • 6. Re: Applying full justification automatically when the last line is almost the width of the frame
                    rob day Adobe Community Professional & MVP

                    If you know some js it should be easy with the ExtendScript app, or someone in the scripting forum might translate for you. You probably should reset any fully justified paragraphs in the loop via— if justification of x is fully justified then set justification of x to left justified:

                     

                    ---------------------

                    set zone to 0.95

                    tell application "Adobe InDesign CS6"

                        --get all of the document's paragraphs as a list of objects

                        set paras to object reference of every paragraph of every story of active document

                       

                        --check the length of each last line

                        repeat with x in paras

                           

                            --reset any fully justified paragraphs

                            if justification of x is fully justified then set justification of x to left justified

                           

                            --catch any single line paragraphs with try

                            try

                                --get the full column width of the paragraph by measuring the 2nd to last line

                                set i to horizontal offset of first character of line -2 of x

                                set j to horizontal offset of last character of line -2 of x

                                set colw to j - i

                               

                                --get the last line width

                                set a to horizontal offset of first character of line -1 of x

                                set b to horizontal offset of last character of line -1 of x

                                set lastw to b - a

                               

                                --if the last line percentage is greater than zone number justify

                                if lastw / colw is greater than zone then

                                    set justification of x to fully justified

                                end if

                            end try

                        end repeat

                    end tell