下面列出了java.awt.print.Paper#getWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Resolves a page format, so that the result can be serialized.
*
* @param format the page format that should be prepared for serialisation.
* @return the prepared page format data.
*/
private Object[] resolvePageFormat( final PageFormat format ) {
final Integer orientation = new Integer( format.getOrientation() );
final Paper p = format.getPaper();
final float[] fdim = new float[] { (float) p.getWidth(), (float) p.getHeight() };
final float[] rect = new float[] { (float) p.getImageableX(),
(float) p.getImageableY(),
(float) p.getImageableWidth(),
(float) p.getImageableHeight() };
return new Object[] { orientation, fdim, rect };
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
protected double getPhysicalPageWidth(Paper p) {
return p.getWidth();
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
/**
* Compiles a collection of page format properties.
*
* @param fmt
* the pageformat
* @param retval
* the attribute list
* @return The properties.
*/
private static AttributeList buildPageFormatProperties( final PageFormat fmt, final AttributeList retval ) {
if ( fmt == null ) {
throw new NullPointerException();
}
if ( retval == null ) {
throw new NullPointerException();
}
final Paper paper = fmt.getPaper();
final int w = (int) paper.getWidth();
final int h = (int) paper.getHeight();
final String pageDefinition = PageFormatFactory.getInstance().getPageFormatName( w, h );
if ( pageDefinition != null ) {
retval.setAttribute( BundleNamespaces.STYLE, "pageformat", pageDefinition );
} else {
retval.setAttribute( BundleNamespaces.STYLE, "width", String.valueOf( w ) );
retval.setAttribute( BundleNamespaces.STYLE, "height", String.valueOf( h ) );
}
final Insets borders = getBorders( paper );
if ( fmt.getOrientation() == PageFormat.REVERSE_LANDSCAPE ) {
retval.setAttribute( BundleNamespaces.STYLE, "orientation", "reverse-landscape" );
retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.right ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.top ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.left ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.bottom ) );
} else if ( fmt.getOrientation() == PageFormat.PORTRAIT ) {
retval.setAttribute( BundleNamespaces.STYLE, "orientation", "portrait" );
retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.top ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.left ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.bottom ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.right ) );
} else {
retval.setAttribute( BundleNamespaces.STYLE, "orientation", "landscape" );
retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.left ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.bottom ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.right ) );
retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.top ) );
}
return retval;
}
/**
* updates a Paper object to reflect the current printer's selected
* paper size and imageable area for that paper size.
* Default implementation copies settings from the original, applies
* applies some validity checks, changes them only if they are
* clearly unreasonable, then sets them into the new Paper.
* Subclasses are expected to override this method to make more
* informed decisons.
*/
protected void validatePaper(Paper origPaper, Paper newPaper) {
if (origPaper == null || newPaper == null) {
return;
} else {
double wid = origPaper.getWidth();
double hgt = origPaper.getHeight();
double ix = origPaper.getImageableX();
double iy = origPaper.getImageableY();
double iw = origPaper.getImageableWidth();
double ih = origPaper.getImageableHeight();
/* Assume any +ve values are legal. Overall paper dimensions
* take precedence. Make sure imageable area fits on the paper.
*/
Paper defaultPaper = new Paper();
wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
/* full width/height is not likely to be imageable, but since we
* don't know the limits we have to allow it
*/
if (iw > wid) {
iw = wid;
}
if (ih > hgt) {
ih = hgt;
}
if ((ix + iw) > wid) {
ix = wid - iw;
}
if ((iy + ih) > hgt) {
iy = hgt - ih;
}
newPaper.setSize(wid, hgt);
newPaper.setImageableArea(ix, iy, iw, ih);
}
}
/**
* Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are
* given in points.
*
* @param paper
* the paper that should be modified
* @param top
* the bordersize of the top-border
* @param left
* the border in points in the left
* @param bottom
* the border in points in the bottom
* @param right
* the border in points in the right
*/
public void setBorders( final Paper paper, final double top, final double left, final double bottom,
final double right ) {
final double w = paper.getWidth() - ( right + left );
final double h = paper.getHeight() - ( bottom + top );
paper.setImageableArea( left, top, w, h );
}