[Libreoffice-commits] core.git: 3 commits - vcl/inc vcl/win

Khaled Hosny khaledhosny at eglug.org
Sat Mar 4 00:49:09 UTC 2017


 vcl/inc/win/salgdi.h      |    2 
 vcl/inc/win/winlayout.hxx |   17 +++---
 vcl/win/gdi/winlayout.cxx |  113 ++++------------------------------------------
 3 files changed, 22 insertions(+), 110 deletions(-)

New commits:
commit c328c26a67a865d965cb8bde1b248eeae92f4e75
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Sat Mar 4 01:37:52 2017 +0200

    SalLayout::GetBoundRect() works just fine here
    
    Change-Id: Idce9a8f374f62bd92756d7391ccca3122c89683e

diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index e357083..3af90cb 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -299,7 +299,7 @@ protected:
 private:
     // local helpers
 
-    static void             DrawTextLayout(const CommonSalLayout&, HDC, bool bUseDWrite);
+    void                    DrawTextLayout(const CommonSalLayout&, HDC, bool bUseDWrite);
 
 public:
     // public SalGraphics methods, the interface to the independent vcl part
diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index cca6a46..42b25b6 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -177,7 +177,9 @@ public:
 
     virtual ~TextOutRenderer() = default;
 
-    virtual bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
+    virtual bool operator ()(CommonSalLayout const &rLayout,
+        SalGraphics &rGraphics,
+        HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) = 0;
 };
@@ -190,7 +192,9 @@ class ExTextOutRenderer : public TextOutRenderer
 public:
     explicit ExTextOutRenderer() = default;
 
-    bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
+    bool operator ()(CommonSalLayout const &rLayout,
+        SalGraphics &rGraphics,
+        HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) override;
 };
@@ -213,7 +217,9 @@ public:
     explicit D2DWriteTextOutRenderer();
     virtual ~D2DWriteTextOutRenderer() override;
 
-    bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
+    bool operator ()(CommonSalLayout const &rLayout,
+        SalGraphics &rGraphics,
+        HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) override;
 
@@ -245,7 +251,6 @@ private:
     D2DWriteTextOutRenderer & operator = (const D2DWriteTextOutRenderer &) = delete;
 
     bool GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const;
-    bool GetDWriteInkBox(CommonSalLayout const &rLayout, Rectangle &) const;
 
     ID2D1Factory        * mpD2DFactory;
     IDWriteFactory      * mpDWriteFactory;
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 47e98cc..c884c9e 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -262,7 +262,9 @@ TextOutRenderer & TextOutRenderer::get(bool bUseDWrite)
 }
 
 
-bool ExTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hDC,
+bool ExTextOutRenderer::operator ()(CommonSalLayout const &rLayout,
+    SalGraphics & /*rGraphics*/,
+    HDC hDC,
     const Rectangle* pRectToErase,
     Point* pPos, int* pGetNextGlypInfo)
 {
@@ -339,7 +341,9 @@ D2DWriteTextOutRenderer::~D2DWriteTextOutRenderer()
     CleanupModules();
 }
 
-bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hDC,
+bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout,
+    SalGraphics &rGraphics,
+    HDC hDC,
     const Rectangle* pRectToErase,
     Point* pPos, int* pGetNextGlypInfo)
 {
@@ -349,11 +353,11 @@ bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hD
     if (!BindFont(hDC))
     {
         // If for any reason we can't bind fallback to legacy APIs.
-        return ExTextOutRenderer()(rLayout, hDC, pRectToErase, pPos, pGetNextGlypInfo);
+        return ExTextOutRenderer()(rLayout, rGraphics, hDC, pRectToErase, pPos, pGetNextGlypInfo);
     }
 
     Rectangle bounds;
-    bool succeeded = GetDWriteInkBox(rLayout, bounds);
+    bool succeeded = rLayout.GetBoundRect(rGraphics, bounds);
     succeeded &= BindDC(hDC, bounds);   // Update the bounding rect.
 
     ID2D1SolidColorBrush* pBrush = nullptr;
@@ -497,44 +501,6 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
     return succeeded;
 }
 
-bool D2DWriteTextOutRenderer::GetDWriteInkBox(CommonSalLayout const &rLayout, Rectangle & rOut) const
-{
-    rOut.SetEmpty();
-
-    DWRITE_FONT_METRICS aFontMetrics;
-    mpFontFace->GetMetrics(&aFontMetrics);
-
-    Point aPos;
-    const GlyphItem* pGlyph;
-    std::vector<uint16_t> indices;
-    std::vector<Point>  positions;
-    int nStart = 0;
-    while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
-    {
-        positions.push_back(aPos);
-        indices.push_back(pGlyph->maGlyphId);
-    }
-
-    auto aBoxes = GetGlyphInkBoxes(indices.data(), indices.data() + indices.size());
-    if (aBoxes.empty())
-        return false;
-
-    auto p = positions.begin();
-    for (auto &b:aBoxes)
-    {
-        b += *p;
-        p++;
-        rOut.Union(b);
-    }
-
-    // The clipping rectangle is sometimes overzealous, add an extra pixel to
-    // remedy this.
-    if (!rOut.IsEmpty())
-        rOut.expand(1);
-
-    return true;
-}
-
 SalLayout* WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
 {
     if (!mpWinFontEntry[nFallbackLevel])
@@ -643,7 +609,7 @@ void WinSalGraphics::DrawTextLayout(const CommonSalLayout& rLayout, HDC hDC, boo
     Point aPos(0, 0);
     int nGlyphCount(0);
     TextOutRenderer &render = TextOutRenderer::get(bUseDWrite);
-    bool result = render(rLayout, hDC, nullptr, &aPos, &nGlyphCount);
+    bool result = render(rLayout, *this, hDC, nullptr, &aPos, &nGlyphCount);
     assert(!result);
 }
 
commit df4f30560a1297e2a42a66f20660d53004e44f0b
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Sat Mar 4 01:05:21 2017 +0200

    Drop dead code
    
    We don’t try to render vertical text with DirectWrite any more, so all
    of this is dead code now.
    
    Change-Id: If9f513f6b96fd65d275b9ec46c6e349f1c335bcf

diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index 29122fc..cca6a46 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -200,15 +200,11 @@ class D2DWriteTextOutRenderer : public TextOutRenderer
     typedef HRESULT(WINAPI *pD2D1CreateFactory_t)(D2D1_FACTORY_TYPE,
         REFIID, const D2D1_FACTORY_OPTIONS *, void **);
 
-    typedef HRESULT(WINAPI *pD2D1MakeRotateMatrix_t)(float, D2D1_POINT_2F,
-        D2D1_MATRIX_3X2_F*);
-
     typedef HRESULT(WINAPI *pDWriteCreateFactory_t)(DWRITE_FACTORY_TYPE,
         REFIID, IUnknown **);
 
     static HINSTANCE mmD2d1, mmDWrite;
     static pD2D1CreateFactory_t     D2D1CreateFactory;
-    static pD2D1MakeRotateMatrix_t  D2D1MakeRotateMatrix;
     static pDWriteCreateFactory_t   DWriteCreateFactory;
 
 public:
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 4847d67..47e98cc 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -209,7 +209,6 @@ bool WinFontInstance::CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, S
 HINSTANCE D2DWriteTextOutRenderer::mmD2d1 = nullptr,
           D2DWriteTextOutRenderer::mmDWrite = nullptr;
 D2DWriteTextOutRenderer::pD2D1CreateFactory_t D2DWriteTextOutRenderer::D2D1CreateFactory = nullptr;
-D2DWriteTextOutRenderer::pD2D1MakeRotateMatrix_t D2DWriteTextOutRenderer::D2D1MakeRotateMatrix = nullptr;
 D2DWriteTextOutRenderer::pDWriteCreateFactory_t D2DWriteTextOutRenderer::DWriteCreateFactory = nullptr;
 
 bool D2DWriteTextOutRenderer::InitModules()
@@ -219,11 +218,10 @@ bool D2DWriteTextOutRenderer::InitModules()
     if (mmD2d1 && mmDWrite)
     {
         D2D1CreateFactory = pD2D1CreateFactory_t(GetProcAddress(mmD2d1, "D2D1CreateFactory"));
-        D2D1MakeRotateMatrix = pD2D1MakeRotateMatrix_t(GetProcAddress(mmD2d1, "D2D1MakeRotateMatrix"));
         DWriteCreateFactory = pDWriteCreateFactory_t(GetProcAddress(mmDWrite, "DWriteCreateFactory"));
     }
 
-    if (!D2D1CreateFactory || !DWriteCreateFactory || !D2D1MakeRotateMatrix)
+    if (!D2D1CreateFactory || !DWriteCreateFactory)
     {
         CleanupModules();
         return false;
@@ -242,7 +240,6 @@ void D2DWriteTextOutRenderer::CleanupModules()
     mmD2d1 = nullptr;
     mmDWrite = nullptr;
     D2D1CreateFactory = nullptr;
-    D2D1MakeRotateMatrix = nullptr;
     DWriteCreateFactory = nullptr;
 }
 
@@ -367,21 +364,8 @@ bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hD
     bool bGlyphs = false;
     if (succeeded)
     {
-        float nYDiff = 0.0f;
-        bool bVertical = rLayout.getFontSelData().mbVertical;
-
-        if (bVertical)
-        {
-            DWRITE_FONT_METRICS aFM;
-            mpFontFace->GetMetrics(&aFM);
-            nYDiff = (aFM.ascent - aFM.descent) * mlfEmHeight / aFM.designUnitsPerEm;
-        }
-
         mpRT->BeginDraw();
 
-        D2D1_MATRIX_3X2_F aOrigTrans, aRotTrans;
-        mpRT->GetTransform(&aOrigTrans);
-
         const GlyphItem* pGlyph;
         while (rLayout.GetNextGlyphs(1, &pGlyph, *pPos, *pGetNextGlypInfo))
         {
@@ -401,17 +385,7 @@ bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hD
                 0
             };
 
-            if (bVertical && !pGlyph->IsVertical())
-            {
-                D2D1MakeRotateMatrix(90.0f, baseline, &aRotTrans);
-                mpRT->SetTransform(aOrigTrans * aRotTrans);
-                mpRT->DrawGlyphRun(baseline, &glyphs, pBrush);
-                mpRT->SetTransform(aOrigTrans);
-            }
-            else
-            {
-                mpRT->DrawGlyphRun({ baseline.x, baseline.y + nYDiff }, &glyphs, pBrush);
-            }
+            mpRT->DrawGlyphRun(baseline, &glyphs, pBrush);
         }
 
         hr = mpRT->EndDraw();
@@ -533,45 +507,23 @@ bool D2DWriteTextOutRenderer::GetDWriteInkBox(CommonSalLayout const &rLayout, Re
     Point aPos;
     const GlyphItem* pGlyph;
     std::vector<uint16_t> indices;
-    std::vector<bool> vertical;
     std::vector<Point>  positions;
     int nStart = 0;
     while (rLayout.GetNextGlyphs(1, &pGlyph, aPos, nStart))
     {
         positions.push_back(aPos);
         indices.push_back(pGlyph->maGlyphId);
-        vertical.push_back(pGlyph->IsVertical());
     }
 
     auto aBoxes = GetGlyphInkBoxes(indices.data(), indices.data() + indices.size());
     if (aBoxes.empty())
         return false;
 
-    double nYDiff = 0.0f;
-    bool bVertical = rLayout.getFontSelData().mbVertical;
-
-    if (bVertical)
-    {
-        DWRITE_FONT_METRICS aFM;
-        mpFontFace->GetMetrics(&aFM);
-        nYDiff = (aFM.ascent - aFM.descent) * mlfEmHeight / aFM.designUnitsPerEm;
-    }
-
     auto p = positions.begin();
-    auto v = vertical.begin();
     for (auto &b:aBoxes)
     {
-        if (bVertical)
-        {
-            if (!*v)
-                // FIXME: Hack, should rotate the box here instead.
-                b.expand(std::max(b.getHeight(), b.getWidth()));
-            else
-                b += Point(0, nYDiff);
-        }
         b += *p;
         p++;
-        v++;
         rOut.Union(b);
     }
 
commit baf3940bcafbb1acbaf75e1149e4895986f4c50f
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Sat Mar 4 00:51:15 2017 +0200

    Avoid needless dynamic_cast’s
    
    It is all CommonSalLayout() for sometime now.
    
    Change-Id: I3d4ad56df195f51242c3d007bc5257c071a03a50

diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
index b057819..29122fc 100644
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -177,7 +177,7 @@ public:
 
     virtual ~TextOutRenderer() = default;
 
-    virtual bool operator ()(SalLayout const &rLayout, HDC hDC,
+    virtual bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) = 0;
 };
@@ -190,7 +190,7 @@ class ExTextOutRenderer : public TextOutRenderer
 public:
     explicit ExTextOutRenderer() = default;
 
-    bool operator ()(SalLayout const &rLayout, HDC hDC,
+    bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) override;
 };
@@ -217,7 +217,7 @@ public:
     explicit D2DWriteTextOutRenderer();
     virtual ~D2DWriteTextOutRenderer() override;
 
-    bool operator ()(SalLayout const &rLayout, HDC hDC,
+    bool operator ()(CommonSalLayout const &rLayout, HDC hDC,
         const Rectangle* pRectToErase,
         Point* pPos, int* pGetNextGlypInfo) override;
 
@@ -249,7 +249,7 @@ private:
     D2DWriteTextOutRenderer & operator = (const D2DWriteTextOutRenderer &) = delete;
 
     bool GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const;
-    bool GetDWriteInkBox(SalLayout const &rLayout, Rectangle &) const;
+    bool GetDWriteInkBox(CommonSalLayout const &rLayout, Rectangle &) const;
 
     ID2D1Factory        * mpD2DFactory;
     IDWriteFactory      * mpDWriteFactory;
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 193d4b6..4847d67 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -265,7 +265,7 @@ TextOutRenderer & TextOutRenderer::get(bool bUseDWrite)
 }
 
 
-bool ExTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
+bool ExTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hDC,
     const Rectangle* pRectToErase,
     Point* pPos, int* pGetNextGlypInfo)
 {
@@ -274,8 +274,7 @@ bool ExTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
     HFONT hFont = static_cast<HFONT>(GetCurrentObject( hDC, OBJ_FONT ));
     HFONT hAltFont = nullptr;
     bool bUseAltFont = false;
-    const CommonSalLayout* pCSL = dynamic_cast<const CommonSalLayout*>(&rLayout);
-    if (pCSL && pCSL->getFontSelData().mbVertical)
+    if (rLayout.getFontSelData().mbVertical)
     {
         LOGFONTW aLogFont;
         GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
@@ -343,7 +342,7 @@ D2DWriteTextOutRenderer::~D2DWriteTextOutRenderer()
     CleanupModules();
 }
 
-bool D2DWriteTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
+bool D2DWriteTextOutRenderer::operator ()(CommonSalLayout const &rLayout, HDC hDC,
     const Rectangle* pRectToErase,
     Point* pPos, int* pGetNextGlypInfo)
 {
@@ -368,11 +367,8 @@ bool D2DWriteTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
     bool bGlyphs = false;
     if (succeeded)
     {
-        bool bVertical = false;
         float nYDiff = 0.0f;
-        const CommonSalLayout* pCSL = dynamic_cast<const CommonSalLayout*>(&rLayout);
-        if (pCSL)
-            bVertical = pCSL->getFontSelData().mbVertical;
+        bool bVertical = rLayout.getFontSelData().mbVertical;
 
         if (bVertical)
         {
@@ -527,7 +523,7 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
     return succeeded;
 }
 
-bool D2DWriteTextOutRenderer::GetDWriteInkBox(SalLayout const &rLayout, Rectangle & rOut) const
+bool D2DWriteTextOutRenderer::GetDWriteInkBox(CommonSalLayout const &rLayout, Rectangle & rOut) const
 {
     rOut.SetEmpty();
 
@@ -551,11 +547,8 @@ bool D2DWriteTextOutRenderer::GetDWriteInkBox(SalLayout const &rLayout, Rectangl
     if (aBoxes.empty())
         return false;
 
-    bool bVertical = false;
     double nYDiff = 0.0f;
-    const CommonSalLayout* pCSL = dynamic_cast<const CommonSalLayout*>(&rLayout);
-    if (pCSL)
-        bVertical = pCSL->getFontSelData().mbVertical;
+    bool bVertical = rLayout.getFontSelData().mbVertical;
 
     if (bVertical)
     {


More information about the Libreoffice-commits mailing list