tdf#153440: Fix font fallback for surrogate pairs in RTL text

When checking for a font that supports the surrogate pair, code was
appending code units one by one to string buffer and in RTL case this
was happening in reverse order leading to invalid text and consequently
failing to find any font that supports it.

We now iterate over runs not individual positions, so the text of each
individual run maintains its correct order regardless of the direction.

Change-Id: Icf2e2aed56512bf907dc6b3c36f387a9e3ad497a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152481
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
(cherry picked from commit 737854f3c5131d3a64803edc0802dbbc07aa4405)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152444
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 6e8db56..3bfbb8f 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1040,11 +1040,11 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
    rLayoutArgs.mnFlags |= SalLayoutFlags::ForFallback;

    // get list of code units that need glyph fallback
    int nCharPos = -1;
    bool bRTL = false;
    bool bRTL;
    int nMinRunPos, nEndRunPos;
    OUStringBuffer aMissingCodeBuf(512);
    while (rLayoutArgs.GetNextPos( &nCharPos, &bRTL))
        aMissingCodeBuf.append(rLayoutArgs.mrStr[nCharPos]);
    while (rLayoutArgs.GetNextRun(&nMinRunPos, &nEndRunPos, &bRTL))
        aMissingCodeBuf.append(rLayoutArgs.mrStr.subView(nMinRunPos, nEndRunPos - nMinRunPos));
    rLayoutArgs.ResetPos();
    OUString aMissingCodes = aMissingCodeBuf.makeStringAndClear();