Kaydet (Commit) 8e33c9be authored tarafından Chris Sherlock's avatar Chris Sherlock Kaydeden (comit) Chris Sherlock

vcl: add GenericSalLayout::GetTextRect()

I have extended GlyphItem to also record the original and new height,
along with the y offset.

Change-Id: I1e9646a8f0d844951d5533d035d9a16dbc8e257c
Reviewed-on: https://gerrit.libreoffice.org/14216Reviewed-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
Tested-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
üst e31eb648
......@@ -514,7 +514,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, nXOffset);
const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance, nXOffset, nYAdvance, nYOffset);
rLayout.AppendGlyph(aGI);
aCurrPos.X() += nXAdvance;
......
......@@ -273,9 +273,15 @@ struct GlyphItem
{
int mnFlags;
int mnCharPos; // index in string
int mnOrigWidth; // original glyph width
int mnNewWidth; // width after adjustments
int mnXOffset;
int mnOrigHeight; // original glyph height
int mnNewHeight; // width after adjustments
int mnYOffset;
sal_GlyphId maGlyphId;
Point maLinearPos; // absolute position of non rotated string
......@@ -298,10 +304,12 @@ public:
{}
GlyphItem( int nCharPos, sal_GlyphId aGlyphId, const Point& rLinearPos,
long nFlags, int nOrigWidth, int nXOffset )
long nFlags, int nOrigWidth, int nXOffset, int nOrigHeight, int nYOffset )
: mnFlags(nFlags), mnCharPos(nCharPos),
mnOrigWidth(nOrigWidth), mnNewWidth(nOrigWidth),
mnXOffset(nXOffset),
mnOrigHeight(nOrigHeight), mnNewHeight(nOrigHeight),
mnYOffset(nYOffset),
maGlyphId(aGlyphId), maLinearPos(rLinearPos)
{}
......@@ -330,6 +338,7 @@ public:
// used by upper layers
virtual DeviceCoordinate GetTextWidth() const SAL_OVERRIDE;
virtual Rectangle GetTextRect() const;
virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const SAL_OVERRIDE;
virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const SAL_OVERRIDE;
virtual void GetCaretPositions( int nArraySize, long* pCaretXArray ) const SAL_OVERRIDE;
......
......@@ -945,6 +945,43 @@ DeviceCoordinate GenericSalLayout::GetTextWidth() const
return nWidth;
}
Rectangle GenericSalLayout::GetTextRect() const
{
if( m_GlyphItems.empty() )
return Rectangle(Point(0, 0), Size(0, 0));
// initialize the extent
DeviceCoordinate nMinXPos = 0;
DeviceCoordinate nMaxXPos = 0;
DeviceCoordinate nMinYPos = 0;
DeviceCoordinate nMaxYPos = 0;
for( GlyphVector::const_iterator pGlyphIter = m_GlyphItems.begin(), end = m_GlyphItems.end(); pGlyphIter != end ; ++pGlyphIter )
{
// update the text extent with the glyph extent
DeviceCoordinate nXPos = pGlyphIter->maLinearPos.X();
DeviceCoordinate nYPos = pGlyphIter->maLinearPos.Y();
if( nMinXPos > nXPos )
nMinXPos = nXPos;
nXPos += pGlyphIter->mnNewWidth - pGlyphIter->mnXOffset;
if( nMaxXPos < nXPos )
nMaxXPos = nXPos;
if( nMinYPos > nYPos )
nMinYPos = nYPos;
nYPos += pGlyphIter->mnNewWidth - pGlyphIter->mnYOffset;
if( nMaxYPos < nYPos )
nMaxYPos = nYPos;
}
DeviceCoordinate nWidth = nMaxXPos - nMinXPos;
DeviceCoordinate nHeight = nMaxYPos - nMinYPos;
return Rectangle( Point(nMinXPos, nMinYPos), Size(nWidth, nHeight) );
}
void GenericSalLayout::AdjustLayout( ImplLayoutArgs& rArgs )
{
SalLayout::AdjustLayout( rArgs );
......
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