@memoized
def getCoords(x, y, w, h, pagesize):
 (ax, ay) = pagesize
 if (x < 0):
  x = (ax + x)
 if (y < 0):
  y = (ay + y)
 if ((w is not None) and (h is not None)):
  if (w <= 0):
   w = ((ax - x) + w)
  if (h <= 0):
   h = ((ay - y) + h)
  return (x, ((ay - y) - h), w, h)
 return (x, (ay - y))

@ memoized def getCoords ( x , y , w , h , pagesize ) : ( ax , ay ) = pagesize if ( x < 0 ) : x = ( ax + x ) if ( y < 0 ) : y = ( ay + y ) if ( ( w is not None ) and ( h is not None ) ) : if ( w <= 0 ) : w = ( ( ax - x ) + w ) if ( h <= 0 ) : h = ( ( ay - y ) + h ) return ( x , ( ( ay - y ) - h ) , w , h ) return ( x , ( ay - y ) )
as a stupid programmer i like to use the upper left corner of the document as the 0 .