public int print(Graphics g1d, PageFormat pf, int pi) throws PrinterException
{
Graphics2D gfx = (Graphics2D)g1d.create();
if(titleText != null && !"".equals(titleText))
{
TextLayout tl = new TextLayout(titleText, titleFont, gfx.getFontRenderContext());
double titleHeight = tl.getBounds().getHeight() + 20;
Paper p = pf.getPaper();
Rectangle2D.Double cr = null;
Rectangle2D.Double tr = null;
if(pf.getOrientation() == PageFormat.PORTRAIT)
{
cr = new Rectangle2D.Double(p.getImageableX(),p.getImageableY()+titleHeight,
p.getImageableWidth(), p.getImageableHeight()-titleHeight);
tr = new Rectangle2D.Double(p.getImageableX(), p.getImageableY(),
p.getImageableWidth(), titleHeight);
}
else if(pf.getOrientation() == PageFormat.LANDSCAPE)
{
cr = new Rectangle2D.Double(p.getImageableX()+titleHeight,p.getImageableY(),
p.getImageableWidth()-titleHeight, p.getImageableHeight());
tr = new Rectangle2D.Double(p.getImageableX(),p.getImageableY(),
p.getImageableHeight(), titleHeight);
}
else if(pf.getOrientation() == PageFormat.REVERSE_LANDSCAPE)
{
cr = new Rectangle2D.Double(p.getImageableX(),p.getImageableY(),
p.getImageableWidth()-titleHeight, p.getImageableHeight());
tr = new Rectangle2D.Double(p.getImageableX(),p.getImageableY(),
p.getImageableHeight(), titleHeight);
}
if(titleBarColor != null)
{
gfx.setColor(Color.lightGray);
gfx.fill(tr);
}
gfx.setColor(titleColor);
Rectangle2D tlb = tl.getBounds();
tl.draw(gfx,
(float)(tr.x + (tr.width-tlb.getWidth())/2.0),
(float)(tr.y + (titleHeight + tlb.getHeight())/2.0));
pf = (PageFormat)pf.clone();
p.setImageableArea(cr.x, cr.y, cr.width, cr.height);
pf.setPaper(p);
}
return super.print(g1d, pf, pi);
}
|