From e5a7a74a5d03815d74f21d2e3c78199cf9eb3086 Mon Sep 17 00:00:00 2001 From: "mitz@apple.com" Date: Thu, 1 May 2008 23:10:36 +0000 Subject: [PATCH] Reviewed by Darin Adler. - make synthetic bold and synthetic italics work in GDI text - account for synthetic bold in complex text on Windows * platform/graphics/win/FontCGWin.cpp: (WebCore::Font::drawGlyphs): Adjusted the text rectangle's x coordinates to fit italics. Added a skew transform for synthetic italics and a second paint pass for synthetic bold. * platform/graphics/win/SimpleFontDataWin.cpp: (WebCore::SimpleFontData::widthForGDIGlyph): Added the synthetic bold offset. * platform/graphics/win/UniscribeController.cpp: (WebCore::UniscribeController::shapeAndPlaceItem): Added the synthetic bold offset. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@32781 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 18 +++++++++ WebCore/platform/graphics/win/FontCGWin.cpp | 40 ++++++++++++++++--- .../graphics/win/SimpleFontDataWin.cpp | 2 +- .../graphics/win/UniscribeController.cpp | 4 +- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 40848cad25b..bc05508b2a1 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,21 @@ +2008-05-01 Dan Bernstein + + Reviewed by Darin Adler. + + - make synthetic bold and synthetic italics work in GDI text + - account for synthetic bold in complex text on Windows + + * platform/graphics/win/FontCGWin.cpp: + (WebCore::Font::drawGlyphs): Adjusted the text rectangle's x coordinates + to fit italics. Added a skew transform for synthetic italics and a + second paint pass for synthetic bold. + * platform/graphics/win/SimpleFontDataWin.cpp: + (WebCore::SimpleFontData::widthForGDIGlyph): Added the synthetic bold + offset. + * platform/graphics/win/UniscribeController.cpp: + (WebCore::UniscribeController::shapeAndPlaceItem): Added the synthetic + bold offset. + 2008-05-01 Alp Toker Qt/Win build fix attempt following plugin changes. Add missing return diff --git a/WebCore/platform/graphics/win/FontCGWin.cpp b/WebCore/platform/graphics/win/FontCGWin.cpp index 30f0bda100d..d29b23201bc 100644 --- a/WebCore/platform/graphics/win/FontCGWin.cpp +++ b/WebCore/platform/graphics/win/FontCGWin.cpp @@ -164,9 +164,8 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo drawIntoBitmap = true; // We put slop into this rect, since glyphs can overflow the ascent/descent bounds and the left/right edges. // FIXME: Can get glyphs' optical bounds (even from CG) to get this right. - // FIXME: Line gap does not make sense as a horizontal distance. int lineGap = font->lineGap(); - textRect = IntRect(point.x() - lineGap, point.y() - font->ascent() - lineGap, totalWidth + 2 * lineGap, font->lineSpacing()); + textRect = IntRect(point.x() - (font->ascent() + font->descent()) / 2, point.y() - font->ascent() - lineGap, totalWidth + font->ascent() + font->descent(), font->lineSpacing()); bitmap.set(graphicsContext->createWindowsBitmap(textRect.size())); memset(bitmap->buffer(), 255, bitmap->bufferLength()); hdc = bitmap->hdc(); @@ -205,15 +204,32 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY); } - if (drawingMode == cTextFill) - ExtTextOut(hdc, point.x(), point.y(), ETO_GLYPH_INDEX, 0, (WCHAR*)glyphBuffer.glyphs(from), numGlyphs, gdiAdvances.data()); - else { + if (drawingMode == cTextFill) { + XFORM xform; + xform.eM11 = 1.0; + xform.eM12 = 0; + xform.eM21 = font->platformData().syntheticOblique() ? -tanf(syntheticObliqueAngle * piFloat / 180.0f) : 0; + xform.eM22 = 1.0; + xform.eDx = point.x(); + xform.eDy = point.y(); + ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY); + ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data()); + if (font->m_syntheticBoldOffset) { + xform.eM21 = 0; + xform.eDx = font->m_syntheticBoldOffset; + xform.eDy = 0; + ModifyWorldTransform(hdc, &xform, MWT_LEFTMULTIPLY); + ExtTextOut(hdc, 0, 0, ETO_GLYPH_INDEX, 0, reinterpret_cast(glyphBuffer.glyphs(from)), numGlyphs, gdiAdvances.data()); + } + } else { RetainPtr path(AdoptCF, CGPathCreateMutable()); XFORM xform; GetWorldTransform(hdc, &xform); AffineTransform hdcTransform(xform.eM11, xform.eM21, xform.eM12, xform.eM22, xform.eDx, xform.eDy); CGAffineTransform initialGlyphTransform = hdcTransform.isInvertible() ? hdcTransform.inverse() : CGAffineTransformIdentity; + if (font->platformData().syntheticOblique()) + initialGlyphTransform = CGAffineTransformConcat(initialGlyphTransform, CGAffineTransformMake(1, 0, tanf(syntheticObliqueAngle * piFloat / 180.0f), 1, 0, 0)); initialGlyphTransform.tx = 0; initialGlyphTransform.ty = 0; CGAffineTransform glyphTranslation = CGAffineTransformIdentity; @@ -238,10 +254,22 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo if (drawingMode & cTextFill) { CGContextAddPath(cgContext, path.get()); CGContextFillPath(cgContext); + if (font->m_syntheticBoldOffset) { + CGContextTranslateCTM(cgContext, font->m_syntheticBoldOffset, 0); + CGContextAddPath(cgContext, path.get()); + CGContextFillPath(cgContext); + CGContextTranslateCTM(cgContext, -font->m_syntheticBoldOffset, 0); + } } if (drawingMode & cTextStroke) { CGContextAddPath(cgContext, path.get()); CGContextStrokePath(cgContext); + if (font->m_syntheticBoldOffset) { + CGContextTranslateCTM(cgContext, font->m_syntheticBoldOffset, 0); + CGContextAddPath(cgContext, path.get()); + CGContextStrokePath(cgContext); + CGContextTranslateCTM(cgContext, -font->m_syntheticBoldOffset, 0); + } } CGContextRestoreGState(cgContext); } @@ -277,7 +305,7 @@ void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* fo matrix.d = -matrix.d; if (platformData.syntheticOblique()) { - static float skew = -tanf(syntheticObliqueAngle * acosf(0) / 90.0f); + static float skew = -tanf(syntheticObliqueAngle * piFloat / 180.0f); matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, skew, 1, 0, 0)); } diff --git a/WebCore/platform/graphics/win/SimpleFontDataWin.cpp b/WebCore/platform/graphics/win/SimpleFontDataWin.cpp index de191b5412e..0e9f9fb8f5e 100644 --- a/WebCore/platform/graphics/win/SimpleFontDataWin.cpp +++ b/WebCore/platform/graphics/win/SimpleFontDataWin.cpp @@ -181,7 +181,7 @@ float SimpleFontData::widthForGDIGlyph(Glyph glyph) const GetCharWidthI(hdc, glyph, 1, 0, &width); SelectObject(hdc, oldFont); ReleaseDC(0, hdc); - return width; + return width + m_syntheticBoldOffset; } SCRIPT_FONTPROPERTIES* SimpleFontData::scriptFontProperties() const diff --git a/WebCore/platform/graphics/win/UniscribeController.cpp b/WebCore/platform/graphics/win/UniscribeController.cpp index 849636922db..9019317bec5 100644 --- a/WebCore/platform/graphics/win/UniscribeController.cpp +++ b/WebCore/platform/graphics/win/UniscribeController.cpp @@ -299,7 +299,9 @@ bool UniscribeController::shapeAndPlaceItem(const UChar* cp, unsigned i, const S offsetX = roundf(offsetX); offsetY = roundf(offsetY); } - + + advance += fontData->m_syntheticBoldOffset; + // We special case spaces in two ways when applying word rounding. // First, we round spaces to an adjusted width in all fonts. // Second, in fixed-pitch fonts we ensure that all glyphs that -- GitLab