Changeset 251900 in webkit


Ignore:
Timestamp:
Oct 31, 2019 5:53:49 PM (4 years ago)
Author:
Brent Fulgham
Message:

[FTW] Adopt DirectWrite in place of Uniscribe
https://bugs.webkit.org/show_bug.cgi?id=203548
<rdar://problem/56695130>

Reviewed by Fujii Hironori.

This patch switches from the Uniscribe text controller to a
DirectWrite based ComplexTextController.

  • PlatformFTW.cmake:
  • platform/graphics/ComplexTextController.cpp:

(WebCore::ComplexTextController::ComplexTextController): Treat Windows
like any other ComplexTextController platform.

  • platform/graphics/Font.cpp:

(WebCore::Font::platformGlyphInit): Add hack for DirectWrite
zero-width space handling.

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::widthOfTextRange const): Don't use Uniscribe.

  • platform/graphics/FontPlatformData.h:

(WebCore::FontPlatformData::dwFontCollection const):
(WebCore::FontPlatformData::faceName const):

  • platform/graphics/win/ComplexTextControllerDirectWrite.cpp:

(WebCore::shape): Added,
(WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
Added.

  • platform/graphics/win/DirectWriteUtilities.cpp:

(WebCore::DirectWrite::createWithPlatformFont): Modify to return a
pair of font and font collection.
(WebCore::DirectWrite::fontWeight): Added stub.
(WebCore::DirectWrite::fontStyle): Ditto.
(WebCore::DirectWrite::fontStretch): Ditto.

  • platform/graphics/win/DirectWriteUtilities.h:
  • platform/graphics/win/FontCustomPlatformData.cpp:

(WebCore::FontCustomPlatformData::fontPlatformData): Add more
information to help DirectWrite handle font styles.

  • platform/graphics/win/FontPlatformDataDirect2D.cpp:

(WebCore::FontPlatformData::platformDataInit):
(WebCore::FontPlatformData::FontPlatformData):
(WebCore::FontPlatformData::createFallbackFont): Deleted.

  • platform/graphics/win/FontWin.cpp:
  • platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp:

(WebCore::GlyphPage::fill): Update to handle multiple runs in a
given string.

  • platform/graphics/win/TextAnalyzerHelper.cpp:

(WebCore::TextAnalyzerHelper::TextAnalyzerHelper): Update to handle
analysis of strings with multiple runs.
(WebCore::TextAnalyzerHelper::SetScriptAnalysis): Ditto.

  • platform/graphics/win/TextAnalyzerHelper.h:
Location:
trunk/Source/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251896 r251900  
     12019-10-31  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [FTW] Adopt DirectWrite in place of Uniscribe
     4        https://bugs.webkit.org/show_bug.cgi?id=203548
     5        <rdar://problem/56695130>
     6
     7        Reviewed by Fujii Hironori.
     8
     9        This patch switches from the Uniscribe text controller to a
     10        DirectWrite based ComplexTextController.
     11
     12        * PlatformFTW.cmake:
     13        * platform/graphics/ComplexTextController.cpp:
     14        (WebCore::ComplexTextController::ComplexTextController): Treat Windows
     15        like any other ComplexTextController platform.
     16        * platform/graphics/Font.cpp:
     17        (WebCore::Font::platformGlyphInit): Add hack for DirectWrite
     18        zero-width space handling.
     19        * platform/graphics/FontCascade.cpp:
     20        (WebCore::FontCascade::widthOfTextRange const): Don't use Uniscribe.
     21        * platform/graphics/FontPlatformData.h:
     22        (WebCore::FontPlatformData::dwFontCollection const):
     23        (WebCore::FontPlatformData::faceName const):
     24        * platform/graphics/win/ComplexTextControllerDirectWrite.cpp:
     25        (WebCore::shape): Added,
     26        (WebCore::ComplexTextController::collectComplexTextRunsForCharacters):
     27        Added.
     28        * platform/graphics/win/DirectWriteUtilities.cpp:
     29        (WebCore::DirectWrite::createWithPlatformFont): Modify to return a
     30        pair of font and font collection.
     31        (WebCore::DirectWrite::fontWeight): Added stub.
     32        (WebCore::DirectWrite::fontStyle): Ditto.
     33        (WebCore::DirectWrite::fontStretch): Ditto.
     34        * platform/graphics/win/DirectWriteUtilities.h:
     35        * platform/graphics/win/FontCustomPlatformData.cpp:
     36        (WebCore::FontCustomPlatformData::fontPlatformData): Add more
     37        information to help DirectWrite handle font styles.
     38        * platform/graphics/win/FontPlatformDataDirect2D.cpp:
     39        (WebCore::FontPlatformData::platformDataInit):
     40        (WebCore::FontPlatformData::FontPlatformData):
     41        (WebCore::FontPlatformData::createFallbackFont): Deleted.
     42        * platform/graphics/win/FontWin.cpp:
     43        * platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp:
     44        (WebCore::GlyphPage::fill): Update to handle multiple runs in a
     45        given string.
     46        * platform/graphics/win/TextAnalyzerHelper.cpp:
     47        (WebCore::TextAnalyzerHelper::TextAnalyzerHelper): Update to handle
     48        analysis of strings with multiple runs.
     49        (WebCore::TextAnalyzerHelper::SetScriptAnalysis): Ditto.
     50        * platform/graphics/win/TextAnalyzerHelper.h:
     51
    1522019-10-31  Tim Horton  <timothy_horton@apple.com>
    253
  • trunk/Source/WebCore/PlatformFTW.cmake

    r251221 r251900  
    102102    platform/graphics/win/TransformationMatrixDirect2D.cpp
    103103    platform/graphics/win/TransformationMatrixWin.cpp
    104     platform/graphics/win/UniscribeController.cpp
    105104
    106105    platform/network/win/CurlSSLHandleWin.cpp
  • trunk/Source/WebCore/platform/graphics/ComplexTextController.cpp

    r248846 r251900  
    11/*
    2  * Copyright (C) 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4444namespace WebCore {
    4545
    46 #if PLATFORM(WIN)
     46#if PLATFORM(WIN) && !USE(DIRECT2D)
    4747
    4848class TextLayout {
     
    6262    ASSERT_NOT_REACHED();
    6363    return 0;
     64}
     65
     66void ComplexTextController::collectComplexTextRunsForCharacters(const UChar*, unsigned, unsigned, const Font*)
     67{
     68    ASSERT_NOT_REACHED();
    6469}
    6570
     
    147152    , m_forTextEmphasis(forTextEmphasis)
    148153{
    149 #if PLATFORM(WIN)
    150     ASSERT_NOT_REACHED();
    151 #endif
    152 
    153154    computeExpansionOpportunity();
    154155
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r248846 r251900  
    120120    if (glyphPageSpace)
    121121        m_spaceGlyph = glyphPageSpace->glyphDataForCharacter(space).glyph;
    122     float width = widthForGlyph(m_spaceGlyph);
    123     m_spaceWidth = width;
    124122    if (glyphPageCharacterZero)
    125123        m_zeroGlyph = glyphPageCharacterZero->glyphDataForCharacter('0').glyph;
    126     m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
    127     determinePitch();
    128     m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
    129124
    130125    // Force the glyph for ZERO WIDTH SPACE to have zero width, unless it is shared with SPACE.
     
    133128    if (m_zeroWidthSpaceGlyph == m_spaceGlyph)
    134129        m_zeroWidthSpaceGlyph = 0;
     130
     131    float width = widthForGlyph(m_spaceGlyph);
     132    m_spaceWidth = width;
     133    m_fontMetrics.setZeroWidth(widthForGlyph(m_zeroGlyph));
     134    determinePitch();
     135    m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
    135136}
    136137
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r248846 r251900  
    4242#include <wtf/text/StringBuilder.h>
    4343
    44 #if PLATFORM(WIN)
     44#if PLATFORM(WIN) && !USE(DIRECT2D)
    4545#include "UniscribeController.h"
    4646#endif
     
    351351    auto codePathToUse = codePath(run);
    352352    if (codePathToUse == Complex) {
    353 #if PLATFORM(WIN)
     353#if PLATFORM(WIN) && !USE(DIRECT2D)
    354354        UniscribeController it(this, run);
    355355        it.advance(from);
     
    13981398}
    13991399
    1400 #if !PLATFORM(WIN)
     1400#if !PLATFORM(WIN) || USE(DIRECT2D)
    14011401float FontCascade::getGlyphsAndAdvancesForComplexText(const TextRun& run, unsigned from, unsigned to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
    14021402{
     
    15461546}
    15471547
    1548 #if !PLATFORM(WIN)
     1548#if !PLATFORM(WIN) || USE(DIRECT2D)
    15491549float FontCascade::floatWidthForComplexText(const TextRun& run, HashSet<const Font*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
    15501550{
     
    15791579}
    15801580
    1581 #if !PLATFORM(WIN)
     1581#if !PLATFORM(WIN) || USE(DIRECT2D)
    15821582void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
    15831583{
     
    16391639}
    16401640
    1641 #if !PLATFORM(WIN)
     1641#if !PLATFORM(WIN) || USE(DIRECT2D)
    16421642int FontCascade::offsetForPositionForComplexText(const TextRun& run, float x, bool includePartialGlyphs) const
    16431643{
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.h

    r248748 r251900  
    104104
    105105#if PLATFORM(WIN) && USE(DIRECT2D)
    106     FontPlatformData(GDIObject<HFONT>&&, IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
     106    FontPlatformData(GDIObject<HFONT>&&, COMPtr<IDWriteFont>&&, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
    107107#endif
    108108
     
    144144    IDWriteFont* dwFont() const { return m_dwFont.get(); }
    145145    IDWriteFontFace* dwFontFace() const { return m_dwFontFace.get(); }
    146 
    147     static HRESULT createFallbackFont(const LOGFONT&, IDWriteFont**);
    148     static HRESULT createFallbackFont(HFONT, IDWriteFont**);
    149146#endif
    150147
  • trunk/Source/WebCore/platform/graphics/win/ComplexTextControllerDirectWrite.cpp

    r211836 r251900  
    11/*
    2 * Copyright (C) 2017 Apple Inc. All rights reserved.
     2* Copyright (C) 2017-2019 Apple Inc. All rights reserved.
    33*
    44* Redistribution and use in source and binary forms, with or without
     
    2626#include "ComplexTextController.h"
    2727
     28#if USE(DIRECT2D)
     29
     30#include "DirectWriteUtilities.h"
     31#include "FontCache.h"
     32#include "FontCascade.h"
     33#include "TextAnalyzerHelper.h"
     34#include <dwrite_3.h>
     35
    2836namespace WebCore {
    2937
    30 void ComplexTextController::collectComplexTextRunsForCharacters(const UChar*, unsigned, unsigned, const Font*)
     38static bool shape(IDWriteTextAnalyzer* analyzer, const DWRITE_SCRIPT_ANALYSIS& analysis, const FontPlatformData& fontPlatformData, const WCHAR* text, unsigned length, unsigned suggestedCount, Vector<Glyph>& glyphs, Vector<Glyph>& clusterMap, Vector<DWRITE_SHAPING_TEXT_PROPERTIES>& textProperties, Vector<DWRITE_SHAPING_GLYPH_PROPERTIES>& glyphProperties, unsigned& glyphCount)
    3139{
    32     // FIXME: Implement this.
    33     ASSERT_NOT_REACHED();
     40    HRESULT shapeResult = E_PENDING;
     41
     42    do {
     43        shapeResult = analyzer->GetGlyphs(text, length, fontPlatformData.dwFontFace(), fontPlatformData.orientation() == FontOrientation::Vertical, false,
     44            &analysis, nullptr, nullptr, nullptr, nullptr, 0, suggestedCount, clusterMap.data(), textProperties.data(),
     45            glyphs.data(), glyphProperties.data(), &glyphCount);
     46
     47        if (shapeResult == E_OUTOFMEMORY) {
     48            // Need to resize our buffers (except for clusterMap. It is always the length of the string).
     49            glyphs.resize(glyphs.size() * 2);
     50            textProperties.resize(glyphs.size());
     51            glyphProperties.resize(glyphs.size());
     52        }
     53    } while (shapeResult == E_OUTOFMEMORY);
     54
     55    if (FAILED(shapeResult))
     56        return false;
     57
     58    return true;
     59}
     60
     61void ComplexTextController::collectComplexTextRunsForCharacters(const UChar* cp, unsigned length, unsigned stringLocation, const Font* font)
     62{
     63    if (!font) {
     64        // Create a run of missing glyphs from the primary font.
     65        m_complexTextRuns.append(ComplexTextRun::create(m_font.primaryFont(), cp, stringLocation, length, 0, length, m_run.ltr()));
     66        return;
     67    }
     68
     69    auto& fontPlatformData = font->platformData();
     70
     71    wchar_t localeName[LOCALE_NAME_MAX_LENGTH] = { };
     72    int localeLength = GetUserDefaultLocaleName(reinterpret_cast<LPWSTR>(&localeName), LOCALE_NAME_MAX_LENGTH);
     73    RELEASE_ASSERT(localeLength < LOCALE_NAME_MAX_LENGTH);
     74
     75    Vector<DWRITE_FONT_FEATURE> fontFeatures(1);
     76    fontFeatures[0].nameTag = DWRITE_FONT_FEATURE_TAG_KERNING;
     77    fontFeatures[0].parameter = m_font.enableKerning() ? 1 : 0;
     78
     79    if (fontPlatformData.orientation() == FontOrientation::Vertical)
     80        fontFeatures.append({DWRITE_FONT_FEATURE_TAG_VERTICAL_WRITING, 1});
     81
     82    DWRITE_TYPOGRAPHIC_FEATURES usedFeatures;
     83    usedFeatures.features = fontFeatures.data();
     84    usedFeatures.featureCount = fontFeatures.size();
     85
     86    Vector<const DWRITE_TYPOGRAPHIC_FEATURES*> features;
     87    features.append(&usedFeatures);
     88
     89    COMPtr<IDWriteTextAnalyzer> analyzer;
     90    HRESULT hr = DirectWrite::factory()->CreateTextAnalyzer(&analyzer);
     91    RELEASE_ASSERT(SUCCEEDED(hr));
     92
     93    TextAnalyzerHelper helper(reinterpret_cast<LPWSTR>(&localeName), reinterpret_cast<LPCWSTR>(cp), length);
     94
     95    hr = analyzer->AnalyzeScript(&helper, 0, length, &helper);
     96    RELEASE_ASSERT(SUCCEEDED(hr));
     97
     98    unsigned totalSuggestedCount = (3 * length / 2 + 16);
     99
     100    Vector<Glyph> glyphs;
     101    Vector<Glyph> clusterMap;
     102    Vector<DWRITE_SHAPING_TEXT_PROPERTIES> textProperties;
     103    Vector<DWRITE_SHAPING_GLYPH_PROPERTIES> glyphProperties;
     104    Vector<FLOAT> glyphAdvances;
     105    Vector<DWRITE_GLYPH_OFFSET> glyphOffsets;
     106    Vector<FloatPoint> origins;
     107    Vector<FloatSize> advances;
     108    Vector<unsigned> stringIndices;
     109
     110    glyphs.reserveCapacity(totalSuggestedCount);
     111    clusterMap.reserveCapacity(length);
     112    textProperties.reserveCapacity(totalSuggestedCount);
     113    glyphProperties.reserveCapacity(totalSuggestedCount);
     114    glyphAdvances.reserveCapacity(totalSuggestedCount);
     115    glyphOffsets.reserveCapacity(totalSuggestedCount);
     116    origins.reserveCapacity(totalSuggestedCount);
     117    advances.reserveCapacity(totalSuggestedCount);
     118    stringIndices.reserveCapacity(totalSuggestedCount);
     119
     120    for (const auto& run : helper.m_analyzedRuns) {
     121        const UChar* currentCP = cp + run.startPosition;
     122        LPCWSTR textPosition = reinterpret_cast<LPCWSTR>(currentCP);
     123
     124        unsigned suggestedCount = (3 * run.length / 2 + 16);
     125        glyphs.resize(suggestedCount);
     126        clusterMap.resize(run.length);
     127        textProperties.resize(suggestedCount);
     128        glyphProperties.resize(suggestedCount);
     129
     130        unsigned glyphCount = 0;
     131        if (!shape(analyzer.get(), run.analysis, fontPlatformData, textPosition, run.length, suggestedCount, glyphs, clusterMap, textProperties, glyphProperties, glyphCount))
     132            return;
     133
     134        glyphs.shrink(glyphCount);
     135        textProperties.shrink(glyphCount);
     136        glyphProperties.shrink(glyphCount);
     137        glyphAdvances.resize(glyphCount);
     138        glyphOffsets.resize(glyphCount);
     139
     140        HRESULT placementResult = analyzer->GetGlyphPlacements(textPosition, clusterMap.data(), textProperties.data(), run.length,
     141            glyphs.data(), glyphProperties.data(), glyphCount, fontPlatformData.dwFontFace(),
     142            fontPlatformData.size(), fontPlatformData.orientation() == FontOrientation::Vertical, m_run.ltr(),
     143            &run.analysis, reinterpret_cast<LPCWSTR>(localeName),
     144            features.data(), &run.length, 1,
     145            glyphAdvances.data(), glyphOffsets.data());
     146        if (FAILED(placementResult))
     147            return;
     148
     149        // Convert all chars that should be treated as spaces to use the space glyph.
     150        // We also create a map that allows us to quickly go from space glyphs back to their corresponding characters.
     151        float spaceWidth = font->spaceWidth() - font->syntheticBoldOffset();
     152
     153        for (int k = 0; k < run.length; ++k) {
     154            UChar ch = *(currentCP + k);
     155            bool treatAsSpace = FontCascade::treatAsSpace(ch);
     156            bool treatAsZeroWidthSpace = FontCascade::treatAsZeroWidthSpace(ch);
     157            if (treatAsSpace || treatAsZeroWidthSpace) {
     158                // Substitute in the space glyph at the appropriate place in the glyphs
     159                // array.
     160                glyphs[clusterMap[k]] = font->spaceGlyph();
     161                glyphAdvances[clusterMap[k]] = treatAsSpace ? spaceWidth : 0;
     162            }
     163        }
     164
     165        origins.resize(glyphCount);
     166        advances.resize(glyphCount);
     167        stringIndices.resize(glyphCount);
     168
     169        for (size_t i = 0; i < glyphCount; ++i) {
     170            stringIndices[i] = i;
     171            origins[i] = FloatPoint(glyphOffsets[i].advanceOffset, glyphOffsets[i].ascenderOffset);
     172            advances[i] = FloatSize(glyphAdvances[i], 0);
     173        }
     174
     175        m_complexTextRuns.append(ComplexTextRun::create(advances, origins, glyphs, stringIndices, FloatSize(), *font, currentCP, 0, run.length, 0, run.length, m_run.ltr()));
     176    }
    34177}
    35178
    36179}
     180
     181#endif
  • trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.cpp

    r248748 r251900  
    191191    Vector<wchar_t> localeName(LOCALE_NAME_MAX_LENGTH);
    192192    int localeLength = GetUserDefaultLocaleName(localeName.data(), LOCALE_NAME_MAX_LENGTH);
    193 
    194     COMPtr<IDWriteFontFamily> fontFamily = fontFamilyForCollection(systemFontCollection.get(), localeName, logFont);
    195     if (!fontFamily)
    196         fontFamily = fontFamilyForCollection(webProcessFontCollection(), localeName, logFont);
     193    RELEASE_ASSERT(localeLength <= LOCALE_NAME_MAX_LENGTH);
     194
     195    COMPtr<IDWriteFontCollection1> collection(Query, systemFontCollection);
     196
     197    COMPtr<IDWriteFontFamily> fontFamily = fontFamilyForCollection(collection.get(), localeName, logFont);
     198    if (!fontFamily) {
     199        collection = webProcessFontCollection();
     200        fontFamily = fontFamilyForCollection(collection.get(), localeName, logFont);
     201    }
    197202
    198203    if (!fontFamily) {
    199204        // Just return the first system font.
    200         hr = systemFontCollection->GetFontFamily(0, &fontFamily);
     205        collection = COMPtr<IDWriteFontCollection1>(Query, systemFontCollection);
     206        hr = collection->GetFontFamily(0, &fontFamily);
    201207        if (FAILED(hr))
    202208            return nullptr;
     
    219225}
    220226
     227DWRITE_FONT_WEIGHT fontWeight(const FontPlatformData&)
     228{
     229    return DWRITE_FONT_WEIGHT_REGULAR;
     230}
     231
     232DWRITE_FONT_STYLE fontStyle(const FontPlatformData&)
     233{
     234    return DWRITE_FONT_STYLE_NORMAL;
     235}
     236
     237DWRITE_FONT_STRETCH fontStretch(const FontPlatformData&)
     238{
     239    return DWRITE_FONT_STRETCH_NORMAL;
     240}
     241
    221242} // namespace DirectWrite
    222243
  • trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.h

    r248748 r251900  
    3737interface IDWriteGdiInterop;
    3838
     39enum DWRITE_FONT_WEIGHT;
     40enum DWRITE_FONT_STYLE;
     41enum DWRITE_FONT_STRETCH;
     42
    3943namespace WebCore {
    4044
     45class FontPlatformData;
    4146class SharedBuffer;
    4247
     
    5358Vector<wchar_t> familyNameForLocale(IDWriteFontFamily*, const Vector<wchar_t>& localeName);
    5459
     60DWRITE_FONT_WEIGHT fontWeight(const FontPlatformData&);
     61DWRITE_FONT_STYLE fontStyle(const FontPlatformData&);
     62DWRITE_FONT_STRETCH fontStretch(const FontPlatformData&);
     63
    5564} // namespace DirectWrite
    5665
  • trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp

    r248846 r251900  
    5454    ASSERT(m_fontReference);
    5555
     56    auto faceName = m_name.charactersWithNullTermination();
     57    if (faceName.size() > LF_FACESIZE) {
     58        faceName.resize(LF_FACESIZE);
     59        faceName.last() = 0;
     60    }
     61
    5662    LOGFONT logFont { };
    57     memcpy(logFont.lfFaceName, m_name.charactersWithNullTermination().data(), sizeof(logFont.lfFaceName[0]) * std::min<size_t>(static_cast<size_t>(LF_FACESIZE), 1 + m_name.length()));
     63    memcpy(logFont.lfFaceName, faceName.data(), sizeof(logFont.lfFaceName[0]) * std::min<size_t>(static_cast<size_t>(LF_FACESIZE), 1 + m_name.length()));
    5864
    5965    logFont.lfHeight = -size;
     
    8187    return FontPlatformData(WTFMove(hfont), cgFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
    8288#else
    83     COMPtr<IDWriteFont> dwFont = DirectWrite::createWithPlatformFont(logFont);
    84     return FontPlatformData(WTFMove(hfont), dwFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
     89    auto font = DirectWrite::createWithPlatformFont(logFont);
     90    return FontPlatformData(WTFMove(hfont), WTFMove(font), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
    8591#endif
    8692}
  • trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp

    r248748 r251900  
    11/*
    2  * Copyright (C) 2016 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2016-2019 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5454}
    5555
    56 FontPlatformData::FontPlatformData(GDIObject<HFONT>&& hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI)
     56FontPlatformData::FontPlatformData(GDIObject<HFONT>&& hfont, COMPtr<IDWriteFont>&& font, float size, bool bold, bool oblique, bool useGDI)
    5757    : m_syntheticBold(bold)
    5858    , m_syntheticOblique(oblique)
    5959    , m_size(size)
    6060    , m_font(SharedGDIObject<HFONT>::create(WTFMove(hfont)))
    61     , m_dwFont(font)
     61    , m_dwFont(WTFMove(font))
    6262    , m_useGDI(useGDI)
    6363{
     
    117117}
    118118
    119 HRESULT FontPlatformData::createFallbackFont(const LOGFONT& logFont, IDWriteFont** dwFont)
    120 {
    121     if (!dwFont)
    122         return E_POINTER;
    123 
    124     *dwFont = DirectWrite::createWithPlatformFont(logFont).get();
    125 
    126     return S_OK;
    127 }
    128 
    129 HRESULT FontPlatformData::createFallbackFont(HFONT hfont, IDWriteFont** dwFont)
    130 {
    131     if (!dwFont)
    132         return E_POINTER;
    133 
    134     COMPtr<IDWriteFontCollection> fontCollection;
    135     HRESULT hr = DirectWrite::factory()->GetSystemFontCollection(&fontCollection);
    136     if (FAILED(hr))
    137         return hr;
    138 
    139     HWndDC hdc(0);
    140     HGDIOBJ oldFont = ::SelectObject(hdc, hfont);
    141 
    142     COMPtr<IDWriteFontFace> fontFace;
    143     hr = DirectWrite::gdiInterop()->CreateFontFaceFromHdc(hdc, &fontFace);
    144     if (FAILED(hr)) {
    145         ::SelectObject(hdc, oldFont);
    146         return hr;
    147     }
    148 
    149     LOGFONT gdiBasedFont = { };
    150     hr = DirectWrite::gdiInterop()->ConvertFontFaceToLOGFONT(fontFace.get(), &gdiBasedFont);
    151     if (FAILED(hr)) {
    152         ::SelectObject(hdc, oldFont);
    153         return hr;
    154     }
    155 
    156     hr = fontCollection->GetFontFromFontFace(fontFace.get(), dwFont);
    157 
    158     if (!SUCCEEDED(hr))
    159         hr = DirectWrite::webProcessFontCollection()->GetFontFromFontFace(fontFace.get(), dwFont);
    160 
    161     ::SelectObject(hdc, oldFont);
    162     if (SUCCEEDED(hr))
    163         return hr;
    164 
    165     return createFallbackFont(gdiBasedFont, dwFont);
    166 }
    167 
    168119}
    169120
  • trunk/Source/WebCore/platform/graphics/win/FontWin.cpp

    r239549 r251900  
    3434#include "Logging.h"
    3535#include "TextRun.h"
    36 #include "UniscribeController.h"
    3736#include <wtf/MathExtras.h>
    3837
     38#if !USE(DIRECT2D)
     39#include "UniscribeController.h"
     40#endif
    3941
    4042namespace WebCore {
     
    4951    return false;
    5052}
     53
     54#if !USE(DIRECT2D)
    5155
    5256void FontCascade::adjustSelectionRectForComplexText(const TextRun& run, LayoutRect& selectionRect, unsigned from, unsigned to) const
     
    114118}
    115119
     120#endif
     121
    116122}
  • trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp

    r248748 r251900  
    5353    int localeLength = GetUserDefaultLocaleName(reinterpret_cast<LPWSTR>(&localeName), LOCALE_NAME_MAX_LENGTH);
    5454    RELEASE_ASSERT(localeLength <= LOCALE_NAME_MAX_LENGTH);
    55     localeName[localeLength] = '\0';
    5655
    5756    TextAnalyzerHelper helper(reinterpret_cast<LPWSTR>(&localeName), reinterpret_cast<LPWSTR>(buffer), bufferLength);
     
    6059    RELEASE_ASSERT(SUCCEEDED(hr));
    6160
    62     unsigned returnedCount = 0;
    63     Glyph localGlyphBuffer[GlyphPage::size];
    64     Glyph clusterMap[GlyphPage::size];
     61    Vector<Glyph> glyphs(GlyphPage::size, 0);
     62    Vector<Glyph> clusterMap(GlyphPage::size, 0);
    6563    Vector<DWRITE_SHAPING_TEXT_PROPERTIES> textProperties(GlyphPage::size);
    6664    Vector<DWRITE_SHAPING_GLYPH_PROPERTIES> glyphProperties(GlyphPage::size);
    6765
    68     hr = analyzer->GetGlyphs(reinterpret_cast<LPCWSTR>(buffer), bufferLength, fontPlatformData.dwFontFace(), fontPlatformData.orientation() == FontOrientation::Vertical, false,
    69         &helper.m_analysis, nullptr, nullptr, nullptr, nullptr, 0, GlyphPage::size, clusterMap, textProperties.data(),
    70         localGlyphBuffer, glyphProperties.data(), &returnedCount);
    71     if (!SUCCEEDED(hr))
    72         return false;
     66    const WCHAR* textStart = reinterpret_cast<LPCWSTR>(buffer);
     67    Glyph* glyphData = glyphs.data();
     68    Glyph* clusterMapData = clusterMap.data();
     69    DWRITE_SHAPING_TEXT_PROPERTIES* textPropertiesData = textProperties.data();
     70    DWRITE_SHAPING_GLYPH_PROPERTIES* glyphPropertiesData = glyphProperties.data();
    7371
    74     for (unsigned i = 0; i < GlyphPage::size; i++) {
    75         Glyph glyph = localGlyphBuffer[i];
     72    unsigned total = 0;
     73    unsigned maxGlyphCount = GlyphPage::size;
     74    for (const auto& run : helper.m_analyzedRuns) {
     75        RELEASE_ASSERT(total + run.length <= bufferLength);
     76
     77        unsigned returnedCount = 0;
     78        hr = analyzer->GetGlyphs(textStart + run.startPosition, run.length, fontPlatformData.dwFontFace(), fontPlatformData.orientation() == FontOrientation::Vertical, false,
     79            &run.analysis, nullptr, nullptr, nullptr, nullptr, 0, maxGlyphCount, clusterMapData, textPropertiesData,
     80            glyphData, glyphPropertiesData, &returnedCount);
     81
     82        if (!SUCCEEDED(hr))
     83            return false;
     84
     85        glyphData += returnedCount;
     86        clusterMapData += returnedCount;
     87        textPropertiesData += returnedCount;
     88        glyphPropertiesData += returnedCount;
     89        maxGlyphCount -= returnedCount;
     90    }
     91
     92    for (unsigned i = 0; i < GlyphPage::size; ++i) {
     93        Glyph glyph = glyphs[i];
    7694        if (!glyph)
    7795            setGlyphForIndex(i, 0);
  • trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.cpp

    r206597 r251900  
    3131namespace WebCore {
    3232
    33 TextAnalyzerHelper::TextAnalyzerHelper(WCHAR* localeName, WCHAR* buffer, unsigned bufferLength)
     33TextAnalyzerHelper::TextAnalyzerHelper(const WCHAR* localeName, const WCHAR* buffer, unsigned bufferLength)
    3434    : m_localeName(localeName)
    3535    , m_buffer(buffer)
     
    123123HRESULT TextAnalyzerHelper::SetScriptAnalysis(UINT32 textPosition, UINT32 textLength, const DWRITE_SCRIPT_ANALYSIS* analysis)
    124124{
    125     m_analysis = *analysis;
     125    AnalyzedRun current = { textPosition, textLength, *analysis };
     126    m_analyzedRuns.append(WTFMove(current));
    126127
    127128    return S_OK;
  • trunk/Source/WebCore/platform/graphics/win/TextAnalyzerHelper.h

    r206597 r251900  
    2727
    2828#include <dwrite.h>
     29#include <wtf/Vector.h>
    2930
    3031namespace WebCore {
    3132
     33struct AnalyzedRun {
     34    unsigned startPosition { 0 };
     35    unsigned length { 0 };
     36    DWRITE_SCRIPT_ANALYSIS analysis;
     37};
     38
    3239struct TextAnalyzerHelper : public IDWriteTextAnalysisSink, IDWriteTextAnalysisSource {
    33     TextAnalyzerHelper(WCHAR* localeName, WCHAR* buffer, unsigned bufferLength);
     40    TextAnalyzerHelper(const WCHAR* localeName, const WCHAR* buffer, unsigned bufferLength);
    3441
    3542    // IUnknown
     
    5158    virtual HRESULT STDMETHODCALLTYPE SetNumberSubstitution(UINT32 textPosition, UINT32 textLength, IDWriteNumberSubstitution*);
    5259
    53     WCHAR* m_localeName { nullptr };
    54     WCHAR* m_buffer { nullptr };
     60    const WCHAR* m_localeName { nullptr };
     61    const WCHAR* m_buffer { nullptr };
    5562    unsigned m_bufferLength { 0 };
    56     DWRITE_SCRIPT_ANALYSIS m_analysis { };
     63    Vector<AnalyzedRun> m_analyzedRuns;
    5764    ULONG m_refCount { 0 };
    5865};
Note: See TracChangeset for help on using the changeset viewer.