Bug 266236 part 4: Aggressively prune unused methods and dead #ifdefs from nsRenderingContext.

--HG--
rename : gfx/src/nsThebesRenderingContext.cpp => gfx/src/nsRenderingContext.cpp
rename : gfx/src/nsThebesRenderingContext.h => gfx/src/nsRenderingContext.h
extra : rebase_source : b2911406bbe1b5995d1a501c59e02b5fffefa390
This commit is contained in:
Zack Weinberg 2011-04-07 18:04:40 -07:00
Родитель 23271beb1d
Коммит 3486378dac
15 изменённых файлов: 145 добавлений и 948 удалений

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

@ -38,27 +38,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsRenderingContext.h"
#include "nsThebesDeviceContext.h"
#include "nsString.h"
#include "nsTransform2D.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsGfxCIID.h"
#include "nsThebesRegion.h"
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "gfxPlatform.h"
#ifdef XP_WIN
#include "gfxWindowsSurface.h"
#include "cairo-win32.h"
#endif
// XXXTodo: rename FORM_TWIPS to FROM_APPUNITS
#define FROM_TWIPS(_x) ((gfxFloat)((_x)/(mP2A)))
@ -69,14 +48,8 @@
// Hard limit substring lengths to 8000 characters ... this lets us statically
// size the cluster buffer array in FindSafeLength
#define MAX_GFX_TEXT_BUF_SIZE 8000
static PRInt32 GetMaxChunkLength(nsRenderingContext* aContext)
{
PRInt32 len = aContext->GetMaxStringLength();
return PR_MIN(len, MAX_GFX_TEXT_BUF_SIZE);
}
static PRInt32 FindSafeLength(nsRenderingContext* aContext,
const PRUnichar *aString, PRUint32 aLength,
static PRInt32 FindSafeLength(const PRUnichar *aString, PRUint32 aLength,
PRUint32 aMaxChunkLength)
{
if (aLength <= aMaxChunkLength)
@ -99,8 +72,7 @@ static PRInt32 FindSafeLength(nsRenderingContext* aContext,
return len;
}
static PRInt32 FindSafeLength(nsRenderingContext* aContext,
const char *aString, PRUint32 aLength,
static PRInt32 FindSafeLength(const char *aString, PRUint32 aLength,
PRUint32 aMaxChunkLength)
{
// Since it's ASCII, we don't need to worry about clusters or RTL
@ -111,57 +83,20 @@ static PRInt32 FindSafeLength(nsRenderingContext* aContext,
//// nsRenderingContext
nsresult
nsRenderingContext::Init(nsIDeviceContext* aContext, gfxASurface *aThebesSurface)
nsRenderingContext::Init(nsIDeviceContext* aContext,
gfxASurface *aThebesSurface)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p thebesSurface %p\n", this, aContext, aThebesSurface));
mDeviceContext = aContext;
mWidget = nsnull;
mThebes = new gfxContext(aThebesSurface);
return (CommonInit());
return Init(aContext, new gfxContext(aThebesSurface));
}
nsresult
nsRenderingContext::Init(nsIDeviceContext* aContext, gfxContext *aThebesContext)
nsRenderingContext::Init(nsIDeviceContext* aContext,
gfxContext *aThebesContext)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p thebesContext %p\n", this, aContext, aThebesContext));
mDeviceContext = aContext;
mWidget = nsnull;
mThebes = aThebesContext;
return (CommonInit());
}
nsresult
nsRenderingContext::Init(nsIDeviceContext* aContext, nsIWidget *aWidget)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Init ctx %p widget %p\n", this, aContext, aWidget));
mDeviceContext = aContext;
mWidget = aWidget;
mThebes = new gfxContext(aWidget->GetThebesSurface());
//mThebes->SetColor(gfxRGBA(0.9, 0.0, 0.0, 0.3));
//mThebes->Paint();
//mThebes->Translate(gfxPoint(300,0));
//mThebes->Rotate(M_PI/4);
return (CommonInit());
}
nsresult
nsRenderingContext::CommonInit(void)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::CommonInit\n", this));
mThebes->SetLineWidth(1.0);
mP2A = mDeviceContext->AppUnitsPerDevPixel();
return NS_OK;
@ -174,43 +109,9 @@ nsRenderingContext::GetDeviceContext()
return mDeviceContext.get();
}
nsresult
nsRenderingContext::PushTranslation(PushedTranslation* aState)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushTranslation\n", this));
// XXX this is slow!
PushState();
return NS_OK;
}
nsresult
nsRenderingContext::PopTranslation(PushedTranslation* aState)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopTranslation\n", this));
// XXX this is slow!
PopState();
return NS_OK;
}
nsresult
nsRenderingContext::SetTranslation(const nsPoint& aPt)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetTranslation %d %d\n", this, aPt.x, aPt.y));
gfxMatrix newMat(mThebes->CurrentMatrix());
newMat.x0 = aPt.x;
newMat.y0 = aPt.y;
mThebes->SetMatrix(newMat);
return NS_OK;
}
nsresult
nsRenderingContext::PushState()
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushState\n", this));
mThebes->Save();
return NS_OK;
}
@ -218,8 +119,6 @@ nsRenderingContext::PushState()
nsresult
nsRenderingContext::PopState()
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopState\n", this));
mThebes->Restore();
return NS_OK;
}
@ -231,9 +130,6 @@ nsRenderingContext::PopState()
nsresult
nsRenderingContext::SetClipRect(const nsRect& aRect, nsClipCombine aCombine)
{
//return NS_OK;
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetClipRect [%d,%d,%d,%d] %d\n", this, aRect.x, aRect.y, aRect.width, aRect.height, aCombine));
if (aCombine == nsClipCombine_kReplace) {
mThebes->ResetClip();
} else if (aCombine != nsClipCombine_kIntersect) {
@ -293,7 +189,6 @@ nsRenderingContext::SetClipRegion(const nsIntRegion& aRegion,
nsresult
nsRenderingContext::SetLineStyle(nsLineStyle aLineStyle)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetLineStyle %d\n", this, aLineStyle));
switch (aLineStyle) {
case nsLineStyle_kSolid:
mThebes->SetDash(gfxContext::gfxLineSolid);
@ -310,8 +205,6 @@ nsRenderingContext::SetLineStyle(nsLineStyle aLineStyle)
NS_ERROR("SetLineStyle: Invalid line style");
break;
}
mLineStyle = aLineStyle;
return NS_OK;
}
@ -319,27 +212,16 @@ nsRenderingContext::SetLineStyle(nsLineStyle aLineStyle)
nsresult
nsRenderingContext::SetColor(nscolor aColor)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetColor 0x%08x\n", this, aColor));
/* This sets the color assuming the sRGB color space, since that's what all
* CSS colors are defined to be in by the spec.
/* This sets the color assuming the sRGB color space, since that's
* what all CSS colors are defined to be in by the spec.
*/
mThebes->SetColor(gfxRGBA(aColor));
mColor = aColor;
return NS_OK;
}
nsresult
nsRenderingContext::GetColor(nscolor &aColor) const
{
aColor = mColor;
return NS_OK;
}
nsresult
nsRenderingContext::Translate(const nsPoint& aPt)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Translate %d %d\n", this, aPt.x, aPt.y));
mThebes->Translate (gfxPoint(FROM_TWIPS(aPt.x), FROM_TWIPS(aPt.y)));
return NS_OK;
}
@ -347,71 +229,10 @@ nsRenderingContext::Translate(const nsPoint& aPt)
nsresult
nsRenderingContext::Scale(float aSx, float aSy)
{
// as far as I can tell, noone actually calls this
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Scale %f %f\n", this, aSx, aSy));
mThebes->Scale (aSx, aSy);
return NS_OK;
}
void
nsRenderingContext::UpdateTempTransformMatrix()
{
//PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::UpdateTempTransformMatrix\n", this));
/*****
* Thebes matrix layout: gfx matrix layout:
* | xx yx 0 | | m00 m01 0 |
* | xy yy 0 | | m10 m11 0 |
* | x0 y0 1 | | m20 m21 1 |
*****/
const gfxMatrix& ctm = mThebes->CurrentMatrix();
NS_ASSERTION(ctm.yx == 0 && ctm.xy == 0, "Can't represent Thebes matrix to Gfx");
mTempTransform.SetToTranslate(TO_TWIPS(ctm.x0), TO_TWIPS(ctm.y0));
mTempTransform.AddScale(ctm.xx, ctm.yy);
}
nsTransform2D&
nsRenderingContext::CurrentTransform()
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::CurrentTransform\n", this));
UpdateTempTransformMatrix();
return mTempTransform;
}
/****
**** XXXXXX
****
**** On other gfx implementations, the transform returned by this
**** has a built in twips to pixels ratio. That is, you pass in
**** twips to any nsTransform2D TransformCoord method, and you
**** get back pixels. This makes no sense. We don't do this.
**** This in turn breaks SVG and <object>; those should just be
**** fixed to not use this!
****/
nsTransform2D*
nsRenderingContext::GetCurrentTransform()
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
("## %p nsTRC::GetCurrentTransform\n", this));
UpdateTempTransformMatrix();
return &mTempTransform;
}
void
nsRenderingContext::TransformCoord (nscoord *aX, nscoord *aY)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::TransformCoord\n", this));
gfxPoint pt(FROM_TWIPS(*aX), FROM_TWIPS(*aY));
pt = mThebes->UserToDevice (pt);
*aX = TO_TWIPS(pt.x);
*aY = TO_TWIPS(pt.y);
}
nsresult
nsRenderingContext::DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt)
{
@ -422,9 +243,6 @@ nsresult
nsRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
nscoord aX1, nscoord aY1)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
("## %p nsTRC::DrawLine %d %d %d %d\n", this, aX0, aY0, aX1, aY1));
gfxPoint p0 = gfxPoint(FROM_TWIPS(aX0), FROM_TWIPS(aY0));
gfxPoint p1 = gfxPoint(FROM_TWIPS(aX1), FROM_TWIPS(aY1));
@ -468,8 +286,6 @@ nsRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
nsresult
nsRenderingContext::DrawRect(const nsRect& aRect)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::DrawRect [%d,%d,%d,%d]\n", this, aRect.x, aRect.y, aRect.width, aRect.height));
mThebes->NewPath();
mThebes->Rectangle(GFX_RECT_FROM_TWIPS_RECT(aRect), PR_TRUE);
mThebes->Stroke();
@ -550,8 +366,6 @@ ConditionRect(gfxRect& r) {
nsresult
nsRenderingContext::FillRect(const nsRect& aRect)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillRect [%d,%d,%d,%d]\n", this, aRect.x, aRect.y, aRect.width, aRect.height));
gfxRect r(GFX_RECT_FROM_TWIPS_RECT(aRect));
/* Clamp coordinates to work around a design bug in cairo */
@ -573,8 +387,6 @@ nsRenderingContext::FillRect(const nsRect& aRect)
mThebes->IdentityMatrix();
mThebes->NewPath();
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillRect conditioned to [%f,%f,%f,%f]\n", this, r.pos.x, r.pos.y, r.size.width, r.size.height));
mThebes->Rectangle(r, PR_TRUE);
mThebes->Fill();
mThebes->SetMatrix(mat);
@ -582,8 +394,6 @@ nsRenderingContext::FillRect(const nsRect& aRect)
return NS_OK;
}
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillRect raw [%f,%f,%f,%f]\n", this, r.pos.x, r.pos.y, r.size.width, r.size.height));
mThebes->NewPath();
mThebes->Rectangle(r, PR_TRUE);
mThebes->Fill();
@ -628,8 +438,6 @@ nsresult
nsRenderingContext::DrawEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::DrawEllipse [%d,%d,%d,%d]\n", this, aX, aY, aWidth, aHeight));
mThebes->NewPath();
mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
@ -650,8 +458,6 @@ nsresult
nsRenderingContext::FillEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillEllipse [%d,%d,%d,%d]\n", this, aX, aY, aWidth, aHeight));
mThebes->NewPath();
mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
@ -665,8 +471,6 @@ nsRenderingContext::FillEllipse(nscoord aX, nscoord aY,
nsresult
nsRenderingContext::FillPolygon(const nsPoint twPoints[], PRInt32 aNumPoints)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::FillPolygon %d\n", this, aNumPoints));
if (aNumPoints == 0)
return NS_OK;
@ -687,98 +491,14 @@ nsRenderingContext::FillPolygon(const nsPoint twPoints[], PRInt32 aNumPoints)
return NS_OK;
}
void*
nsRenderingContext::GetNativeGraphicData(GraphicDataType aType)
{
if (aType == NATIVE_GDK_DRAWABLE)
{
if (mWidget)
return mWidget->GetNativeData(NS_NATIVE_WIDGET);
}
if (aType == NATIVE_THEBES_CONTEXT)
return mThebes;
if (aType == NATIVE_CAIRO_CONTEXT)
return mThebes->GetCairo();
#ifdef XP_WIN
if (aType == NATIVE_WINDOWS_DC) {
nsRefPtr<gfxASurface> surf(mThebes->CurrentSurface());
if (!surf || surf->CairoStatus())
return nsnull;
return static_cast<gfxWindowsSurface*>(static_cast<gfxASurface*>(surf.get()))->GetDC();
}
#endif
#ifdef XP_OS2
if (aType == NATIVE_OS2_PS) {
nsRefPtr<gfxASurface> surf(mThebes->CurrentSurface());
if (!surf || surf->CairoStatus())
return nsnull;
return (void*)(static_cast<gfxOS2Surface*>(static_cast<gfxASurface*>(surf.get()))->GetPS());
}
#endif
// text
return nsnull;
}
nsresult
nsRenderingContext::PushFilter(const nsRect& twRect, PRBool aAreaIsOpaque,
float aOpacity)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
("## %p nsTRC::PushFilter [%d,%d,%d,%d] isOpaque: %d opacity: %f\n",
this, twRect.x, twRect.y, twRect.width, twRect.height,
aAreaIsOpaque, aOpacity));
mOpacityArray.AppendElement(aOpacity);
mThebes->Save();
mThebes->Clip(GFX_RECT_FROM_TWIPS_RECT(twRect));
mThebes->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
return NS_OK;
}
nsresult
nsRenderingContext::PopFilter()
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopFilter\n"));
if (mOpacityArray.Length() > 0) {
float f = mOpacityArray[mOpacityArray.Length()-1];
mOpacityArray.RemoveElementAt(mOpacityArray.Length()-1);
mThebes->PopGroupToSource();
if (f < 0.0) {
mThebes->SetOperator(gfxContext::OPERATOR_SOURCE);
mThebes->Paint();
} else {
mThebes->SetOperator(gfxContext::OPERATOR_OVER);
mThebes->Paint(f);
}
mThebes->Restore();
}
return NS_OK;
}
//
// text junk
//
nsresult
nsRenderingContext::SetRightToLeftText(PRBool aIsRTL)
{
return mFontMetrics->SetRightToLeftText(aIsRTL);
}
nsresult
nsRenderingContext::GetRightToLeftText(PRBool* aIsRTL)
{
*aIsRTL = mFontMetrics->GetRightToLeftText();
return NS_OK;
}
void
nsRenderingContext::SetTextRunRTL(PRBool aIsRTL)
{
@ -789,8 +509,6 @@ nsresult
nsRenderingContext::SetFont(const nsFont& aFont, nsIAtom* aLanguage,
gfxUserFontSet *aUserFontSet)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont %p\n", this, &aFont));
nsCOMPtr<nsIFontMetrics> newMetrics;
mDeviceContext->GetMetricsFor(aFont, aLanguage, aUserFontSet,
*getter_AddRefs(newMetrics));
@ -802,8 +520,6 @@ nsresult
nsRenderingContext::SetFont(const nsFont& aFont,
gfxUserFontSet *aUserFontSet)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont %p\n", this, &aFont));
nsCOMPtr<nsIFontMetrics> newMetrics;
mDeviceContext->GetMetricsFor(aFont, nsnull, aUserFontSet,
*getter_AddRefs(newMetrics));
@ -814,8 +530,6 @@ nsRenderingContext::SetFont(const nsFont& aFont,
nsresult
nsRenderingContext::SetFont(nsIFontMetrics *aFontMetrics)
{
PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont[Metrics] %p\n", this, aFontMetrics));
mFontMetrics = static_cast<nsIThebesFontMetrics*>(aFontMetrics);
return NS_OK;
}
@ -828,11 +542,11 @@ nsRenderingContext::GetFontMetrics()
}
PRInt32
nsRenderingContext::GetMaxStringLength()
nsRenderingContext::GetMaxChunkLength()
{
if (!mFontMetrics)
return 1;
return mFontMetrics->GetMaxStringLength();
return PR_MIN(mFontMetrics->GetMaxStringLength(), MAX_GFX_TEXT_BUF_SIZE);
}
nsresult
@ -876,10 +590,10 @@ nsRenderingContext::GetWidth(const char* aString,
PRUint32 aLength,
nscoord& aWidth)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
PRUint32 maxChunkLength = GetMaxChunkLength();
aWidth = 0;
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
nscoord width;
nsresult rv = GetWidthInternal(aString, len, width);
if (NS_FAILED(rv))
@ -897,7 +611,7 @@ nsRenderingContext::GetWidth(const PRUnichar *aString,
nscoord &aWidth,
PRInt32 *aFontID)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
PRUint32 maxChunkLength = GetMaxChunkLength();
aWidth = 0;
if (aFontID) {
@ -905,7 +619,7 @@ nsRenderingContext::GetWidth(const PRUnichar *aString,
}
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
nscoord width;
nsresult rv = GetWidthInternal(aString, len, width);
if (NS_FAILED(rv))
@ -917,228 +631,17 @@ nsRenderingContext::GetWidth(const PRUnichar *aString,
return NS_OK;
}
nsresult
nsRenderingContext::GetTextDimensions(const char* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
if (aLength <= maxChunkLength)
return GetTextDimensionsInternal(aString, aLength, aDimensions);
PRBool firstIteration = PR_TRUE;
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
nsTextDimensions dimensions;
nsresult rv = GetTextDimensionsInternal(aString, len, dimensions);
if (NS_FAILED(rv))
return rv;
if (firstIteration) {
// Instead of combining with a Clear()ed nsTextDimensions, we
// assign directly in the first iteration. This ensures that
// negative ascent/ descent can be returned.
aDimensions = dimensions;
} else {
aDimensions.Combine(dimensions);
}
aLength -= len;
aString += len;
firstIteration = PR_FALSE;
}
return NS_OK;
}
nsresult
nsRenderingContext::GetTextDimensions(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
if (aLength <= maxChunkLength)
return GetTextDimensionsInternal(aString, aLength, aDimensions);
if (aFontID) {
*aFontID = nsnull;
}
PRBool firstIteration = PR_TRUE;
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
nsTextDimensions dimensions;
nsresult rv = GetTextDimensionsInternal(aString, len, dimensions);
if (NS_FAILED(rv))
return rv;
if (firstIteration) {
// Instead of combining with a Clear()ed nsTextDimensions, we
// assign directly in the first iteration. This ensures that
// negative ascent/ descent can be returned.
aDimensions = dimensions;
} else {
aDimensions.Combine(dimensions);
}
aLength -= len;
aString += len;
firstIteration = PR_FALSE;
}
return NS_OK;
}
#if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11)
nsresult
nsRenderingContext::GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
if (aLength <= PRInt32(maxChunkLength))
return GetTextDimensionsInternal(aString, aLength, aAvailWidth, aBreaks, aNumBreaks,
aDimensions, aNumCharsFit, aLastWordDimensions, aFontID);
if (aFontID) {
*aFontID = 0;
}
// Do a naive implementation based on 3-arg GetTextDimensions
PRInt32 x = 0;
PRInt32 wordCount;
for (wordCount = 0; wordCount < aNumBreaks; ++wordCount) {
PRInt32 lastBreak = wordCount > 0 ? aBreaks[wordCount - 1] : 0;
nsTextDimensions dimensions;
NS_ASSERTION(aBreaks[wordCount] > lastBreak, "Breaks must be monotonically increasing");
NS_ASSERTION(aBreaks[wordCount] <= aLength, "Breaks can't exceed string length");
// Call safe method
nsresult rv =
GetTextDimensions(aString + lastBreak, aBreaks[wordCount] - lastBreak,
dimensions);
if (NS_FAILED(rv))
return rv;
x += dimensions.width;
// The first word always "fits"
if (x > aAvailWidth && wordCount > 0)
break;
// aDimensions ascent/descent should exclude the last word (unless there
// is only one word) so we let it run one word behind
if (wordCount == 0) {
aDimensions = dimensions;
} else {
aDimensions.Combine(aLastWordDimensions);
}
aNumCharsFit = aBreaks[wordCount];
aLastWordDimensions = dimensions;
}
// aDimensions width should include all the text
aDimensions.width = x;
return NS_OK;
}
nsresult
nsRenderingContext::GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
if (aLength <= PRInt32(maxChunkLength))
return GetTextDimensionsInternal(aString, aLength, aAvailWidth, aBreaks, aNumBreaks,
aDimensions, aNumCharsFit, aLastWordDimensions, aFontID);
if (aFontID) {
*aFontID = 0;
}
// Do a naive implementation based on 3-arg GetTextDimensions
PRInt32 x = 0;
PRInt32 wordCount;
for (wordCount = 0; wordCount < aNumBreaks; ++wordCount) {
PRInt32 lastBreak = wordCount > 0 ? aBreaks[wordCount - 1] : 0;
NS_ASSERTION(aBreaks[wordCount] > lastBreak, "Breaks must be monotonically increasing");
NS_ASSERTION(aBreaks[wordCount] <= aLength, "Breaks can't exceed string length");
nsTextDimensions dimensions;
// Call safe method
nsresult rv =
GetTextDimensions(aString + lastBreak, aBreaks[wordCount] - lastBreak,
dimensions);
if (NS_FAILED(rv))
return rv;
x += dimensions.width;
// The first word always "fits"
if (x > aAvailWidth && wordCount > 0)
break;
// aDimensions ascent/descent should exclude the last word (unless there
// is only one word) so we let it run one word behind
if (wordCount == 0) {
aDimensions = dimensions;
} else {
aDimensions.Combine(aLastWordDimensions);
}
aNumCharsFit = aBreaks[wordCount];
aLastWordDimensions = dimensions;
}
// aDimensions width should include all the text
aDimensions.width = x;
return NS_OK;
}
#endif
#ifdef MOZ_MATHML
nsresult
nsRenderingContext::GetBoundingMetrics(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
if (aLength <= maxChunkLength)
return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics);
PRBool firstIteration = PR_TRUE;
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
nsBoundingMetrics metrics;
nsresult rv = GetBoundingMetricsInternal(aString, len, metrics);
if (NS_FAILED(rv))
return rv;
if (firstIteration) {
// Instead of combining with a Clear()ed nsBoundingMetrics, we
// assign directly in the first iteration. This ensures that
// negative ascent/ descent can be returned and the left bearing
// is properly initialized.
aBoundingMetrics = metrics;
} else {
aBoundingMetrics += metrics;
}
aLength -= len;
aString += len;
firstIteration = PR_FALSE;
}
return NS_OK;
}
nsresult
nsRenderingContext::GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics,
PRInt32* aFontID)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
PRUint32 maxChunkLength = GetMaxChunkLength();
if (aLength <= maxChunkLength)
return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics, aFontID);
return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics,
aFontID);
if (aFontID) {
*aFontID = 0;
@ -1146,7 +649,7 @@ nsRenderingContext::GetBoundingMetrics(const PRUnichar* aString,
PRBool firstIteration = PR_TRUE;
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
nsBoundingMetrics metrics;
nsresult rv = GetBoundingMetricsInternal(aString, len, metrics);
if (NS_FAILED(rv))
@ -1173,9 +676,9 @@ nsRenderingContext::DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
PRUint32 maxChunkLength = GetMaxChunkLength();
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
nsresult rv = DrawStringInternal(aString, len, aX, aY);
if (NS_FAILED(rv))
return rv;
@ -1199,13 +702,12 @@ nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength,
PRInt32 aFontID,
const nscoord* aSpacing)
{
PRUint32 maxChunkLength = GetMaxChunkLength(this);
PRUint32 maxChunkLength = GetMaxChunkLength();
if (aLength <= maxChunkLength) {
return DrawStringInternal(aString, aLength, aX, aY, aFontID, aSpacing);
}
PRBool isRTL = PR_FALSE;
GetRightToLeftText(&isRTL);
PRBool isRTL = mFontMetrics->GetRightToLeftText();
if (isRTL) {
nscoord totalWidth = 0;
@ -1222,7 +724,7 @@ nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength,
}
while (aLength > 0) {
PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
nscoord width = 0;
if (aSpacing) {
for (PRInt32 i = 0; i < len; ++i) {
@ -1256,11 +758,6 @@ nsresult
nsRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength,
nscoord& aWidth)
{
#ifdef DISABLE_TEXT
aWidth = (8 * aLength);
return NS_OK;
#endif
if (aLength == 0) {
aWidth = 0;
return NS_OK;
@ -1273,11 +770,6 @@ nsresult
nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
nscoord &aWidth, PRInt32 *aFontID)
{
#ifdef DISABLE_TEXT
aWidth = (8 * aLength);
return NS_OK;
#endif
if (aLength == 0) {
aWidth = 0;
return NS_OK;
@ -1286,67 +778,7 @@ nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
return mFontMetrics->GetWidth(aString, aLength, aWidth, aFontID, this);
}
nsresult
nsRenderingContext::GetTextDimensionsInternal(const char* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions)
{
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return GetWidth(aString, aLength, aDimensions.width);
}
nsresult
nsRenderingContext::GetTextDimensionsInternal(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID)
{
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return GetWidth(aString, aLength, aDimensions.width, aFontID);
}
#if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) || defined(XP_MACOSX) || defined (MOZ_DFB)
nsresult
nsRenderingContext::GetTextDimensionsInternal(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsRenderingContext::GetTextDimensionsInternal(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif
#ifdef MOZ_MATHML
nsresult
nsRenderingContext::GetBoundingMetricsInternal(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics)
{
return mFontMetrics->GetBoundingMetrics(aString, aLength, this,
aBoundingMetrics);
}
nsresult
nsRenderingContext::GetBoundingMetricsInternal(const PRUnichar* aString,
PRUint32 aLength,
@ -1363,12 +795,7 @@ nsRenderingContext::DrawStringInternal(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing)
{
#ifdef DISABLE_TEXT
return NS_OK;
#endif
return mFontMetrics->DrawString(aString, aLength, aX, aY, aSpacing,
this);
return mFontMetrics->DrawString(aString, aLength, aX, aY, aSpacing, this);
}
nsresult
@ -1378,45 +805,6 @@ nsRenderingContext::DrawStringInternal(const PRUnichar *aString,
PRInt32 aFontID,
const nscoord* aSpacing)
{
#ifdef DISABLE_TEXT
return NS_OK;
#endif
return mFontMetrics->DrawString(aString, aLength, aX, aY, aFontID,
aSpacing, this);
}
PRInt32
nsRenderingContext::GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt)
{
return -1;
}
nsresult
nsRenderingContext::GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsRenderingContext::GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsRenderingContext::RenderEPS(const nsRect& aRect, FILE *aDataFile)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -40,17 +40,13 @@
#define NSRENDERINGCONTEXT__H__
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsIWidget.h"
#include "nsIThebesFontMetrics.h"
#include "nsIRegion.h"
#include "nsPoint.h"
#include "nsSize.h"
#include "nsColor.h"
#include "nsRect.h"
#include "nsIRegion.h"
#include "nsTransform2D.h"
#include "nsIThebesFontMetrics.h"
#include "gfxContext.h"
typedef enum {
@ -67,41 +63,6 @@ typedef enum {
nsLineStyle_kDotted = 3
} nsLineStyle;
/* Struct used to represent the overall extent of a string
* whose rendering may involve switching between different
* fonts that have different metrics.
*/
struct nsTextDimensions {
// max ascent amongst all the fonts needed to represent the string
nscoord ascent;
// max descent amongst all the fonts needed to represent the string
nscoord descent;
// width of the string
nscoord width;
nsTextDimensions()
{
Clear();
}
/* Set all member data to zero */
void
Clear() {
ascent = descent = width = 0;
}
/* Sum with another dimension */
void
Combine(const nsTextDimensions& aOther) {
if (ascent < aOther.ascent) ascent = aOther.ascent;
if (descent < aOther.descent) descent = aOther.descent;
width += aOther.width;
}
};
#ifdef MOZ_MATHML
/* Struct used for accurate measurements of a string in order
* to allow precise positioning when processing MathML.
@ -147,30 +108,16 @@ struct nsBoundingMetrics {
The _exact_ height of the string is therefore:
ascent + descent */
//////////
// Metrics for placing other surrounding text:
nscoord width;
/* The horizontal distance from the origin of the drawing
operation to the correct origin for drawing another string
to follow the current one. Depending on the font, this
could be greater than or less than the right bearing. */
nsBoundingMetrics() {
Clear();
}
nsBoundingMetrics() : leftBearing(0), rightBearing(0),
ascent(0), descent(0), width(0)
{}
//////////
// Utility methods and operators:
/* Set all member data to zero */
void
Clear() {
leftBearing = rightBearing = 0;
ascent = descent = width = 0;
}
/* Append another bounding metrics */
void
operator += (const nsBoundingMetrics& bm) {
if (ascent + descent == 0 && rightBearing - leftBearing == 0) {
@ -194,73 +141,93 @@ struct nsBoundingMetrics {
class nsRenderingContext
{
public:
nsRenderingContext()
: mP2A(0.), mLineStyle(nsLineStyle_kNone), mColor(NS_RGB(0,0,0))
{}
nsRenderingContext() : mP2A(0.) {}
// ~nsRenderingContext() {}
NS_INLINE_DECL_REFCOUNTING(nsRenderingContext)
/**
* Return the maximum length of a string that can be handled by
* the platform using the current font metrics.
*/
PRInt32 GetMaxStringLength();
nsresult Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
nsresult Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
already_AddRefed<nsIDeviceContext> GetDeviceContext();
gfxContext *ThebesContext() { return mThebes; }
// Graphics state
nsresult PushState(void);
nsresult PopState(void);
nsresult SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
nsresult SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
nsresult SetLineStyle(nsLineStyle aLineStyle);
nsresult SetColor(nscolor aColor);
nsresult Translate(const nsPoint& aPt);
nsresult Scale(float aSx, float aSy);
class AutoPushTranslation {
nsRenderingContext* mCtx;
public:
AutoPushTranslation(nsRenderingContext* aCtx, const nsPoint& aPt)
: mCtx(aCtx) {
mCtx->PushState();
mCtx->Translate(aPt);
}
~AutoPushTranslation() {
mCtx->PopState();
}
};
// Shapes
nsresult DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
nsresult DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
nsresult DrawRect(const nsRect& aRect);
nsresult DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
nsresult DrawEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
nsresult DrawEllipse(const nsRect& aRect);
nsresult FillRect(const nsRect& aRect);
nsresult FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
nsresult FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
nsresult FillEllipse(const nsRect& aRect);
nsresult FillEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
nsresult InvertRect(const nsRect& aRect);
nsresult InvertRect(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
// Text
nsresult SetFont(const nsFont& aFont, nsIAtom* aLanguage,
gfxUserFontSet *aUserFontSet);
nsresult SetFont(const nsFont& aFont, gfxUserFontSet *aUserFontSet);
nsresult SetFont(nsIFontMetrics *aFontMetrics);
already_AddRefed<nsIFontMetrics> GetFontMetrics();
nsresult SetRightToLeftText(PRBool aIsRTL);
void SetTextRunRTL(PRBool aIsRTL);
// Safe string method variants: by default, these defer to the more
// elaborate methods below
nsresult GetWidth(const nsString& aString, nscoord &aWidth,
PRInt32 *aFontID = nsnull);
nsresult GetWidth(const char* aString, nscoord& aWidth);
nsresult DrawString(const nsString& aString, nscoord aX, nscoord aY,
PRInt32 aFontID = -1,
const nscoord* aSpacing = nsnull);
// Safe string methods
nsresult GetWidth(const char* aString, PRUint32 aLength,
nscoord& aWidth);
nsresult GetWidth(const PRUnichar *aString, PRUint32 aLength,
nscoord &aWidth, PRInt32 *aFontID = nsnull);
nsresult GetWidth(char aC, nscoord &aWidth);
nsresult GetWidth(PRUnichar aC, nscoord &aWidth,
PRInt32 *aFontID);
nsresult GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID = nsnull);
nsresult GetTextDimensions(const char* aString, PRUint32 aLength,
nsTextDimensions& aDimensions);
nsresult GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID = nsnull);
#if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11)
nsresult GetTextDimensions(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
nsresult GetTextDimensions(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
#endif
#ifdef MOZ_MATHML
nsresult GetBoundingMetrics(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
nsresult GetBoundingMetrics(const PRUnichar* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics,
PRInt32* aFontID = nsnull);
#endif
nsresult DrawString(const nsString& aString, nscoord aX, nscoord aY,
PRInt32 aFontID = -1,
const nscoord* aSpacing = nsnull);
nsresult DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing = nsnull);
@ -269,113 +236,9 @@ public:
PRInt32 aFontID = -1,
const nscoord* aSpacing = nsnull);
nsresult Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
nsresult Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
nsresult Init(nsIDeviceContext* aContext, nsIWidget *aWidget);
nsresult CommonInit(void);
already_AddRefed<nsIDeviceContext> GetDeviceContext();
nsresult PushState(void);
nsresult PopState(void);
nsresult SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
nsresult SetLineStyle(nsLineStyle aLineStyle);
nsresult SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
nsresult SetColor(nscolor aColor);
nsresult GetColor(nscolor &aColor) const;
nsresult SetFont(const nsFont& aFont, nsIAtom* aLanguage,
gfxUserFontSet *aUserFontSet);
nsresult SetFont(const nsFont& aFont,
gfxUserFontSet *aUserFontSet);
nsresult SetFont(nsIFontMetrics *aFontMetrics);
already_AddRefed<nsIFontMetrics> GetFontMetrics();
nsresult Translate(const nsPoint& aPt);
nsresult Scale(float aSx, float aSy);
nsTransform2D* GetCurrentTransform();
nsresult DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
nsresult DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
nsresult DrawRect(const nsRect& aRect);
nsresult DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
nsresult FillRect(const nsRect& aRect);
nsresult FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
nsresult InvertRect(const nsRect& aRect);
nsresult InvertRect(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
nsresult FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
nsresult DrawEllipse(const nsRect& aRect);
nsresult DrawEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
nsresult FillEllipse(const nsRect& aRect);
nsresult FillEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
nsresult PushFilter(const nsRect& aRect,
PRBool aAreaIsOpaque, float aOpacity);
nsresult PopFilter();
enum GraphicDataType {
NATIVE_CAIRO_CONTEXT = 1,
NATIVE_GDK_DRAWABLE = 2,
NATIVE_WINDOWS_DC = 3,
NATIVE_MAC_THING = 4,
NATIVE_THEBES_CONTEXT = 5,
NATIVE_OS2_PS = 6
};
void* GetNativeGraphicData(GraphicDataType aType);
struct PushedTranslation {
float mSavedX, mSavedY;
};
class AutoPushTranslation {
nsRenderingContext* mCtx;
PushedTranslation mPushed;
public:
AutoPushTranslation(nsRenderingContext* aCtx, const nsPoint& aPt)
: mCtx(aCtx) {
mCtx->PushTranslation(&mPushed);
mCtx->Translate(aPt);
}
~AutoPushTranslation() {
mCtx->PopTranslation(&mPushed);
}
};
nsresult PushTranslation(PushedTranslation* aState);
nsresult PopTranslation(PushedTranslation* aState);
nsresult SetTranslation(const nsPoint& aPoint);
/**
* Let the device context know whether we want text reordered with
* right-to-left base direction
*/
nsresult SetRightToLeftText(PRBool aIsRTL);
nsresult GetRightToLeftText(PRBool* aIsRTL);
void SetTextRunRTL(PRBool aIsRTL);
PRInt32 GetPosition(const PRUnichar *aText,
PRUint32 aLength,
nsPoint aPt);
nsresult GetRangeWidth(const PRUnichar *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
nsresult GetRangeWidth(const char *aText,
PRUint32 aLength,
PRUint32 aStart,
PRUint32 aEnd,
PRUint32 &aWidth);
nsresult RenderEPS(const nsRect& aRect, FILE *aDataFile);
// Thebes specific stuff
gfxContext *ThebesContext() { return mThebes; }
nsTransform2D& CurrentTransform();
void TransformCoord (nscoord *aX, nscoord *aY);
protected:
PRInt32 GetMaxChunkLength();
nsresult GetWidthInternal(const char *aString, PRUint32 aLength,
nscoord &aWidth);
nsresult GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
@ -389,42 +252,7 @@ protected:
PRInt32 aFontID = -1,
const nscoord* aSpacing = nsnull);
nsresult GetTextDimensionsInternal(const char* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions);
nsresult GetTextDimensionsInternal(const PRUnichar* aString,
PRUint32 aLength,
nsTextDimensions& aDimensions,
PRInt32* aFontID = nsnull);
nsresult GetTextDimensionsInternal(const char* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
nsresult GetTextDimensionsInternal(const PRUnichar* aString,
PRInt32 aLength,
PRInt32 aAvailWidth,
PRInt32* aBreaks,
PRInt32 aNumBreaks,
nsTextDimensions& aDimensions,
PRInt32& aNumCharsFit,
nsTextDimensions& aLastWordDimensions,
PRInt32* aFontID = nsnull);
void UpdateTempTransformMatrix();
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string
*/
nsresult GetBoundingMetricsInternal(const char* aString,
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics);
/**
* Returns metrics (in app units) of a Unicode character string
*/
@ -432,23 +260,13 @@ protected:
PRUint32 aLength,
nsBoundingMetrics& aBoundingMetrics,
PRInt32* aFontID = nsnull);
#endif /* MOZ_MATHML */
nsRefPtr<gfxContext> mThebes;
nsCOMPtr<nsIDeviceContext> mDeviceContext;
nsCOMPtr<nsIWidget> mWidget;
nsCOMPtr<nsIThebesFontMetrics> mFontMetrics;
double mP2A; // cached app units per device pixel value
nsLineStyle mLineStyle;
nscolor mColor;
// for handing out to people
nsTransform2D mTempTransform;
// keeping track of pushgroup/popgroup opacities
nsTArray<float> mOpacityArray;
};
#endif // NSRENDERINGCONTEXT__H__

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

@ -451,7 +451,7 @@ nsThebesFontMetrics::GetBoundingMetrics(const char *aString, PRUint32 aLength,
nsBoundingMetrics &aBoundingMetrics)
{
if (aLength == 0) {
aBoundingMetrics.Clear();
aBoundingMetrics = nsBoundingMetrics();
return NS_OK;
}
@ -469,7 +469,7 @@ nsThebesFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLeng
nsBoundingMetrics &aBoundingMetrics)
{
if (aLength == 0) {
aBoundingMetrics.Clear();
aBoundingMetrics = nsBoundingMetrics();
return NS_OK;
}

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

@ -235,6 +235,8 @@ struct nsHTMLReflowMetrics {
nscoord width, height; // [OUT] desired width and height (border-box)
nscoord ascent; // [OUT] baseline (from top), or ASK_FOR_BASELINE
PRUint32 mFlags;
enum { ASK_FOR_BASELINE = nscoord_MAX };
#ifdef MOZ_MATHML
@ -276,39 +278,15 @@ struct nsHTMLReflowMetrics {
// Union all of mOverflowAreas with (0, 0, width, height).
void UnionOverflowAreasWithDesiredBounds();
PRUint32 mFlags;
// XXXldb Should |aFlags| generally be passed from parent to child?
// Some places do it, and some don't. |aFlags| should perhaps go away
// entirely.
nsHTMLReflowMetrics(PRUint32 aFlags = 0) {
mFlags = aFlags;
#ifdef MOZ_MATHML
mBoundingMetrics.Clear();
#endif
// XXX These are OUT parameters and so they shouldn't have to be
// initialized, but there are some bad frame classes that aren't
// properly setting them when returning from Reflow()...
width = height = 0;
ascent = ASK_FOR_BASELINE;
}
nsHTMLReflowMetrics& operator=(const nsHTMLReflowMetrics& aOther)
{
mFlags = aOther.mFlags;
mCarriedOutBottomMargin = aOther.mCarriedOutBottomMargin;
mOverflowAreas = aOther.mOverflowAreas;
#ifdef MOZ_MATHML
mBoundingMetrics = aOther.mBoundingMetrics;
#endif
width = aOther.width;
height = aOther.height;
ascent = aOther.ascent;
return *this;
}
// XXX width/height/ascent are OUT parameters and so they shouldn't
// have to be initialized, but there are some bad frame classes that
// aren't properly setting them when returning from Reflow()...
nsHTMLReflowMetrics(PRUint32 aFlags = 0)
: width(0), height(0), ascent(ASK_FOR_BASELINE), mFlags(aFlags)
{}
};
#endif /* nsHTMLReflowMetrics_h___ */

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

@ -1131,12 +1131,12 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext,
inner.XMost() - size : inner.x;
nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2);
aRenderingContext.DrawRect(iconXPos, inner.y,size,size);
aRenderingContext.GetColor(oldColor);
aRenderingContext.PushState();
aRenderingContext.SetColor(NS_RGB(0xFF,0,0));
aRenderingContext.FillEllipse(size/2 + iconXPos, size/2 + inner.y,
size/2 - twoPX, size/2 - twoPX);
aRenderingContext.SetColor(oldColor);
}
aRenderingContext.PopState();
}
// Reduce the inner rect by the width of the icon, and leave an
// additional ICON_PADDING pixels for padding

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

@ -1662,6 +1662,19 @@ nsObjectFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
return NS_OK;
}
#ifdef XP_OS2
static void *
GetPSFromRC(nsRenderingContext& aRC)
{
nsRefPtr<gfxASurface>
surf = aRenderingContext.ThebesContext()->CurrentSurface();
if (!surf || surf->CairoStatus())
return nsnull;
return (void *)(static_cast<gfxOS2Surface*>
(static_cast<gfxASurface*>(surf.get()))->GetPS());
}
#endif
void
nsObjectFrame::PrintPlugin(nsRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
@ -1804,7 +1817,7 @@ nsObjectFrame::PrintPlugin(nsRenderingContext& aRenderingContext,
*/
#elif defined(XP_OS2)
void *hps = aRenderingContext.GetNativeGraphicData(nsRenderingContext::NATIVE_OS2_PS);
void *hps = GetPSFromRC(aRenderingContext);
if (!hps)
return;
@ -2470,7 +2483,7 @@ nsObjectFrame::PaintPlugin(nsDisplayListBuilder* aBuilder,
}
// check if we need to update the PS
HPS hps = (HPS)aRenderingContext.GetNativeGraphicData(nsRenderingContext::NATIVE_OS2_PS);
HPS hps = (HPS)GetPSFromRC(aRenderingContext);
if (reinterpret_cast<HPS>(window->window) != hps) {
window->window = reinterpret_cast<void*>(hps);
doupdatewindow = PR_TRUE;

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

@ -864,7 +864,7 @@ nsMathMLChar::SetData(nsPresContext* aPresContext,
// some assumptions until proven otherwise
// note that mGlyph is not initialized
mDirection = NS_STRETCH_DIRECTION_UNSUPPORTED;
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
mGlyphTable = nsnull;
// check if stretching is applicable ...
if (gGlyphTableList && (1 == mData.Length())) {

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

@ -949,7 +949,7 @@ nsMathMLContainerFrame::Reflow(nsPresContext* aPresContext,
{
aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
aDesiredSize.mBoundingMetrics.Clear();
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
/////////////
// Reflow children
@ -1286,7 +1286,7 @@ nsMathMLContainerFrame::Place(nsRenderingContext& aRenderingContext,
nsHTMLReflowMetrics& aDesiredSize)
{
// This is needed in case this frame is empty (i.e., no child frames)
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
RowChildFrameIterator child(this);
nscoord ascent = 0, descent = 0;

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

@ -79,7 +79,7 @@ nsMathMLForeignFrameWrapper::Reflow(nsPresContext* aPresContext,
mReference.y = aDesiredSize.ascent;
// just make-up a bounding metrics
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
mBoundingMetrics.ascent = aDesiredSize.ascent;
mBoundingMetrics.descent = aDesiredSize.height - aDesiredSize.ascent;
mBoundingMetrics.width = aDesiredSize.width;

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

@ -159,7 +159,7 @@ nsMathMLTokenFrame::Reflow(nsPresContext* aPresContext,
// initializations needed for empty markup like <mtag></mtag>
aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
aDesiredSize.mBoundingMetrics.Clear();
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
nsIFrame* childFrame = GetFirstChild(nsnull);
@ -201,7 +201,7 @@ nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext,
PRBool aPlaceOrigin,
nsHTMLReflowMetrics& aDesiredSize)
{
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
for (nsIFrame* childFrame = GetFirstChild(nsnull); childFrame;
childFrame = childFrame->GetNextSibling()) {
nsHTMLReflowMetrics childSize;

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

@ -297,7 +297,7 @@ nsMathMLmactionFrame::Reflow(nsPresContext* aPresContext,
aStatus = NS_FRAME_COMPLETE;
aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
nsIFrame* childFrame = GetSelectedFrame();
if (childFrame) {
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
@ -322,7 +322,7 @@ nsMathMLmactionFrame::Place(nsRenderingContext& aRenderingContext,
{
aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
nsIFrame* childFrame = GetSelectedFrame();
if (childFrame) {
GetReflowAndBoundingMetricsFor(childFrame, aDesiredSize, mBoundingMetrics);

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

@ -239,7 +239,7 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
nsresult rv;
aDesiredSize.width = aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
aDesiredSize.mBoundingMetrics.Clear();
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
PRInt32 i;
const nsStyleFont* font = GetStyleFont();
@ -502,11 +502,11 @@ nsMathMLmfencedFrame::ReflowChar(nsPresContext* aPresContext,
if (NS_FAILED(res)) {
nsAutoString data;
aMathMLChar->GetData(data);
nsTextDimensions dimensions;
aRenderingContext.GetTextDimensions(data.get(), data.Length(), dimensions);
charSize.ascent = dimensions.ascent;
charSize.descent = dimensions.descent;
charSize.width = dimensions.width;
nsBoundingMetrics metrics;
aRenderingContext.GetBoundingMetrics(data.get(), data.Length(), metrics);
charSize.ascent = metrics.ascent;
charSize.descent = metrics.descent;
charSize.width = metrics.width;
// Set this as the bounding metrics of the MathMLChar to leave
// the necessary room to paint the char.
aMathMLChar->SetBoundingMetrics(charSize);

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

@ -968,7 +968,7 @@ nsMathMLmoFrame::Reflow(nsPresContext* aPresContext,
aDesiredSize.width = 0;
aDesiredSize.height = 0;
aDesiredSize.ascent = 0;
aDesiredSize.mBoundingMetrics.Clear();
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
aStatus = NS_FRAME_COMPLETE;
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);

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

@ -129,7 +129,7 @@ nsMathMLmspaceFrame::Reflow(nsPresContext* aPresContext,
{
ProcessAttributes(aPresContext);
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
mBoundingMetrics.width = mWidth;
mBoundingMetrics.ascent = mHeight;
mBoundingMetrics.descent = mDepth;

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

@ -661,7 +661,7 @@ nsMathMLmtableOuterFrame::Reflow(nsPresContext* aPresContext,
mReference.y = aDesiredSize.ascent;
// just make-up a bounding metrics
mBoundingMetrics.Clear();
mBoundingMetrics = nsBoundingMetrics();
mBoundingMetrics.ascent = aDesiredSize.ascent;
mBoundingMetrics.descent = aDesiredSize.height - aDesiredSize.ascent;
mBoundingMetrics.width = aDesiredSize.width;