Kaydet (Commit) 71507ba3 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

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: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst adf71090
...@@ -92,11 +92,29 @@ VCL_DLLPUBLIC void GlyphItem::CacheGlyphBoundRect(tools::Rectangle& rRect) const ...@@ -92,11 +92,29 @@ VCL_DLLPUBLIC void GlyphItem::CacheGlyphBoundRect(tools::Rectangle& rRect) const
class SalLayoutGlyphsImpl : public std::vector<GlyphItem> class SalLayoutGlyphsImpl : public std::vector<GlyphItem>
{ {
friend class GenericSalLayout; protected:
friend class SalLayoutGlyphs;
void SetPImpl(SalLayoutGlyphs* pFacade) { pFacade->m_pImpl = this; } 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 #endif // INCLUDED_VCL_IMPGLYPHITEM_HXX
......
...@@ -181,7 +181,8 @@ public: ...@@ -181,7 +181,8 @@ public:
void GetCaretPositions(int nArraySize, long* pCaretXArray) const final override; void GetCaretPositions(int nArraySize, long* pCaretXArray) const final override;
// used by display layers // 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, bool GetNextGlyph(const GlyphItem** pGlyph, Point& rPos, int& nStart,
const PhysicalFontFace** pFallbackFont = nullptr, const PhysicalFontFace** pFallbackFont = nullptr,
...@@ -208,7 +209,6 @@ private: ...@@ -208,7 +209,6 @@ private:
void ParseFeatures(const OUString& name); void ParseFeatures(const OUString& name);
rtl::Reference<LogicalFontInstance> const mpFont;
css::uno::Reference<css::i18n::XBreakIterator> mxBreak; css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
SalLayoutGlyphs m_GlyphItems; SalLayoutGlyphs m_GlyphItems;
......
...@@ -57,11 +57,10 @@ static hb_unicode_funcs_t* getUnicodeFuncs() ...@@ -57,11 +57,10 @@ static hb_unicode_funcs_t* getUnicodeFuncs()
#endif #endif
GenericSalLayout::GenericSalLayout(LogicalFontInstance &rFont) GenericSalLayout::GenericSalLayout(LogicalFontInstance &rFont)
: mpFont(&rFont) : mpVertGlyphs(nullptr)
, mpVertGlyphs(nullptr)
, mbFuzzing(utl::ConfigManager::IsFuzzing()) , mbFuzzing(utl::ConfigManager::IsFuzzing())
{ {
new SalLayoutGlyphsImpl(m_GlyphItems); new SalGenericLayoutGlyphsImpl(m_GlyphItems, rFont);
} }
GenericSalLayout::~GenericSalLayout() GenericSalLayout::~GenericSalLayout()
...@@ -230,7 +229,7 @@ void GenericSalLayout::DrawText(SalGraphics& rSalGraphics) const ...@@ -230,7 +229,7 @@ void GenericSalLayout::DrawText(SalGraphics& rSalGraphics) const
bool GenericSalLayout::HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aVariationSelector) bool GenericSalLayout::HasVerticalAlternate(sal_UCS4 aChar, sal_UCS4 aVariationSelector)
{ {
hb_codepoint_t nGlyphIndex = 0; 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)) if (!hb_font_get_glyph(pHbFont, aChar, aVariationSelector, &nGlyphIndex))
return false; return false;
...@@ -277,7 +276,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs* ...@@ -277,7 +276,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
return true; return true;
} }
hb_font_t *pHbFont = mpFont->GetHbFont(); hb_font_t *pHbFont = GetFont().GetHbFont();
int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos); int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos);
m_GlyphItems.Impl()->reserve(nGlyphCapacity); m_GlyphItems.Impl()->reserve(nGlyphCapacity);
...@@ -304,7 +303,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs* ...@@ -304,7 +303,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs); hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs);
#endif #endif
const FontSelectPattern& rFontSelData = mpFont->GetFontSelectPattern(); const FontSelectPattern& rFontSelData = GetFont().GetFontSelectPattern();
if (rArgs.mnFlags & SalLayoutFlags::DisableKerning) if (rArgs.mnFlags & SalLayoutFlags::DisableKerning)
{ {
SAL_INFO("vcl.harfbuzz", "Disabling kerning for font: " << rFontSelData.maTargetName); SAL_INFO("vcl.harfbuzz", "Disabling kerning for font: " << rFontSelData.maTargetName);
...@@ -315,7 +314,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs* ...@@ -315,7 +314,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
double nXScale = 0; double nXScale = 0;
double nYScale = 0; double nYScale = 0;
mpFont->GetScale(&nXScale, &nYScale); GetFont().GetScale(&nXScale, &nYScale);
Point aCurrPos(0, 0); Point aCurrPos(0, 0);
while (true) while (true)
...@@ -571,7 +570,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs* ...@@ -571,7 +570,7 @@ bool GenericSalLayout::LayoutText(ImplLayoutArgs& rArgs, const SalLayoutGlyphs*
Point aNewPos(aCurrPos.X() + nXOffset, aCurrPos.Y() + nYOffset); Point aNewPos(aCurrPos.X() + nXOffset, aCurrPos.Y() + nYOffset);
const GlyphItem aGI(nCharPos, nCharCount, nGlyphIndex, aNewPos, nGlyphFlags, const GlyphItem aGI(nCharPos, nCharCount, nGlyphIndex, aNewPos, nGlyphFlags,
nAdvance, nXOffset, mpFont.get()); nAdvance, nXOffset, &GetFont());
m_GlyphItems.Impl()->push_back(aGI); m_GlyphItems.Impl()->push_back(aGI);
aCurrPos.AdjustX(nAdvance ); aCurrPos.AdjustX(nAdvance );
...@@ -644,10 +643,10 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs) ...@@ -644,10 +643,10 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs)
hb_codepoint_t nKashidaIndex = 0; hb_codepoint_t nKashidaIndex = 0;
if (rArgs.mnFlags & SalLayoutFlags::KashidaJustification) if (rArgs.mnFlags & SalLayoutFlags::KashidaJustification)
{ {
hb_font_t *pHbFont = mpFont->GetHbFont(); hb_font_t *pHbFont = GetFont().GetHbFont();
// Find Kashida glyph width and index. // Find Kashida glyph width and index.
if (hb_font_get_glyph(pHbFont, 0x0640, 0, &nKashidaIndex)) if (hb_font_get_glyph(pHbFont, 0x0640, 0, &nKashidaIndex))
nKashidaWidth = mpFont->GetKashidaWidth(); nKashidaWidth = GetFont().GetKashidaWidth();
bKashidaJustify = nKashidaWidth != 0; bKashidaJustify = nKashidaWidth != 0;
} }
...@@ -768,7 +767,7 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs) ...@@ -768,7 +767,7 @@ void GenericSalLayout::ApplyDXArray(ImplLayoutArgs& rArgs)
int const nFlags = GlyphItem::IS_IN_CLUSTER | GlyphItem::IS_RTL_GLYPH; int const nFlags = GlyphItem::IS_IN_CLUSTER | GlyphItem::IS_RTL_GLYPH;
while (nCopies--) 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); pGlyphIter = m_GlyphItems.Impl()->insert(pGlyphIter, aKashida);
aPos.AdjustX(nKashidaWidth ); aPos.AdjustX(nKashidaWidth );
aPos.AdjustX( -nOverlap ); aPos.AdjustX( -nOverlap );
......
...@@ -30,9 +30,10 @@ SalLayoutGlyphs::SalLayoutGlyphs(const SalLayoutGlyphs& rOther) { *m_pImpl = *rO ...@@ -30,9 +30,10 @@ SalLayoutGlyphs::SalLayoutGlyphs(const SalLayoutGlyphs& rOther) { *m_pImpl = *rO
SalLayoutGlyphs& SalLayoutGlyphs::operator=(const SalLayoutGlyphs& rOther) SalLayoutGlyphs& SalLayoutGlyphs::operator=(const SalLayoutGlyphs& rOther)
{ {
if (!m_pImpl) if (m_pImpl)
m_pImpl = new SalLayoutGlyphsImpl(*this); *m_pImpl = *rOther.m_pImpl;
*m_pImpl = *rOther.m_pImpl; else
m_pImpl = rOther.m_pImpl->clone(*this);
return *this; return *this;
} }
...@@ -44,4 +45,13 @@ void SalLayoutGlyphs::clear() ...@@ -44,4 +45,13 @@ void SalLayoutGlyphs::clear()
m_pImpl->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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment