void DrawGlyphRunTestCase()

in winrt/test.internal/graphics/CanvasTextRendererUnitTests.cpp [185:306]


        void DrawGlyphRunTestCase(bool useBrush, bool useDescription)
        {
            Fixture f;

            std::wstring localeString = L"xa-yb";
            std::wstring textString = L"Some text";

            unsigned short clusterMapElements[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            Assert::AreEqual(textString.size(), _countof(clusterMapElements));

            f.TextRenderer->DrawGlyphRunMethod.SetExpectedCalls(1,
                [&](
                Vector2 baselineOrigin,
                ICanvasFontFace* fontFace,
                float fontSize,
                uint32_t glyphCount,
                CanvasGlyph* glyphs,
                boolean isSideways,
                uint32_t bidiLevel,
                IInspectable* brush,
                CanvasTextMeasuringMode measuringMode,
                HSTRING locale,
                HSTRING text,
                uint32_t clusterMapIndicesCount,
                int* clusterMapIndices,
                unsigned int characterIndex,
                CanvasGlyphOrientation glyphOrientation)
            {
                Assert::AreEqual(1.2f, baselineOrigin.X);
                Assert::AreEqual(3.4f, baselineOrigin.Y);
                Assert::IsTrue(IsSameInstance(f.FontFace.Get(), fontFace));
                Assert::AreEqual(11.0f, fontSize);
                Assert::AreEqual(3u, glyphCount);

                for (int i = 0; i < 3; ++i)
                {
                    int inc = i * 4;
                    Assert::AreEqual(inc + 1, glyphs[i].Index);
                    Assert::AreEqual(static_cast<float>(inc)+2.0f, glyphs[i].Advance);
                    Assert::AreEqual(static_cast<float>(inc)+3.0f, glyphs[i].AdvanceOffset);
                    Assert::AreEqual(static_cast<float>(inc)+4.0f, glyphs[i].AscenderOffset);
                }

                Assert::AreEqual(static_cast<boolean>(true), isSideways);
                Assert::AreEqual(5u, bidiLevel);

                if (useBrush)
                    Assert::IsTrue(IsSameInstance(f.SolidColorBrush.Get(), brush));
                else
                    Assert::IsNull(brush);

                Assert::AreEqual(CanvasTextMeasuringMode::GdiNatural, measuringMode);

                if (useDescription)
                {
                    Assert::IsTrue(StringEquals(localeString, locale));
                    Assert::IsTrue(StringEquals(textString, text));

                    Assert::AreEqual(clusterMapIndicesCount, static_cast<uint32_t>(_countof(clusterMapElements)));
                    for (int i = 0; i < _countof(clusterMapElements); ++i)
                    {
                        Assert::AreEqual(clusterMapIndices[i], static_cast<int>(clusterMapElements[i]));
                    }
                    Assert::AreEqual(123u, characterIndex);
                }
                else
                {
                    Assert::IsNull(locale);
                    Assert::IsNull(text);
                    Assert::AreEqual(0u, clusterMapIndicesCount);
                    Assert::IsNull(clusterMapIndices);
                    Assert::AreEqual(0u, characterIndex);                    
                }

                Assert::AreEqual(CanvasGlyphOrientation::Upright, glyphOrientation);

                return S_OK;
            });

            UINT16 glyphIndices[] = { 1, 5, 9 };
            float glyphAdvances[] = { 2.0f, 6.0f, 10.0f };
            DWRITE_GLYPH_OFFSET glyphOffsets[] = { { 3.0f, 4.0f }, { 7.0f, 8.0f }, { 11.0f, 12.0f } };

            f.Adapter->MockTextLayout->DrawMethod.SetExpectedCalls(1,
                [&](void* context, IDWriteTextRenderer* renderer, FLOAT originX, FLOAT originY)
                {
                    DWRITE_GLYPH_RUN glyphRun;
                    glyphRun.fontFace = f.RealizedDWriteFontFace.Get();
                    glyphRun.fontEmSize = 11.0f;
                    glyphRun.glyphCount = 3;
                    glyphRun.glyphIndices = glyphIndices;
                    glyphRun.glyphAdvances = glyphAdvances;
                    glyphRun.glyphOffsets = glyphOffsets;
                    glyphRun.isSideways = true;
                    glyphRun.bidiLevel = 5;

                    DWRITE_GLYPH_RUN_DESCRIPTION glyphRunDescription;
                    if (useDescription)
                    {
                        glyphRunDescription.localeName = localeString.c_str();
                        glyphRunDescription.string = textString.c_str();
                        glyphRunDescription.stringLength = static_cast<uint32_t>(textString.size());
                        glyphRunDescription.clusterMap = clusterMapElements;
                        glyphRunDescription.textPosition = 123u;
                    }

                    renderer->DrawGlyphRun(
                        nullptr,
                        1.2f,
                        3.4f,
                        DWRITE_MEASURING_MODE_GDI_NATURAL,
                        &glyphRun,
                        useDescription? &glyphRunDescription : nullptr,
                        useBrush? f.D2DBrush.Get() : nullptr);

                    return S_OK;
                });

            auto textLayout = f.CreateSimpleTextLayout();

            Assert::AreEqual(S_OK, textLayout->DrawToTextRenderer(f.TextRenderer.Get(), Vector2{ 0, 0 }));
        }