mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 14:44:26 +00:00
bug 1018551 - clean up redundancy in the font/shaper code. r=jdaggett
This commit is contained in:
parent
e6e3ddadf9
commit
68d2010cfd
@ -7,9 +7,7 @@
|
||||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include <algorithm>
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "gfxDWriteFontList.h"
|
||||
#include "gfxContext.h"
|
||||
#include <dwrite.h>
|
||||
@ -106,14 +104,6 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
|
||||
}
|
||||
|
||||
ComputeMetrics(anAAOption);
|
||||
|
||||
if (FontCanSupportGraphite()) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
|
||||
if (FontCanSupportHarfBuzz()) {
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
}
|
||||
|
||||
gfxDWriteFont::~gfxDWriteFont()
|
||||
@ -134,32 +124,6 @@ gfxDWriteFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
|
||||
&mStyle, mNeedsBold, anAAOption);
|
||||
}
|
||||
|
||||
bool
|
||||
gfxDWriteFont::ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
||||
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
if (!ok && mHarfBuzzShaper) {
|
||||
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
const gfxFont::Metrics&
|
||||
gfxDWriteFont::GetMetrics()
|
||||
{
|
||||
|
@ -71,14 +71,6 @@ public:
|
||||
virtual cairo_scaled_font_t *GetCairoScaledFont();
|
||||
|
||||
protected:
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping = false);
|
||||
|
||||
bool GetFakeMetricsForArialBlack(DWRITE_FONT_METRICS *aFontMetrics);
|
||||
|
||||
void ComputeMetrics(AntialiasOption anAAOption);
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include "gfxFT2Utils.h"
|
||||
#include "gfxFT2FontList.h"
|
||||
#include <locale.h>
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsUnicodeRange.h"
|
||||
@ -44,42 +42,20 @@
|
||||
*/
|
||||
|
||||
bool
|
||||
gfxFT2Font::ShapeText(gfxContext *aContext,
|
||||
gfxFT2Font::ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if (FontCanSupportGraphite()) {
|
||||
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
||||
if (!mGraphiteShaper) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
ok = mGraphiteShaper->ShapeText(aContext, aText,
|
||||
aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!mHarfBuzzShaper) {
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
ok = mHarfBuzzShaper->ShapeText(aContext, aText,
|
||||
aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
|
||||
aShapedText)) {
|
||||
// harfbuzz must have failed(?!), just render raw glyphs
|
||||
AddRange(aText, aOffset, aLength, aShapedText);
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
}
|
||||
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,7 @@ protected:
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping);
|
||||
gfxShapedText *aShapedText);
|
||||
|
||||
void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "gfxTypes.h"
|
||||
#include "gfxContext.h"
|
||||
#include "gfxFontMissingGlyphs.h"
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include "gfxUserFontSet.h"
|
||||
#include "gfxPlatformFontList.h"
|
||||
@ -4074,8 +4075,7 @@ gfxFont::ShapeText(gfxContext *aContext,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
gfxShapedText *aShapedText)
|
||||
{
|
||||
nsDependentCSubstring ascii((const char*)aText, aLength);
|
||||
nsAutoString utf16;
|
||||
@ -4084,7 +4084,7 @@ gfxFont::ShapeText(gfxContext *aContext,
|
||||
return false;
|
||||
}
|
||||
return ShapeText(aContext, utf16.BeginReading(), aOffset, aLength,
|
||||
aScript, aShapedText, aPreferPlatformShaping);
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -4093,30 +4093,29 @@ gfxFont::ShapeText(gfxContext *aContext,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
gfxShapedText *aShapedText)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if (mGraphiteShaper && gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
||||
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
if (FontCanSupportGraphite()) {
|
||||
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
||||
if (!mGraphiteShaper) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok && mHarfBuzzShaper && !aPreferPlatformShaping) {
|
||||
if (!ok) {
|
||||
if (!mHarfBuzzShaper) {
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!mPlatformShaper) {
|
||||
CreatePlatformShaper();
|
||||
}
|
||||
if (mPlatformShaper) {
|
||||
ok = mPlatformShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
}
|
||||
NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text");
|
||||
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
|
||||
|
@ -1479,12 +1479,12 @@ public:
|
||||
// Shape a piece of text and store the resulting glyph data into
|
||||
// aShapedText. Parameters aOffset/aLength indicate the range of
|
||||
// aShapedText to be updated; aLength is also the length of aText.
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText) = 0;
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText) = 0;
|
||||
|
||||
gfxFont *GetFont() const { return mFont; }
|
||||
|
||||
@ -1996,8 +1996,7 @@ protected:
|
||||
uint32_t aOffset, // dest offset in gfxShapedText
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText, // where to store the result
|
||||
bool aPreferPlatformShaping = false);
|
||||
gfxShapedText *aShapedText); // where to store the result
|
||||
|
||||
// Call the appropriate shaper to generate glyphs for aText and store
|
||||
// them into aShapedText.
|
||||
@ -2006,8 +2005,7 @@ protected:
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping = false);
|
||||
gfxShapedText *aShapedText);
|
||||
|
||||
// Helper to adjust for synthetic bold and set character-type flags
|
||||
// in the shaped text; implementations of ShapeText should call this
|
||||
@ -2166,19 +2164,14 @@ protected:
|
||||
// measurement by mathml code
|
||||
nsAutoPtr<gfxFont> mNonAAFont;
|
||||
|
||||
// we may switch between these shapers on the fly, based on the script
|
||||
// of the text run being shaped
|
||||
nsAutoPtr<gfxFontShaper> mPlatformShaper;
|
||||
// we create either or both of these shapers when needed, depending
|
||||
// whether the font has graphite tables, and whether graphite shaping
|
||||
// is actually enabled
|
||||
nsAutoPtr<gfxFontShaper> mHarfBuzzShaper;
|
||||
nsAutoPtr<gfxFontShaper> mGraphiteShaper;
|
||||
|
||||
mozilla::RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFont;
|
||||
|
||||
// Create a default platform text shaper for this font.
|
||||
// (TODO: This should become pure virtual once all font backends have
|
||||
// been updated.)
|
||||
virtual void CreatePlatformShaper() { }
|
||||
|
||||
// Helper for subclasses that want to initialize standard metrics from the
|
||||
// tables of sfnt (TrueType/OpenType) fonts.
|
||||
// This will use mFUnitsConvFactor if it is already set, else compute it
|
||||
|
@ -8,9 +8,7 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/WindowsVersion.h"
|
||||
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include <algorithm>
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "gfxWindowsPlatform.h"
|
||||
#include "gfxContext.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
@ -52,10 +50,6 @@ gfxGDIFont::gfxGDIFont(GDIFontEntry *aFontEntry,
|
||||
mNeedsBold(aNeedsBold),
|
||||
mScriptCache(nullptr)
|
||||
{
|
||||
if (FontCanSupportGraphite()) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
|
||||
gfxGDIFont::~gfxGDIFont()
|
||||
@ -83,13 +77,12 @@ gfxGDIFont::CopyWithAntialiasOption(AntialiasOption anAAOption)
|
||||
}
|
||||
|
||||
bool
|
||||
gfxGDIFont::ShapeText(gfxContext *aContext,
|
||||
gfxGDIFont::ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText)
|
||||
{
|
||||
if (!mMetrics) {
|
||||
Initialize();
|
||||
@ -108,7 +101,7 @@ gfxGDIFont::ShapeText(gfxContext *aContext,
|
||||
}
|
||||
|
||||
return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
|
||||
aShapedText, aPreferPlatformShaping);
|
||||
aShapedText);
|
||||
}
|
||||
|
||||
const gfxFont::Metrics&
|
||||
|
@ -72,13 +72,12 @@ public:
|
||||
|
||||
protected:
|
||||
/* override to ensure the cairo font is set up properly */
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping);
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText);
|
||||
|
||||
void Initialize(); // creates metrics and Cairo fonts
|
||||
|
||||
|
@ -8,9 +8,7 @@
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
#include "gfxCoreTextShaper.h"
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include <algorithm>
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "gfxPlatformMac.h"
|
||||
#include "gfxContext.h"
|
||||
#include "gfxFontUtils.h"
|
||||
@ -107,13 +105,6 @@ gfxMacFont::gfxMacFont(MacOSFontEntry *aFontEntry, const gfxFontStyle *aFontStyl
|
||||
NS_WARNING(warnBuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (FontCanSupportGraphite()) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
if (FontCanSupportHarfBuzz()) {
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
}
|
||||
|
||||
gfxMacFont::~gfxMacFont()
|
||||
@ -127,29 +118,31 @@ gfxMacFont::~gfxMacFont()
|
||||
}
|
||||
|
||||
bool
|
||||
gfxMacFont::ShapeText(gfxContext *aContext,
|
||||
gfxMacFont::ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText)
|
||||
{
|
||||
if (!mIsValid) {
|
||||
NS_WARNING("invalid font! expect incorrect text rendering");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool requiresAAT =
|
||||
static_cast<MacOSFontEntry*>(GetFontEntry())->RequiresAATLayout();
|
||||
return gfxFont::ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText, requiresAAT);
|
||||
}
|
||||
if (static_cast<MacOSFontEntry*>(GetFontEntry())->RequiresAATLayout()) {
|
||||
if (!mCoreTextShaper) {
|
||||
mCoreTextShaper = new gfxCoreTextShaper(this);
|
||||
}
|
||||
if (mCoreTextShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText)) {
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfxMacFont::CreatePlatformShaper()
|
||||
{
|
||||
mPlatformShaper = new gfxCoreTextShaper(this);
|
||||
return gfxFont::ShapeText(aContext, aText, aOffset, aLength, aScript,
|
||||
aShapedText);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -51,16 +51,13 @@ public:
|
||||
virtual FontType GetType() const { return FONT_TYPE_MAC; }
|
||||
|
||||
protected:
|
||||
virtual void CreatePlatformShaper();
|
||||
|
||||
// override to prefer CoreText shaping with fonts that depend on AAT
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping = false);
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText);
|
||||
|
||||
void InitMetrics();
|
||||
void InitMetricsFromPlatform();
|
||||
@ -76,6 +73,8 @@ protected:
|
||||
|
||||
cairo_font_face_t *mFontFace;
|
||||
|
||||
nsAutoPtr<gfxFontShaper> mCoreTextShaper;
|
||||
|
||||
Metrics mMetrics;
|
||||
uint32_t mSpaceGlyph;
|
||||
};
|
||||
|
@ -20,8 +20,6 @@
|
||||
#include "gfxFT2Utils.h"
|
||||
#include "harfbuzz/hb.h"
|
||||
#include "harfbuzz/hb-ot.h"
|
||||
#include "gfxHarfBuzzShaper.h"
|
||||
#include "gfxGraphiteShaper.h"
|
||||
#include "nsUnicodeProperties.h"
|
||||
#include "nsUnicodeScriptCodes.h"
|
||||
#include "gfxFontconfigUtils.h"
|
||||
@ -663,14 +661,6 @@ public:
|
||||
protected:
|
||||
virtual already_AddRefed<gfxFont> GetSmallCapsFont();
|
||||
|
||||
virtual bool ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping);
|
||||
|
||||
private:
|
||||
gfxFcFont(cairo_scaled_font_t *aCairoFont, gfxFcFontEntry *aFontEntry,
|
||||
const gfxFontStyle *aFontStyle);
|
||||
@ -1564,42 +1554,6 @@ gfxFcFont::GetSmallCapsFont()
|
||||
return font.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
gfxFcFont::ShapeText(gfxContext *aContext,
|
||||
const char16_t *aText,
|
||||
uint32_t aOffset,
|
||||
uint32_t aLength,
|
||||
int32_t aScript,
|
||||
gfxShapedText *aShapedText,
|
||||
bool aPreferPlatformShaping)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if (FontCanSupportGraphite()) {
|
||||
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
||||
if (!mGraphiteShaper) {
|
||||
mGraphiteShaper = new gfxGraphiteShaper(this);
|
||||
}
|
||||
ok = mGraphiteShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!mHarfBuzzShaper) {
|
||||
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
||||
}
|
||||
ok = mHarfBuzzShaper->ShapeText(aContext, aText, aOffset, aLength,
|
||||
aScript, aShapedText);
|
||||
}
|
||||
|
||||
NS_WARN_IF_FALSE(ok, "shaper failed, expect scrambled or missing text");
|
||||
|
||||
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
gfxPangoFontGroup::Shutdown()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user