InDesign MY-NOTEBOOK

Saturday, January 14, 2012

jsx-howt How to convert from TextFrame geometricBounds to java.awt.Rectangle

InDesign TextFrame object has a geometricBounds property. It looks like ... 10,15,30,115 .
This means top,left,bottom,right .
So if you want to convert this property value to java.awt.Rectangle , you have to write code under below .

ToAwtRectangle.groovy


def tfBounds = Eval.me('[ 10,15,30,115 ]')

int top  = tfBounds[0] as Integer
int left = tfBounds[1] as Integer
int bottom = tfBounds[2] as Integer
int right  = tfBounds[3] as Integer

int x = left
int y = top
int width  = (right-left)
int height = (bottom - top)

println new java.awt.Rectangle( x,y,width,height )

as a result


$ groovy toAwtRectangle
java.awt.Rectangle[x=15,y=10,width=100,height=20]

© 2011,2012 Tomoaki Oshima