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