34#include <com/sun/star/geometry/IntegerRectangle2D.hpp>
35#include <com/sun/star/geometry/RealPoint2D.hpp>
36#include <com/sun/star/lang/XServiceInfo.hpp>
37#include <com/sun/star/lang/XUnoTunnel.hpp>
67 const sal_Int32 nPolys( xPoly->getNumberOfPolygons() );
71 uno::Reference< rendering::XBezierPolyPolygon2D > xBezierPoly(
75 if( xBezierPoly.is() )
77 return ::basegfx::unotools::polyPolygonFromBezier2DSequenceSequence(
78 xBezierPoly->getBezierSegments( 0,
85 uno::Reference< rendering::XLinePolyPolygon2D > xLinePoly(
92 "VCLCanvas::polyPolygonFromXPolyPolygon2D(): Invalid input "
93 "poly-polygon, cannot retrieve vertex data" );
95 return ::basegfx::unotools::polyPolygonFromPoint2DSequenceSequence(
96 xLinePoly->getPoints( 0,
108 rGraphics.SetCompositingQuality( Gdiplus::CompositingQualityHighSpeed );
110 rGraphics.SetInterpolationMode( Gdiplus::InterpolationModeBilinear );
117 rGraphics.SetPixelOffsetMode( Gdiplus::PixelOffsetModeHalf );
122 rGraphics.SetSmoothingMode( Gdiplus::SmoothingModeAntiAlias );
124 rGraphics.SetTextRenderingHint( Gdiplus::TextRenderingHintSystemDefault );
125 rGraphics.SetPageUnit(Gdiplus::UnitPixel);
130 Gdiplus::Graphics* pRet =
new Gdiplus::Graphics(aHDC);
145 rGdiplusMatrix.SetElements(
static_cast<Gdiplus::REAL
>(rMatrix.get(0,0)),
146 static_cast<Gdiplus::REAL
>(rMatrix.get(1,0)),
147 static_cast<Gdiplus::REAL
>(rMatrix.get(0,1)),
148 static_cast<Gdiplus::REAL
>(rMatrix.get(1,1)),
149 static_cast<Gdiplus::REAL
>(rMatrix.get(0,2)),
150 static_cast<Gdiplus::REAL
>(rMatrix.get(1,2)) );
154 const geometry::AffineMatrix2D& rMatrix )
156 rGdiplusMatrix.SetElements(
static_cast<Gdiplus::REAL
>(rMatrix.m00),
157 static_cast<Gdiplus::REAL
>(rMatrix.m10),
158 static_cast<Gdiplus::REAL
>(rMatrix.m01),
159 static_cast<Gdiplus::REAL
>(rMatrix.m11),
160 static_cast<Gdiplus::REAL
>(rMatrix.m02),
161 static_cast<Gdiplus::REAL
>(rMatrix.m12) );
168 Gdiplus::PointF implGdiPlusPointFromRealPoint2D(
const css::geometry::RealPoint2D& rPoint )
170 return Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rPoint.X),
171 static_cast<Gdiplus::REAL
>(rPoint.Y) );
175 std::vector< Gdiplus::PointF >& rPoints,
176 const ::basegfx::B2DPolygon& rPoly,
179 const sal_uInt32 nPoints( rPoly.count() );
184 rOutput->StartFigure();
186 const bool bClosedPolygon( rPoly.isClosed() );
188 if( rPoly.areControlPointsUsed() )
197 rPoints.resize( 3*nPoints + (bClosedPolygon ? 1 : 0) );
199 sal_uInt32 nCurrOutput=0;
200 for( sal_uInt32 nCurrPoint=0; nCurrPoint<nPoints; ++nCurrPoint )
202 const ::basegfx::B2DPoint& rPoint( rPoly.getB2DPoint( nCurrPoint ) );
203 rPoints[nCurrOutput++] = Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rPoint.getX()),
204 static_cast<Gdiplus::REAL
>(rPoint.getY()) );
206 const ::basegfx::B2DPoint& rControlPointA( rPoly.getNextControlPoint( nCurrPoint ) );
207 rPoints[nCurrOutput++] = Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rControlPointA.getX()),
208 static_cast<Gdiplus::REAL
>(rControlPointA.getY()) );
210 const ::basegfx::B2DPoint& rControlPointB( rPoly.getPrevControlPoint( (nCurrPoint + 1) % nPoints) );
211 rPoints[nCurrOutput++] = Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rControlPointB.getX()),
212 static_cast<Gdiplus::REAL
>(rControlPointB.getY()) );
220 const ::basegfx::B2DPoint& rPoint( rPoly.getB2DPoint(0) );
221 rPoints[nCurrOutput++] = Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rPoint.getX()),
222 static_cast<Gdiplus::REAL
>(rPoint.getY()) );
224 if(bNoLineJoin && nCurrOutput > 7)
226 for(sal_uInt32
a(3);
a < nCurrOutput;
a+=3)
228 rOutput->StartFigure();
229 rOutput->AddBezier(rPoints[a - 3], rPoints[a - 2], rPoints[a - 1], rPoints[a]);
234 rOutput->AddBeziers( rPoints.data(), nCurrOutput );
244 if( nCurrOutput > 3 )
246 if(bNoLineJoin && nCurrOutput > 7)
248 for(sal_uInt32
a(3);
a < nCurrOutput;
a+=3)
250 rOutput->StartFigure();
251 rOutput->AddBezier(rPoints[a - 3], rPoints[a - 2], rPoints[a - 1], rPoints[a]);
256 rOutput->AddBeziers( rPoints.data(), nCurrOutput-2 );
265 rPoints.resize( nPoints );
267 for( sal_uInt32 nCurrPoint=0; nCurrPoint<nPoints; ++nCurrPoint )
269 const ::basegfx::B2DPoint& rPoint( rPoly.getB2DPoint( nCurrPoint ) );
270 rPoints[nCurrPoint] = Gdiplus::PointF(
static_cast<Gdiplus::REAL
>(rPoint.getX()),
271 static_cast<Gdiplus::REAL
>(rPoint.getY()) );
274 if(bNoLineJoin && nPoints > 2)
276 for(sal_uInt32
a(1);
a < nPoints;
a++)
278 rOutput->StartFigure();
279 rOutput->AddLine(rPoints[a - 1], rPoints[a]);
284 rOutput->StartFigure();
285 rOutput->AddLine(rPoints[nPoints - 1], rPoints[0]);
290 rOutput->AddLines( rPoints.data(), nPoints );
294 if( bClosedPolygon && !bNoLineJoin )
295 rOutput->CloseFigure();
301 return Gdiplus::Rect( rRect.X1,
304 rRect.Y2 - rRect.Y1 );
309 return Gdiplus::RectF(
static_cast<Gdiplus::REAL
>(rRect.X1),
310 static_cast<Gdiplus::REAL
>(rRect.Y1),
311 static_cast<Gdiplus::REAL
>(rRect.X2 - rRect.X1),
312 static_cast<Gdiplus::REAL
>(rRect.Y2 - rRect.Y1) );
317 RECT aRect = {rRect.getMinX(),
327 return geometry::RealPoint2D( rPoint.X, rPoint.Y );
332 return geometry::RealRectangle2D( rRect.X, rRect.Y,
333 rRect.X + rRect.Width,
334 rRect.Y + rRect.Height );
339 return ::basegfx::B2DPoint( rPoint.X, rPoint.Y );
344 return ::basegfx::B2DRange( rRect.X, rRect.Y,
345 rRect.X + rRect.Width,
346 rRect.Y + rRect.Height );
354 static_cast<sal_Int8>((rColor >> 16) & 0xFF),
355 static_cast<sal_Int8>((rColor >> 8) & 0xFF),
356 static_cast<sal_Int8>(rColor & 0xFF),
357 static_cast<sal_Int8>((rColor >> 24) & 0xFF)
364 "sequenceToArgb: need at least three channels" );
367 Gdiplus::ARGB aColor;
371 if( rColor.getLength() > 3 )
372 aColor |=
static_cast<sal_uInt8>(rColor[3]) << 24;
380 "sequenceToColor: need at least three channels" );
383 Gdiplus::ARGB aColor;
390 (
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[0] ) ) << 16) |
391 (
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[1] ) ) << 8) |
392 static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[2] ) );
394 if( rColor.getLength() > 3 )
397 aColor |=
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[3] ) ) << 24;
406 std::vector< Gdiplus::PointF > aPoints;
408 for( uno::Sequence< geometry::RealPoint2D >
const & seqPoints : points )
410 const sal_Int32 nCurrSize( seqPoints.getLength() );
413 aPoints.resize( nCurrSize );
418 std::transform( seqPoints.getConstArray(),
419 seqPoints.getConstArray()+nCurrSize,
421 implGdiPlusPointFromRealPoint2D );
423 pRes->AddLines( aPoints.data(), nCurrSize );
433 std::vector< Gdiplus::PointF > aPoints;
443 std::vector< Gdiplus::PointF > aPoints;
445 const sal_uInt32 nPolies( rPoly.count() );
446 for( sal_uInt32 nCurrPoly=0; nCurrPoly<nPolies; ++nCurrPoly )
450 rPoly.getB2DPolygon( nCurrPoly ),
475 Gdiplus::PointF aPoint;
476 return (Gdiplus::Ok == rGraphics->DrawImage( rBitmap.get(),
480 bool drawDIBits(
const std::shared_ptr<Gdiplus::Graphics>& rGraphics,
481 const BITMAPINFO& rBI,
485 Gdiplus::Bitmap::FromBITMAPINFO( &rBI,
486 const_cast<void*
>(pBits) ) );
492 bool drawRGBABits(
const std::shared_ptr<Gdiplus::Graphics>& rGraphics,
497 PixelFormat32bppARGB );
503 aBmpData.PixelFormat = PixelFormat32bppARGB;
507 if( Gdiplus::Ok != pBitmap->LockBits( &aRect,
508 Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeUserInputBuf,
509 PixelFormat32bppARGB,
526 if( pBitmapProvider )
529 return pBitmap->getBitmap();
537 const geometry::IntegerSize2D aBmpSize( xBitmap->getSize() );
540 if( xBitmap->hasAlpha() )
545 pBitmap = std::make_shared<Gdiplus::Bitmap>( aBmpSize.Width,
547 PixelFormat32bppARGB );
555 pBitmap = std::make_shared<Gdiplus::Bitmap>( aBmpSize.Width,
557 PixelFormat24bppRGB );
578 "canvasFontFromXFont(): Invalid XFont (or incompatible font for this XCanvas)" );
584 double nRedModulation,
585 double nGreenModulation,
586 double nBlueModulation,
587 double nAlphaModulation )
592 Gdiplus::ColorMatrix aColorMatrix;
594 aColorMatrix.m[0][0] =
static_cast<Gdiplus::REAL
>(nRedModulation);
595 aColorMatrix.m[0][1] = 0.0;
596 aColorMatrix.m[0][2] = 0.0;
597 aColorMatrix.m[0][3] = 0.0;
598 aColorMatrix.m[0][4] = 0.0;
600 aColorMatrix.m[1][0] = 0.0;
601 aColorMatrix.m[1][1] =
static_cast<Gdiplus::REAL
>(nGreenModulation);
602 aColorMatrix.m[1][2] = 0.0;
603 aColorMatrix.m[1][3] = 0.0;
604 aColorMatrix.m[1][4] = 0.0;
606 aColorMatrix.m[2][0] = 0.0;
607 aColorMatrix.m[2][1] = 0.0;
608 aColorMatrix.m[2][2] =
static_cast<Gdiplus::REAL
>(nBlueModulation);
609 aColorMatrix.m[2][3] = 0.0;
610 aColorMatrix.m[2][4] = 0.0;
612 aColorMatrix.m[3][0] = 0.0;
613 aColorMatrix.m[3][1] = 0.0;
614 aColorMatrix.m[3][2] = 0.0;
615 aColorMatrix.m[3][3] =
static_cast<Gdiplus::REAL
>(nAlphaModulation);
616 aColorMatrix.m[3][4] = 0.0;
618 aColorMatrix.m[4][0] = 0.0;
619 aColorMatrix.m[4][1] = 0.0;
620 aColorMatrix.m[4][2] = 0.0;
621 aColorMatrix.m[4][3] = 0.0;
622 aColorMatrix.m[4][4] = 1.0;
624 o_rAttr.SetColorMatrix( &aColorMatrix );
rtl::Reference< CanvasFont > ImplRef
GraphicsPathSharedPtr getGraphicsPath(bool bNoLineJoin=false) const
#define ENSURE_OR_THROW(c, m)
#define ENSURE_ARG_OR_THROW(c, m)
Gdiplus::BitmapData aBmpData
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr
std::shared_ptr< IBitmap > IBitmapSharedPtr
std::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr
std::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr
virtual IBitmapSharedPtr getBitmap() const =0