зеркало из https://github.com/mozilla/gecko-dev.git
Bug 752638, part 1 - Move SVGTextFrame::SetupContextPaint to nsSVGUtils. r=heycam
This commit is contained in:
Родитель
22c58476c8
Коммит
debbbba148
|
@ -3736,8 +3736,8 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
|
|||
|
||||
SVGTextContextPaint contextPaint;
|
||||
DrawMode drawMode =
|
||||
SetupContextPaint(&aDrawTarget, aContext.CurrentMatrix(),
|
||||
frame, outerContextPaint, &contextPaint);
|
||||
nsSVGUtils::SetupContextPaint(&aDrawTarget, aContext.CurrentMatrix(),
|
||||
frame, outerContextPaint, &contextPaint);
|
||||
|
||||
if (drawMode & DrawMode::GLYPH_STROKE) {
|
||||
// This may change the gfxContext's transform (for non-scaling stroke),
|
||||
|
@ -5722,109 +5722,3 @@ SVGTextFrame::TransformFrameRectFromTextChild(const nsRect& aRect,
|
|||
return result - framePosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores in |aTargetPaint| information on how to reconstruct the current
|
||||
* fill or stroke pattern. Will also set the paint opacity to transparent if
|
||||
* the paint is set to "none".
|
||||
* @param aOuterContextPaint pattern information from the outer text context
|
||||
* @param aTargetPaint where to store the current pattern information
|
||||
* @param aFillOrStroke member pointer to the paint we are setting up
|
||||
* @param aProperty the frame property descriptor of the fill or stroke paint
|
||||
* server frame
|
||||
*/
|
||||
static void
|
||||
SetupInheritablePaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
float& aOpacity,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint::Paint& aTargetPaint,
|
||||
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
||||
nsSVGEffects::ObserverPropertyDescriptor aProperty)
|
||||
{
|
||||
const nsStyleSVG *style = aFrame->StyleSVG();
|
||||
nsSVGPaintServerFrame *ps =
|
||||
nsSVGEffects::GetPaintServer(aFrame, &(style->*aFillOrStroke), aProperty);
|
||||
|
||||
if (ps) {
|
||||
RefPtr<gfxPattern> pattern =
|
||||
ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix,
|
||||
aFillOrStroke, aOpacity);
|
||||
if (pattern) {
|
||||
aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (aOuterContextPaint) {
|
||||
RefPtr<gfxPattern> pattern;
|
||||
switch ((style->*aFillOrStroke).mType) {
|
||||
case eStyleSVGPaintType_ContextFill:
|
||||
pattern = aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity,
|
||||
aContextMatrix);
|
||||
break;
|
||||
case eStyleSVGPaintType_ContextStroke:
|
||||
pattern = aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity,
|
||||
aContextMatrix);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
if (pattern) {
|
||||
aTargetPaint.SetContextPaint(aOuterContextPaint, (style->*aFillOrStroke).mType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
nscolor color =
|
||||
nsSVGUtils::GetFallbackOrPaintColor(aFrame->StyleContext(), aFillOrStroke);
|
||||
aTargetPaint.SetColor(color);
|
||||
}
|
||||
|
||||
DrawMode
|
||||
SVGTextFrame::SetupContextPaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint* aThisContextPaint)
|
||||
{
|
||||
DrawMode toDraw = DrawMode(0);
|
||||
|
||||
const nsStyleSVG *style = aFrame->StyleSVG();
|
||||
|
||||
// fill:
|
||||
if (style->mFill.mType == eStyleSVGPaintType_None) {
|
||||
aThisContextPaint->SetFillOpacity(0.0f);
|
||||
} else {
|
||||
float opacity = nsSVGUtils::GetOpacity(style->mFillOpacitySource,
|
||||
style->mFillOpacity,
|
||||
aOuterContextPaint);
|
||||
|
||||
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
|
||||
opacity, aOuterContextPaint,
|
||||
aThisContextPaint->mFillPaint, &nsStyleSVG::mFill,
|
||||
nsSVGEffects::FillProperty());
|
||||
|
||||
aThisContextPaint->SetFillOpacity(opacity);
|
||||
|
||||
toDraw |= DrawMode::GLYPH_FILL;
|
||||
}
|
||||
|
||||
// stroke:
|
||||
if (style->mStroke.mType == eStyleSVGPaintType_None) {
|
||||
aThisContextPaint->SetStrokeOpacity(0.0f);
|
||||
} else {
|
||||
float opacity = nsSVGUtils::GetOpacity(style->mStrokeOpacitySource,
|
||||
style->mStrokeOpacity,
|
||||
aOuterContextPaint);
|
||||
|
||||
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
|
||||
opacity, aOuterContextPaint,
|
||||
aThisContextPaint->mStrokePaint, &nsStyleSVG::mStroke,
|
||||
nsSVGEffects::StrokeProperty());
|
||||
|
||||
aThisContextPaint->SetStrokeOpacity(opacity);
|
||||
|
||||
toDraw |= DrawMode::GLYPH_STROKE;
|
||||
}
|
||||
|
||||
return toDraw;
|
||||
}
|
||||
|
|
|
@ -608,12 +608,6 @@ private:
|
|||
gfxFloat GetOffsetScale(nsIFrame* aTextPathFrame);
|
||||
gfxFloat GetStartOffset(nsIFrame* aTextPathFrame);
|
||||
|
||||
DrawMode SetupContextPaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint* aThisContextPaint);
|
||||
|
||||
/**
|
||||
* The MutationObserver we have registered for the <text> element subtree.
|
||||
*/
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "mozilla/dom/SVGSVGElement.h"
|
||||
#include "nsTextFrame.h"
|
||||
#include "SVGContentUtils.h"
|
||||
#include "SVGTextFrame.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
@ -1297,6 +1298,113 @@ nsSVGUtils::GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
|
|||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores in |aTargetPaint| information on how to reconstruct the current
|
||||
* fill or stroke pattern. Will also set the paint opacity to transparent if
|
||||
* the paint is set to "none".
|
||||
* @param aOuterContextPaint pattern information from the outer text context
|
||||
* @param aTargetPaint where to store the current pattern information
|
||||
* @param aFillOrStroke member pointer to the paint we are setting up
|
||||
* @param aProperty the frame property descriptor of the fill or stroke paint
|
||||
* server frame
|
||||
*/
|
||||
static void
|
||||
SetupInheritablePaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
float& aOpacity,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint::Paint& aTargetPaint,
|
||||
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
||||
nsSVGEffects::ObserverPropertyDescriptor aProperty)
|
||||
{
|
||||
const nsStyleSVG *style = aFrame->StyleSVG();
|
||||
nsSVGPaintServerFrame *ps =
|
||||
nsSVGEffects::GetPaintServer(aFrame, &(style->*aFillOrStroke), aProperty);
|
||||
|
||||
if (ps) {
|
||||
RefPtr<gfxPattern> pattern =
|
||||
ps->GetPaintServerPattern(aFrame, aDrawTarget, aContextMatrix,
|
||||
aFillOrStroke, aOpacity);
|
||||
if (pattern) {
|
||||
aTargetPaint.SetPaintServer(aFrame, aContextMatrix, ps);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (aOuterContextPaint) {
|
||||
RefPtr<gfxPattern> pattern;
|
||||
switch ((style->*aFillOrStroke).mType) {
|
||||
case eStyleSVGPaintType_ContextFill:
|
||||
pattern = aOuterContextPaint->GetFillPattern(aDrawTarget, aOpacity,
|
||||
aContextMatrix);
|
||||
break;
|
||||
case eStyleSVGPaintType_ContextStroke:
|
||||
pattern = aOuterContextPaint->GetStrokePattern(aDrawTarget, aOpacity,
|
||||
aContextMatrix);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
if (pattern) {
|
||||
aTargetPaint.SetContextPaint(aOuterContextPaint, (style->*aFillOrStroke).mType);
|
||||
return;
|
||||
}
|
||||
}
|
||||
nscolor color =
|
||||
nsSVGUtils::GetFallbackOrPaintColor(aFrame->StyleContext(), aFillOrStroke);
|
||||
aTargetPaint.SetColor(color);
|
||||
}
|
||||
|
||||
/* static */ DrawMode
|
||||
nsSVGUtils::SetupContextPaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint* aThisContextPaint)
|
||||
{
|
||||
DrawMode toDraw = DrawMode(0);
|
||||
|
||||
const nsStyleSVG *style = aFrame->StyleSVG();
|
||||
|
||||
// fill:
|
||||
if (style->mFill.mType == eStyleSVGPaintType_None) {
|
||||
aThisContextPaint->SetFillOpacity(0.0f);
|
||||
} else {
|
||||
float opacity = nsSVGUtils::GetOpacity(style->mFillOpacitySource,
|
||||
style->mFillOpacity,
|
||||
aOuterContextPaint);
|
||||
|
||||
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
|
||||
opacity, aOuterContextPaint,
|
||||
aThisContextPaint->mFillPaint, &nsStyleSVG::mFill,
|
||||
nsSVGEffects::FillProperty());
|
||||
|
||||
aThisContextPaint->SetFillOpacity(opacity);
|
||||
|
||||
toDraw |= DrawMode::GLYPH_FILL;
|
||||
}
|
||||
|
||||
// stroke:
|
||||
if (style->mStroke.mType == eStyleSVGPaintType_None) {
|
||||
aThisContextPaint->SetStrokeOpacity(0.0f);
|
||||
} else {
|
||||
float opacity = nsSVGUtils::GetOpacity(style->mStrokeOpacitySource,
|
||||
style->mStrokeOpacity,
|
||||
aOuterContextPaint);
|
||||
|
||||
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame,
|
||||
opacity, aOuterContextPaint,
|
||||
aThisContextPaint->mStrokePaint, &nsStyleSVG::mStroke,
|
||||
nsSVGEffects::StrokeProperty());
|
||||
|
||||
aThisContextPaint->SetStrokeOpacity(opacity);
|
||||
|
||||
toDraw |= DrawMode::GLYPH_STROKE;
|
||||
}
|
||||
|
||||
return toDraw;
|
||||
}
|
||||
|
||||
static float
|
||||
MaybeOptimizeOpacity(nsIFrame *aFrame, float aFillOrStrokeOpacity)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// include math.h to pick up definition of M_ maths defines e.g. M_PI
|
||||
#include <math.h>
|
||||
|
||||
#include "DrawMode.h"
|
||||
#include "gfx2DGlue.h"
|
||||
#include "gfxMatrix.h"
|
||||
#include "gfxPoint.h"
|
||||
|
@ -46,6 +47,7 @@ struct nsStyleSVGPaint;
|
|||
struct nsRect;
|
||||
|
||||
namespace mozilla {
|
||||
struct SVGTextContextPaint;
|
||||
namespace dom {
|
||||
class Element;
|
||||
class UserSpaceMetrics;
|
||||
|
@ -178,9 +180,11 @@ class nsSVGUtils
|
|||
public:
|
||||
typedef mozilla::dom::Element Element;
|
||||
typedef mozilla::gfx::AntialiasMode AntialiasMode;
|
||||
typedef mozilla::gfx::DrawTarget DrawTarget;
|
||||
typedef mozilla::gfx::FillRule FillRule;
|
||||
typedef mozilla::gfx::GeneralPattern GeneralPattern;
|
||||
typedef mozilla::gfx::Size Size;
|
||||
typedef mozilla::SVGTextContextPaint SVGTextContextPaint;
|
||||
|
||||
static void Init();
|
||||
|
||||
|
@ -492,6 +496,13 @@ public:
|
|||
static nscolor GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
|
||||
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke);
|
||||
|
||||
static DrawMode
|
||||
SetupContextPaint(const DrawTarget* aDrawTarget,
|
||||
const gfxMatrix& aContextMatrix,
|
||||
nsIFrame* aFrame,
|
||||
gfxTextContextPaint* aOuterContextPaint,
|
||||
SVGTextContextPaint* aThisContextPaint);
|
||||
|
||||
static void
|
||||
MakeFillPatternFor(nsIFrame *aFrame,
|
||||
gfxContext* aContext,
|
||||
|
|
Загрузка…
Ссылка в новой задаче