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

vcl: introduce a SalLayoutFlags::GlyphItemsOnly

OutputDevice::ImplLayout() does a number of things: first it calls the
expensive SalLayout::LayoutText(), then it does a number of remaing
tweaks to the resulting SalLayout based on the rLogicalPos and pDXArray
parameters.

This means that the resulting layout is not easy to reuse for Writer
purposes, as it typically operates with the same text multiple times,
but with different LogicalPos/DXArray.

Add a new flag that returns the glyph items early, with the hope that
this way the result only depends on the output device state and the
string only, nothing else.

Change-Id: I7c4a23d0f230495c8ba0ebbd1cfc3421e4a6e43c
Reviewed-on: https://gerrit.libreoffice.org/59159Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst 0a99baa1
......@@ -142,10 +142,11 @@ enum class SalLayoutFlags
SubstituteDigits = 0x0400,
KashidaJustification = 0x0800,
ForFallback = 0x2000,
GlyphItemsOnly = 0x4000,
};
namespace o3tl
{
template<> struct typed_flags<SalLayoutFlags> : is_typed_flags<SalLayoutFlags, 0x2e77> {};
template<> struct typed_flags<SalLayoutFlags> : is_typed_flags<SalLayoutFlags, 0x6e77> {};
}
typedef std::vector< tools::Rectangle > MetricVector;
......
......@@ -21,6 +21,7 @@
#define INCLUDED_VCL_VCLLAYOUT_HXX
#include <memory>
#include <vector>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <tools/gen.hxx>
......@@ -30,12 +31,65 @@
class ImplLayoutArgs;
class PhysicalFontFace;
class SalGraphics;
struct GlyphItem;
namespace vcl
{
class TextLayoutCache;
}
typedef sal_uInt16 sal_GlyphId;
struct VCL_DLLPUBLIC GlyphItem
{
int mnFlags;
int mnCharPos; // index in string
int mnCharCount; // number of characters making up this glyph
int mnOrigWidth; // original glyph width
int mnNewWidth; // width after adjustments
int mnXOffset;
sal_GlyphId maGlyphId;
Point maLinearPos; // absolute position of non rotated string
int mnFallbackLevel;
public:
GlyphItem(int nCharPos, int nCharCount, sal_GlyphId aGlyphId, const Point& rLinearPos,
long nFlags, int nOrigWidth, int nXOffset )
: mnFlags(nFlags)
, mnCharPos(nCharPos)
, mnCharCount(nCharCount)
, mnOrigWidth(nOrigWidth)
, mnNewWidth(nOrigWidth)
, mnXOffset(nXOffset)
, maGlyphId(aGlyphId)
, maLinearPos(rLinearPos)
, mnFallbackLevel(0)
{ }
enum {
IS_IN_CLUSTER = 0x001,
IS_RTL_GLYPH = 0x002,
IS_DIACRITIC = 0x004,
IS_VERTICAL = 0x008,
IS_SPACING = 0x010,
ALLOW_KASHIDA = 0x020,
IS_DROPPED = 0x040,
IS_CLUSTER_START = 0x080
};
bool IsInCluster() const { return ((mnFlags & IS_IN_CLUSTER) != 0); }
bool IsRTLGlyph() const { return ((mnFlags & IS_RTL_GLYPH) != 0); }
bool IsDiacritic() const { return ((mnFlags & IS_DIACRITIC) != 0); }
bool IsVertical() const { return ((mnFlags & IS_VERTICAL) != 0); }
bool IsSpacing() const { return ((mnFlags & IS_SPACING) != 0); }
bool AllowKashida() const { return ((mnFlags & ALLOW_KASHIDA) != 0); }
bool IsDropped() const { return ((mnFlags & IS_DROPPED) != 0); }
bool IsClusterStart() const { return ((mnFlags & IS_CLUSTER_START) != 0); }
};
typedef std::vector<GlyphItem> SalLayoutGlyphs;
// all positions/widths are in font units
// one exception: drawposition is in pixel units
......@@ -105,6 +159,7 @@ public:
virtual std::shared_ptr<vcl::TextLayoutCache>
CreateTextLayoutCache(OUString const&) const;
virtual SalLayoutGlyphs GetGlyphs() const;
protected:
// used by layout engines
......
......@@ -165,58 +165,6 @@ private:
bool mbIncomplete;
};
typedef sal_uInt16 sal_GlyphId;
struct GlyphItem
{
int mnFlags;
int mnCharPos; // index in string
int mnCharCount; // number of characters making up this glyph
int mnOrigWidth; // original glyph width
int mnNewWidth; // width after adjustments
int mnXOffset;
sal_GlyphId maGlyphId;
Point maLinearPos; // absolute position of non rotated string
int mnFallbackLevel;
public:
GlyphItem(int nCharPos, int nCharCount, sal_GlyphId aGlyphId, const Point& rLinearPos,
long nFlags, int nOrigWidth, int nXOffset )
: mnFlags(nFlags)
, mnCharPos(nCharPos)
, mnCharCount(nCharCount)
, mnOrigWidth(nOrigWidth)
, mnNewWidth(nOrigWidth)
, mnXOffset(nXOffset)
, maGlyphId(aGlyphId)
, maLinearPos(rLinearPos)
, mnFallbackLevel(0)
{ }
enum {
IS_IN_CLUSTER = 0x001,
IS_RTL_GLYPH = 0x002,
IS_DIACRITIC = 0x004,
IS_VERTICAL = 0x008,
IS_SPACING = 0x010,
ALLOW_KASHIDA = 0x020,
IS_DROPPED = 0x040,
IS_CLUSTER_START = 0x080
};
bool IsInCluster() const { return ((mnFlags & IS_IN_CLUSTER) != 0); }
bool IsRTLGlyph() const { return ((mnFlags & IS_RTL_GLYPH) != 0); }
bool IsDiacritic() const { return ((mnFlags & IS_DIACRITIC) != 0); }
bool IsVertical() const { return ((mnFlags & IS_VERTICAL) != 0); }
bool IsSpacing() const { return ((mnFlags & IS_SPACING) != 0); }
bool AllowKashida() const { return ((mnFlags & ALLOW_KASHIDA) != 0); }
bool IsDropped() const { return ((mnFlags & IS_DROPPED) != 0); }
bool IsClusterStart() const { return ((mnFlags & IS_CLUSTER_START) != 0); }
};
class VCL_PLUGIN_PUBLIC GenericSalLayout : public SalLayout
{
public:
......@@ -227,6 +175,7 @@ public:
bool LayoutText(ImplLayoutArgs&) final override;
void DrawText(SalGraphics&) const final override;
std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&) const final override;
SalLayoutGlyphs GetGlyphs() const final override;
bool IsKashidaPosValid(int nCharPos) const final override;
......@@ -267,7 +216,7 @@ private:
rtl::Reference<LogicalFontInstance> const mpFont;
css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
std::vector<GlyphItem> m_GlyphItems;
SalLayoutGlyphs m_GlyphItems;
OString msLanguage;
std::vector<hb_feature_t> maFeatures;
......
......@@ -169,6 +169,11 @@ std::shared_ptr<vcl::TextLayoutCache> GenericSalLayout::CreateTextLayoutCache(OU
return std::make_shared<vcl::TextLayoutCache>(rString.getStr(), rString.getLength());
}
SalLayoutGlyphs GenericSalLayout::GetGlyphs() const
{
return m_GlyphItems;
}
void GenericSalLayout::SetNeedFallback(ImplLayoutArgs& rArgs, sal_Int32 nCharPos, bool bRightToLeft)
{
if (nCharPos < 0 || mbFuzzing)
......
......@@ -1579,4 +1579,10 @@ std::shared_ptr<vcl::TextLayoutCache> SalLayout::CreateTextLayoutCache(
return nullptr; // by default, nothing to cache
}
SalLayoutGlyphs SalLayout::GetGlyphs() const
{
// No access to the glyphs by default.
return SalLayoutGlyphs();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -1360,6 +1360,9 @@ std::unique_ptr<SalLayout> OutputDevice::ImplLayout(const OUString& rOrigStr,
if( !pSalLayout )
return nullptr;
if (flags & SalLayoutFlags::GlyphItemsOnly)
return pSalLayout;
// do glyph fallback if needed
// #105768# avoid fallback for very small font sizes
if (aLayoutArgs.NeedFallback() && mpFontInstance->GetFontSelectPattern().mnHeight >= 3)
......
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