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:
void DrawText( const Point& rStartPt, const OUString& rStr,
sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
MetricVector* pVector = nullptr, OUString* pDisplayText = nullptr,
SalLayout* pLayoutCache = nullptr );
const SalLayoutGlyphs* pLayoutCache = nullptr );
void DrawText( const tools::Rectangle& rRect,
const OUString& rStr, DrawTextFlags nStyle = DrawTextFlags::NONE,
......@@ -1138,7 +1138,7 @@ public:
*/
long GetTextWidth( const OUString& rStr, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
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.
......@@ -1154,11 +1154,11 @@ public:
sal_Int32 nLen = -1,
SalLayoutFlags flags = SalLayoutFlags::NONE,
vcl::TextLayoutCache const* = nullptr,
SalLayout* pLayoutCache = nullptr);
const SalLayoutGlyphs* pLayoutCache = nullptr);
long GetTextArray( const OUString& rStr, long* pDXAry,
sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
vcl::TextLayoutCache const* = nullptr,
SalLayout const*const pLayoutCache = nullptr) const;
SalLayoutGlyphs const*const pLayoutCache = nullptr) const;
void GetCaretPositions( const OUString&, long* pCaretXArray,
sal_Int32 nIndex, sal_Int32 nLen ) const;
......
......@@ -159,7 +159,7 @@ public:
virtual std::shared_ptr<vcl::TextLayoutCache>
CreateTextLayoutCache(OUString const&) const;
virtual SalLayoutGlyphs GetGlyphs() const;
virtual const SalLayoutGlyphs* GetGlyphs() const;
protected:
// used by layout engines
......
......@@ -175,7 +175,7 @@ public:
bool LayoutText(ImplLayoutArgs&, const SalLayoutGlyphs*) final override;
void DrawText(SalGraphics&) 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;
......
......@@ -169,9 +169,9 @@ std::shared_ptr<vcl::TextLayoutCache> GenericSalLayout::CreateTextLayoutCache(OU
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)
......
......@@ -1579,10 +1579,10 @@ std::shared_ptr<vcl::TextLayoutCache> SalLayout::CreateTextLayoutCache(
return nullptr; // by default, nothing to cache
}
SalLayoutGlyphs SalLayout::GetGlyphs() const
const SalLayoutGlyphs* SalLayout::GetGlyphs() const
{
// No access to the glyphs by default.
return SalLayoutGlyphs();
return nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -788,7 +788,7 @@ void OutputDevice::SetTextAlign( TextAlign eAlign )
void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
sal_Int32 nIndex, sal_Int32 nLen,
MetricVector* pVector, OUString* pDisplayText,
SalLayout* pLayoutCache
const SalLayoutGlyphs* pLayoutCache
)
{
assert(!is_double_buffered_window());
......@@ -873,27 +873,10 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
pLayoutCache = nullptr;
#endif
// without cache
if(!pLayoutCache)
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, nullptr, SalLayoutFlags::NONE, nullptr, pLayoutCache);
if(pSalLayout)
{
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt);
if(pSalLayout)
{
ImplDrawText( *pSalLayout );
}
}
else
{
// initialize font if needed
if( mbNewFont )
if( !ImplNewFont() )
return;
if( mbInitFont )
InitFont();
pLayoutCache->DrawBase() = ImplLogicToDevicePixel( rStartPt );
ImplDrawText( *pLayoutCache );
ImplDrawText( *pSalLayout );
}
if( mpAlphaVDev )
......@@ -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,
vcl::TextLayoutCache const*const pLayoutCache,
SalLayout const*const pSalLayoutCache) const
SalLayoutGlyphs const*const pSalLayoutCache) const
{
long nWidth = GetTextArray( rStr, nullptr, nIndex,
......@@ -946,7 +929,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
const long* pDXAry,
sal_Int32 nIndex, sal_Int32 nLen, SalLayoutFlags flags,
vcl::TextLayoutCache const*const pLayoutCache,
SalLayout* pSalLayoutCache )
const SalLayoutGlyphs* pSalLayoutCache )
{
assert(!is_double_buffered_window());
......@@ -966,13 +949,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
if( mbOutputClipped )
return;
SalLayout* pSalLayout = pSalLayoutCache;
std::unique_ptr<SalLayout> pLayout;
if (!pSalLayout)
{
pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags, pLayoutCache);
pSalLayout = pLayout.get();
}
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags, pLayoutCache, pSalLayoutCache);
if( pSalLayout )
{
ImplDrawText( *pSalLayout );
......@@ -985,7 +962,7 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
sal_Int32 nIndex, sal_Int32 nLen,
vcl::TextLayoutCache const*const pLayoutCache,
SalLayout const*const pSalLayoutCache) const
SalLayoutGlyphs const*const pSalLayoutCache) const
{
if( nIndex >= rStr.getLength() )
return 0; // TODO: this looks like a buggy caller?
......@@ -995,29 +972,22 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
nLen = rStr.getLength() - nIndex;
}
std::unique_ptr<SalLayout> xSalLayout;
const SalLayout* pSalLayout = pSalLayoutCache;
if(!pSalLayoutCache)
// do layout
std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen,
Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache, pSalLayoutCache);
if( !pSalLayout )
{
// do layout
xSalLayout = ImplLayout(rStr, nIndex, nLen,
Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache);
pSalLayout = xSalLayout.get();
if( !pSalLayout )
// The caller expects this to init the elements of 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)
{
// The caller expects this to init the elements of 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;
memset(pDXAry, 0, nLen * sizeof(*pDXAry));
}
return 0;
}
#if VCL_FLOAT_DEVICE_PIXEL
......
......@@ -408,7 +408,8 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
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);
......@@ -418,7 +419,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
aTextPos,
pItem->maText,
0, -1, nullptr, nullptr,
pLayoutCache );
pGlyphs );
}
else
{
......@@ -428,7 +429,7 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
aTextPos,
pItem->maText,
0, -1, nullptr, nullptr,
pLayoutCache );
pGlyphs );
}
// call DrawItem if necessary
......@@ -1192,7 +1193,8 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
long nFudge = GetTextHeight()/4;
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.
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