mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
First Checked In.
This commit is contained in:
parent
a67977bcdd
commit
bcb4633b7a
532
gfx/src/mac/nsDeviceContextMac.cpp
Normal file
532
gfx/src/mac/nsDeviceContextMac.cpp
Normal file
@ -0,0 +1,532 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextMac.h"
|
||||
#include "nsRenderingContextMac.h"
|
||||
//XXX#include "../nsGfxCIID.h"
|
||||
|
||||
#include "math.h"
|
||||
#include "nspr.h"
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
|
||||
#define NS_TO_X_COMPONENT(a) ((a << 8) | (a))
|
||||
|
||||
#define NS_TO_X_RED(a) (((NS_GET_R(a) >> (8 - mRedBits)) << mRedOffset) & mRedMask)
|
||||
#define NS_TO_X_GREEN(a) (((NS_GET_G(a) >> (8 - mGreenBits)) << mGreenOffset) & mGreenMask)
|
||||
#define NS_TO_X_BLUE(a) (((NS_GET_B(a) >> (8 - mBlueBits)) << mBlueOffset) & mBlueMask)
|
||||
|
||||
#define NS_TO_X(a) (NS_TO_X_RED(a) | NS_TO_X_GREEN(a) | NS_TO_X_BLUE(a))
|
||||
|
||||
|
||||
nsDeviceContextMac :: nsDeviceContextMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
/*mFontCache = nsnull;
|
||||
mSurface = nsnull;
|
||||
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
|
||||
mDevUnitsToAppUnits = 1.0f;
|
||||
mAppUnitsToDevUnits = 1.0f;
|
||||
|
||||
mGammaValue = 1.0f;
|
||||
mGammaTable = new PRUint8[256];
|
||||
|
||||
mZoom = 1.0f;
|
||||
|
||||
mVisual = nsnull;
|
||||
|
||||
mRedMask = 0;
|
||||
mGreenMask = 0;
|
||||
mBlueMask = 0;
|
||||
|
||||
mRedBits = 0;
|
||||
mGreenBits = 0;
|
||||
mBlueBits = 0;
|
||||
|
||||
mRedOffset = 0;
|
||||
mGreenOffset = 0;
|
||||
mBlueOffset = 0;
|
||||
|
||||
mNativeWidget = nsnull;
|
||||
|
||||
mDepth = 0 ;
|
||||
mColormap = 0 ;*/
|
||||
}
|
||||
|
||||
nsDeviceContextMac :: ~nsDeviceContextMac()
|
||||
{
|
||||
// XXX Does the Mac have gamma stuff in quickdraw so we don't have to write our own?
|
||||
|
||||
/*if (nsnull != mGammaTable)
|
||||
{
|
||||
delete mGammaTable;
|
||||
mGammaTable = nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mFontCache);
|
||||
|
||||
if (mSurface) delete mSurface;*/
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextMac, kDeviceContextIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextMac)
|
||||
NS_IMPL_RELEASE(nsDeviceContextMac)
|
||||
|
||||
nsresult nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget)
|
||||
{
|
||||
NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget");
|
||||
|
||||
/*for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
mGammaTable[cnt] = cnt;*/
|
||||
|
||||
// XXX We really need to have Display passed to us since it could be specified
|
||||
// not from the environment, which is the one we use here.
|
||||
|
||||
/* XXX rewrite for mac
|
||||
mNativeWidget = aNativeWidget;
|
||||
|
||||
if (nsnull != mNativeWidget)
|
||||
{
|
||||
mTwipsToPixels = (((float)::XDisplayWidth(XtDisplay((Widget)mNativeWidget), DefaultScreen(XtDisplay((Widget)mNativeWidget)))) /
|
||||
((float)::XDisplayWidthMM(XtDisplay((Widget)mNativeWidget),DefaultScreen(XtDisplay((Widget)mNativeWidget)) )) * 25.4) /
|
||||
NS_POINTS_TO_TWIPS_FLOAT(72.0f);
|
||||
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
}*/
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetTwipsToDevUnits() const
|
||||
{
|
||||
//return mTwipsToPixels;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetDevUnitsToTwips() const
|
||||
{
|
||||
// return mPixelsToTwips;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
void nsDeviceContextMac :: SetAppUnitsToDevUnits(float aAppUnits)
|
||||
{
|
||||
// mAppUnitsToDevUnits = aAppUnits;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetDevUnitsToAppUnits(float aDevUnits)
|
||||
{
|
||||
// mDevUnitsToAppUnits = aDevUnits;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetAppUnitsToDevUnits() const
|
||||
{
|
||||
//return mAppUnitsToDevUnits;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetDevUnitsToAppUnits() const
|
||||
{
|
||||
// return mDevUnitsToAppUnits;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetScrollBarWidth() const
|
||||
{
|
||||
// XXX Should we push this to widget library
|
||||
return 240.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetScrollBarHeight() const
|
||||
{
|
||||
// XXX Should we push this to widget library
|
||||
return 240.0;
|
||||
}
|
||||
|
||||
nsIRenderingContext * nsDeviceContextMac :: CreateRenderingContext(nsIView *aView)
|
||||
{
|
||||
/*nsIRenderingContext *pContext = nsnull;
|
||||
nsIWidget *win = aView->GetWidget();
|
||||
nsresult rv;
|
||||
|
||||
static NS_DEFINE_IID(kRCCID, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kRCIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
rv = InitRenderingContext(pContext, win);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(pContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(win);
|
||||
return pContext;*/
|
||||
return nsnull; /// XXX need something reasonable here
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextMac :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
{
|
||||
return (aContext->Init(this, aWin));
|
||||
}
|
||||
|
||||
nsIFontCache* nsDeviceContextMac::GetFontCache()
|
||||
{
|
||||
/*if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
NS_ADDREF(mFontCache);
|
||||
return mFontCache;*/
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextMac::CreateFontCache()
|
||||
{
|
||||
/*nsresult rv = NS_NewFontCache(&mFontCache);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
mFontCache->Init(this);*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac::FlushFontCache()
|
||||
{
|
||||
//NS_RELEASE(mFontCache);
|
||||
}
|
||||
|
||||
|
||||
nsIFontMetrics* nsDeviceContextMac::GetMetricsFor(const nsFont& aFont)
|
||||
{
|
||||
/*if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
return mFontCache->GetMetricsFor(aFont);*/
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetZoom(float aZoom)
|
||||
{
|
||||
// mZoom = aZoom;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetZoom() const
|
||||
{
|
||||
//return mZoom;
|
||||
return 0.0; // should be 1.0 perhaps?
|
||||
}
|
||||
|
||||
nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface(nsIRenderingContext &aContext)
|
||||
{
|
||||
//return aContext.CreateDrawingSurface(nsnull);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetGamma(void)
|
||||
{
|
||||
//return mGammaValue;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetGamma(float aGamma)
|
||||
{/*
|
||||
if (aGamma != mGammaValue)
|
||||
{
|
||||
//we don't need to-recorrect existing images for this case
|
||||
//so pass in 1.0 for the current gamma regardless of what it
|
||||
//really happens to be. existing images will get a one time
|
||||
//re-correction when they're rendered the next time. MMP
|
||||
|
||||
SetGammaTable(mGammaTable, 1.0f, aGamma);
|
||||
|
||||
mGammaValue = aGamma;
|
||||
}*/
|
||||
}
|
||||
|
||||
PRUint8 * nsDeviceContextMac :: GetGammaTable(void)
|
||||
{
|
||||
//XXX we really need to ref count this somehow. MMP
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma)
|
||||
{
|
||||
/*double fgval = (1.0f / aCurrentGamma) * (1.0f / aNewGamma);
|
||||
|
||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
aTable[cnt] = (PRUint8)(pow((double)cnt * (1. / 256.), fgval) * 255.99999999);*/
|
||||
}
|
||||
|
||||
nsNativeWidget nsDeviceContextMac :: GetNativeWidget(void)
|
||||
{
|
||||
//XXX return mNativeWidget;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRUint32 nsDeviceContextMac :: ConvertPixel(nscolor aColor)
|
||||
{
|
||||
PRUint32 newcolor = 0;
|
||||
|
||||
/*
|
||||
For now, we assume anything in 12 planes or more is a TrueColor visual.
|
||||
If it is not (like older IRIS GL graphics boards, we'll look stupid for now.
|
||||
*/
|
||||
|
||||
/* switch (mDepth) {
|
||||
|
||||
case 8:
|
||||
{
|
||||
|
||||
if (mWriteable == PR_FALSE) {
|
||||
|
||||
Status rc ;
|
||||
XColor colorcell;
|
||||
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
colorcell.pixel = 0;
|
||||
colorcell.flags = 0;
|
||||
colorcell.pad = 0;
|
||||
|
||||
// On static displays, this will return closest match
|
||||
rc = ::XAllocColor(mSurface->display,
|
||||
mColormap,
|
||||
&colorcell);
|
||||
|
||||
if (rc == 0) {
|
||||
// Punt ... this cannot happen!
|
||||
fprintf(stderr,"WHOA! IT FAILED!\n");
|
||||
} else {
|
||||
newcolor = colorcell.pixel;
|
||||
} // rc == 0
|
||||
} else {
|
||||
|
||||
// Check to see if this exact color is present. If not, add it ourselves.
|
||||
// If there are no unallocated cells left, do our own closest match lookup
|
||||
//since X doesn't provide us with one.
|
||||
|
||||
Status rc ;
|
||||
XColor colorcell;
|
||||
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
colorcell.pixel = 0;
|
||||
colorcell.flags = 0;
|
||||
colorcell.pad = 0;
|
||||
|
||||
// On non-static displays, this may fail
|
||||
rc = ::XAllocColor(mSurface->display,
|
||||
mColormap,
|
||||
&colorcell);
|
||||
|
||||
if (rc == 0) {
|
||||
|
||||
// The color does not already exist AND we do not have any unallocated colorcells left
|
||||
// At his point we need to implement our own lookup matching algorithm.
|
||||
|
||||
unsigned long pixel;
|
||||
|
||||
rc = ::XAllocColorCells(mSurface->display,
|
||||
mColormap,
|
||||
False,0,0,
|
||||
&pixel,
|
||||
1);
|
||||
|
||||
if (rc == 0){
|
||||
|
||||
fprintf(stderr, "Failed to allocate Color cells...this sux\n");
|
||||
|
||||
} else {
|
||||
|
||||
colorcell.pixel = pixel;
|
||||
colorcell.pad = 0 ;
|
||||
colorcell.flags = DoRed | DoGreen | DoBlue ;
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
::XStoreColor(mSurface->display, mColormap, &colorcell);
|
||||
|
||||
newcolor = colorcell.pixel;
|
||||
|
||||
} // rc == 0
|
||||
} else {
|
||||
newcolor = colorcell.pixel;
|
||||
} // rc == 0
|
||||
} // mWriteable == FALSE
|
||||
} // 8
|
||||
break;
|
||||
|
||||
case 12:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 12
|
||||
break;
|
||||
|
||||
case 15:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 15
|
||||
break;
|
||||
|
||||
case 16:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 16
|
||||
break;
|
||||
|
||||
case 24:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
//newcolor = (PRUint32)NS_TO_X24(aColor);
|
||||
} // 24
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
// newcolor = (PRUint32) aColor;
|
||||
} // default
|
||||
break;
|
||||
|
||||
} // switch(mDepth)
|
||||
*/
|
||||
return (newcolor);
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: InstallColormap()
|
||||
{
|
||||
#if 0
|
||||
/*
|
||||
Unfortunately, we don't have control of the visual created for this display.
|
||||
That should be managed at an application level, since the gfx only cares that all
|
||||
values be passed in as 32 bit RGBA quantites.
|
||||
|
||||
This means we have to write lots and lots of code to support the fact that any
|
||||
number of visuals may be the one associated with this device context.
|
||||
*/
|
||||
|
||||
//XWindowAttributes wa;
|
||||
|
||||
|
||||
/* Already installed? */
|
||||
if (0 != mColormap)
|
||||
return;
|
||||
|
||||
// Find the depth of this visual
|
||||
::XGetWindowAttributes(mSurface->display,
|
||||
mSurface->drawable,
|
||||
&wa);
|
||||
|
||||
mDepth = wa.depth;
|
||||
|
||||
// Check to see if the colormap is writable
|
||||
mVisual = wa.visual;
|
||||
|
||||
if (mVisual->c_class == GrayScale || mVisual->c_class == PseudoColor || mVisual->c_class == DirectColor)
|
||||
mWriteable = PR_TRUE;
|
||||
else // We have StaticGray, StaticColor or TrueColor
|
||||
mWriteable = PR_FALSE;
|
||||
|
||||
mNumCells = pow(2, mDepth);
|
||||
|
||||
mColormap = wa.colormap;
|
||||
|
||||
// if the colormap is writeable .....
|
||||
if (mWriteable) {
|
||||
|
||||
// XXX We should check the XExtensions to see if this hardware supports multiple
|
||||
// hardware colormaps. If so, change this colormap to be a RGB ramp.
|
||||
if (mDepth == 8) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Compute rgb masks and number of bits for each
|
||||
mRedMask = mVisual->red_mask;
|
||||
mGreenMask = mVisual->green_mask;
|
||||
mBlueMask = mVisual->blue_mask;
|
||||
|
||||
PRUint32 i = mRedMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0) {
|
||||
mRedBits++;
|
||||
} else {
|
||||
mRedOffset++;
|
||||
}
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
|
||||
i = mGreenMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0)
|
||||
mGreenBits++;
|
||||
else
|
||||
mGreenOffset++;
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
|
||||
i = mBlueMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0)
|
||||
mBlueBits++;
|
||||
else
|
||||
mBlueOffset++;
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
125
gfx/src/mac/nsDeviceContextMac.h
Normal file
125
gfx/src/mac/nsDeviceContextMac.h
Normal file
@ -0,0 +1,125 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextMac_h___
|
||||
#define nsDeviceContextMac_h___
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIFontCache.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
|
||||
/* nsDrawingSurface is actually the following struct */
|
||||
struct nsDrawingSurfaceMac {
|
||||
/* Display *display ;
|
||||
Drawable drawable ;
|
||||
GC gc ;
|
||||
Visual * visual ;
|
||||
PRUint32 depth ; */
|
||||
};
|
||||
|
||||
class nsDeviceContextMac : public nsIDeviceContext
|
||||
{
|
||||
public:
|
||||
nsDeviceContextMac();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsNativeWidget aNativeWidget);
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView);
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
|
||||
virtual float GetTwipsToDevUnits() const;
|
||||
virtual float GetDevUnitsToTwips() const;
|
||||
|
||||
virtual void SetAppUnitsToDevUnits(float aAppUnits);
|
||||
virtual void SetDevUnitsToAppUnits(float aDevUnits);
|
||||
|
||||
virtual float GetAppUnitsToDevUnits() const;
|
||||
virtual float GetDevUnitsToAppUnits() const;
|
||||
|
||||
virtual float GetScrollBarWidth() const;
|
||||
virtual float GetScrollBarHeight() const;
|
||||
|
||||
virtual nsIFontCache * GetFontCache();
|
||||
virtual void FlushFontCache();
|
||||
|
||||
virtual nsIFontMetrics* GetMetricsFor(const nsFont& aFont);
|
||||
|
||||
virtual void SetZoom(float aZoom);
|
||||
virtual float GetZoom() const;
|
||||
|
||||
virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext);
|
||||
|
||||
//functions for handling gamma correction of output device
|
||||
virtual float GetGamma(void);
|
||||
virtual void SetGamma(float aGamma);
|
||||
|
||||
//XXX the return from this really needs to be ref counted somehow. MMP
|
||||
virtual PRUint8 * GetGammaTable(void);
|
||||
|
||||
virtual nsNativeWidget GetNativeWidget(void);
|
||||
|
||||
virtual PRUint32 ConvertPixel(nscolor aColor);
|
||||
|
||||
protected:
|
||||
~nsDeviceContextMac();
|
||||
nsresult CreateFontCache();
|
||||
|
||||
//nsIFontCache *mFontCache;
|
||||
//nsDrawingSurfaceMac * mSurface ;
|
||||
|
||||
/*PRUint32 mDepth;
|
||||
Visual * mVisual;
|
||||
PRBool mWriteable;
|
||||
PRUint32 mNumCells;
|
||||
Colormap mColormap;*/
|
||||
// XXX There should be a nsIColormap interface
|
||||
|
||||
/*float mTwipsToPixels;
|
||||
float mPixelsToTwips;
|
||||
float mAppUnitsToDevUnits;
|
||||
float mDevUnitsToAppUnits;
|
||||
float mZoom;
|
||||
float mGammaValue;
|
||||
PRUint8 *mGammaTable;*/
|
||||
|
||||
public:
|
||||
void InstallColormap(void);
|
||||
void SetDrawingSurface(nsDrawingSurfaceMac * aSurface);
|
||||
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
|
||||
nsDrawingSurface GetDrawingSurface();
|
||||
|
||||
//private:
|
||||
/*PRUint32 mRedMask;
|
||||
PRUint32 mGreenMask;
|
||||
PRUint32 mBlueMask;
|
||||
PRUint32 mRedBits;
|
||||
PRUint32 mGreenBits;
|
||||
PRUint32 mBlueBits;
|
||||
PRUint32 mRedOffset;
|
||||
PRUint32 mGreenOffset;
|
||||
PRUint32 mBlueOffset;
|
||||
|
||||
nsNativeWidget mNativeWidget;*/
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextMac_h___ */
|
384
gfx/src/mac/nsFontMetricsMac.cpp
Normal file
384
gfx/src/mac/nsFontMetricsMac.cpp
Normal file
@ -0,0 +1,384 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsFontMetricsMac.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
|
||||
|
||||
//#define NOISY_FONTS
|
||||
|
||||
nsFontMetricsMac :: nsFontMetricsMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
//mFont = nsnull;
|
||||
//mFontHandle = nsnull;
|
||||
}
|
||||
|
||||
nsFontMetricsMac :: ~nsFontMetricsMac()
|
||||
{
|
||||
/*if (nsnull != mFont)
|
||||
{
|
||||
delete mFont;
|
||||
mFont = nsnull;
|
||||
}*/
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFontMetricsMac, kIFontMetricsIID)
|
||||
|
||||
nsresult nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
{
|
||||
/* NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");
|
||||
|
||||
char **fnames = nsnull;
|
||||
PRInt32 namelen = aFont.name.Length() + 1;
|
||||
char *wildstring = (char *)PR_Malloc((namelen << 1) + 200);
|
||||
int numnames = 0;
|
||||
char altitalicization = 0;
|
||||
XFontStruct *fonts;
|
||||
PRInt32 dpi = NS_TO_INT_ROUND(aCX->GetTwipsToDevUnits() * 1440);
|
||||
Display *dpy = XtDisplay((Widget)aCX->GetNativeWidget());
|
||||
|
||||
if (nsnull == wildstring)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
mFont = new nsFont(aFont);
|
||||
mContext = aCX;
|
||||
mFontHandle = nsnull;
|
||||
|
||||
aFont.name.ToCString(wildstring, namelen);
|
||||
|
||||
if (abs(dpi - 75) < abs(dpi - 100))
|
||||
dpi = 75;
|
||||
else
|
||||
dpi = 100;
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, "looking for font %s (%d)", wildstring, aFont.size / 20);
|
||||
#endif
|
||||
|
||||
//font properties we care about:
|
||||
//name
|
||||
//weight (bold, medium)
|
||||
//slant (r = normal, i = italic, o = oblique)
|
||||
//size in nscoords >> 1
|
||||
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
wildstring,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
(aFont.style == NS_FONT_STYLE_NORMAL) ? 'r' :
|
||||
((aFont.style == NS_FONT_STYLE_ITALIC) ? 'i' : 'o'), dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
|
||||
if (aFont.style == NS_FONT_STYLE_ITALIC)
|
||||
altitalicization = 'o';
|
||||
else if (aFont.style == NS_FONT_STYLE_OBLIQUE)
|
||||
altitalicization = 'i';
|
||||
|
||||
if ((numnames <= 0) && altitalicization)
|
||||
{
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
wildstring,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
altitalicization, dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
}
|
||||
|
||||
if (numnames <= 0)
|
||||
{
|
||||
//we were not able to match the font name at all...
|
||||
|
||||
const char *newname = MapFamilyToFont(aFont.name);
|
||||
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
newname,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
(aFont.style == NS_FONT_STYLE_NORMAL) ? 'r' :
|
||||
((aFont.style == NS_FONT_STYLE_ITALIC) ? 'i' : 'o'), dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
|
||||
if ((numnames <= 0) && altitalicization)
|
||||
{
|
||||
PR_snprintf(&wildstring[namelen + 1], namelen + 200,
|
||||
"*-%s-%s-%c-normal--*-*-%d-%d-*-*-*",
|
||||
newname,
|
||||
(aFont.weight <= NS_FONT_WEIGHT_NORMAL) ? "medium" : "bold",
|
||||
altitalicization, dpi, dpi);
|
||||
|
||||
fnames = XListFontsWithInfo(dpy, &wildstring[namelen + 1], 200, &numnames, &fonts);
|
||||
}
|
||||
}
|
||||
|
||||
if (numnames > 0)
|
||||
{
|
||||
char *nametouse = PickAppropriateSize(fnames, fonts, numnames, aFont.size);
|
||||
|
||||
mFontHandle = ::XLoadFont(dpy, nametouse);
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, " is: %s\n", nametouse);
|
||||
#endif
|
||||
|
||||
XFreeFontInfo(fnames, fonts, numnames);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ack. we're in real trouble, go for fixed...
|
||||
|
||||
#ifdef NOISY_FONTS
|
||||
fprintf(stderr, " is: %s\n", "fixed (final fallback)");
|
||||
#endif
|
||||
|
||||
mFontHandle = ::XLoadFont(dpy, "fixed");
|
||||
}
|
||||
|
||||
RealizeFont();
|
||||
|
||||
PR_Free(wildstring);*/
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*char * nsFontMetricsMac::PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired)
|
||||
{
|
||||
int idx;
|
||||
PRInt32 desiredpix = NS_TO_INT_ROUND(mContext->GetAppUnitsToDevUnits() * desired);
|
||||
XFontStruct *curfont;
|
||||
PRInt32 closestmin = -1, minidx;
|
||||
|
||||
//first try an exact or closest smaller match...
|
||||
|
||||
for (idx = 0, curfont = fonts; idx < cnt; idx++, curfont++)
|
||||
{
|
||||
PRInt32 height = curfont->ascent + curfont->descent;
|
||||
|
||||
if (height == desiredpix)
|
||||
break;
|
||||
|
||||
if ((height < desiredpix) && (height > closestmin))
|
||||
{
|
||||
closestmin = height;
|
||||
minidx = idx;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx < cnt)
|
||||
return names[idx];
|
||||
else if (closestmin >= 0)
|
||||
return names[minidx];
|
||||
else
|
||||
{
|
||||
closestmin = 2000000;
|
||||
|
||||
for (idx = 0, curfont = fonts; idx < cnt; idx++, curfont++)
|
||||
{
|
||||
PRInt32 height = curfont->ascent + curfont->descent;
|
||||
|
||||
if ((height > desiredpix) && (height < closestmin))
|
||||
{
|
||||
closestmin = height;
|
||||
minidx = idx;
|
||||
}
|
||||
}
|
||||
|
||||
return names[minidx];
|
||||
}
|
||||
}*/
|
||||
|
||||
/*void nsFontMetricsMac::RealizeFont()
|
||||
{
|
||||
XFontStruct * fs = ::XQueryFont(XtDisplay((Widget)mContext->GetNativeWidget()), mFontHandle);
|
||||
|
||||
float f = mContext->GetDevUnitsToAppUnits();
|
||||
|
||||
mAscent = nscoord(fs->ascent * f);
|
||||
mDescent = nscoord(fs->descent * f);
|
||||
mMaxAscent = nscoord(fs->ascent * f) ;
|
||||
mMaxDescent = nscoord(fs->descent * f);
|
||||
|
||||
mHeight = nscoord((fs->ascent + fs->descent) * f) ;
|
||||
mMaxAdvance = nscoord(fs->max_bounds.width * f);
|
||||
|
||||
PRUint32 i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if ((i < fs->min_char_or_byte2) || (i > fs->max_char_or_byte2))
|
||||
mCharWidths[i] = mMaxAdvance;
|
||||
else
|
||||
mCharWidths[i] = nscoord((fs->per_char[i - fs->min_char_or_byte2].width) * f);
|
||||
}
|
||||
|
||||
mLeading = 0;
|
||||
}*/
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(char ch)
|
||||
{
|
||||
//if (ch < 256)
|
||||
// return mCharWidths[ch];
|
||||
//else
|
||||
return 0; //XXX
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(PRUnichar ch)
|
||||
{
|
||||
//if (ch < 256)
|
||||
// return mCharWidths[PRUint8(ch)];
|
||||
// else
|
||||
return 0;/* XXX */
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const nsString& aString)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const char *aString)
|
||||
{
|
||||
/* PRInt32 rc = 0 ;
|
||||
|
||||
XFontStruct * fs = ::XQueryFont(XtDisplay((Widget)mContext->GetNativeWidget()), mFontHandle);
|
||||
|
||||
rc = (PRInt32) ::XTextWidth(fs, aString, nsCRT::strlen(aString));
|
||||
|
||||
return (nscoord(rc * mContext->GetDevUnitsToAppUnits()));*/
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
{
|
||||
// XChar2b * xstring ;
|
||||
// XChar2b * thischar ;
|
||||
// PRUint16 aunichar;
|
||||
nscoord width ;
|
||||
// PRUint32 i ;
|
||||
|
||||
// xstring = (XChar2b *) PR_Malloc(sizeof(XChar2b)*aLength);
|
||||
|
||||
// for (i=0; i<aLength; i++) {
|
||||
// thischar = (xstring+i);
|
||||
// aunichar = (PRUint16)(*(aString+i));
|
||||
// thischar->byte2 = (aunichar & 0xff);
|
||||
// thischar->byte1 = (aunichar & 0xff00) >> 8;
|
||||
// }
|
||||
|
||||
//XFontStruct * fs = ::XQueryFont(XtDisplay((Widget)mContext->GetNativeWidget()), mFontHandle);
|
||||
|
||||
// width = ::XTextWidth16(fs, xstring, aLength);
|
||||
//width = ::XTextWidth16(fs, (XChar2b *)aString, aLength);
|
||||
|
||||
// PR_Free(xstring);
|
||||
|
||||
//return (nscoord(width * mContext->GetDevUnitsToAppUnits()));
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetHeight()
|
||||
{
|
||||
//return mHeight;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetLeading()
|
||||
{
|
||||
//return mLeading;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxAscent()
|
||||
{
|
||||
//return mMaxAscent;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxDescent()
|
||||
{
|
||||
//return mMaxDescent;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxAdvance()
|
||||
{
|
||||
//return mMaxAdvance;
|
||||
}
|
||||
|
||||
const nscoord * nsFontMetricsMac :: GetWidths()
|
||||
{
|
||||
//return mCharWidths;
|
||||
}
|
||||
|
||||
const nsFont& nsFontMetricsMac :: GetFont()
|
||||
{
|
||||
//return *mFont;
|
||||
//return nsnull;
|
||||
}
|
||||
|
||||
nsFontHandle nsFontMetricsMac :: GetFontHandle()
|
||||
{
|
||||
//return (nsFontHandle)mFontHandle;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
// XXX this function is a hack; the only logical font names we should
|
||||
// support are the one used by css.
|
||||
|
||||
// we'll probably need something similar for the mac
|
||||
/*const char* nsFontMetricsMac::MapFamilyToFont(const nsString& aLogicalFontName)
|
||||
{
|
||||
if (aLogicalFontName.EqualsIgnoreCase("Times Roman")) {
|
||||
return "times";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("Times New Roman")) {
|
||||
return "times";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("Unicode")) {
|
||||
return "Bitstream Cyberbit";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("Courier New")) {
|
||||
return "courier";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("Arial")) {
|
||||
return "helvetica";
|
||||
}
|
||||
|
||||
// the CSS generic names
|
||||
if (aLogicalFontName.EqualsIgnoreCase("serif")) {
|
||||
return "times";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("sans-serif")) {
|
||||
return "helvetica";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("cursive")) {
|
||||
// return "XXX";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("fantasy")) {
|
||||
// return "XXX";
|
||||
}
|
||||
if (aLogicalFontName.EqualsIgnoreCase("monospace")) {
|
||||
return "fixed";
|
||||
}
|
||||
return "helvetica";
|
||||
}
|
||||
*/
|
||||
|
84
gfx/src/mac/nsFontMetricsMac.h
Normal file
84
gfx/src/mac/nsFontMetricsMac.h
Normal file
@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsFontMetricsMac_h__
|
||||
#define nsFontMetricsMac_h__
|
||||
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
class nsFontMetricsMac : public nsIFontMetrics
|
||||
{
|
||||
public:
|
||||
nsFontMetricsMac();
|
||||
~nsFontMetricsMac();
|
||||
|
||||
void* operator new(size_t sz) {
|
||||
void* rv = new char[sz];
|
||||
nsCRT::zero(rv, sz);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
virtual nscoord GetWidth(char aC);
|
||||
virtual nscoord GetWidth(PRUnichar aC);
|
||||
virtual nscoord GetWidth(const nsString& aString);
|
||||
virtual nscoord GetWidth(const char *aString);
|
||||
virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength);
|
||||
virtual nscoord GetHeight();
|
||||
virtual nscoord GetLeading();
|
||||
virtual nscoord GetMaxAscent();
|
||||
virtual nscoord GetMaxDescent();
|
||||
virtual nscoord GetMaxAdvance();
|
||||
virtual const nscoord *GetWidths();
|
||||
virtual const nsFont& GetFont();
|
||||
virtual nsFontHandle GetFontHandle();
|
||||
|
||||
/*protected:
|
||||
void RealizeFont();
|
||||
static const char* MapFamilyToFont(const nsString& aLogicalFontName);
|
||||
|
||||
protected:
|
||||
void QueryFont();
|
||||
char *PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired);
|
||||
|
||||
nsFont *mFont;
|
||||
nsIDeviceContext *mContext;
|
||||
XFontStruct *mFontInfo;
|
||||
Font mFontHandle;
|
||||
nscoord mCharWidths[256];
|
||||
nscoord mHeight;
|
||||
nscoord mAscent;
|
||||
nscoord mDescent;
|
||||
nscoord mLeading;
|
||||
nscoord mMaxAscent;
|
||||
nscoord mMaxDescent;
|
||||
nscoord mMaxAdvance;*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
176
gfx/src/mac/nsGfxFactoryMac.cpp
Normal file
176
gfx/src/mac/nsGfxFactoryMac.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsFontMetricsMac.h"
|
||||
#include "nsRenderingContextMac.h"
|
||||
#include "nsImageMac.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
#include "nsRegionMac.h"
|
||||
|
||||
static NS_DEFINE_IID(kCFontMetrics, NS_FONT_METRICS_CID);
|
||||
static NS_DEFINE_IID(kCRenderingContext, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCImage, NS_IMAGE_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContext, NS_DEVICE_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCRegion, NS_REGION_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
class nsGfxFactoryMac : public nsIFactory
|
||||
{
|
||||
public:
|
||||
// nsISupports methods
|
||||
NS_IMETHOD QueryInterface(const nsIID &aIID,
|
||||
void **aResult);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
nsGfxFactoryMac(const nsCID &aClass);
|
||||
~nsGfxFactoryMac();
|
||||
|
||||
private:
|
||||
nsrefcnt mRefCnt;
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
nsGfxFactoryMac::nsGfxFactoryMac(const nsCID &aClass)
|
||||
{
|
||||
mRefCnt = 0;
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
nsGfxFactoryMac::~nsGfxFactoryMac()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryMac::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = (void *)(nsISupports*)this;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
}
|
||||
|
||||
if (*aResult == NULL) {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef(); // Increase reference count for caller
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsrefcnt nsGfxFactoryMac::AddRef()
|
||||
{
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt nsGfxFactoryMac::Release()
|
||||
{
|
||||
if (--mRefCnt == 0) {
|
||||
delete this;
|
||||
return 0; // Don't access mRefCnt after deleting!
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryMac::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
|
||||
if (mClassID.Equals(kCFontMetrics)) {
|
||||
inst = (nsISupports *)new nsFontMetricsMac();
|
||||
}
|
||||
else if (mClassID.Equals(kCDeviceContext)) {
|
||||
inst = (nsISupports *)new nsDeviceContextMac();
|
||||
}
|
||||
else if (mClassID.Equals(kCRenderingContext)) {
|
||||
inst = (nsISupports *)new nsRenderingContextMac();
|
||||
}
|
||||
else if (mClassID.Equals(kCImage)) {
|
||||
inst = (nsISupports *)new nsImageMac();
|
||||
}
|
||||
else if (mClassID.Equals(kCRegion)) {
|
||||
inst = (nsISupports *)new nsRegionMac();
|
||||
}
|
||||
|
||||
if (inst == NULL) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (res != NS_OK) {
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
}
|
||||
// else {
|
||||
// inst->Release();
|
||||
// }
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryMac::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" NS_GFXNONXP nsresult NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aFactory = new nsGfxFactoryMac(aClass);
|
||||
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
377
gfx/src/mac/nsImageMac.cpp
Normal file
377
gfx/src/mac/nsImageMac.cpp
Normal file
@ -0,0 +1,377 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsImageMac.h"
|
||||
#include "nsRenderingContextMac.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#define IsFlagSet(a,b) (a & b)
|
||||
|
||||
static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsImageMac :: nsImageMac()
|
||||
{
|
||||
/* printf("[[[[[[[[[[[[[[[[[[[[ New Image Created ]]]]]]]]]]]]]]]]]]]]]]\n");
|
||||
NS_INIT_REFCNT();
|
||||
mImage = nsnull ;
|
||||
mImageBits = nsnull;
|
||||
mConvertedBits = nsnull;
|
||||
mBitsForCreate = nsnull;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mDepth = 0;
|
||||
mOriginalDepth = 0;
|
||||
mColorMap = nsnull;*/
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsImageMac :: ~nsImageMac()
|
||||
{
|
||||
/* if (nsnull != mImage) {
|
||||
XDestroyImage(mImage);
|
||||
mImage = nsnull;
|
||||
}
|
||||
if(nsnull != mConvertedBits)
|
||||
{
|
||||
delete[] (PRUint8*)mConvertedBits;
|
||||
mConvertedBits = nsnull;
|
||||
}
|
||||
|
||||
if(nsnull != mImageBits)
|
||||
{
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
mImageBits = nsnull;
|
||||
}
|
||||
if(nsnull!= mColorMap)
|
||||
delete mColorMap;*/
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsImageMac, kIImageIID);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult nsImageMac :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMaskRequirements aMaskRequirements)
|
||||
{
|
||||
/* if(nsnull != mImageBits)
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
|
||||
if(nsnull != mColorMap)
|
||||
delete[] mColorMap;
|
||||
|
||||
if (nsnull != mImage) {
|
||||
XDestroyImage(mImage);
|
||||
mImage = nsnull;
|
||||
}
|
||||
mWidth = aWidth;
|
||||
mHeight = aHeight;
|
||||
mDepth = aDepth;
|
||||
mOriginalDepth = aDepth;
|
||||
mOriginalRowBytes = CalcBytesSpan(aWidth);
|
||||
mConverted = PR_FALSE;
|
||||
|
||||
ComputePaletteSize(aDepth);
|
||||
|
||||
// create the memory for the image
|
||||
ComputMetrics();
|
||||
|
||||
mImageBits = (PRUint8*) new PRUint8[mSizeImage];
|
||||
|
||||
mColorMap = new nsColorMap;
|
||||
|
||||
if (mColorMap != nsnull)
|
||||
{
|
||||
mColorMap->NumColors = mNumPalleteColors;
|
||||
mColorMap->Index = new PRUint8[3 * mNumPalleteColors];
|
||||
memset(mColorMap->Index, 0, sizeof(PRUint8) * (3 * mNumPalleteColors));
|
||||
}
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
/*void nsImageMac::ComputMetrics()
|
||||
{
|
||||
|
||||
mRowBytes = CalcBytesSpan(mWidth);
|
||||
mSizeImage = mRowBytes * mHeight;
|
||||
|
||||
}*/
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// figure out how big our palette needs to be
|
||||
/*void nsImageMac :: ComputePaletteSize(PRIntn nBitCount)
|
||||
{
|
||||
switch (nBitCount)
|
||||
{
|
||||
case 8:
|
||||
mNumPalleteColors = 256;
|
||||
mNumBytesPixel = 1;
|
||||
break;
|
||||
case 16:
|
||||
mNumPalleteColors = 0;
|
||||
mNumBytesPixel = 2;
|
||||
break;
|
||||
case 24:
|
||||
mNumPalleteColors = 0;
|
||||
mNumBytesPixel = 3;
|
||||
break;
|
||||
default:
|
||||
mNumPalleteColors = -1;
|
||||
mNumBytesPixel = 0;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
PRInt32 nsImageMac :: CalcBytesSpan(PRUint32 aWidth)
|
||||
{
|
||||
/*PRInt32 spanbytes;
|
||||
|
||||
spanbytes = (aWidth * mDepth) >> 5;
|
||||
|
||||
if (((PRUint32)aWidth * mDepth) & 0x1F)
|
||||
spanbytes++;
|
||||
spanbytes <<= 2;
|
||||
return(spanbytes);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// set up the pallete to the passed in color array, RGB only in this array
|
||||
void nsImageMac :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
|
||||
{
|
||||
|
||||
/*if (nsnull == mImage)
|
||||
return;
|
||||
|
||||
if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, aFlags)){
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// Draw the bitmap, this method has a source and destination coordinates
|
||||
PRBool nsImageMac :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
|
||||
{
|
||||
/*nsDrawingSurfaceMac *Macdrawing =(nsDrawingSurfaceMac*) aSurface;
|
||||
|
||||
if (nsnull == mImage)
|
||||
return PR_FALSE;
|
||||
|
||||
XPutImage(Macdrawing->display,Macdrawing->drawable,Macdrawing->gc,mImage,
|
||||
aSX,aSY,aDX,aDY,aDWidth,aDHeight);
|
||||
*/
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// Draw the bitmap, this draw just has destination coordinates
|
||||
PRBool nsImageMac :: Draw(nsIRenderingContext &aContext,
|
||||
nsDrawingSurface aSurface,
|
||||
PRInt32 aX, PRInt32 aY,
|
||||
PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/*nsDrawingSurfaceMac *Macdrawing =(nsDrawingSurfaceMac*) aSurface;
|
||||
|
||||
mImage = nsnull;
|
||||
Optimize(aSurface);
|
||||
|
||||
if (nsnull == mImage)
|
||||
return PR_FALSE;
|
||||
XPutImage(Macdrawing->display,Macdrawing->drawable,Macdrawing->gc,mImage,
|
||||
0,0,aX,aY,aWidth,aHeight); */
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
void nsImageMac::CompositeImage(nsIImage *aTheImage, nsPoint *aULLocation,nsBlendQuality aBlendQuality)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// lets build an alpha mask from this image
|
||||
PRBool nsImageMac::SetAlphaMask(nsIImage *aTheMask)
|
||||
{
|
||||
return(PR_FALSE);
|
||||
}
|
||||
|
||||
|
||||
void nsImageMac::AllocConvertedBits(PRUint32 aSize)
|
||||
{
|
||||
/*if (nsnull == mConvertedBits)
|
||||
mConvertedBits = (PRUint8*) new PRUint8[aSize]; */
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
void nsImageMac::ConvertImage(nsDrawingSurface aDrawingSurface)
|
||||
{
|
||||
/*nsDrawingSurfaceMac *Macdrawing =(nsDrawingSurfaceMac*) aDrawingSurface;
|
||||
PRUint8 *tempbuffer,*cursrc,*curdest;
|
||||
PRInt32 x,y;
|
||||
PRUint16 red,green,blue,*cur16;
|
||||
|
||||
mBitsForCreate = mImageBits;
|
||||
|
||||
if((Macdrawing->depth==24) && (mOriginalDepth==8))
|
||||
{
|
||||
// convert this nsImage to a 24 bit image
|
||||
mDepth = 24;
|
||||
ComputePaletteSize(mDepth);
|
||||
ComputMetrics();
|
||||
AllocConvertedBits(mSizeImage);
|
||||
tempbuffer = mConvertedBits;
|
||||
mBitsForCreate = mConvertedBits;
|
||||
|
||||
for(y=0;y<mHeight;y++)
|
||||
{
|
||||
cursrc = mImageBits+(y*mOriginalRowBytes);
|
||||
curdest =tempbuffer+(y*mRowBytes);
|
||||
for(x=0;x<mOriginalRowBytes;x++)
|
||||
{
|
||||
*curdest = mColorMap->Index[(3*(*cursrc))+2]; // red
|
||||
curdest++;
|
||||
*curdest = mColorMap->Index[(3*(*cursrc))+1]; // green
|
||||
curdest++;
|
||||
*curdest = mColorMap->Index[(3*(*cursrc))]; // blue
|
||||
curdest++;
|
||||
cursrc++;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if(mColorMap)
|
||||
delete mColorMap;
|
||||
|
||||
// after we are finished converting the image, build a new color map
|
||||
mColorMap = new nsColorMap;
|
||||
|
||||
if (mColorMap != nsnull)
|
||||
{
|
||||
mColorMap->NumColors = mNumPalleteColors;
|
||||
mColorMap->Index = new PRUint8[3 * mNumPalleteColors];
|
||||
memset(mColorMap->Index, 0, sizeof(PRUint8) * (3 * mNumPalleteColors));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// convert the 8 bit image to 16 bit
|
||||
if((Macdrawing->depth==16) && (mOriginalDepth==8))
|
||||
{
|
||||
mDepth = 16;
|
||||
ComputePaletteSize(mDepth);
|
||||
ComputMetrics();
|
||||
AllocConvertedBits(mSizeImage);
|
||||
tempbuffer = mConvertedBits;
|
||||
mBitsForCreate = mConvertedBits;
|
||||
|
||||
for(y=0;y<mHeight;y++)
|
||||
{
|
||||
cursrc = mImageBits+(y*mOriginalRowBytes);
|
||||
cur16 = (PRUint16*) (tempbuffer+(y*mRowBytes));
|
||||
|
||||
for(x=0;x<mOriginalRowBytes;x++)
|
||||
{
|
||||
blue = mColorMap->Index[(3*(*cursrc))+2]; // red
|
||||
green = mColorMap->Index[(3*(*cursrc))+1]; // green
|
||||
red = mColorMap->Index[(3*(*cursrc))]; // blue
|
||||
cursrc++;
|
||||
*cur16 = ((red&0xf8)<<8)|((green&0xfc)<<3)| ((blue&0xf8)>>3);
|
||||
cur16++;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (mColorMap != nsnull)
|
||||
{
|
||||
mColorMap->NumColors = mNumPalleteColors;
|
||||
mColorMap->Index = new PRUint8[3 * mNumPalleteColors];
|
||||
memset(mColorMap->Index, 0, sizeof(PRUint8) * (3 * mNumPalleteColors));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult nsImageMac::Optimize(nsDrawingSurface aDrawingSurface)
|
||||
{
|
||||
/*PRInt16 i;
|
||||
|
||||
if (nsnull == mImage)
|
||||
{
|
||||
ConvertImage(aDrawingSurface);
|
||||
CreateImage(aDrawingSurface);
|
||||
}*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
void nsImageMac::CreateImage(nsDrawingSurface aSurface)
|
||||
{
|
||||
/* PRUint32 wdepth;
|
||||
Visual * visual ;
|
||||
PRUint32 format ;
|
||||
nsDrawingSurfaceMac *Macdrawing =(nsDrawingSurfaceMac*) aSurface;
|
||||
|
||||
if(mImageBits) {
|
||||
if (Macdrawing->visual->c_class == TrueColor ||
|
||||
Macdrawing->visual->c_class == DirectColor)
|
||||
{
|
||||
format = ZPixmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
format = XYPixmap;
|
||||
}
|
||||
|
||||
mImage = ::XCreateImage(Macdrawing->display,
|
||||
Macdrawing->visual,
|
||||
Macdrawing->depth,
|
||||
format,
|
||||
0,
|
||||
(char *)mBitsForCreate,
|
||||
(unsigned int)mWidth,
|
||||
(unsigned int)mHeight,
|
||||
32,mRowBytes);
|
||||
|
||||
mImage->byte_order = ImageByteOrder(Macdrawing->display);
|
||||
mImage->bits_per_pixel = Macdrawing->depth;
|
||||
mImage->bitmap_bit_order = BitmapBitOrder(Macdrawing->display);
|
||||
mImage->bitmap_unit = 32;
|
||||
|
||||
}
|
||||
return ;*/
|
||||
}
|
112
gfx/src/mac/nsImageMac.h
Normal file
112
gfx/src/mac/nsImageMac.h
Normal file
@ -0,0 +1,112 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsImageMac_h___
|
||||
#define nsImageMac_h___
|
||||
|
||||
#include "nsIImage.h"
|
||||
|
||||
class nsImageMac : public nsIImage
|
||||
{
|
||||
public:
|
||||
nsImageMac();
|
||||
~nsImageMac();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
@see nsIImage.h
|
||||
*/
|
||||
virtual PRInt32 GetHeight() { return 0; }
|
||||
virtual PRInt32 GetWidth() { return 0; }
|
||||
virtual PRUint8* GetBits() { return 0; }
|
||||
virtual void* GetBitInfo() { return nsnull; }
|
||||
virtual PRInt32 GetLineStride() {return 0; }
|
||||
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
|
||||
virtual nsColorMap* GetColorMap() {return nsnull;}
|
||||
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
|
||||
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
|
||||
virtual PRBool IsOptimized() { return false; }
|
||||
virtual nsresult Optimize(nsDrawingSurface aSurface);
|
||||
virtual PRUint8* GetAlphaBits() { return nsnull; }
|
||||
virtual PRInt32 GetAlphaWidth() { return 0;}
|
||||
virtual PRInt32 GetAlphaHeight() {return 0;}
|
||||
virtual PRInt32 GetAlphaXLoc() {return 0;}
|
||||
virtual PRInt32 GetAlphaYLoc() {return 0;}
|
||||
virtual PRInt32 GetAlphaLineStride(){ return 0; }
|
||||
virtual void CompositeImage(nsIImage *aTheImage,nsPoint *aULLocation,nsBlendQuality aQuality);
|
||||
virtual nsIImage* DuplicateImage() {return(nsnull);}
|
||||
|
||||
void AllocConvertedBits(PRUint32 aSize);
|
||||
|
||||
/**
|
||||
* Return the image size of the Device Independent Bitmap(DIB).
|
||||
* @return size of image in bytes
|
||||
*/
|
||||
PRIntn GetSizeImage(){ return 0; }
|
||||
|
||||
/**
|
||||
* Make a palette for the DIB.
|
||||
* @return true or false if the palette was created
|
||||
*/
|
||||
PRBool MakePalette();
|
||||
|
||||
/**
|
||||
* Calculate the number of bytes spaned for this image for a given width
|
||||
* @param aWidth is the width to calculate the number of bytes for
|
||||
* @return the number of bytes in this span
|
||||
*/
|
||||
PRInt32 CalcBytesSpan(PRUint32 aWidth);
|
||||
PRBool SetAlphaMask(nsIImage *aTheMask);
|
||||
virtual void SetAlphaLevel(PRInt32 aAlphaLevel) {}
|
||||
virtual PRInt32 GetAlphaLevel() {return(0);}
|
||||
virtual void MoveAlphaMask(PRInt32 aX, PRInt32 aY) {}
|
||||
|
||||
private:
|
||||
void CreateImage(nsDrawingSurface aSurface);
|
||||
void ConvertImage(nsDrawingSurface aSurface);
|
||||
|
||||
/**
|
||||
* Calculate the amount of memory needed for the initialization of the image
|
||||
*/
|
||||
//void ComputMetrics();
|
||||
//void ComputePaletteSize(PRIntn nBitCount);
|
||||
|
||||
|
||||
/*private:
|
||||
PRInt32 mWidth;
|
||||
PRInt32 mHeight;
|
||||
PRInt32 mDepth; // bits per pixel
|
||||
PRInt32 mOriginalDepth; // bits per pixel
|
||||
PRInt32 mRowBytes;
|
||||
PRInt32 mOriginalRowBytes;
|
||||
Pixmap mThePixMap;
|
||||
PRUint8 *mImageBits;
|
||||
PRUint8 *mConvertedBits;
|
||||
PRBool mConverted;
|
||||
PRUint8 *mBitsForCreate;
|
||||
PRInt32 mSizeImage;
|
||||
XImage *mImage ;
|
||||
nsColorMap *mColorMap;
|
||||
PRInt16 mNumPalleteColors;
|
||||
PRInt8 mNumBytesPixel;*/
|
||||
};
|
||||
|
||||
#endif
|
239
gfx/src/mac/nsRegionMac.cpp
Normal file
239
gfx/src/mac/nsRegionMac.cpp
Normal file
@ -0,0 +1,239 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsRegionMac.h"
|
||||
|
||||
static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
|
||||
|
||||
nsRegionMac :: nsRegionMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
/* mRegion = nsnull;
|
||||
mRegionType = eRegionType_empty;*/
|
||||
}
|
||||
|
||||
nsRegionMac :: ~nsRegionMac()
|
||||
{
|
||||
/* if (mRegion)
|
||||
::XDestroyRegion(mRegion);
|
||||
mRegion = nsnull;*/
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsRegionMac, kRegionIID)
|
||||
NS_IMPL_ADDREF(nsRegionMac)
|
||||
NS_IMPL_RELEASE(nsRegionMac)
|
||||
|
||||
nsresult nsRegionMac :: Init(void)
|
||||
{
|
||||
/* mRegion = ::XCreateRegion();
|
||||
mRegionType = eRegionType_empty;*/
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRegionMac :: SetTo(const nsIRegion &aRegion)
|
||||
{
|
||||
/* nsRegionMac * pRegion = (nsRegionMac *)&aRegion;
|
||||
|
||||
SetRegionEmpty();
|
||||
|
||||
::XUnionRegion(mRegion, pRegion->mRegion, mRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
}
|
||||
|
||||
void nsRegionMac :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/*
|
||||
SetRegionEmpty();
|
||||
|
||||
XRectangle xrect;
|
||||
|
||||
xrect.x = aX;
|
||||
xrect.y = aY;
|
||||
xrect.width = aWidth;
|
||||
xrect.height = aHeight;
|
||||
|
||||
::XUnionRectWithRegion(&xrect, mRegion, mRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
}
|
||||
|
||||
void nsRegionMac :: Intersect(const nsIRegion &aRegion)
|
||||
{
|
||||
/* nsRegionMac * pRegion = (nsRegionMac *)&aRegion;
|
||||
|
||||
::XIntersectRegion(mRegion, pRegion->mRegion, mRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
}
|
||||
|
||||
void nsRegionMac :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/* Region tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
::XIntersectRegion(mRegion, tRegion, mRegion);
|
||||
|
||||
::XDestroyRegion(tRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
|
||||
}
|
||||
|
||||
void nsRegionMac :: Union(const nsIRegion &aRegion)
|
||||
{
|
||||
/* nsRegionMac * pRegion = (nsRegionMac *)&aRegion;
|
||||
|
||||
::XUnionRegion(mRegion, pRegion->mRegion, mRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
|
||||
}
|
||||
|
||||
void nsRegionMac :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
|
||||
/* Region tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
::XUnionRegion(mRegion, tRegion, mRegion);
|
||||
|
||||
::XDestroyRegion(tRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
|
||||
}
|
||||
|
||||
void nsRegionMac :: Subtract(const nsIRegion &aRegion)
|
||||
{
|
||||
/* nsRegionMac * pRegion = (nsRegionMac *)&aRegion;
|
||||
|
||||
::XSubtractRegion(mRegion, pRegion->mRegion, mRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
|
||||
}
|
||||
|
||||
void nsRegionMac :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/* Region tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
::XSubtractRegion(mRegion, tRegion, mRegion);
|
||||
|
||||
::XDestroyRegion(tRegion);
|
||||
|
||||
SetRegionType();*/
|
||||
|
||||
}
|
||||
|
||||
PRBool nsRegionMac :: IsEmpty(void)
|
||||
{
|
||||
/* if (mRegionType == eRegionType_empty)
|
||||
return PR_TRUE;*/
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsRegionMac :: IsEqual(const nsIRegion &aRegion)
|
||||
{
|
||||
/* nsRegionMac * pRegion = (nsRegionMac *)&aRegion;
|
||||
|
||||
return(::XEqualRegion(mRegion, pRegion->mRegion));*/
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
void nsRegionMac :: GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
|
||||
{
|
||||
/* XRectangle rect;
|
||||
|
||||
::XClipBox(mRegion, &rect);
|
||||
|
||||
*aX = rect.x;
|
||||
*aY = rect.y;
|
||||
*aWidth = rect.width;
|
||||
*aHeight = rect.height;*/
|
||||
}
|
||||
|
||||
void nsRegionMac :: Offset(PRInt32 aXOffset, PRInt32 aYOffset)
|
||||
{
|
||||
//::XOffsetRegion(mRegion, aXOffset, aYOffset);
|
||||
}
|
||||
|
||||
PRBool nsRegionMac :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/*PRInt32 containment;
|
||||
|
||||
containment = ::XRectInRegion(mRegion, aX, aY, aWidth, aHeight);
|
||||
|
||||
if (containment == RectangleIn)
|
||||
return PR_TRUE;
|
||||
else*/
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
PRBool nsRegionMac :: ForEachRect(nsRectInRegionFunc *func, void *closure)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*Region nsRegionMac :: GetXRegion(void)
|
||||
{
|
||||
return (mRegion);
|
||||
}*/
|
||||
|
||||
/*void nsRegionMac :: SetRegionType()
|
||||
{
|
||||
if (::XEmptyRegion(mRegion) == True)
|
||||
mRegionType = eRegionType_empty;
|
||||
else
|
||||
mRegionType = eRegionType_rect ;
|
||||
}
|
||||
*/
|
||||
|
||||
/*void nsRegionMac :: SetRegionEmpty()
|
||||
{
|
||||
::XDestroyRegion(mRegion);
|
||||
mRegion = ::XCreateRegion();
|
||||
}*/
|
||||
|
||||
/*Region nsRegionMac :: CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
Region r = ::XCreateRegion();
|
||||
|
||||
XRectangle xrect;
|
||||
|
||||
xrect.x = aX;
|
||||
xrect.y = aY;
|
||||
xrect.width = aWidth;
|
||||
xrect.height = aHeight;
|
||||
|
||||
::XUnionRectWithRegion(&xrect, r, r);
|
||||
|
||||
return (r);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
70
gfx/src/mac/nsRegionMac.h
Normal file
70
gfx/src/mac/nsRegionMac.h
Normal file
@ -0,0 +1,70 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsRegionMac_h___
|
||||
#define nsRegionMac_h___
|
||||
|
||||
#include "nsIRegion.h"
|
||||
|
||||
enum nsRegionType {
|
||||
eRegionType_empty,
|
||||
eRegionType_rect,
|
||||
eRegionType_poly,
|
||||
eRegionType_complex
|
||||
};
|
||||
|
||||
|
||||
class nsRegionMac : public nsIRegion
|
||||
{
|
||||
public:
|
||||
nsRegionMac();
|
||||
~nsRegionMac();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init();
|
||||
|
||||
virtual void SetTo(const nsIRegion &aRegion);
|
||||
virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual void Intersect(const nsIRegion &aRegion);
|
||||
virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual void Union(const nsIRegion &aRegion);
|
||||
virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual void Subtract(const nsIRegion &aRegion);
|
||||
virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual PRBool IsEmpty(void);
|
||||
virtual PRBool IsEqual(const nsIRegion &aRegion);
|
||||
virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
|
||||
virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
|
||||
virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure);
|
||||
|
||||
//Region GetXRegion(void);
|
||||
|
||||
private:
|
||||
//Region mRegion;
|
||||
nsRegionType mRegionType;
|
||||
|
||||
/*private:
|
||||
virtual void SetRegionType();
|
||||
virtual void SetRegionEmpty();
|
||||
virtual Region CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);*/
|
||||
|
||||
};
|
||||
|
||||
#endif // nsRegionMac_h___
|
960
gfx/src/mac/nsRenderingContextMac.cpp
Normal file
960
gfx/src/mac/nsRenderingContextMac.cpp
Normal file
@ -0,0 +1,960 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsRenderingContextMac.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "nspr.h"
|
||||
|
||||
#include "nsRegionMac.h"
|
||||
#include "nsGfxCIID.h"
|
||||
|
||||
//#define NO_CLIP
|
||||
|
||||
/*
|
||||
Some Implementation Notes
|
||||
|
||||
REGIONS: Regions are clipping rects associated with a GC. Since
|
||||
multiple Drawable's can and do share GC's (they are hardware cached)
|
||||
In order to select clip rect's into GC's, they must be writeable. Thus,
|
||||
any consumer of the 'gfx' library must assume that GC's created by them
|
||||
will be modified in gfx.
|
||||
|
||||
*/
|
||||
|
||||
class GraphicsState
|
||||
{
|
||||
public:
|
||||
GraphicsState();
|
||||
~GraphicsState();
|
||||
|
||||
/*nsTransform2D *mMatrix;
|
||||
nsRect mLocalClip;
|
||||
Region mClipRegion;
|
||||
nscolor mColor;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
Font mFont;*/
|
||||
};
|
||||
|
||||
GraphicsState :: GraphicsState()
|
||||
{
|
||||
/* mMatrix = nsnull;
|
||||
mLocalClip.x = mLocalClip.y = mLocalClip.width = mLocalClip.height = 0;
|
||||
mClipRegion = nsnull;
|
||||
mColor = NS_RGB(0, 0, 0);
|
||||
mFontMetrics = nsnull;
|
||||
mFont = nsnull;*/
|
||||
}
|
||||
|
||||
GraphicsState :: ~GraphicsState()
|
||||
{
|
||||
// mFont = nsnull;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
nsRenderingContextMac :: nsRenderingContextMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
/*mFontCache = nsnull ;
|
||||
mFontMetrics = nsnull ;
|
||||
mContext = nsnull ;
|
||||
mFrontBuffer = nsnull ;
|
||||
mRenderingSurface = nsnull ;
|
||||
mCurrentColor = 0;
|
||||
mTMatrix = nsnull;
|
||||
mP2T = 1.0f;
|
||||
mStateCache = new nsVoidArray();
|
||||
mRegion = nsnull;
|
||||
mCurrFontHandle = 0;*/
|
||||
PushState();
|
||||
}
|
||||
|
||||
nsRenderingContextMac :: ~nsRenderingContextMac()
|
||||
{
|
||||
/*
|
||||
if (mRegion) {
|
||||
::XDestroyRegion(mRegion);
|
||||
mRegion = nsnull;
|
||||
}
|
||||
|
||||
mTMatrix = nsnull;
|
||||
|
||||
// Destroy the State Machine
|
||||
if (nsnull != mStateCache)
|
||||
{
|
||||
PRInt32 cnt = mStateCache->Count();
|
||||
|
||||
while (--cnt >= 0)
|
||||
{
|
||||
GraphicsState *state = (GraphicsState *)mStateCache->ElementAt(cnt);
|
||||
mStateCache->RemoveElementAt(cnt);
|
||||
|
||||
if (nsnull != state)
|
||||
delete state;
|
||||
}
|
||||
|
||||
delete mStateCache;
|
||||
mStateCache = nsnull;
|
||||
}
|
||||
|
||||
// Destroy the front buffer and it's GC if one was allocated for it
|
||||
if (nsnull != mFrontBuffer) {
|
||||
if (mFrontBuffer != mRenderingSurface) {
|
||||
::XFreeGC(mFrontBuffer->display,
|
||||
mFrontBuffer->gc);
|
||||
}
|
||||
delete mFrontBuffer;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mFontMetrics);
|
||||
NS_IF_RELEASE(mFontCache);
|
||||
NS_IF_RELEASE(mContext);
|
||||
*/
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsRenderingContextMac, kRenderingContextIID)
|
||||
NS_IMPL_ADDREF(nsRenderingContextMac)
|
||||
NS_IMPL_RELEASE(nsRenderingContextMac)
|
||||
|
||||
nsresult nsRenderingContextMac :: Init(nsIDeviceContext* aContext,
|
||||
nsIWidget *aWindow)
|
||||
{
|
||||
/*
|
||||
if (nsnull == aWindow->GetNativeData(NS_NATIVE_WINDOW))
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
mContext = aContext;
|
||||
NS_IF_ADDREF(mContext);
|
||||
|
||||
mRenderingSurface = new nsDrawingSurfaceMac();
|
||||
|
||||
mRenderingSurface->display = (Display *)aWindow->GetNativeData(NS_NATIVE_DISPLAY);
|
||||
mRenderingSurface->drawable = (Drawable)aWindow->GetNativeData(NS_NATIVE_WINDOW);
|
||||
mRenderingSurface->gc = (GC)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);
|
||||
|
||||
XWindowAttributes wa;
|
||||
|
||||
::XGetWindowAttributes(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
&wa);
|
||||
|
||||
mRenderingSurface->visual = wa.visual;
|
||||
mRenderingSurface->depth = wa.depth;
|
||||
|
||||
mFrontBuffer = mRenderingSurface;
|
||||
*/
|
||||
return (CommonInit());
|
||||
}
|
||||
|
||||
nsresult nsRenderingContextMac :: Init(nsIDeviceContext* aContext,
|
||||
nsDrawingSurface aSurface)
|
||||
{
|
||||
/*
|
||||
mContext = aContext;
|
||||
NS_IF_ADDREF(mContext);
|
||||
|
||||
mRenderingSurface = (nsDrawingSurfaceMac *) aSurface;
|
||||
*/
|
||||
return (CommonInit());
|
||||
}
|
||||
|
||||
nsresult nsRenderingContextMac :: CommonInit()
|
||||
{
|
||||
/* ((nsDeviceContextMac *)mContext)->SetDrawingSurface(mRenderingSurface);
|
||||
((nsDeviceContextMac *)mContext)->InstallColormap();
|
||||
|
||||
mFontCache = mContext->GetFontCache();
|
||||
mP2T = mContext->GetDevUnitsToAppUnits();
|
||||
mTMatrix->AddScale(mContext->GetAppUnitsToDevUnits(),
|
||||
mContext->GetAppUnitsToDevUnits());*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsRenderingContextMac :: SelectOffScreenDrawingSurface(nsDrawingSurface aSurface)
|
||||
{
|
||||
|
||||
/* if (mFrontBuffer == mRenderingSurface) {
|
||||
XGCValues values;
|
||||
mFrontBuffer->gc = ::XCreateGC(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
nsnull, &values);
|
||||
}
|
||||
|
||||
mRenderingSurface = (nsDrawingSurfaceMac *) aSurface; */
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: Reset()
|
||||
{
|
||||
}
|
||||
|
||||
nsIDeviceContext * nsRenderingContextMac :: GetDeviceContext(void)
|
||||
{
|
||||
//NS_IF_ADDREF(mContext);
|
||||
//return mContext;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: PushState(void)
|
||||
{
|
||||
/*
|
||||
nsRect rect;
|
||||
|
||||
GraphicsState * state = new GraphicsState();
|
||||
|
||||
// Push into this state object, add to vector
|
||||
state->mMatrix = mTMatrix;
|
||||
|
||||
mStateCache->AppendElement(state);
|
||||
|
||||
if (nsnull == mTMatrix)
|
||||
mTMatrix = new nsTransform2D();
|
||||
else
|
||||
mTMatrix = new nsTransform2D(mTMatrix);
|
||||
|
||||
GetClipRect(state->mLocalClip);
|
||||
|
||||
state->mClipRegion = mRegion;
|
||||
|
||||
if (nsnull != state->mClipRegion) {
|
||||
mRegion = ::XCreateRegion();
|
||||
|
||||
XRectangle xrect;
|
||||
|
||||
xrect.x = state->mLocalClip.x;
|
||||
xrect.y = state->mLocalClip.y;
|
||||
xrect.width = state->mLocalClip.width;
|
||||
xrect.height = state->mLocalClip.height;
|
||||
|
||||
::XUnionRectWithRegion(&xrect, mRegion, mRegion);
|
||||
}
|
||||
|
||||
state->mColor = mCurrentColor;
|
||||
*/
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: PopState(void)
|
||||
{
|
||||
/*
|
||||
PRBool bEmpty = PR_FALSE;
|
||||
|
||||
PRUint32 cnt = mStateCache->Count();
|
||||
GraphicsState * state;
|
||||
|
||||
if (cnt > 0) {
|
||||
state = (GraphicsState *)mStateCache->ElementAt(cnt - 1);
|
||||
mStateCache->RemoveElementAt(cnt - 1);
|
||||
|
||||
// Assign all local attributes from the state object just popped
|
||||
if (mTMatrix)
|
||||
delete mTMatrix;
|
||||
mTMatrix = state->mMatrix;
|
||||
|
||||
if (nsnull != mRegion)
|
||||
::XDestroyRegion(mRegion);
|
||||
|
||||
mRegion = state->mClipRegion;
|
||||
|
||||
if (nsnull != mRegion && ::XEmptyRegion(mRegion) == True){
|
||||
bEmpty = PR_TRUE;
|
||||
}else{
|
||||
|
||||
// Select in the old region. We probably want to set a dirty flag and only
|
||||
// do this IFF we need to draw before the next Pop. We'd need to check the
|
||||
// state flag on every draw operation.
|
||||
if (nsnull != mRegion)
|
||||
::XSetRegion(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
mRegion);
|
||||
|
||||
}
|
||||
|
||||
if (state->mColor != mCurrentColor)
|
||||
SetColor(state->mColor);
|
||||
|
||||
|
||||
// Delete this graphics state object
|
||||
delete state;
|
||||
}
|
||||
|
||||
return bEmpty;*/
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: IsVisibleRect(const nsRect& aRect)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine)
|
||||
{
|
||||
/* PRBool bEmpty = PR_FALSE;
|
||||
|
||||
nsRect trect = aRect;
|
||||
|
||||
XRectangle xrect;
|
||||
|
||||
xrect.x = trect.x;
|
||||
xrect.y = trect.y;
|
||||
xrect.width = trect.width;
|
||||
xrect.height = trect.height;
|
||||
|
||||
Region a = ::XCreateRegion();
|
||||
::XUnionRectWithRegion(&xrect, a, a);
|
||||
|
||||
if (aCombine == nsClipCombine_kIntersect)
|
||||
{
|
||||
Region tRegion = ::XCreateRegion();
|
||||
|
||||
if (nsnull != mRegion) {
|
||||
::XIntersectRegion(a, mRegion, tRegion);
|
||||
::XDestroyRegion(mRegion);
|
||||
::XDestroyRegion(a);
|
||||
mRegion = tRegion;
|
||||
} else {
|
||||
::XDestroyRegion(tRegion);
|
||||
mRegion = a;
|
||||
}
|
||||
|
||||
}
|
||||
else if (aCombine == nsClipCombine_kUnion)
|
||||
{
|
||||
if (nsnull != mRegion) {
|
||||
Region tRegion = ::XCreateRegion();
|
||||
::XUnionRegion(a, mRegion, tRegion);
|
||||
::XDestroyRegion(mRegion);
|
||||
::XDestroyRegion(a);
|
||||
mRegion = tRegion;
|
||||
} else {
|
||||
mRegion = a;
|
||||
}
|
||||
|
||||
}
|
||||
else if (aCombine == nsClipCombine_kSubtract)
|
||||
{
|
||||
|
||||
if (nsnull != mRegion) {
|
||||
|
||||
Region tRegion = ::XCreateRegion();
|
||||
::XSubtractRegion(mRegion, a, tRegion);
|
||||
::XDestroyRegion(mRegion);
|
||||
::XDestroyRegion(a);
|
||||
mRegion = tRegion;
|
||||
|
||||
} else {
|
||||
mRegion = a;
|
||||
}
|
||||
|
||||
}
|
||||
else if (aCombine == nsClipCombine_kReplace)
|
||||
{
|
||||
|
||||
if (nsnull != mRegion)
|
||||
::XDestroyRegion(mRegion);
|
||||
|
||||
mRegion = a;
|
||||
|
||||
}
|
||||
else
|
||||
NS_ASSERTION(PR_FALSE, "illegal clip combination");
|
||||
|
||||
if (::XEmptyRegion(mRegion) == True) {
|
||||
|
||||
bEmpty = PR_TRUE;
|
||||
::XSetClipMask(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
None);
|
||||
|
||||
} else {
|
||||
|
||||
::XSetRegion(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
mRegion);
|
||||
|
||||
}
|
||||
|
||||
return bEmpty;
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: SetClipRect(const nsRect& aRect, nsClipCombine aCombine)
|
||||
{
|
||||
nsRect trect = aRect;
|
||||
|
||||
mTMatrix->TransformCoord(&trect.x, &trect.y,
|
||||
&trect.width, &trect.height);
|
||||
return(SetClipRectInPixels(trect,aCombine));
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: GetClipRect(nsRect &aRect)
|
||||
{
|
||||
|
||||
if (mRegion != nsnull) {
|
||||
XRectangle xrect;
|
||||
::XClipBox(mRegion, &xrect);
|
||||
aRect.SetRect(xrect.x, xrect.y, xrect.width, xrect.height);
|
||||
} else {
|
||||
aRect.SetRect(0,0,0,0);
|
||||
return (PR_TRUE);
|
||||
}
|
||||
if (::XEmptyRegion(mRegion) == True)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
PRBool nsRenderingContextMac :: SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine)
|
||||
{
|
||||
nsRect rect;
|
||||
XRectangle xrect;
|
||||
|
||||
nsRegionMac *pRegion = (nsRegionMac *)&aRegion;
|
||||
Region xregion = pRegion->GetXRegion();
|
||||
|
||||
::XClipBox(xregion, &xrect);
|
||||
|
||||
rect.x = xrect.x;
|
||||
rect.y = xrect.y;
|
||||
rect.width = xrect.width;
|
||||
rect.height = xrect.height;
|
||||
|
||||
SetClipRectInPixels(rect, aCombine);
|
||||
|
||||
if (::XEmptyRegion(mRegion) == True)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: GetClipRegion(nsIRegion **aRegion)
|
||||
{
|
||||
|
||||
nsIRegion * pRegion ;
|
||||
|
||||
static NS_DEFINE_IID(kCRegionCID, NS_REGION_CID);
|
||||
static NS_DEFINE_IID(kIRegionIID, NS_IREGION_IID);
|
||||
|
||||
nsresult rv = NSRepository::CreateInstance(kCRegionCID,
|
||||
nsnull,
|
||||
kIRegionIID,
|
||||
(void **)aRegion);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
nsRect rect;
|
||||
pRegion = (nsIRegion *)&aRegion;
|
||||
pRegion->Init();
|
||||
this->GetClipRect(rect);
|
||||
pRegion->Union(rect.x,rect.y,rect.width,rect.height);
|
||||
}
|
||||
|
||||
return ;
|
||||
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: SetColor(nscolor aColor)
|
||||
{
|
||||
XGCValues values ;
|
||||
|
||||
mCurrentColor = ((nsDeviceContextMac *)mContext)->ConvertPixel(aColor);
|
||||
|
||||
values.foreground = mCurrentColor;
|
||||
values.background = mCurrentColor;
|
||||
|
||||
::XChangeGC(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
GCForeground | GCBackground,
|
||||
&values);
|
||||
|
||||
mCurrentColor = aColor ;
|
||||
|
||||
}
|
||||
|
||||
nscolor nsRenderingContextMac :: GetColor() const
|
||||
{
|
||||
return mCurrentColor;
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: SetFont(const nsFont& aFont)
|
||||
{
|
||||
NS_IF_RELEASE(mFontMetrics);
|
||||
mFontMetrics = mFontCache->GetMetricsFor(aFont);
|
||||
|
||||
if (mFontMetrics)
|
||||
{
|
||||
// mCurrFontHandle = ::XLoadFont(mRenderingSurface->display, (char *)mFontMetrics->GetFontHandle());
|
||||
mCurrFontHandle = (Font)mFontMetrics->GetFontHandle();
|
||||
|
||||
::XSetFont(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
mCurrFontHandle);
|
||||
|
||||
// ::XFlushGC(mRenderingSurface->display,
|
||||
// mRenderingSurface->gc);
|
||||
}
|
||||
}
|
||||
|
||||
const nsFont& nsRenderingContextMac :: GetFont()
|
||||
{
|
||||
return mFontMetrics->GetFont();
|
||||
}
|
||||
|
||||
nsIFontMetrics* nsRenderingContextMac :: GetFontMetrics()
|
||||
{
|
||||
return mFontMetrics;
|
||||
}
|
||||
|
||||
// add the passed in translation to the current translation
|
||||
void nsRenderingContextMac :: Translate(nscoord aX, nscoord aY)
|
||||
{
|
||||
mTMatrix->AddTranslation((float)aX,(float)aY);
|
||||
}
|
||||
|
||||
// add the passed in scale to the current scale
|
||||
void nsRenderingContextMac :: Scale(float aSx, float aSy)
|
||||
{
|
||||
mTMatrix->AddScale(aSx, aSy);
|
||||
}
|
||||
|
||||
nsTransform2D * nsRenderingContextMac :: GetCurrentTransform()
|
||||
{
|
||||
return mTMatrix;
|
||||
}
|
||||
|
||||
nsDrawingSurface nsRenderingContextMac :: CreateDrawingSurface(nsRect *aBounds)
|
||||
{
|
||||
// Must make sure this code never gets called when nsRenderingSurface is nsnull
|
||||
PRUint32 depth = DefaultDepth(mRenderingSurface->display,
|
||||
DefaultScreen(mRenderingSurface->display));
|
||||
Pixmap p;
|
||||
|
||||
if (aBounds != nsnull) {
|
||||
p = ::XCreatePixmap(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
aBounds->width, aBounds->height, depth);
|
||||
} else {
|
||||
p = ::XCreatePixmap(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
2, 2, depth);
|
||||
}
|
||||
|
||||
nsDrawingSurfaceMac * surface = new nsDrawingSurfaceMac();
|
||||
|
||||
surface->drawable = p ;
|
||||
surface->display = mRenderingSurface->display;
|
||||
surface->gc = mFrontBuffer->gc;
|
||||
surface->visual = mRenderingSurface->visual;
|
||||
surface->depth = mRenderingSurface->depth;
|
||||
|
||||
return ((nsDrawingSurface)surface);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DestroyDrawingSurface(nsDrawingSurface aDS)
|
||||
{
|
||||
nsDrawingSurfaceMac * surface = (nsDrawingSurfaceMac *) aDS;
|
||||
|
||||
// XXX - Could this be a GC? If so, store the type of surface in nsDrawingSurfaceMac
|
||||
::XFreePixmap(surface->display, surface->drawable);
|
||||
|
||||
//XXX greg, this seems bad. MMP
|
||||
if (mRenderingSurface == surface)
|
||||
mRenderingSurface = nsnull;
|
||||
|
||||
delete aDS;
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1)
|
||||
{
|
||||
mTMatrix->TransformCoord(&aX0,&aY0);
|
||||
mTMatrix->TransformCoord(&aX1,&aY1);
|
||||
|
||||
::XDrawLine(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
aX0, aY0, aX1, aY1);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawRect(const nsRect& aRect)
|
||||
{
|
||||
DrawRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
::XDrawRectangle(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillRect(const nsRect& aRect)
|
||||
{
|
||||
FillRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
::XFillRectangle(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void nsRenderingContextMac::DrawPolygon(nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
PRUint32 i ;
|
||||
XPoint * xpoints;
|
||||
XPoint * thispoint;
|
||||
|
||||
xpoints = (XPoint *) PR_Malloc(sizeof(XPoint) * aNumPoints);
|
||||
|
||||
for (i = 0; i < aNumPoints; i++){
|
||||
thispoint = (xpoints+i);
|
||||
thispoint->x = aPoints[i].x;
|
||||
thispoint->y = aPoints[i].y;
|
||||
mTMatrix->TransformCoord((PRInt32*)&thispoint->x,(PRInt32*)&thispoint->y);
|
||||
}
|
||||
|
||||
::XDrawLines(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
xpoints, aNumPoints, CoordModeOrigin);
|
||||
|
||||
PR_Free((void *)xpoints);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac::FillPolygon(nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
PRUint32 i ;
|
||||
XPoint * xpoints;
|
||||
XPoint * thispoint;
|
||||
nscoord x,y;
|
||||
|
||||
xpoints = (XPoint *) PR_Malloc(sizeof(XPoint) * aNumPoints);
|
||||
|
||||
for (i = 0; i < aNumPoints; i++){
|
||||
thispoint = (xpoints+i);
|
||||
x = aPoints[i].x;
|
||||
y = aPoints[i].y;
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
thispoint->x = x;
|
||||
thispoint->y = y;
|
||||
}
|
||||
|
||||
::XFillPolygon(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
xpoints, aNumPoints, Convex, CoordModeOrigin);
|
||||
|
||||
PR_Free((void *)xpoints);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawEllipse(const nsRect& aRect)
|
||||
{
|
||||
DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
::XDrawArc(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h, 0, 360 * 64);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillEllipse(const nsRect& aRect)
|
||||
{
|
||||
FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
::XFillArc(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h, 0, 360 * 64);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle)
|
||||
{
|
||||
this->DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle)
|
||||
{
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
::XDrawArc(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h, NS_TO_INT_ROUND(aStartAngle * 64.0f),
|
||||
NS_TO_INT_ROUND(aEndAngle * 64.0f));
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle)
|
||||
{
|
||||
this->FillArc(aRect.x, aRect.y, aRect.width, aRect.height, aStartAngle, aEndAngle);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle)
|
||||
{
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
::XFillArc(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x,y,w,h, NS_TO_INT_ROUND(aStartAngle * 64.0f),
|
||||
NS_TO_INT_ROUND(aEndAngle * 64.0f));
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawString(const char *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY,
|
||||
nscoord aWidth)
|
||||
{
|
||||
PRInt32 x = aX;
|
||||
PRInt32 y = aY;
|
||||
|
||||
// Substract xFontStruct ascent since drawing specifies baseline
|
||||
if (mFontMetrics)
|
||||
y += mFontMetrics->GetMaxAscent();
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
|
||||
::XDrawString(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x, y, aString, aLength);
|
||||
|
||||
if (mFontMetrics)
|
||||
{
|
||||
PRUint8 deco = mFontMetrics->GetFont().decorations;
|
||||
|
||||
if (deco & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
|
||||
if (deco & NS_FONT_DECORATION_UNDERLINE)
|
||||
{
|
||||
nscoord ascent = mFontMetrics->GetMaxAscent();
|
||||
nscoord descent = mFontMetrics->GetMaxDescent();
|
||||
|
||||
DrawLine(aX, aY + ascent + (descent >> 1),
|
||||
aX + aWidth, aY + ascent + (descent >> 1));
|
||||
}
|
||||
|
||||
if (deco & NS_FONT_DECORATION_LINE_THROUGH)
|
||||
{
|
||||
nscoord height = mFontMetrics->GetHeight();
|
||||
|
||||
DrawLine(aX, aY + (height >> 1), aX + aWidth, aY + (height >> 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawString(const PRUnichar *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY, nscoord aWidth)
|
||||
{
|
||||
PRInt32 x = aX;
|
||||
PRInt32 y = aY;
|
||||
|
||||
// Substract xFontStruct ascent since drawing specifies baseline
|
||||
if (mFontMetrics)
|
||||
y += mFontMetrics->GetMaxAscent();
|
||||
|
||||
mTMatrix->TransformCoord(&x, &y);
|
||||
|
||||
::XDrawString16(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mRenderingSurface->gc,
|
||||
x, y, (XChar2b *)aString, aLength);
|
||||
|
||||
if (mFontMetrics)
|
||||
{
|
||||
PRUint8 deco = mFontMetrics->GetFont().decorations;
|
||||
|
||||
if (deco & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
|
||||
if (deco & NS_FONT_DECORATION_UNDERLINE)
|
||||
{
|
||||
nscoord ascent = mFontMetrics->GetMaxAscent();
|
||||
nscoord descent = mFontMetrics->GetMaxDescent();
|
||||
|
||||
DrawLine(aX, aY + ascent + (descent >> 1),
|
||||
aX + aWidth, aY + ascent + (descent >> 1));
|
||||
}
|
||||
|
||||
if (deco & NS_FONT_DECORATION_LINE_THROUGH)
|
||||
{
|
||||
nscoord height = mFontMetrics->GetHeight();
|
||||
|
||||
DrawLine(aX, aY + (height >> 1), aX + aWidth, aY + (height >> 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawString(const nsString& aString,
|
||||
nscoord aX, nscoord aY, nscoord aWidth)
|
||||
{
|
||||
DrawString(aString.GetUnicode(), aString.Length(), aX, aY, aWidth);
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawImage(nsIImage *aImage, nscoord aX, nscoord aY)
|
||||
{
|
||||
nscoord width,height;
|
||||
width = NS_TO_INT_ROUND(mP2T * aImage->GetWidth());
|
||||
height = NS_TO_INT_ROUND(mP2T * aImage->GetHeight());
|
||||
|
||||
this->DrawImage(aImage,aX,aY,width,height);8?
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
|
||||
nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
/* nsRect tr;
|
||||
|
||||
tr.x = aX;
|
||||
tr.y = aY;
|
||||
tr.width = aWidth;
|
||||
tr.height = aHeight;
|
||||
this->DrawImage(aImage,tr);*/
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect)
|
||||
{
|
||||
/* nsRect sr,dr;
|
||||
|
||||
sr = aSRect;
|
||||
mTMatrix ->TransformCoord(&sr.x,&sr.y,&sr.width,&sr.height);
|
||||
|
||||
dr = aDRect;
|
||||
mTMatrix->TransformCoord(&dr.x,&dr.y,&dr.width,&dr.height);
|
||||
|
||||
((nsImageMac*)aImage)->Draw(*this,mRenderingSurface,sr.x,sr.y,sr.width,sr.height,
|
||||
dr.x,dr.y,dr.width,dr.height);*/
|
||||
}
|
||||
|
||||
void nsRenderingContextMac :: DrawImage(nsIImage *aImage, const nsRect& aRect)
|
||||
{
|
||||
/* nsRect tr;
|
||||
|
||||
tr = aRect;
|
||||
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
|
||||
|
||||
if (aImage != nsnull) {
|
||||
((nsImageMac*)aImage)->Draw(*this,mRenderingSurface,tr.x,tr.y,tr.width,tr.height);
|
||||
} else {
|
||||
printf("Image is NULL!\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
nsresult nsRenderingContextMac :: CopyOffScreenBits(nsRect &aBounds)
|
||||
{
|
||||
/*
|
||||
|
||||
::XSetClipMask(mFrontBuffer->display,
|
||||
mFrontBuffer->gc,
|
||||
None);
|
||||
|
||||
|
||||
::XCopyArea(mRenderingSurface->display,
|
||||
mRenderingSurface->drawable,
|
||||
mFrontBuffer->drawable,
|
||||
mFrontBuffer->gc,
|
||||
aBounds.x, aBounds.y, aBounds.width, aBounds.height, 0, 0);
|
||||
|
||||
if (nsnull != mRegion)
|
||||
::XSetRegion(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
mRegion);
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
151
gfx/src/mac/nsRenderingContextMac.h
Normal file
151
gfx/src/mac/nsRenderingContextMac.h
Normal file
@ -0,0 +1,151 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsRenderingContextMac_h___
|
||||
#define nsRenderingContextMac_h___
|
||||
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsPoint.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsTransform2D.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsIFontCache.h"
|
||||
#include "nsImageMac.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIRegion.h"
|
||||
#include "nsDeviceContextMac.h"
|
||||
|
||||
class GraphicsState;
|
||||
|
||||
class nsRenderingContextMac : public nsIRenderingContext
|
||||
{
|
||||
public:
|
||||
nsRenderingContextMac();
|
||||
~nsRenderingContextMac();
|
||||
|
||||
void* operator new(size_t sz) {
|
||||
void* rv = new char[sz];
|
||||
nsCRT::zero(rv, sz);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
|
||||
virtual nsresult Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface);
|
||||
virtual nsresult CommonInit();
|
||||
|
||||
virtual void Reset();
|
||||
|
||||
virtual nsIDeviceContext * GetDeviceContext(void);
|
||||
|
||||
virtual nsresult SelectOffScreenDrawingSurface(nsDrawingSurface aSurface);
|
||||
|
||||
virtual void PushState(void);
|
||||
virtual PRBool PopState(void);
|
||||
|
||||
virtual PRBool IsVisibleRect(const nsRect& aRect);
|
||||
|
||||
virtual PRBool SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine);
|
||||
virtual PRBool SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
|
||||
virtual PRBool GetClipRect(nsRect &aRect);
|
||||
virtual PRBool SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
|
||||
virtual void GetClipRegion(nsIRegion **aRegion);
|
||||
|
||||
virtual void SetColor(nscolor aColor);
|
||||
virtual nscolor GetColor() const;
|
||||
|
||||
virtual void SetFont(const nsFont& aFont);
|
||||
virtual const nsFont& GetFont();
|
||||
|
||||
virtual nsIFontMetrics * GetFontMetrics();
|
||||
|
||||
virtual void Translate(nscoord aX, nscoord aY);
|
||||
virtual void Scale(float aSx, float aSy);
|
||||
virtual nsTransform2D * GetCurrentTransform();
|
||||
|
||||
virtual nsDrawingSurface CreateDrawingSurface(nsRect *aBounds);
|
||||
virtual void DestroyDrawingSurface(nsDrawingSurface aDS);
|
||||
|
||||
virtual void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
|
||||
|
||||
virtual void DrawRect(const nsRect& aRect);
|
||||
virtual void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
virtual void FillRect(const nsRect& aRect);
|
||||
virtual void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
virtual void DrawPolygon(nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
virtual void FillPolygon(nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
virtual void DrawEllipse(const nsRect& aRect);
|
||||
virtual void DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
virtual void FillEllipse(const nsRect& aRect);
|
||||
virtual void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
virtual void DrawArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle);
|
||||
virtual void DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle);
|
||||
virtual void FillArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle);
|
||||
virtual void FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle);
|
||||
|
||||
virtual void DrawString(const char *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY,
|
||||
nscoord aWidth);
|
||||
virtual void DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY,
|
||||
nscoord aWidth);
|
||||
virtual void DrawString(const nsString& aString, nscoord aX, nscoord aY,
|
||||
nscoord aWidth);
|
||||
|
||||
virtual void DrawImage(nsIImage *aImage, nscoord aX, nscoord aY);
|
||||
virtual void DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
|
||||
nscoord aWidth, nscoord aHeight);
|
||||
virtual void DrawImage(nsIImage *aImage, const nsRect& aRect);
|
||||
virtual void DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect);
|
||||
|
||||
virtual nsresult CopyOffScreenBits(nsRect &aBounds);
|
||||
|
||||
protected:
|
||||
|
||||
/*nscolor mCurrentColor ;
|
||||
nsTransform2D *mTMatrix; // transform that all the graphics drawn here will obey
|
||||
float mP2T;
|
||||
|
||||
nsDrawingSurfaceMac *mRenderingSurface; // Can be a BackBuffer if Selected in
|
||||
nsDrawingSurfaceMac *mFrontBuffer;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
nsIFontCache *mFontCache;
|
||||
Region mRegion;
|
||||
Font mCurrFontHandle;*/
|
||||
|
||||
//state management
|
||||
nsVoidArray *mStateCache;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsRenderingContextMac_h___ */
|
532
widget/src/mac/nsDeviceContextMac.cpp
Normal file
532
widget/src/mac/nsDeviceContextMac.cpp
Normal file
@ -0,0 +1,532 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextMac.h"
|
||||
#include "nsRenderingContextMac.h"
|
||||
//XXX#include "../nsGfxCIID.h"
|
||||
|
||||
#include "math.h"
|
||||
#include "nspr.h"
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
|
||||
#define NS_TO_X_COMPONENT(a) ((a << 8) | (a))
|
||||
|
||||
#define NS_TO_X_RED(a) (((NS_GET_R(a) >> (8 - mRedBits)) << mRedOffset) & mRedMask)
|
||||
#define NS_TO_X_GREEN(a) (((NS_GET_G(a) >> (8 - mGreenBits)) << mGreenOffset) & mGreenMask)
|
||||
#define NS_TO_X_BLUE(a) (((NS_GET_B(a) >> (8 - mBlueBits)) << mBlueOffset) & mBlueMask)
|
||||
|
||||
#define NS_TO_X(a) (NS_TO_X_RED(a) | NS_TO_X_GREEN(a) | NS_TO_X_BLUE(a))
|
||||
|
||||
|
||||
nsDeviceContextMac :: nsDeviceContextMac()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
/*mFontCache = nsnull;
|
||||
mSurface = nsnull;
|
||||
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
|
||||
mDevUnitsToAppUnits = 1.0f;
|
||||
mAppUnitsToDevUnits = 1.0f;
|
||||
|
||||
mGammaValue = 1.0f;
|
||||
mGammaTable = new PRUint8[256];
|
||||
|
||||
mZoom = 1.0f;
|
||||
|
||||
mVisual = nsnull;
|
||||
|
||||
mRedMask = 0;
|
||||
mGreenMask = 0;
|
||||
mBlueMask = 0;
|
||||
|
||||
mRedBits = 0;
|
||||
mGreenBits = 0;
|
||||
mBlueBits = 0;
|
||||
|
||||
mRedOffset = 0;
|
||||
mGreenOffset = 0;
|
||||
mBlueOffset = 0;
|
||||
|
||||
mNativeWidget = nsnull;
|
||||
|
||||
mDepth = 0 ;
|
||||
mColormap = 0 ;*/
|
||||
}
|
||||
|
||||
nsDeviceContextMac :: ~nsDeviceContextMac()
|
||||
{
|
||||
// XXX Does the Mac have gamma stuff in quickdraw so we don't have to write our own?
|
||||
|
||||
/*if (nsnull != mGammaTable)
|
||||
{
|
||||
delete mGammaTable;
|
||||
mGammaTable = nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mFontCache);
|
||||
|
||||
if (mSurface) delete mSurface;*/
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextMac, kDeviceContextIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextMac)
|
||||
NS_IMPL_RELEASE(nsDeviceContextMac)
|
||||
|
||||
nsresult nsDeviceContextMac :: Init(nsNativeWidget aNativeWidget)
|
||||
{
|
||||
NS_ASSERTION(!(aNativeWidget == nsnull), "attempt to init devicecontext with null widget");
|
||||
|
||||
/*for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
mGammaTable[cnt] = cnt;*/
|
||||
|
||||
// XXX We really need to have Display passed to us since it could be specified
|
||||
// not from the environment, which is the one we use here.
|
||||
|
||||
/* XXX rewrite for mac
|
||||
mNativeWidget = aNativeWidget;
|
||||
|
||||
if (nsnull != mNativeWidget)
|
||||
{
|
||||
mTwipsToPixels = (((float)::XDisplayWidth(XtDisplay((Widget)mNativeWidget), DefaultScreen(XtDisplay((Widget)mNativeWidget)))) /
|
||||
((float)::XDisplayWidthMM(XtDisplay((Widget)mNativeWidget),DefaultScreen(XtDisplay((Widget)mNativeWidget)) )) * 25.4) /
|
||||
NS_POINTS_TO_TWIPS_FLOAT(72.0f);
|
||||
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
}*/
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetTwipsToDevUnits() const
|
||||
{
|
||||
//return mTwipsToPixels;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetDevUnitsToTwips() const
|
||||
{
|
||||
// return mPixelsToTwips;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
||||
void nsDeviceContextMac :: SetAppUnitsToDevUnits(float aAppUnits)
|
||||
{
|
||||
// mAppUnitsToDevUnits = aAppUnits;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetDevUnitsToAppUnits(float aDevUnits)
|
||||
{
|
||||
// mDevUnitsToAppUnits = aDevUnits;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetAppUnitsToDevUnits() const
|
||||
{
|
||||
//return mAppUnitsToDevUnits;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetDevUnitsToAppUnits() const
|
||||
{
|
||||
// return mDevUnitsToAppUnits;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetScrollBarWidth() const
|
||||
{
|
||||
// XXX Should we push this to widget library
|
||||
return 240.0;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetScrollBarHeight() const
|
||||
{
|
||||
// XXX Should we push this to widget library
|
||||
return 240.0;
|
||||
}
|
||||
|
||||
nsIRenderingContext * nsDeviceContextMac :: CreateRenderingContext(nsIView *aView)
|
||||
{
|
||||
/*nsIRenderingContext *pContext = nsnull;
|
||||
nsIWidget *win = aView->GetWidget();
|
||||
nsresult rv;
|
||||
|
||||
static NS_DEFINE_IID(kRCCID, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kRCIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
rv = InitRenderingContext(pContext, win);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(pContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(win);
|
||||
return pContext;*/
|
||||
return nsnull; /// XXX need something reasonable here
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextMac :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
{
|
||||
return (aContext->Init(this, aWin));
|
||||
}
|
||||
|
||||
nsIFontCache* nsDeviceContextMac::GetFontCache()
|
||||
{
|
||||
/*if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
NS_ADDREF(mFontCache);
|
||||
return mFontCache;*/
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextMac::CreateFontCache()
|
||||
{
|
||||
/*nsresult rv = NS_NewFontCache(&mFontCache);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
mFontCache->Init(this);*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac::FlushFontCache()
|
||||
{
|
||||
//NS_RELEASE(mFontCache);
|
||||
}
|
||||
|
||||
|
||||
nsIFontMetrics* nsDeviceContextMac::GetMetricsFor(const nsFont& aFont)
|
||||
{
|
||||
/*if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
return mFontCache->GetMetricsFor(aFont);*/
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetZoom(float aZoom)
|
||||
{
|
||||
// mZoom = aZoom;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetZoom() const
|
||||
{
|
||||
//return mZoom;
|
||||
return 0.0; // should be 1.0 perhaps?
|
||||
}
|
||||
|
||||
nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface(nsIRenderingContext &aContext)
|
||||
{
|
||||
//return aContext.CreateDrawingSurface(nsnull);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
float nsDeviceContextMac :: GetGamma(void)
|
||||
{
|
||||
//return mGammaValue;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetGamma(float aGamma)
|
||||
{/*
|
||||
if (aGamma != mGammaValue)
|
||||
{
|
||||
//we don't need to-recorrect existing images for this case
|
||||
//so pass in 1.0 for the current gamma regardless of what it
|
||||
//really happens to be. existing images will get a one time
|
||||
//re-correction when they're rendered the next time. MMP
|
||||
|
||||
SetGammaTable(mGammaTable, 1.0f, aGamma);
|
||||
|
||||
mGammaValue = aGamma;
|
||||
}*/
|
||||
}
|
||||
|
||||
PRUint8 * nsDeviceContextMac :: GetGammaTable(void)
|
||||
{
|
||||
//XXX we really need to ref count this somehow. MMP
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma)
|
||||
{
|
||||
/*double fgval = (1.0f / aCurrentGamma) * (1.0f / aNewGamma);
|
||||
|
||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
aTable[cnt] = (PRUint8)(pow((double)cnt * (1. / 256.), fgval) * 255.99999999);*/
|
||||
}
|
||||
|
||||
nsNativeWidget nsDeviceContextMac :: GetNativeWidget(void)
|
||||
{
|
||||
//XXX return mNativeWidget;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRUint32 nsDeviceContextMac :: ConvertPixel(nscolor aColor)
|
||||
{
|
||||
PRUint32 newcolor = 0;
|
||||
|
||||
/*
|
||||
For now, we assume anything in 12 planes or more is a TrueColor visual.
|
||||
If it is not (like older IRIS GL graphics boards, we'll look stupid for now.
|
||||
*/
|
||||
|
||||
/* switch (mDepth) {
|
||||
|
||||
case 8:
|
||||
{
|
||||
|
||||
if (mWriteable == PR_FALSE) {
|
||||
|
||||
Status rc ;
|
||||
XColor colorcell;
|
||||
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
colorcell.pixel = 0;
|
||||
colorcell.flags = 0;
|
||||
colorcell.pad = 0;
|
||||
|
||||
// On static displays, this will return closest match
|
||||
rc = ::XAllocColor(mSurface->display,
|
||||
mColormap,
|
||||
&colorcell);
|
||||
|
||||
if (rc == 0) {
|
||||
// Punt ... this cannot happen!
|
||||
fprintf(stderr,"WHOA! IT FAILED!\n");
|
||||
} else {
|
||||
newcolor = colorcell.pixel;
|
||||
} // rc == 0
|
||||
} else {
|
||||
|
||||
// Check to see if this exact color is present. If not, add it ourselves.
|
||||
// If there are no unallocated cells left, do our own closest match lookup
|
||||
//since X doesn't provide us with one.
|
||||
|
||||
Status rc ;
|
||||
XColor colorcell;
|
||||
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
colorcell.pixel = 0;
|
||||
colorcell.flags = 0;
|
||||
colorcell.pad = 0;
|
||||
|
||||
// On non-static displays, this may fail
|
||||
rc = ::XAllocColor(mSurface->display,
|
||||
mColormap,
|
||||
&colorcell);
|
||||
|
||||
if (rc == 0) {
|
||||
|
||||
// The color does not already exist AND we do not have any unallocated colorcells left
|
||||
// At his point we need to implement our own lookup matching algorithm.
|
||||
|
||||
unsigned long pixel;
|
||||
|
||||
rc = ::XAllocColorCells(mSurface->display,
|
||||
mColormap,
|
||||
False,0,0,
|
||||
&pixel,
|
||||
1);
|
||||
|
||||
if (rc == 0){
|
||||
|
||||
fprintf(stderr, "Failed to allocate Color cells...this sux\n");
|
||||
|
||||
} else {
|
||||
|
||||
colorcell.pixel = pixel;
|
||||
colorcell.pad = 0 ;
|
||||
colorcell.flags = DoRed | DoGreen | DoBlue ;
|
||||
colorcell.red = NS_TO_X_COMPONENT(NS_GET_R(aColor));
|
||||
colorcell.green = NS_TO_X_COMPONENT(NS_GET_G(aColor));
|
||||
colorcell.blue = NS_TO_X_COMPONENT(NS_GET_B(aColor));
|
||||
|
||||
::XStoreColor(mSurface->display, mColormap, &colorcell);
|
||||
|
||||
newcolor = colorcell.pixel;
|
||||
|
||||
} // rc == 0
|
||||
} else {
|
||||
newcolor = colorcell.pixel;
|
||||
} // rc == 0
|
||||
} // mWriteable == FALSE
|
||||
} // 8
|
||||
break;
|
||||
|
||||
case 12:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 12
|
||||
break;
|
||||
|
||||
case 15:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 15
|
||||
break;
|
||||
|
||||
case 16:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
} // 16
|
||||
break;
|
||||
|
||||
case 24:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
//newcolor = (PRUint32)NS_TO_X24(aColor);
|
||||
} // 24
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
newcolor = (PRUint32)NS_TO_X(aColor);
|
||||
// newcolor = (PRUint32) aColor;
|
||||
} // default
|
||||
break;
|
||||
|
||||
} // switch(mDepth)
|
||||
*/
|
||||
return (newcolor);
|
||||
}
|
||||
|
||||
void nsDeviceContextMac :: InstallColormap()
|
||||
{
|
||||
#if 0
|
||||
/*
|
||||
Unfortunately, we don't have control of the visual created for this display.
|
||||
That should be managed at an application level, since the gfx only cares that all
|
||||
values be passed in as 32 bit RGBA quantites.
|
||||
|
||||
This means we have to write lots and lots of code to support the fact that any
|
||||
number of visuals may be the one associated with this device context.
|
||||
*/
|
||||
|
||||
//XWindowAttributes wa;
|
||||
|
||||
|
||||
/* Already installed? */
|
||||
if (0 != mColormap)
|
||||
return;
|
||||
|
||||
// Find the depth of this visual
|
||||
::XGetWindowAttributes(mSurface->display,
|
||||
mSurface->drawable,
|
||||
&wa);
|
||||
|
||||
mDepth = wa.depth;
|
||||
|
||||
// Check to see if the colormap is writable
|
||||
mVisual = wa.visual;
|
||||
|
||||
if (mVisual->c_class == GrayScale || mVisual->c_class == PseudoColor || mVisual->c_class == DirectColor)
|
||||
mWriteable = PR_TRUE;
|
||||
else // We have StaticGray, StaticColor or TrueColor
|
||||
mWriteable = PR_FALSE;
|
||||
|
||||
mNumCells = pow(2, mDepth);
|
||||
|
||||
mColormap = wa.colormap;
|
||||
|
||||
// if the colormap is writeable .....
|
||||
if (mWriteable) {
|
||||
|
||||
// XXX We should check the XExtensions to see if this hardware supports multiple
|
||||
// hardware colormaps. If so, change this colormap to be a RGB ramp.
|
||||
if (mDepth == 8) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Compute rgb masks and number of bits for each
|
||||
mRedMask = mVisual->red_mask;
|
||||
mGreenMask = mVisual->green_mask;
|
||||
mBlueMask = mVisual->blue_mask;
|
||||
|
||||
PRUint32 i = mRedMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0) {
|
||||
mRedBits++;
|
||||
} else {
|
||||
mRedOffset++;
|
||||
}
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
|
||||
i = mGreenMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0)
|
||||
mGreenBits++;
|
||||
else
|
||||
mGreenOffset++;
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
|
||||
i = mBlueMask;
|
||||
|
||||
while (i) {
|
||||
|
||||
if ((i & 0x1) != 0)
|
||||
mBlueBits++;
|
||||
else
|
||||
mBlueOffset++;
|
||||
|
||||
i = i >> 1;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
nsDrawingSurface nsDeviceContextMac :: GetDrawingSurface()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
125
widget/src/mac/nsDeviceContextMac.h
Normal file
125
widget/src/mac/nsDeviceContextMac.h
Normal file
@ -0,0 +1,125 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextMac_h___
|
||||
#define nsDeviceContextMac_h___
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIFontCache.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
|
||||
/* nsDrawingSurface is actually the following struct */
|
||||
struct nsDrawingSurfaceMac {
|
||||
/* Display *display ;
|
||||
Drawable drawable ;
|
||||
GC gc ;
|
||||
Visual * visual ;
|
||||
PRUint32 depth ; */
|
||||
};
|
||||
|
||||
class nsDeviceContextMac : public nsIDeviceContext
|
||||
{
|
||||
public:
|
||||
nsDeviceContextMac();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(nsNativeWidget aNativeWidget);
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView);
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
|
||||
virtual float GetTwipsToDevUnits() const;
|
||||
virtual float GetDevUnitsToTwips() const;
|
||||
|
||||
virtual void SetAppUnitsToDevUnits(float aAppUnits);
|
||||
virtual void SetDevUnitsToAppUnits(float aDevUnits);
|
||||
|
||||
virtual float GetAppUnitsToDevUnits() const;
|
||||
virtual float GetDevUnitsToAppUnits() const;
|
||||
|
||||
virtual float GetScrollBarWidth() const;
|
||||
virtual float GetScrollBarHeight() const;
|
||||
|
||||
virtual nsIFontCache * GetFontCache();
|
||||
virtual void FlushFontCache();
|
||||
|
||||
virtual nsIFontMetrics* GetMetricsFor(const nsFont& aFont);
|
||||
|
||||
virtual void SetZoom(float aZoom);
|
||||
virtual float GetZoom() const;
|
||||
|
||||
virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext);
|
||||
|
||||
//functions for handling gamma correction of output device
|
||||
virtual float GetGamma(void);
|
||||
virtual void SetGamma(float aGamma);
|
||||
|
||||
//XXX the return from this really needs to be ref counted somehow. MMP
|
||||
virtual PRUint8 * GetGammaTable(void);
|
||||
|
||||
virtual nsNativeWidget GetNativeWidget(void);
|
||||
|
||||
virtual PRUint32 ConvertPixel(nscolor aColor);
|
||||
|
||||
protected:
|
||||
~nsDeviceContextMac();
|
||||
nsresult CreateFontCache();
|
||||
|
||||
//nsIFontCache *mFontCache;
|
||||
//nsDrawingSurfaceMac * mSurface ;
|
||||
|
||||
/*PRUint32 mDepth;
|
||||
Visual * mVisual;
|
||||
PRBool mWriteable;
|
||||
PRUint32 mNumCells;
|
||||
Colormap mColormap;*/
|
||||
// XXX There should be a nsIColormap interface
|
||||
|
||||
/*float mTwipsToPixels;
|
||||
float mPixelsToTwips;
|
||||
float mAppUnitsToDevUnits;
|
||||
float mDevUnitsToAppUnits;
|
||||
float mZoom;
|
||||
float mGammaValue;
|
||||
PRUint8 *mGammaTable;*/
|
||||
|
||||
public:
|
||||
void InstallColormap(void);
|
||||
void SetDrawingSurface(nsDrawingSurfaceMac * aSurface);
|
||||
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
|
||||
nsDrawingSurface GetDrawingSurface();
|
||||
|
||||
//private:
|
||||
/*PRUint32 mRedMask;
|
||||
PRUint32 mGreenMask;
|
||||
PRUint32 mBlueMask;
|
||||
PRUint32 mRedBits;
|
||||
PRUint32 mGreenBits;
|
||||
PRUint32 mBlueBits;
|
||||
PRUint32 mRedOffset;
|
||||
PRUint32 mGreenOffset;
|
||||
PRUint32 mBlueOffset;
|
||||
|
||||
nsNativeWidget mNativeWidget;*/
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextMac_h___ */
|
Loading…
Reference in New Issue
Block a user