下面列出了java.awt.print.Paper#getImageableHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Describes the physical output characteristics like page size, margins, and imaginable area.
*
* @return
*/
public PageFormat getPageFormat() {
if ( pageDefinition == null ) {
return new PageFormat();
}
final PageFormat pageFormat = pageDefinition.getPageFormat();
final Paper orgPaper = pageFormat.getPaper();
final PageFormatFactory pff = PageFormatFactory.getInstance();
final double virtualPaperWidth =
orgPaper.getImageableWidth() + pff.getLeftBorder( orgPaper ) + pff.getRightBorder( orgPaper );
final double virtualPaperHeight =
orgPaper.getImageableHeight() + pff.getTopBorder( orgPaper ) + pff.getBottomBorder( orgPaper );
final Paper p = pff.createPaper( virtualPaperWidth, virtualPaperHeight );
pff.setBorders( p, pff.getTopBorder( orgPaper ), pff.getLeftBorder( orgPaper ), pff.getBottomBorder( orgPaper ),
pff.getRightBorder( orgPaper ) );
return pff.createPageFormat( p, pageFormat.getOrientation() );
}
/**
* Tests, whether the given two page format objects are equal.
*
* @param pf1
* the first page format that should be compared.
* @param pf2
* the second page format that should be compared.
* @return true, if both page formats are equal, false otherwise.
*/
public static boolean isEqual( final PageFormat pf1, final PageFormat pf2 ) {
if ( pf1 == pf2 ) {
return true;
}
if ( pf1 == null || pf2 == null ) {
return false;
}
if ( pf1.getOrientation() != pf2.getOrientation() ) {
return false;
}
final Paper p1 = pf1.getPaper();
final Paper p2 = pf2.getPaper();
if ( p1.getWidth() != p2.getWidth() ) {
return false;
}
if ( p1.getHeight() != p2.getHeight() ) {
return false;
}
if ( p1.getImageableX() != p2.getImageableX() ) {
return false;
}
if ( p1.getImageableY() != p2.getImageableY() ) {
return false;
}
if ( p1.getImageableWidth() != p2.getImageableWidth() ) {
return false;
}
if ( p1.getImageableHeight() != p2.getImageableHeight() ) {
return false;
}
return true;
}
/**
* 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 getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
protected double getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
/**
* 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);
}
}
protected double getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
protected double getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
protected double getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
/**
* 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 getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
/**
* 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 getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
protected double getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
/**
* 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 getPhysicalPrintableHeight(Paper p) {
return p.getImageableHeight();
}
/**
* 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);
}
}
/**
* Returns the bottom border of the given paper.
*
* @param p
* the paper that defines the borders.
* @return the bottom border.
*/
public double getBottomBorder( final Paper p ) {
return p.getHeight() - ( p.getImageableY() + p.getImageableHeight() );
}
/**
* Returns the borders for the given paper.
*
* @param p
* the paper.
* @return The borders.
*/
private static Insets getBorders( final Paper p ) {
return new Insets( (int) p.getImageableY(), (int) p.getImageableX(),
(int) ( p.getHeight() - ( p.getImageableY() + p.getImageableHeight() ) ), (int) ( p.getWidth() - ( p
.getImageableX() + p.getImageableWidth() ) ) );
}