Add GC-cache support to Xprint

Thanks to Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de> for the patch.
Bug #83242 r=pocemit sr=kin a=dbaron
This commit is contained in:
cls%seawood.org 2001-06-21 03:07:06 +00:00
Родитель 8dec4d01ce
Коммит fc20f6bf00
9 изменённых файлов: 1273 добавлений и 1065 удалений

Просмотреть файл

@ -75,7 +75,7 @@ endif
EXTRA_DSO_LDOPTS += \
$(NSPR_LIBS) \
-lxpcom \
-lxpcom \
-lgkgfx \
$(GFX_XIE_LIBS) \
$(NULL)
@ -88,6 +88,7 @@ endif
ifdef MOZ_ENABLE_XPRINT
DEFINES += -DUSE_XPRINT
INCLUDES += -I$(srcdir)/../xprint
endif
INCLUDES += \

Просмотреть файл

@ -341,12 +341,12 @@ typedef struct nsFontLangGroupXlib {
nsIAtom* mLangGroup;
} FontLangGroup;
nsFontLangGroupXlib FLG_WESTERN = { "x-western", nsnull };
nsFontLangGroupXlib FLG_ZHCN = { "zh-CN", nsnull };
nsFontLangGroupXlib FLG_ZHTW = { "zh-TW", nsnull };
nsFontLangGroupXlib FLG_JA = { "ja", nsnull };
nsFontLangGroupXlib FLG_KO = { "ko", nsnull };
nsFontLangGroupXlib FLG_NONE = { nsnull , nsnull };
static nsFontLangGroupXlib FLG_WESTERN = { "x-western", nsnull };
static nsFontLangGroupXlib FLG_ZHCN = { "zh-CN", nsnull };
static nsFontLangGroupXlib FLG_ZHTW = { "zh-TW", nsnull };
static nsFontLangGroupXlib FLG_JA = { "ja", nsnull };
static nsFontLangGroupXlib FLG_KO = { "ko", nsnull };
static nsFontLangGroupXlib FLG_NONE = { nsnull , nsnull };
/*
* Normally, the charset of an X font can be determined simply by looking at
@ -661,8 +661,8 @@ FreeNodeArray(nsHashKey* aKey, void* aData, void* aClosure)
return PR_TRUE;
}
static void
FreeGlobals(void)
void
nsFontMetricsXlib::FreeGlobals(void)
{
gInitialized = 0;
@ -728,8 +728,8 @@ FreeGlobals(void)
/*
* Initialize all the font lookup hash tables and other globals
*/
static nsresult
InitGlobals(void)
nsresult
nsFontMetricsXlib::InitGlobals(void)
{
nsServiceManager::GetService(kCharSetManagerCID,
NS_GET_IID(nsICharsetConverterManager2),
@ -931,6 +931,18 @@ FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
return PR_TRUE;
}
#ifdef USE_XPRINT
/* does this nsFont(Metrics)Xlib class operate on a Xprt (X11 print server) ? */
PRPackedBool nsFontMetricsXlib::mPrinterMode = PR_FALSE;
void
nsFontMetricsXlib::EnablePrinterMode(PRBool printermode)
{
mPrinterMode = printermode;
}
#endif /* USE_XPRINT */
NS_IMETHODIMP
nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext* aContext)
@ -1708,6 +1720,19 @@ nsFontXlib::LoadFont(void)
NS_ASSERTION(!mFont, "Font already loaded.");
Display *aDisplay = xlib_rgb_get_display();
#ifdef USE_XPRINT
if (nsFontMetricsXlib::mPrinterMode)
{
if (XpGetContext(aDisplay) == None)
{
/* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */
NS_ERROR("Obtaining font information without a valid print context (XLoadQueryFont()) _before_ XpSetContext()\n");
abort();
}
}
#endif /* USE_XPRINT */
XFontStruct *xlibFont = XLoadQueryFont(aDisplay, mName);
if (xlibFont) {
@ -1767,6 +1792,13 @@ public:
nsDrawingSurfaceXlib* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength);
#ifdef USE_XPRINT
virtual int DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength);
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
@ -1872,6 +1904,69 @@ nsFontXlibNormal::DrawString(nsRenderingContextXlib* aContext,
return textWidth;
}
#ifdef USE_XPRINT
int
nsFontXlibNormal::DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength)
{
if (!mFont) {
LoadFont();
if (!mFont)
return 0;
}
XChar2b buf[512];
char *p;
PRInt32 bufLen;
int textWidth;
ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mCharSetInfo->mConverter,
aString, aLength, buf, sizeof(buf), bufLen);
int len = mCharSetInfo->Convert(mCharSetInfo, mFont, aString, aLength,
p, bufLen);
xGC *gc = aContext->GetGC();
if ((mFont->min_byte1 == 0) && (mFont->max_byte1 == 0)) {
XDrawString(aSurface->GetDisplay(),
aSurface->GetDrawable(),
*gc,
aX, aY + mBaselineAdjust, p, len);
gc->Release();
textWidth = XTextWidth(mFont, p, len);
}
else
{
/* XXX is this the right way to do it? Can I get GCCache to give me a
* new GC? */
GC copyGC;
XGCValues values;
memset(&values, 0, sizeof(XGCValues));
XGetGCValues(aSurface->GetDisplay(), *gc, GCForeground | GCBackground,
&values);
values.font = mFont->fid;
copyGC = XCreateGC(aSurface->GetDisplay(), aSurface->GetDrawable(),
GCForeground | GCBackground | GCFont, &values);
/* note the length must be divided by 2 for X*16 functions */
XDrawString16(aSurface->GetDisplay(),
aSurface->GetDrawable(),
copyGC,
aX, aY + mBaselineAdjust, (XChar2b *)p, len / 2);
XFreeGC(aSurface->GetDisplay(), copyGC);
gc->Release();
textWidth = XTextWidth16(mFont, (XChar2b *)p, len / 2);
}
ENCODER_BUFFER_FREE_IF_NEEDED(p, buf);
return textWidth;
}
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
nsresult
nsFontXlibNormal::GetBoundingMetrics(const PRUnichar* aString,
@ -1933,6 +2028,12 @@ public:
nsDrawingSurfaceXlib* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength);
#ifdef USE_XPRINT
virtual int DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength);
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
@ -2064,6 +2165,34 @@ nsFontXlibSubstitute::DrawString(nsRenderingContextXlib* aContext,
return textWidth;
}
#ifdef USE_XPRINT
int
nsFontXlibSubstitute::DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength)
{
PRUnichar buf[512];
PRUnichar *p = buf;
PRUint32 bufLen = sizeof(buf) / sizeof(PRUnichar);
if ((aLength * 2) > bufLen) {
PRUnichar *tmp;
tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength * 2));
if (tmp) {
p = tmp;
bufLen = (aLength * 2);
}
}
PRUint32 len = Convert(aString, aLength, p, bufLen);
int textWidth = mSubstituteFont->DrawString(aContext, aSurface,
aX, aY, p, len);
if (p != buf)
nsMemory::Free(p);
return textWidth;
}
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
// bounding metrics for a string
// remember returned values are not in app units
@ -2108,6 +2237,12 @@ public:
nsDrawingSurfaceXlib* aSurface,
nscoord aX, nscoord aY, const PRUnichar* aString,
PRUint32 aLength);
#ifdef USE_XPRINT
virtual int DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength);
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
virtual nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
@ -2200,6 +2335,37 @@ nsFontXlibUserDefined::DrawString(nsRenderingContextXlib* aContext,
return textWidth;
}
#ifdef USE_XPRINT
int
nsFontXlibUserDefined::DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength)
{
char buf[1024];
char *p;
PRInt32 bufLen;
ENCODER_BUFFER_ALLOC_IF_NEEDED(p, gUserDefinedConverter,
aString, aLength, buf, sizeof(buf), bufLen);
PRUint32 len = Convert(aString, aLength, p, bufLen);
xGC *gc = aContext->GetGC();
XDrawString(aSurface->GetDisplay(),
aSurface->GetDrawable(),
*gc,
aX, aY + mBaselineAdjust, p, len);
gc->Release();
int textWidth = XTextWidth(mFont, p, len);
ENCODER_BUFFER_FREE_IF_NEEDED(p, buf);
return textWidth;
}
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
nsresult
nsFontXlibUserDefined::GetBoundingMetrics(const PRUnichar* aString,
@ -2678,6 +2844,17 @@ GetFontNames(const char* aPattern, nsFontNodeArrayXlib* aNodes)
{
nsCAutoString previousNodeName;
#ifdef USE_XPRINT
if(nsFontMetricsXlib::mPrinterMode)
{
if (XpGetContext(xlib_rgb_get_display()) == None)
{
/* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */
NS_ERROR("Obtaining font information without valid print context (XListFonts()) _before_ XpSetContext()");
abort(); /* DIE!! */
}
}
#endif /* USE_XPRINT */
int count;
char** list = ::XListFonts(xlib_rgb_get_display(), aPattern, INT_MAX, &count);
if ((!list) || (count < 1)) {

Просмотреть файл

@ -34,6 +34,11 @@
#include "nsCOMPtr.h"
#include "nsDeviceContextXlib.h"
#include "nsDrawingSurfaceXlib.h"
#ifdef USE_XPRINT
#include "nsDeviceContextXP.h"
#include "nsXPrintContext.h"
#include "nsRenderingContextXP.h"
#endif /* USE_XPRINT */
#include "nsFont.h"
#include "nsRenderingContextXlib.h"
#include "nsString.h"
@ -81,6 +86,13 @@ public:
nsDrawingSurfaceXlib* aSurface,
nscoord aX, nscoord aY,
const PRUnichar* aString, PRUint32 aLength) = 0;
#ifdef USE_XPRINT
virtual int DrawString(nsRenderingContextXp* aContext,
nsXPrintContext* aSurface,
nscoord aX,
nscoord aY, const PRUnichar* aString,
PRUint32 aLength) = 0;
#endif /* USE_XPRINT */
#ifdef MOZ_MATHML
// bounding metrics for a string
@ -90,7 +102,7 @@ public:
GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics) = 0;
#endif
#endif /* MOZ_MATHML */
XFontStruct *mFont;
PRUint32 *mMap;
@ -107,6 +119,13 @@ public:
nsFontMetricsXlib();
virtual ~nsFontMetricsXlib();
#ifdef USE_XPRINT
static void EnablePrinterMode(PRBool printermode);
#endif /* USE_XPRINT */
static nsresult InitGlobals(void);
static void FreeGlobals(void);
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
@ -211,6 +230,11 @@ protected:
PRUint16 mPixelSize;
PRUint8 mStretchIndex;
PRUint8 mStyleIndex;
#ifdef USE_XPRINT
public:
static PRPackedBool mPrinterMode;
#endif /* USE_XPRINT */
};
class nsFontEnumeratorXlib : public nsIFontEnumerator

Просмотреть файл

@ -43,11 +43,12 @@ CSRCS = \
CPPSRCS = \
nsDeviceContextXP.cpp \
nsFontMetricsXP.cpp \
nsFontMetricsXlib.cpp \
nsRenderingContextXP.cpp \
nsGfxFactoryXP.cpp \
nsXPrintContext.cpp \
nsRegionXlib.cpp \
nsGCCache.cpp \
$(NULL)
EXPORTS = \
@ -64,7 +65,7 @@ EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_GFXONXP -DUSE_MOZILLA_TYPES
DEFINES += -D_IMPL_NS_GFXONXP -DUSE_MOZILLA_TYPES -DUSE_XPRINT
ifeq ($(OS_ARCH), Linux)
DEFINES += -D_BSD_SOURCE
endif
@ -83,4 +84,5 @@ INCLUDES += \
-I$(srcdir)/../gtk \
-I$(srcdir)/../xlib \
-I$(srcdir)/../xlibrgb \
-I$(srcdir)/../xprint \
$(NULL)

Просмотреть файл

@ -30,10 +30,12 @@
#include "nsDeviceContextXP.h"
#include "nsRenderingContextXP.h"
#include "nsString.h"
#include "nsFontMetricsXP.h"
#include "nsFontMetricsXlib.h"
#include "xlibrgb.h"
#include "X11/Xatom.h"
#include "nsIDeviceContext.h"
#include "nsIDeviceContextSpecXPrint.h"
#include "nsString.h"
#include "il_util.h"
#include "nspr.h"
#include "nsXPrintContext.h"
@ -50,12 +52,9 @@ static NS_DEFINE_IID(kIDeviceContextSpecXPIID, NS_IDEVICE_CONTEXT_SPEC_XP_IID);
nsDeviceContextXp :: nsDeviceContextXp()
{
NS_INIT_REFCNT();
/* Inherited from xlib device context code */
//mTwipsToPixels = 1.0;
//mPixelsToTwips = 1.0;
mPrintContext = nsnull;
mSpec = nsnull;
mParentDeviceContext = nsnull;
mPrintContext = nsnull;
mSpec = nsnull;
mParentDeviceContext = nsnull;
NS_NewISupportsArray(getter_AddRefs(mFontMetrics));
}
@ -127,13 +126,14 @@ nsDeviceContextXp::InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext,
mAppUnitsToDevUnits = (a2d / t2d) * mTwipsToPixels;
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
// mPrintContext->GetAppUnitsToDevUnits(mAppUnitsToDevUnits);
// mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
mParentDeviceContext = aParentContext;
NS_ASSERTION(mParentDeviceContext, "aCreatingDeviceContext cannot be NULL!!!");
NS_ADDREF(mParentDeviceContext);
/* be sure we've cleaned-up old rubbish - new values will re-populate nsFontMetricsXlib soon... */
nsFontMetricsXlib::FreeGlobals();
nsFontMetricsXlib::EnablePrinterMode(PR_TRUE);
return NS_OK;
}
@ -173,8 +173,8 @@ NS_IMETHODIMP nsDeviceContextXp :: GetScrollBarDimensions(float &aWidth,
float &aHeight) const
{
// XXX Oh, yeah. These are hard coded.
aWidth = 15 * mPixelsToTwips;
aHeight = 15 * mPixelsToTwips;
aWidth = 15.f * mPixelsToTwips;
aHeight = 15.f * mPixelsToTwips;
return NS_OK;
}
@ -245,8 +245,10 @@ NS_IMETHODIMP nsDeviceContextXp::GetILColorSpace(IL_ColorSpace*& aColorSpace)
*/
NS_IMETHODIMP nsDeviceContextXp :: CheckFontExistence(const nsString& aFontName)
{
PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::CheckFontExistence()\n"));
return nsFontMetricsXp::FamilyExists(aFontName);
PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG,
("nsDeviceContextXp::CheckFontExistence('%s')\n",
NS_ConvertUCS2toUTF8(aFontName).get()));
return nsFontMetricsXlib::FamilyExists(aFontName);
}
NS_IMETHODIMP nsDeviceContextXp :: GetSystemAttribute(nsSystemAttrID anID,
@ -328,6 +330,10 @@ NS_IMETHODIMP nsDeviceContextXp::EndDocument(void)
// or the printer used on the same print server has other
// properties (build-in fonts for example ) than the printer
// previously used
mFontMetrics = nsnull; /* nsCOMPtr will release/free all objects */
nsRenderingContextXp::Shutdown();
nsFontMetricsXlib::FreeGlobals();
delete mPrintContext;
mPrintContext = nsnull;
}
@ -406,8 +412,8 @@ NS_IMETHODIMP nsDeviceContextXp::GetMetricsFor(const nsFont& aFont,
NS_IMETHODIMP nsDeviceContextXp::GetMetricsFor(const nsFont& aFont,
nsIFontMetrics *&aMetrics)
{
PRUint32 n,cnt;
nsresult rv;
PRUint32 n, cnt;
nsresult rv;
// First check our cache
rv = mFontMetrics->Count(&n);
@ -431,7 +437,7 @@ NS_IMETHODIMP nsDeviceContextXp::GetMetricsFor(const nsFont& aFont,
}
// It's not in the cache. Get font metrics and then cache them.
nsCOMPtr<nsIFontMetrics> fm = new nsFontMetricsXp();
nsCOMPtr<nsIFontMetrics> fm = new nsFontMetricsXlib();
if (!fm) {
aMetrics = nsnull;
return NS_ERROR_FAILURE;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -38,29 +38,26 @@
#include "nsVoidArray.h"
#include "nsRegionXlib.h"
class XP_State;
#include "nsImageXlib.h" // nsGCCache.h wants this
#include "nsGCCache.h"
class nsXPrintContext;
class nsRenderingContextXp : public nsRenderingContextImpl
{
public:
public:
nsRenderingContextXp();
virtual ~nsRenderingContextXp();
static nsresult Shutdown(); // release statics
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
// nsIPrinterRenderingContext methods
protected:
public:
// nsIRenderingContext
NS_IMETHOD Init(nsIDeviceContext* aContext);
NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget) { return NS_OK; }
NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface){return NS_OK;}
NS_IMETHOD Reset(void);
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
@ -77,7 +74,7 @@ public:
NS_IMETHOD PushState(void);
NS_IMETHOD PopState(PRBool &aClipState);
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aClipState);
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aCilpState);
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipState);
@ -108,6 +105,7 @@ public:
NS_IMETHOD DrawRect(const nsRect& aRect);
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawStdLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
NS_IMETHOD FillRect(const nsRect& aRect);
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
@ -123,9 +121,6 @@ public:
NS_IMETHOD FillEllipse(const nsRect& aRect);
NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawTile(nsIImage *aImage,nscoord aX0,nscoord aY0,nscoord aX1,
nscoord aY1, nscoord aWidth,nscoord aHeight);
NS_IMETHOD DrawArc(const nsRect& aRect,
float aStartAngle, float aEndAngle);
NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
@ -162,17 +157,19 @@ public:
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aRect);
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect);
#ifdef USE_IMG2
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
#endif
#endif /* USE_IMG2 */
NS_IMETHOD DrawTile(nsIImage *aImage,nscoord aX, nscoord aY, const nsRect&);
NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
const nsRect &aDestBounds, PRUint32 aCopyFlags);
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 * ngd);
nsXPrintContext *GetXPrintContext() { return mPrintContext; }
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string
@ -180,7 +177,7 @@ public:
NS_IMETHOD GetBoundingMetrics(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
/**
* Returns metrics (in app units) of a Unicode character string
*/
@ -190,23 +187,53 @@ public:
PRInt32* aFontID = nsnull);
#endif /* MOZ_MATHML */
private:
// this is a common init function for both of the init functions.
nsresult CommonInit(void);
void SetupFontAndColor(void);
void PushClipState(void);
protected:
nsCOMPtr<nsIDeviceContextXp> mContext;
nsXPrintContext *mPrintContext;
nsIFontMetrics *mFontMetrics;
nsRegionXlib *mClipRegion;
float mP2T;
nscolor mCurrentColor;
xGC *GetGC() { mGC->AddRef(); return mGC; };
nsLineStyle mCurrLineStyle;
XP_State *mStates;
nsVoidArray *mStateCache;
XFontStruct *mCurrentFont;
private:
void UpdateGC();
nsXPrintContext *mPrintContext;
nsCOMPtr<nsIDeviceContextXp> mContext;
nsIFontMetrics *mFontMetrics;
nsCOMPtr<nsIRegion> mClipRegion;
float mP2T;
nscolor mCurrentColor;
Display * mDisplay;
Screen * mScreen;
Visual * mVisual;
int mDepth;
xGC *mGC;
// graphics state stuff
nsVoidArray *mStateCache;
XFontStruct *mCurrentFont;
nsLineStyle mCurrentLineStyle;
int mFunction;
int mLineStyle;
char *mDashList;
int mDashes;
// ConditionRect is used to fix coordinate overflow problems for
// rectangles after they are transformed to screen coordinates
void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h) {
if ( y < -32766 ) {
y = -32766;
}
if ( y + h > 32766 ) {
h = 32766 - y;
}
if ( x < -32766 ) {
x = -32766;
}
if ( x + w > 32766 ) {
w = 32766 - x;
}
}
};

Просмотреть файл

@ -33,7 +33,7 @@
#include "prenv.h" /* for PR_GetEnv */
/* misc defines */
// #define HACK_PRINTONSCREEN 1
//#define HACK_PRINTONSCREEN 1
#define XPRINT_MAKE_24BIT_VISUAL_AVAILABLE_FOR_TESTING 1
#ifdef XPRINT_NOT_YET /* ToDo: make this dynamically */
@ -74,7 +74,6 @@ nsXPrintContext::nsXPrintContext()
mPContext = (XPContext)None;
mScreen = (Screen *)nsnull;
mVisual = (Visual *)nsnull;
mGC = (GC)None;
mDrawable = (Drawable)None;
mDepth = 0;
mIsGrayscale = PR_FALSE; /* default is color output */
@ -90,7 +89,17 @@ nsXPrintContext::~nsXPrintContext()
// end the document
if( mPDisplay != nsnull )
EndDocument();
{
XpDestroyContext(mPDisplay, mPContext);
// Cleanup things allocated along the way
xlib_rgb_detach();
XCloseDisplay(mPDisplay);
mPContext = nsnull;
mPDisplay = nsnull;
}
}
NS_IMETHODIMP
@ -172,8 +181,6 @@ nsXPrintContext::SetupWindow(int x, int y, int width, int height)
Window parent_win;
XVisualInfo *visual_info;
unsigned long gcmask;
XGCValues gcvalues;
XSetWindowAttributes xattributes;
long xattributes_mask;
unsigned long background,
@ -201,17 +208,11 @@ nsXPrintContext::SetupWindow(int x, int y, int width, int height)
width, height, 0,
mDepth, InputOutput, mVisual, xattributes_mask,
&xattributes);
gcmask = GCBackground | GCForeground | GCFunction;
gcvalues.background = background;
gcvalues.foreground = foreground;
gcvalues.function = GXcopy;
mGC = XCreateGC(mPDisplay, mDrawable, gcmask, &gcvalues); /* ToDo: Check for error */
/* %p would be better instead of %lx for pointers - but does PR_LOG() support that ? */
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG,
("nsXPrintContext::SetupWindow: mDepth=%d, mScreenNumber=%d, colormap=%lx, mDrawable=%lx, mGC=%lx\n",
(int)mDepth, (int)mScreenNumber, (long)xattributes.colormap, (long)mDrawable, (long)mGC));
("nsXPrintContext::SetupWindow: mDepth=%d, mScreenNumber=%d, colormap=%lx, mDrawable=%lx\n",
(int)mDepth, (int)mScreenNumber, (long)xattributes.colormap, (long)mDrawable));
return NS_OK;
}
@ -419,15 +420,6 @@ nsXPrintContext::EndDocument()
sleep(15);
}
#endif /* HACK_PRINTONSCREEN */
// Cleanup things allocated along the way
xlib_rgb_detach();
XpDestroyContext(mPDisplay, mPContext);
XCloseDisplay(mPDisplay);
mPContext = nsnull;
mPDisplay = nsnull;
return NS_OK;
}
@ -480,7 +472,16 @@ GetScaledXImage(XImage *img,
for(dy = 0 ; dy < newHeight ; dy++)
{
sy = dy * factorY;
#ifdef XPRINT_USE_SLOW_BUT_EASY_CODE
XPutPixel(newImg, dx, dy, XGetPixel(img, sx, sy));
#else
/* quick&dirty - but this is still legal because XInitImage() has
* initalized the function pointers
* This shortcut avoids tons of test in XGetPixel()/XPutPixel()
* which are not neccesary here...
*/
(*newImg->f.put_pixel)(newImg, dx, dy, (*img->f.get_pixel)(img, sx, sy));
#endif /* XPRINT_USE_SLOW_BUT_EASY_CODE */
}
}
@ -489,7 +490,7 @@ GetScaledXImage(XImage *img,
NS_IMETHODIMP
nsXPrintContext::DrawImage(nsIImage *aImage,
nsXPrintContext::DrawImage(xGC *xgc, nsIImage *aImage,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
{
@ -537,12 +538,12 @@ nsXPrintContext::DrawImage(nsIImage *aImage,
if( (aSX != 0) || (aSY != 0) || (aSWidth != aDWidth_scaled) || (aSHeight != aDHeight_scaled) )
{
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using DrawImageBitsScaled()\n"));
rv = DrawImageBitsScaled(aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
rv = DrawImageBitsScaled(xgc, aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
}
else
{
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("using DrawImage() [shortcut]\n"));
rv = DrawImage(aImage, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
rv = DrawImage(xgc, aImage, aDX, aDY, aDWidth_scaled, aDHeight_scaled);
}
/* reset image resolution to previous resolution */
@ -555,7 +556,7 @@ nsXPrintContext::DrawImage(nsIImage *aImage,
(void)XpSetImageResolution(mPDisplay, mPContext, prev_res, &dummy);
/* scale image on our side (bad) */
rv = DrawImageBitsScaled(aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight);
rv = DrawImageBitsScaled(xgc, aImage, aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight);
}
return rv;
@ -564,7 +565,7 @@ nsXPrintContext::DrawImage(nsIImage *aImage,
// use DeviceContextImpl :: GetCanonicalPixelScale(float &aScale)
// to get the pixel scale of the device context
nsresult
nsXPrintContext::DrawImageBitsScaled(nsIImage *aImage,
nsXPrintContext::DrawImageBitsScaled(xGC *xgc, nsIImage *aImage,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
{
@ -679,7 +680,8 @@ nsXPrintContext::DrawImageBitsScaled(nsIImage *aImage,
aDWidth, aDHeight);
PR_LOG(nsXPrintContextLM, PR_LOG_DEBUG, ("rendering ALPHA image !!\n"));
rv = DrawImageBits((PRUint8 *)dstAlphaImg->data, dstAlphaImg->bytes_per_line,
rv = DrawImageBits(xgc,
(PRUint8 *)dstAlphaImg->data, dstAlphaImg->bytes_per_line,
(PRUint8 *)dstImg->data, dstImg->bytes_per_line,
aDX, aDY, aDWidth, aDHeight);
@ -689,7 +691,7 @@ nsXPrintContext::DrawImageBitsScaled(nsIImage *aImage,
{
/* shortcut */
xlib_draw_rgb_image(mDrawable,
mGC,
*xgc,
aDX, aDY, aDWidth, aDHeight,
NS_XPRINT_RGB_DITHER,
(unsigned char *)dstImg->data, dstImg->bytes_per_line);
@ -730,7 +732,7 @@ nsXPrintContext::DrawImageBitsScaled(nsIImage *aImage,
NS_IMETHODIMP
nsXPrintContext::DrawImage(nsIImage *aImage,
nsXPrintContext::DrawImage(xGC *xgc, nsIImage *aImage,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
{
@ -759,7 +761,7 @@ nsXPrintContext::DrawImage(nsIImage *aImage,
return NS_OK;
}
return DrawImageBits(alphaBits, alphaRowBytes,
return DrawImageBits(xgc, alphaBits, alphaRowBytes,
image_bits, row_bytes,
aX, aY, aWidth, aHeight);
}
@ -767,7 +769,8 @@ nsXPrintContext::DrawImage(nsIImage *aImage,
// Draw the bitmap, this draw just has destination coordinates
nsresult
nsXPrintContext::DrawImageBits(PRUint8 *alphaBits, PRInt32 alphaRowBytes,
nsXPrintContext::DrawImageBits(xGC *xgc,
PRUint8 *alphaBits, PRInt32 alphaRowBytes,
PRUint8 *image_bits, PRInt32 row_bytes,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight)
@ -814,8 +817,9 @@ nsXPrintContext::DrawImageBits(PRUint8 *alphaBits, PRInt32 alphaRowBytes,
// Write into the pixemap that is underneath gdk's alpha_pixmap
// the image we just created.
memset(&gcv, 0, sizeof(XGCValues)); /* this may be unneccesary */
XGetGCValues(mPDisplay, *xgc, GCForeground|GCBackground, &gcv);
gcv.function = GXcopy;
gc = XCreateGC(mPDisplay, alpha_pixmap, GCFunction, &gcv);
gc = XCreateGC(mPDisplay, alpha_pixmap, GCForeground|GCBackground|GCFunction, &gcv);
XPutImage(mPDisplay, alpha_pixmap, gc, x_image, 0, 0, 0, 0,
aWidth, aHeight);
@ -831,18 +835,22 @@ nsXPrintContext::DrawImageBits(PRUint8 *alphaBits, PRInt32 alphaRowBytes,
/* create copy of GC before start to playing with it... */
XGCValues gcv;
memset(&gcv, 0, sizeof(XGCValues)); /* this may be unneccesary */
gcv.function = GXcopy;
image_gc = XCreateGC(mPDisplay, mDrawable, GCFunction, &gcv);
// set up the gc to use the alpha pixmap for clipping
XSetClipOrigin(mPDisplay, image_gc, aX, aY);
XSetClipMask(mPDisplay, image_gc, alpha_pixmap);
XGetGCValues(mPDisplay, *xgc, GCForeground|GCBackground, &gcv);
gcv.function = GXcopy;
gcv.clip_mask = alpha_pixmap;
gcv.clip_x_origin = aX;
gcv.clip_y_origin = aY;
image_gc = XCreateGC(mPDisplay, mDrawable,
(GCForeground|GCBackground|GCFunction|
GCClipXOrigin|GCClipYOrigin|GCClipMask),
&gcv);
}
else
{
/* this assumes that xlib_draw_rgb_image()/xlib_draw_gray_image()
* does not change the GC... */
image_gc = mGC;
image_gc = *xgc;
}
if( mIsGrayscale )
@ -863,10 +871,7 @@ nsXPrintContext::DrawImageBits(PRUint8 *alphaBits, PRInt32 alphaRowBytes,
}
if( alpha_pixmap != None )
{
XSetClipOrigin(mPDisplay, image_gc, 0, 0);
XSetClipMask(mPDisplay, image_gc, None);
{
XFreeGC(mPDisplay, image_gc);
XFreePixmap(mPDisplay, alpha_pixmap);
}
@ -883,10 +888,3 @@ NS_IMETHODIMP nsXPrintContext::GetPrintResolution(int &aPrintResolution) const
return NS_OK;
}
NS_IMETHODIMP nsXPrintContext::SetForegroundColor(nscolor aColor)
{
xlib_rgb_gc_set_foreground(mGC,
NS_RGB(NS_GET_B(aColor), NS_GET_G(aColor), NS_GET_R(aColor)));
return NS_OK;
}

Просмотреть файл

@ -35,6 +35,9 @@
#include "nsString.h"
#include "nsIImage.h"
#include "nsImageXlib.h" // nsGCCache.h wants this
#include "nsGCCache.h"
#include "nsIDeviceContextSpecXPrint.h"
class nsDeviceContextXp;
@ -51,8 +54,7 @@ public:
NS_IMETHOD BeginDocument(PRUnichar *aTitle);
NS_IMETHOD EndDocument();
GC GetGC(void) { return mGC; }
Drawable GetDrawable(void) { return (mDrawable); }
Drawable GetDrawable() { return (mDrawable); }
Screen * GetScreen() { return mScreen; }
Visual * GetVisual() { return mVisual; }
int GetDepth() { return mDepth; }
@ -63,23 +65,20 @@ public:
Display * GetDisplay() { return mPDisplay; }
NS_IMETHOD GetPrintResolution(int &aPrintResolution) const;
NS_IMETHOD DrawImage(nsIImage *aImage,
NS_IMETHOD DrawImage(xGC *gc, nsIImage *aImage,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
NS_IMETHOD DrawImage(nsIImage *aImage,
NS_IMETHOD DrawImage(xGC *gc, nsIImage *aImage,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD SetForegroundColor(nscolor aColor);
private:
nsresult DrawImageBitsScaled(nsIImage *aImage,
nsresult DrawImageBitsScaled(xGC *gc, nsIImage *aImage,
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
nsresult DrawImageBits(PRUint8 *alphaBits, PRInt32 alphaRowBytes,
nsresult DrawImageBits(xGC *gc, PRUint8 *alphaBits, PRInt32 alphaRowBytes,
PRUint8 *image_bits, PRInt32 row_bytes,
PRInt32 aX, PRInt32 aY,
PRInt32 aWidth, PRInt32 aHeight);