bug 617008 - avoid creating a rendering context that we may not need. r=roc

This commit is contained in:
Jonathan Kew 2014-03-31 11:53:09 +01:00
parent fc018b8633
commit b0f64ce1f9
4 changed files with 36 additions and 15 deletions

View File

@ -74,6 +74,14 @@ public:
NS_ERROR("This shouldn't be called because we never enable hyphens");
return 0;
}
virtual already_AddRefed<gfxContext> GetContext() {
NS_ERROR("This shouldn't be called because we never enable hyphens");
return nullptr;
}
virtual uint32_t GetAppUnitsPerDevUnit() {
NS_ERROR("This shouldn't be called because we never enable hyphens");
return 60;
}
virtual void GetSpacing(uint32_t aStart, uint32_t aLength,
Spacing* aSpacing) {
NS_ERROR("This shouldn't be called because we never enable spacing");

View File

@ -4878,13 +4878,17 @@ gfxFontGroup::MakeHyphenTextRun(gfxContext *aCtx, uint32_t aAppUnitsPerDevUnit)
}
gfxFloat
gfxFontGroup::GetHyphenWidth(gfxContext *aCtx, uint32_t aAppUnitsPerDevUnit)
gfxFontGroup::GetHyphenWidth(gfxTextRun::PropertyProvider *aProvider)
{
if (mHyphenWidth < 0) {
nsAutoPtr<gfxTextRun> hyphRun(MakeHyphenTextRun(aCtx,
aAppUnitsPerDevUnit));
mHyphenWidth = hyphRun.get() ?
hyphRun->GetAdvanceWidth(0, hyphRun->GetLength(), nullptr) : 0;
nsRefPtr<gfxContext> ctx(aProvider->GetContext());
if (ctx) {
nsAutoPtr<gfxTextRun>
hyphRun(MakeHyphenTextRun(ctx,
aProvider->GetAppUnitsPerDevUnit()));
mHyphenWidth = hyphRun.get() ?
hyphRun->GetAdvanceWidth(0, hyphRun->GetLength(), nullptr) : 0;
}
}
return mHyphenWidth;
}

View File

@ -2834,6 +2834,14 @@ public:
*/
virtual void GetSpacing(uint32_t aStart, uint32_t aLength,
Spacing *aSpacing) = 0;
// Returns a gfxContext that can be used to measure the hyphen glyph.
// Only called if the hyphen width is requested.
virtual already_AddRefed<gfxContext> GetContext() = 0;
// Return the appUnitsPerDevUnit value to be used when measuring.
// Only called if the hyphen width is requested.
virtual uint32_t GetAppUnitsPerDevUnit() = 0;
};
class ClusterIterator {
@ -3433,7 +3441,7 @@ public:
* needed to initialize the cached hyphen width; otherwise they are
* ignored.
*/
gfxFloat GetHyphenWidth(gfxContext *aCtx, uint32_t aAppUnitsPerDevUnit);
gfxFloat GetHyphenWidth(gfxTextRun::PropertyProvider* aProvider);
/**
* Make a text run representing a single hyphen character.

View File

@ -2839,6 +2839,14 @@ public:
return mTextStyle->mHyphens;
}
virtual already_AddRefed<gfxContext> GetContext() {
return GetReferenceRenderingContext(GetFrame(), nullptr);
}
virtual uint32_t GetAppUnitsPerDevUnit() {
return mTextRun->GetAppUnitsPerDevUnit();
}
void GetSpacingInternal(uint32_t aStart, uint32_t aLength, Spacing* aSpacing,
bool aIgnoreTabs);
@ -3194,16 +3202,9 @@ gfxFloat
PropertyProvider::GetHyphenWidth()
{
if (mHyphenWidth < 0) {
mHyphenWidth = mLetterSpacing;
nsRefPtr<gfxContext> context(GetReferenceRenderingContext(GetFrame(),
nullptr));
if (context) {
mHyphenWidth +=
GetFontGroup()->GetHyphenWidth(context,
mTextRun->GetAppUnitsPerDevUnit());
}
mHyphenWidth = GetFontGroup()->GetHyphenWidth(this);
}
return mHyphenWidth;
return mHyphenWidth + mLetterSpacing;
}
void