Kaydet (Commit) c5dc0422 authored tarafından Miklos Vajna's avatar Miklos Vajna

vcl: use SalLayoutGlyphs, not SalLayout for pre-computed layout

This means that the pre-computed glyph ids and positions are usable with
multiple dx array or draw base.

So the amount of cached data is smaller, but it can be used in more
situations, most importantly Writer's SwFntObj::DrawText() use-case
(which does GetTextArray() followed by a DrawTextArray(), with different
dx array arguments).

Change-Id: I3bcd1b7a015c2cf9921efa0f3f355f2c627fb652
Reviewed-on: https://gerrit.libreoffice.org/59207Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst 24a30e5b
...@@ -976,7 +976,7 @@ public: ...@@ -976,7 +976,7 @@ public:
void DrawText( const Point& rStartPt, const OUString& rStr, void DrawText( const Point& rStartPt, const OUString& rStr,
sal_Int32 nIndex = 0, sal_Int32 nLen = -1, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
MetricVector* pVector = nullptr, OUString* pDisplayText = nullptr, MetricVector* pVector = nullptr, OUString* pDisplayText = nullptr,
SalLayout* pLayoutCache = nullptr ); const SalLayoutGlyphs* pLayoutCache = nullptr );
void DrawText( const tools::Rectangle& rRect, void DrawText( const tools::Rectangle& rRect,
const OUString& rStr, DrawTextFlags nStyle = DrawTextFlags::NONE, const OUString& rStr, DrawTextFlags nStyle = DrawTextFlags::NONE,
...@@ -1138,7 +1138,7 @@ public: ...@@ -1138,7 +1138,7 @@ public:
*/ */
long GetTextWidth( const OUString& rStr, sal_Int32 nIndex = 0, sal_Int32 nLen = -1, long GetTextWidth( const OUString& rStr, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
vcl::TextLayoutCache const* = nullptr, vcl::TextLayoutCache const* = nullptr,
SalLayout const*const pLayoutCache = nullptr) const; SalLayoutGlyphs const*const pLayoutCache = nullptr) const;
/** Height where any character of the current font fits; in logic coordinates. /** Height where any character of the current font fits; in logic coordinates.
...@@ -1154,11 +1154,11 @@ public: ...@@ -1154,11 +1154,11 @@ public:
sal_Int32 nLen = -1, sal_Int32 nLen = -1,
SalLayoutFlags flags = SalLayoutFlags::NONE, SalLayoutFlags flags = SalLayoutFlags::NONE,
vcl::TextLayoutCache const* = nullptr, vcl::TextLayoutCache const* = nullptr,
SalLayout* pLayoutCache = nullptr); const SalLayoutGlyphs* pLayoutCache = nullptr);
long GetTextArray( const OUString& rStr, long* pDXAry, long GetTextArray( const OUString& rStr, long* pDXAry,
sal_Int32 nIndex = 0, sal_Int32 nLen = -1, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
vcl::TextLayoutCache const* = nullptr, vcl::TextLayoutCache const* = nullptr,
SalLayout const*const pLayoutCache = nullptr) const; SalLayoutGlyphs const*const pLayoutCache = nullptr) const;
void GetCaretPositions( const OUString&, long* pCaretXArray, void GetCaretPositions( const OUString&, long* pCaretXArray,
sal_Int32 nIndex, sal_Int32 nLen ) const; sal_Int32 nIndex, sal_Int32 nLen ) const;
......
...@@ -159,7 +159,7 @@ public: ...@@ -159,7 +159,7 @@ public:
virtual std::shared_ptr<vcl::TextLayoutCache> virtual std::shared_ptr<vcl::TextLayoutCache>
CreateTextLayoutCache(OUString const&) const; CreateTextLayoutCache(OUString const&) const;
virtual SalLayoutGlyphs GetGlyphs() const; virtual const SalLayoutGlyphs* GetGlyphs() const;
protected: protected:
// used by layout engines // used by layout engines
......
...@@ -175,7 +175,7 @@ public: ...@@ -175,7 +175,7 @@ public:
bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphs*) final override; bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphs*) final override;
void DrawText(SalGraphics&) const final override; void DrawText(SalGraphics&) const final override;
std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&) const final override; std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&) const final override;
SalLayoutGlyphs GetGlyphs() const final override; const SalLayoutGlyphs* GetGlyphs() const final override;
bool IsKashidaPosValid(int nCharPos) const final override; bool IsKashidaPosValid(int nCharPos) const final override;
......
...@@ -169,9 +169,9 @@ std::shared_ptr<vcl::TextLayoutCache> GenericSalLayout::CreateTextLayoutCache(OU ...@@ -169,9 +169,9 @@ std::shared_ptr<vcl::TextLayoutCache> GenericSalLayout::CreateTextLayoutCache(OU
return std::make_shared<vcl::TextLayoutCache>(rString.getStr(), rString.getLength()); return std::make_shared<vcl::TextLayoutCache>(rString.getStr(), rString.getLength());
} }
SalLayoutGlyphs GenericSalLayout::GetGlyphs() const const SalLayoutGlyphs* GenericSalLayout::GetGlyphs() const
{ {
return m_GlyphItems; return &m_GlyphItems;
} }
void GenericSalLayout::SetNeedFallback(ImplLayoutArgs& rArgs, sal_Int32 nCharPos, bool bRightToLeft) void GenericSalLayout::SetNeedFallback(ImplLayoutArgs& rArgs, sal_Int32 nCharPos, bool bRightToLeft)
......
...@@ -1579,10 +1579,10 @@ std::shared_ptr<vcl::TextLayoutCache> SalLayout::CreateTextLayoutCache( ...@@ -1579,10 +1579,10 @@ std::shared_ptr<vcl::TextLayoutCache> SalLayout::CreateTextLayoutCache(
return nullptr; // by default, nothing to cache return nullptr; // by default, nothing to cache
} }
SalLayoutGlyphs SalLayout::GetGlyphs() const const SalLayoutGlyphs* SalLayout::GetGlyphs() const
{ {
// No access to the glyphs by default. // No access to the glyphs by default.
return SalLayoutGlyphs(); return nullptr;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -788,7 +788,7 @@ void OutputDevice::SetTextAlign( TextAlign eAlign ) ...@@ -788,7 +788,7 @@ void OutputDevice::SetTextAlign( TextAlign eAlign )
void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
sal_Int32 nIndex, sal_Int32 nLen, sal_Int32 nIndex, sal_Int32 nLen,
MetricVector* pVector, OUString* pDisplayText, MetricVector* pVector, OUString* pDisplayText,
SalLayout* pLayoutCache const SalLayoutGlyphs* pLayoutCache
) )
{ {
assert(!is_double_buffered_window()); assert(!is_double_buffered_window());
...@@ -873,27 +873,10 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, ...@@ -873,27 +873,10 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
pLayoutCache = nullptr; pLayoutCache = nullptr;
#endif #endif
// without cache std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, nullptr, SalLayoutFlags::NONE, nullptr, pLayoutCache);
if(!pLayoutCache) if(pSalLayout)
{ {
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt); ImplDrawText( *pSalLayout );
if(pSalLayout)
{
ImplDrawText( *pSalLayout );
}
}
else
{
// initialize font if needed
if( mbNewFont )
if( !ImplNewFont() )
return;
if( mbInitFont )
InitFont();
pLayoutCache->DrawBase() = ImplLogicToDevicePixel( rStartPt );
ImplDrawText( *pLayoutCache );
} }
if( mpAlphaVDev ) if( mpAlphaVDev )
...@@ -902,7 +885,7 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr, ...@@ -902,7 +885,7 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen, long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen,
vcl::TextLayoutCache const*const pLayoutCache, vcl::TextLayoutCache const*const pLayoutCache,
SalLayout const*const pSalLayoutCache) const SalLayoutGlyphs const*const pSalLayoutCache) const
{ {
long nWidth = GetTextArray( rStr, nullptr, nIndex, long nWidth = GetTextArray( rStr, nullptr, nIndex,
...@@ -946,7 +929,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, ...@@ -946,7 +929,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
const long* pDXAry, const long* pDXAry,
sal_Int32 nIndex, sal_Int32 nLen, SalLayoutFlags flags, sal_Int32 nIndex, sal_Int32 nLen, SalLayoutFlags flags,
vcl::TextLayoutCache const*const pLayoutCache, vcl::TextLayoutCache const*const pLayoutCache,
SalLayout* pSalLayoutCache ) const SalLayoutGlyphs* pSalLayoutCache )
{ {
assert(!is_double_buffered_window()); assert(!is_double_buffered_window());
...@@ -966,13 +949,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, ...@@ -966,13 +949,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
if( mbOutputClipped ) if( mbOutputClipped )
return; return;
SalLayout* pSalLayout = pSalLayoutCache; std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags, pLayoutCache, pSalLayoutCache);
std::unique_ptr<SalLayout> pLayout;
if (!pSalLayout)
{
pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags, pLayoutCache);
pSalLayout = pLayout.get();
}
if( pSalLayout ) if( pSalLayout )
{ {
ImplDrawText( *pSalLayout ); ImplDrawText( *pSalLayout );
...@@ -985,7 +962,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr, ...@@ -985,7 +962,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
sal_Int32 nIndex, sal_Int32 nLen, sal_Int32 nIndex, sal_Int32 nLen,
vcl::TextLayoutCache const*const pLayoutCache, vcl::TextLayoutCache const*const pLayoutCache,
SalLayout const*const pSalLayoutCache) const SalLayoutGlyphs const*const pSalLayoutCache) const
{ {
if( nIndex >= rStr.getLength() ) if( nIndex >= rStr.getLength() )
return 0; // TODO: this looks like a buggy caller? return 0; // TODO: this looks like a buggy caller?
...@@ -995,29 +972,22 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, ...@@ -995,29 +972,22 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
nLen = rStr.getLength() - nIndex; nLen = rStr.getLength() - nIndex;
} }
std::unique_ptr<SalLayout> xSalLayout; // do layout
const SalLayout* pSalLayout = pSalLayoutCache; std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen,
Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache, pSalLayoutCache);
if(!pSalLayoutCache) if( !pSalLayout )
{ {
// do layout // The caller expects this to init the elements of pDXAry.
xSalLayout = ImplLayout(rStr, nIndex, nLen, // Adapting all the callers to check that GetTextArray succeeded seems
Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache); // too much work.
pSalLayout = xSalLayout.get(); // Init here to 0 only in the (rare) error case, so that any missing
if( !pSalLayout ) // element init in the happy case will still be found by tools,
// and hope that is sufficient.
if (pDXAry)
{ {
// The caller expects this to init the elements of pDXAry. memset(pDXAry, 0, nLen * sizeof(*pDXAry));
// Adapting all the callers to check that GetTextArray succeeded seems
// too much work.
// Init here to 0 only in the (rare) error case, so that any missing
// element init in the happy case will still be found by tools,
// and hope that is sufficient.
if (pDXAry)
{
memset(pDXAry, 0, nLen * sizeof(*pDXAry));
}
return 0;
} }
return 0;
} }
#if VCL_FLOAT_DEVICE_PIXEL #if VCL_FLOAT_DEVICE_PIXEL
......
...@@ -408,7 +408,8 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen ...@@ -408,7 +408,8 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
pLayoutCache = pItem->mxLayoutCache.get(); pLayoutCache = pItem->mxLayoutCache.get();
} }
Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,pLayoutCache), rRenderContext.GetTextHeight()); const SalLayoutGlyphs* pGlyphs = pLayoutCache ? pLayoutCache->GetGlyphs() : nullptr;
Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,pGlyphs), rRenderContext.GetTextHeight());
Point aTextPos = ImplGetItemTextPos(aTextRectSize, aTextSize, pItem->mnBits); Point aTextPos = ImplGetItemTextPos(aTextRectSize, aTextSize, pItem->mnBits);
...@@ -418,7 +419,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen ...@@ -418,7 +419,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
aTextPos, aTextPos,
pItem->maText, pItem->maText,
0, -1, nullptr, nullptr, 0, -1, nullptr, nullptr,
pLayoutCache ); pGlyphs );
} }
else else
{ {
...@@ -428,7 +429,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen ...@@ -428,7 +429,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
aTextPos, aTextPos,
pItem->maText, pItem->maText,
0, -1, nullptr, nullptr, 0, -1, nullptr, nullptr,
pLayoutCache ); pGlyphs );
} }
// call DrawItem if necessary // call DrawItem if necessary
...@@ -1192,7 +1193,8 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText ) ...@@ -1192,7 +1193,8 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
long nFudge = GetTextHeight()/4; long nFudge = GetTextHeight()/4;
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(pItem->maText,0,-1); std::unique_ptr<SalLayout> pSalLayout = ImplLayout(pItem->maText,0,-1);
long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pSalLayout.get() ) + nFudge; const SalLayoutGlyphs* pGlyphs = pSalLayout ? pSalLayout->GetGlyphs() : nullptr;
long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pGlyphs ) + nFudge;
// Store the calculated layout. // Store the calculated layout.
pItem->mxLayoutCache = std::move(pSalLayout); pItem->mxLayoutCache = std::move(pSalLayout);
......
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