tdf#127325: Revert "Use HarfBuzz to get glyph bounding rectangle"

This reverts commit 502d73cda8fa1f482634bb6435fd1440757fdad9.

Change-Id: Ib1a318e6d9a722f9ca056ba1df3a6f2ab19855e5
Reviewed-on: https://gerrit.libreoffice.org/79323
Tested-by: Jenkins
Reviewed-by: Khaled Hosny <khaledhosny@eglug.org>
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index b57955f..da5af02 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -71,7 +71,7 @@
    const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
    const ImplFontCache* GetFontCache() const { return mpFontCache; }

    bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool);
    bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
    virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;

    int GetKashidaWidth();
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx
index 808f2d0..58d7208 100644
--- a/vcl/source/font/fontinstance.cxx
+++ b/vcl/source/font/fontinstance.cxx
@@ -144,51 +144,12 @@
        mpUnicodeFallbackList->erase( it );
}

bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect, bool bVertical)
bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect, bool bVertical) const
{
    if (mpFontCache && mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect))
        return true;

    hb_font_t* pHbFont = GetHbFont();
    hb_glyph_extents_t aExtents;
    bool res = hb_font_get_glyph_extents(pHbFont, nID, &aExtents);
    if (res)
    {
        double nXScale = 0, nYScale = 0;
        GetScale(&nXScale, &nYScale);

        double fMinX = aExtents.x_bearing;
        double fMinY = aExtents.y_bearing;
        double fMaxX = aExtents.x_bearing + aExtents.width;
        double fMaxY = aExtents.y_bearing + aExtents.height;

        tools::Rectangle aRect( std::floor(fMinX * nXScale),
                               -std::ceil(fMinY  * nYScale),
                                std::ceil(fMaxX  * nXScale),
                               -std::floor(fMaxY * nYScale));

        if (mnOrientation && !bVertical)
        {
            // Apply font rotation.
            const double fRad = basegfx::deg2rad(mnOrientation);
            const double fCos = cos(fRad);
            const double fSin = sin(fRad);

            rRect.SetLeft(   fCos * aRect.Left() + fSin * aRect.Top());
            rRect.SetTop(   -fSin * aRect.Left() - fCos * aRect.Top());
            rRect.SetRight(  fCos * aRect.Right() + fSin * aRect.Bottom());
            rRect.SetBottom(-fSin * aRect.Right() - fCos * aRect.Bottom());
        }
        else
            rRect = aRect;
    }
    else
    {
        // Fallback to platform implementations.
        // TODO: remove once we require HarfBuzz >= 2.3.0
        res = ImplGetGlyphBoundRect(nID, rRect, bVertical);
    }

    bool res = ImplGetGlyphBoundRect(nID, rRect, bVertical);
    if (mpFontCache && res)
        mpFontCache->CacheGlyphBoundRect(this, nID, rRect);
    return res;