зеркало из https://github.com/mozilla/gecko-dev.git
First Checked In.
This commit is contained in:
Родитель
e3293207a6
Коммит
c4bdaba534
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
PrintingPort.java
|
||||
|
||||
Wraps a Quickdraw printing port and provides a way to image on it
|
||||
with a java.awt.Graphics object.
|
||||
|
||||
by Patrick C. Beard.
|
||||
*/
|
||||
|
||||
package com.apple.mrj.internal.awt;
|
||||
|
||||
import com.apple.mrj.macos.generated.RectStruct;
|
||||
import com.apple.mrj.macos.generated.QuickdrawFunctions;
|
||||
import java.awt.*;
|
||||
|
||||
public class PrintingPort implements GraphicsHost {
|
||||
private int mPrintingPort;
|
||||
private int mOriginX;
|
||||
private int mOriginY;
|
||||
private PortManager mPortManager;
|
||||
private QDPipeline mPipeline;
|
||||
private Rectangle mClipping;
|
||||
|
||||
public PrintingPort(int printingPort, int originX, int originY) {
|
||||
mPrintingPort = printingPort;
|
||||
mOriginX = originX;
|
||||
mOriginY = originY;
|
||||
mPortManager = new PortManager(printingPort, 0, 0, PortManager.kPrinting, 0);
|
||||
mPipeline = new QDPipeline();
|
||||
mPortManager.setPipeline(mPipeline);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
// dispose of port manager flushes the pipeline.
|
||||
if (mPortManager != null) {
|
||||
mPortManager.dispose();
|
||||
mPortManager = null;
|
||||
}
|
||||
if (mPipeline != null) {
|
||||
mPipeline.dispose();
|
||||
mPipeline = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a graphics object that wraps the specified printing port.
|
||||
* Assumes that the underlying port's coordinate system is already
|
||||
* set up to have (0, 0) as the upper left corner.
|
||||
*/
|
||||
public Graphics getGraphics(Component component) {
|
||||
mClipping = component.getBounds();
|
||||
mClipping.x = mOriginX; mClipping.y = mOriginY;
|
||||
QDGraphics graphics = new QDPrintGraphics();
|
||||
graphics.initialize(mPrintingPort, this, mPortManager,
|
||||
mOriginX, mOriginY, mClipping, component.getForeground(),
|
||||
component.getFont());
|
||||
return graphics;
|
||||
}
|
||||
|
||||
/** methods to satisfy GraphicsHost interface. */
|
||||
public void graphicsCreated(QDGraphics g) throws OutOfMemoryError {}
|
||||
|
||||
private static final short MAXSHORT = 32767, MINSHORT = -32768;
|
||||
|
||||
static short pinToShort(int value) {
|
||||
if (value > MAXSHORT)
|
||||
return MAXSHORT;
|
||||
else if (value < MINSHORT)
|
||||
return MINSHORT;
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
public void graphicsDisposed(QDGraphics g) {
|
||||
synchronized (VToolkit.LOCK) {
|
||||
// restore the origin so that printing comes out in correct location.
|
||||
// this fixes a bug in QDGraphics, which uses SetOrigin so native components
|
||||
// come out in the right location, but causes the commands in the pipeline
|
||||
// to come out in the wrong location.
|
||||
int port = VAWTDirect.FastGetThePort();
|
||||
if (port != mPrintingPort)
|
||||
QuickdrawFunctions.SetPort(mPrintingPort);
|
||||
|
||||
// restore original orgin.
|
||||
QuickdrawFunctions.SetOrigin((short)0, (short)0);
|
||||
|
||||
// set up correct clipping.
|
||||
QDRectStruct clipRect = new QDRectStruct();
|
||||
clipRect.Set(pinToShort(mClipping.x), pinToShort(mClipping.y),
|
||||
pinToShort(mClipping.x + mClipping.width), pinToShort(mClipping.y + mClipping.width));
|
||||
QuickdrawFunctions.ClipRect(clipRect);
|
||||
|
||||
if (port != mPrintingPort)
|
||||
QuickdrawFunctions.SetPort(port);
|
||||
}
|
||||
}
|
||||
|
||||
public RGBColorValue getBackgroundRGB() { return new RGBColorValue(Color.white); }
|
||||
public void repaint(com.apple.mrj.macos.generated.RectStruct r) {}
|
||||
public boolean markInUse() { return (mPortManager != null); }
|
||||
public void doneUsingIt() {}
|
||||
}
|
Загрузка…
Ссылка в новой задаче