1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_canvas.hxx"
26 
27 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
28 #include <com/sun/star/geometry/Matrix2D.hpp>
29 #include <com/sun/star/geometry/RealPoint2D.hpp>
30 #include <com/sun/star/geometry/RealSize2D.hpp>
31 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
32 #include <com/sun/star/geometry/IntegerSize2D.hpp>
33 #include <com/sun/star/geometry/RealRectangle2D.hpp>
34 #include <com/sun/star/geometry/RealBezierSegment2D.hpp>
35 #include <com/sun/star/rendering/RenderState.hpp>
36 #include <com/sun/star/rendering/ViewState.hpp>
37 #include <com/sun/star/rendering/XCanvas.hpp>
38 #include <com/sun/star/rendering/CompositeOperation.hpp>
39 #include <com/sun/star/rendering/TexturingMode.hpp>
40 #include <com/sun/star/util/Endianness.hpp>
41 #include <com/sun/star/rendering/PathCapType.hpp>
42 #include <com/sun/star/rendering/PathJoinType.hpp>
43 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
44 #include <com/sun/star/rendering/FloatingPointBitmapFormat.hpp>
45 #include <com/sun/star/rendering/FloatingPointBitmapLayout.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 
49 #include <basegfx/matrix/b2dhommatrix.hxx>
50 #include <basegfx/range/b2drange.hxx>
51 #include <basegfx/range/b2irange.hxx>
52 #include <basegfx/range/b2drectangle.hxx>
53 #include <basegfx/point/b2dpoint.hxx>
54 #include <basegfx/tools/canvastools.hxx>
55 #include <basegfx/polygon/b2dpolygon.hxx>
56 
57 #include <canvas/verifyinput.hxx>
58 #include <canvas/canvastools.hxx>
59 
60 
61 using namespace ::com::sun::star;
62 
63 namespace canvas
64 {
65     namespace tools
66     {
verifyInput(const geometry::RealPoint2D & rPoint,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)67         void verifyInput( const geometry::RealPoint2D&				rPoint,
68                           const char*								pStr,
69                           const uno::Reference< uno::XInterface >&	xIf,
70                           ::sal_Int16								nArgPos )
71         {
72             (void)pStr; (void)xIf; (void)nArgPos;
73 
74 #if OSL_DEBUG_LEVEL > 0
75             if( !::rtl::math::isFinite( rPoint.X ) )
76             {
77                 throw lang::IllegalArgumentException(
78                     ::rtl::OUString::createFromAscii(pStr) +
79                     ::rtl::OUString::createFromAscii(": verifyInput(): point X value contains infinite or NAN"),
80                     xIf,
81                     nArgPos );
82             }
83 
84             if( !::rtl::math::isFinite( rPoint.Y ) )
85             {
86                 throw lang::IllegalArgumentException(
87                     ::rtl::OUString::createFromAscii(pStr) +
88                     ::rtl::OUString::createFromAscii(": verifyInput(): point X value contains infinite or NAN"),
89                     xIf,
90                     nArgPos );
91             }
92 #else
93             if( !::rtl::math::isFinite( rPoint.X ) ||
94                 !::rtl::math::isFinite( rPoint.Y ) )
95             {
96                 throw lang::IllegalArgumentException();
97             }
98 #endif
99         }
100 
verifyInput(const geometry::RealSize2D & rSize,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)101         void verifyInput( const geometry::RealSize2D&				rSize,
102                           const char*								pStr,
103                           const uno::Reference< uno::XInterface >&	xIf,
104                           ::sal_Int16								nArgPos )
105         {
106             (void)pStr; (void)xIf; (void)nArgPos;
107 
108 #if OSL_DEBUG_LEVEL > 0
109             if( !::rtl::math::isFinite( rSize.Width ) )
110             {
111                 throw lang::IllegalArgumentException(
112                     ::rtl::OUString::createFromAscii(pStr) +
113                     ::rtl::OUString::createFromAscii(": verifyInput(): size.Width value contains infinite or NAN"),
114                     xIf,
115                     nArgPos );
116             }
117 
118             if( !::rtl::math::isFinite( rSize.Height ) )
119             {
120                 throw lang::IllegalArgumentException(
121                     ::rtl::OUString::createFromAscii(pStr) +
122                     ::rtl::OUString::createFromAscii(": verifyInput(): size.Height value contains infinite or NAN"),
123                     xIf,
124                     nArgPos );
125             }
126 #else
127             if( !::rtl::math::isFinite( rSize.Width ) ||
128                 !::rtl::math::isFinite( rSize.Height ) )
129             {
130                 throw lang::IllegalArgumentException();
131             }
132 #endif
133         }
134 
verifyInput(const geometry::RealBezierSegment2D & rSegment,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)135         void verifyInput( const geometry::RealBezierSegment2D&		rSegment,
136                           const char*								pStr,
137                           const uno::Reference< uno::XInterface >&	xIf,
138                           ::sal_Int16								nArgPos )
139         {
140             (void)pStr; (void)xIf; (void)nArgPos;
141 
142 #if OSL_DEBUG_LEVEL > 0
143             if( !::rtl::math::isFinite( rSegment.Px ) )
144             {
145                 throw lang::IllegalArgumentException(
146                     ::rtl::OUString::createFromAscii(pStr) +
147                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's Px value contains infinite or NAN"),
148                     xIf,
149                     nArgPos );
150             }
151 
152             if( !::rtl::math::isFinite( rSegment.Py ) )
153             {
154                 throw lang::IllegalArgumentException(
155                     ::rtl::OUString::createFromAscii(pStr) +
156                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's Py value contains infinite or NAN"),
157                     xIf,
158                     nArgPos );
159             }
160 
161             if( !::rtl::math::isFinite( rSegment.C1x ) )
162             {
163                 throw lang::IllegalArgumentException(
164                     ::rtl::OUString::createFromAscii(pStr) +
165                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's C1x value contains infinite or NAN"),
166                     xIf,
167                     nArgPos );
168             }
169 
170             if( !::rtl::math::isFinite( rSegment.C1y ) )
171             {
172                 throw lang::IllegalArgumentException(
173                     ::rtl::OUString::createFromAscii(pStr) +
174                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's C1y value contains infinite or NAN"),
175                     xIf,
176                     nArgPos );
177             }
178 
179             if( !::rtl::math::isFinite( rSegment.C2x ) )
180             {
181                 throw lang::IllegalArgumentException(
182                     ::rtl::OUString::createFromAscii(pStr) +
183                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's C2x value contains infinite or NAN"),
184                     xIf,
185                     nArgPos );
186             }
187 
188             if( !::rtl::math::isFinite( rSegment.C2y ) )
189             {
190                 throw lang::IllegalArgumentException(
191                     ::rtl::OUString::createFromAscii(pStr) +
192                     ::rtl::OUString::createFromAscii(": verifyInput(): bezier segment's C2y value contains infinite or NAN"),
193                     xIf,
194                     nArgPos );
195             }
196 #else
197             if( !::rtl::math::isFinite( rSegment.Px ) ||
198                 !::rtl::math::isFinite( rSegment.Py ) ||
199                 !::rtl::math::isFinite( rSegment.C1x ) ||
200                 !::rtl::math::isFinite( rSegment.C1y ) ||
201                 !::rtl::math::isFinite( rSegment.C2x ) ||
202                 !::rtl::math::isFinite( rSegment.C2y ) )
203             {
204                 throw lang::IllegalArgumentException();
205             }
206 #endif
207         }
208 
verifyInput(const geometry::RealRectangle2D & rRect,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)209         void verifyInput( const geometry::RealRectangle2D&			rRect,
210                           const char*								pStr,
211                           const uno::Reference< uno::XInterface >&	xIf,
212                           ::sal_Int16								nArgPos )
213         {
214             (void)pStr; (void)xIf; (void)nArgPos;
215 
216 #if OSL_DEBUG_LEVEL > 0
217             if( !::rtl::math::isFinite( rRect.X1 ) )
218             {
219                 throw lang::IllegalArgumentException(
220                     ::rtl::OUString::createFromAscii(pStr) +
221                     ::rtl::OUString::createFromAscii(": verifyInput(): rectangle point X1 contains infinite or NAN"),
222                     xIf,
223                     nArgPos );
224             }
225 
226             if( !::rtl::math::isFinite( rRect.Y1 ) )
227             {
228                 throw lang::IllegalArgumentException(
229                     ::rtl::OUString::createFromAscii(pStr) +
230                     ::rtl::OUString::createFromAscii(": verifyInput(): rectangle point Y1 contains infinite or NAN"),
231                     xIf,
232                     nArgPos );
233             }
234 
235             if( !::rtl::math::isFinite( rRect.X2 ) )
236             {
237                 throw lang::IllegalArgumentException(
238                     ::rtl::OUString::createFromAscii(pStr) +
239                     ::rtl::OUString::createFromAscii(": verifyInput(): rectangle point X2 contains infinite or NAN"),
240                     xIf,
241                     nArgPos );
242             }
243 
244             if( !::rtl::math::isFinite( rRect.Y2 ) )
245             {
246                 throw lang::IllegalArgumentException(
247                     ::rtl::OUString::createFromAscii(pStr) +
248                     ::rtl::OUString::createFromAscii(": verifyInput(): rectangle point Y2 contains infinite or NAN"),
249                     xIf,
250                     nArgPos );
251             }
252 #else
253             if( !::rtl::math::isFinite( rRect.X1 ) ||
254                 !::rtl::math::isFinite( rRect.Y1 ) ||
255                 !::rtl::math::isFinite( rRect.X2 ) ||
256                 !::rtl::math::isFinite( rRect.Y2 ) )
257             {
258                 throw lang::IllegalArgumentException();
259             }
260 #endif
261         }
262 
verifyInput(const geometry::AffineMatrix2D & matrix,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)263         void verifyInput( const geometry::AffineMatrix2D&			matrix,
264                           const char*								pStr,
265                           const uno::Reference< uno::XInterface >&	xIf,
266                           ::sal_Int16								nArgPos )
267         {
268             (void)pStr; (void)xIf; (void)nArgPos;
269 
270 #if OSL_DEBUG_LEVEL > 0
271             const sal_Int32 nBinaryState(
272                 100000 * !::rtl::math::isFinite( matrix.m00 ) +
273                  10000 * !::rtl::math::isFinite( matrix.m01 ) +
274                   1000 * !::rtl::math::isFinite( matrix.m02 ) +
275                    100 * !::rtl::math::isFinite( matrix.m10 ) +
276                     10 * !::rtl::math::isFinite( matrix.m11 ) +
277                      1 * !::rtl::math::isFinite( matrix.m12 ) );
278 
279             if( nBinaryState )
280             {
281                 throw lang::IllegalArgumentException(
282                     ::rtl::OUString::createFromAscii(pStr) +
283                     ::rtl::OUString::createFromAscii(": verifyInput(): AffineMatrix2D contains infinite or NAN value(s) at the following positions (m00-m12): ") +
284                     ::rtl::OUString::valueOf(nBinaryState),
285                     xIf,
286                     nArgPos );
287             }
288 #else
289             if( !::rtl::math::isFinite( matrix.m00 ) ||
290                 !::rtl::math::isFinite( matrix.m01 ) ||
291                 !::rtl::math::isFinite( matrix.m02 ) ||
292                 !::rtl::math::isFinite( matrix.m10 ) ||
293                 !::rtl::math::isFinite( matrix.m11 ) ||
294                 !::rtl::math::isFinite( matrix.m12 ) )
295             {
296                 throw lang::IllegalArgumentException();
297             }
298 #endif
299         }
300 
verifyInput(const geometry::Matrix2D & matrix,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)301         void verifyInput( const geometry::Matrix2D&					matrix,
302                           const char*								pStr,
303                           const uno::Reference< uno::XInterface >&	xIf,
304                           ::sal_Int16								nArgPos )
305         {
306             (void)pStr; (void)xIf; (void)nArgPos;
307 
308 #if OSL_DEBUG_LEVEL > 0
309             const sal_Int32 nBinaryState(
310                 1000 * !::rtl::math::isFinite( matrix.m00 ) +
311                  100 * !::rtl::math::isFinite( matrix.m01 ) +
312                   10 * !::rtl::math::isFinite( matrix.m10 ) +
313                    1 * !::rtl::math::isFinite( matrix.m11 ) );
314 
315             if( nBinaryState )
316             {
317                 throw lang::IllegalArgumentException(
318                     ::rtl::OUString::createFromAscii(pStr) +
319                     ::rtl::OUString::createFromAscii(": verifyInput(): Matrix2D contains infinite or NAN value(s) at the following positions (m00-m11): ") +
320                     ::rtl::OUString::valueOf(nBinaryState),
321                     xIf,
322                     nArgPos );
323             }
324 #else
325             if( !::rtl::math::isFinite( matrix.m00 ) ||
326                 !::rtl::math::isFinite( matrix.m01 ) ||
327                 !::rtl::math::isFinite( matrix.m10 ) ||
328                 !::rtl::math::isFinite( matrix.m11 ) )
329             {
330                 throw lang::IllegalArgumentException();
331             }
332 #endif
333         }
334 
verifyInput(const rendering::ViewState & viewState,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)335         void verifyInput( const rendering::ViewState&				viewState,
336                           const char*								pStr,
337                           const uno::Reference< uno::XInterface >&	xIf,
338                           ::sal_Int16								nArgPos )
339         {
340             verifyInput( viewState.AffineTransform,
341                          pStr, xIf, nArgPos );
342         }
343 
verifyInput(const rendering::RenderState & renderState,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos,sal_Int32 nMinColorComponents)344         void verifyInput( const rendering::RenderState&				renderState,
345                           const char*								pStr,
346                           const uno::Reference< uno::XInterface >&	xIf,
347                           ::sal_Int16								nArgPos,
348                           sal_Int32									nMinColorComponents )
349         {
350             verifyInput( renderState.AffineTransform,
351                          pStr, xIf, nArgPos );
352 
353             if( renderState.DeviceColor.getLength() < nMinColorComponents )
354             {
355 #if OSL_DEBUG_LEVEL > 0
356                 throw lang::IllegalArgumentException(
357                     ::rtl::OUString::createFromAscii(pStr) +
358                     ::rtl::OUString::createFromAscii(": verifyInput(): render state's device color has too few components (") +
359                     ::rtl::OUString::valueOf(nMinColorComponents) +
360                     ::rtl::OUString::createFromAscii(" expected, ") +
361                     ::rtl::OUString::valueOf(renderState.DeviceColor.getLength()) +
362                     ::rtl::OUString::createFromAscii(" provided)"),
363                     xIf,
364                     nArgPos );
365 #else
366                 throw lang::IllegalArgumentException();
367 #endif
368             }
369 
370             if( renderState.CompositeOperation < rendering::CompositeOperation::CLEAR ||
371                 renderState.CompositeOperation > rendering::CompositeOperation::SATURATE )
372             {
373 #if OSL_DEBUG_LEVEL > 0
374                 throw lang::IllegalArgumentException(
375                     ::rtl::OUString::createFromAscii(pStr) +
376                     ::rtl::OUString::createFromAscii(": verifyInput(): render state's CompositeOperation value out of range (") +
377                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(renderState.CompositeOperation)) +
378                     ::rtl::OUString::createFromAscii(" not known)"),
379                     xIf,
380                     nArgPos );
381 #else
382                 throw lang::IllegalArgumentException();
383 #endif
384             }
385         }
386 
verifyInput(const rendering::Texture & texture,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)387         void verifyInput( const rendering::Texture&					texture,
388                           const char*								pStr,
389                           const uno::Reference< uno::XInterface >&	xIf,
390                           ::sal_Int16								nArgPos )
391         {
392             verifyInput( texture.AffineTransform,
393                          pStr, xIf, nArgPos );
394 
395             if( !::rtl::math::isFinite( texture.Alpha ) ||
396                 texture.Alpha < 0.0 ||
397                 texture.Alpha > 1.0 )
398             {
399 #if OSL_DEBUG_LEVEL > 0
400                 throw lang::IllegalArgumentException(
401                     ::rtl::OUString::createFromAscii(pStr) +
402                     ::rtl::OUString::createFromAscii(": verifyInput(): textures' alpha value out of range (is ") +
403                     ::rtl::OUString::valueOf(texture.Alpha) +
404                     ::rtl::OUString::createFromAscii(")"),
405                     xIf,
406                     nArgPos );
407 #else
408                 throw lang::IllegalArgumentException();
409 #endif
410             }
411 
412             if( texture.NumberOfHatchPolygons < 0 )
413             {
414 #if OSL_DEBUG_LEVEL > 0
415                 throw lang::IllegalArgumentException(
416                     ::rtl::OUString::createFromAscii(pStr) +
417                     ::rtl::OUString::createFromAscii(": verifyInput(): textures' NumberOfHatchPolygons is negative"),
418                     xIf,
419                     nArgPos );
420 #else
421                 throw lang::IllegalArgumentException();
422 #endif
423             }
424 
425             if( texture.RepeatModeX < rendering::TexturingMode::NONE ||
426                 texture.RepeatModeX > rendering::TexturingMode::REPEAT )
427             {
428 #if OSL_DEBUG_LEVEL > 0
429                 throw lang::IllegalArgumentException(
430                     ::rtl::OUString::createFromAscii(pStr) +
431                     ::rtl::OUString::createFromAscii(": verifyInput(): textures' RepeatModeX value is out of range (") +
432                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(texture.RepeatModeX)) +
433                     ::rtl::OUString::createFromAscii(" not known)"),
434                     xIf,
435                     nArgPos );
436 #else
437                 throw lang::IllegalArgumentException();
438 #endif
439             }
440 
441             if( texture.RepeatModeY < rendering::TexturingMode::NONE ||
442                 texture.RepeatModeY > rendering::TexturingMode::REPEAT )
443             {
444 #if OSL_DEBUG_LEVEL > 0
445                 throw lang::IllegalArgumentException(
446                     ::rtl::OUString::createFromAscii(pStr) +
447                     ::rtl::OUString::createFromAscii(": verifyInput(): textures' RepeatModeY value is out of range (") +
448                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(texture.RepeatModeY)) +
449                     ::rtl::OUString::createFromAscii(" not known)"),
450                     xIf,
451                     nArgPos );
452 #else
453                 throw lang::IllegalArgumentException();
454 #endif
455             }
456         }
457 
458         namespace
459         {
460             struct VerifyDashValue
461             {
VerifyDashValuecanvas::tools::__anon798306070111::VerifyDashValue462                 VerifyDashValue( const char*								pStr,
463                                  const uno::Reference< uno::XInterface >&	xIf,
464                                  ::sal_Int16								nArgPos ) :
465                     mpStr( pStr ),
466                     mrIf( xIf ),
467                     mnArgPos( nArgPos )
468                 {
469                 }
470 
operator ()canvas::tools::__anon798306070111::VerifyDashValue471                 void operator()( const double& rVal )
472                 {
473                     if( !::rtl::math::isFinite( rVal ) || rVal < 0.0 )
474                     {
475 #if OSL_DEBUG_LEVEL > 0
476                         throw lang::IllegalArgumentException(
477                             ::rtl::OUString::createFromAscii(mpStr) +
478                             ::rtl::OUString::createFromAscii(": verifyInput(): one of stroke attributes' DashArray value out of range (is ") +
479                             ::rtl::OUString::valueOf(rVal) +
480                             ::rtl::OUString::createFromAscii(")"),
481                             mrIf,
482                             mnArgPos );
483 #else
484                         throw lang::IllegalArgumentException();
485 #endif
486                     }
487                 }
488 
489                 const char*									mpStr;
490                 const uno::Reference< uno::XInterface >&	mrIf;
491                 sal_Int16									mnArgPos;
492             };
493         }
494 
verifyInput(const rendering::StrokeAttributes & strokeAttributes,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)495         void verifyInput( const rendering::StrokeAttributes&		strokeAttributes,
496                           const char*								pStr,
497                           const uno::Reference< uno::XInterface >&	xIf,
498                           ::sal_Int16								nArgPos )
499         {
500             if( !::rtl::math::isFinite( strokeAttributes.StrokeWidth ) ||
501                 strokeAttributes.StrokeWidth < 0.0 )
502             {
503 #if OSL_DEBUG_LEVEL > 0
504                 throw lang::IllegalArgumentException(
505                     ::rtl::OUString::createFromAscii(pStr) +
506                     ::rtl::OUString::createFromAscii(": verifyInput(): stroke attributes' StrokeWidth value out of range (is ") +
507                     ::rtl::OUString::valueOf(strokeAttributes.StrokeWidth) +
508                     ::rtl::OUString::createFromAscii(")"),
509                     xIf,
510                     nArgPos );
511 #else
512                 throw lang::IllegalArgumentException();
513 #endif
514             }
515 
516             if( !::rtl::math::isFinite( strokeAttributes.MiterLimit ) ||
517                 strokeAttributes.MiterLimit < 0.0 )
518             {
519 #if OSL_DEBUG_LEVEL > 0
520                 throw lang::IllegalArgumentException(
521                     ::rtl::OUString::createFromAscii(pStr) +
522                     ::rtl::OUString::createFromAscii(": verifyInput(): stroke attributes' MiterLimit value out of range (is ") +
523                     ::rtl::OUString::valueOf(strokeAttributes.MiterLimit) +
524                     ::rtl::OUString::createFromAscii(")"),
525                     xIf,
526                     nArgPos );
527 #else
528                 throw lang::IllegalArgumentException();
529 #endif
530             }
531 
532             ::std::for_each( strokeAttributes.DashArray.getConstArray(),
533                              strokeAttributes.DashArray.getConstArray() + strokeAttributes.DashArray.getLength(),
534                              VerifyDashValue( pStr, xIf, nArgPos ) );
535 
536             ::std::for_each( strokeAttributes.LineArray.getConstArray(),
537                              strokeAttributes.LineArray.getConstArray() + strokeAttributes.LineArray.getLength(),
538                              VerifyDashValue( pStr, xIf, nArgPos ) );
539 
540             if( strokeAttributes.StartCapType < rendering::PathCapType::BUTT ||
541                 strokeAttributes.StartCapType > rendering::PathCapType::SQUARE )
542             {
543 #if OSL_DEBUG_LEVEL > 0
544                 throw lang::IllegalArgumentException(
545                     ::rtl::OUString::createFromAscii(pStr) +
546                     ::rtl::OUString::createFromAscii(": verifyInput(): stroke attributes' StartCapType value is out of range (") +
547                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(strokeAttributes.StartCapType)) +
548                     ::rtl::OUString::createFromAscii(" not known)"),
549                     xIf,
550                     nArgPos );
551 #else
552                 throw lang::IllegalArgumentException();
553 #endif
554             }
555 
556             if( strokeAttributes.EndCapType < rendering::PathCapType::BUTT ||
557                 strokeAttributes.EndCapType > rendering::PathCapType::SQUARE )
558             {
559 #if OSL_DEBUG_LEVEL > 0
560                 throw lang::IllegalArgumentException(
561                     ::rtl::OUString::createFromAscii(pStr) +
562                     ::rtl::OUString::createFromAscii(": verifyInput(): stroke attributes' StartCapType value is out of range (") +
563                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(strokeAttributes.EndCapType)) +
564                     ::rtl::OUString::createFromAscii(" not known)"),
565                     xIf,
566                     nArgPos );
567 #else
568                 throw lang::IllegalArgumentException();
569 #endif
570             }
571 
572             if( strokeAttributes.JoinType < rendering::PathJoinType::NONE ||
573                 strokeAttributes.JoinType > rendering::PathJoinType::BEVEL )
574             {
575 #if OSL_DEBUG_LEVEL > 0
576                 throw lang::IllegalArgumentException(
577                     ::rtl::OUString::createFromAscii(pStr) +
578                     ::rtl::OUString::createFromAscii(": verifyInput(): stroke attributes' JoinType value is out of range (") +
579                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(strokeAttributes.JoinType)) +
580                     ::rtl::OUString::createFromAscii(" not known)"),
581                     xIf,
582                     nArgPos );
583 #else
584                 throw lang::IllegalArgumentException();
585 #endif
586             }
587         }
588 
verifyInput(const rendering::IntegerBitmapLayout & bitmapLayout,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)589         void verifyInput( const rendering::IntegerBitmapLayout& 	bitmapLayout,
590                           const char*								pStr,
591                           const uno::Reference< uno::XInterface >&	xIf,
592                           ::sal_Int16								nArgPos )
593         {
594             (void)pStr; (void)xIf; (void)nArgPos;
595 
596             if( bitmapLayout.ScanLines < 0 )
597             {
598 #if OSL_DEBUG_LEVEL > 0
599                 throw lang::IllegalArgumentException(
600                     ::rtl::OUString::createFromAscii(pStr) +
601                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ScanLines is negative"),
602                     xIf,
603                     nArgPos );
604 #else
605                 throw lang::IllegalArgumentException();
606 #endif
607             }
608 
609             if( bitmapLayout.ScanLineBytes < 0 )
610             {
611 #if OSL_DEBUG_LEVEL > 0
612                 throw lang::IllegalArgumentException(
613                     ::rtl::OUString::createFromAscii(pStr) +
614                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ScanLineBytes is negative"),
615                     xIf,
616                     nArgPos );
617 #else
618                 throw lang::IllegalArgumentException();
619 #endif
620             }
621 
622             if( !bitmapLayout.ColorSpace.is() )
623             {
624 #if OSL_DEBUG_LEVEL > 0
625                 throw lang::IllegalArgumentException(
626                     ::rtl::OUString::createFromAscii(pStr) +
627                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ColorSpace is invalid"),
628                     xIf,
629                     nArgPos );
630 #else
631                 throw lang::IllegalArgumentException();
632 #endif
633             }
634             else
635             {
636                 if( bitmapLayout.ColorSpace->getBitsPerPixel() < 0 )
637                 {
638 #if OSL_DEBUG_LEVEL > 0
639                     throw lang::IllegalArgumentException(
640                         ::rtl::OUString::createFromAscii(pStr) +
641                         ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ColorSpace getBitsPerPixel() is negative"),
642                         xIf,
643                         nArgPos );
644 #else
645                     throw lang::IllegalArgumentException();
646 #endif
647                 }
648 
649                 if( bitmapLayout.ColorSpace->getEndianness() < util::Endianness::LITTLE ||
650                     bitmapLayout.ColorSpace->getEndianness() > util::Endianness::BIG )
651                 {
652 #if OSL_DEBUG_LEVEL > 0
653                     throw lang::IllegalArgumentException(
654                         ::rtl::OUString::createFromAscii(pStr) +
655                         ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ColorSpace getEndianness() value is out of range (") +
656                         ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(bitmapLayout.ColorSpace->getEndianness())) +
657                         ::rtl::OUString::createFromAscii(" not known)"),
658                         xIf,
659                         nArgPos );
660 #else
661                     throw lang::IllegalArgumentException();
662 #endif
663                 }
664             }
665         }
666 
verifyInput(const rendering::FloatingPointBitmapLayout & bitmapLayout,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)667         void verifyInput( const rendering::FloatingPointBitmapLayout&	bitmapLayout,
668                           const char*									pStr,
669                           const uno::Reference< uno::XInterface >&		xIf,
670                           ::sal_Int16									nArgPos )
671         {
672             (void)pStr; (void)xIf; (void)nArgPos;
673 
674             if( bitmapLayout.ScanLines < 0 )
675             {
676 #if OSL_DEBUG_LEVEL > 0
677                 throw lang::IllegalArgumentException(
678                     ::rtl::OUString::createFromAscii(pStr) +
679                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ScanLines is negative"),
680                     xIf,
681                     nArgPos );
682 #else
683                 throw lang::IllegalArgumentException();
684 #endif
685             }
686 
687             if( bitmapLayout.ScanLineBytes < 0 )
688             {
689 #if OSL_DEBUG_LEVEL > 0
690                 throw lang::IllegalArgumentException(
691                     ::rtl::OUString::createFromAscii(pStr) +
692                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ScanLineBytes is negative"),
693                     xIf,
694                     nArgPos );
695 #else
696                 throw lang::IllegalArgumentException();
697 #endif
698             }
699 
700             if( !bitmapLayout.ColorSpace.is() )
701             {
702 #if OSL_DEBUG_LEVEL > 0
703                 throw lang::IllegalArgumentException(
704                     ::rtl::OUString::createFromAscii(pStr) +
705                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's ColorSpace is invalid"),
706                     xIf,
707                     nArgPos );
708 #else
709                 throw lang::IllegalArgumentException();
710 #endif
711             }
712 
713             if( bitmapLayout.NumComponents < 0 )
714             {
715 #if OSL_DEBUG_LEVEL > 0
716                 throw lang::IllegalArgumentException(
717                     ::rtl::OUString::createFromAscii(pStr) +
718                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's NumComponents is negative"),
719                     xIf,
720                     nArgPos );
721 #else
722                 throw lang::IllegalArgumentException();
723 #endif
724             }
725 
726             if( bitmapLayout.Endianness < util::Endianness::LITTLE ||
727                 bitmapLayout.Endianness > util::Endianness::BIG )
728             {
729 #if OSL_DEBUG_LEVEL > 0
730                 throw lang::IllegalArgumentException(
731                     ::rtl::OUString::createFromAscii(pStr) +
732                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's Endianness value is out of range (") +
733                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(bitmapLayout.Endianness)) +
734                     ::rtl::OUString::createFromAscii(" not known)"),
735                     xIf,
736                     nArgPos );
737 #else
738                 throw lang::IllegalArgumentException();
739 #endif
740             }
741 
742             if( bitmapLayout.Format < rendering::FloatingPointBitmapFormat::HALFFLOAT ||
743                 bitmapLayout.Format > rendering::FloatingPointBitmapFormat::DOUBLE )
744             {
745 #if OSL_DEBUG_LEVEL > 0
746                 throw lang::IllegalArgumentException(
747                     ::rtl::OUString::createFromAscii(pStr) +
748                     ::rtl::OUString::createFromAscii(": verifyInput(): bitmap layout's Format value is out of range (") +
749                     ::rtl::OUString::valueOf(sal::static_int_cast<sal_Int32>(bitmapLayout.Format)) +
750                     ::rtl::OUString::createFromAscii(" not known)"),
751                     xIf,
752                     nArgPos );
753 #else
754                 throw lang::IllegalArgumentException();
755 #endif
756             }
757         }
758 
verifyInput(const rendering::FontInfo &,const char *,const uno::Reference<uno::XInterface> &,::sal_Int16)759         void verifyInput( const rendering::FontInfo&				/*fontInfo*/,
760                           const char*								/*pStr*/,
761                           const uno::Reference< uno::XInterface >&	/*xIf*/,
762                           ::sal_Int16								/*nArgPos*/ )
763         {
764             // TODO(E3): Implement FontDescription checks, once the
765             // Panose stuff is ready.
766         }
767 
verifyInput(const rendering::FontRequest & fontRequest,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)768         void verifyInput( const rendering::FontRequest&				fontRequest,
769                           const char*								pStr,
770                           const uno::Reference< uno::XInterface >&	xIf,
771                           ::sal_Int16								nArgPos )
772         {
773             verifyInput( fontRequest.FontDescription,
774                          pStr, xIf, nArgPos );
775 
776             if( !::rtl::math::isFinite( fontRequest.CellSize ) )
777             {
778 #if OSL_DEBUG_LEVEL > 0
779                 throw lang::IllegalArgumentException(
780                     ::rtl::OUString::createFromAscii(pStr) +
781                     ::rtl::OUString::createFromAscii(": verifyInput(): font request's CellSize value contains infinite or NAN"),
782                     xIf,
783                     nArgPos );
784 #else
785                 throw lang::IllegalArgumentException();
786 #endif
787             }
788 
789             if( !::rtl::math::isFinite( fontRequest.ReferenceAdvancement ) )
790             {
791 #if OSL_DEBUG_LEVEL > 0
792                 throw lang::IllegalArgumentException(
793                     ::rtl::OUString::createFromAscii(pStr) +
794                     ::rtl::OUString::createFromAscii(": verifyInput(): font request's ReferenceAdvancement value contains infinite or NAN"),
795                     xIf,
796                     nArgPos );
797 #else
798                 throw lang::IllegalArgumentException();
799 #endif
800             }
801 
802             if( fontRequest.CellSize != 0.0 &&
803                 fontRequest.ReferenceAdvancement != 0.0 )
804             {
805 #if OSL_DEBUG_LEVEL > 0
806                 throw lang::IllegalArgumentException(
807                     ::rtl::OUString::createFromAscii(pStr) +
808                     ::rtl::OUString::createFromAscii(": verifyInput(): font request's CellSize and ReferenceAdvancement are mutually exclusive, one of them must be 0.0"),
809                     xIf,
810                     nArgPos );
811 #else
812                 throw lang::IllegalArgumentException();
813 #endif
814             }
815         }
816 
verifyIndexRange(const geometry::IntegerRectangle2D & rect,const geometry::IntegerSize2D & size)817         void verifyIndexRange( const geometry::IntegerRectangle2D& 	rect,
818                                const geometry::IntegerSize2D& 	 	size )
819         {
820             const ::basegfx::B2IRange aRect(
821                 ::basegfx::unotools::b2IRectangleFromIntegerRectangle2D(
822                     rect ) );
823 
824             if( aRect.getMinX() < 0 ||
825                 aRect.getMaxX() > size.Width ||
826                 aRect.getMinY() < 0 ||
827                 aRect.getMaxY() > size.Height )
828             {
829                 throw ::com::sun::star::lang::IndexOutOfBoundsException();
830             }
831         }
832 
verifyIndexRange(const geometry::IntegerPoint2D & pos,const geometry::IntegerSize2D & size)833         void verifyIndexRange( const geometry::IntegerPoint2D& pos,
834                                const geometry::IntegerSize2D&  size )
835         {
836             if( pos.X < 0 ||
837                 pos.X > size.Width ||
838                 pos.Y < 0 ||
839                 pos.Y > size.Height )
840             {
841                 throw ::com::sun::star::lang::IndexOutOfBoundsException();
842             }
843         }
844 
verifyBitmapSize(const geometry::IntegerSize2D & size,const char * pStr,const uno::Reference<uno::XInterface> & xIf)845         void verifyBitmapSize( const geometry::IntegerSize2D& 			size,
846                                const char*								pStr,
847                                const uno::Reference< uno::XInterface >&	xIf )
848         {
849             (void)pStr; (void)xIf;
850 
851             if( size.Width <= 0 )
852             {
853 #if OSL_DEBUG_LEVEL > 0
854                 throw lang::IllegalArgumentException(
855                     ::rtl::OUString::createFromAscii(pStr) +
856                     ::rtl::OUString::createFromAscii(": verifyBitmapSize(): size has 0 or negative width (value: ") +
857                     ::rtl::OUString::valueOf(size.Width) +
858                     ::rtl::OUString::createFromAscii(")"),
859                     xIf,
860                     0 );
861 #else
862                 throw lang::IllegalArgumentException();
863 #endif
864             }
865 
866             if( size.Height <= 0 )
867             {
868 #if OSL_DEBUG_LEVEL > 0
869                 throw lang::IllegalArgumentException(
870                     ::rtl::OUString::createFromAscii(pStr) +
871                     ::rtl::OUString::createFromAscii(": verifyBitmapSize(): size has 0 or negative height (value: ") +
872                     ::rtl::OUString::valueOf(size.Height) +
873                     ::rtl::OUString::createFromAscii(")"),
874                     xIf,
875                     0 );
876 #else
877                 throw lang::IllegalArgumentException();
878 #endif
879             }
880         }
881 
verifySpriteSize(const geometry::RealSize2D & size,const char * pStr,const uno::Reference<uno::XInterface> & xIf)882         void verifySpriteSize( const geometry::RealSize2D& 				size,
883                                const char*								pStr,
884                                const uno::Reference< uno::XInterface >&	xIf )
885         {
886             (void)pStr; (void)xIf;
887 
888             if( size.Width <= 0.0 )
889             {
890 #if OSL_DEBUG_LEVEL > 0
891                 throw lang::IllegalArgumentException(
892                     ::rtl::OUString::createFromAscii(pStr) +
893                     ::rtl::OUString::createFromAscii(": verifySpriteSize(): size has 0 or negative width (value: ") +
894                     ::rtl::OUString::valueOf(size.Width) +
895                     ::rtl::OUString::createFromAscii(")"),
896                     xIf,
897                     0 );
898 #else
899                 throw lang::IllegalArgumentException();
900 #endif
901             }
902 
903             if( size.Height <= 0.0 )
904             {
905 #if OSL_DEBUG_LEVEL > 0
906                 throw lang::IllegalArgumentException(
907                     ::rtl::OUString::createFromAscii(pStr) +
908                     ::rtl::OUString::createFromAscii(": verifySpriteSize(): size has 0 or negative height (value: ") +
909                     ::rtl::OUString::valueOf(size.Height) +
910                     ::rtl::OUString::createFromAscii(")"),
911                     xIf,
912                     0 );
913 #else
914                 throw lang::IllegalArgumentException();
915 #endif
916             }
917         }
918 
919 
920 	} // namespace tools
921 
922 } // namespace canvas
923