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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 30 11:46:14 UTC 2018


 vcl/inc/impglyphitem.hxx           |   24 +++++++++++++++++++++---
 vcl/inc/sallayout.hxx              |    4 ++--
 vcl/source/gdi/CommonSalLayout.cxx |   21 ++++++++++-----------
 vcl/source/gdi/impglyphitem.cxx    |   16 +++++++++++++---
 4 files changed, 46 insertions(+), 19 deletions(-)

New commits:
commit 71507ba3eb4bc6e8b36cd66b865c49a1b66b787e
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Mon Oct 29 13:32:03 2018 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Tue Oct 30 12:45:47 2018 +0100

    tdf#120982 add font reference to SalLayoutGlyphsImpl
    
    Now that we store the LogicalFontInstance instead of the fallback
    level, it's not enough to keep a pointer in the glyphs in
    SalLayoutGlyphsImpl. We also need a reference to the font, to
    keep the font instance alive.
    
    Change-Id: Idc99cf9259af6be672a97ab2c67dbffd9cf29c70
    Reviewed-on: https://gerrit.libreoffice.org/62520
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/impglyphitem.hxx b/vcl/inc/impglyphitem.hxx
index 7c5dc66d1d8b..d4c944717419 100644
--- a/vcl/inc/impglyphitem.hxx
+++ b/vcl/inc/impglyphitem.hxx
@@ -92,11 +92,29 @@ VCL_DLLPUBLIC void GlyphItem::CacheGlyphBoundRect(tools::Rectangle& rRect) const
 
 class SalLayoutGlyphsImpl : public std::vector<GlyphItem>
 {
-    friend class GenericSalLayout;
-    friend class SalLayoutGlyphs;
+protected:
     void SetPImpl(SalLayoutGlyphs* pFacade) { pFacade->m_pImpl = this; }
 
-    SalLayoutGlyphsImpl(SalLayoutGlyphs& rGlyphs) { SetPImpl(&rGlyphs); }
+public:
+    virtual ~SalLayoutGlyphsImpl();
+    virtual SalLayoutGlyphsImpl* clone(SalLayoutGlyphs&) const = 0;
+};
+
+class SalGenericLayoutGlyphsImpl : public SalLayoutGlyphsImpl
+{
+    friend class GenericSalLayout;
+
+    const rtl::Reference<LogicalFontInstance> m_rFontInstance;
+
+    SalGenericLayoutGlyphsImpl(SalLayoutGlyphs& rGlyphs, LogicalFontInstance& rFontInstance)
+        : m_rFontInstance(&rFontInstance)
+    {
+        SetPImpl(&rGlyphs);
+    }
+
+public:
+    SalLayoutGlyphsImpl* clone(SalLayoutGlyphs& rGlyphs) const override;
+    LogicalFontInstance& GetFont() const { return *m_rFontInstance; }
 };
 
 #endif // INCLUDED_VCL_IMPGLYPHITEM_HXX
diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx
index 972631d838e8..56c25f9d70c4 100644
--- a/vcl/inc/sallayout.hxx
+++ b/vcl/inc/sallayout.hxx
@@ -181,7 +181,8 @@ public:
     void            GetCaretPositions(int nArraySize, long* pCaretXArray) const final override;
 
     // used by display layers
-    LogicalFontInstance& GetFont() const { return *mpFont; }
+    LogicalFontInstance& GetFont() const
+        { return static_cast<SalGenericLayoutGlyphsImpl*>(m_GlyphItems.Impl())->GetFont(); }
 
     bool            GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
                                  const PhysicalFontFace** pFallbackFont = nullptr,
@@ -208,7 +209,6 @@ private:
 
     void            ParseFeatures(const OUString& name);
 
-    rtl::Reference<LogicalFontInstance> const mpFont;
     css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
 
     SalLayoutGlyphs m_GlyphItems;
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 0fc540fcb823..21d4d1c22ad3 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -57,11 +57,10 @@ static hb_unicode_funcs_t* getUnicodeFuncs()
 #endif
 
 GenericSalLayout::GenericSalLayout(LogicalFontInstance &rFont)
-    : mpFont(&rFont)
-    , mpVertGlyphs(nullptr)
+    : mpVertGlyphs(nullptr)
     , mbFuzzing(utl::ConfigManager::IsFuzzing())
 {
-    new SalLayoutGlyphsImpl(m_GlyphItems);
+    new SalGenericLayoutGlyphsImpl(m_GlyphItems, rFont);
 }
 
 GenericSalLayout::~GenericSalLayout()
@@ -230,7 +229,7 @@ void GenericSalLayout::DrawText(SalGraphics& rSalGraphics) const
 bool GenericSalLayout::HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aVariationSelector)
 {
     hb_codepoint_t nGlyphIndex = 0;
-    hb_font_t *pHbFont = mpFont->GetHbFont();
+    hb_font_t *pHbFont = GetFont().GetHbFont();
     if (!hb_font_get_glyph(pHbFont, aChar, aVariationSelector, &nGlyphIndex))
         return false;
 
@@ -277,7 +276,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
         return true;
     }
 
-    hb_font_t *pHbFont = mpFont->GetHbFont();
+    hb_font_t *pHbFont = GetFont().GetHbFont();
 
     int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos);
     m_GlyphItems.Impl()->reserve(nGlyphCapacity);
@@ -304,7 +303,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
     hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs);
 #endif
 
-    const FontSelectPattern& rFontSelData = mpFont->GetFontSelectPattern();
+    const FontSelectPattern& rFontSelData = GetFont().GetFontSelectPattern();
     if (rArgs.mnFlags & SalLayoutFlags::DisableKerning)
     {
         SAL_INFO("vcl.harfbuzz", "Disabling kerning for font: " << rFontSelData.maTargetName);
@@ -315,7 +314,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
 
     double nXScale = 0;
     double nYScale = 0;
-    mpFont->GetScale(&nXScale, &nYScale);
+    GetFont().GetScale(&nXScale, &nYScale);
 
     Point aCurrPos(0, 0);
     while (true)
@@ -571,7 +570,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
 
                 Point aNewPos(aCurrPos.X() + nXOffset, aCurrPos.Y() + nYOffset);
                 const GlyphItem aGI(nCharPos, nCharCount, nGlyphIndex, aNewPos, nGlyphFlags,
-                                    nAdvance, nXOffset, mpFont.get());
+                                    nAdvance, nXOffset, &GetFont());
                 m_GlyphItems.Impl()->push_back(aGI);
 
                 aCurrPos.AdjustX(nAdvance );
@@ -644,10 +643,10 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs)
     hb_codepoint_t nKashidaIndex = 0;
     if (rArgs.mnFlags & SalLayoutFlags::KashidaJustification)
     {
-        hb_font_t *pHbFont = mpFont->GetHbFont();
+        hb_font_t *pHbFont = GetFont().GetHbFont();
         // Find Kashida glyph width and index.
         if (hb_font_get_glyph(pHbFont, 0x0640, 0, &nKashidaIndex))
-            nKashidaWidth = mpFont->GetKashidaWidth();
+            nKashidaWidth = GetFont().GetKashidaWidth();
         bKashidaJustify = nKashidaWidth != 0;
     }
 
@@ -768,7 +767,7 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs)
             int const nFlags = GlyphItem::IS_IN_CLUSTER | GlyphItem::IS_RTL_GLYPH;
             while (nCopies--)
             {
-                GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, nKashidaWidth, 0, mpFont.get());
+                GlyphItem aKashida(nCharPos, 0, nKashidaIndex, aPos, nFlags, nKashidaWidth, 0, &GetFont());
                 pGlyphIter = m_GlyphItems.Impl()->insert(pGlyphIter, aKashida);
                 aPos.AdjustX(nKashidaWidth );
                 aPos.AdjustX( -nOverlap );
diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index ee30ee5ab2df..47125f6cd595 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -30,9 +30,10 @@ SalLayoutGlyphs::SalLayoutGlyphs(const SalLayoutGlyphs& rOther) { *m_pImpl = *rO
 
 SalLayoutGlyphs& SalLayoutGlyphs::operator=(const SalLayoutGlyphs& rOther)
 {
-    if (!m_pImpl)
-        m_pImpl = new SalLayoutGlyphsImpl(*this);
-    *m_pImpl = *rOther.m_pImpl;
+    if (m_pImpl)
+        *m_pImpl = *rOther.m_pImpl;
+    else
+        m_pImpl = rOther.m_pImpl->clone(*this);
     return *this;
 }
 
@@ -44,4 +45,13 @@ void SalLayoutGlyphs::clear()
         m_pImpl->clear();
 }
 
+SalLayoutGlyphsImpl::~SalLayoutGlyphsImpl() {}
+
+SalLayoutGlyphsImpl* SalGenericLayoutGlyphsImpl::clone(SalLayoutGlyphs& rGlyphs) const
+{
+    SalLayoutGlyphsImpl* pNew = new SalGenericLayoutGlyphsImpl(rGlyphs, *m_rFontInstance);
+    *pNew = *this;
+    return pNew;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list