cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | // This may look like C code, but it is really -*- C++ -*- |
| 2 | // |
| 3 | // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003 |
| 4 | // |
| 5 | // Implementation of Options |
| 6 | // |
| 7 | // A wrapper around DrawInfo, ImageInfo, and QuantizeInfo |
| 8 | // |
| 9 | |
| 10 | #define MAGICKCORE_IMPLEMENTATION 1 |
| 11 | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
| 12 | |
| 13 | #include "Magick++/Include.h" |
| 14 | #include <string> |
| 15 | #include <string.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <math.h> |
| 18 | #include "Magick++/Options.h" |
| 19 | #include "Magick++/Functions.h" |
| 20 | #include "Magick++/Exception.h" |
| 21 | |
| 22 | #define MagickPI 3.14159265358979323846264338327950288419716939937510 |
| 23 | #define DegreesToRadians(x) (MagickPI*(x)/180.0) |
| 24 | |
| 25 | // Constructor |
| 26 | Magick::Options::Options( void ) |
| 27 | : _imageInfo(static_cast<ImageInfo*>(AcquireMagickMemory(sizeof(ImageInfo)))), |
| 28 | _quantizeInfo(static_cast<QuantizeInfo*>(AcquireMagickMemory(sizeof(QuantizeInfo)))), |
| 29 | _drawInfo(static_cast<DrawInfo*>(AcquireMagickMemory( sizeof(DrawInfo)))) |
| 30 | { |
| 31 | // Initialize image info with defaults |
| 32 | GetImageInfo( _imageInfo ); |
| 33 | |
| 34 | // Initialize quantization info |
| 35 | GetQuantizeInfo( _quantizeInfo ); |
| 36 | |
| 37 | // Initialize drawing info |
| 38 | GetDrawInfo( _imageInfo, _drawInfo ); |
| 39 | } |
| 40 | |
| 41 | // Copy constructor |
| 42 | Magick::Options::Options( const Magick::Options& options_ ) |
| 43 | : _imageInfo(CloneImageInfo( options_._imageInfo )), |
| 44 | _quantizeInfo(CloneQuantizeInfo(options_._quantizeInfo)), |
| 45 | _drawInfo(CloneDrawInfo(_imageInfo, options_._drawInfo)) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | // Construct using raw structures |
| 50 | Magick::Options::Options( const MagickCore::ImageInfo* imageInfo_, |
| 51 | const MagickCore::QuantizeInfo* quantizeInfo_, |
| 52 | const MagickCore::DrawInfo* drawInfo_ ) |
| 53 | : _imageInfo(0), |
| 54 | _quantizeInfo(0), |
| 55 | _drawInfo(0) |
| 56 | { |
| 57 | _imageInfo = CloneImageInfo(imageInfo_); |
| 58 | _quantizeInfo = CloneQuantizeInfo(quantizeInfo_); |
| 59 | _drawInfo = CloneDrawInfo(imageInfo_,drawInfo_); |
| 60 | } |
| 61 | |
| 62 | // Destructor |
| 63 | Magick::Options::~Options() |
| 64 | { |
| 65 | // Destroy image info |
| 66 | _imageInfo =DestroyImageInfo( _imageInfo ); |
| 67 | _imageInfo=0; |
| 68 | |
| 69 | // Destroy quantization info |
| 70 | _quantizeInfo =DestroyQuantizeInfo( _quantizeInfo ); |
| 71 | _quantizeInfo=0; |
| 72 | |
| 73 | // Destroy drawing info |
| 74 | _drawInfo =DestroyDrawInfo( _drawInfo ); |
| 75 | _drawInfo=0; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Methods for setting image attributes |
| 80 | * |
| 81 | */ |
| 82 | |
| 83 | // Anti-alias Postscript and TrueType fonts (default true) |
| 84 | void Magick::Options::antiAlias( bool flag_ ) |
| 85 | { |
| 86 | _drawInfo->text_antialias = static_cast<MagickBooleanType> |
| 87 | (flag_ ? MagickTrue : MagickFalse); |
| 88 | } |
| 89 | bool Magick::Options::antiAlias( void ) const |
| 90 | { |
| 91 | return static_cast<bool>(_drawInfo->text_antialias); |
| 92 | } |
| 93 | |
| 94 | void Magick::Options::adjoin ( bool flag_ ) |
| 95 | { |
| 96 | _imageInfo->adjoin = static_cast<MagickBooleanType> |
| 97 | (flag_ ? MagickTrue : MagickFalse); |
| 98 | } |
| 99 | bool Magick::Options::adjoin ( void ) const |
| 100 | { |
| 101 | return static_cast<bool>(_imageInfo->adjoin); |
| 102 | } |
| 103 | |
| 104 | void Magick::Options::backgroundColor ( const Magick::Color &color_ ) |
| 105 | { |
| 106 | _imageInfo->background_color = color_; |
| 107 | } |
| 108 | Magick::Color Magick::Options::backgroundColor ( void ) const |
| 109 | { |
| 110 | return Magick::Color( _imageInfo->background_color ); |
| 111 | } |
| 112 | |
| 113 | void Magick::Options::backgroundTexture ( const std::string &backgroundTexture_ ) |
| 114 | { |
| 115 | if ( backgroundTexture_.length() == 0 ) |
| 116 | _imageInfo->texture=(char *) RelinquishMagickMemory(_imageInfo->texture); |
| 117 | else |
| 118 | Magick::CloneString( &_imageInfo->texture, backgroundTexture_ ); |
| 119 | } |
| 120 | std::string Magick::Options::backgroundTexture ( void ) const |
| 121 | { |
| 122 | if ( _imageInfo->texture ) |
| 123 | return std::string( _imageInfo->texture ); |
| 124 | else |
| 125 | return std::string(); |
| 126 | } |
| 127 | |
| 128 | void Magick::Options::borderColor ( const Color &color_ ) |
| 129 | { |
| 130 | _imageInfo->border_color = color_; |
| 131 | _drawInfo->border_color = color_; |
| 132 | } |
| 133 | Magick::Color Magick::Options::borderColor ( void ) const |
| 134 | { |
| 135 | return Magick::Color( _imageInfo->border_color ); |
| 136 | } |
| 137 | |
| 138 | // Text bounding-box base color |
| 139 | void Magick::Options::boxColor ( const Magick::Color &boxColor_ ) |
| 140 | { |
| 141 | _drawInfo->undercolor = boxColor_; |
| 142 | } |
| 143 | Magick::Color Magick::Options::boxColor ( void ) const |
| 144 | { |
| 145 | return Magick::Color( _drawInfo->undercolor ); |
| 146 | } |
| 147 | |
| 148 | void Magick::Options::colorspaceType ( Magick::ColorspaceType colorspace_ ) |
| 149 | { |
| 150 | _imageInfo->colorspace = colorspace_; |
| 151 | } |
| 152 | Magick::ColorspaceType Magick::Options::colorspaceType ( void ) const |
| 153 | { |
| 154 | return static_cast<Magick::ColorspaceType>(_imageInfo->colorspace); |
| 155 | } |
| 156 | |
| 157 | void Magick::Options::compressType ( CompressionType compressType_ ) |
| 158 | { |
| 159 | _imageInfo->compression = compressType_; |
| 160 | } |
| 161 | Magick::CompressionType Magick::Options::compressType ( void ) const |
| 162 | { |
| 163 | return static_cast<Magick::CompressionType>(_imageInfo->compression); |
| 164 | } |
| 165 | |
| 166 | void Magick::Options::colorFuzz ( double fuzz_ ) |
| 167 | { |
| 168 | _imageInfo->fuzz = fuzz_; |
| 169 | } |
| 170 | double Magick::Options::colorFuzz ( void ) const |
| 171 | { |
| 172 | return _imageInfo->fuzz; |
| 173 | } |
| 174 | |
| 175 | // Enable printing of debug messages from ImageMagick |
| 176 | void Magick::Options::debug ( bool flag_ ) |
| 177 | { |
| 178 | if(flag_) |
| 179 | { |
| 180 | SetLogEventMask("All"); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | SetLogEventMask("None"); |
| 185 | } |
| 186 | } |
| 187 | bool Magick::Options::debug ( void ) const |
| 188 | { |
| 189 | if( IsEventLogging() ) |
| 190 | { |
| 191 | return true; |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | void Magick::Options::density ( const Magick::Geometry &density_ ) |
| 197 | { |
| 198 | if ( !density_.isValid() ) |
| 199 | _imageInfo->density=(char *) RelinquishMagickMemory(_imageInfo->density); |
| 200 | else |
| 201 | Magick::CloneString( &_imageInfo->density, density_ ); |
| 202 | } |
| 203 | Magick::Geometry Magick::Options::density ( void ) const |
| 204 | { |
| 205 | if ( _imageInfo->density ) |
| 206 | return Geometry( _imageInfo->density ); |
| 207 | |
| 208 | return Geometry(); |
| 209 | } |
| 210 | |
| 211 | void Magick::Options::depth ( unsigned int depth_ ) |
| 212 | { |
| 213 | _imageInfo->depth = depth_; |
| 214 | } |
| 215 | unsigned int Magick::Options::depth ( void ) const |
| 216 | { |
| 217 | return _imageInfo->depth; |
| 218 | } |
| 219 | |
| 220 | // Endianness (little like Intel or big like SPARC) for image |
| 221 | // formats which support endian-specific options. |
| 222 | void Magick::Options::endian ( Magick::EndianType endian_ ) |
| 223 | { |
| 224 | _imageInfo->endian = endian_; |
| 225 | } |
| 226 | Magick::EndianType Magick::Options::endian ( void ) const |
| 227 | { |
| 228 | return _imageInfo->endian; |
| 229 | } |
| 230 | |
cristy | 15781e5 | 2009-12-05 23:05:27 +0000 | [diff] [blame] | 231 | void Magick::Options::file ( FILE *file_ ) |
| 232 | { |
cristy | c3ff8d8 | 2009-12-05 23:55:49 +0000 | [diff] [blame] | 233 | SetImageInfoFile( _imageInfo, file_ ); |
cristy | 15781e5 | 2009-12-05 23:05:27 +0000 | [diff] [blame] | 234 | } |
| 235 | FILE *Magick::Options::file ( void ) const |
| 236 | { |
cristy | 658cdd1 | 2009-12-06 15:13:04 +0000 | [diff] [blame^] | 237 | return GetImageInfoFile( _imageInfo ); |
cristy | 15781e5 | 2009-12-05 23:05:27 +0000 | [diff] [blame] | 238 | } |
| 239 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | void Magick::Options::fileName ( const std::string &fileName_ ) |
| 241 | { |
| 242 | fileName_.copy( _imageInfo->filename, MaxTextExtent-1 ); |
| 243 | _imageInfo->filename[ fileName_.length() ] = 0; |
| 244 | } |
| 245 | std::string Magick::Options::fileName ( void ) const |
| 246 | { |
| 247 | return std::string( _imageInfo->filename ); |
| 248 | } |
| 249 | |
| 250 | // Color to use when drawing inside an object |
| 251 | void Magick::Options::fillColor ( const Magick::Color &fillColor_ ) |
| 252 | { |
| 253 | _drawInfo->fill = fillColor_; |
| 254 | if (fillColor_ == Magick::Color()) |
| 255 | fillPattern((const MagickCore::Image*) NULL); |
| 256 | } |
| 257 | Magick::Color Magick::Options::fillColor ( void ) const |
| 258 | { |
| 259 | return _drawInfo->fill; |
| 260 | } |
| 261 | // Pattern image to use when filling objects |
| 262 | void Magick::Options::fillPattern ( const MagickCore::Image *fillPattern_ ) |
| 263 | { |
| 264 | if ( _drawInfo->fill_pattern ) |
| 265 | { |
| 266 | DestroyImageList( _drawInfo->fill_pattern ); |
| 267 | _drawInfo->fill_pattern = 0; |
| 268 | } |
| 269 | if ( fillPattern_ ) |
| 270 | { |
| 271 | ExceptionInfo exceptionInfo; |
| 272 | GetExceptionInfo( &exceptionInfo ); |
| 273 | _drawInfo->fill_pattern = |
| 274 | CloneImage( const_cast<MagickCore::Image*>(fillPattern_), |
| 275 | 0, |
| 276 | 0, |
| 277 | static_cast<MagickBooleanType>(MagickTrue), |
| 278 | &exceptionInfo ); |
| 279 | throwException( exceptionInfo ); |
| 280 | (void) DestroyExceptionInfo( &exceptionInfo ); |
| 281 | } |
| 282 | } |
| 283 | const MagickCore::Image* Magick::Options::fillPattern ( void ) const |
| 284 | { |
| 285 | return _drawInfo->fill_pattern; |
| 286 | } |
| 287 | |
| 288 | // Rule to use when filling drawn objects |
| 289 | void Magick::Options::fillRule ( const Magick::FillRule &fillRule_ ) |
| 290 | { |
| 291 | _drawInfo->fill_rule = fillRule_; |
| 292 | } |
| 293 | Magick::FillRule Magick::Options::fillRule ( void ) const |
| 294 | { |
| 295 | return _drawInfo->fill_rule; |
| 296 | } |
| 297 | |
| 298 | void Magick::Options::font ( const std::string &font_ ) |
| 299 | { |
| 300 | if ( font_.length() == 0 ) |
| 301 | { |
| 302 | _imageInfo->font=(char *) RelinquishMagickMemory(_imageInfo->font); |
| 303 | _drawInfo->font=(char *) RelinquishMagickMemory(_drawInfo->font); |
| 304 | } |
| 305 | else |
| 306 | { |
| 307 | Magick::CloneString( &_imageInfo->font, font_ ); |
| 308 | Magick::CloneString( &_drawInfo->font, font_ ); |
| 309 | } |
| 310 | } |
| 311 | std::string Magick::Options::font ( void ) const |
| 312 | { |
| 313 | if ( _imageInfo->font ) |
| 314 | return std::string( _imageInfo->font ); |
| 315 | |
| 316 | return std::string(); |
| 317 | } |
| 318 | |
| 319 | void Magick::Options::fontPointsize ( double pointSize_ ) |
| 320 | { |
| 321 | _imageInfo->pointsize = pointSize_; |
| 322 | _drawInfo->pointsize = pointSize_; |
| 323 | } |
| 324 | double Magick::Options::fontPointsize ( void ) const |
| 325 | { |
| 326 | return _imageInfo->pointsize; |
| 327 | } |
| 328 | |
| 329 | std::string Magick::Options::format ( void ) const |
| 330 | { |
| 331 | ExceptionInfo exception; |
| 332 | |
| 333 | const MagickInfo * magick_info = 0; |
| 334 | GetExceptionInfo(&exception); |
| 335 | if ( *_imageInfo->magick != '\0' ) |
| 336 | magick_info = GetMagickInfo( _imageInfo->magick , &exception); |
| 337 | throwException( exception ); |
| 338 | (void) DestroyExceptionInfo( &exception ); |
| 339 | |
| 340 | if (( magick_info != 0 ) && |
| 341 | ( *magick_info->description != '\0' )) |
| 342 | return std::string( magick_info->description ); |
| 343 | |
| 344 | return std::string(); |
| 345 | } |
| 346 | |
| 347 | void Magick::Options::interlaceType ( Magick::InterlaceType interlace_ ) |
| 348 | { |
| 349 | _imageInfo->interlace = interlace_; |
| 350 | } |
| 351 | Magick::InterlaceType Magick::Options::interlaceType ( void ) const |
| 352 | { |
| 353 | return static_cast<Magick::InterlaceType>(_imageInfo->interlace); |
| 354 | } |
| 355 | |
| 356 | void Magick::Options::magick ( const std::string &magick_ ) |
| 357 | { |
| 358 | ExceptionInfo exception; |
| 359 | |
| 360 | FormatMagickString( _imageInfo->filename, MaxTextExtent, "%.1024s:", magick_.c_str() ); |
| 361 | GetExceptionInfo(&exception); |
| 362 | SetImageInfo( _imageInfo, MagickTrue, &exception); |
| 363 | if ( *_imageInfo->magick == '\0' ) |
| 364 | throwExceptionExplicit( OptionWarning, |
| 365 | "Unrecognized image format", |
| 366 | magick_.c_str() ); |
| 367 | (void) DestroyExceptionInfo( &exception ); |
| 368 | } |
| 369 | std::string Magick::Options::magick ( void ) const |
| 370 | { |
| 371 | if ( _imageInfo->magick && *_imageInfo->magick ) |
| 372 | return std::string( _imageInfo->magick ); |
| 373 | |
| 374 | return std::string(); |
| 375 | } |
| 376 | |
| 377 | void Magick::Options::matteColor ( const Magick::Color &matteColor_ ) |
| 378 | { |
| 379 | _imageInfo->matte_color = matteColor_; |
| 380 | } |
| 381 | Magick::Color Magick::Options::matteColor ( void ) const |
| 382 | { |
| 383 | return Magick::Color( _imageInfo->matte_color ); |
| 384 | } |
| 385 | |
| 386 | void Magick::Options::monochrome ( bool monochromeFlag_ ) |
| 387 | { |
| 388 | _imageInfo->monochrome = (MagickBooleanType) monochromeFlag_; |
| 389 | } |
| 390 | bool Magick::Options::monochrome ( void ) const |
| 391 | { |
| 392 | return static_cast<bool>(_imageInfo->monochrome); |
| 393 | } |
| 394 | |
| 395 | void Magick::Options::page ( const Magick::Geometry &pageSize_ ) |
| 396 | { |
| 397 | if ( !pageSize_.isValid() ) |
| 398 | _imageInfo->page=(char *) RelinquishMagickMemory(_imageInfo->page); |
| 399 | else |
| 400 | Magick::CloneString( &_imageInfo->page, pageSize_ ); |
| 401 | } |
| 402 | Magick::Geometry Magick::Options::page ( void ) const |
| 403 | { |
| 404 | if ( _imageInfo->page ) |
| 405 | return Geometry( _imageInfo->page ); |
| 406 | |
| 407 | return Geometry(); |
| 408 | } |
| 409 | |
| 410 | void Magick::Options::quality ( unsigned int quality_ ) |
| 411 | { |
| 412 | _imageInfo->quality = quality_; |
| 413 | } |
| 414 | unsigned int Magick::Options::quality ( void ) const |
| 415 | { |
| 416 | return _imageInfo->quality; |
| 417 | } |
| 418 | |
| 419 | void Magick::Options::quantizeColors ( unsigned int colors_ ) |
| 420 | { |
| 421 | _quantizeInfo->number_colors = colors_; |
| 422 | } |
| 423 | unsigned int Magick::Options::quantizeColors ( void ) const |
| 424 | { |
| 425 | return _quantizeInfo->number_colors; |
| 426 | } |
| 427 | |
| 428 | void Magick::Options::quantizeColorSpace ( Magick::ColorspaceType colorSpace_ ) |
| 429 | { |
| 430 | _quantizeInfo->colorspace = colorSpace_; |
| 431 | } |
| 432 | Magick::ColorspaceType Magick::Options::quantizeColorSpace ( void ) const |
| 433 | { |
| 434 | return static_cast<Magick::ColorspaceType>(_quantizeInfo->colorspace); |
| 435 | } |
| 436 | |
| 437 | void Magick::Options::quantizeDither ( bool ditherFlag_ ) |
| 438 | { |
| 439 | _imageInfo->dither = (MagickBooleanType) ditherFlag_; |
| 440 | _quantizeInfo->dither = (MagickBooleanType) ditherFlag_; |
| 441 | } |
| 442 | bool Magick::Options::quantizeDither ( void ) const |
| 443 | { |
| 444 | return static_cast<bool>(_imageInfo->dither); |
| 445 | } |
| 446 | |
| 447 | void Magick::Options::quantizeTreeDepth ( unsigned int treeDepth_ ) |
| 448 | { |
| 449 | _quantizeInfo->tree_depth = treeDepth_; |
| 450 | } |
| 451 | unsigned int Magick::Options::quantizeTreeDepth ( void ) const |
| 452 | { |
| 453 | return _quantizeInfo->tree_depth; |
| 454 | } |
| 455 | |
| 456 | void Magick::Options::resolutionUnits ( Magick::ResolutionType resolutionUnits_ ) |
| 457 | { |
| 458 | _imageInfo->units = resolutionUnits_; |
| 459 | } |
| 460 | Magick::ResolutionType Magick::Options::resolutionUnits ( void ) const |
| 461 | { |
| 462 | return static_cast<Magick::ResolutionType>(_imageInfo->units); |
| 463 | } |
| 464 | |
| 465 | void Magick::Options::samplingFactor ( const std::string &samplingFactor_ ) |
| 466 | { |
| 467 | if ( samplingFactor_.length() == 0 ) |
| 468 | _imageInfo->sampling_factor=(char *) RelinquishMagickMemory(_imageInfo->sampling_factor); |
| 469 | else |
| 470 | Magick::CloneString( &_imageInfo->sampling_factor, samplingFactor_ ); |
| 471 | } |
| 472 | std::string Magick::Options::samplingFactor ( void ) const |
| 473 | { |
| 474 | if ( _imageInfo->sampling_factor ) |
| 475 | return std::string( _imageInfo->sampling_factor ); |
| 476 | |
| 477 | return std::string(); |
| 478 | } |
| 479 | |
| 480 | void Magick::Options::size ( const Geometry &geometry_ ) |
| 481 | { |
| 482 | _imageInfo->size=(char *) RelinquishMagickMemory(_imageInfo->size); |
| 483 | |
| 484 | if ( geometry_.isValid() ) |
| 485 | Magick::CloneString( &_imageInfo->size, geometry_ ); |
| 486 | } |
| 487 | Magick::Geometry Magick::Options::size ( void ) const |
| 488 | { |
| 489 | if ( _imageInfo->size ) |
| 490 | return Geometry( _imageInfo->size ); |
| 491 | |
| 492 | return Geometry(); |
| 493 | } |
| 494 | |
| 495 | void Magick::Options::strokeAntiAlias( bool flag_ ) |
| 496 | { |
| 497 | flag_ ? _drawInfo->stroke_antialias=MagickTrue : _drawInfo->stroke_antialias=MagickFalse; |
| 498 | } |
| 499 | bool Magick::Options::strokeAntiAlias( void ) const |
| 500 | { |
| 501 | return (_drawInfo->stroke_antialias != 0 ? true : false); |
| 502 | } |
| 503 | |
| 504 | // Color to use when drawing object outlines |
| 505 | void Magick::Options::strokeColor ( const Magick::Color &strokeColor_ ) |
| 506 | { |
| 507 | _drawInfo->stroke = strokeColor_; |
| 508 | } |
| 509 | Magick::Color Magick::Options::strokeColor ( void ) const |
| 510 | { |
| 511 | return _drawInfo->stroke; |
| 512 | } |
| 513 | |
| 514 | void Magick::Options::strokeDashArray ( const double* strokeDashArray_ ) |
| 515 | { |
| 516 | _drawInfo->dash_pattern=(double *) |
| 517 | RelinquishMagickMemory(_drawInfo->dash_pattern); |
| 518 | |
| 519 | if(strokeDashArray_) |
| 520 | { |
| 521 | // Count elements in dash array |
| 522 | unsigned int x; |
| 523 | for (x=0; strokeDashArray_[x]; x++) ; |
| 524 | // Allocate elements |
| 525 | _drawInfo->dash_pattern = |
| 526 | static_cast<double*>(AcquireMagickMemory((x+1)*sizeof(double))); |
| 527 | // Copy elements |
| 528 | memcpy(_drawInfo->dash_pattern,strokeDashArray_, |
| 529 | (x+1)*sizeof(double)); |
| 530 | } |
| 531 | } |
| 532 | const double* Magick::Options::strokeDashArray ( void ) const |
| 533 | { |
| 534 | return _drawInfo->dash_pattern; |
| 535 | } |
| 536 | |
| 537 | void Magick::Options::strokeDashOffset ( double strokeDashOffset_ ) |
| 538 | { |
| 539 | _drawInfo->dash_offset = strokeDashOffset_; |
| 540 | } |
| 541 | double Magick::Options::strokeDashOffset ( void ) const |
| 542 | { |
| 543 | return _drawInfo->dash_offset; |
| 544 | } |
| 545 | |
| 546 | // Specify the shape to be used at the end of open subpaths when they |
| 547 | // are stroked. Values of LineCap are ButtCap, RoundCap, and |
| 548 | // SquareCap. |
| 549 | void Magick::Options::strokeLineCap ( Magick::LineCap lineCap_ ) |
| 550 | { |
| 551 | _drawInfo->linecap = lineCap_; |
| 552 | } |
| 553 | Magick::LineCap Magick::Options::strokeLineCap ( void ) const |
| 554 | { |
| 555 | return _drawInfo->linecap; |
| 556 | } |
| 557 | |
| 558 | // Specify the shape to be used at the corners of paths (or other |
| 559 | // vector shapes) when they are stroked. |
| 560 | void Magick::Options::strokeLineJoin ( Magick::LineJoin lineJoin_ ) |
| 561 | { |
| 562 | _drawInfo->linejoin = lineJoin_; |
| 563 | } |
| 564 | Magick::LineJoin Magick::Options::strokeLineJoin ( void ) const |
| 565 | { |
| 566 | return _drawInfo->linejoin; |
| 567 | } |
| 568 | |
| 569 | // miterLimit for drawing lines, circles, ellipses, etc. |
| 570 | void Magick::Options::strokeMiterLimit ( unsigned int miterLimit_ ) |
| 571 | { |
| 572 | _drawInfo->miterlimit = miterLimit_; |
| 573 | } |
| 574 | unsigned int Magick::Options::strokeMiterLimit ( void ) const |
| 575 | { |
| 576 | return _drawInfo->miterlimit; |
| 577 | } |
| 578 | |
| 579 | // Pattern image to use for stroked outlines |
| 580 | void Magick::Options::strokePattern ( const MagickCore::Image *strokePattern_ ) |
| 581 | { |
| 582 | if ( _drawInfo->stroke_pattern ) |
| 583 | { |
| 584 | DestroyImageList( _drawInfo->stroke_pattern ); |
| 585 | _drawInfo->stroke_pattern = 0; |
| 586 | } |
| 587 | |
| 588 | if ( strokePattern_ ) |
| 589 | { |
| 590 | ExceptionInfo exceptionInfo; |
| 591 | GetExceptionInfo( &exceptionInfo ); |
| 592 | _drawInfo->stroke_pattern = |
| 593 | CloneImage( const_cast<MagickCore::Image*>(strokePattern_), |
| 594 | 0, |
| 595 | 0, |
| 596 | MagickTrue, |
| 597 | &exceptionInfo ); |
| 598 | throwException( exceptionInfo ); |
| 599 | (void) DestroyExceptionInfo( &exceptionInfo ); |
| 600 | } |
| 601 | } |
| 602 | const MagickCore::Image* Magick::Options::strokePattern ( void ) const |
| 603 | { |
| 604 | return _drawInfo->stroke_pattern; |
| 605 | } |
| 606 | |
| 607 | // Stroke width for drawing lines, circles, ellipses, etc. |
| 608 | void Magick::Options::strokeWidth ( double strokeWidth_ ) |
| 609 | { |
| 610 | _drawInfo->stroke_width = strokeWidth_; |
| 611 | } |
| 612 | double Magick::Options::strokeWidth ( void ) const |
| 613 | { |
| 614 | return _drawInfo->stroke_width; |
| 615 | } |
| 616 | |
| 617 | void Magick::Options::subImage ( unsigned int subImage_ ) |
| 618 | { |
| 619 | _imageInfo->scene = subImage_; |
| 620 | } |
| 621 | unsigned int Magick::Options::subImage ( void ) const |
| 622 | { |
| 623 | return _imageInfo->scene; |
| 624 | } |
| 625 | |
| 626 | void Magick::Options::subRange ( unsigned int subRange_ ) |
| 627 | { |
| 628 | _imageInfo->number_scenes = subRange_; |
| 629 | } |
| 630 | unsigned int Magick::Options::subRange ( void ) const |
| 631 | { |
| 632 | return _imageInfo->number_scenes; |
| 633 | } |
| 634 | |
| 635 | // Annotation text encoding (e.g. "UTF-16") |
| 636 | void Magick::Options::textEncoding ( const std::string &encoding_ ) |
| 637 | { |
| 638 | CloneString(&_drawInfo->encoding, encoding_.c_str()); |
| 639 | } |
| 640 | std::string Magick::Options::textEncoding ( void ) const |
| 641 | { |
| 642 | if ( _drawInfo->encoding && *_drawInfo->encoding ) |
| 643 | return std::string( _drawInfo->encoding ); |
| 644 | |
| 645 | return std::string(); |
| 646 | } |
| 647 | |
| 648 | void Magick::Options::tileName ( const std::string &tileName_ ) |
| 649 | { |
| 650 | if ( tileName_.length() == 0 ) |
| 651 | _imageInfo->tile=(char *) RelinquishMagickMemory(_imageInfo->tile); |
| 652 | else |
| 653 | Magick::CloneString( &_imageInfo->tile, tileName_ ); |
| 654 | } |
| 655 | std::string Magick::Options::tileName ( void ) const |
| 656 | { |
| 657 | if ( _imageInfo->tile ) |
| 658 | return std::string( _imageInfo->tile ); |
| 659 | return std::string(); |
| 660 | } |
| 661 | |
| 662 | // Image representation type |
| 663 | void Magick::Options::type ( const Magick::ImageType type_ ) |
| 664 | { |
| 665 | _imageInfo->type = type_; |
| 666 | } |
| 667 | Magick::ImageType Magick::Options::type ( void ) const |
| 668 | { |
| 669 | return _imageInfo->type; |
| 670 | } |
| 671 | |
| 672 | // Origin of coordinate system to use when annotating with text or drawing |
| 673 | void Magick::Options::transformOrigin ( double tx_, double ty_ ) |
| 674 | { |
| 675 | AffineMatrix current = _drawInfo->affine; |
| 676 | AffineMatrix affine; |
| 677 | affine.sx=1.0; |
| 678 | affine.rx=0.0; |
| 679 | affine.ry=0.0; |
| 680 | affine.sy=1.0; |
| 681 | affine.tx=0.0; |
| 682 | affine.ty=0.0; |
| 683 | |
| 684 | affine.tx = tx_; |
| 685 | affine.ty = ty_; |
| 686 | |
| 687 | _drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 688 | _drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 689 | _drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 690 | _drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 691 | _drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; |
| 692 | _drawInfo->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; |
| 693 | } |
| 694 | |
| 695 | // Reset transformation parameters to default |
| 696 | void Magick::Options::transformReset ( void ) |
| 697 | { |
| 698 | _drawInfo->affine.sx=1.0; |
| 699 | _drawInfo->affine.rx=0.0; |
| 700 | _drawInfo->affine.ry=0.0; |
| 701 | _drawInfo->affine.sy=1.0; |
| 702 | _drawInfo->affine.tx=0.0; |
| 703 | _drawInfo->affine.ty=0.0; |
| 704 | } |
| 705 | |
| 706 | // Rotation to use when annotating with text or drawing |
| 707 | void Magick::Options::transformRotation ( double angle_ ) |
| 708 | { |
| 709 | AffineMatrix current = _drawInfo->affine; |
| 710 | AffineMatrix affine; |
| 711 | affine.sx=1.0; |
| 712 | affine.rx=0.0; |
| 713 | affine.ry=0.0; |
| 714 | affine.sy=1.0; |
| 715 | affine.tx=0.0; |
| 716 | affine.ty=0.0; |
| 717 | |
| 718 | affine.sx=cos(DegreesToRadians(fmod(angle_,360.0))); |
| 719 | affine.rx=(-sin(DegreesToRadians(fmod(angle_,360.0)))); |
| 720 | affine.ry=sin(DegreesToRadians(fmod(angle_,360.0))); |
| 721 | affine.sy=cos(DegreesToRadians(fmod(angle_,360.0))); |
| 722 | |
| 723 | _drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 724 | _drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 725 | _drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 726 | _drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 727 | _drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; |
| 728 | _drawInfo->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; |
| 729 | } |
| 730 | |
| 731 | // Scale to use when annotating with text or drawing |
| 732 | void Magick::Options::transformScale ( double sx_, double sy_ ) |
| 733 | { |
| 734 | AffineMatrix current = _drawInfo->affine; |
| 735 | AffineMatrix affine; |
| 736 | affine.sx=1.0; |
| 737 | affine.rx=0.0; |
| 738 | affine.ry=0.0; |
| 739 | affine.sy=1.0; |
| 740 | affine.tx=0.0; |
| 741 | affine.ty=0.0; |
| 742 | |
| 743 | affine.sx = sx_; |
| 744 | affine.sy = sy_; |
| 745 | |
| 746 | _drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 747 | _drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 748 | _drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 749 | _drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 750 | _drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; |
| 751 | _drawInfo->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; |
| 752 | } |
| 753 | |
| 754 | // Skew to use in X axis when annotating with text or drawing |
| 755 | void Magick::Options::transformSkewX ( double skewx_ ) |
| 756 | { |
| 757 | AffineMatrix current = _drawInfo->affine; |
| 758 | AffineMatrix affine; |
| 759 | affine.sx=1.0; |
| 760 | affine.rx=0.0; |
| 761 | affine.ry=0.0; |
| 762 | affine.sy=1.0; |
| 763 | affine.tx=0.0; |
| 764 | affine.ty=0.0; |
| 765 | |
| 766 | affine.sx=1.0; |
| 767 | affine.ry=tan(DegreesToRadians(fmod(skewx_,360.0))); |
| 768 | affine.sy=1.0; |
| 769 | |
| 770 | _drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 771 | _drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 772 | _drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 773 | _drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 774 | _drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; |
| 775 | _drawInfo->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; |
| 776 | } |
| 777 | |
| 778 | // Skew to use in Y axis when annotating with text or drawing |
| 779 | void Magick::Options::transformSkewY ( double skewy_ ) |
| 780 | { |
| 781 | AffineMatrix current = _drawInfo->affine; |
| 782 | AffineMatrix affine; |
| 783 | affine.sx=1.0; |
| 784 | affine.rx=0.0; |
| 785 | affine.ry=0.0; |
| 786 | affine.sy=1.0; |
| 787 | affine.tx=0.0; |
| 788 | affine.ty=0.0; |
| 789 | |
| 790 | affine.sx=1.0; |
| 791 | affine.rx=tan(DegreesToRadians(fmod(skewy_,360.0))); |
| 792 | affine.sy=1.0; |
| 793 | |
| 794 | _drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 795 | _drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 796 | _drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 797 | _drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 798 | _drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; |
| 799 | _drawInfo->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; |
| 800 | } |
| 801 | |
| 802 | void Magick::Options::verbose ( bool verboseFlag_ ) |
| 803 | { |
| 804 | _imageInfo->verbose = (MagickBooleanType) verboseFlag_; |
| 805 | } |
| 806 | bool Magick::Options::verbose ( void ) const |
| 807 | { |
| 808 | return static_cast<bool>(_imageInfo->verbose); |
| 809 | } |
| 810 | |
| 811 | void Magick::Options::virtualPixelMethod ( VirtualPixelMethod virtual_pixel_method_ ) |
| 812 | { |
| 813 | _imageInfo->virtual_pixel_method = virtual_pixel_method_; |
| 814 | } |
| 815 | Magick::VirtualPixelMethod Magick::Options::virtualPixelMethod ( void ) const |
| 816 | { |
| 817 | return static_cast<Magick::VirtualPixelMethod>(_imageInfo->virtual_pixel_method); |
| 818 | } |
| 819 | |
| 820 | void Magick::Options::view ( const std::string &view_ ) |
| 821 | { |
| 822 | if ( view_.length() == 0 ) |
| 823 | _imageInfo->view=(char *) RelinquishMagickMemory(_imageInfo->view); |
| 824 | else |
| 825 | Magick::CloneString( &_imageInfo->view, view_ ); |
| 826 | } |
| 827 | std::string Magick::Options::view ( void ) const |
| 828 | { |
| 829 | if ( _imageInfo->view ) |
| 830 | return std::string( _imageInfo->view ); |
| 831 | |
| 832 | return std::string(); |
| 833 | } |
| 834 | |
| 835 | void Magick::Options::x11Display ( const std::string &display_ ) |
| 836 | { |
| 837 | if ( display_.length() == 0 ) |
| 838 | _imageInfo->server_name=(char *) RelinquishMagickMemory(_imageInfo->server_name); |
| 839 | else |
| 840 | Magick::CloneString( &_imageInfo->server_name, display_ ); |
| 841 | } |
| 842 | std::string Magick::Options::x11Display ( void ) const |
| 843 | { |
| 844 | if ( _imageInfo->server_name ) |
| 845 | return std::string( _imageInfo->server_name ); |
| 846 | |
| 847 | return std::string(); |
| 848 | } |
| 849 | |
| 850 | // |
| 851 | // Internal implementation methods. Please do not use. |
| 852 | // |
| 853 | |
| 854 | MagickCore::DrawInfo * Magick::Options::drawInfo( void ) |
| 855 | { |
| 856 | return _drawInfo; |
| 857 | } |
| 858 | |
| 859 | MagickCore::ImageInfo * Magick::Options::imageInfo( void ) |
| 860 | { |
| 861 | return _imageInfo; |
| 862 | } |
| 863 | |
| 864 | MagickCore::QuantizeInfo * Magick::Options::quantizeInfo( void ) |
| 865 | { |
| 866 | return _quantizeInfo; |
| 867 | } |