From 52ccba88763cd6a82604230b1f89bf955f3a086a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Str=C3=A1nsk=C3=BD?= Date: Wed, 17 Dec 2008 13:44:32 +1300 Subject: [PATCH] b=403513 bad kerning in print output if hinting is set to medium or full r=karlt sr=vlad --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 6 +++++- gfx/src/thebes/nsThebesDeviceContext.cpp | 6 ++++++ gfx/src/thebes/nsThebesDeviceContext.h | 2 ++ gfx/src/thebes/nsThebesFontMetrics.cpp | 4 +++- gfx/thebes/public/gfxFont.h | 7 ++++++- gfx/thebes/src/gfxFont.cpp | 11 +++++----- gfx/thebes/src/gfxPangoFonts.cpp | 21 ++++++++++++++----- layout/svg/base/src/nsSVGGlyphFrame.cpp | 5 ++++- 8 files changed, 48 insertions(+), 14 deletions(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 89c6bce36a1..73618a55050 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -1967,13 +1967,17 @@ nsCanvasRenderingContext2D::SetFont(const nsAString& font) // un-zoom the font size to avoid being affected by text-only zoom const nscoord fontSize = nsStyleFont::UnZoomText(parentContext->PresContext(), fontStyle->mFont.size); + PRBool printerFont = (presShell->GetPresContext()->Type() == nsPresContext::eContext_PrintPreview || + presShell->GetPresContext()->Type() == nsPresContext::eContext_Print); + gfxFontStyle style(fontStyle->mFont.style, fontStyle->mFont.weight, NSAppUnitsToFloatPixels(fontSize, aupcp), langGroup, fontStyle->mFont.sizeAdjust, fontStyle->mFont.systemFont, - fontStyle->mFont.familyNameQuirks); + fontStyle->mFont.familyNameQuirks, + printerFont); CurrentState().fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(fontStyle->mFont.name, &style, presShell->GetPresContext()->GetUserFontSet()); NS_ASSERTION(CurrentState().fontGroup, "Could not get font group"); diff --git a/gfx/src/thebes/nsThebesDeviceContext.cpp b/gfx/src/thebes/nsThebesDeviceContext.cpp index f0b94587656..19803875ba4 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -148,6 +148,12 @@ nsThebesDeviceContext::Shutdown() gSystemFonts = nsnull; } +PRBool +nsThebesDeviceContext::IsPrinterSurface() +{ + return(mPrintingSurface != NULL); +} + nsresult nsThebesDeviceContext::SetDPI() { diff --git a/gfx/src/thebes/nsThebesDeviceContext.h b/gfx/src/thebes/nsThebesDeviceContext.h index 629c2ac6c03..e6bdc827459 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.h +++ b/gfx/src/thebes/nsThebesDeviceContext.h @@ -118,6 +118,8 @@ public: virtual PRBool SetPixelScale(float aScale); + PRBool IsPrinterSurface(void); + nsNativeWidget GetWidget() { return mWidget; } #if defined(XP_WIN) || defined(XP_OS2) HDC GetPrintHDC(); diff --git a/gfx/src/thebes/nsThebesFontMetrics.cpp b/gfx/src/thebes/nsThebesFontMetrics.cpp index ce6a494eeeb..e2b5a70be7a 100644 --- a/gfx/src/thebes/nsThebesFontMetrics.cpp +++ b/gfx/src/thebes/nsThebesFontMetrics.cpp @@ -83,9 +83,11 @@ nsThebesFontMetrics::Init(const nsFont& aFont, nsIAtom* aLangGroup, langGroup.Assign(lg); } + PRBool printerFont = mDeviceContext->IsPrinterSurface(); mFontStyle = new gfxFontStyle(aFont.style, aFont.weight, size, langGroup, aFont.sizeAdjust, aFont.systemFont, - aFont.familyNameQuirks); + aFont.familyNameQuirks, + printerFont); mFontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(aFont.name, mFontStyle, diff --git a/gfx/thebes/public/gfxFont.h b/gfx/thebes/public/gfxFont.h index f4b10be6af6..2b7de9b3a1a 100644 --- a/gfx/thebes/public/gfxFont.h +++ b/gfx/thebes/public/gfxFont.h @@ -78,7 +78,8 @@ struct THEBES_API gfxFontStyle { gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize, const nsACString& aLangGroup, float aSizeAdjust, PRPackedBool aSystemFont, - PRPackedBool aFamilyNameQuirks); + PRPackedBool aFamilyNameQuirks, + PRPackedBool aPrinterFont); gfxFontStyle(const gfxFontStyle& aStyle); // The style of font (normal, italic, oblique) @@ -89,6 +90,9 @@ struct THEBES_API gfxFontStyle { // sources. PRPackedBool systemFont : 1; + // Say that this font is used for print or print preview. + PRPackedBool printerFont : 1; + // True if the character set quirks (for treatment of "Symbol", // "Wingdings", etc.) should be applied. PRPackedBool familyNameQuirks : 1; @@ -133,6 +137,7 @@ struct THEBES_API gfxFontStyle { return (size == other.size) && (style == other.style) && (systemFont == other.systemFont) && + (printerFont == other.printerFont) && (familyNameQuirks == other.familyNameQuirks) && (weight == other.weight) && (langGroup.Equals(other.langGroup)) && diff --git a/gfx/thebes/src/gfxFont.cpp b/gfx/thebes/src/gfxFont.cpp index 9d80e2175c2..b5ec902a92d 100644 --- a/gfx/thebes/src/gfxFont.cpp +++ b/gfx/thebes/src/gfxFont.cpp @@ -1227,8 +1227,8 @@ gfxFontGroup::GetGeneration() #define DEFAULT_PIXEL_FONT_SIZE 16.0f gfxFontStyle::gfxFontStyle() : - style(FONT_STYLE_NORMAL), systemFont(PR_TRUE), familyNameQuirks(PR_FALSE), - weight(FONT_WEIGHT_NORMAL), size(DEFAULT_PIXEL_FONT_SIZE), + style(FONT_STYLE_NORMAL), systemFont(PR_TRUE), printerFont(PR_FALSE), + familyNameQuirks(PR_FALSE), weight(FONT_WEIGHT_NORMAL), size(DEFAULT_PIXEL_FONT_SIZE), langGroup(NS_LITERAL_CSTRING("x-western")), sizeAdjust(0.0f) { } @@ -1236,8 +1236,9 @@ gfxFontStyle::gfxFontStyle() : gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize, const nsACString& aLangGroup, float aSizeAdjust, PRPackedBool aSystemFont, - PRPackedBool aFamilyNameQuirks) : - style(aStyle), systemFont(aSystemFont), + PRPackedBool aFamilyNameQuirks, + PRPackedBool aPrinterFont): + style(aStyle), systemFont(aSystemFont), printerFont(aPrinterFont), familyNameQuirks(aFamilyNameQuirks), weight(aWeight), size(aSize), langGroup(aLangGroup), sizeAdjust(aSizeAdjust) { @@ -1261,7 +1262,7 @@ gfxFontStyle::gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize, } gfxFontStyle::gfxFontStyle(const gfxFontStyle& aStyle) : - style(aStyle.style), systemFont(aStyle.systemFont), + style(aStyle.style), systemFont(aStyle.systemFont), printerFont(aStyle.printerFont), familyNameQuirks(aStyle.familyNameQuirks), weight(aStyle.weight), size(aStyle.size), langGroup(aStyle.langGroup), sizeAdjust(aStyle.sizeAdjust) diff --git a/gfx/thebes/src/gfxPangoFonts.cpp b/gfx/thebes/src/gfxPangoFonts.cpp index bfafb65b8bb..41ceb8edcb4 100644 --- a/gfx/thebes/src/gfxPangoFonts.cpp +++ b/gfx/thebes/src/gfxPangoFonts.cpp @@ -1712,7 +1712,7 @@ static void ApplyGdkScreenFontOptions(FcPattern *aPattern); // Apply user settings and defaults to pattern in preparation for matching. static void PrepareSortPattern(FcPattern *aPattern, double aFallbackSize, - double aSizeAdjustFactor) + double aSizeAdjustFactor, PRBool aIsPrinterFont) { FcConfigSubstitute(NULL, aPattern, FcMatchPattern); @@ -1728,8 +1728,17 @@ PrepareSortPattern(FcPattern *aPattern, double aFallbackSize, // Using an xlib surface would also be an option to get Screen font // options for non-GTK X11 toolkits, but less efficient than using GDK to // pick up dynamic changes. + if(aIsPrinterFont) { + cairo_font_options_t *options = cairo_font_options_create(); + cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_GRAY); + cairo_ft_font_options_substitute(options, aPattern); + cairo_font_options_destroy(options); + } #ifdef MOZ_WIDGET_GTK2 - ApplyGdkScreenFontOptions(aPattern); + else { + ApplyGdkScreenFontOptions(aPattern); + } #endif // Protect against any fontconfig settings that may have incorrectly @@ -1752,7 +1761,9 @@ gfx_pango_font_map_context_substitute(PangoFcFontMap *fontmap, // owned by the context PangoFontDescription *desc = pango_context_get_font_description(context); double size = pango_font_description_get_size(desc) / FLOAT_PANGO_SCALE; - PrepareSortPattern(pattern, size, 1.0); + gfxPangoFontGroup *fontGroup = GetFontGroup(context); + PRBool usePrinterFont = fontGroup && fontGroup->GetStyle()->printerFont; + PrepareSortPattern(pattern, size, 1.0, usePrinterFont); } static PangoFcFont * @@ -1968,7 +1979,7 @@ gfxPangoFontGroup::MakeFontSet(PangoLanguage *aLang, gfxFloat aSizeAdjustFactor, nsAutoRef pattern (gfxFontconfigUtils::NewPattern(fcFamilyList, mStyle, lang)); - PrepareSortPattern(pattern, mStyle.size, aSizeAdjustFactor); + PrepareSortPattern(pattern, mStyle.size, aSizeAdjustFactor, mStyle.printerFont); nsRefPtr fontset = new gfxFcPangoFontSet(pattern, mUserFontSet); @@ -2144,7 +2155,7 @@ gfxFcFont::GetOrMakeFont(FcPattern *aPattern) // string through FcNameUnparse() is more trouble than it's worth. NS_NAMED_LITERAL_CSTRING(langGroup, "x-unicode"); gfxFontStyle fontStyle(style, weight, size, langGroup, 0.0, - PR_TRUE, PR_FALSE); + PR_TRUE, PR_FALSE, PR_FALSE); nsRefPtr fe; FcChar8 *fc_file; diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index f1c5b9e3b86..42656353a23 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -1263,9 +1263,12 @@ nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale, } const nsFont& font = fontData->mFont; + PRBool printerFont = (presContext->Type() == nsPresContext::eContext_PrintPreview || + presContext->Type() == nsPresContext::eContext_Print); gfxFontStyle fontStyle(font.style, font.weight, textRunSize, langGroup, font.sizeAdjust, font.systemFont, - font.familyNameQuirks); + font.familyNameQuirks, + printerFont); nsRefPtr fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(font.name, &fontStyle, presContext->GetUserFontSet());