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

This fallback code makes no sense any more

Ito probably made sense only with bitmap fonts which we no longer
support, and if we don’t need the fallback for printer devices then we
don’t need it on screen either (that whole printer/screen distinction
needs to die someday).

Change-Id: Icf77cd70f0f1b2c186a3c856900295caba72e903
Reviewed-on: https://gerrit.libreoffice.org/31914Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarKhaled Hosny <khaledhosny@eglug.org>
üst b8ae49a3
...@@ -774,7 +774,6 @@ namespace oglcanvas ...@@ -774,7 +774,6 @@ namespace oglcanvas
0, 0,
rTxt.StartPosition, rTxt.StartPosition,
rTxt.Length, rTxt.Length,
true,
0, 0,
pDXArray.get() ); pDXArray.get() );
} }
......
...@@ -130,7 +130,6 @@ namespace vclcanvas ...@@ -130,7 +130,6 @@ namespace vclcanvas
maText.StartPosition, maText.StartPosition,
maText.StartPosition, maText.StartPosition,
maText.Length, maText.Length,
false,
0, 0,
aOffsets.get())) aOffsets.get()))
{ {
......
...@@ -261,7 +261,6 @@ namespace drawinglayer ...@@ -261,7 +261,6 @@ namespace drawinglayer
nIndex, nIndex,
nIndex, nIndex,
nLength, nLength,
true,
0, 0,
&(aIntegerDXArray[0])); &(aIntegerDXArray[0]));
} }
......
...@@ -1082,7 +1082,7 @@ public: ...@@ -1082,7 +1082,7 @@ public:
bool GetTextOutlines( basegfx::B2DPolyPolygonVector &rVector, bool GetTextOutlines( basegfx::B2DPolyPolygonVector &rVector,
const OUString& rStr, sal_Int32 nBase, sal_Int32 nIndex = 0, const OUString& rStr, sal_Int32 nBase, sal_Int32 nIndex = 0,
sal_Int32 nLen = -1, bool bOptimize = true, sal_Int32 nLen = -1,
sal_uLong nLayoutWidth = 0, const long* pDXArray = nullptr ) const; sal_uLong nLayoutWidth = 0, const long* pDXArray = nullptr ) const;
......
...@@ -2434,125 +2434,13 @@ bool OutputDevice::GetTextBoundRect( Rectangle& rRect, ...@@ -2434,125 +2434,13 @@ bool OutputDevice::GetTextBoundRect( Rectangle& rRect,
pSalLayout->Release(); pSalLayout->Release();
} }
if( bRet || (OUTDEV_PRINTER == meOutDevType) || !mpFontInstance )
return bRet; return bRet;
// fall back to bitmap method to get the bounding rectangle,
// so we need a monochrome virtual device with matching font
ScopedVclPtrInstance< VirtualDevice > aVDev(DeviceFormat::BITMASK);
vcl::Font aFont( GetFont() );
aFont.SetShadow( false );
aFont.SetOutline( false );
aFont.SetRelief( FontRelief::NONE );
aFont.SetOrientation( 0 );
aFont.SetFontSize( Size( mpFontInstance->maFontSelData.mnWidth, mpFontInstance->maFontSelData.mnHeight ) );
aVDev->SetFont( aFont );
aVDev->SetTextAlign( ALIGN_TOP );
// layout the text on the virtual device
pSalLayout = aVDev->ImplLayout( rStr, nIndex, nLen, aPoint, nLayoutWidth, pDXAry );
if( !pSalLayout )
return false;
// make the bitmap big enough
// TODO: use factors when it would get too big
long nWidth = pSalLayout->GetTextWidth();
long nHeight = mpFontInstance->mnLineHeight + mnEmphasisAscent + mnEmphasisDescent;
Point aOffset( nWidth/2, 8 );
Size aOutSize( nWidth + 2*aOffset.X(), nHeight + 2*aOffset.Y() );
if( !nWidth || !aVDev->SetOutputSizePixel( aOutSize ) )
{
pSalLayout->Release();
return false;
}
// draw text in black
pSalLayout->DrawBase() = aOffset;
aVDev->SetTextColor( Color( COL_BLACK ) );
aVDev->SetTextFillColor();
aVDev->ImplInitTextColor();
aVDev->ImplDrawText( *pSalLayout );
pSalLayout->Release();
// find extents using the bitmap
Bitmap aBmp = aVDev->GetBitmap( Point(), aOutSize );
Bitmap::ScopedReadAccess pAcc(aBmp);
if( !pAcc )
return false;
const BitmapColor aBlack( pAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
const long nW = pAcc->Width();
const long nH = pAcc->Height();
long nLeft = 0;
long nRight = 0;
// find top left point
long nTop = 0;
for(; nTop < nH; ++nTop )
{
for( nLeft = 0; nLeft < nW; ++nLeft )
if( pAcc->GetPixel( nTop, nLeft ) == aBlack )
break;
if( nLeft < nW )
break;
}
// find bottom right point
long nBottom = nH;
while( --nBottom >= nTop )
{
for( nRight = nW; --nRight >= 0; )
if( pAcc->GetPixel( nBottom, nRight ) == aBlack )
break;
if( nRight >= 0 )
break;
}
if( nRight < nLeft )
{
long nX = nRight;
nRight = nLeft;
nLeft = nX;
}
for( long nY = nTop; nY <= nBottom; ++nY )
{
// find leftmost point
long nX;
for( nX = 0; nX < nLeft; ++nX )
if( pAcc->GetPixel( nY, nX ) == aBlack )
break;
nLeft = nX;
// find rightmost point
for( nX = nW; --nX > nRight; )
if( pAcc->GetPixel( nY, nX ) == aBlack )
break;
nRight = nX;
}
pAcc.reset();
if( nTop <= nBottom )
{
Size aSize( nRight - nLeft + 1, nBottom - nTop + 1 );
Point aTopLeft( nLeft, nTop );
aTopLeft -= aOffset;
// adjust to text alignment
aTopLeft.Y()+= mnTextOffY - (mpFontInstance->mxFontMetric->GetAscent() + mnEmphasisAscent);
// convert to logical coordinates
aSize = PixelToLogic( aSize );
aTopLeft.X() = ImplDevicePixelToLogicWidth( aTopLeft.X() );
aTopLeft.Y() = ImplDevicePixelToLogicHeight( aTopLeft.Y() );
rRect = Rectangle( aTopLeft, aSize );
return true;
}
return false;
} }
bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector, bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
const OUString& rStr, sal_Int32 nBase, const OUString& rStr, sal_Int32 nBase,
sal_Int32 nIndex, sal_Int32 nLen, sal_Int32 nIndex, sal_Int32 nLen,
bool bOptimize, sal_uLong nLayoutWidth, const long* pDXArray ) const sal_uLong nLayoutWidth, const long* pDXArray ) const
{ {
if(nLen == 0x0FFFF) if(nLen == 0x0FFFF)
{ {
...@@ -2644,145 +2532,6 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector, ...@@ -2644,145 +2532,6 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
const_cast<OutputDevice&>(*this).mbNewFont = true; const_cast<OutputDevice&>(*this).mbNewFont = true;
} }
if( bRet || (OUTDEV_PRINTER == meOutDevType) || !mpFontInstance )
return bRet;
// reset work done (tdf#81876)
rVector.clear();
// fall back to bitmap conversion
// Here, we can safely assume that the mapping between characters and glyphs
// is one-to-one. This is most probably valid for the old bitmap fonts.
// fall back to bitmap method to get the bounding rectangle,
// so we need a monochrome virtual device with matching font
pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0), nLayoutWidth, pDXArray );
if (pSalLayout == nullptr)
return false;
long nOrgWidth = pSalLayout->GetTextWidth();
long nOrgHeight = mpFontInstance->mnLineHeight + mnEmphasisAscent
+ mnEmphasisDescent;
pSalLayout->Release();
ScopedVclPtrInstance< VirtualDevice > aVDev(DeviceFormat::BITMASK);
vcl::Font aFont(GetFont());
aFont.SetShadow(false);
aFont.SetOutline(false);
aFont.SetRelief(FontRelief::NONE);
aFont.SetOrientation(0);
if( bOptimize )
{
aFont.SetFontSize( Size( 0, GLYPH_FONT_HEIGHT ) );
aVDev->SetMapMode( MapUnit::MapPixel );
}
aVDev->SetFont( aFont );
aVDev->SetTextAlign( ALIGN_TOP );
aVDev->SetTextColor( Color(COL_BLACK) );
aVDev->SetTextFillColor();
pSalLayout = aVDev->ImplLayout( rStr, nIndex, nLen, Point(0,0), nLayoutWidth, pDXArray );
if (pSalLayout == nullptr)
return false;
long nWidth = pSalLayout->GetTextWidth();
long nHeight = aVDev->mpFontInstance->mnLineHeight + aVDev->mnEmphasisAscent +
aVDev->mnEmphasisDescent;
pSalLayout->Release();
if( !nWidth || !nHeight )
return true;
double fScaleX = static_cast< double >(nOrgWidth) / nWidth;
double fScaleY = static_cast< double >(nOrgHeight) / nHeight;
// calculate offset when nBase!=nIndex
// TODO: fix offset calculation for Bidi case
nXOffset = 0;
if( nBase != nIndex )
{
sal_Int32 nStart = ((nBase < nIndex) ? nBase : nIndex);
sal_Int32 nLength = ((nBase > nIndex) ? nBase : nIndex) - nStart;
pSalLayout = aVDev->ImplLayout( rStr, nStart, nLength, Point(0,0), nLayoutWidth, pDXArray );
if( pSalLayout )
{
nXOffset = pSalLayout->GetTextWidth();
pSalLayout->Release();
if( nBase > nIndex)
nXOffset = -nXOffset;
}
}
bRet = true;
bool bRTL = false;
OUString aStr( rStr ); // prepare for e.g. localized digits
sal_Int32 nIndex2 = nIndex; // only needed until nIndex is sal_Int32
sal_Int32 nLen2 = nLen; // only needed until nLen is sal_Int32
ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStr, nIndex2, nLen2, 0, nullptr );
for( int nCharPos = -1; aLayoutArgs.GetNextPos( &nCharPos, &bRTL);)
{
bool bSuccess = false;
// draw character into virtual device
pSalLayout = aVDev->ImplLayout( rStr, nCharPos, 1, Point(0,0), nLayoutWidth, pDXArray );
if (pSalLayout == nullptr)
return false;
long nCharWidth = pSalLayout->GetTextWidth();
Point aOffset(nCharWidth / 2, 8);
Size aSize(nCharWidth + 2 * aOffset.X(), nHeight + 2 * aOffset.Y());
bSuccess = (bool)aVDev->SetOutputSizePixel(aSize);
if( bSuccess )
{
// draw glyph into virtual device
aVDev->Erase();
pSalLayout->DrawBase() += aOffset;
pSalLayout->DrawBase() += Point( aVDev->mnTextOffX, aVDev->mnTextOffY );
pSalLayout->DrawText( *aVDev->mpGraphics );
pSalLayout->Release();
// convert character image into outline
Bitmap aBmp( aVDev->GetBitmap(Point(0, 0), aSize));
tools::PolyPolygon aPolyPoly;
bool bVectorized = aBmp.Vectorize(aPolyPoly);
if( !bVectorized )
bSuccess = false;
else
{
// convert units to logical width
for (sal_uInt16 j = 0; j < aPolyPoly.Count(); ++j)
{
tools::Polygon& rPoly = aPolyPoly[j];
for (sal_uInt16 k = 0; k < rPoly.GetSize(); ++k)
{
Point& rPt = rPoly[k];
rPt -= aOffset;
int nPixelX = rPt.X() - static_cast<OutputDevice*>(aVDev.get())->mnTextOffX + nXOffset;
int nPixelY = rPt.Y() - static_cast<OutputDevice*>(aVDev.get())->mnTextOffY;
rPt.X() = ImplDevicePixelToLogicWidth( nPixelX );
rPt.Y() = ImplDevicePixelToLogicHeight( nPixelY );
}
}
// ignore "empty" glyphs:
if( aPolyPoly.Count() > 0 )
{
// convert to B2DPolyPolygon
// TODO: get rid of intermediate tool's PolyPolygon
basegfx::B2DPolyPolygon aB2DPolyPoly = aPolyPoly.getB2DPolyPolygon();
basegfx::B2DHomMatrix aMatrix;
aMatrix.scale( fScaleX, fScaleY );
int nAngle = GetFont().GetOrientation();
if( nAngle )
aMatrix.rotate( nAngle * F_PI1800 );
aB2DPolyPoly.transform( aMatrix );
rVector.push_back( aB2DPolyPoly );
}
}
}
nXOffset += nCharWidth;
bRet = bRet && bSuccess;
}
return bRet; return bRet;
} }
...@@ -2802,7 +2551,7 @@ bool OutputDevice::GetTextOutlines( PolyPolyVector& rResultVector, ...@@ -2802,7 +2551,7 @@ bool OutputDevice::GetTextOutlines( PolyPolyVector& rResultVector,
// get the basegfx polypolygon vector // get the basegfx polypolygon vector
basegfx::B2DPolyPolygonVector aB2DPolyPolyVector; basegfx::B2DPolyPolygonVector aB2DPolyPolyVector;
if( !GetTextOutlines( aB2DPolyPolyVector, rStr, nBase, nIndex, nLen, if( !GetTextOutlines( aB2DPolyPolyVector, rStr, nBase, nIndex, nLen,
true/*bOptimize*/, nTWidth, pDXArray ) ) nTWidth, pDXArray ) )
return false; return false;
// convert to a tool polypolygon vector // convert to a tool polypolygon vector
...@@ -2828,7 +2577,7 @@ bool OutputDevice::GetTextOutline( tools::PolyPolygon& rPolyPoly, const OUString ...@@ -2828,7 +2577,7 @@ bool OutputDevice::GetTextOutline( tools::PolyPolygon& rPolyPoly, const OUString
// get the basegfx polypolygon vector // get the basegfx polypolygon vector
basegfx::B2DPolyPolygonVector aB2DPolyPolyVector; basegfx::B2DPolyPolygonVector aB2DPolyPolyVector;
if( !GetTextOutlines( aB2DPolyPolyVector, rStr, 0/*nBase*/, 0/*nIndex*/, nLen, if( !GetTextOutlines( aB2DPolyPolyVector, rStr, 0/*nBase*/, 0/*nIndex*/, nLen,
true/*bOptimize*/, nTWidth, pDXArray ) ) nTWidth, pDXArray ) )
return false; return false;
// convert and merge into a tool polypolygon // convert and merge into a tool polypolygon
......
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