1 Reply Latest reply on Feb 19, 2014 1:21 AM by Trevorׅ

    Script to justify text vertically in multi-column frame?

    mosheyfri

      Can I create a script to justify text vertically in a multi-column frame but within the baseline grid?

       

      I understand that it can be done manually by adjusting the tracking in order to force the text to end evenly on bottom. However I'm looking to achieve that result automatically, pretty much like the "Justify Vertically" feature except by doing so it spreads the last column lines out, but I need to keep the text on the grid.

       

      In a nutshell: I'm looking to fill the text box, using automatic tracking between words (based on pre-defined min-max values) to end evenly on bottom.

        • 1. Re: Script to justify text vertically in multi-column frame?
          Trevorׅ Adobe Community Professional

          Hi Moshey

           

          You might want to consider buying some of Harb's readymade products, in particular http://in-tools.com/products/plugins/column-flow/ and http://in-tools.com/products/plugins/proper-vj/ but have a look at some of the other products there.

           

          Otherwise you can try something like this

           

           

          // On the bases that the textFrame is not linked
          // very very rough guide and not optimized!
                 app.doScript("balanceColumns()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Balance Columns");
          
          function balanceColumns() { 
              var myTextFrame = app.selection[0];
              if (myTextFrame.hasOwnProperty ('endBaseline')) myTextFrame = myTextFrame.parentTextFrames[0];
              var bottomOfFrame = myTextFrame.geometricBounds[2] - myTextFrame.textFramePreferences.insetSpacing[2];
              var topOfFrame = myTextFrame.geometricBounds[0] + myTextFrame.textFramePreferences.insetSpacing[0];
              var columnWritingArea = myTextFrame.textFramePreferences.textColumnFixedWidth * (bottomOfFrame- topOfFrame );
                      var myParagraphs = myTextFrame.paragraphs.everyItem().getElements().slice(0);
              while (!myTextFrame.overflows) { 
                  z++
              var l = myParagraphs.length;
                  var columnCount = myTextFrame.textFramePreferences.textColumnCount;
              var numberOfCurrentColumnsUsed = myTextFrame.insertionPoints.itemByRange(0,-1).textColumns.length;
          try {
              if (myTextFrame.textColumns[columnCount - 1].isValid && myTextFrame.textColumns[columnCount - 1].characters[-1].endBaseline >= myTextFrame.textColumns[columnCount - 2].characters[-1].endBaseline) break
          }
          catch (e) {break};
              var areaOfFullColumns = columnWritingArea * (numberOfCurrentColumnsUsed - 1);
              var areaOfPartColumn = myTextFrame.textFramePreferences.textColumnFixedWidth * (myTextFrame.insertionPoints[-1].endBaseline - topOfFrame);
              var totalUsedAreaOfColums = areaOfFullColumns + areaOfPartColumn;
              var desiredAreaOfColums = columnWritingArea * (columnCount);
              var ratio = 1.05 * desiredAreaOfColums / totalUsedAreaOfColums;
              while (l--) {
                  var p = myParagraphs[l];
                  p.properties = {maximumWordSpacing: p.maximumWordSpacing *ratio, desiredWordSpacing: p.desiredWordSpacing *ratio, minimumWordSpacing: p.minimumWordSpacing *ratio};
                  }
              }
          ratio = .98;
          while (myTextFrame.overflows) {
                   l = myParagraphs.length;
          while (l--) {
                  var p = myParagraphs[l];
                  p.properties = {maximumWordSpacing: p.maximumWordSpacing *ratio, desiredWordSpacing: p.desiredWordSpacing *ratio, minimumWordSpacing: p.minimumWordSpacing *ratio};
                  }
              }
          }