From af4b0389ed3a49818007f2c6f7542556432aac53 Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Thu, 22 Mar 2007 23:07:18 +0000 Subject: [PATCH] Bug 374720. Minor gfx changes to support new textframe work. r=pavlov git-svn-id: svn://10.0.0.236/trunk@222209 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/thebes/public/gfxAtsuiFonts.h | 6 +-- mozilla/gfx/thebes/public/gfxFont.h | 60 +++++++++++---------- mozilla/gfx/thebes/public/gfxWindowsFonts.h | 6 +-- mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp | 6 +++ mozilla/gfx/thebes/src/gfxFont.cpp | 13 ++--- mozilla/gfx/thebes/src/gfxPangoFonts.cpp | 2 +- mozilla/gfx/thebes/src/gfxWindowsFonts.cpp | 6 +++ 7 files changed, 57 insertions(+), 42 deletions(-) diff --git a/mozilla/gfx/thebes/public/gfxAtsuiFonts.h b/mozilla/gfx/thebes/public/gfxAtsuiFonts.h index 3ef2cabd6d1..c2e62e8a019 100644 --- a/mozilla/gfx/thebes/public/gfxAtsuiFonts.h +++ b/mozilla/gfx/thebes/public/gfxAtsuiFonts.h @@ -95,10 +95,8 @@ public: const gfxFontStyle *aStyle); virtual ~gfxAtsuiFontGroup(); - virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle) { - NS_ERROR("NOT IMPLEMENTED"); - return nsnull; - } + virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); + virtual gfxTextRun *MakeTextRun(const PRUnichar* aString, PRUint32 aLength, Parameters* aParams); virtual gfxTextRun *MakeTextRun(const PRUint8* aString, PRUint32 aLength, diff --git a/mozilla/gfx/thebes/public/gfxFont.h b/mozilla/gfx/thebes/public/gfxFont.h index 9fb9e46f754..29826cea854 100644 --- a/mozilla/gfx/thebes/public/gfxFont.h +++ b/mozilla/gfx/thebes/public/gfxFont.h @@ -417,7 +417,7 @@ public: * to handle some unusual situation. So gfxTextRuns have two modes: "not * remembering text" (initial state) and "remembering text". A call to * gfxTextRun::RememberText forces a transition from the former to latter state. - * The text is never forgotten. A gfxTextRun call that receives a TextProvider + * The text is never forgotten. A gfxTextRun call that receives a PropertyProvider * object may call ForceRememberText to request a transition to "remembering text". * * It is important that zero-length substrings are handled correctly. This will @@ -466,7 +466,7 @@ public: /** * This can be called to force gfxTextRun to remember the text used - * to create it and *never* call TextProvider::GetText again. + * to create it and *never* call PropertyProvider::GetText again. * * Right now we don't implement these. */ @@ -478,28 +478,15 @@ public: * the "allow break before" points. Initially, there are no potential * linebreaks. * + * This can change glyphs and/or geometry! Some textruns' shapes + * depend on potential line breaks (e.g., title-case-converting textruns). + * This function is virtual so that those textruns can reshape themselves. + * * @return true if this changed the linebreaks, false if the new line * breaks are the same as the old */ - PRBool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength, - PRPackedBool *aBreakBefore); - - /** - * This is provided so a textrun can (re)obtain the original text used to - * construct it, if necessary. - */ - class TextProvider { - public: - /** - * Recover the text originally used to build the textrun. This should - * only be requested infrequently as it may be slow. If you need to - * call it a lot you should probably be saving the text in the text run - * itself. It just forces the textrun user to call RememberText on the - * text run. If you call this and RememberText doesn't get called, - * then something has failed and you should handle it. - */ - virtual void ForceRememberText() = 0; - }; + virtual PRBool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength, + PRPackedBool *aBreakBefore); /** * Layout provides PropertyProvider objects. These allow detection of @@ -511,8 +498,18 @@ public: * is unable to apply it in some context. Exception: spacing around a * whitespace character MUST always be applied. */ - class PropertyProvider : public TextProvider { + class PropertyProvider { public: + /** + * Recover the text originally used to build the textrun. This should + * only be requested infrequently as it may be slow. If you need to + * call it a lot you should probably be saving the text in the text run + * itself. It just forces the textrun user to call RememberText on the + * text run. If you call this and RememberText doesn't get called, + * then something has failed and you should handle it. + */ + virtual void ForceRememberText() = 0; + // Detect hyphenation break opportunities in the given range; breaks // not at cluster boundaries will be ignored. virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength, @@ -620,13 +617,17 @@ public: * alter nsTextFrame::TrimTrailingWhitespace, perhaps drastically becase * it could affect the layout of frames before it...) * + * We return true if glyphs or geometry changed, false otherwise. This + * function is virtual so that gfxTextRun subclasses can reshape + * properly. + * * @param aAdvanceWidthDelta if non-null, returns the change in advance * width of the given range. */ - void SetLineBreaks(PRUint32 aStart, PRUint32 aLength, - PRBool aLineBreakBefore, PRBool aLineBreakAfter, - TextProvider *aProvider, - gfxFloat *aAdvanceWidthDelta); + virtual PRBool SetLineBreaks(PRUint32 aStart, PRUint32 aLength, + PRBool aLineBreakBefore, PRBool aLineBreakAfter, + PropertyProvider *aProvider, + gfxFloat *aAdvanceWidthDelta); /** * Finds the longest substring that will fit into the given width. @@ -867,6 +868,7 @@ public: * only during initialization when font substitution has been computed. */ nsresult AddGlyphRun(gfxFont *aFont, PRUint32 aStartCharIndex); + void ResetGlyphRuns() { mGlyphRuns.Clear(); } // Call the following glyph-setters during initialization or during reshaping // only. It is OK to overwrite existing data for a character. /** @@ -888,7 +890,7 @@ public: * Set some detailed glyphs for a character. The data is copied from aGlyphs, * the caller retains ownership. */ - void SetDetailedGlyphs(PRUint32 aCharIndex, DetailedGlyph *aGlyphs, + void SetDetailedGlyphs(PRUint32 aCharIndex, const DetailedGlyph *aGlyphs, PRUint32 aNumGlyphs); // API for access to the raw glyph data, needed by gfxFont::Draw @@ -901,6 +903,10 @@ public: return mDetailedGlyphs[aCharIndex]; } PRUint32 CountMissingGlyphs(); + const GlyphRun *GetGlyphRuns(PRUint32 *aNumGlyphRuns) { + *aNumGlyphRuns = mGlyphRuns.Length(); + return mGlyphRuns.Elements(); + } private: // **** general helpers **** diff --git a/mozilla/gfx/thebes/public/gfxWindowsFonts.h b/mozilla/gfx/thebes/public/gfxWindowsFonts.h index 2d3e20e13f6..c9e6b40c08b 100644 --- a/mozilla/gfx/thebes/public/gfxWindowsFonts.h +++ b/mozilla/gfx/thebes/public/gfxWindowsFonts.h @@ -426,10 +426,8 @@ public: gfxWindowsFontGroup(const nsAString& aFamilies, const gfxFontStyle* aStyle); virtual ~gfxWindowsFontGroup(); - virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle) { - NS_ERROR("NOT IMPLEMENTED"); - return nsnull; - } + virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); + virtual gfxTextRun *MakeTextRun(const PRUnichar* aString, PRUint32 aLength, Parameters* aParams); virtual gfxTextRun *MakeTextRun(const PRUint8* aString, PRUint32 aLength, diff --git a/mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp b/mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp index afd8bef16e3..2c7d2e2be9c 100644 --- a/mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/mozilla/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -342,6 +342,12 @@ gfxAtsuiFontGroup::~gfxAtsuiFontGroup() ATSUDisposeFontFallbacks(mFallbacks); } +gfxFontGroup * +gfxAtsuiFontGroup::Copy(const gfxFontStyle *aStyle) +{ + return new gfxAtsuiFontGroup(mFamilies, aStyle); +} + static void SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString, PRUint32 aLength) { diff --git a/mozilla/gfx/thebes/src/gfxFont.cpp b/mozilla/gfx/thebes/src/gfxFont.cpp index e422cd7d166..c3fab805c24 100644 --- a/mozilla/gfx/thebes/src/gfxFont.cpp +++ b/mozilla/gfx/thebes/src/gfxFont.cpp @@ -162,8 +162,9 @@ gfxFont::Measure(gfxTextRun *aTextRun, Spacing *aSpacing) { // XXX temporary code, does not handle glyphs outside the font-box - NS_ASSERTION(!(aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX), - "Glyph extents not yet supported"); + // XXX comment out the assertion for now since it fires too much + // NS_ASSERTION(!(aTextRun->GetFlags() & gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX), + // "Glyph extents not yet supported"); PRInt32 advance = 0; PRUint32 i; const gfxTextRun::CompressedGlyph *charGlyphs = aTextRun->GetCharacterGlyphs(); @@ -1244,11 +1245,10 @@ gfxTextRun::GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength, return result; } - -void +PRBool gfxTextRun::SetLineBreaks(PRUint32 aStart, PRUint32 aLength, PRBool aLineBreakBefore, PRBool aLineBreakAfter, - TextProvider *aProvider, + PropertyProvider *aProvider, gfxFloat *aAdvanceWidthDelta) { // Do nothing because our shaping does not currently take linebreaks into @@ -1256,6 +1256,7 @@ gfxTextRun::SetLineBreaks(PRUint32 aStart, PRUint32 aLength, if (aAdvanceWidthDelta) { *aAdvanceWidthDelta = 0; } + return PR_FALSE; } PRUint32 @@ -1307,7 +1308,7 @@ gfxTextRun::CountMissingGlyphs() } void -gfxTextRun::SetDetailedGlyphs(PRUint32 aIndex, DetailedGlyph *aGlyphs, +gfxTextRun::SetDetailedGlyphs(PRUint32 aIndex, const DetailedGlyph *aGlyphs, PRUint32 aCount) { NS_ASSERTION(aCount > 0, "Can't set zero detailed glyphs"); diff --git a/mozilla/gfx/thebes/src/gfxPangoFonts.cpp b/mozilla/gfx/thebes/src/gfxPangoFonts.cpp index 6ecbef37778..bcc5ff94654 100644 --- a/mozilla/gfx/thebes/src/gfxPangoFonts.cpp +++ b/mozilla/gfx/thebes/src/gfxPangoFonts.cpp @@ -783,7 +783,7 @@ gfxPangoFont::Measure(gfxTextRun *aTextRun, PRUint32 leftSpacePango = 0; PRUint32 rightSpacePango = 0; if (aSpacing) { - gfxTextRun::PropertyProvider::Spacing *space = &aSpacing[i]; + gfxTextRun::PropertyProvider::Spacing *space = &aSpacing[i - aStart]; leftSpacePango = NS_lround((isRTL ? space->mAfter : space->mBefore)*appUnitsToPango); rightSpacePango = diff --git a/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp b/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp index 72d10c19321..b168d68b73a 100644 --- a/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp +++ b/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp @@ -536,6 +536,12 @@ gfxWindowsFontGroup::~gfxWindowsFontGroup() { } +gfxFontGroup * +gfxWindowsFontGroup::Copy(const gfxFontStyle *aStyle) +{ + return new gfxWindowsFontGroup(mFamilies, aStyle); +} + gfxTextRun * gfxWindowsFontGroup::MakeTextRun(const PRUnichar *aString, PRUint32 aLength, Parameters *aParams)