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 );
352 uno::Sequence< sal_Int8 > aRet(4);
354 aRet[0] =
static_cast<sal_Int8>((rColor >> 16) & 0xFF);
355 aRet[1] =
static_cast<sal_Int8>((rColor >> 8) & 0xFF);
356 aRet[2] =
static_cast<sal_Int8>(rColor & 0xFF);
357 aRet[3] =
static_cast<sal_Int8>((rColor >> 24) & 0xFF);
365 "sequenceToArgb: need at least three channels" );
368 Gdiplus::ARGB aColor;
372 if( rColor.getLength() > 3 )
373 aColor |= static_cast<sal_uInt8>(rColor[3]) << 24;
381 "sequenceToColor: need at least three channels" );
384 Gdiplus::ARGB aColor;
391 (
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[0] ) ) << 16) |
392 (
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[1] ) ) << 8) |
393 static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[2] ) );
395 if( rColor.getLength() > 3 )
398 aColor |=
static_cast<sal_uInt8>( ::basegfx::fround( 255*rColor[3] ) ) << 24;
407 std::vector< Gdiplus::PointF > aPoints;
409 for( uno::Sequence< geometry::RealPoint2D >
const & seqPoints : points )
411 const sal_Int32 nCurrSize( seqPoints.getLength() );
414 aPoints.resize( nCurrSize );
419 std::transform( seqPoints.getConstArray(),
420 seqPoints.getConstArray()+nCurrSize,
422 implGdiPlusPointFromRealPoint2D );
424 pRes->AddLines( aPoints.data(), nCurrSize );
434 std::vector< Gdiplus::PointF > aPoints;
444 std::vector< Gdiplus::PointF > aPoints;
446 const sal_uInt32 nPolies( rPoly.count() );
447 for( sal_uInt32 nCurrPoly=0; nCurrPoly<nPolies; ++nCurrPoly )
451 rPoly.getB2DPolygon( nCurrPoly ),
476 Gdiplus::PointF aPoint;
477 return (Gdiplus::Ok == rGraphics->DrawImage( rBitmap.get(),
481 bool drawDIBits(
const std::shared_ptr<Gdiplus::Graphics>& rGraphics,
482 const BITMAPINFO& rBI,
486 Gdiplus::Bitmap::FromBITMAPINFO( &rBI,
487 const_cast<void*>(pBits) ) );
493 bool drawRGBABits(
const std::shared_ptr<Gdiplus::Graphics>& rGraphics,
498 PixelFormat32bppARGB );
501 aBmpData.Width = rRawRGBAData.
mnWidth;
502 aBmpData.Height = rRawRGBAData.
mnHeight;
503 aBmpData.Stride = 4*aBmpData.Width;
504 aBmpData.PixelFormat = PixelFormat32bppARGB;
507 const Gdiplus::Rect aRect( 0,0,aBmpData.Width,aBmpData.Height );
508 if( Gdiplus::Ok != pBitmap->LockBits( &aRect,
509 Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeUserInputBuf,
510 PixelFormat32bppARGB,
517 pBitmap->UnlockBits( &aBmpData );
527 if( pBitmapProvider )
538 const geometry::IntegerSize2D aBmpSize( xBitmap->getSize() );
541 if( xBitmap->hasAlpha() )
546 pBitmap = std::make_shared<Gdiplus::Bitmap>( aBmpSize.Width,
548 PixelFormat32bppARGB );
556 pBitmap = std::make_shared<Gdiplus::Bitmap>( aBmpSize.Width,
558 PixelFormat24bppRGB );
579 "canvasFontFromXFont(): Invalid XFont (or incompatible font for this XCanvas)" );
585 double nRedModulation,
586 double nGreenModulation,
587 double nBlueModulation,
588 double nAlphaModulation )
593 Gdiplus::ColorMatrix aColorMatrix;
595 aColorMatrix.m[0][0] =
static_cast<Gdiplus::REAL
>(nRedModulation);
596 aColorMatrix.m[0][1] = 0.0;
597 aColorMatrix.m[0][2] = 0.0;
598 aColorMatrix.m[0][3] = 0.0;
599 aColorMatrix.m[0][4] = 0.0;
601 aColorMatrix.m[1][0] = 0.0;
602 aColorMatrix.m[1][1] =
static_cast<Gdiplus::REAL
>(nGreenModulation);
603 aColorMatrix.m[1][2] = 0.0;
604 aColorMatrix.m[1][3] = 0.0;
605 aColorMatrix.m[1][4] = 0.0;
607 aColorMatrix.m[2][0] = 0.0;
608 aColorMatrix.m[2][1] = 0.0;
609 aColorMatrix.m[2][2] =
static_cast<Gdiplus::REAL
>(nBlueModulation);
610 aColorMatrix.m[2][3] = 0.0;
611 aColorMatrix.m[2][4] = 0.0;
613 aColorMatrix.m[3][0] = 0.0;
614 aColorMatrix.m[3][1] = 0.0;
615 aColorMatrix.m[3][2] = 0.0;
616 aColorMatrix.m[3][3] =
static_cast<Gdiplus::REAL
>(nAlphaModulation);
617 aColorMatrix.m[3][4] = 0.0;
619 aColorMatrix.m[4][0] = 0.0;
620 aColorMatrix.m[4][1] = 0.0;
621 aColorMatrix.m[4][2] = 0.0;
622 aColorMatrix.m[4][3] = 0.0;
623 aColorMatrix.m[4][4] = 1.0;
625 o_rAttr.SetColorMatrix( &aColorMatrix );
GraphicsPathSharedPtr getGraphicsPath(bool bNoLineJoin=false) const
std::shared_ptr< IBitmap > IBitmapSharedPtr
Gdiplus::BitmapData aBmpData
#define ENSURE_ARG_OR_THROW(c, m)
std::shared_ptr< Gdiplus::Bitmap > BitmapSharedPtr
#define ENSURE_OR_THROW(c, m)
std::shared_ptr< Gdiplus::GraphicsPath > GraphicsPathSharedPtr
rtl::Reference< CanvasFont > ImplRef
virtual IBitmapSharedPtr getBitmap() const =0
std::shared_ptr< Gdiplus::Graphics > GraphicsSharedPtr