gfx to new branch

git-svn-id: svn://10.0.0.236/branches/IMGLIB2_20010309_BRANCH@89214 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pavlov%netscape.com
2001-03-10 03:39:13 +00:00
parent 8a8d2539db
commit d51c3a6fa1
10 changed files with 390 additions and 5 deletions

View File

@@ -44,6 +44,13 @@ struct nsRect;
struct nsBoundingMetrics;
#endif
#ifdef USE_IMG2
/* gfx2 */
#include "gfxtypes.h"
class imgIContainer;
#endif
//cliprect/region combination methods
typedef enum
@@ -756,6 +763,21 @@ public:
nsBoundingMetrics& aBoundingMetrics,
PRInt32* aFontID = nsnull) = 0;
#endif
#ifdef USE_IMG2
/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint) = 0;
/* [noscript] void drawScaledImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect) = 0;
/* [noscript] void drawTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect aTargetRect); */
NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect) = 0;
/* [noscript] void drawScaledTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect aTargetRect); */
NS_IMETHOD DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect) = 0;
#endif
};
//modifiers for text rendering

View File

@@ -79,7 +79,6 @@ public:
*/
NS_IMETHOD RasterPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
/** ---------------------------------------------------
* See documentation in nsIRenderingContext.h
* @update 05/01/00 dwc
@@ -92,6 +91,14 @@ public:
*/
NS_IMETHOD FillStdPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) { return NS_OK; }
#ifdef USE_IMG2
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
NS_IMETHOD DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect);
#endif
protected:
virtual ~nsRenderingContextImpl();

View File

@@ -1986,3 +1986,66 @@ nsRenderingContextGTK::my_gdk_draw_text (GdkDrawable *drawable,
else
g_error("undefined font type\n");
}
#ifdef USE_IMG2
#include "gfxIImageContainer.h"
#include "nsPIImageContainerGtk.h"
/* [noscript] void drawImage (in gfxIImageContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
nsPoint pt;
nsRect sr;
pt = *aDestPoint;
mTranMatrix->TransformCoord(&pt.x, &pt.y);
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x = aSrcRect->x;
sr.y = aSrcRect->y;
mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
nsCOMPtr<nsPIImageContainerGtk> cx(do_QueryInterface(aImage));
if (!cx) return NS_ERROR_FAILURE;
return cx->DrawImage(mSurface->GetDrawable(), NS_CONST_CAST(const GdkGC *, mGC), &sr, &pt);
}
/* [noscript] void drawScaledImage (in gfxIImageContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */
NS_IMETHODIMP nsRenderingContextGTK::DrawScaledImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
nsRect dr;
nsRect sr;
dr = *aDestRect;
mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x = aSrcRect->x;
sr.y = aSrcRect->y;
mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
nsCOMPtr<nsPIImageContainerGtk> cg(do_QueryInterface(aImage));
if (!cg) return NS_ERROR_FAILURE;
return cg->DrawScaledImage(mSurface->GetDrawable(), NS_CONST_CAST(const GdkGC *, mGC), &sr, &dr);
}
/* [noscript] void drawTile (in gfxIImageContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextGTK::DrawTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledTile (in gfxIImageContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextGTK::DrawScaledTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

View File

@@ -173,6 +173,13 @@ public:
const nsRect &aDestBounds, PRUint32 aCopyFlags);
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 * ngd);
#ifdef USE_IMG2
NS_IMETHOD DrawImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
NS_IMETHOD DrawTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
NS_IMETHOD DrawScaledTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect);
#endif
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string

View File

@@ -23,6 +23,7 @@
#include "nsRenderingContextMac.h"
#include "nsImageMac.h"
#include "nsDeviceContextMac.h"
#include "nsFontMetricsMac.h"
#include "nsIRegion.h"
@@ -1482,3 +1483,151 @@ nsRenderingContextMac::GetBoundingMetrics(const PRUnichar* aString,
}
#endif /* MOZ_MATHML */
#ifdef USE_IMG2
#include "gfxIImageContainer.h"
#include "nsIImageFrame.h"
/* [noscript] void drawImage (in gfxIImageContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextMac::DrawImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
// XXX there are some rounding problems in this code (or in the image frame)
nsresult rv;
nsCOMPtr<nsIImageFrame> img;
rv = aImage->GetCurrentFrame(getter_AddRefs(img));
if (NS_FAILED(rv))
return rv;
// XXX this is ugly.
nsPoint pt;
nsRect sr;
pt = *aDestPoint;
mTranMatrix->TransformCoord(&pt.x, &pt.y);
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x = aSrcRect->x;
sr.y = aSrcRect->y;
mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
PRUint32 len;
PRUint8 *bits;
rv = img->GetImageData(&bits, &len);
if (NS_FAILED(rv))
return rv;
PRUint32 bpr;
img->GetImageBytesPerRow(&bpr);
PRInt32 height;
img->GetHeight(&height);
PRInt32 width;
img->GetWidth(&width);
// void* oldThing = ::SelectObject(mDC, memBM);
// mBHead->biHeight = -mBHead->biHeight;
/*::StretchDIBits(mDC, PRInt32(pt.x + sr.x), PRInt32(pt.y + sr.y), width, height,
GFXCoordToIntFloor(sr.x), 0, width, height,
bits + (GFXCoordToIntFloor(sr.y) * bpr),
(LPBITMAPINFO)mBHead, DIB_RGB_COLORS, SRCAND);
*/
PixMap imagePixmap;
Handle imageBitsHandle = nsnull;
PixMap maskPixmap; // the alpha level pixel map
Handle maskBitsHandle = nsnull; // handle for the mask bits
nsImageMac::CreatePixMap(width, height, 24, nsnull, imagePixmap, imageBitsHandle);
// lock and set up bits handles
StHandleLocker imageBitsLocker(imageBitsHandle);
StHandleLocker maskBitsLocker(maskBitsHandle); // ok with nil handle
imagePixmap.baseAddr = (char*) bits;
if (maskBitsHandle)
maskPixmap.baseAddr = *maskBitsHandle;
imagePixmap.rowBytes = bpr | 0x8000;
// make sure the current port is correct. where else does this need to be done?
StPortSetter setter(mPort);
// set the right colors for CopyBits
RGBColor foreColor;
Boolean changedForeColor = false;
::GetForeColor(&foreColor);
if ((foreColor.red != 0x0000) || (foreColor.green != 0x0000) || (foreColor.blue != 0x0000)) {
RGBColor rgbBlack = {0x0000,0x0000,0x0000};
::RGBForeColor(&rgbBlack);
changedForeColor = true;
}
RGBColor backColor;
Boolean changedBackColor = false;
::GetBackColor(&backColor);
if ((backColor.red != 0xFFFF) || (backColor.green != 0xFFFF) || (backColor.blue != 0xFFFF)) {
RGBColor rgbWhite = {0xFFFF,0xFFFF,0xFFFF};
::RGBBackColor(&rgbWhite);
changedBackColor = true;
}
Rect macSrcRect;
Rect macDstRect;
::SetRect(&macSrcRect, 0, 0, width, height);
::SetRect(&macDstRect, pt.x, pt.y, pt.x + width, pt.y + height);
//PixMapHandle destPixels = GetGWorldPixMap(mPort);
// copy the bits now
::CopyBits(
#if TARGET_CARBON
::GetPortBitMapForCopyBits(srcPort),
::GetPortBitMapForCopyBits(mPort),
#else
(BitMap*)&imagePixmap,
&mPort->portBits,
#endif
&macSrcRect,
&macDstRect,
srcCopy,
0L);
// restore colors and surface
if (changedForeColor)
::RGBForeColor(&foreColor);
if (changedBackColor)
::RGBBackColor(&backColor);
return NS_OK;
}
/* [noscript] void drawScaledImage (in gfxIImageContainer aImage, [const] in nsRect2 aSrcRect, [const] in nsRect2 aDestRect); */
NS_IMETHODIMP nsRenderingContextMac::DrawScaledImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawTile (in gfxIImageContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect2 aTargetRect); */
NS_IMETHODIMP nsRenderingContextMac::DrawTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledTile (in gfxIImageContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect2 aTargetRect); */
NS_IMETHODIMP nsRenderingContextMac::DrawScaledTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

View File

@@ -151,6 +151,13 @@ public:
PRInt32* aFontID);
#endif /* MOZ_MATHML */
#ifdef USE_IMG2
NS_IMETHOD DrawImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(gfxIImageContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
NS_IMETHOD DrawTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
NS_IMETHOD DrawScaledTile(gfxIImageContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect);
#endif
//locals
NS_IMETHOD SetPortTextState();
nsresult Init(nsIDeviceContext* aContext, GrafPtr aPort);

View File

@@ -115,7 +115,7 @@ nsTransform2D *theTransform;
// copy the initial image to our buffer, this takes twips and converts to pixels..
// which is what the image is in
this->DrawImage(aImage,0,0,aWidth,aHeight);
NS_STATIC_CAST(nsIRenderingContext*, this)->DrawImage(aImage,0,0,aWidth,aHeight);
// duplicate the image in the upperleft corner to fill up the nsDrawingSurface
srcRect.SetRect(0,0,aWidth,aHeight);
@@ -143,7 +143,7 @@ nsTransform2D *theTransform;
// slow blitting, one tile at a time.... ( will create a mask and fall into code below -next task-)
for(y=aY0;y<aY1;y+=aHeight){
for(x=aX0;x<aX1;x+=aWidth){
this->DrawImage(aImage,x,y,aWidth,aHeight);
NS_STATIC_CAST(nsIRenderingContext*, this)->DrawImage(aImage,x,y,aWidth,aHeight);
}
}
}
@@ -663,3 +663,29 @@ float avx,avy,av1x,av1y;
return result;
}
#ifdef USE_IMG2
/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextImpl::DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

View File

@@ -115,7 +115,7 @@ nsTransform2D *theTransform;
// copy the initial image to our buffer, this takes twips and converts to pixels..
// which is what the image is in
this->DrawImage(aImage,0,0,aWidth,aHeight);
NS_STATIC_CAST(nsIRenderingContext*, this)->DrawImage(aImage,0,0,aWidth,aHeight);
// duplicate the image in the upperleft corner to fill up the nsDrawingSurface
srcRect.SetRect(0,0,aWidth,aHeight);
@@ -143,7 +143,7 @@ nsTransform2D *theTransform;
// slow blitting, one tile at a time.... ( will create a mask and fall into code below -next task-)
for(y=aY0;y<aY1;y+=aHeight){
for(x=aX0;x<aX1;x+=aWidth){
this->DrawImage(aImage,x,y,aWidth,aHeight);
NS_STATIC_CAST(nsIRenderingContext*, this)->DrawImage(aImage,x,y,aWidth,aHeight);
}
}
}
@@ -663,3 +663,29 @@ float avx,avy,av1x,av1y;
return result;
}
#ifdef USE_IMG2
/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextImpl::DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextImpl::DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

View File

@@ -3785,3 +3785,74 @@ nsRenderingContextWin::ConditionRect(nsRect& aSrcRect, RECT& aDestRect)
#ifdef USE_IMG2
#include "imgIContainer.h"
#include "gfxIImageFrame.h"
#include "nsIInterfaceRequestor.h"
/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextWin::DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
nsPoint pt;
nsRect sr;
pt = *aDestPoint;
mTranMatrix->TransformCoord(&pt.x, &pt.y);
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x = aSrcRect->x;
sr.y = aSrcRect->y;
mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
nsCOMPtr<gfxIImageFrame> iframe;
aImage->GetCurrentFrame(getter_AddRefs(iframe));
if (!iframe) return NS_ERROR_FAILURE;
nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
if (!img) return NS_ERROR_FAILURE;
return img->Draw(*this, mSurface, pt.x, pt.y, sr.width, sr.height);
}
/* [noscript] void drawScaledImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */
NS_IMETHODIMP nsRenderingContextWin::DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
nsRect dr;
nsRect sr;
dr = *aDestRect;
mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
sr.x = aSrcRect->x;
sr.y = aSrcRect->y;
mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);
nsCOMPtr<gfxIImageFrame> iframe;
aImage->GetCurrentFrame(getter_AddRefs(iframe));
if (!iframe) return NS_ERROR_FAILURE;
nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
if (!img) return NS_ERROR_FAILURE;
return img->Draw(*this, mSurface, sr.x, sr.y, sr.width, sr.height, dr.x, dr.y, dr.width, dr.height);
}
/* [noscript] void drawTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextWin::DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* [noscript] void drawScaledTile (in imgIContainer aImage, in nscoord aXOffset, in nscoord aYOffset, in nscoord aTileWidth, in nscoord aTileHeight, [const] in nsRect aTargetRect); */
NS_IMETHODIMP nsRenderingContextWin::DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

View File

@@ -199,6 +199,13 @@ public:
PRInt32* aFontID);
#endif
#ifdef USE_IMG2
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
NS_IMETHOD DrawScaledTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, nscoord aTileWidth, nscoord aTileHeight, const nsRect * aTargetRect);
#endif
protected:
void SetupFontAndColor(void);