Kaydet (Commit) f0393d7f authored tarafından Khaled Hosny's avatar Khaled Hosny

[harfbuzz] Fix text width calculation, 3rd try

It turns out storing the width in the layout is not so good idea,
because in some mysterious cases when font fallback is involved we call
GetTextWidth() without calling LayoutText() first, and we return the
width of the previous text run.

It seems all I needed is to pass down the X offset with the glyph item,
and take it into account when calculating the width.

Change-Id: Idbdb6bba00573fb6ca773701757d667e21ac0912
üst 64fc186b
......@@ -72,17 +72,6 @@ bool ServerFontLayout::LayoutText( ImplLayoutArgs& rArgs )
}
// -----------------------------------------------------------------------
long ServerFontLayout::GetTextWidth() const
{
long nWidth;
if (bUseHarfBuzz)
nWidth = GetWidth();
else
nWidth = GenericSalLayout::GetTextWidth();
return nWidth;
}
void ServerFontLayout::AdjustLayout( ImplLayoutArgs& rArgs )
{
GenericSalLayout::AdjustLayout( rArgs );
......@@ -524,7 +513,7 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs)
int32_t nYAdvance = pHbPositions[i].y_advance >> 6;
Point aNewPos = Point(aCurrPos.X() + nXOffset, -(aCurrPos.Y() + nYOffset));
const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance);
const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance, nXOffset);
rLayout.AppendGlyph(aGI);
aCurrPos.X() += nXAdvance;
......@@ -533,7 +522,6 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs)
hb_buffer_destroy(pHbBuffer);
}
rLayout.SetWidth(aCurrPos.X());
hb_font_destroy(pHbFont);
......
......@@ -317,7 +317,6 @@ private:
SAL_DLLPRIVATE ServerFontLayout& operator=( const ServerFontLayout& );
bool bUseHarfBuzz;
long mnTextWidth;
public:
ServerFontLayout( ServerFont& );
......@@ -325,12 +324,7 @@ public:
virtual void AdjustLayout( ImplLayoutArgs& );
virtual void ApplyDXArray( ImplLayoutArgs& );
virtual void DrawText( SalGraphics& ) const;
virtual long GetTextWidth() const;
ServerFont& GetServerFont() const { return mrServerFont; }
// used by layout engine
void SetWidth( long nWidth ) { mnTextWidth = nWidth; }
long GetWidth() const { return mnTextWidth; }
};
// =======================================================================
......
......@@ -310,6 +310,7 @@ struct GlyphItem
int mnCharPos; // index in string
int mnOrigWidth; // original glyph width
int mnNewWidth; // width after adjustments
int mnXOffset;
sal_GlyphId mnGlyphIndex;
Point maLinearPos; // absolute position of non rotated string
......@@ -320,9 +321,19 @@ public:
long nFlags, int nOrigWidth )
: mnFlags(nFlags), mnCharPos(nCharPos),
mnOrigWidth(nOrigWidth), mnNewWidth(nOrigWidth),
mnXOffset(0),
mnGlyphIndex(nGlyphIndex), maLinearPos(rLinearPos)
{}
GlyphItem( int nCharPos, sal_GlyphId nGlyphIndex, const Point& rLinearPos,
long nFlags, int nOrigWidth, int nXOffset )
: mnFlags(nFlags), mnCharPos(nCharPos),
mnOrigWidth(nOrigWidth), mnNewWidth(nOrigWidth),
mnXOffset(nXOffset),
mnGlyphIndex(nGlyphIndex), maLinearPos(rLinearPos)
{}
enum{ FALLBACK_MASK=0xFF, IS_IN_CLUSTER=0x100, IS_RTL_GLYPH=0x200, IS_DIACRITIC=0x400 };
bool IsClusterStart() const { return ((mnFlags & IS_IN_CLUSTER) == 0); }
......
......@@ -996,7 +996,7 @@ long GenericSalLayout::GetTextWidth() const
long nXPos = pG->maLinearPos.X();
if( nMinPos > nXPos )
nMinPos = nXPos;
nXPos += pG->mnNewWidth;
nXPos += pG->mnNewWidth - pG->mnXOffset;
if( nMaxPos < nXPos )
nMaxPos = nXPos;
}
......
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