Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Last insertion point of a line is ignored. Why?

$
0
0

I am writing a script that takes a multiline paragraph and scales down the pointSize to fit all the text on one lines that matches the width of the text frame.

 

Screen Shot 2013-08-27 at 12.33.55 PM.png

 

Here's how i calculate it.

- I add up the length of each line to get the total width.

- calculate the scaling percentage by diving the text frame width with the total width.

- multiple current point size with pecentage.

 

Pretty simple stuff.

 

The issue i am facing is that indesign makes the last character as the last insertion point of each line. IT IGNORES THE SPACE AFTER IT. Which shoul technically be the last inseriton point. So since that space doesnt get calculated, it throw off my entire scaling.

 

Screen Shot 2013-08-27 at 12.34.09 PM.png

 

Am i doing something wrong. Any help would be appreciated.

 

my code:

 

 

var frameWidth = app.selection[0].geometricBounds[3] - app.selection[0].geometricBounds[1];
var numOfLines = app.selection[0].lines.length;
var totalWidth = 0;  for (var j = numOfLines - 1; j>-1; j--) {      if(j == numOfLines-1) {            totalWidth = totalWidth + (app.selection[0].lines[j].insertionPoints[-1].horizontalOffset - app.selection[0].lines[j].insertionPoints[0].horizontalOffset);      }else{            totalWidth = totalWidth + (app.selection[0].lines[j].characters[-1].horizontalOffset - app.selection[0].lines[j].characters[0].horizontalOffset);      }}  
var percentage = frameWidth / totalWidth;  
app.selection[0].paragraphs[0].pointSize = app.selection[0].paragraphs[0].pointSize * percentage + "pt"

Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>