* This is the case when we use the values from the attribute set.
*/
Media media = (Media)attributes.get(Media.class);
OrientationRequested orientReq =
(OrientationRequested)attributes.get(OrientationRequested.class);
MediaPrintableArea mpa =
(MediaPrintableArea)attributes.get(MediaPrintableArea.class);
if ((orientReq != null || media != null || mpa != null) &&
getPageable() instanceof OpenBook) {
/* We could almost(!) use PrinterJob.getPageFormat() except
* here we need to start with the PageFormat from the OpenBook :
*/
Pageable pageable = getPageable();
Printable printable = pageable.getPrintable(0);
PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
Paper paper = pf.getPaper();
/* If there's a media but no media printable area, we can try
* to retrieve the default value for mpa and use that.
*/
if (mpa == null && media != null &&
service.
isAttributeCategorySupported(MediaPrintableArea.class)) {
Object mpaVals = service.
getSupportedAttributeValues(MediaPrintableArea.class,
null, attributes);
if (mpaVals instanceof MediaPrintableArea[] &&
((MediaPrintableArea[])mpaVals).length > 0) {
mpa = ((MediaPrintableArea[])mpaVals)[0];
}
}
if (isSupportedValue(orientReq, attributes) ||
(!fidelity && orientReq != null)) {
int orient;
if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
orient = PageFormat.REVERSE_LANDSCAPE;
} else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
orient = PageFormat.LANDSCAPE;
} else {
orient = PageFormat.PORTRAIT;
}
pf.setOrientation(orient);
}
if (isSupportedValue(media, attributes) ||
(!fidelity && media != null)) {
if (media instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName)media;
MediaSize msz = MediaSize.getMediaSizeForName(msn);
if (msz != null) {
float paperWid = msz.getX(MediaSize.INCH) * 72.0f;
float paperHgt = msz.getY(MediaSize.INCH) * 72.0f;
paper.setSize(paperWid, paperHgt);
if (mpa == null) {
paper.setImageableArea(72.0, 72.0,
paperWid-144.0,
paperHgt-144.0);
}
}
}
}
if (isSupportedValue(mpa, attributes) ||
(!fidelity && mpa != null)) {
float [] printableArea =
mpa.getPrintableArea(MediaPrintableArea.INCH);
for (int i=0; i < printableArea.length; i++) {
printableArea[i] = printableArea[i]*72.0f;
}
paper.setImageableArea(printableArea[0], printableArea[1],
printableArea[2], printableArea[3]);