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

[harfbuzz] Fix text width calculation for real

No more second guessing if text width, we know that information already,
so pass it around instead of trying to re-create it.

Change-Id: I19faacbc309d38753c3c9f7214dfa0bf59cc66b5
üst 2e302f18
...@@ -76,33 +76,9 @@ long ServerFontLayout::GetTextWidth() const ...@@ -76,33 +76,9 @@ long ServerFontLayout::GetTextWidth() const
{ {
long nWidth; long nWidth;
if (bUseHarfBuzz) if (bUseHarfBuzz)
{ nWidth = GetWidth();
GlyphVector aGlyphItems = GenericSalLayout::GetGlyphItems();
if( aGlyphItems.empty() )
return 0;
// initialize the extent
long nMinPos = 0;
long nMaxPos = 0;
for( GlyphVector::const_iterator pG = aGlyphItems.begin(), end = aGlyphItems.end(); pG != end ; ++pG )
{
// update the text extent with the glyph extent
long nXPos = pG->maLinearPos.X();
if( nMinPos > nXPos )
nMinPos = nXPos;
nXPos += pG->mnOrigWidth;
if( nMaxPos < nXPos )
nMaxPos = nXPos;
}
nWidth = nMaxPos - nMinPos;
}
else else
{
nWidth = GenericSalLayout::GetTextWidth(); nWidth = GenericSalLayout::GetTextWidth();
}
return nWidth; return nWidth;
} }
...@@ -448,9 +424,6 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) ...@@ -448,9 +424,6 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs)
continue; continue;
} }
const GlyphMetric& rGM = rFont.GetGlyphMetric(nGlyphIndex);
int nGlyphWidth = rGM.GetCharWidth();
long nGlyphFlags = 0; long nGlyphFlags = 0;
if (bRightToLeft) if (bRightToLeft)
nGlyphFlags |= GlyphItem::IS_RTL_GLYPH; nGlyphFlags |= GlyphItem::IS_RTL_GLYPH;
...@@ -473,10 +446,7 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) ...@@ -473,10 +446,7 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs)
int32_t nYAdvance = pHbPositions[i].y_advance >> 6; int32_t nYAdvance = pHbPositions[i].y_advance >> 6;
Point aNewPos = Point(aCurrPos.X() + nXOffset, -(aCurrPos.Y() + nYOffset)); Point aNewPos = Point(aCurrPos.X() + nXOffset, -(aCurrPos.Y() + nYOffset));
const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance);
GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nGlyphWidth);
aGI.mnNewWidth = nXAdvance;
rLayout.AppendGlyph(aGI); rLayout.AppendGlyph(aGI);
aCurrPos.X() += nXAdvance; aCurrPos.X() += nXAdvance;
...@@ -485,6 +455,7 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) ...@@ -485,6 +455,7 @@ bool HbLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs)
hb_buffer_destroy(pHbBuffer); hb_buffer_destroy(pHbBuffer);
} }
rLayout.SetWidth(aCurrPos.X());
hb_font_destroy(pHbFont); hb_font_destroy(pHbFont);
......
...@@ -319,6 +319,7 @@ private: ...@@ -319,6 +319,7 @@ private:
SAL_DLLPRIVATE ServerFontLayout& operator=( const ServerFontLayout& ); SAL_DLLPRIVATE ServerFontLayout& operator=( const ServerFontLayout& );
bool bUseHarfBuzz; bool bUseHarfBuzz;
long mnTextWidth;
public: public:
ServerFontLayout( ServerFont& ); ServerFontLayout( ServerFont& );
...@@ -328,6 +329,10 @@ public: ...@@ -328,6 +329,10 @@ public:
virtual void DrawText( SalGraphics& ) const; virtual void DrawText( SalGraphics& ) const;
virtual long GetTextWidth() const; virtual long GetTextWidth() const;
ServerFont& GetServerFont() const { return mrServerFont; } ServerFont& GetServerFont() const { return mrServerFont; }
// used by layout engine
void SetWidth( long nWidth ) { mnTextWidth = nWidth; }
long GetWidth() const { return mnTextWidth; }
}; };
// ======================================================================= // =======================================================================
......
...@@ -367,8 +367,6 @@ protected: ...@@ -367,8 +367,6 @@ protected:
bool GetCharWidths( sal_Int32* pCharWidths ) const; bool GetCharWidths( sal_Int32* pCharWidths ) const;
GlyphVector GetGlyphItems() const { return m_GlyphItems; }
private: private:
GlyphVector m_GlyphItems; GlyphVector m_GlyphItems;
mutable Point maBasePoint; mutable Point maBasePoint;
......
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