1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <basegfx/range/b2irange.hxx>
23 #include <basegfx/utils/canvastools.hxx>
24 #include <com/sun/star/geometry/AffineMatrix2D.hpp>
25 #include <com/sun/star/geometry/IntegerPoint2D.hpp>
26 #include <com/sun/star/geometry/IntegerSize2D.hpp>
27 #include <com/sun/star/geometry/Matrix2D.hpp>
28 #include <com/sun/star/geometry/RealBezierSegment2D.hpp>
29 #include <com/sun/star/geometry/RealPoint2D.hpp>
30 #include <com/sun/star/geometry/RealRectangle2D.hpp>
31 #include <com/sun/star/geometry/RealSize2D.hpp>
32 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33 #include <com/sun/star/rendering/CompositeOperation.hpp>
34 #include <com/sun/star/rendering/FontRequest.hpp>
35 #include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
36 #include <com/sun/star/rendering/PathCapType.hpp>
37 #include <com/sun/star/rendering/PathJoinType.hpp>
38 #include <com/sun/star/rendering/RenderState.hpp>
39 #include <com/sun/star/rendering/Texture.hpp>
40 #include <com/sun/star/rendering/TexturingMode.hpp>
41 #include <com/sun/star/rendering/ViewState.hpp>
42 #include <com/sun/star/util/Endianness.hpp>
43 
44 #include <canvas/verifyinput.hxx>
45 
46 
47 using namespace ::com::sun::star;
48 
49 namespace canvas
50 {
51     namespace tools
52     {
verifyInput(const geometry::RealPoint2D & rPoint,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)53         void verifyInput( const geometry::RealPoint2D&              rPoint,
54                           const char*                               pStr,
55                           const uno::Reference< uno::XInterface >&  xIf,
56                           ::sal_Int16                               nArgPos )
57         {
58 #if OSL_DEBUG_LEVEL > 0
59             if( !::rtl::math::isFinite( rPoint.X ) )
60             {
61                 throw lang::IllegalArgumentException(
62                     OUString::createFromAscii( pStr ) + ": verifyInput(): point X value contains infinite or NAN",
63                     xIf, nArgPos );
64             }
65 
66             if( !::rtl::math::isFinite( rPoint.Y ) )
67             {
68                 throw lang::IllegalArgumentException(
69                     OUString::createFromAscii( pStr ) + ": verifyInput(): point X value contains infinite or NAN",
70                     xIf, nArgPos );
71             }
72 #else
73             (void)pStr; (void)xIf; (void)nArgPos;
74             if( !::rtl::math::isFinite( rPoint.X ) ||
75                 !::rtl::math::isFinite( rPoint.Y ) )
76             {
77                 throw lang::IllegalArgumentException();
78             }
79 #endif
80         }
81 
verifyInput(const geometry::RealBezierSegment2D & rSegment,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)82         void verifyInput( const geometry::RealBezierSegment2D&      rSegment,
83                           const char*                               pStr,
84                           const uno::Reference< uno::XInterface >&  xIf,
85                           ::sal_Int16                               nArgPos )
86         {
87 #if OSL_DEBUG_LEVEL > 0
88             if( !::rtl::math::isFinite( rSegment.Px ) )
89             {
90                 throw lang::IllegalArgumentException(
91                     OUString::createFromAscii( pStr ) +
92                     ": verifyInput(): bezier segment's Px value contains infinite or NAN",
93                     xIf, nArgPos );
94             }
95 
96             if( !::rtl::math::isFinite( rSegment.Py ) )
97             {
98                 throw lang::IllegalArgumentException(
99                     OUString::createFromAscii( pStr ) +
100                     ": verifyInput(): bezier segment's Py value contains infinite or NAN",
101                     xIf, nArgPos );
102             }
103 
104             if( !::rtl::math::isFinite( rSegment.C1x ) )
105             {
106                 throw lang::IllegalArgumentException(
107                     OUString::createFromAscii( pStr ) +
108                     ": verifyInput(): bezier segment's C1x value contains infinite or NAN",
109                     xIf, nArgPos );
110             }
111 
112             if( !::rtl::math::isFinite( rSegment.C1y ) )
113             {
114                 throw lang::IllegalArgumentException(
115                     OUString::createFromAscii( pStr ) +
116                     ": verifyInput(): bezier segment's C1y value contains infinite or NAN",
117                     xIf, nArgPos );
118             }
119 
120             if( !::rtl::math::isFinite( rSegment.C2x ) )
121             {
122                 throw lang::IllegalArgumentException(
123                     OUString::createFromAscii( pStr ) +
124                     ": verifyInput(): bezier segment's C2x value contains infinite or NAN",
125                     xIf, nArgPos );
126             }
127 
128             if( !::rtl::math::isFinite( rSegment.C2y ) )
129             {
130                 throw lang::IllegalArgumentException(
131                     OUString::createFromAscii( pStr ) +
132                     ": verifyInput(): bezier segment's C2y value contains infinite or NAN",
133                     xIf, nArgPos );
134             }
135 #else
136             (void)pStr; (void)xIf; (void)nArgPos;
137             if( !::rtl::math::isFinite( rSegment.Px ) ||
138                 !::rtl::math::isFinite( rSegment.Py ) ||
139                 !::rtl::math::isFinite( rSegment.C1x ) ||
140                 !::rtl::math::isFinite( rSegment.C1y ) ||
141                 !::rtl::math::isFinite( rSegment.C2x ) ||
142                 !::rtl::math::isFinite( rSegment.C2y ) )
143             {
144                 throw lang::IllegalArgumentException();
145             }
146 #endif
147         }
148 
verifyInput(const geometry::RealRectangle2D & rRect,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)149         void verifyInput( const geometry::RealRectangle2D&          rRect,
150                           const char*                               pStr,
151                           const uno::Reference< uno::XInterface >&  xIf,
152                           ::sal_Int16                               nArgPos )
153         {
154 #if OSL_DEBUG_LEVEL > 0
155             if( !::rtl::math::isFinite( rRect.X1 ) )
156             {
157                 throw lang::IllegalArgumentException(
158                     OUString::createFromAscii(pStr) +
159                     ": verifyInput(): rectangle point X1 contains infinite or NAN",
160                     xIf, nArgPos );
161             }
162 
163             if( !::rtl::math::isFinite( rRect.Y1 ) )
164             {
165                 throw lang::IllegalArgumentException(
166                     OUString::createFromAscii(pStr) +
167                     ": verifyInput(): rectangle point Y1 contains infinite or NAN",
168                     xIf, nArgPos );
169             }
170 
171             if( !::rtl::math::isFinite( rRect.X2 ) )
172             {
173                 throw lang::IllegalArgumentException(
174                     OUString::createFromAscii(pStr) +
175                     ": verifyInput(): rectangle point X2 contains infinite or NAN",
176                     xIf, nArgPos );
177             }
178 
179             if( !::rtl::math::isFinite( rRect.Y2 ) )
180             {
181                 throw lang::IllegalArgumentException(
182                     OUString::createFromAscii(pStr) +
183                     ": verifyInput(): rectangle point Y2 contains infinite or NAN",
184                     xIf, nArgPos );
185             }
186 #else
187             (void)pStr; (void)xIf; (void)nArgPos;
188             if( !::rtl::math::isFinite( rRect.X1 ) ||
189                 !::rtl::math::isFinite( rRect.Y1 ) ||
190                 !::rtl::math::isFinite( rRect.X2 ) ||
191                 !::rtl::math::isFinite( rRect.Y2 ) )
192             {
193                 throw lang::IllegalArgumentException();
194             }
195 #endif
196         }
197 
verifyInput(const geometry::AffineMatrix2D & matrix,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)198         void verifyInput( const geometry::AffineMatrix2D&           matrix,
199                           const char*                               pStr,
200                           const uno::Reference< uno::XInterface >&  xIf,
201                           ::sal_Int16                               nArgPos )
202         {
203 #if OSL_DEBUG_LEVEL > 0
204             const sal_Int32 nBinaryState(
205                 100000 * int(!::rtl::math::isFinite( matrix.m00 )) +
206                  10000 * int(!::rtl::math::isFinite( matrix.m01 )) +
207                   1000 * int(!::rtl::math::isFinite( matrix.m02 )) +
208                    100 * int(!::rtl::math::isFinite( matrix.m10 )) +
209                     10 * int(!::rtl::math::isFinite( matrix.m11 )) +
210                      1 * int(!::rtl::math::isFinite( matrix.m12 )) );
211 
212             if( nBinaryState )
213             {
214                 throw lang::IllegalArgumentException(
215                     OUString::createFromAscii(pStr) +
216                     ": verifyInput(): AffineMatrix2D contains infinite or NAN value(s) at the following positions (m00-m12): " +
217                     OUString::number(nBinaryState),
218                     xIf, nArgPos );
219             }
220 #else
221             (void)pStr; (void)xIf; (void)nArgPos;
222             if( !::rtl::math::isFinite( matrix.m00 ) ||
223                 !::rtl::math::isFinite( matrix.m01 ) ||
224                 !::rtl::math::isFinite( matrix.m02 ) ||
225                 !::rtl::math::isFinite( matrix.m10 ) ||
226                 !::rtl::math::isFinite( matrix.m11 ) ||
227                 !::rtl::math::isFinite( matrix.m12 ) )
228             {
229                 throw lang::IllegalArgumentException();
230             }
231 #endif
232         }
233 
verifyInput(const geometry::Matrix2D & matrix,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)234         void verifyInput( const geometry::Matrix2D&                 matrix,
235                           const char*                               pStr,
236                           const uno::Reference< uno::XInterface >&  xIf,
237                           ::sal_Int16                               nArgPos )
238         {
239 #if OSL_DEBUG_LEVEL > 0
240             const sal_Int32 nBinaryState(
241                 1000 * int(!::rtl::math::isFinite( matrix.m00 )) +
242                  100 * int(!::rtl::math::isFinite( matrix.m01 )) +
243                   10 * int(!::rtl::math::isFinite( matrix.m10 )) +
244                    1 * int(!::rtl::math::isFinite( matrix.m11 )) );
245 
246             if( nBinaryState )
247             {
248                 throw lang::IllegalArgumentException(
249                     OUString::createFromAscii(pStr) +
250                     ": verifyInput(): Matrix2D contains infinite or NAN value(s) at the following positions (m00-m11): " +
251                     OUString::number(nBinaryState),
252                     xIf, nArgPos );
253             }
254 #else
255             (void)pStr; (void)xIf; (void)nArgPos;
256             if( !::rtl::math::isFinite( matrix.m00 ) ||
257                 !::rtl::math::isFinite( matrix.m01 ) ||
258                 !::rtl::math::isFinite( matrix.m10 ) ||
259                 !::rtl::math::isFinite( matrix.m11 ) )
260             {
261                 throw lang::IllegalArgumentException();
262             }
263 #endif
264         }
265 
verifyInput(const rendering::ViewState & viewState,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)266         void verifyInput( const rendering::ViewState&               viewState,
267                           const char*                               pStr,
268                           const uno::Reference< uno::XInterface >&  xIf,
269                           ::sal_Int16                               nArgPos )
270         {
271             verifyInput( viewState.AffineTransform,
272                          pStr, xIf, nArgPos );
273         }
274 
verifyInput(const rendering::RenderState & renderState,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos,sal_Int32 nMinColorComponents)275         void verifyInput( const rendering::RenderState&             renderState,
276                           const char*                               pStr,
277                           const uno::Reference< uno::XInterface >&  xIf,
278                           ::sal_Int16                               nArgPos,
279                           sal_Int32                                 nMinColorComponents )
280         {
281             verifyInput( renderState.AffineTransform,
282                          pStr, xIf, nArgPos );
283 
284             if( renderState.DeviceColor.getLength() < nMinColorComponents )
285             {
286 #if OSL_DEBUG_LEVEL > 0
287                 throw lang::IllegalArgumentException(
288                     OUString::createFromAscii(pStr) +
289                     ": verifyInput(): render state's device color has too few components (" +
290                     OUString::number(nMinColorComponents) +
291                     " expected, " +
292                     OUString::number(renderState.DeviceColor.getLength()) +
293                     " provided)",
294                     xIf, nArgPos );
295 #else
296                 throw lang::IllegalArgumentException();
297 #endif
298             }
299 
300             if( renderState.CompositeOperation < rendering::CompositeOperation::CLEAR ||
301                 renderState.CompositeOperation > rendering::CompositeOperation::SATURATE )
302             {
303 #if OSL_DEBUG_LEVEL > 0
304                 throw lang::IllegalArgumentException(
305                     OUString::createFromAscii(pStr) +
306                     ": verifyInput(): render state's CompositeOperation value out of range (" +
307                     OUString::number(sal::static_int_cast<sal_Int32>(renderState.CompositeOperation)) +
308                     " not known)",
309                     xIf, nArgPos );
310 #else
311                 throw lang::IllegalArgumentException();
312 #endif
313             }
314         }
315 
verifyInput(const rendering::Texture & texture,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)316         void verifyInput( const rendering::Texture&                 texture,
317                           const char*                               pStr,
318                           const uno::Reference< uno::XInterface >&  xIf,
319                           ::sal_Int16                               nArgPos )
320         {
321             verifyInput( texture.AffineTransform,
322                          pStr, xIf, nArgPos );
323 
324             if( !::rtl::math::isFinite( texture.Alpha ) ||
325                 texture.Alpha < 0.0 ||
326                 texture.Alpha > 1.0 )
327             {
328 #if OSL_DEBUG_LEVEL > 0
329                 throw lang::IllegalArgumentException(
330                     OUString::createFromAscii(pStr) +
331                     ": verifyInput(): textures' alpha value out of range (is " +
332                     OUString::number(texture.Alpha) + ")",
333                     xIf, nArgPos );
334 #else
335                 throw lang::IllegalArgumentException();
336 #endif
337             }
338 
339             if( texture.NumberOfHatchPolygons < 0 )
340             {
341 #if OSL_DEBUG_LEVEL > 0
342                 throw lang::IllegalArgumentException(
343                     OUString::createFromAscii(pStr) +
344                     ": verifyInput(): textures' NumberOfHatchPolygons is negative",
345                     xIf, nArgPos );
346 #else
347                 throw lang::IllegalArgumentException();
348 #endif
349             }
350 
351             if( texture.RepeatModeX < rendering::TexturingMode::NONE ||
352                 texture.RepeatModeX > rendering::TexturingMode::REPEAT )
353             {
354 #if OSL_DEBUG_LEVEL > 0
355                 throw lang::IllegalArgumentException(
356                     OUString::createFromAscii(pStr) +
357                     ": verifyInput(): textures' RepeatModeX value is out of range (" +
358                     OUString::number(sal::static_int_cast<sal_Int32>(texture.RepeatModeX)) +
359                     " not known)",
360                     xIf, nArgPos );
361 #else
362                 throw lang::IllegalArgumentException();
363 #endif
364             }
365 
366             if( texture.RepeatModeY < rendering::TexturingMode::NONE ||
367                 texture.RepeatModeY > rendering::TexturingMode::REPEAT )
368             {
369 #if OSL_DEBUG_LEVEL > 0
370                 throw lang::IllegalArgumentException(
371                     OUString::createFromAscii(pStr) +
372                     ": verifyInput(): textures' RepeatModeY value is out of range (" +
373                     OUString::number(sal::static_int_cast<sal_Int32>(texture.RepeatModeY)) +
374                     " not known)",
375                     xIf, nArgPos );
376 #else
377                 throw lang::IllegalArgumentException();
378 #endif
379             }
380         }
381 
382         namespace
383         {
384             struct VerifyDashValue
385             {
VerifyDashValuecanvas::tools::__anon204808b60111::VerifyDashValue386                 VerifyDashValue( const char*                                pStr,
387                                  const uno::Reference< uno::XInterface >&   xIf,
388                                  ::sal_Int16                                nArgPos ) :
389                     mpStr( pStr ),
390                     mrIf( xIf ),
391                     mnArgPos( nArgPos )
392                 {
393                 }
394 
operator ()canvas::tools::__anon204808b60111::VerifyDashValue395                 void operator()( const double& rVal )
396                 {
397                     if( !::rtl::math::isFinite( rVal ) || rVal < 0.0 )
398                     {
399 #if OSL_DEBUG_LEVEL > 0
400                         throw lang::IllegalArgumentException(
401                             OUString::createFromAscii(mpStr) +
402                             ": verifyInput(): one of stroke attributes' DashArray value out of range (is " +
403                             OUString::number(rVal) + ")",
404                             mrIf, mnArgPos );
405 #else
406                         throw lang::IllegalArgumentException();
407 #endif
408                     }
409                 }
410 
411                 const char*                                 mpStr;
412                 const uno::Reference< uno::XInterface >&    mrIf;
413                 sal_Int16                                   mnArgPos;
414             };
415         }
416 
verifyInput(const rendering::StrokeAttributes & strokeAttributes,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)417         void verifyInput( const rendering::StrokeAttributes&        strokeAttributes,
418                           const char*                               pStr,
419                           const uno::Reference< uno::XInterface >&  xIf,
420                           ::sal_Int16                               nArgPos )
421         {
422             if( !::rtl::math::isFinite( strokeAttributes.StrokeWidth ) ||
423                 strokeAttributes.StrokeWidth < 0.0 )
424             {
425 #if OSL_DEBUG_LEVEL > 0
426                 throw lang::IllegalArgumentException(
427                     OUString::createFromAscii(pStr) +
428                     ": verifyInput(): stroke attributes' StrokeWidth value out of range (is " +
429                     OUString::number(strokeAttributes.StrokeWidth) +
430                     ")",
431                     xIf, nArgPos );
432 #else
433                 throw lang::IllegalArgumentException();
434 #endif
435             }
436 
437             if( !::rtl::math::isFinite( strokeAttributes.MiterLimit ) ||
438                 strokeAttributes.MiterLimit < 0.0 )
439             {
440 #if OSL_DEBUG_LEVEL > 0
441                 throw lang::IllegalArgumentException(
442                     OUString::createFromAscii(pStr) +
443                     ": verifyInput(): stroke attributes' MiterLimit value out of range (is " +
444                     OUString::number(strokeAttributes.MiterLimit) + ")",
445                     xIf, nArgPos );
446 #else
447                 throw lang::IllegalArgumentException();
448 #endif
449             }
450 
451             VerifyDashValue aVerifyDashValue( pStr, xIf, nArgPos );
452             for (auto const& aStrokeAttribute : strokeAttributes.DashArray)
453                 aVerifyDashValue( aStrokeAttribute );
454 
455             for (auto const& aStrokeAttribute : strokeAttributes.LineArray)
456                 aVerifyDashValue( aStrokeAttribute );
457 
458             if( strokeAttributes.StartCapType < rendering::PathCapType::BUTT ||
459                 strokeAttributes.StartCapType > rendering::PathCapType::SQUARE )
460             {
461 #if OSL_DEBUG_LEVEL > 0
462                 throw lang::IllegalArgumentException(
463                     OUString::createFromAscii(pStr) +
464                     ": verifyInput(): stroke attributes' StartCapType value is out of range (" +
465                     OUString::number(sal::static_int_cast<sal_Int32>(strokeAttributes.StartCapType)) +
466                     " not known)",
467                     xIf, nArgPos );
468 #else
469                 throw lang::IllegalArgumentException();
470 #endif
471             }
472 
473             if( strokeAttributes.EndCapType < rendering::PathCapType::BUTT ||
474                 strokeAttributes.EndCapType > rendering::PathCapType::SQUARE )
475             {
476 #if OSL_DEBUG_LEVEL > 0
477                 throw lang::IllegalArgumentException(
478                     OUString::createFromAscii(pStr) +
479                     ": verifyInput(): stroke attributes' StartCapType value is out of range (" +
480                     OUString::number(sal::static_int_cast<sal_Int32>(strokeAttributes.EndCapType)) +
481                     " not known)",
482                     xIf, nArgPos );
483 #else
484                 throw lang::IllegalArgumentException();
485 #endif
486             }
487 
488             if( strokeAttributes.JoinType < rendering::PathJoinType::NONE ||
489                 strokeAttributes.JoinType > rendering::PathJoinType::BEVEL )
490             {
491 #if OSL_DEBUG_LEVEL > 0
492                 throw lang::IllegalArgumentException(
493                     OUString::createFromAscii(pStr) +
494                     ": verifyInput(): stroke attributes' JoinType value is out of range (" +
495                     OUString::number(sal::static_int_cast<sal_Int32>(strokeAttributes.JoinType)) +
496                     " not known)",
497                     xIf, nArgPos );
498 #else
499                 throw lang::IllegalArgumentException();
500 #endif
501             }
502         }
503 
verifyInput(const rendering::IntegerBitmapLayout & bitmapLayout,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)504         void verifyInput( const rendering::IntegerBitmapLayout&     bitmapLayout,
505                           const char*                               pStr,
506                           const uno::Reference< uno::XInterface >&  xIf,
507                           ::sal_Int16                               nArgPos )
508         {
509             if( bitmapLayout.ScanLines < 0 )
510             {
511 #if OSL_DEBUG_LEVEL > 0
512                 throw lang::IllegalArgumentException(
513                     OUString::createFromAscii(pStr) +
514                     ": verifyInput(): bitmap layout's ScanLines is negative",
515                     xIf, nArgPos );
516 #else
517                 (void)pStr; (void)xIf; (void)nArgPos;
518                 throw lang::IllegalArgumentException();
519 #endif
520             }
521 
522             if( bitmapLayout.ScanLineBytes < 0 )
523             {
524 #if OSL_DEBUG_LEVEL > 0
525                 throw lang::IllegalArgumentException(
526                     OUString::createFromAscii(pStr) +
527                     ": verifyInput(): bitmap layout's ScanLineBytes is negative",
528                     xIf, nArgPos );
529 #else
530                 throw lang::IllegalArgumentException();
531 #endif
532             }
533 
534             if( !bitmapLayout.ColorSpace.is() )
535             {
536 #if OSL_DEBUG_LEVEL > 0
537                 throw lang::IllegalArgumentException(
538                     OUString::createFromAscii(pStr) +
539                     ": verifyInput(): bitmap layout's ColorSpace is invalid",
540                     xIf, nArgPos );
541 #else
542                 throw lang::IllegalArgumentException();
543 #endif
544             }
545             if( bitmapLayout.ColorSpace->getBitsPerPixel() < 0 )
546             {
547 #if OSL_DEBUG_LEVEL > 0
548                 throw lang::IllegalArgumentException(
549                     OUString::createFromAscii(pStr) +
550                     ": verifyInput(): bitmap layout's ColorSpace getBitsPerPixel() is negative",
551                     xIf, nArgPos );
552 #else
553                 throw lang::IllegalArgumentException();
554 #endif
555             }
556 
557             if( bitmapLayout.ColorSpace->getEndianness() < util::Endianness::LITTLE ||
558                 bitmapLayout.ColorSpace->getEndianness() > util::Endianness::BIG )
559             {
560 #if OSL_DEBUG_LEVEL > 0
561                 throw lang::IllegalArgumentException(
562                     OUString::createFromAscii(pStr) +
563                     ": verifyInput(): bitmap layout's ColorSpace getEndianness() value is out of range (" +
564                     OUString::number(sal::static_int_cast<sal_Int32>(bitmapLayout.ColorSpace->getEndianness())) +
565                     " not known)",
566                     xIf, nArgPos );
567 #else
568                 throw lang::IllegalArgumentException();
569 #endif
570             }
571         }
572 
verifyInput(const rendering::FontRequest & fontRequest,const char * pStr,const uno::Reference<uno::XInterface> & xIf,::sal_Int16 nArgPos)573         void verifyInput( const rendering::FontRequest&             fontRequest,
574                           const char*                               pStr,
575                           const uno::Reference< uno::XInterface >&  xIf,
576                           ::sal_Int16                               nArgPos )
577         {
578             verifyInput( fontRequest.FontDescription,
579                          pStr, xIf, nArgPos );
580 
581             if( !::rtl::math::isFinite( fontRequest.CellSize ) )
582             {
583 #if OSL_DEBUG_LEVEL > 0
584                 throw lang::IllegalArgumentException(
585                     OUString::createFromAscii(pStr) +
586                     ": verifyInput(): font request's CellSize value contains infinite or NAN",
587                     xIf, nArgPos );
588 #else
589                 throw lang::IllegalArgumentException();
590 #endif
591             }
592 
593             if( !::rtl::math::isFinite( fontRequest.ReferenceAdvancement ) )
594             {
595 #if OSL_DEBUG_LEVEL > 0
596                 throw lang::IllegalArgumentException(
597                     OUString::createFromAscii(pStr) +
598                     ": verifyInput(): font request's ReferenceAdvancement value contains infinite or NAN",
599                     xIf, nArgPos );
600 #else
601                 throw lang::IllegalArgumentException();
602 #endif
603             }
604 
605             if( fontRequest.CellSize != 0.0 &&
606                 fontRequest.ReferenceAdvancement != 0.0 )
607             {
608 #if OSL_DEBUG_LEVEL > 0
609                 throw lang::IllegalArgumentException(
610                     OUString::createFromAscii(pStr) +
611                     ": verifyInput(): font request's CellSize and ReferenceAdvancement are mutually exclusive, one of them must be 0.0",
612                     xIf, nArgPos );
613 #else
614                 throw lang::IllegalArgumentException();
615 #endif
616             }
617         }
618 
verifyIndexRange(const geometry::IntegerRectangle2D & rect,const geometry::IntegerSize2D & size)619         void verifyIndexRange( const geometry::IntegerRectangle2D&  rect,
620                                const geometry::IntegerSize2D&       size )
621         {
622             const ::basegfx::B2IRange aRect(
623                 ::basegfx::unotools::b2IRectangleFromIntegerRectangle2D(
624                     rect ) );
625 
626             if( aRect.getMinX() < 0 ||
627                 aRect.getMaxX() > size.Width ||
628                 aRect.getMinY() < 0 ||
629                 aRect.getMaxY() > size.Height )
630             {
631                 throw css::lang::IndexOutOfBoundsException();
632             }
633         }
634 
verifyIndexRange(const geometry::IntegerPoint2D & pos,const geometry::IntegerSize2D & size)635         void verifyIndexRange( const geometry::IntegerPoint2D& pos,
636                                const geometry::IntegerSize2D&  size )
637         {
638             if( pos.X < 0 ||
639                 pos.X > size.Width ||
640                 pos.Y < 0 ||
641                 pos.Y > size.Height )
642             {
643                 throw css::lang::IndexOutOfBoundsException();
644             }
645         }
646 
verifyBitmapSize(const geometry::IntegerSize2D & size,const char * pStr,const uno::Reference<uno::XInterface> & xIf)647         void verifyBitmapSize( const geometry::IntegerSize2D&           size,
648                                const char*                              pStr,
649                                const uno::Reference< uno::XInterface >& xIf )
650         {
651             if( size.Width <= 0 )
652             {
653 #if OSL_DEBUG_LEVEL > 0
654                 throw lang::IllegalArgumentException(
655                     OUString::createFromAscii(pStr) +
656                     ": verifyBitmapSize(): size has 0 or negative width (value: " +
657                     OUString::number(size.Width) + ")",
658                     xIf, 0 );
659 #else
660                 (void)pStr; (void)xIf;
661                 throw lang::IllegalArgumentException();
662 #endif
663             }
664 
665             if( size.Height <= 0 )
666             {
667 #if OSL_DEBUG_LEVEL > 0
668                 throw lang::IllegalArgumentException(
669                     OUString::createFromAscii(pStr) +
670                     ": verifyBitmapSize(): size has 0 or negative height (value: " +
671                     OUString::number(size.Height) +
672                     ")",
673                     xIf, 0 );
674 #else
675                 throw lang::IllegalArgumentException();
676 #endif
677             }
678         }
679 
verifySpriteSize(const geometry::RealSize2D & size,const char * pStr,const uno::Reference<uno::XInterface> & xIf)680         void verifySpriteSize( const geometry::RealSize2D&              size,
681                                const char*                              pStr,
682                                const uno::Reference< uno::XInterface >& xIf )
683         {
684             if( size.Width <= 0.0 )
685             {
686 #if OSL_DEBUG_LEVEL > 0
687                 throw lang::IllegalArgumentException(
688                     OUString::createFromAscii(pStr) +
689                     ": verifySpriteSize(): size has 0 or negative width (value: " +
690                     OUString::number(size.Width) + ")",
691                     xIf, 0 );
692 #else
693                 (void)pStr; (void)xIf;
694                 throw lang::IllegalArgumentException();
695 #endif
696             }
697 
698             if( size.Height <= 0.0 )
699             {
700 #if OSL_DEBUG_LEVEL > 0
701                 throw lang::IllegalArgumentException(
702                     OUString::createFromAscii(pStr) +
703                     ": verifySpriteSize(): size has 0 or negative height (value: " +
704                     OUString::number(size.Height) + ")",
705                     xIf, 0 );
706 #else
707                 throw lang::IllegalArgumentException();
708 #endif
709             }
710         }
711 
712 
713     } // namespace tools
714 
715 } // namespace canvas
716 
717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
718