ewe.fx.print
Class PageRect

java.lang.Object
  extended byewe.fx.print.PageRect

public class PageRect
extends Object


Field Summary
protected  Graphics buffer
           
protected  double height
           
protected  Image image
           
protected  double width
           
protected  double x
           
protected  double xDPI
           
protected  double y
           
protected  double yDPI
           
 
Constructor Summary
PageRect()
           
 
Method Summary
 void adjustForPen(double penSize, Rect source)
           
 Rect adjustForPen(double penSize, Rect source, Rect destination)
           
 boolean allocateScalingBuffer(int destWidth, int destHeight)
          Attempt to allocate enough buffer space to allow the entire PageRect can be scaled from the dimensions of the allocated image buffer to an Image of the specified destination dimensions.
 boolean allocateScalingBuffer(int sourceWidth, int sourceHeight, int destWidth, int destHeight, boolean usesAlpha)
          Attempt to allocate enough buffer space to allow the entire PageRect can be scaled from the specified source dimensions to an Image of the specified destination dimensions.
 int getBufferHeight()
          Returns the height of the buffer in pixels.
 int getBufferWidth()
          Returns the width of the buffer in pixels.
 Graphics getGraphics()
          Returns the graphics that you use to draw on.
 double getHeightOnPaper()
          Returns the height of the PageRect in Points (1/72 of an inch).
 Image getImage()
          This returns the Image that was used to store images drawn if an Image was used for storing the drawn data.
 Image getScaledImage(int destWidth, int destHeight)
          This is used to get a scaled version of the data that was drawn into the PageRect via the Graphics returned by getGraphics().
 Graphics getSourceGraphics()
          Returns a graphics that you use to copy data from.
 double getWidthOnPaper()
          Returns the width of the PageRect in Points (1/72 of an inch).
 double getX()
          Returns the x location of the PageRect in Points (1/72 of an inch) in relation to the top-left corner of the paper.
 double getXDPI()
          Returns the DPI of the buffer horizontally.
 double getXPointToPixelScale()
          Return the factor that will convert values in Point co-ordinates to pixel co-ordinates horizontally.
 double getY()
          Returns the y location of the PageRect in Points (1/72 of an inch) in relation to the top-left corner of the paper.
 double getYDPI()
          Returns the DPI of the buffer horizontally.
 double getYPointToPixelScale()
          Return the factor that will convert values in Point co-ordinates to pixel co-ordinates horizontally.
 boolean isWithin(double x, double y)
          Returns true if the specified co-ordinate in Points is within this PageRect.
 boolean isWithin(double x, double y, double width, double height)
          Returns true if the specified rectangle in Points intersects with this PageRect.
 int scaleDimension(double pointSize)
          Scale a dimension value in Points (1/72 of an inch) into the correct number of pixels for this PageRect - but the return value will always be a minimum of 1.
 Rect scaleToPixels(PointRect pr, Rect destination)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

width

protected double width

height

protected double height

x

protected double x

y

protected double y

xDPI

protected double xDPI

yDPI

protected double yDPI

image

protected Image image

buffer

protected Graphics buffer
Constructor Detail

PageRect

public PageRect()
Method Detail

allocateScalingBuffer

public boolean allocateScalingBuffer(int sourceWidth,
                                     int sourceHeight,
                                     int destWidth,
                                     int destHeight,
                                     boolean usesAlpha)
Attempt to allocate enough buffer space to allow the entire PageRect can be scaled from the specified source dimensions to an Image of the specified destination dimensions.

Returns true if this was successful, false if not. If this method is successful, then the method getScaled image will successfully return a scaled image without running out of resources or memory.


allocateScalingBuffer

public boolean allocateScalingBuffer(int destWidth,
                                     int destHeight)
Attempt to allocate enough buffer space to allow the entire PageRect can be scaled from the dimensions of the allocated image buffer to an Image of the specified destination dimensions.

Returns true if this was successful, false if not. If this method is successful, then the method getScaled image will successfully return a scaled image without running out of resources or memory.

This version of the method can only be called after the PageRect has already had its buffer Image setup.


getScaledImage

public Image getScaledImage(int destWidth,
                            int destHeight)
This is used to get a scaled version of the data that was drawn into the PageRect via the Graphics returned by getGraphics().

Only call this if a call to allocateScalingBuffer() had succeeded, and only use the same destWidth and destHeight used in that method call. The returned scaled image will be re-used the next time getScaledImage() is called.


getImage

public Image getImage()
This returns the Image that was used to store images drawn if an Image was used for storing the drawn data. It is possible that a PageRect may choose to buffer the drawn commands in a different way. If this returns null then you can use getSourceGraphics() instead to attempt to retrieve the drawn data.


getWidthOnPaper

public double getWidthOnPaper()
Returns the width of the PageRect in Points (1/72 of an inch). This is different to the number of pixels in the buffer horizontally, which depends on the dpi you requested on creation. To get the number of pixels in the image horizontally call getBufferWidth().


getHeightOnPaper

public double getHeightOnPaper()
Returns the height of the PageRect in Points (1/72 of an inch). This is different to the number of pixels in the buffer vertically, which depends on the dpi you requested on creation. To get the number of pixels in the image vertically call getBufferHeight().


getX

public double getX()
Returns the x location of the PageRect in Points (1/72 of an inch) in relation to the top-left corner of the paper.


getY

public double getY()
Returns the y location of the PageRect in Points (1/72 of an inch) in relation to the top-left corner of the paper.


getGraphics

public Graphics getGraphics()
Returns the graphics that you use to draw on.


getSourceGraphics

public Graphics getSourceGraphics()
Returns a graphics that you use to copy data from. Call free() on this Graphics after you use it.


getBufferWidth

public int getBufferWidth()
Returns the width of the buffer in pixels. This is independant of the DPI of the printer.


getBufferHeight

public int getBufferHeight()
Returns the height of the buffer in pixels. This is independant of the DPI of the printer.


getXDPI

public double getXDPI()
Returns the DPI of the buffer horizontally. This indicates the number of pixels in the buffer that equal one inch on the printed page.


getYDPI

public double getYDPI()
Returns the DPI of the buffer horizontally. This indicates the number of pixels in the buffer that equal one inch on the printed page.


getXPointToPixelScale

public double getXPointToPixelScale()
Return the factor that will convert values in Point co-ordinates to pixel co-ordinates horizontally. Multiply the point co-ordinate value by the value returned and then round to the nearest integer.


getYPointToPixelScale

public double getYPointToPixelScale()
Return the factor that will convert values in Point co-ordinates to pixel co-ordinates horizontally. Multiply the point co-ordinate value by the value returned and then round to the nearest integer.


isWithin

public boolean isWithin(double x,
                        double y)
Returns true if the specified co-ordinate in Points is within this PageRect.

Parameters:
x - the x co-ordinate in Points (1/72 of an inch).
y - the y co-ordinate in Points (1/72 of an inch).
Returns:
true if the specified co-ordinate in Points is within this PageRect.

isWithin

public boolean isWithin(double x,
                        double y,
                        double width,
                        double height)
Returns true if the specified rectangle in Points intersects with this PageRect.

Parameters:
x - the x co-ordinate in Points (1/72 of an inch).
y - the y co-ordinate in Points (1/72 of an inch).
width - the width in Points (1/72 of an inch).
height - the height in Points (1/72 of an inch).
Returns:
true if the specified rectangle in Points intersects with this PageRect.

scaleToPixels

public Rect scaleToPixels(PointRect pr,
                          Rect destination)

scaleDimension

public int scaleDimension(double pointSize)
Scale a dimension value in Points (1/72 of an inch) into the correct number of pixels for this PageRect - but the return value will always be a minimum of 1.


adjustForPen

public Rect adjustForPen(double penSize,
                         Rect source,
                         Rect destination)

adjustForPen

public void adjustForPen(double penSize,
                         Rect source)