From a54d0815c23258067412055ec82a507f622280a0 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 4 Aug 2023 00:41:14 +0000 Subject: [PATCH 1/5] re-add qt-specific text transforms --- Source/WebCore/platform/graphics/Font.cpp | 2 +- Source/WebCore/platform/graphics/qt/FontQt.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/WebCore/platform/graphics/Font.cpp b/Source/WebCore/platform/graphics/Font.cpp index b481122c9c681..abcc5cc023468 100644 --- a/Source/WebCore/platform/graphics/Font.cpp +++ b/Source/WebCore/platform/graphics/Font.cpp @@ -549,7 +549,7 @@ RefPtr Font::createScaledFont(const FontDescription& fontDescription, floa return platformCreateScaledFont(fontDescription, scaleFactor); } -#if !USE(CORE_TEXT) +#if !USE(CORE_TEXT) && !PLATFORM(QT) GlyphBufferAdvance Font::applyTransforms(GlyphBuffer&, unsigned, unsigned, bool, bool, const AtomString&, StringView, TextDirection) const { return makeGlyphBufferAdvance(); diff --git a/Source/WebCore/platform/graphics/qt/FontQt.cpp b/Source/WebCore/platform/graphics/qt/FontQt.cpp index f6e3273d33c17..2b40e10dad3a6 100644 --- a/Source/WebCore/platform/graphics/qt/FontQt.cpp +++ b/Source/WebCore/platform/graphics/qt/FontQt.cpp @@ -59,6 +59,14 @@ FloatRect Font::platformBoundsForGlyph(Glyph glyph) const return m_platformData.rawFont().boundingRect(glyph); } +GlyphBufferAdvance Font::applyTransforms(GlyphBuffer& glyphBuffer, unsigned beginningGlyphIndex, unsigned beginningStringIndex, bool enableKerning, bool, const AtomString&, StringView, TextDirection) const +{ + QRawFont::LayoutFlags flags = enableKerning ? QRawFont::KernedAdvances : QRawFont::SeparateAdvances; + m_platformData.rawFont().advancesForGlyphIndexes(reinterpret_cast(glyphBuffer.glyphs(beginningGlyphIndex)), glyphBuffer.advances(beginningGlyphIndex), glyphBuffer.size(), flags); + + return makeGlyphBufferAdvance(); +} + void Font::platformInit() { if (!m_platformData.size()) { From 3b9591d8181dc5d32cd7c2599e4b303af07a59e3 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 4 Aug 2023 00:41:50 +0000 Subject: [PATCH 2/5] remove qt guards around advanced text rendering --- Source/WebCore/platform/graphics/FontCascade.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/WebCore/platform/graphics/FontCascade.h b/Source/WebCore/platform/graphics/FontCascade.h index 452cb40b89d4d..a992fbf7a1924 100644 --- a/Source/WebCore/platform/graphics/FontCascade.h +++ b/Source/WebCore/platform/graphics/FontCascade.h @@ -307,17 +307,7 @@ class FontCascade : public CanMakeWeakPtr { bool advancedTextRenderingMode() const { -#if PLATFORM(QT) - auto textRenderingMode = m_fontDescription.textRenderingMode(); - if (textRenderingMode == TextRenderingMode::GeometricPrecision || textRenderingMode == TextRenderingMode::OptimizeLegibility) - return true; - if (textRenderingMode == TextRenderingMode::OptimizeSpeed) - return false; - - return false; -#else return m_fontDescription.textRenderingMode() != TextRenderingMode::OptimizeSpeed; -#endif } bool computeEnableKerning() const From 3ab9a0cbbf848d3825d5a9c21f4d872350ed3f59 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 4 Aug 2023 00:42:16 +0000 Subject: [PATCH 3/5] Ensure drawGlyph advances on a newline Newlines are rendered as whitespace. The layout engine gets this right, but the glyph that is used for newline is 0. In the paint phase, if we came across a 0 glyph we bailed, even though that glyph contained an advance. We should always advance. --- Source/WebCore/platform/graphics/qt/FontCascadeQt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/WebCore/platform/graphics/qt/FontCascadeQt.cpp b/Source/WebCore/platform/graphics/qt/FontCascadeQt.cpp index 37182118e9b86..f347f9bcdeb3b 100644 --- a/Source/WebCore/platform/graphics/qt/FontCascadeQt.cpp +++ b/Source/WebCore/platform/graphics/qt/FontCascadeQt.cpp @@ -312,8 +312,12 @@ void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const G for (int i = 0; i < numGlyphs; ++i) { Glyph glyph = glyphs[i]; float advance = advances[i].x(); - if (!glyph) + + if (!glyph) { + width += advance; continue; + } + glyphIndexes.append(glyph); positions.append(QPointF(width, 0)); width += advance; From 2169b50f013f44c8149e345d95b1c8d091b99911 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 4 Aug 2023 01:25:12 +0000 Subject: [PATCH 4/5] fixme: need to treat newline like a space --- Source/WebCore/platform/graphics/FontCascadeFonts.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/WebCore/platform/graphics/FontCascadeFonts.cpp b/Source/WebCore/platform/graphics/FontCascadeFonts.cpp index 4d86c25f45e16..31af7f3702ebb 100644 --- a/Source/WebCore/platform/graphics/FontCascadeFonts.cpp +++ b/Source/WebCore/platform/graphics/FontCascadeFonts.cpp @@ -495,6 +495,9 @@ GlyphData FontCascadeFonts::glyphDataForCharacter(UChar32 c, const FontCascadeDe ASSERT(m_thread ? m_thread->ptr() == &Thread::current() : isMainThread()); ASSERT(variant != AutoVariant); + if (c == 10) // newline + c = space; + if (variant != NormalVariant) return glyphDataForVariant(c, description, variant); From 1cc87f2893545f17e54a11501c973eded1004593 Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Fri, 4 Aug 2023 20:38:26 +0000 Subject: [PATCH 5/5] revert qt-specific transforms code --- Source/WebCore/platform/graphics/Font.cpp | 2 +- Source/WebCore/platform/graphics/qt/FontQt.cpp | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Source/WebCore/platform/graphics/Font.cpp b/Source/WebCore/platform/graphics/Font.cpp index abcc5cc023468..b481122c9c681 100644 --- a/Source/WebCore/platform/graphics/Font.cpp +++ b/Source/WebCore/platform/graphics/Font.cpp @@ -549,7 +549,7 @@ RefPtr Font::createScaledFont(const FontDescription& fontDescription, floa return platformCreateScaledFont(fontDescription, scaleFactor); } -#if !USE(CORE_TEXT) && !PLATFORM(QT) +#if !USE(CORE_TEXT) GlyphBufferAdvance Font::applyTransforms(GlyphBuffer&, unsigned, unsigned, bool, bool, const AtomString&, StringView, TextDirection) const { return makeGlyphBufferAdvance(); diff --git a/Source/WebCore/platform/graphics/qt/FontQt.cpp b/Source/WebCore/platform/graphics/qt/FontQt.cpp index 2b40e10dad3a6..f6e3273d33c17 100644 --- a/Source/WebCore/platform/graphics/qt/FontQt.cpp +++ b/Source/WebCore/platform/graphics/qt/FontQt.cpp @@ -59,14 +59,6 @@ FloatRect Font::platformBoundsForGlyph(Glyph glyph) const return m_platformData.rawFont().boundingRect(glyph); } -GlyphBufferAdvance Font::applyTransforms(GlyphBuffer& glyphBuffer, unsigned beginningGlyphIndex, unsigned beginningStringIndex, bool enableKerning, bool, const AtomString&, StringView, TextDirection) const -{ - QRawFont::LayoutFlags flags = enableKerning ? QRawFont::KernedAdvances : QRawFont::SeparateAdvances; - m_platformData.rawFont().advancesForGlyphIndexes(reinterpret_cast(glyphBuffer.glyphs(beginningGlyphIndex)), glyphBuffer.advances(beginningGlyphIndex), glyphBuffer.size(), flags); - - return makeGlyphBufferAdvance(); -} - void Font::platformInit() { if (!m_platformData.size()) {