void ExpectGetGlyphs()

in winrt/test.internal/graphics/CanvasTextAnalyzerUnitTests.cpp [515:649]


        void ExpectGetGlyphs(int getGlyphCount=1, int getGlyphPlacementsCount=1)
        {
            TextAnalyzer->GetGlyphsMethod.SetExpectedCalls(getGlyphCount,
                [&](WCHAR const* textString,
                    uint32_t textLength,
                    IDWriteFontFace* fontFace,
                    BOOL isSideways,
                    BOOL isRightToLeft,
                    DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis,
                    WCHAR const* localeName,
                    IDWriteNumberSubstitution* numberSubstitution,
                    DWRITE_TYPOGRAPHIC_FEATURES const** features,
                    uint32_t const* featureRangeLengths,
                    uint32_t featureRanges,
                    uint32_t maxGlyphCount,
                    UINT16* clusterMap,
                    DWRITE_SHAPING_TEXT_PROPERTIES* textProps,
                    UINT16* glyphIndices,
                    DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProps,
                    uint32_t* actualGlyphCount)
                {
                    Assert::AreEqual(0, wcscmp(this->Text.c_str(), textString));
                    Assert::AreEqual(static_cast<uint32_t>(this->Text.length()), textLength);
                    Assert::IsTrue(IsSameInstance(RealizedFontFace.Get(), fontFace));

                    Assert::AreEqual(IsSideways, !!isSideways);
                    Assert::AreEqual(IsRightToLeft, !!isRightToLeft);

                    Assert::AreEqual(static_cast<uint16_t>(123), scriptAnalysis->script);
                    Assert::AreEqual(DWRITE_SCRIPT_SHAPES_NO_VISUAL, scriptAnalysis->shapes);

                    Assert::AreEqual(0, wcscmp(Locale.c_str(), localeName));

                    VerifyNumberSubstitution(numberSubstitution);

                    VerifyFeatureRanges(features, featureRangeLengths, featureRanges);

                    //
                    // For these contrived tests, the glyph breakdown will add some extra glyphs.
                    //
                    const int calculatedGlyphCount = GetGlyphCount();

                    if (calculatedGlyphCount > static_cast<int>(maxGlyphCount))
                        return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);

                    for (int i = 0; i < static_cast<int>(this->Text.length()); ++i)
                    {
                        clusterMap[i] = static_cast<uint16_t>(ClusterMap[i]);
                        textProps[i].isShapedAlone = i % 2 == 0;
                    }

                    *actualGlyphCount = calculatedGlyphCount;

                    for (int i = 0; i < calculatedGlyphCount; ++i)
                    {
                        glyphIndices[i] = static_cast<uint16_t>(GetGlyphIndex(i));

                        auto shaping = GetDWriteShaping(i);
                        glyphProps[i].justification = shaping.justification;
                        glyphProps[i].isClusterStart = shaping.isClusterStart;
                        glyphProps[i].isDiacritic = shaping.isDiacritic;
                        glyphProps[i].isZeroWidthSpace = shaping.isZeroWidthSpace;
                    }

                    return S_OK;
                });
            
            TextAnalyzer->GetGlyphPlacementsMethod.SetExpectedCalls(getGlyphPlacementsCount,
                [&](WCHAR const* textString,
                    UINT16 const* clusterMap,
                    DWRITE_SHAPING_TEXT_PROPERTIES* textProps,
                    uint32_t textLength,
                    UINT16 const* glyphIndices,
                    DWRITE_SHAPING_GLYPH_PROPERTIES const* glyphProps,
                    uint32_t glyphCount,
                    IDWriteFontFace * fontFace,
                    FLOAT fontEmSize,
                    BOOL isSideways,
                    BOOL isRightToLeft,
                    DWRITE_SCRIPT_ANALYSIS const* scriptAnalysis,
                    WCHAR const* localeName,
                    DWRITE_TYPOGRAPHIC_FEATURES const** features,
                    uint32_t const* featureRangeLengths,
                    uint32_t featureRanges,
                    FLOAT* glyphAdvances,
                    DWRITE_GLYPH_OFFSET* glyphOffsets)
                {
                    Assert::AreEqual(0, wcscmp(this->Text.c_str(), textString));

                    for (int i = 0; i < static_cast<int>(this->Text.length()); ++i)
                    {
                        Assert::AreEqual(ClusterMap[i], static_cast<int>(clusterMap[i]));
                        Assert::AreEqual(i % 2 == 0, static_cast<bool>(textProps[i].isShapedAlone));
                    }

                    Assert::AreEqual(static_cast<uint32_t>(this->Text.length()), textLength);

                    for (uint32_t i = 0; i < glyphCount; i++)
                    {
                        Assert::AreEqual(GetGlyphIndex(i), static_cast<int>(glyphIndices[i]));

                        auto expectedShaping = GetDWriteShaping(i);
                        Assert::AreEqual(expectedShaping.justification, glyphProps[i].justification);
                        Assert::AreEqual(expectedShaping.isClusterStart, glyphProps[i].isClusterStart);
                        Assert::AreEqual(expectedShaping.isDiacritic, glyphProps[i].isDiacritic);
                        Assert::AreEqual(expectedShaping.isZeroWidthSpace, glyphProps[i].isZeroWidthSpace);
                    }

                    const int extraGlyphs = AdditionalGlyphsToAddDuringExpansion;
                    Assert::AreEqual(static_cast<int>(this->Text.length()) + extraGlyphs, static_cast<int>(glyphCount));

                    Assert::IsTrue(IsSameInstance(RealizedFontFace.Get(), fontFace));

                    Assert::AreEqual(FontSize, fontEmSize);
                    Assert::AreEqual(IsSideways, !!isSideways);
                    Assert::AreEqual(IsRightToLeft, !!isRightToLeft);

                    Assert::AreEqual(static_cast<uint16_t>(123), scriptAnalysis->script);
                    Assert::AreEqual(DWRITE_SCRIPT_SHAPES_NO_VISUAL, scriptAnalysis->shapes);

                    Assert::AreEqual(0, wcscmp(Locale.c_str(), localeName));

                    VerifyFeatureRanges(features, featureRangeLengths, featureRanges);

                    for (uint32_t i = 0; i < glyphCount; ++i)
                    {
                        glyphAdvances[i] = GetGlyphAdvance(i);
                        auto offset = GetGlyphOffset(i);
                        glyphOffsets[i].advanceOffset = offset.advanceOffset;
                        glyphOffsets[i].ascenderOffset = offset.ascenderOffset;
                    }

                    return S_OK;
                });
        }