зеркало из https://github.com/mozilla/pjs.git
Bug 244895 - remove gfx code related to old svg implementation. r+sr=roc
This commit is contained in:
Родитель
6ae037caa8
Коммит
b8ef0725dc
|
@ -57,7 +57,6 @@ class nsIAtom;
|
|||
|
||||
struct nsFont;
|
||||
struct nsPoint;
|
||||
struct nsPathPoint;
|
||||
struct nsRect;
|
||||
struct nsTextDimensions;
|
||||
#ifdef MOZ_MATHML
|
||||
|
@ -96,7 +95,7 @@ typedef enum
|
|||
|
||||
// IID for the nsIRenderingContext interface
|
||||
#define NS_IRENDERING_CONTEXT_IID \
|
||||
{ 0xa6cf9068, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
{ 0x79be0166, 0x4491, 0x48e8,{0xb9, 0xe2, 0xce, 0xfb, 0xa1, 0xb1, 0x71, 0x99}}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -437,13 +436,6 @@ public:
|
|||
*/
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) = 0;
|
||||
|
||||
/**
|
||||
* Rasterize a polygon with the current fill color.
|
||||
* @param aPoints points to use for the drawing, last must equal first
|
||||
* @param aNumPonts number of points in the polygon
|
||||
*/
|
||||
NS_IMETHOD RasterPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)=0;
|
||||
|
||||
/**
|
||||
* Fill a poly in the current foreground color, without transformation taking place
|
||||
* @param aPoints points to use for the drawing, last must equal first
|
||||
|
@ -696,28 +688,6 @@ public:
|
|||
NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
|
||||
PRInt32 aFontID = -1,
|
||||
const nscoord* aSpacing = nsnull) = 0;
|
||||
/**
|
||||
* Draw a path.. given a point array. The Path currently supported is a Quadratic
|
||||
* Bezier curve
|
||||
* @param aPointArray an array of points on the path
|
||||
* @param aNumPoints number of points in the array
|
||||
* @param aY0 starting y
|
||||
* @param aX1 ending x
|
||||
* @param aY1 ending y
|
||||
* @param aWidth tile width
|
||||
* @param aHeight tile height
|
||||
*/
|
||||
NS_IMETHOD DrawPath(nsPathPoint aPointArray[],PRInt32 aNumPts) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* fill a path.. given a point array. The Path currently supported is a Quadratic
|
||||
* Bezier curve
|
||||
* @param aPointArray an array of points on the path
|
||||
* @param aNumPts number of points in the array
|
||||
*/
|
||||
NS_IMETHOD FillPath(nsPathPoint aPointArray[],PRInt32 aNumPts) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Copy offscreen pixelmap to this RenderingContext.
|
||||
|
|
|
@ -119,22 +119,4 @@ struct nsFloatPoint {
|
|||
}
|
||||
};
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* A special type of point which also add the capability to tell if a point is on
|
||||
* the curve.. or off of the curve for a path
|
||||
* @update 03/29/00 dwc
|
||||
*/
|
||||
struct nsPathPoint: public nsFloatPoint{
|
||||
|
||||
PRBool mIsOnCurve;
|
||||
|
||||
// Constructors
|
||||
nsPathPoint() {}
|
||||
nsPathPoint(const nsPathPoint& aPoint) {x = aPoint.x; y = aPoint.y;mIsOnCurve=aPoint.mIsOnCurve;}
|
||||
nsPathPoint(float aX, float aY) {x = aX; y = aY;mIsOnCurve=PR_TRUE;}
|
||||
nsPathPoint(float aX, float aY,PRBool aIsOnCurve) {x = aX; y = aY;mIsOnCurve=aIsOnCurve;}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* NSPOINT_H */
|
||||
|
|
|
@ -90,26 +90,6 @@ public:
|
|||
*/
|
||||
NS_IMETHOD SetPenMode(nsPenMode aPenMode) { return NS_ERROR_FAILURE;};
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 03/29/00 dwc
|
||||
*/
|
||||
NS_IMETHOD DrawPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 03/29/00 dwc
|
||||
*/
|
||||
NS_IMETHOD FillPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
|
||||
|
||||
/**
|
||||
* Fill a poly in the current foreground color
|
||||
* @param aPoints points to use for the drawing, last must equal first
|
||||
* @param aNumPonts number of points in the polygon
|
||||
*/
|
||||
NS_IMETHOD RasterPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 05/01/00 dwc
|
||||
|
@ -141,9 +121,6 @@ public:
|
|||
protected:
|
||||
virtual ~nsRenderingContextImpl();
|
||||
|
||||
void cdelete(int i);
|
||||
void cinsert(int i,int y,const nsPoint aPointArray[],PRInt32 aNumPts);
|
||||
|
||||
/**
|
||||
* Determine if a rect's width and height will fit within a specified width and height
|
||||
* @param aRect rectangle to test
|
||||
|
@ -211,73 +188,4 @@ private:
|
|||
#undef IMETHOD_VISIBILITY
|
||||
#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Class QBezierCurve, a quadratic bezier curve
|
||||
* @update 4/27/2000 dwc
|
||||
*/
|
||||
class QBezierCurve
|
||||
{
|
||||
|
||||
public:
|
||||
nsFloatPoint mAnc1;
|
||||
nsFloatPoint mCon;
|
||||
nsFloatPoint mAnc2;
|
||||
|
||||
QBezierCurve() {mAnc1.x=0;mAnc1.y=0;mCon=mAnc2=mAnc1;}
|
||||
void SetControls(nsFloatPoint &aAnc1,nsFloatPoint &aCon,nsFloatPoint &aAnc2) { mAnc1 = aAnc1; mCon = aCon; mAnc2 = aAnc2;}
|
||||
void SetPoints(nscoord a1x,nscoord a1y,nscoord acx,nscoord acy,nscoord a2x,nscoord a2y) {mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}
|
||||
void SetPoints(float a1x,float a1y,float acx,float acy,float a2x,float a2y) {mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}
|
||||
void DebugPrint();
|
||||
/** ---------------------------------------------------
|
||||
* Divide a Quadratic curve into line segments if it is not smaller than a certain size
|
||||
* else it is so small that it can be approximated by 2 lineto calls
|
||||
* @param aRenderingContext -- The RenderingContext to use to draw with
|
||||
* @update 3/26/99 dwc
|
||||
*/
|
||||
void SubDivide(nsIRenderingContext *aRenderingContext);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Divide a Quadratic curve into line segments if it is not smaller than a certain size
|
||||
* else it is so small that it can be approximated by 2 lineto calls
|
||||
* @param nsPoint* -- The points array to rasterize into
|
||||
* @param aNumPts* -- Current number of points in this array
|
||||
* @update 3/26/99 dwc
|
||||
*/
|
||||
void SubDivide(nsPoint aThePoints[],PRInt16 *aNumPts);
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* Divide a Quadratic Bezier curve at the mid-point
|
||||
* @update 3/26/99 dwc
|
||||
* @param aCurve1 -- Curve 1 as a result of the division
|
||||
* @param aCurve2 -- Curve 2 as a result of the division
|
||||
*/
|
||||
void MidPointDivide(QBezierCurve *A,QBezierCurve *B);
|
||||
};
|
||||
|
||||
enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* A class to iterate through a nsPathPoint array and return segments
|
||||
* @update 04/27/00 dwc
|
||||
*/
|
||||
class nsPathIter {
|
||||
|
||||
public:
|
||||
enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
|
||||
|
||||
private:
|
||||
PRUint32 mCurPoint;
|
||||
PRUint32 mNumPoints;
|
||||
nsPathPoint *mThePath;
|
||||
|
||||
public:
|
||||
nsPathIter();
|
||||
nsPathIter(nsPathPoint* aThePath,PRUint32 aNumPts);
|
||||
|
||||
PRBool NextSeg(QBezierCurve& TheSegment,eSegType& aCurveType);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsRenderingContextImpl */
|
||||
|
|
|
@ -43,16 +43,10 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
|
||||
const nsPoint *gPts;
|
||||
|
||||
nsDrawingSurface nsRenderingContextImpl::gBackbuffer = nsnull;
|
||||
nsRect nsRenderingContextImpl::gBackbufferBounds = nsRect(0, 0, 0, 0);
|
||||
nsSize nsRenderingContextImpl::gLargestRequestedSize = nsSize(0, 0);
|
||||
|
||||
// comparison routines for qsort
|
||||
PRInt32 PR_CALLBACK compare_ind(const void *u,const void *v){return gPts[(PRInt32)*((PRInt32*)u)].y <= gPts[(PRInt32)*((PRInt32*)v)].y ? -1 : 1;}
|
||||
PRInt32 PR_CALLBACK compare_active(const void *u,const void *v){return ((Edge*)u)->x <= ((Edge*)v)->x ? -1 : 1;}
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
|
@ -77,245 +71,6 @@ nsRenderingContextImpl :: ~nsRenderingContextImpl()
|
|||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextImpl::DrawPath(nsPathPoint aPointArray[],PRInt32 aNumPts)
|
||||
{
|
||||
PRInt32 i;
|
||||
nsPathPoint pts[20];
|
||||
nsPathPoint *pp0,*np=0,*pp;
|
||||
QBezierCurve thecurve;
|
||||
nsPathIter::eSegType curveType;
|
||||
|
||||
|
||||
// Transform the points first
|
||||
if (aNumPts > 20){
|
||||
pp0 = new nsPathPoint[aNumPts];
|
||||
} else {
|
||||
pp0 = &pts[0];
|
||||
}
|
||||
pp = pp0;
|
||||
np = &aPointArray[0];
|
||||
|
||||
for ( i= 0; i < aNumPts; i++,np++,pp++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
pp->mIsOnCurve = np->mIsOnCurve;
|
||||
mTranMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
|
||||
}
|
||||
|
||||
nsPathIter thePathIter (pp0,aNumPts);
|
||||
while ( thePathIter.NextSeg(thecurve,curveType) ) {
|
||||
// draw the curve we found
|
||||
if(nsPathIter::eLINE == curveType){
|
||||
DrawStdLine(NSToCoordRound(thecurve.mAnc1.x),NSToCoordRound(thecurve.mAnc1.y),NSToCoordRound(thecurve.mAnc2.x),NSToCoordRound(thecurve.mAnc2.y));
|
||||
} else {
|
||||
thecurve.SubDivide(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Release temporary storage if necessary
|
||||
if (pp0 != pts)
|
||||
delete [] pp0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#define MAXPATHSIZE 1000
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextImpl::FillPath(nsPathPoint aPointArray[],PRInt32 aNumPts)
|
||||
{
|
||||
PRInt32 i;
|
||||
nsPathPoint pts[20];
|
||||
nsPathPoint *pp0,*np=0,*pp;
|
||||
QBezierCurve thecurve;
|
||||
nsPathIter::eSegType curveType;
|
||||
nsPoint thePath[MAXPATHSIZE];
|
||||
PRInt16 curPoint=0;
|
||||
|
||||
// Transform the points first
|
||||
if (aNumPts > 20){
|
||||
pp0 = new nsPathPoint[aNumPts];
|
||||
} else {
|
||||
pp0 = &pts[0];
|
||||
}
|
||||
pp = pp0;
|
||||
np = &aPointArray[0];
|
||||
|
||||
for ( i= 0; i < aNumPts; i++,np++,pp++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
pp->mIsOnCurve = np->mIsOnCurve;
|
||||
mTranMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
|
||||
}
|
||||
|
||||
nsPathIter thePathIter (pp0,aNumPts);
|
||||
while ( thePathIter.NextSeg(thecurve,curveType) ) {
|
||||
// build a polygon with the points
|
||||
if(nsPathIter::eLINE == curveType){
|
||||
thePath[curPoint++].MoveTo(NSToCoordRound(thecurve.mAnc1.x),NSToCoordRound(thecurve.mAnc1.y));
|
||||
thePath[curPoint++].MoveTo(NSToCoordRound(thecurve.mAnc2.x),NSToCoordRound(thecurve.mAnc2.y));
|
||||
} else {
|
||||
thecurve.SubDivide(thePath,&curPoint);
|
||||
}
|
||||
}
|
||||
|
||||
this->FillStdPolygon(thePath,curPoint);
|
||||
|
||||
// Release temporary storage if necessary
|
||||
if (pp0 != pts)
|
||||
delete [] pp0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextImpl::RasterPolygon(const nsPoint aPointArray[],PRInt32 aNumPts)
|
||||
{
|
||||
PRInt32 k,y0,y1,y,i,j,xl,xr,extra=0;
|
||||
PRInt32 *ind;
|
||||
nsPoint pts[20];
|
||||
nsPoint *pp,*pp0;
|
||||
const nsPoint *np;
|
||||
|
||||
if (aNumPts<=0)
|
||||
return NS_OK;
|
||||
|
||||
#ifdef XP_WIN
|
||||
extra = 1;
|
||||
#endif
|
||||
|
||||
// Transform the points first
|
||||
if (aNumPts > 20){
|
||||
pp0 = new nsPoint[aNumPts];
|
||||
} else {
|
||||
pp0 = &pts[0];
|
||||
}
|
||||
pp = pp0;
|
||||
np = &aPointArray[0];
|
||||
|
||||
for ( i= 0; i < aNumPts; i++,np++,pp++){
|
||||
pp->x = np->x;
|
||||
pp->y = np->y;
|
||||
mTranMatrix->TransformCoord((PRInt32*)&pp->x,(PRInt32*)&pp->y);
|
||||
}
|
||||
|
||||
ind = new PRInt32[aNumPts];
|
||||
mActive = new Edge[aNumPts];
|
||||
|
||||
gPts = pp0;
|
||||
|
||||
// create y-sorted array of indices ind[k] into vertex list
|
||||
for (k=0; k<aNumPts; k++)
|
||||
ind[k] = k;
|
||||
qsort(ind, aNumPts, sizeof ind[0], compare_ind); // sort ind by mPointList[ind[k]].y
|
||||
|
||||
mAct = 0; // start with empty active list
|
||||
k = 0; // ind[k] is next vertex to process
|
||||
y0 = (PRInt32)ceil(pp0[ind[0]].y-.5);
|
||||
y1 = (PRInt32)floor(pp0[ind[aNumPts-1]].y-.5);
|
||||
|
||||
for (y=y0; y<=y1; y++) { // step through scanlines
|
||||
// check vertices between previous scanline and current one, if any */
|
||||
for (; k<aNumPts && pp0[ind[k]].y<=y+.5; k++) {
|
||||
i = ind[k];
|
||||
j = i>0 ? i-1 : aNumPts-1;
|
||||
if (pp0[j].y <= y-.5)
|
||||
cdelete(j);
|
||||
else if (pp0[j].y > y+.5)
|
||||
cinsert(j, y,pp0, aNumPts);
|
||||
j = i<aNumPts-1 ? i+1 : 0;
|
||||
if (pp0[j].y <= y-.5)
|
||||
cdelete(i);
|
||||
else if (pp0[j].y > y+.5)
|
||||
cinsert(i, y,pp0, aNumPts);
|
||||
}
|
||||
|
||||
// sort active edge list by active[j].x
|
||||
qsort(mActive, mAct, sizeof mActive[0], compare_active);
|
||||
|
||||
// draw horizontal segments for scanline y
|
||||
for (j=0; j<mAct; j+=2) { // draw horizontal segments
|
||||
xl = (PRInt32) ceil(mActive[j].x-.5); /* left end of span */
|
||||
|
||||
xr = (PRInt32)floor(mActive[j+1].x-.5); /* right end of span */
|
||||
|
||||
if(xl<=xr){
|
||||
DrawStdLine(xl,y,xr+extra,y);
|
||||
}
|
||||
mActive[j].x += mActive[j].dx; /* increment edge coords */
|
||||
mActive[j+1].x += mActive[j+1].dx;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] ind;
|
||||
delete[] mActive;
|
||||
|
||||
if (pp0 != pts)
|
||||
delete [] pp0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**-------------------------------------------------------------------
|
||||
* remove edge i from active list
|
||||
* @update dc 12/06/1999
|
||||
*/
|
||||
void
|
||||
nsRenderingContextImpl::cdelete(PRInt32 i)
|
||||
{
|
||||
PRInt32 j;
|
||||
|
||||
for(j=0;j<mAct;j++){
|
||||
if (mActive[j].i==i)
|
||||
break;
|
||||
}
|
||||
|
||||
if (j>=mAct)
|
||||
return;
|
||||
mAct--;
|
||||
memcpy(&mActive[j], &mActive[j+1],(mAct-j)*sizeof mActive[0]);
|
||||
}
|
||||
|
||||
/**-------------------------------------------------------------------
|
||||
* append edge i to end of active list
|
||||
* @update dc 12/06/1999
|
||||
*/
|
||||
void
|
||||
nsRenderingContextImpl::cinsert(PRInt32 i,PRInt32 y,const nsPoint aPointArray[],PRInt32 aNumPts)
|
||||
{
|
||||
PRInt32 j;
|
||||
double dx;
|
||||
const nsPoint *p, *q;
|
||||
|
||||
j = i<aNumPts-1 ? i+1 : 0;
|
||||
if (aPointArray[i].y < aPointArray[j].y) {
|
||||
p = &aPointArray[i]; q = &aPointArray[j];
|
||||
}else{
|
||||
p = &aPointArray[j]; q = &aPointArray[i];
|
||||
}
|
||||
// initialize x position at intersection of edge with scanline y
|
||||
mActive[mAct].dx = dx = ((double)q->x-(double)p->x)/((double)q->y-(double)p->y);
|
||||
mActive[mAct].x = dx*(y+.5-(double)p->y)+(double)p->x;
|
||||
mActive[mAct].i = i;
|
||||
mAct++;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextImpl::GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, nsDrawingSurface &aBackbuffer)
|
||||
{
|
||||
|
@ -500,243 +255,6 @@ nsRenderingContextImpl::SetRightToLeftText(PRBool aIsRTL)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
void
|
||||
QBezierCurve::SubDivide(nsIRenderingContext *aRenderingContext)
|
||||
{
|
||||
QBezierCurve curve1,curve2;
|
||||
float fx,fy,smag;
|
||||
|
||||
// divide the curve into 2 pieces
|
||||
MidPointDivide(&curve1,&curve2);
|
||||
|
||||
// for now to fix the build
|
||||
fx = (float) fabs(curve1.mAnc2.x - this->mCon.x);
|
||||
fy = (float) fabs(curve1.mAnc2.y - this->mCon.y);
|
||||
|
||||
//smag = fx+fy-(PR_MIN(fx,fy)>>1);
|
||||
smag = fx*fx + fy*fy;
|
||||
|
||||
if (smag>1){
|
||||
// split the curve again
|
||||
curve1.SubDivide(aRenderingContext);
|
||||
curve2.SubDivide(aRenderingContext);
|
||||
}else{
|
||||
// draw the curve
|
||||
#ifdef DEBUGCURVE
|
||||
printf("LINE 1- %d,%d %d,%d\n",NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y),
|
||||
NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y));
|
||||
printf("LINE 2- %d,%d %d,%d\n",NSToCoordRound(curve1.mAnc2.x),NSToCoordRound(curve1.mAnc2.y),
|
||||
NSToCoordRound(curve2.mAnc2.x),NSToCoordRound(curve2.mAnc2.y));
|
||||
#endif
|
||||
aRenderingContext->DrawStdLine(NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y),NSToCoordRound(curve1.mAnc2.x),NSToCoordRound(curve1.mAnc2.y));
|
||||
aRenderingContext->DrawStdLine(NSToCoordRound(curve1.mAnc2.x),NSToCoordRound(curve1.mAnc2.y),NSToCoordRound(curve2.mAnc2.x),NSToCoordRound(curve2.mAnc2.y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
void
|
||||
QBezierCurve::DebugPrint()
|
||||
{
|
||||
printf("CURVE COORDINATES\n");
|
||||
printf("Anchor 1 %f %f\n",mAnc1.x,mAnc1.y);
|
||||
printf("Control %f %f\n",mCon.x,mCon.y);
|
||||
printf("Anchor %f %f\n",mAnc2.x,mAnc2.y);
|
||||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 3/29/00 dwc
|
||||
*/
|
||||
void
|
||||
QBezierCurve::SubDivide(nsPoint aThePoints[],PRInt16 *aNumPts)
|
||||
{
|
||||
QBezierCurve curve1,curve2;
|
||||
float fx,fy,smag;
|
||||
|
||||
// divide the curve into 2 pieces
|
||||
MidPointDivide(&curve1,&curve2);
|
||||
|
||||
|
||||
// for now to fix the build
|
||||
fx = (float) fabs(curve1.mAnc2.x - this->mCon.x);
|
||||
fy = (float) fabs(curve1.mAnc2.y - this->mCon.y);
|
||||
//smag = fx+fy-(PR_MIN(fx,fy)>>1);
|
||||
smag = fx*fx + fy*fy;
|
||||
|
||||
if (smag>1){
|
||||
// split the curve again
|
||||
curve1.SubDivide(aThePoints,aNumPts);
|
||||
curve2.SubDivide(aThePoints,aNumPts);
|
||||
}else{
|
||||
// draw the curve
|
||||
aThePoints[(*aNumPts)++].MoveTo(NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y));
|
||||
aThePoints[(*aNumPts)++].MoveTo(NSToCoordRound(curve1.mAnc2.x),NSToCoordRound(curve1.mAnc2.y));
|
||||
aThePoints[(*aNumPts)++].MoveTo(NSToCoordRound(curve2.mAnc2.x),NSToCoordRound(curve2.mAnc2.y));
|
||||
|
||||
#ifdef DEBUGCURVE
|
||||
printf("LINE 1- %d,%d %d,%d\n",NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y),
|
||||
NSToCoordRound(curve1.mAnc1.x),NSToCoordRound(curve1.mAnc1.y));
|
||||
printf("LINE 2- %d,%d %d,%d\n",NSToCoordRound(curve1.mAnc2.x),NSToCoordRound(curve1.mAnc2.y),
|
||||
NSToCoordRound(curve2.mAnc2.x),NSToCoordRound(curve2.mAnc2.y));
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 4/27/2000 dwc
|
||||
*/
|
||||
void
|
||||
QBezierCurve::MidPointDivide(QBezierCurve *A,QBezierCurve *B)
|
||||
{
|
||||
float c1x,c1y,c2x,c2y;
|
||||
nsFloatPoint a1;
|
||||
|
||||
c1x = (float) ((mAnc1.x+mCon.x)/2.0);
|
||||
c1y = (float) ((mAnc1.y+mCon.y)/2.0);
|
||||
c2x = (float) ((mAnc2.x+mCon.x)/2.0);
|
||||
c2y = (float) ((mAnc2.y+mCon.y)/2.0);
|
||||
|
||||
a1.x = (float) ((c1x + c2x)/2.0);
|
||||
a1.y = (float) ((c1y + c2y)/2.0);
|
||||
|
||||
// put the math into our 2 new curves
|
||||
A->mAnc1 = this->mAnc1;
|
||||
A->mCon.x = c1x;
|
||||
A->mCon.y = c1y;
|
||||
A->mAnc2 = a1;
|
||||
B->mAnc1 = a1;
|
||||
B->mCon.x = c2x;
|
||||
B->mCon.y = c2y;
|
||||
B->mAnc2 = this->mAnc2;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 4/27/2000 dwc
|
||||
*/
|
||||
nsPathIter::nsPathIter()
|
||||
{
|
||||
|
||||
mCurPoint = 0;
|
||||
mNumPoints = 0;
|
||||
mThePath = 0;
|
||||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 4/27/2000 dwc
|
||||
*/
|
||||
nsPathIter::nsPathIter(nsPathPoint* aThePath,PRUint32 aNumPts)
|
||||
{
|
||||
|
||||
mCurPoint = 0;
|
||||
mNumPoints = aNumPts;
|
||||
mThePath = aThePath;
|
||||
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsRenderingContextImpl.h
|
||||
* @update 4/27/2000 dwc
|
||||
*/
|
||||
PRBool
|
||||
nsPathIter::NextSeg(QBezierCurve& TheSegment,eSegType& aCurveType)
|
||||
{
|
||||
PRInt8 code=0,number=1;
|
||||
PRBool result = PR_TRUE;
|
||||
nsPathPoint *pt1,*pt2,*pt3;
|
||||
float avx,avy,av1x,av1y;
|
||||
|
||||
if ( mCurPoint < mNumPoints) {
|
||||
// 1st point
|
||||
pt1 = &(mThePath[mCurPoint]);
|
||||
if(PR_TRUE == pt1->mIsOnCurve) {
|
||||
code += 0x04;
|
||||
}
|
||||
// 2nd point
|
||||
if ( (mCurPoint+1) < mNumPoints) {
|
||||
number++;
|
||||
pt2 = &(mThePath[mCurPoint+1]);
|
||||
if(PR_TRUE == pt2->mIsOnCurve) {
|
||||
code += 0x02;
|
||||
}
|
||||
|
||||
// 3rd point
|
||||
if( (mCurPoint+2) < mNumPoints) {
|
||||
number++;
|
||||
pt3 = &(mThePath[mCurPoint+2]);
|
||||
if(PR_TRUE == pt3->mIsOnCurve) {
|
||||
code += 0x01;
|
||||
}
|
||||
// have all three points..
|
||||
switch(code) {
|
||||
case 07: // 111
|
||||
case 06: // 110
|
||||
TheSegment.SetPoints(pt1->x,pt1->y,0.0,0.0,pt2->x,pt2->y);
|
||||
aCurveType = eLINE;
|
||||
mCurPoint++;
|
||||
break;
|
||||
case 05: // 101
|
||||
TheSegment.SetPoints(pt1->x,pt1->y,pt2->x,pt2->y,pt3->x,pt3->y);
|
||||
aCurveType = eQCURVE;
|
||||
mCurPoint+=2;
|
||||
break;
|
||||
case 04: // 100
|
||||
avx = (float)((pt2->x+pt3->x)/2.0);
|
||||
avy = (float)((pt2->y+pt3->y)/2.0);
|
||||
TheSegment.SetPoints(pt1->x,pt1->y,pt2->x,pt2->y,avx,avy);
|
||||
aCurveType = eQCURVE;
|
||||
mCurPoint++;
|
||||
case 03: // 011
|
||||
case 02: // 010
|
||||
TheSegment.SetPoints(pt1->x,pt1->y,0.0,0.0,pt2->x,pt2->y);
|
||||
aCurveType = eLINE;
|
||||
mCurPoint++;
|
||||
case 01: // 001
|
||||
avx = (float)((pt1->x+pt2->x)/2.0);
|
||||
avy = (float)((pt1->y+pt2->y)/2.0);
|
||||
TheSegment.SetPoints(avx,avy,pt2->x,pt3->y,pt2->x,pt3->y);
|
||||
aCurveType = eQCURVE;
|
||||
mCurPoint+=2;
|
||||
case 00: // 000
|
||||
avx = (float)((pt1->x+pt2->x)/2.0);
|
||||
avy = (float)((pt1->y+pt2->y)/2.0);
|
||||
av1x = (float)((pt2->x+pt3->x)/2.0);
|
||||
av1y = (float)((pt2->y+pt3->y)/2.0);
|
||||
TheSegment.SetPoints(avx,avy,pt2->x,pt2->y,av1x,av1y);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// have two points.. draw a line
|
||||
TheSegment.SetPoints(pt1->x,pt1->y,0.0,0.0,pt2->x,pt2->y);
|
||||
aCurveType = eLINE;
|
||||
mCurPoint++;
|
||||
}
|
||||
} else {
|
||||
// just have one point
|
||||
result = PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
// all finished
|
||||
result = PR_FALSE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#include "imgIContainer.h"
|
||||
#include "gfxIImageFrame.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче