cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS V V GGGG % |
| 7 | % SS V V G % |
| 8 | % SSS V V G GG % |
| 9 | % SS V V G G % |
| 10 | % SSSSS V GGG % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Scalable Vector Graphics Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % William Radcliffe % |
| 18 | % March 2000 % |
| 19 | % % |
| 20 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 21 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 22 | % dedicated to making software imaging solutions freely available. % |
| 23 | % % |
| 24 | % You may not use this file except in compliance with the License. You may % |
| 25 | % obtain a copy of the License at % |
| 26 | % % |
| 27 | % http://www.imagemagick.org/script/license.php % |
| 28 | % % |
| 29 | % Unless required by applicable law or agreed to in writing, software % |
| 30 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 31 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 32 | % See the License for the specific language governing permissions and % |
| 33 | % limitations under the License. % |
| 34 | % % |
| 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/annotate.h" |
| 45 | #include "MagickCore/artifact.h" |
| 46 | #include "MagickCore/attribute.h" |
| 47 | #include "MagickCore/blob.h" |
| 48 | #include "MagickCore/blob-private.h" |
| 49 | #include "MagickCore/cache.h" |
| 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/composite-private.h" |
| 52 | #include "MagickCore/draw.h" |
| 53 | #include "MagickCore/exception.h" |
| 54 | #include "MagickCore/exception-private.h" |
| 55 | #include "MagickCore/gem.h" |
| 56 | #include "MagickCore/image.h" |
| 57 | #include "MagickCore/image-private.h" |
| 58 | #include "MagickCore/list.h" |
| 59 | #include "MagickCore/log.h" |
| 60 | #include "MagickCore/magick.h" |
| 61 | #include "MagickCore/memory_.h" |
| 62 | #include "MagickCore/module.h" |
| 63 | #include "MagickCore/monitor.h" |
| 64 | #include "MagickCore/monitor-private.h" |
| 65 | #include "MagickCore/quantum-private.h" |
| 66 | #include "MagickCore/pixel-accessor.h" |
| 67 | #include "MagickCore/property.h" |
| 68 | #include "MagickCore/resource_.h" |
| 69 | #include "MagickCore/static.h" |
| 70 | #include "MagickCore/string_.h" |
| 71 | #include "MagickCore/string-private.h" |
| 72 | #include "MagickCore/token.h" |
| 73 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 74 | #if defined(MAGICKCORE_XML_DELEGATE) |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 75 | # if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | # if defined(__MINGW32__) |
| 77 | # define _MSC_VER |
| 78 | # else |
| 79 | # include <win32config.h> |
| 80 | # endif |
| 81 | # endif |
| 82 | # include <libxml/parser.h> |
| 83 | # include <libxml/xmlmemory.h> |
| 84 | # include <libxml/parserInternals.h> |
| 85 | # include <libxml/xmlerror.h> |
| 86 | #endif |
| 87 | |
| 88 | #if defined(MAGICKCORE_AUTOTRACE_DELEGATE) |
| 89 | #include "autotrace/autotrace.h" |
| 90 | #endif |
| 91 | |
| 92 | #if defined(MAGICKCORE_RSVG_DELEGATE) |
| 93 | #include "librsvg/rsvg.h" |
| 94 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 95 | #include "librsvg/rsvg-cairo.h" |
| 96 | #endif |
| 97 | #include "librsvg/librsvg-features.h" |
| 98 | #endif |
| 99 | |
| 100 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | Typedef declarations. |
| 102 | */ |
| 103 | typedef struct _BoundingBox |
| 104 | { |
| 105 | double |
| 106 | x, |
| 107 | y, |
| 108 | width, |
| 109 | height; |
| 110 | } BoundingBox; |
| 111 | |
| 112 | typedef struct _ElementInfo |
| 113 | { |
| 114 | double |
| 115 | cx, |
| 116 | cy, |
| 117 | major, |
| 118 | minor, |
| 119 | angle; |
| 120 | } ElementInfo; |
| 121 | |
| 122 | typedef struct _SVGInfo |
| 123 | { |
| 124 | FILE |
| 125 | *file; |
| 126 | |
| 127 | ExceptionInfo |
| 128 | *exception; |
| 129 | |
| 130 | Image |
| 131 | *image; |
| 132 | |
| 133 | const ImageInfo |
| 134 | *image_info; |
| 135 | |
| 136 | AffineMatrix |
| 137 | affine; |
| 138 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 139 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | width, |
| 141 | height; |
| 142 | |
| 143 | char |
| 144 | *size, |
| 145 | *title, |
| 146 | *comment; |
| 147 | |
| 148 | int |
| 149 | n; |
| 150 | |
| 151 | double |
| 152 | *scale, |
| 153 | pointsize; |
| 154 | |
| 155 | ElementInfo |
| 156 | element; |
| 157 | |
| 158 | SegmentInfo |
| 159 | segment; |
| 160 | |
| 161 | BoundingBox |
| 162 | bounds, |
| 163 | center, |
| 164 | view_box; |
| 165 | |
| 166 | PointInfo |
| 167 | radius; |
| 168 | |
| 169 | char |
| 170 | *stop_color, |
| 171 | *offset, |
| 172 | *text, |
| 173 | *vertices, |
| 174 | *url; |
| 175 | |
| 176 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 177 | xmlParserCtxtPtr |
| 178 | parser; |
| 179 | |
| 180 | xmlDocPtr |
| 181 | document; |
| 182 | #endif |
| 183 | } SVGInfo; |
| 184 | |
| 185 | /* |
| 186 | Forward declarations. |
| 187 | */ |
| 188 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 189 | WriteSVGImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 193 | % % |
| 194 | % % |
| 195 | % % |
| 196 | % I s S V G % |
| 197 | % % |
| 198 | % % |
| 199 | % % |
| 200 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 201 | % |
| 202 | % IsSVG()() returns MagickTrue if the image format type, identified by the |
| 203 | % magick string, is SVG. |
| 204 | % |
| 205 | % The format of the IsSVG method is: |
| 206 | % |
| 207 | % MagickBooleanType IsSVG(const unsigned char *magick,const size_t length) |
| 208 | % |
| 209 | % A description of each parameter follows: |
| 210 | % |
| 211 | % o magick: compare image format pattern against these bytes. |
| 212 | % |
| 213 | % o length: Specifies the length of the magick string. |
| 214 | % |
| 215 | */ |
| 216 | static MagickBooleanType IsSVG(const unsigned char *magick,const size_t length) |
| 217 | { |
| 218 | if (length < 4) |
| 219 | return(MagickFalse); |
| 220 | if (LocaleNCompare((const char *) magick,"?xml",4) == 0) |
| 221 | return(MagickTrue); |
| 222 | return(MagickFalse); |
| 223 | } |
| 224 | |
| 225 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 226 | /* |
| 227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 228 | % % |
| 229 | % % |
| 230 | % % |
| 231 | % R e a d S V G I m a g e % |
| 232 | % % |
| 233 | % % |
| 234 | % % |
| 235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 236 | % |
| 237 | % ReadSVGImage() reads a Scalable Vector Gaphics file and returns it. It |
| 238 | % allocates the memory necessary for the new Image structure and returns a |
| 239 | % pointer to the new image. |
| 240 | % |
| 241 | % The format of the ReadSVGImage method is: |
| 242 | % |
| 243 | % Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 244 | % |
| 245 | % A description of each parameter follows: |
| 246 | % |
| 247 | % o image_info: the image info. |
| 248 | % |
| 249 | % o exception: return any errors or warnings in this structure. |
| 250 | % |
| 251 | */ |
| 252 | |
| 253 | static SVGInfo *AcquireSVGInfo(void) |
| 254 | { |
| 255 | SVGInfo |
| 256 | *svg_info; |
| 257 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 258 | svg_info=(SVGInfo *) AcquireMagickMemory(sizeof(*svg_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 259 | if (svg_info == (SVGInfo *) NULL) |
| 260 | return((SVGInfo *) NULL); |
| 261 | (void) ResetMagickMemory(svg_info,0,sizeof(*svg_info)); |
| 262 | svg_info->text=AcquireString(""); |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 263 | svg_info->scale=(double *) AcquireMagickMemory(sizeof(*svg_info->scale)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | if (svg_info->scale == (double *) NULL) |
| 265 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 266 | GetAffineMatrix(&svg_info->affine); |
| 267 | svg_info->scale[0]=ExpandAffine(&svg_info->affine); |
| 268 | return(svg_info); |
| 269 | } |
| 270 | |
| 271 | static SVGInfo *DestroySVGInfo(SVGInfo *svg_info) |
| 272 | { |
| 273 | if (svg_info->text != (char *) NULL) |
| 274 | svg_info->text=DestroyString(svg_info->text); |
| 275 | if (svg_info->scale != (double *) NULL) |
| 276 | svg_info->scale=(double *) (svg_info->scale); |
| 277 | if (svg_info->title != (char *) NULL) |
| 278 | svg_info->title=DestroyString(svg_info->title); |
| 279 | if (svg_info->comment != (char *) NULL) |
| 280 | svg_info->comment=DestroyString(svg_info->comment); |
| 281 | return((SVGInfo *) RelinquishMagickMemory(svg_info)); |
| 282 | } |
| 283 | |
| 284 | static double GetUserSpaceCoordinateValue(const SVGInfo *svg_info,int type, |
| 285 | const char *string) |
| 286 | { |
| 287 | char |
| 288 | token[MaxTextExtent]; |
| 289 | |
| 290 | const char |
| 291 | *p; |
| 292 | |
| 293 | double |
| 294 | value; |
| 295 | |
| 296 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",string); |
| 297 | assert(string != (const char *) NULL); |
| 298 | p=(const char *) string; |
| 299 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 300 | value=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 301 | if (strchr(token,'%') != (char *) NULL) |
| 302 | { |
| 303 | double |
| 304 | alpha, |
| 305 | beta; |
| 306 | |
| 307 | if (type > 0) |
| 308 | { |
| 309 | if (svg_info->view_box.width == 0.0) |
| 310 | return(1000.0); |
| 311 | return(svg_info->view_box.width*value/100.0); |
| 312 | } |
| 313 | if (type < 0) |
| 314 | { |
| 315 | if (svg_info->view_box.height == 0.0) |
| 316 | return(1000.0); |
| 317 | return(svg_info->view_box.height*value/100.0); |
| 318 | } |
| 319 | alpha=value-svg_info->view_box.width; |
| 320 | beta=value-svg_info->view_box.height; |
| 321 | return(hypot(alpha,beta)/sqrt(2.0)/100.0); |
| 322 | } |
| 323 | GetMagickToken(p,&p,token); |
| 324 | if (LocaleNCompare(token,"cm",2) == 0) |
| 325 | return(DefaultResolution*svg_info->scale[0]/2.54*value); |
| 326 | if (LocaleNCompare(token,"em",2) == 0) |
| 327 | return(svg_info->pointsize*value); |
| 328 | if (LocaleNCompare(token,"ex",2) == 0) |
| 329 | return(svg_info->pointsize*value/2.0); |
| 330 | if (LocaleNCompare(token,"in",2) == 0) |
| 331 | return(DefaultResolution*svg_info->scale[0]*value); |
| 332 | if (LocaleNCompare(token,"mm",2) == 0) |
| 333 | return(DefaultResolution*svg_info->scale[0]/25.4*value); |
| 334 | if (LocaleNCompare(token,"pc",2) == 0) |
| 335 | return(DefaultResolution*svg_info->scale[0]/6.0*value); |
| 336 | if (LocaleNCompare(token,"pt",2) == 0) |
| 337 | return(svg_info->scale[0]*value); |
| 338 | if (LocaleNCompare(token,"px",2) == 0) |
| 339 | return(value); |
| 340 | return(value); |
| 341 | } |
| 342 | |
| 343 | static void StripStyleTokens(char *message) |
| 344 | { |
| 345 | register char |
| 346 | *p, |
| 347 | *q; |
| 348 | |
| 349 | size_t |
| 350 | length; |
| 351 | |
| 352 | assert(message != (char *) NULL); |
| 353 | if (*message == '\0') |
| 354 | return; |
| 355 | length=strlen(message); |
| 356 | p=message; |
| 357 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 358 | p++; |
| 359 | q=message+length-1; |
| 360 | while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p)) |
| 361 | q--; |
| 362 | (void) CopyMagickMemory(message,p,(size_t) (q-p+1)); |
| 363 | message[q-p+1]='\0'; |
| 364 | StripString(message); |
| 365 | } |
| 366 | |
| 367 | static char **GetStyleTokens(void *context,const char *style,int *number_tokens) |
| 368 | { |
| 369 | char |
| 370 | *text, |
| 371 | **tokens; |
| 372 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 373 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | i; |
| 375 | |
| 376 | SVGInfo |
| 377 | *svg_info; |
| 378 | |
| 379 | svg_info=(SVGInfo *) context; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 380 | (void) svg_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 381 | *number_tokens=0; |
| 382 | if (style == (const char *) NULL) |
| 383 | return((char **) NULL); |
| 384 | text=AcquireString(style); |
| 385 | (void) SubstituteString(&text,":","\n"); |
| 386 | (void) SubstituteString(&text,";","\n"); |
| 387 | tokens=StringToList(text); |
| 388 | text=DestroyString(text); |
| 389 | for (i=0; tokens[i] != (char *) NULL; i++) |
| 390 | StripStyleTokens(tokens[i]); |
| 391 | *number_tokens=i; |
| 392 | return(tokens); |
| 393 | } |
| 394 | |
| 395 | static char **GetTransformTokens(void *context,const char *text, |
| 396 | int *number_tokens) |
| 397 | { |
| 398 | char |
| 399 | **tokens; |
| 400 | |
| 401 | register const char |
| 402 | *p, |
| 403 | *q; |
| 404 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 405 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 406 | i; |
| 407 | |
| 408 | SVGInfo |
| 409 | *svg_info; |
| 410 | |
| 411 | svg_info=(SVGInfo *) context; |
| 412 | *number_tokens=0; |
| 413 | if (text == (const char *) NULL) |
| 414 | return((char **) NULL); |
| 415 | /* |
| 416 | Determine the number of arguments. |
| 417 | */ |
| 418 | for (p=text; *p != '\0'; p++) |
| 419 | { |
| 420 | if (*p == '(') |
| 421 | (*number_tokens)+=2; |
| 422 | } |
| 423 | tokens=(char **) AcquireQuantumMemory(*number_tokens+2UL,sizeof(*tokens)); |
| 424 | if (tokens == (char **) NULL) |
| 425 | { |
| 426 | (void) ThrowMagickException(svg_info->exception,GetMagickModule(), |
| 427 | ResourceLimitError,"MemoryAllocationFailed","`%s'",text); |
| 428 | return((char **) NULL); |
| 429 | } |
| 430 | /* |
| 431 | Convert string to an ASCII list. |
| 432 | */ |
| 433 | i=0; |
| 434 | p=text; |
| 435 | for (q=p; *q != '\0'; q++) |
| 436 | { |
| 437 | if ((*q != '(') && (*q != ')') && (*q != '\0')) |
| 438 | continue; |
| 439 | tokens[i]=AcquireString(p); |
| 440 | (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1)); |
| 441 | StripString(tokens[i++]); |
| 442 | p=q+1; |
| 443 | } |
| 444 | tokens[i]=AcquireString(p); |
| 445 | (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1)); |
| 446 | StripString(tokens[i++]); |
| 447 | tokens[i]=(char *) NULL; |
| 448 | return(tokens); |
| 449 | } |
| 450 | |
| 451 | #if defined(__cplusplus) || defined(c_plusplus) |
| 452 | extern "C" { |
| 453 | #endif |
| 454 | |
| 455 | static int SVGIsStandalone(void *context) |
| 456 | { |
| 457 | SVGInfo |
| 458 | *svg_info; |
| 459 | |
| 460 | /* |
| 461 | Is this document tagged standalone? |
| 462 | */ |
| 463 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.SVGIsStandalone()"); |
| 464 | svg_info=(SVGInfo *) context; |
| 465 | return(svg_info->document->standalone == 1); |
| 466 | } |
| 467 | |
| 468 | static int SVGHasInternalSubset(void *context) |
| 469 | { |
| 470 | SVGInfo |
| 471 | *svg_info; |
| 472 | |
| 473 | /* |
| 474 | Does this document has an internal subset? |
| 475 | */ |
| 476 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 477 | " SAX.SVGHasInternalSubset()"); |
| 478 | svg_info=(SVGInfo *) context; |
| 479 | return(svg_info->document->intSubset != NULL); |
| 480 | } |
| 481 | |
| 482 | static int SVGHasExternalSubset(void *context) |
| 483 | { |
| 484 | SVGInfo |
| 485 | *svg_info; |
| 486 | |
| 487 | /* |
| 488 | Does this document has an external subset? |
| 489 | */ |
| 490 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 491 | " SAX.SVGHasExternalSubset()"); |
| 492 | svg_info=(SVGInfo *) context; |
| 493 | return(svg_info->document->extSubset != NULL); |
| 494 | } |
| 495 | |
| 496 | static void SVGInternalSubset(void *context,const xmlChar *name, |
| 497 | const xmlChar *external_id,const xmlChar *system_id) |
| 498 | { |
| 499 | SVGInfo |
| 500 | *svg_info; |
| 501 | |
| 502 | /* |
| 503 | Does this document has an internal subset? |
| 504 | */ |
| 505 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 506 | " SAX.internalSubset(%s, %s, %s)",(const char *) name, |
| 507 | (external_id != (const xmlChar *) NULL ? (const char *) external_id : "none"), |
| 508 | (system_id != (const xmlChar *) NULL ? (const char *) system_id : "none")); |
| 509 | svg_info=(SVGInfo *) context; |
| 510 | (void) xmlCreateIntSubset(svg_info->document,name,external_id,system_id); |
| 511 | } |
| 512 | |
| 513 | static xmlParserInputPtr SVGResolveEntity(void *context, |
| 514 | const xmlChar *public_id,const xmlChar *system_id) |
| 515 | { |
| 516 | SVGInfo |
| 517 | *svg_info; |
| 518 | |
| 519 | xmlParserInputPtr |
| 520 | stream; |
| 521 | |
| 522 | /* |
| 523 | Special entity resolver, better left to the parser, it has more |
| 524 | context than the application layer. The default behaviour is to |
| 525 | not resolve the entities, in that case the ENTITY_REF nodes are |
| 526 | built in the structure (and the parameter values). |
| 527 | */ |
| 528 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 529 | " SAX.resolveEntity(%s, %s)", |
| 530 | (public_id != (const xmlChar *) NULL ? (const char *) public_id : "none"), |
| 531 | (system_id != (const xmlChar *) NULL ? (const char *) system_id : "none")); |
| 532 | svg_info=(SVGInfo *) context; |
| 533 | stream=xmlLoadExternalEntity((const char *) system_id,(const char *) |
| 534 | public_id,svg_info->parser); |
| 535 | return(stream); |
| 536 | } |
| 537 | |
| 538 | static xmlEntityPtr SVGGetEntity(void *context,const xmlChar *name) |
| 539 | { |
| 540 | SVGInfo |
| 541 | *svg_info; |
| 542 | |
| 543 | /* |
| 544 | Get an entity by name. |
| 545 | */ |
| 546 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.SVGGetEntity(%s)", |
| 547 | name); |
| 548 | svg_info=(SVGInfo *) context; |
| 549 | return(xmlGetDocEntity(svg_info->document,name)); |
| 550 | } |
| 551 | |
| 552 | static xmlEntityPtr SVGGetParameterEntity(void *context,const xmlChar *name) |
| 553 | { |
| 554 | SVGInfo |
| 555 | *svg_info; |
| 556 | |
| 557 | /* |
| 558 | Get a parameter entity by name. |
| 559 | */ |
| 560 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 561 | " SAX.getParameterEntity(%s)",name); |
| 562 | svg_info=(SVGInfo *) context; |
| 563 | return(xmlGetParameterEntity(svg_info->document,name)); |
| 564 | } |
| 565 | |
| 566 | static void SVGEntityDeclaration(void *context,const xmlChar *name,int type, |
| 567 | const xmlChar *public_id,const xmlChar *system_id,xmlChar *content) |
| 568 | { |
| 569 | SVGInfo |
| 570 | *svg_info; |
| 571 | |
| 572 | /* |
| 573 | An entity definition has been parsed. |
| 574 | */ |
| 575 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 576 | " SAX.entityDecl(%s, %d, %s, %s, %s)",name,type, |
| 577 | public_id != (xmlChar *) NULL ? (const char *) public_id : "none", |
| 578 | system_id != (xmlChar *) NULL ? (const char *) system_id : "none",content); |
| 579 | svg_info=(SVGInfo *) context; |
| 580 | if (svg_info->parser->inSubset == 1) |
| 581 | (void) xmlAddDocEntity(svg_info->document,name,type,public_id,system_id, |
| 582 | content); |
| 583 | else |
| 584 | if (svg_info->parser->inSubset == 2) |
| 585 | (void) xmlAddDtdEntity(svg_info->document,name,type,public_id,system_id, |
| 586 | content); |
| 587 | } |
| 588 | |
| 589 | static void SVGAttributeDeclaration(void *context,const xmlChar *element, |
| 590 | const xmlChar *name,int type,int value,const xmlChar *default_value, |
| 591 | xmlEnumerationPtr tree) |
| 592 | { |
| 593 | SVGInfo |
| 594 | *svg_info; |
| 595 | |
| 596 | xmlChar |
| 597 | *fullname, |
| 598 | *prefix; |
| 599 | |
| 600 | xmlParserCtxtPtr |
| 601 | parser; |
| 602 | |
| 603 | /* |
| 604 | An attribute definition has been parsed. |
| 605 | */ |
| 606 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 607 | " SAX.attributeDecl(%s, %s, %d, %d, %s, ...)",element,name,type,value, |
| 608 | default_value); |
| 609 | svg_info=(SVGInfo *) context; |
| 610 | fullname=(xmlChar *) NULL; |
| 611 | prefix=(xmlChar *) NULL; |
| 612 | parser=svg_info->parser; |
| 613 | fullname=(xmlChar *) xmlSplitQName(parser,name,&prefix); |
| 614 | if (parser->inSubset == 1) |
| 615 | (void) xmlAddAttributeDecl(&parser->vctxt,svg_info->document->intSubset, |
| 616 | element,fullname,prefix,(xmlAttributeType) type, |
| 617 | (xmlAttributeDefault) value,default_value,tree); |
| 618 | else |
| 619 | if (parser->inSubset == 2) |
| 620 | (void) xmlAddAttributeDecl(&parser->vctxt,svg_info->document->extSubset, |
| 621 | element,fullname,prefix,(xmlAttributeType) type, |
| 622 | (xmlAttributeDefault) value,default_value,tree); |
| 623 | if (prefix != (xmlChar *) NULL) |
| 624 | xmlFree(prefix); |
| 625 | if (fullname != (xmlChar *) NULL) |
| 626 | xmlFree(fullname); |
| 627 | } |
| 628 | |
| 629 | static void SVGElementDeclaration(void *context,const xmlChar *name,int type, |
| 630 | xmlElementContentPtr content) |
| 631 | { |
| 632 | SVGInfo |
| 633 | *svg_info; |
| 634 | |
| 635 | xmlParserCtxtPtr |
| 636 | parser; |
| 637 | |
| 638 | /* |
| 639 | An element definition has been parsed. |
| 640 | */ |
| 641 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 642 | " SAX.elementDecl(%s, %d, ...)",name,type); |
| 643 | svg_info=(SVGInfo *) context; |
| 644 | parser=svg_info->parser; |
| 645 | if (parser->inSubset == 1) |
| 646 | (void) xmlAddElementDecl(&parser->vctxt,svg_info->document->intSubset, |
| 647 | name,(xmlElementTypeVal) type,content); |
| 648 | else |
| 649 | if (parser->inSubset == 2) |
| 650 | (void) xmlAddElementDecl(&parser->vctxt,svg_info->document->extSubset, |
| 651 | name,(xmlElementTypeVal) type,content); |
| 652 | } |
| 653 | |
| 654 | static void SVGNotationDeclaration(void *context,const xmlChar *name, |
| 655 | const xmlChar *public_id,const xmlChar *system_id) |
| 656 | { |
| 657 | SVGInfo |
| 658 | *svg_info; |
| 659 | |
| 660 | xmlParserCtxtPtr |
| 661 | parser; |
| 662 | |
| 663 | /* |
| 664 | What to do when a notation declaration has been parsed. |
| 665 | */ |
| 666 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 667 | " SAX.notationDecl(%s, %s, %s)",name, |
| 668 | public_id != (const xmlChar *) NULL ? (const char *) public_id : "none", |
| 669 | system_id != (const xmlChar *) NULL ? (const char *) system_id : "none"); |
| 670 | svg_info=(SVGInfo *) context; |
| 671 | parser=svg_info->parser; |
| 672 | if (parser->inSubset == 1) |
| 673 | (void) xmlAddNotationDecl(&parser->vctxt,svg_info->document->intSubset, |
| 674 | name,public_id,system_id); |
| 675 | else |
| 676 | if (parser->inSubset == 2) |
| 677 | (void) xmlAddNotationDecl(&parser->vctxt,svg_info->document->intSubset, |
| 678 | name,public_id,system_id); |
| 679 | } |
| 680 | |
| 681 | static void SVGUnparsedEntityDeclaration(void *context,const xmlChar *name, |
| 682 | const xmlChar *public_id,const xmlChar *system_id,const xmlChar *notation) |
| 683 | { |
| 684 | SVGInfo |
| 685 | *svg_info; |
| 686 | |
| 687 | /* |
| 688 | What to do when an unparsed entity declaration is parsed. |
| 689 | */ |
| 690 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 691 | " SAX.unparsedEntityDecl(%s, %s, %s, %s)",name, |
| 692 | public_id != (xmlChar *) NULL ? (const char *) public_id : "none", |
| 693 | system_id != (xmlChar *) NULL ? (const char *) system_id : "none",notation); |
| 694 | svg_info=(SVGInfo *) context; |
| 695 | (void) xmlAddDocEntity(svg_info->document,name, |
| 696 | XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,public_id,system_id,notation); |
| 697 | |
| 698 | } |
| 699 | |
| 700 | static void SVGSetDocumentLocator(void *context,xmlSAXLocatorPtr location) |
| 701 | { |
| 702 | SVGInfo |
| 703 | *svg_info; |
| 704 | |
| 705 | /* |
| 706 | Receive the document locator at startup, actually xmlDefaultSAXLocator. |
| 707 | */ |
| 708 | (void) location; |
| 709 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 710 | " SAX.setDocumentLocator()"); |
| 711 | svg_info=(SVGInfo *) context; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 712 | (void) svg_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static void SVGStartDocument(void *context) |
| 716 | { |
| 717 | SVGInfo |
| 718 | *svg_info; |
| 719 | |
| 720 | xmlParserCtxtPtr |
| 721 | parser; |
| 722 | |
| 723 | /* |
| 724 | Called when the document start being processed. |
| 725 | */ |
| 726 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.startDocument()"); |
| 727 | svg_info=(SVGInfo *) context; |
| 728 | GetExceptionInfo(svg_info->exception); |
| 729 | parser=svg_info->parser; |
| 730 | svg_info->document=xmlNewDoc(parser->version); |
| 731 | if (svg_info->document == (xmlDocPtr) NULL) |
| 732 | return; |
| 733 | if (parser->encoding == NULL) |
| 734 | svg_info->document->encoding=(const xmlChar *) NULL; |
| 735 | else |
| 736 | svg_info->document->encoding=xmlStrdup(parser->encoding); |
| 737 | svg_info->document->standalone=parser->standalone; |
| 738 | } |
| 739 | |
| 740 | static void SVGEndDocument(void *context) |
| 741 | { |
| 742 | SVGInfo |
| 743 | *svg_info; |
| 744 | |
| 745 | /* |
| 746 | Called when the document end has been detected. |
| 747 | */ |
| 748 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.endDocument()"); |
| 749 | svg_info=(SVGInfo *) context; |
| 750 | if (svg_info->offset != (char *) NULL) |
| 751 | svg_info->offset=DestroyString(svg_info->offset); |
| 752 | if (svg_info->stop_color != (char *) NULL) |
| 753 | svg_info->stop_color=DestroyString(svg_info->stop_color); |
| 754 | if (svg_info->scale != (double *) NULL) |
| 755 | svg_info->scale=(double *) RelinquishMagickMemory(svg_info->scale); |
| 756 | if (svg_info->text != (char *) NULL) |
| 757 | svg_info->text=DestroyString(svg_info->text); |
| 758 | if (svg_info->vertices != (char *) NULL) |
| 759 | svg_info->vertices=DestroyString(svg_info->vertices); |
| 760 | if (svg_info->url != (char *) NULL) |
| 761 | svg_info->url=DestroyString(svg_info->url); |
| 762 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 763 | if (svg_info->document != (xmlDocPtr) NULL) |
| 764 | { |
| 765 | xmlFreeDoc(svg_info->document); |
| 766 | svg_info->document=(xmlDocPtr) NULL; |
| 767 | } |
| 768 | #endif |
| 769 | } |
| 770 | |
| 771 | static void SVGStartElement(void *context,const xmlChar *name, |
| 772 | const xmlChar **attributes) |
| 773 | { |
| 774 | char |
| 775 | *color, |
| 776 | id[MaxTextExtent], |
| 777 | token[MaxTextExtent], |
| 778 | **tokens, |
| 779 | *units; |
| 780 | |
| 781 | const char |
| 782 | *keyword, |
| 783 | *p, |
| 784 | *value; |
| 785 | |
| 786 | int |
| 787 | number_tokens; |
| 788 | |
| 789 | SVGInfo |
| 790 | *svg_info; |
| 791 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 792 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 793 | i, |
| 794 | j; |
| 795 | |
| 796 | /* |
| 797 | Called when an opening tag has been processed. |
| 798 | */ |
| 799 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.startElement(%s", |
| 800 | name); |
| 801 | svg_info=(SVGInfo *) context; |
| 802 | svg_info->n++; |
| 803 | svg_info->scale=(double *) ResizeQuantumMemory(svg_info->scale, |
| 804 | svg_info->n+1UL,sizeof(*svg_info->scale)); |
| 805 | if (svg_info->scale == (double *) NULL) |
| 806 | { |
| 807 | (void) ThrowMagickException(svg_info->exception,GetMagickModule(), |
| 808 | ResourceLimitError,"MemoryAllocationFailed","`%s'",name); |
| 809 | return; |
| 810 | } |
| 811 | svg_info->scale[svg_info->n]=svg_info->scale[svg_info->n-1]; |
| 812 | color=AcquireString("none"); |
| 813 | units=AcquireString("userSpaceOnUse"); |
| 814 | value=(const char *) NULL; |
| 815 | if (attributes != (const xmlChar **) NULL) |
| 816 | for (i=0; (attributes[i] != (const xmlChar *) NULL); i+=2) |
| 817 | { |
| 818 | keyword=(const char *) attributes[i]; |
| 819 | value=(const char *) attributes[i+1]; |
| 820 | switch (*keyword) |
| 821 | { |
| 822 | case 'C': |
| 823 | case 'c': |
| 824 | { |
| 825 | if (LocaleCompare(keyword,"cx") == 0) |
| 826 | { |
| 827 | svg_info->element.cx= |
| 828 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 829 | break; |
| 830 | } |
| 831 | if (LocaleCompare(keyword,"cy") == 0) |
| 832 | { |
| 833 | svg_info->element.cy= |
| 834 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 835 | break; |
| 836 | } |
| 837 | break; |
| 838 | } |
| 839 | case 'F': |
| 840 | case 'f': |
| 841 | { |
| 842 | if (LocaleCompare(keyword,"fx") == 0) |
| 843 | { |
| 844 | svg_info->element.major= |
| 845 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 846 | break; |
| 847 | } |
| 848 | if (LocaleCompare(keyword,"fy") == 0) |
| 849 | { |
| 850 | svg_info->element.minor= |
| 851 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 852 | break; |
| 853 | } |
| 854 | break; |
| 855 | } |
| 856 | case 'H': |
| 857 | case 'h': |
| 858 | { |
| 859 | if (LocaleCompare(keyword,"height") == 0) |
| 860 | { |
| 861 | svg_info->bounds.height= |
| 862 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 863 | break; |
| 864 | } |
| 865 | break; |
| 866 | } |
| 867 | case 'I': |
| 868 | case 'i': |
| 869 | { |
| 870 | if (LocaleCompare(keyword,"id") == 0) |
| 871 | { |
| 872 | (void) CopyMagickString(id,value,MaxTextExtent); |
| 873 | break; |
| 874 | } |
| 875 | break; |
| 876 | } |
| 877 | case 'R': |
| 878 | case 'r': |
| 879 | { |
| 880 | if (LocaleCompare(keyword,"r") == 0) |
| 881 | { |
| 882 | svg_info->element.angle= |
| 883 | GetUserSpaceCoordinateValue(svg_info,0,value); |
| 884 | break; |
| 885 | } |
| 886 | break; |
| 887 | } |
| 888 | case 'W': |
| 889 | case 'w': |
| 890 | { |
| 891 | if (LocaleCompare(keyword,"width") == 0) |
| 892 | { |
| 893 | svg_info->bounds.width= |
| 894 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 895 | break; |
| 896 | } |
| 897 | break; |
| 898 | } |
| 899 | case 'X': |
| 900 | case 'x': |
| 901 | { |
| 902 | if (LocaleCompare(keyword,"x") == 0) |
| 903 | { |
| 904 | svg_info->bounds.x=GetUserSpaceCoordinateValue(svg_info,1,value)- |
| 905 | svg_info->center.x; |
| 906 | break; |
| 907 | } |
| 908 | if (LocaleCompare(keyword,"x1") == 0) |
| 909 | { |
| 910 | svg_info->segment.x1=GetUserSpaceCoordinateValue(svg_info,1, |
| 911 | value); |
| 912 | break; |
| 913 | } |
| 914 | if (LocaleCompare(keyword,"x2") == 0) |
| 915 | { |
| 916 | svg_info->segment.x2=GetUserSpaceCoordinateValue(svg_info,1, |
| 917 | value); |
| 918 | break; |
| 919 | } |
| 920 | break; |
| 921 | } |
| 922 | case 'Y': |
| 923 | case 'y': |
| 924 | { |
| 925 | if (LocaleCompare(keyword,"y") == 0) |
| 926 | { |
| 927 | svg_info->bounds.y=GetUserSpaceCoordinateValue(svg_info,-1,value)- |
| 928 | svg_info->center.y; |
| 929 | break; |
| 930 | } |
| 931 | if (LocaleCompare(keyword,"y1") == 0) |
| 932 | { |
| 933 | svg_info->segment.y1= |
| 934 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 935 | break; |
| 936 | } |
| 937 | if (LocaleCompare(keyword,"y2") == 0) |
| 938 | { |
| 939 | svg_info->segment.y2= |
| 940 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 941 | break; |
| 942 | } |
| 943 | break; |
| 944 | } |
| 945 | default: |
| 946 | break; |
| 947 | } |
| 948 | } |
cristy | 13d0704 | 2010-11-21 20:56:18 +0000 | [diff] [blame] | 949 | if (strchr((char *) name,':') != (char *) NULL) |
cristy | 768b930 | 2010-11-20 00:05:47 +0000 | [diff] [blame] | 950 | { |
| 951 | /* |
| 952 | Skip over namespace. |
| 953 | */ |
| 954 | for ( ; *name != ':'; name++) ; |
| 955 | name++; |
| 956 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 957 | switch (*name) |
| 958 | { |
| 959 | case 'C': |
| 960 | case 'c': |
| 961 | { |
| 962 | if (LocaleCompare((const char *) name,"circle") == 0) |
| 963 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 964 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 965 | break; |
| 966 | } |
| 967 | if (LocaleCompare((const char *) name,"clipPath") == 0) |
| 968 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 969 | (void) FormatLocaleFile(svg_info->file,"push clip-path '%s'\n",id); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 970 | break; |
| 971 | } |
| 972 | break; |
| 973 | } |
| 974 | case 'D': |
| 975 | case 'd': |
| 976 | { |
| 977 | if (LocaleCompare((const char *) name,"defs") == 0) |
| 978 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 979 | (void) FormatLocaleFile(svg_info->file,"push defs\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | break; |
| 983 | } |
| 984 | case 'E': |
| 985 | case 'e': |
| 986 | { |
| 987 | if (LocaleCompare((const char *) name,"ellipse") == 0) |
| 988 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 989 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | break; |
| 991 | } |
| 992 | break; |
| 993 | } |
| 994 | case 'G': |
| 995 | case 'g': |
| 996 | { |
| 997 | if (LocaleCompare((const char *) name,"g") == 0) |
| 998 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 999 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1000 | break; |
| 1001 | } |
| 1002 | break; |
| 1003 | } |
| 1004 | case 'I': |
| 1005 | case 'i': |
| 1006 | { |
| 1007 | if (LocaleCompare((const char *) name,"image") == 0) |
| 1008 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1009 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1010 | break; |
| 1011 | } |
| 1012 | break; |
| 1013 | } |
| 1014 | case 'L': |
| 1015 | case 'l': |
| 1016 | { |
| 1017 | if (LocaleCompare((const char *) name,"line") == 0) |
| 1018 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1019 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | } |
| 1022 | if (LocaleCompare((const char *) name,"linearGradient") == 0) |
| 1023 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1024 | (void) FormatLocaleFile(svg_info->file, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1025 | "push gradient '%s' linear %g,%g %g,%g\n",id, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1026 | svg_info->segment.x1,svg_info->segment.y1,svg_info->segment.x2, |
| 1027 | svg_info->segment.y2); |
| 1028 | break; |
| 1029 | } |
| 1030 | break; |
| 1031 | } |
| 1032 | case 'P': |
| 1033 | case 'p': |
| 1034 | { |
| 1035 | if (LocaleCompare((const char *) name,"path") == 0) |
| 1036 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1037 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | if (LocaleCompare((const char *) name,"pattern") == 0) |
| 1041 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1042 | (void) FormatLocaleFile(svg_info->file, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1043 | "push pattern '%s' %g,%g %g,%g\n",id, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1044 | svg_info->bounds.x,svg_info->bounds.y,svg_info->bounds.width, |
| 1045 | svg_info->bounds.height); |
| 1046 | break; |
| 1047 | } |
| 1048 | if (LocaleCompare((const char *) name,"polygon") == 0) |
| 1049 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1050 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1051 | break; |
| 1052 | } |
| 1053 | if (LocaleCompare((const char *) name,"polyline") == 0) |
| 1054 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1055 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1056 | break; |
| 1057 | } |
| 1058 | break; |
| 1059 | } |
| 1060 | case 'R': |
| 1061 | case 'r': |
| 1062 | { |
| 1063 | if (LocaleCompare((const char *) name,"radialGradient") == 0) |
| 1064 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1065 | (void) FormatLocaleFile(svg_info->file, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1066 | "push gradient '%s' radial %g,%g %g,%g %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1067 | id,svg_info->element.cx,svg_info->element.cy, |
| 1068 | svg_info->element.major,svg_info->element.minor, |
| 1069 | svg_info->element.angle); |
| 1070 | break; |
| 1071 | } |
| 1072 | if (LocaleCompare((const char *) name,"rect") == 0) |
| 1073 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1074 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1075 | break; |
| 1076 | } |
| 1077 | break; |
| 1078 | } |
| 1079 | case 'S': |
| 1080 | case 's': |
| 1081 | { |
| 1082 | if (LocaleCompare((const char *) name,"svg") == 0) |
| 1083 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1084 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1085 | break; |
| 1086 | } |
| 1087 | break; |
| 1088 | } |
| 1089 | case 'T': |
| 1090 | case 't': |
| 1091 | { |
| 1092 | if (LocaleCompare((const char *) name,"text") == 0) |
| 1093 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1094 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1095 | break; |
| 1096 | } |
| 1097 | if (LocaleCompare((const char *) name,"tspan") == 0) |
| 1098 | { |
| 1099 | if (*svg_info->text != '\0') |
| 1100 | { |
| 1101 | DrawInfo |
| 1102 | *draw_info; |
| 1103 | |
| 1104 | TypeMetric |
| 1105 | metrics; |
| 1106 | |
| 1107 | char |
| 1108 | *text; |
| 1109 | |
| 1110 | text=EscapeString(svg_info->text,'\''); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1111 | (void) FormatLocaleFile(svg_info->file,"text %g,%g '%s'\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1112 | svg_info->bounds.x-svg_info->center.x,svg_info->bounds.y- |
| 1113 | svg_info->center.y,text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1114 | text=DestroyString(text); |
| 1115 | draw_info=CloneDrawInfo(svg_info->image_info,(DrawInfo *) NULL); |
| 1116 | draw_info->pointsize=svg_info->pointsize; |
| 1117 | draw_info->text=AcquireString(svg_info->text); |
| 1118 | (void) ConcatenateString(&draw_info->text," "); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1119 | (void) GetTypeMetrics(svg_info->image,draw_info, |
| 1120 | &metrics,svg_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1121 | svg_info->bounds.x+=metrics.width; |
| 1122 | draw_info=DestroyDrawInfo(draw_info); |
| 1123 | *svg_info->text='\0'; |
| 1124 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1125 | (void) FormatLocaleFile(svg_info->file,"push graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| 1128 | break; |
| 1129 | } |
| 1130 | default: |
| 1131 | break; |
| 1132 | } |
| 1133 | if (attributes != (const xmlChar **) NULL) |
| 1134 | for (i=0; (attributes[i] != (const xmlChar *) NULL); i+=2) |
| 1135 | { |
| 1136 | keyword=(const char *) attributes[i]; |
| 1137 | value=(const char *) attributes[i+1]; |
| 1138 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1139 | " %s = %s",keyword,value); |
| 1140 | switch (*keyword) |
| 1141 | { |
| 1142 | case 'A': |
| 1143 | case 'a': |
| 1144 | { |
| 1145 | if (LocaleCompare(keyword,"angle") == 0) |
| 1146 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1147 | (void) FormatLocaleFile(svg_info->file,"angle %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1148 | GetUserSpaceCoordinateValue(svg_info,0,value)); |
| 1149 | break; |
| 1150 | } |
| 1151 | break; |
| 1152 | } |
| 1153 | case 'C': |
| 1154 | case 'c': |
| 1155 | { |
| 1156 | if (LocaleCompare(keyword,"clip-path") == 0) |
| 1157 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1158 | (void) FormatLocaleFile(svg_info->file,"clip-path '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | if (LocaleCompare(keyword,"clip-rule") == 0) |
| 1162 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1163 | (void) FormatLocaleFile(svg_info->file,"clip-rule '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1164 | break; |
| 1165 | } |
| 1166 | if (LocaleCompare(keyword,"clipPathUnits") == 0) |
| 1167 | { |
| 1168 | (void) CloneString(&units,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1169 | (void) FormatLocaleFile(svg_info->file,"clip-units '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1170 | break; |
| 1171 | } |
| 1172 | if (LocaleCompare(keyword,"color") == 0) |
| 1173 | { |
| 1174 | (void) CloneString(&color,value); |
| 1175 | break; |
| 1176 | } |
| 1177 | if (LocaleCompare(keyword,"cx") == 0) |
| 1178 | { |
| 1179 | svg_info->element.cx= |
| 1180 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1181 | break; |
| 1182 | } |
| 1183 | if (LocaleCompare(keyword,"cy") == 0) |
| 1184 | { |
| 1185 | svg_info->element.cy= |
| 1186 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1187 | break; |
| 1188 | } |
| 1189 | break; |
| 1190 | } |
| 1191 | case 'D': |
| 1192 | case 'd': |
| 1193 | { |
| 1194 | if (LocaleCompare(keyword,"d") == 0) |
| 1195 | { |
| 1196 | (void) CloneString(&svg_info->vertices,value); |
| 1197 | break; |
| 1198 | } |
| 1199 | if (LocaleCompare(keyword,"dx") == 0) |
| 1200 | { |
| 1201 | svg_info->bounds.x+=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1202 | break; |
| 1203 | } |
| 1204 | if (LocaleCompare(keyword,"dy") == 0) |
| 1205 | { |
| 1206 | svg_info->bounds.y+= |
| 1207 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1208 | break; |
| 1209 | } |
| 1210 | break; |
| 1211 | } |
| 1212 | case 'F': |
| 1213 | case 'f': |
| 1214 | { |
| 1215 | if (LocaleCompare(keyword,"fill") == 0) |
| 1216 | { |
| 1217 | if (LocaleCompare(value,"currentColor") == 0) |
| 1218 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1219 | (void) FormatLocaleFile(svg_info->file,"fill '%s'\n",color); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | break; |
| 1221 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1222 | (void) FormatLocaleFile(svg_info->file,"fill '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1223 | break; |
| 1224 | } |
| 1225 | if (LocaleCompare(keyword,"fillcolor") == 0) |
| 1226 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1227 | (void) FormatLocaleFile(svg_info->file,"fill '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1228 | break; |
| 1229 | } |
| 1230 | if (LocaleCompare(keyword,"fill-rule") == 0) |
| 1231 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1232 | (void) FormatLocaleFile(svg_info->file,"fill-rule '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | break; |
| 1234 | } |
| 1235 | if (LocaleCompare(keyword,"fill-opacity") == 0) |
| 1236 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1237 | (void) FormatLocaleFile(svg_info->file,"fill-opacity '%s'\n", |
| 1238 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | } |
| 1241 | if (LocaleCompare(keyword,"font-family") == 0) |
| 1242 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1243 | (void) FormatLocaleFile(svg_info->file,"font-family '%s'\n", |
| 1244 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1245 | break; |
| 1246 | } |
| 1247 | if (LocaleCompare(keyword,"font-stretch") == 0) |
| 1248 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1249 | (void) FormatLocaleFile(svg_info->file,"font-stretch '%s'\n", |
| 1250 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1251 | break; |
| 1252 | } |
| 1253 | if (LocaleCompare(keyword,"font-style") == 0) |
| 1254 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1255 | (void) FormatLocaleFile(svg_info->file,"font-style '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1256 | break; |
| 1257 | } |
| 1258 | if (LocaleCompare(keyword,"font-size") == 0) |
| 1259 | { |
| 1260 | svg_info->pointsize=GetUserSpaceCoordinateValue(svg_info,0,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1261 | (void) FormatLocaleFile(svg_info->file,"font-size %g\n", |
| 1262 | svg_info->pointsize); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1263 | break; |
| 1264 | } |
| 1265 | if (LocaleCompare(keyword,"font-weight") == 0) |
| 1266 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1267 | (void) FormatLocaleFile(svg_info->file,"font-weight '%s'\n", |
| 1268 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1269 | break; |
| 1270 | } |
| 1271 | break; |
| 1272 | } |
| 1273 | case 'G': |
| 1274 | case 'g': |
| 1275 | { |
| 1276 | if (LocaleCompare(keyword,"gradientTransform") == 0) |
| 1277 | { |
| 1278 | AffineMatrix |
| 1279 | affine, |
| 1280 | current, |
| 1281 | transform; |
| 1282 | |
| 1283 | GetAffineMatrix(&transform); |
| 1284 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," "); |
| 1285 | tokens=GetTransformTokens(context,value,&number_tokens); |
| 1286 | for (j=0; j < (number_tokens-1); j+=2) |
| 1287 | { |
| 1288 | keyword=(char *) tokens[j]; |
| 1289 | if (keyword == (char *) NULL) |
| 1290 | continue; |
| 1291 | value=(char *) tokens[j+1]; |
| 1292 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1293 | " %s: %s",keyword,value); |
| 1294 | current=transform; |
| 1295 | GetAffineMatrix(&affine); |
| 1296 | switch (*keyword) |
| 1297 | { |
| 1298 | case 'M': |
| 1299 | case 'm': |
| 1300 | { |
| 1301 | if (LocaleCompare(keyword,"matrix") == 0) |
| 1302 | { |
| 1303 | p=(const char *) value; |
| 1304 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1305 | affine.sx=InterpretLocaleValue(value,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1306 | GetMagickToken(p,&p,token); |
| 1307 | if (*token == ',') |
| 1308 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1309 | affine.rx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1310 | GetMagickToken(p,&p,token); |
| 1311 | if (*token == ',') |
| 1312 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1313 | affine.ry=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1314 | GetMagickToken(p,&p,token); |
| 1315 | if (*token == ',') |
| 1316 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1317 | affine.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1318 | GetMagickToken(p,&p,token); |
| 1319 | if (*token == ',') |
| 1320 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1321 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1322 | GetMagickToken(p,&p,token); |
| 1323 | if (*token == ',') |
| 1324 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1325 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1326 | break; |
| 1327 | } |
| 1328 | break; |
| 1329 | } |
| 1330 | case 'R': |
| 1331 | case 'r': |
| 1332 | { |
| 1333 | if (LocaleCompare(keyword,"rotate") == 0) |
| 1334 | { |
| 1335 | double |
| 1336 | angle; |
| 1337 | |
| 1338 | angle=GetUserSpaceCoordinateValue(svg_info,0,value); |
| 1339 | affine.sx=cos(DegreesToRadians(fmod(angle,360.0))); |
| 1340 | affine.rx=sin(DegreesToRadians(fmod(angle,360.0))); |
| 1341 | affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0)))); |
| 1342 | affine.sy=cos(DegreesToRadians(fmod(angle,360.0))); |
| 1343 | break; |
| 1344 | } |
| 1345 | break; |
| 1346 | } |
| 1347 | case 'S': |
| 1348 | case 's': |
| 1349 | { |
| 1350 | if (LocaleCompare(keyword,"scale") == 0) |
| 1351 | { |
| 1352 | for (p=(const char *) value; *p != '\0'; p++) |
| 1353 | if ((isspace((int) ((unsigned char) *p)) != 0) || |
| 1354 | (*p == ',')) |
| 1355 | break; |
| 1356 | affine.sx=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1357 | affine.sy=affine.sx; |
| 1358 | if (*p != '\0') |
| 1359 | affine.sy= |
| 1360 | GetUserSpaceCoordinateValue(svg_info,-1,p+1); |
| 1361 | svg_info->scale[svg_info->n]=ExpandAffine(&affine); |
| 1362 | break; |
| 1363 | } |
| 1364 | if (LocaleCompare(keyword,"skewX") == 0) |
| 1365 | { |
| 1366 | affine.sx=svg_info->affine.sx; |
| 1367 | affine.ry=tan(DegreesToRadians(fmod( |
| 1368 | GetUserSpaceCoordinateValue(svg_info,1,value), |
| 1369 | 360.0))); |
| 1370 | affine.sy=svg_info->affine.sy; |
| 1371 | break; |
| 1372 | } |
| 1373 | if (LocaleCompare(keyword,"skewY") == 0) |
| 1374 | { |
| 1375 | affine.sx=svg_info->affine.sx; |
| 1376 | affine.rx=tan(DegreesToRadians(fmod( |
| 1377 | GetUserSpaceCoordinateValue(svg_info,-1,value), |
| 1378 | 360.0))); |
| 1379 | affine.sy=svg_info->affine.sy; |
| 1380 | break; |
| 1381 | } |
| 1382 | break; |
| 1383 | } |
| 1384 | case 'T': |
| 1385 | case 't': |
| 1386 | { |
| 1387 | if (LocaleCompare(keyword,"translate") == 0) |
| 1388 | { |
| 1389 | for (p=(const char *) value; *p != '\0'; p++) |
| 1390 | if ((isspace((int) ((unsigned char) *p)) != 0) || |
| 1391 | (*p == ',')) |
| 1392 | break; |
| 1393 | affine.tx=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1394 | affine.ty=affine.tx; |
| 1395 | if (*p != '\0') |
| 1396 | affine.ty= |
| 1397 | GetUserSpaceCoordinateValue(svg_info,-1,p+1); |
| 1398 | break; |
| 1399 | } |
| 1400 | break; |
| 1401 | } |
| 1402 | default: |
| 1403 | break; |
| 1404 | } |
cristy | ef7c8a5 | 2010-10-10 13:46:51 +0000 | [diff] [blame] | 1405 | transform.sx=affine.sx*current.sx+affine.ry*current.rx; |
| 1406 | transform.rx=affine.rx*current.sx+affine.sy*current.rx; |
| 1407 | transform.ry=affine.sx*current.ry+affine.ry*current.sy; |
| 1408 | transform.sy=affine.rx*current.ry+affine.sy*current.sy; |
| 1409 | transform.tx=affine.sx*current.tx+affine.ry*current.ty+ |
| 1410 | affine.tx; |
| 1411 | transform.ty=affine.rx*current.tx+affine.sy*current.ty+ |
| 1412 | affine.ty; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1413 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1414 | (void) FormatLocaleFile(svg_info->file, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1415 | "affine %g %g %g %g %g %g\n",transform.sx, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1416 | transform.rx,transform.ry,transform.sy,transform.tx, |
| 1417 | transform.ty); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1418 | for (j=0; tokens[j] != (char *) NULL; j++) |
| 1419 | tokens[j]=DestroyString(tokens[j]); |
| 1420 | tokens=(char **) RelinquishMagickMemory(tokens); |
| 1421 | break; |
| 1422 | } |
| 1423 | if (LocaleCompare(keyword,"gradientUnits") == 0) |
| 1424 | { |
| 1425 | (void) CloneString(&units,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1426 | (void) FormatLocaleFile(svg_info->file,"gradient-units '%s'\n", |
| 1427 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | } |
| 1430 | break; |
| 1431 | } |
| 1432 | case 'H': |
| 1433 | case 'h': |
| 1434 | { |
| 1435 | if (LocaleCompare(keyword,"height") == 0) |
| 1436 | { |
| 1437 | svg_info->bounds.height= |
| 1438 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1439 | break; |
| 1440 | } |
| 1441 | if (LocaleCompare(keyword,"href") == 0) |
| 1442 | { |
| 1443 | (void) CloneString(&svg_info->url,value); |
| 1444 | break; |
| 1445 | } |
| 1446 | break; |
| 1447 | } |
| 1448 | case 'M': |
| 1449 | case 'm': |
| 1450 | { |
| 1451 | if (LocaleCompare(keyword,"major") == 0) |
| 1452 | { |
| 1453 | svg_info->element.major= |
| 1454 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1455 | break; |
| 1456 | } |
| 1457 | if (LocaleCompare(keyword,"minor") == 0) |
| 1458 | { |
| 1459 | svg_info->element.minor= |
| 1460 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1461 | break; |
| 1462 | } |
| 1463 | break; |
| 1464 | } |
| 1465 | case 'O': |
| 1466 | case 'o': |
| 1467 | { |
| 1468 | if (LocaleCompare(keyword,"offset") == 0) |
| 1469 | { |
| 1470 | (void) CloneString(&svg_info->offset,value); |
| 1471 | break; |
| 1472 | } |
| 1473 | if (LocaleCompare(keyword,"opacity") == 0) |
| 1474 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1475 | (void) FormatLocaleFile(svg_info->file,"opacity '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1476 | break; |
| 1477 | } |
| 1478 | break; |
| 1479 | } |
| 1480 | case 'P': |
| 1481 | case 'p': |
| 1482 | { |
| 1483 | if (LocaleCompare(keyword,"path") == 0) |
| 1484 | { |
| 1485 | (void) CloneString(&svg_info->url,value); |
| 1486 | break; |
| 1487 | } |
| 1488 | if (LocaleCompare(keyword,"points") == 0) |
| 1489 | { |
| 1490 | (void) CloneString(&svg_info->vertices,value); |
| 1491 | break; |
| 1492 | } |
| 1493 | break; |
| 1494 | } |
| 1495 | case 'R': |
| 1496 | case 'r': |
| 1497 | { |
| 1498 | if (LocaleCompare(keyword,"r") == 0) |
| 1499 | { |
| 1500 | svg_info->element.major= |
| 1501 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1502 | svg_info->element.minor= |
| 1503 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1504 | break; |
| 1505 | } |
| 1506 | if (LocaleCompare(keyword,"rotate") == 0) |
| 1507 | { |
| 1508 | double |
| 1509 | angle; |
| 1510 | |
| 1511 | angle=GetUserSpaceCoordinateValue(svg_info,0,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1512 | (void) FormatLocaleFile(svg_info->file,"translate %g,%g\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1513 | svg_info->bounds.x,svg_info->bounds.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1514 | svg_info->bounds.x=0; |
| 1515 | svg_info->bounds.y=0; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1516 | (void) FormatLocaleFile(svg_info->file,"rotate %g\n",angle); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | } |
| 1519 | if (LocaleCompare(keyword,"rx") == 0) |
| 1520 | { |
| 1521 | if (LocaleCompare((const char *) name,"ellipse") == 0) |
| 1522 | svg_info->element.major= |
| 1523 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1524 | else |
| 1525 | svg_info->radius.x= |
| 1526 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1527 | break; |
| 1528 | } |
| 1529 | if (LocaleCompare(keyword,"ry") == 0) |
| 1530 | { |
| 1531 | if (LocaleCompare((const char *) name,"ellipse") == 0) |
| 1532 | svg_info->element.minor= |
| 1533 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1534 | else |
| 1535 | svg_info->radius.y= |
| 1536 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 1537 | break; |
| 1538 | } |
| 1539 | break; |
| 1540 | } |
| 1541 | case 'S': |
| 1542 | case 's': |
| 1543 | { |
| 1544 | if (LocaleCompare(keyword,"stop-color") == 0) |
| 1545 | { |
| 1546 | (void) CloneString(&svg_info->stop_color,value); |
| 1547 | break; |
| 1548 | } |
| 1549 | if (LocaleCompare(keyword,"stroke") == 0) |
| 1550 | { |
| 1551 | if (LocaleCompare(value,"currentColor") == 0) |
| 1552 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1553 | (void) FormatLocaleFile(svg_info->file,"stroke '%s'\n",color); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1554 | break; |
| 1555 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1556 | (void) FormatLocaleFile(svg_info->file,"stroke '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1557 | break; |
| 1558 | } |
| 1559 | if (LocaleCompare(keyword,"stroke-antialiasing") == 0) |
| 1560 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1561 | (void) FormatLocaleFile(svg_info->file,"stroke-antialias %d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1562 | LocaleCompare(value,"true") == 0); |
| 1563 | break; |
| 1564 | } |
| 1565 | if (LocaleCompare(keyword,"stroke-dasharray") == 0) |
| 1566 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1567 | (void) FormatLocaleFile(svg_info->file,"stroke-dasharray %s\n", |
| 1568 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1569 | break; |
| 1570 | } |
| 1571 | if (LocaleCompare(keyword,"stroke-dashoffset") == 0) |
| 1572 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1573 | (void) FormatLocaleFile(svg_info->file,"stroke-dashoffset %s\n", |
| 1574 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1575 | break; |
| 1576 | } |
| 1577 | if (LocaleCompare(keyword,"stroke-linecap") == 0) |
| 1578 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1579 | (void) FormatLocaleFile(svg_info->file,"stroke-linecap '%s'\n", |
| 1580 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | if (LocaleCompare(keyword,"stroke-linejoin") == 0) |
| 1584 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1585 | (void) FormatLocaleFile(svg_info->file,"stroke-linejoin '%s'\n", |
| 1586 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | } |
| 1589 | if (LocaleCompare(keyword,"stroke-miterlimit") == 0) |
| 1590 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1591 | (void) FormatLocaleFile(svg_info->file,"stroke-miterlimit '%s'\n", |
| 1592 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1593 | break; |
| 1594 | } |
| 1595 | if (LocaleCompare(keyword,"stroke-opacity") == 0) |
| 1596 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1597 | (void) FormatLocaleFile(svg_info->file,"stroke-opacity '%s'\n", |
| 1598 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1599 | break; |
| 1600 | } |
| 1601 | if (LocaleCompare(keyword,"stroke-width") == 0) |
| 1602 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1603 | (void) FormatLocaleFile(svg_info->file,"stroke-width %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1604 | GetUserSpaceCoordinateValue(svg_info,1,value)); |
| 1605 | break; |
| 1606 | } |
| 1607 | if (LocaleCompare(keyword,"style") == 0) |
| 1608 | { |
| 1609 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," "); |
| 1610 | tokens=GetStyleTokens(context,value,&number_tokens); |
| 1611 | for (j=0; j < (number_tokens-1); j+=2) |
| 1612 | { |
| 1613 | keyword=(char *) tokens[j]; |
| 1614 | value=(char *) tokens[j+1]; |
| 1615 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1616 | " %s: %s",keyword,value); |
| 1617 | switch (*keyword) |
| 1618 | { |
| 1619 | case 'C': |
| 1620 | case 'c': |
| 1621 | { |
| 1622 | if (LocaleCompare(keyword,"clip-path") == 0) |
| 1623 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1624 | (void) FormatLocaleFile(svg_info->file, |
| 1625 | "clip-path '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1626 | break; |
| 1627 | } |
| 1628 | if (LocaleCompare(keyword,"clip-rule") == 0) |
| 1629 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1630 | (void) FormatLocaleFile(svg_info->file, |
| 1631 | "clip-rule '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | } |
| 1634 | if (LocaleCompare(keyword,"clipPathUnits") == 0) |
| 1635 | { |
| 1636 | (void) CloneString(&units,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1637 | (void) FormatLocaleFile(svg_info->file, |
| 1638 | "clip-units '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1639 | break; |
| 1640 | } |
| 1641 | if (LocaleCompare(keyword,"color") == 0) |
| 1642 | { |
| 1643 | (void) CloneString(&color,value); |
| 1644 | break; |
| 1645 | } |
| 1646 | break; |
| 1647 | } |
| 1648 | case 'F': |
| 1649 | case 'f': |
| 1650 | { |
| 1651 | if (LocaleCompare(keyword,"fill") == 0) |
| 1652 | { |
| 1653 | if (LocaleCompare(value,"currentColor") == 0) |
| 1654 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1655 | (void) FormatLocaleFile(svg_info->file, |
| 1656 | "fill '%s'\n",color); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1657 | break; |
| 1658 | } |
| 1659 | if (LocaleCompare(value,"#00000000") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1660 | (void) FormatLocaleFile(svg_info->file, |
| 1661 | "fill '#000000'\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1663 | (void) FormatLocaleFile(svg_info->file,"fill '%s'\n", |
| 1664 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1665 | break; |
| 1666 | } |
| 1667 | if (LocaleCompare(keyword,"fillcolor") == 0) |
| 1668 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1669 | (void) FormatLocaleFile(svg_info->file,"fill '%s'\n", |
| 1670 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1671 | break; |
| 1672 | } |
| 1673 | if (LocaleCompare(keyword,"fill-rule") == 0) |
| 1674 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1675 | (void) FormatLocaleFile(svg_info->file, |
| 1676 | "fill-rule '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1677 | break; |
| 1678 | } |
| 1679 | if (LocaleCompare(keyword,"fill-opacity") == 0) |
| 1680 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1681 | (void) FormatLocaleFile(svg_info->file, |
| 1682 | "fill-opacity '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1683 | break; |
| 1684 | } |
| 1685 | if (LocaleCompare(keyword,"font-family") == 0) |
| 1686 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1687 | (void) FormatLocaleFile(svg_info->file, |
| 1688 | "font-family '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | break; |
| 1690 | } |
| 1691 | if (LocaleCompare(keyword,"font-stretch") == 0) |
| 1692 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1693 | (void) FormatLocaleFile(svg_info->file, |
| 1694 | "font-stretch '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1695 | break; |
| 1696 | } |
| 1697 | if (LocaleCompare(keyword,"font-style") == 0) |
| 1698 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1699 | (void) FormatLocaleFile(svg_info->file, |
| 1700 | "font-style '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1701 | break; |
| 1702 | } |
| 1703 | if (LocaleCompare(keyword,"font-size") == 0) |
| 1704 | { |
| 1705 | svg_info->pointsize=GetUserSpaceCoordinateValue( |
| 1706 | svg_info,0,value); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1707 | (void) FormatLocaleFile(svg_info->file,"font-size %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1708 | svg_info->pointsize); |
| 1709 | break; |
| 1710 | } |
| 1711 | if (LocaleCompare(keyword,"font-weight") == 0) |
| 1712 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1713 | (void) FormatLocaleFile(svg_info->file, |
| 1714 | "font-weight '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1715 | break; |
| 1716 | } |
| 1717 | break; |
| 1718 | } |
| 1719 | case 'O': |
| 1720 | case 'o': |
| 1721 | { |
| 1722 | if (LocaleCompare(keyword,"offset") == 0) |
| 1723 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1724 | (void) FormatLocaleFile(svg_info->file,"offset %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1725 | GetUserSpaceCoordinateValue(svg_info,1,value)); |
| 1726 | break; |
| 1727 | } |
| 1728 | if (LocaleCompare(keyword,"opacity") == 0) |
| 1729 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1730 | (void) FormatLocaleFile(svg_info->file, |
| 1731 | "opacity '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | break; |
| 1735 | } |
| 1736 | case 'S': |
| 1737 | case 's': |
| 1738 | { |
| 1739 | if (LocaleCompare(keyword,"stop-color") == 0) |
| 1740 | { |
| 1741 | (void) CloneString(&svg_info->stop_color,value); |
| 1742 | break; |
| 1743 | } |
| 1744 | if (LocaleCompare(keyword,"stroke") == 0) |
| 1745 | { |
| 1746 | if (LocaleCompare(value,"currentColor") == 0) |
| 1747 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1748 | (void) FormatLocaleFile(svg_info->file, |
| 1749 | "stroke '%s'\n",color); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1750 | break; |
| 1751 | } |
| 1752 | if (LocaleCompare(value,"#00000000") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1753 | (void) FormatLocaleFile(svg_info->file, |
| 1754 | "fill '#000000'\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1755 | else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1756 | (void) FormatLocaleFile(svg_info->file, |
| 1757 | "stroke '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1758 | break; |
| 1759 | } |
| 1760 | if (LocaleCompare(keyword,"stroke-antialiasing") == 0) |
| 1761 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1762 | (void) FormatLocaleFile(svg_info->file, |
| 1763 | "stroke-antialias %d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1764 | LocaleCompare(value,"true") == 0); |
| 1765 | break; |
| 1766 | } |
| 1767 | if (LocaleCompare(keyword,"stroke-dasharray") == 0) |
| 1768 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1769 | (void) FormatLocaleFile(svg_info->file, |
| 1770 | "stroke-dasharray %s\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1771 | break; |
| 1772 | } |
| 1773 | if (LocaleCompare(keyword,"stroke-dashoffset") == 0) |
| 1774 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1775 | (void) FormatLocaleFile(svg_info->file, |
| 1776 | "stroke-dashoffset %s\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1777 | value); |
| 1778 | break; |
| 1779 | } |
| 1780 | if (LocaleCompare(keyword,"stroke-linecap") == 0) |
| 1781 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1782 | (void) FormatLocaleFile(svg_info->file, |
| 1783 | "stroke-linecap '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1784 | break; |
| 1785 | } |
| 1786 | if (LocaleCompare(keyword,"stroke-linejoin") == 0) |
| 1787 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1788 | (void) FormatLocaleFile(svg_info->file, |
| 1789 | "stroke-linejoin '%s'\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1790 | value); |
| 1791 | break; |
| 1792 | } |
| 1793 | if (LocaleCompare(keyword,"stroke-miterlimit") == 0) |
| 1794 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1795 | (void) FormatLocaleFile(svg_info->file, |
| 1796 | "stroke-miterlimit '%s'\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1797 | value); |
| 1798 | break; |
| 1799 | } |
| 1800 | if (LocaleCompare(keyword,"stroke-opacity") == 0) |
| 1801 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1802 | (void) FormatLocaleFile(svg_info->file, |
| 1803 | "stroke-opacity '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1804 | break; |
| 1805 | } |
| 1806 | if (LocaleCompare(keyword,"stroke-width") == 0) |
| 1807 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1808 | (void) FormatLocaleFile(svg_info->file, |
| 1809 | "stroke-width %g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1810 | GetUserSpaceCoordinateValue(svg_info,1,value)); |
| 1811 | break; |
| 1812 | } |
| 1813 | break; |
| 1814 | } |
| 1815 | case 't': |
| 1816 | case 'T': |
| 1817 | { |
| 1818 | if (LocaleCompare(keyword,"text-align") == 0) |
| 1819 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1820 | (void) FormatLocaleFile(svg_info->file, |
| 1821 | "text-align '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1822 | break; |
| 1823 | } |
| 1824 | if (LocaleCompare(keyword,"text-anchor") == 0) |
| 1825 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1826 | (void) FormatLocaleFile(svg_info->file, |
| 1827 | "text-anchor '%s'\n",value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1828 | break; |
| 1829 | } |
| 1830 | if (LocaleCompare(keyword,"text-decoration") == 0) |
| 1831 | { |
| 1832 | if (LocaleCompare(value,"underline") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1833 | (void) FormatLocaleFile(svg_info->file, |
| 1834 | "decorate underline\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 | if (LocaleCompare(value,"line-through") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1836 | (void) FormatLocaleFile(svg_info->file, |
| 1837 | "decorate line-through\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1838 | if (LocaleCompare(value,"overline") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1839 | (void) FormatLocaleFile(svg_info->file, |
| 1840 | "decorate overline\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1841 | break; |
| 1842 | } |
| 1843 | if (LocaleCompare(keyword,"text-antialiasing") == 0) |
| 1844 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1845 | (void) FormatLocaleFile(svg_info->file, |
| 1846 | "text-antialias %d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1847 | LocaleCompare(value,"true") == 0); |
| 1848 | break; |
| 1849 | } |
| 1850 | break; |
| 1851 | } |
| 1852 | default: |
| 1853 | break; |
| 1854 | } |
| 1855 | } |
| 1856 | for (j=0; tokens[j] != (char *) NULL; j++) |
| 1857 | tokens[j]=DestroyString(tokens[j]); |
| 1858 | tokens=(char **) RelinquishMagickMemory(tokens); |
| 1859 | break; |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | case 'T': |
| 1864 | case 't': |
| 1865 | { |
| 1866 | if (LocaleCompare(keyword,"text-align") == 0) |
| 1867 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1868 | (void) FormatLocaleFile(svg_info->file,"text-align '%s'\n", |
| 1869 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1870 | break; |
| 1871 | } |
| 1872 | if (LocaleCompare(keyword,"text-anchor") == 0) |
| 1873 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1874 | (void) FormatLocaleFile(svg_info->file,"text-anchor '%s'\n", |
| 1875 | value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | if (LocaleCompare(keyword,"text-decoration") == 0) |
| 1879 | { |
| 1880 | if (LocaleCompare(value,"underline") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1881 | (void) FormatLocaleFile(svg_info->file,"decorate underline\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1882 | if (LocaleCompare(value,"line-through") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1883 | (void) FormatLocaleFile(svg_info->file, |
| 1884 | "decorate line-through\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1885 | if (LocaleCompare(value,"overline") == 0) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1886 | (void) FormatLocaleFile(svg_info->file,"decorate overline\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1887 | break; |
| 1888 | } |
| 1889 | if (LocaleCompare(keyword,"text-antialiasing") == 0) |
| 1890 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1891 | (void) FormatLocaleFile(svg_info->file,"text-antialias %d\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | LocaleCompare(value,"true") == 0); |
| 1893 | break; |
| 1894 | } |
| 1895 | if (LocaleCompare(keyword,"transform") == 0) |
| 1896 | { |
| 1897 | AffineMatrix |
| 1898 | affine, |
| 1899 | current, |
| 1900 | transform; |
| 1901 | |
| 1902 | GetAffineMatrix(&transform); |
| 1903 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," "); |
| 1904 | tokens=GetTransformTokens(context,value,&number_tokens); |
| 1905 | for (j=0; j < (number_tokens-1); j+=2) |
| 1906 | { |
| 1907 | keyword=(char *) tokens[j]; |
| 1908 | value=(char *) tokens[j+1]; |
| 1909 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1910 | " %s: %s",keyword,value); |
| 1911 | current=transform; |
| 1912 | GetAffineMatrix(&affine); |
| 1913 | switch (*keyword) |
| 1914 | { |
| 1915 | case 'M': |
| 1916 | case 'm': |
| 1917 | { |
| 1918 | if (LocaleCompare(keyword,"matrix") == 0) |
| 1919 | { |
| 1920 | p=(const char *) value; |
| 1921 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1922 | affine.sx=InterpretLocaleValue(value,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1923 | GetMagickToken(p,&p,token); |
| 1924 | if (*token == ',') |
| 1925 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1926 | affine.rx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1927 | GetMagickToken(p,&p,token); |
| 1928 | if (*token == ',') |
| 1929 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1930 | affine.ry=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1931 | GetMagickToken(p,&p,token); |
| 1932 | if (*token == ',') |
| 1933 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1934 | affine.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1935 | GetMagickToken(p,&p,token); |
| 1936 | if (*token == ',') |
| 1937 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1938 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1939 | GetMagickToken(p,&p,token); |
| 1940 | if (*token == ',') |
| 1941 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1942 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | } |
| 1945 | break; |
| 1946 | } |
| 1947 | case 'R': |
| 1948 | case 'r': |
| 1949 | { |
| 1950 | if (LocaleCompare(keyword,"rotate") == 0) |
| 1951 | { |
| 1952 | double |
| 1953 | angle, |
| 1954 | x, |
| 1955 | y; |
| 1956 | |
| 1957 | p=(const char *) value; |
| 1958 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1959 | angle=InterpretLocaleValue(value,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1960 | GetMagickToken(p,&p,token); |
| 1961 | if (*token == ',') |
| 1962 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1963 | x=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1964 | GetMagickToken(p,&p,token); |
| 1965 | if (*token == ',') |
| 1966 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 1967 | y=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1968 | affine.sx=cos(DegreesToRadians(fmod(angle,360.0))); |
| 1969 | affine.rx=sin(DegreesToRadians(fmod(angle,360.0))); |
| 1970 | affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0)))); |
| 1971 | affine.sy=cos(DegreesToRadians(fmod(angle,360.0))); |
| 1972 | affine.tx=x; |
| 1973 | affine.ty=y; |
| 1974 | svg_info->center.x=x; |
| 1975 | svg_info->center.y=y; |
| 1976 | break; |
| 1977 | } |
| 1978 | break; |
| 1979 | } |
| 1980 | case 'S': |
| 1981 | case 's': |
| 1982 | { |
| 1983 | if (LocaleCompare(keyword,"scale") == 0) |
| 1984 | { |
| 1985 | for (p=(const char *) value; *p != '\0'; p++) |
| 1986 | if ((isspace((int) ((unsigned char) *p)) != 0) || |
| 1987 | (*p == ',')) |
| 1988 | break; |
| 1989 | affine.sx=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 1990 | affine.sy=affine.sx; |
| 1991 | if (*p != '\0') |
| 1992 | affine.sy=GetUserSpaceCoordinateValue(svg_info,-1, |
| 1993 | p+1); |
| 1994 | svg_info->scale[svg_info->n]=ExpandAffine(&affine); |
| 1995 | break; |
| 1996 | } |
| 1997 | if (LocaleCompare(keyword,"skewX") == 0) |
| 1998 | { |
| 1999 | affine.sx=svg_info->affine.sx; |
| 2000 | affine.ry=tan(DegreesToRadians(fmod( |
| 2001 | GetUserSpaceCoordinateValue(svg_info,1,value), |
| 2002 | 360.0))); |
| 2003 | affine.sy=svg_info->affine.sy; |
| 2004 | break; |
| 2005 | } |
| 2006 | if (LocaleCompare(keyword,"skewY") == 0) |
| 2007 | { |
| 2008 | affine.sx=svg_info->affine.sx; |
| 2009 | affine.rx=tan(DegreesToRadians(fmod( |
| 2010 | GetUserSpaceCoordinateValue(svg_info,-1,value), |
| 2011 | 360.0))); |
| 2012 | affine.sy=svg_info->affine.sy; |
| 2013 | break; |
| 2014 | } |
| 2015 | break; |
| 2016 | } |
| 2017 | case 'T': |
| 2018 | case 't': |
| 2019 | { |
| 2020 | if (LocaleCompare(keyword,"translate") == 0) |
| 2021 | { |
| 2022 | for (p=(const char *) value; *p != '\0'; p++) |
| 2023 | if ((isspace((int) ((unsigned char) *p)) != 0) || |
| 2024 | (*p == ',')) |
| 2025 | break; |
| 2026 | affine.tx=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 2027 | affine.ty=affine.tx; |
| 2028 | if (*p != '\0') |
| 2029 | affine.ty=GetUserSpaceCoordinateValue(svg_info,-1, |
| 2030 | p+1); |
| 2031 | break; |
| 2032 | } |
| 2033 | break; |
| 2034 | } |
| 2035 | default: |
| 2036 | break; |
| 2037 | } |
cristy | ef7c8a5 | 2010-10-10 13:46:51 +0000 | [diff] [blame] | 2038 | transform.sx=affine.sx*current.sx+affine.ry*current.rx; |
| 2039 | transform.rx=affine.rx*current.sx+affine.sy*current.rx; |
| 2040 | transform.ry=affine.sx*current.ry+affine.ry*current.sy; |
| 2041 | transform.sy=affine.rx*current.ry+affine.sy*current.sy; |
| 2042 | transform.tx=affine.sx*current.tx+affine.ry*current.ty+ |
| 2043 | affine.tx; |
| 2044 | transform.ty=affine.rx*current.tx+affine.sy*current.ty+ |
| 2045 | affine.ty; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2046 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2047 | (void) FormatLocaleFile(svg_info->file, |
cristy | 4096b01 | 2011-10-19 00:31:56 +0000 | [diff] [blame] | 2048 | "affine %g %g %g %g %g %g\n",transform.sx,transform.rx, |
| 2049 | transform.ry,transform.sy,transform.tx,transform.ty); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2050 | for (j=0; tokens[j] != (char *) NULL; j++) |
| 2051 | tokens[j]=DestroyString(tokens[j]); |
| 2052 | tokens=(char **) RelinquishMagickMemory(tokens); |
| 2053 | break; |
| 2054 | } |
| 2055 | break; |
| 2056 | } |
| 2057 | case 'V': |
| 2058 | case 'v': |
| 2059 | { |
| 2060 | if (LocaleCompare(keyword,"verts") == 0) |
| 2061 | { |
| 2062 | (void) CloneString(&svg_info->vertices,value); |
| 2063 | break; |
| 2064 | } |
| 2065 | if (LocaleCompare(keyword,"viewBox") == 0) |
| 2066 | { |
| 2067 | p=(const char *) value; |
| 2068 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2069 | svg_info->view_box.x=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2070 | GetMagickToken(p,&p,token); |
| 2071 | if (*token == ',') |
| 2072 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2073 | svg_info->view_box.y=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2074 | GetMagickToken(p,&p,token); |
| 2075 | if (*token == ',') |
| 2076 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2077 | svg_info->view_box.width=InterpretLocaleValue(token, |
| 2078 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2079 | if (svg_info->bounds.width == 0) |
| 2080 | svg_info->bounds.width=svg_info->view_box.width; |
| 2081 | GetMagickToken(p,&p,token); |
| 2082 | if (*token == ',') |
| 2083 | GetMagickToken(p,&p,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2084 | svg_info->view_box.height=InterpretLocaleValue(token, |
| 2085 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2086 | if (svg_info->bounds.height == 0) |
| 2087 | svg_info->bounds.height=svg_info->view_box.height; |
| 2088 | break; |
| 2089 | } |
| 2090 | break; |
| 2091 | } |
| 2092 | case 'W': |
| 2093 | case 'w': |
| 2094 | { |
| 2095 | if (LocaleCompare(keyword,"width") == 0) |
| 2096 | { |
| 2097 | svg_info->bounds.width= |
| 2098 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 2099 | break; |
| 2100 | } |
| 2101 | break; |
| 2102 | } |
| 2103 | case 'X': |
| 2104 | case 'x': |
| 2105 | { |
| 2106 | if (LocaleCompare(keyword,"x") == 0) |
| 2107 | { |
| 2108 | svg_info->bounds.x=GetUserSpaceCoordinateValue(svg_info,1,value); |
| 2109 | break; |
| 2110 | } |
| 2111 | if (LocaleCompare(keyword,"xlink:href") == 0) |
| 2112 | { |
| 2113 | (void) CloneString(&svg_info->url,value); |
| 2114 | break; |
| 2115 | } |
| 2116 | if (LocaleCompare(keyword,"x1") == 0) |
| 2117 | { |
| 2118 | svg_info->segment.x1= |
| 2119 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 2120 | break; |
| 2121 | } |
| 2122 | if (LocaleCompare(keyword,"x2") == 0) |
| 2123 | { |
| 2124 | svg_info->segment.x2= |
| 2125 | GetUserSpaceCoordinateValue(svg_info,1,value); |
| 2126 | break; |
| 2127 | } |
| 2128 | break; |
| 2129 | } |
| 2130 | case 'Y': |
| 2131 | case 'y': |
| 2132 | { |
| 2133 | if (LocaleCompare(keyword,"y") == 0) |
| 2134 | { |
| 2135 | svg_info->bounds.y=GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 2136 | break; |
| 2137 | } |
| 2138 | if (LocaleCompare(keyword,"y1") == 0) |
| 2139 | { |
| 2140 | svg_info->segment.y1= |
| 2141 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 2142 | break; |
| 2143 | } |
| 2144 | if (LocaleCompare(keyword,"y2") == 0) |
| 2145 | { |
| 2146 | svg_info->segment.y2= |
| 2147 | GetUserSpaceCoordinateValue(svg_info,-1,value); |
| 2148 | break; |
| 2149 | } |
| 2150 | break; |
| 2151 | } |
| 2152 | default: |
| 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | if (LocaleCompare((const char *) name,"svg") == 0) |
| 2157 | { |
| 2158 | if (svg_info->document->encoding != (const xmlChar *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2159 | (void) FormatLocaleFile(svg_info->file,"encoding \"%s\"\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2160 | (const char *) svg_info->document->encoding); |
| 2161 | if (attributes != (const xmlChar **) NULL) |
| 2162 | { |
| 2163 | double |
| 2164 | sx, |
| 2165 | sy; |
| 2166 | |
| 2167 | if ((svg_info->view_box.width == 0.0) || |
| 2168 | (svg_info->view_box.height == 0.0)) |
| 2169 | svg_info->view_box=svg_info->bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2170 | svg_info->width=(size_t) floor(svg_info->bounds.width+0.5); |
| 2171 | svg_info->height=(size_t) floor(svg_info->bounds.height+0.5); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2172 | (void) FormatLocaleFile(svg_info->file,"viewbox 0 0 %.20g %.20g\n", |
| 2173 | (double) svg_info->width,(double) svg_info->height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2174 | sx=(double) svg_info->width/svg_info->view_box.width; |
| 2175 | sy=(double) svg_info->height/svg_info->view_box.height; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2176 | (void) FormatLocaleFile(svg_info->file,"affine %g 0 0 %g 0.0 0.0\n", |
| 2177 | sx,sy); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," )"); |
| 2181 | units=DestroyString(units); |
| 2182 | if (color != (char *) NULL) |
| 2183 | color=DestroyString(color); |
| 2184 | } |
| 2185 | |
| 2186 | static void SVGEndElement(void *context,const xmlChar *name) |
| 2187 | { |
| 2188 | SVGInfo |
| 2189 | *svg_info; |
| 2190 | |
| 2191 | /* |
| 2192 | Called when the end of an element has been detected. |
| 2193 | */ |
| 2194 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 2195 | " SAX.endElement(%s)",name); |
| 2196 | svg_info=(SVGInfo *) context; |
cristy | 13d0704 | 2010-11-21 20:56:18 +0000 | [diff] [blame] | 2197 | if (strchr((char *) name,':') != (char *) NULL) |
cristy | 768b930 | 2010-11-20 00:05:47 +0000 | [diff] [blame] | 2198 | { |
| 2199 | /* |
| 2200 | Skip over namespace. |
| 2201 | */ |
| 2202 | for ( ; *name != ':'; name++) ; |
| 2203 | name++; |
| 2204 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2205 | switch (*name) |
| 2206 | { |
| 2207 | case 'C': |
| 2208 | case 'c': |
| 2209 | { |
| 2210 | if (LocaleCompare((const char *) name,"circle") == 0) |
| 2211 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2212 | (void) FormatLocaleFile(svg_info->file,"circle %g,%g %g,%g\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2213 | svg_info->element.cx,svg_info->element.cy,svg_info->element.cx, |
| 2214 | svg_info->element.cy+svg_info->element.minor); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2215 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | } |
| 2218 | if (LocaleCompare((const char *) name,"clipPath") == 0) |
| 2219 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2220 | (void) FormatLocaleFile(svg_info->file,"pop clip-path\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | } |
| 2223 | break; |
| 2224 | } |
| 2225 | case 'D': |
| 2226 | case 'd': |
| 2227 | { |
| 2228 | if (LocaleCompare((const char *) name,"defs") == 0) |
| 2229 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2230 | (void) FormatLocaleFile(svg_info->file,"pop defs\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2231 | break; |
| 2232 | } |
| 2233 | if (LocaleCompare((const char *) name,"desc") == 0) |
| 2234 | { |
| 2235 | register char |
| 2236 | *p; |
| 2237 | |
| 2238 | if (*svg_info->text == '\0') |
| 2239 | break; |
| 2240 | (void) fputc('#',svg_info->file); |
| 2241 | for (p=svg_info->text; *p != '\0'; p++) |
| 2242 | { |
| 2243 | (void) fputc(*p,svg_info->file); |
| 2244 | if (*p == '\n') |
| 2245 | (void) fputc('#',svg_info->file); |
| 2246 | } |
| 2247 | (void) fputc('\n',svg_info->file); |
| 2248 | *svg_info->text='\0'; |
| 2249 | break; |
| 2250 | } |
| 2251 | break; |
| 2252 | } |
| 2253 | case 'E': |
| 2254 | case 'e': |
| 2255 | { |
| 2256 | if (LocaleCompare((const char *) name,"ellipse") == 0) |
| 2257 | { |
| 2258 | double |
| 2259 | angle; |
| 2260 | |
| 2261 | angle=svg_info->element.angle; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2262 | (void) FormatLocaleFile(svg_info->file,"ellipse %g,%g %g,%g 0,360\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2263 | svg_info->element.cx,svg_info->element.cy, |
| 2264 | angle == 0.0 ? svg_info->element.major : svg_info->element.minor, |
| 2265 | angle == 0.0 ? svg_info->element.minor : svg_info->element.major); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2266 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2267 | break; |
| 2268 | } |
| 2269 | break; |
| 2270 | } |
| 2271 | case 'G': |
| 2272 | case 'g': |
| 2273 | { |
| 2274 | if (LocaleCompare((const char *) name,"g") == 0) |
| 2275 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2276 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2277 | break; |
| 2278 | } |
| 2279 | break; |
| 2280 | } |
| 2281 | case 'I': |
| 2282 | case 'i': |
| 2283 | { |
| 2284 | if (LocaleCompare((const char *) name,"image") == 0) |
| 2285 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2286 | (void) FormatLocaleFile(svg_info->file, |
| 2287 | "image Over %g,%g %g,%g '%s'\n",svg_info->bounds.x, |
| 2288 | svg_info->bounds.y,svg_info->bounds.width,svg_info->bounds.height, |
| 2289 | svg_info->url); |
| 2290 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | } |
| 2293 | break; |
| 2294 | } |
| 2295 | case 'L': |
| 2296 | case 'l': |
| 2297 | { |
| 2298 | if (LocaleCompare((const char *) name,"line") == 0) |
| 2299 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2300 | (void) FormatLocaleFile(svg_info->file,"line %g,%g %g,%g\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2301 | svg_info->segment.x1,svg_info->segment.y1,svg_info->segment.x2, |
| 2302 | svg_info->segment.y2); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2303 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | } |
| 2306 | if (LocaleCompare((const char *) name,"linearGradient") == 0) |
| 2307 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2308 | (void) FormatLocaleFile(svg_info->file,"pop gradient\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | } |
| 2311 | break; |
| 2312 | } |
| 2313 | case 'P': |
| 2314 | case 'p': |
| 2315 | { |
| 2316 | if (LocaleCompare((const char *) name,"pattern") == 0) |
| 2317 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2318 | (void) FormatLocaleFile(svg_info->file,"pop pattern\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2319 | break; |
| 2320 | } |
| 2321 | if (LocaleCompare((const char *) name,"path") == 0) |
| 2322 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2323 | (void) FormatLocaleFile(svg_info->file,"path '%s'\n", |
| 2324 | svg_info->vertices); |
| 2325 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2326 | break; |
| 2327 | } |
| 2328 | if (LocaleCompare((const char *) name,"polygon") == 0) |
| 2329 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2330 | (void) FormatLocaleFile(svg_info->file,"polygon %s\n", |
| 2331 | svg_info->vertices); |
| 2332 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | } |
| 2335 | if (LocaleCompare((const char *) name,"polyline") == 0) |
| 2336 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2337 | (void) FormatLocaleFile(svg_info->file,"polyline %s\n", |
| 2338 | svg_info->vertices); |
| 2339 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2340 | break; |
| 2341 | } |
| 2342 | break; |
| 2343 | } |
| 2344 | case 'R': |
| 2345 | case 'r': |
| 2346 | { |
| 2347 | if (LocaleCompare((const char *) name,"radialGradient") == 0) |
| 2348 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2349 | (void) FormatLocaleFile(svg_info->file,"pop gradient\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | } |
| 2352 | if (LocaleCompare((const char *) name,"rect") == 0) |
| 2353 | { |
| 2354 | if ((svg_info->radius.x == 0.0) && (svg_info->radius.y == 0.0)) |
| 2355 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2356 | (void) FormatLocaleFile(svg_info->file,"rectangle %g,%g %g,%g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2357 | svg_info->bounds.x,svg_info->bounds.y, |
| 2358 | svg_info->bounds.x+svg_info->bounds.width, |
| 2359 | svg_info->bounds.y+svg_info->bounds.height); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2360 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | } |
| 2363 | if (svg_info->radius.x == 0.0) |
| 2364 | svg_info->radius.x=svg_info->radius.y; |
| 2365 | if (svg_info->radius.y == 0.0) |
| 2366 | svg_info->radius.y=svg_info->radius.x; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2367 | (void) FormatLocaleFile(svg_info->file, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2368 | "roundRectangle %g,%g %g,%g %g,%g\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2369 | svg_info->bounds.x,svg_info->bounds.y,svg_info->bounds.x+ |
| 2370 | svg_info->bounds.width,svg_info->bounds.y+svg_info->bounds.height, |
| 2371 | svg_info->radius.x,svg_info->radius.y); |
| 2372 | svg_info->radius.x=0.0; |
| 2373 | svg_info->radius.y=0.0; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2374 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2375 | break; |
| 2376 | } |
| 2377 | break; |
| 2378 | } |
| 2379 | case 'S': |
| 2380 | case 's': |
| 2381 | { |
| 2382 | if (LocaleCompare((const char *) name,"stop") == 0) |
| 2383 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2384 | (void) FormatLocaleFile(svg_info->file,"stop-color '%s' %s\n", |
| 2385 | svg_info->stop_color,svg_info->offset); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | } |
| 2388 | if (LocaleCompare((const char *) name,"svg") == 0) |
| 2389 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2390 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2391 | break; |
| 2392 | } |
| 2393 | break; |
| 2394 | } |
| 2395 | case 'T': |
| 2396 | case 't': |
| 2397 | { |
| 2398 | if (LocaleCompare((const char *) name,"text") == 0) |
| 2399 | { |
| 2400 | if (*svg_info->text != '\0') |
| 2401 | { |
| 2402 | char |
| 2403 | *text; |
| 2404 | |
| 2405 | text=EscapeString(svg_info->text,'\''); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2406 | (void) FormatLocaleFile(svg_info->file,"text %g,%g '%s'\n", |
cristy | 8815806 | 2011-06-09 00:31:43 +0000 | [diff] [blame] | 2407 | svg_info->bounds.x,svg_info->bounds.y,text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2408 | text=DestroyString(text); |
| 2409 | *svg_info->text='\0'; |
| 2410 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2411 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2412 | break; |
| 2413 | } |
| 2414 | if (LocaleCompare((const char *) name,"tspan") == 0) |
| 2415 | { |
| 2416 | if (*svg_info->text != '\0') |
| 2417 | { |
| 2418 | DrawInfo |
| 2419 | *draw_info; |
| 2420 | |
| 2421 | TypeMetric |
| 2422 | metrics; |
| 2423 | |
| 2424 | char |
| 2425 | *text; |
| 2426 | |
| 2427 | text=EscapeString(svg_info->text,'\''); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2428 | (void) FormatLocaleFile(svg_info->file,"text %g,%g '%s'\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2429 | svg_info->bounds.x,svg_info->bounds.y,text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2430 | text=DestroyString(text); |
| 2431 | draw_info=CloneDrawInfo(svg_info->image_info,(DrawInfo *) NULL); |
| 2432 | draw_info->pointsize=svg_info->pointsize; |
| 2433 | draw_info->text=AcquireString(svg_info->text); |
| 2434 | (void) ConcatenateString(&draw_info->text," "); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 2435 | (void) GetTypeMetrics(svg_info->image,draw_info,&metrics, |
| 2436 | svg_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2437 | svg_info->bounds.x+=metrics.width; |
| 2438 | draw_info=DestroyDrawInfo(draw_info); |
| 2439 | *svg_info->text='\0'; |
| 2440 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2441 | (void) FormatLocaleFile(svg_info->file,"pop graphic-context\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | } |
| 2444 | if (LocaleCompare((const char *) name,"title") == 0) |
| 2445 | { |
| 2446 | if (*svg_info->text == '\0') |
| 2447 | break; |
| 2448 | (void) CloneString(&svg_info->title,svg_info->text); |
| 2449 | *svg_info->text='\0'; |
| 2450 | break; |
| 2451 | } |
| 2452 | break; |
| 2453 | } |
| 2454 | default: |
| 2455 | break; |
| 2456 | } |
| 2457 | *svg_info->text='\0'; |
| 2458 | (void) ResetMagickMemory(&svg_info->element,0,sizeof(svg_info->element)); |
| 2459 | (void) ResetMagickMemory(&svg_info->segment,0,sizeof(svg_info->segment)); |
| 2460 | svg_info->n--; |
| 2461 | } |
| 2462 | |
| 2463 | static void SVGCharacters(void *context,const xmlChar *c,int length) |
| 2464 | { |
| 2465 | register char |
| 2466 | *p; |
| 2467 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2468 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2469 | i; |
| 2470 | |
| 2471 | SVGInfo |
| 2472 | *svg_info; |
| 2473 | |
| 2474 | /* |
| 2475 | Receiving some characters from the parser. |
| 2476 | */ |
| 2477 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 2478 | " SAX.characters(%s,%.20g)",c,(double) length); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2479 | svg_info=(SVGInfo *) context; |
| 2480 | if (svg_info->text != (char *) NULL) |
| 2481 | svg_info->text=(char *) ResizeQuantumMemory(svg_info->text, |
| 2482 | strlen(svg_info->text)+length+MaxTextExtent,sizeof(*svg_info->text)); |
| 2483 | else |
| 2484 | { |
| 2485 | svg_info->text=(char *) AcquireQuantumMemory(length+MaxTextExtent, |
| 2486 | sizeof(*svg_info->text)); |
| 2487 | if (svg_info->text != (char *) NULL) |
| 2488 | *svg_info->text='\0'; |
| 2489 | } |
| 2490 | if (svg_info->text == (char *) NULL) |
| 2491 | return; |
| 2492 | p=svg_info->text+strlen(svg_info->text); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2493 | for (i=0; i < (ssize_t) length; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2494 | *p++=c[i]; |
| 2495 | *p='\0'; |
| 2496 | } |
| 2497 | |
| 2498 | static void SVGReference(void *context,const xmlChar *name) |
| 2499 | { |
| 2500 | SVGInfo |
| 2501 | *svg_info; |
| 2502 | |
| 2503 | xmlParserCtxtPtr |
| 2504 | parser; |
| 2505 | |
| 2506 | /* |
| 2507 | Called when an entity reference is detected. |
| 2508 | */ |
| 2509 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.reference(%s)", |
| 2510 | name); |
| 2511 | svg_info=(SVGInfo *) context; |
| 2512 | parser=svg_info->parser; |
| 2513 | if (parser == (xmlParserCtxtPtr) NULL) |
| 2514 | return; |
| 2515 | if (parser->node == (xmlNodePtr) NULL) |
| 2516 | return; |
| 2517 | if (*name == '#') |
| 2518 | (void) xmlAddChild(parser->node,xmlNewCharRef(svg_info->document,name)); |
| 2519 | else |
| 2520 | (void) xmlAddChild(parser->node,xmlNewReference(svg_info->document,name)); |
| 2521 | } |
| 2522 | |
| 2523 | static void SVGIgnorableWhitespace(void *context,const xmlChar *c,int length) |
| 2524 | { |
| 2525 | SVGInfo |
| 2526 | *svg_info; |
| 2527 | |
| 2528 | /* |
| 2529 | Receiving some ignorable whitespaces from the parser. |
| 2530 | */ |
| 2531 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 2532 | " SAX.ignorableWhitespace(%.30s, %d)",c,length); |
| 2533 | svg_info=(SVGInfo *) context; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 2534 | (void) svg_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | static void SVGProcessingInstructions(void *context,const xmlChar *target, |
| 2538 | const xmlChar *data) |
| 2539 | { |
| 2540 | SVGInfo |
| 2541 | *svg_info; |
| 2542 | |
| 2543 | /* |
| 2544 | A processing instruction has been parsed. |
| 2545 | */ |
| 2546 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 2547 | " SAX.processingInstruction(%s, %s)",target,data); |
| 2548 | svg_info=(SVGInfo *) context; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 2549 | (void) svg_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static void SVGComment(void *context,const xmlChar *value) |
| 2553 | { |
| 2554 | SVGInfo |
| 2555 | *svg_info; |
| 2556 | |
| 2557 | /* |
| 2558 | A comment has been parsed. |
| 2559 | */ |
| 2560 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.comment(%s)", |
| 2561 | value); |
| 2562 | svg_info=(SVGInfo *) context; |
| 2563 | if (svg_info->comment != (char *) NULL) |
| 2564 | (void) ConcatenateString(&svg_info->comment,"\n"); |
| 2565 | (void) ConcatenateString(&svg_info->comment,(const char *) value); |
| 2566 | } |
| 2567 | |
| 2568 | static void SVGWarning(void *context,const char *format,...) |
| 2569 | { |
| 2570 | char |
| 2571 | *message, |
| 2572 | reason[MaxTextExtent]; |
| 2573 | |
| 2574 | SVGInfo |
| 2575 | *svg_info; |
| 2576 | |
| 2577 | va_list |
| 2578 | operands; |
| 2579 | |
| 2580 | /** |
| 2581 | Display and format a warning messages, gives file, line, position and |
| 2582 | extra parameters. |
| 2583 | */ |
| 2584 | va_start(operands,format); |
| 2585 | svg_info=(SVGInfo *) context; |
| 2586 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.warning: "); |
| 2587 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),format,operands); |
| 2588 | #if !defined(MAGICKCORE_HAVE_VSNPRINTF) |
| 2589 | (void) vsprintf(reason,format,operands); |
| 2590 | #else |
| 2591 | (void) vsnprintf(reason,MaxTextExtent,format,operands); |
| 2592 | #endif |
| 2593 | message=GetExceptionMessage(errno); |
| 2594 | (void) ThrowMagickException(svg_info->exception,GetMagickModule(), |
| 2595 | DelegateWarning,reason,"`%s`",message); |
| 2596 | message=DestroyString(message); |
| 2597 | va_end(operands); |
| 2598 | } |
| 2599 | |
| 2600 | static void SVGError(void *context,const char *format,...) |
| 2601 | { |
| 2602 | char |
| 2603 | *message, |
| 2604 | reason[MaxTextExtent]; |
| 2605 | |
| 2606 | SVGInfo |
| 2607 | *svg_info; |
| 2608 | |
| 2609 | va_list |
| 2610 | operands; |
| 2611 | |
| 2612 | /* |
| 2613 | Display and format a error formats, gives file, line, position and |
| 2614 | extra parameters. |
| 2615 | */ |
| 2616 | va_start(operands,format); |
| 2617 | svg_info=(SVGInfo *) context; |
| 2618 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.error: "); |
| 2619 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),format,operands); |
| 2620 | #if !defined(MAGICKCORE_HAVE_VSNPRINTF) |
| 2621 | (void) vsprintf(reason,format,operands); |
| 2622 | #else |
| 2623 | (void) vsnprintf(reason,MaxTextExtent,format,operands); |
| 2624 | #endif |
| 2625 | message=GetExceptionMessage(errno); |
| 2626 | (void) ThrowMagickException(svg_info->exception,GetMagickModule(),CoderError, |
| 2627 | reason,"`%s`",message); |
| 2628 | message=DestroyString(message); |
| 2629 | va_end(operands); |
| 2630 | } |
| 2631 | |
| 2632 | static void SVGCDataBlock(void *context,const xmlChar *value,int length) |
| 2633 | { |
| 2634 | SVGInfo |
| 2635 | *svg_info; |
| 2636 | |
| 2637 | xmlNodePtr |
| 2638 | child; |
| 2639 | |
| 2640 | xmlParserCtxtPtr |
| 2641 | parser; |
| 2642 | |
| 2643 | /* |
| 2644 | Called when a pcdata block has been parsed. |
| 2645 | */ |
| 2646 | (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.pcdata(%s, %d)", |
| 2647 | value,length); |
| 2648 | svg_info=(SVGInfo *) context; |
| 2649 | parser=svg_info->parser; |
| 2650 | child=xmlGetLastChild(parser->node); |
| 2651 | if ((child != (xmlNodePtr) NULL) && (child->type == XML_CDATA_SECTION_NODE)) |
| 2652 | { |
| 2653 | xmlTextConcat(child,value,length); |
| 2654 | return; |
| 2655 | } |
| 2656 | (void) xmlAddChild(parser->node,xmlNewCDataBlock(parser->myDoc,value,length)); |
| 2657 | } |
| 2658 | |
| 2659 | static void SVGExternalSubset(void *context,const xmlChar *name, |
| 2660 | const xmlChar *external_id,const xmlChar *system_id) |
| 2661 | { |
| 2662 | SVGInfo |
| 2663 | *svg_info; |
| 2664 | |
| 2665 | xmlParserCtxt |
| 2666 | parser_context; |
| 2667 | |
| 2668 | xmlParserCtxtPtr |
| 2669 | parser; |
| 2670 | |
| 2671 | xmlParserInputPtr |
| 2672 | input; |
| 2673 | |
| 2674 | /* |
| 2675 | Does this document has an external subset? |
| 2676 | */ |
| 2677 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 2678 | " SAX.externalSubset(%s, %s, %s)",name, |
| 2679 | (external_id != (const xmlChar *) NULL ? (const char *) external_id : "none"), |
| 2680 | (system_id != (const xmlChar *) NULL ? (const char *) system_id : "none")); |
| 2681 | svg_info=(SVGInfo *) context; |
| 2682 | parser=svg_info->parser; |
| 2683 | if (((external_id == NULL) && (system_id == NULL)) || |
| 2684 | ((parser->validate == 0) || (parser->wellFormed == 0) || |
| 2685 | (svg_info->document == 0))) |
| 2686 | return; |
| 2687 | input=SVGResolveEntity(context,external_id,system_id); |
| 2688 | if (input == NULL) |
| 2689 | return; |
| 2690 | (void) xmlNewDtd(svg_info->document,name,external_id,system_id); |
| 2691 | parser_context=(*parser); |
| 2692 | parser->inputTab=(xmlParserInputPtr *) xmlMalloc(5*sizeof(*parser->inputTab)); |
| 2693 | if (parser->inputTab == (xmlParserInputPtr *) NULL) |
| 2694 | { |
| 2695 | parser->errNo=XML_ERR_NO_MEMORY; |
| 2696 | parser->input=parser_context.input; |
| 2697 | parser->inputNr=parser_context.inputNr; |
| 2698 | parser->inputMax=parser_context.inputMax; |
| 2699 | parser->inputTab=parser_context.inputTab; |
| 2700 | return; |
| 2701 | } |
| 2702 | parser->inputNr=0; |
| 2703 | parser->inputMax=5; |
| 2704 | parser->input=NULL; |
| 2705 | xmlPushInput(parser,input); |
| 2706 | (void) xmlSwitchEncoding(parser,xmlDetectCharEncoding(parser->input->cur,4)); |
| 2707 | if (input->filename == (char *) NULL) |
| 2708 | input->filename=(char *) xmlStrdup(system_id); |
| 2709 | input->line=1; |
| 2710 | input->col=1; |
| 2711 | input->base=parser->input->cur; |
| 2712 | input->cur=parser->input->cur; |
| 2713 | input->free=NULL; |
| 2714 | xmlParseExternalSubset(parser,external_id,system_id); |
| 2715 | while (parser->inputNr > 1) |
| 2716 | (void) xmlPopInput(parser); |
| 2717 | xmlFreeInputStream(parser->input); |
| 2718 | xmlFree(parser->inputTab); |
| 2719 | parser->input=parser_context.input; |
| 2720 | parser->inputNr=parser_context.inputNr; |
| 2721 | parser->inputMax=parser_context.inputMax; |
| 2722 | parser->inputTab=parser_context.inputTab; |
| 2723 | } |
| 2724 | |
| 2725 | #if defined(MAGICKCORE_RSVG_DELEGATE) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2726 | static void SVGSetImageSize(int *width,int *height,gpointer context) |
| 2727 | { |
| 2728 | Image |
| 2729 | *image; |
| 2730 | |
| 2731 | image=(Image *) context; |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame^] | 2732 | *width=(int) (*width*image->resolution.x/72.0); |
| 2733 | *height=(int) (*height*image->resolution.y/72.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2734 | } |
| 2735 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2736 | |
| 2737 | #if defined(__cplusplus) || defined(c_plusplus) |
| 2738 | } |
| 2739 | #endif |
| 2740 | |
| 2741 | static Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 2742 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2743 | char |
| 2744 | filename[MaxTextExtent]; |
| 2745 | |
| 2746 | FILE |
| 2747 | *file; |
| 2748 | |
| 2749 | Image |
| 2750 | *image; |
| 2751 | |
| 2752 | int |
| 2753 | status, |
| 2754 | unique_file; |
| 2755 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2756 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2757 | n; |
| 2758 | |
| 2759 | SVGInfo |
| 2760 | *svg_info; |
| 2761 | |
| 2762 | unsigned char |
| 2763 | message[MaxTextExtent]; |
| 2764 | |
cristy | 1f9e1ed | 2009-11-18 04:09:38 +0000 | [diff] [blame] | 2765 | xmlSAXHandler |
cristy | 5f6f01c | 2009-11-19 19:36:42 +0000 | [diff] [blame] | 2766 | sax_modules; |
cristy | 1f9e1ed | 2009-11-18 04:09:38 +0000 | [diff] [blame] | 2767 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2768 | xmlSAXHandlerPtr |
| 2769 | sax_handler; |
| 2770 | |
| 2771 | /* |
| 2772 | Open image file. |
| 2773 | */ |
| 2774 | assert(image_info != (const ImageInfo *) NULL); |
| 2775 | assert(image_info->signature == MagickSignature); |
| 2776 | assert(exception != (ExceptionInfo *) NULL); |
| 2777 | if (image_info->debug != MagickFalse) |
| 2778 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 2779 | image_info->filename); |
| 2780 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2781 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2782 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 2783 | if (status == MagickFalse) |
| 2784 | { |
| 2785 | image=DestroyImageList(image); |
| 2786 | return((Image *) NULL); |
| 2787 | } |
| 2788 | if (LocaleCompare(image_info->magick,"MSVG") != 0) |
| 2789 | { |
| 2790 | #if defined(MAGICKCORE_RSVG_DELEGATE) |
| 2791 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2792 | cairo_surface_t |
| 2793 | *cairo_surface; |
| 2794 | |
| 2795 | cairo_t |
| 2796 | *cairo_info; |
| 2797 | |
| 2798 | register unsigned char |
| 2799 | *p; |
| 2800 | |
| 2801 | RsvgDimensionData |
| 2802 | dimension_info; |
| 2803 | |
| 2804 | unsigned char |
| 2805 | *pixels; |
| 2806 | |
| 2807 | #else |
| 2808 | GdkPixbuf |
| 2809 | *pixel_info; |
| 2810 | |
| 2811 | register const guchar |
| 2812 | *p; |
| 2813 | |
| 2814 | #endif |
| 2815 | |
| 2816 | GError |
| 2817 | *error; |
| 2818 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2819 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2820 | y; |
| 2821 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2822 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2823 | fill_color; |
| 2824 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2825 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2826 | x; |
| 2827 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2828 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2829 | *q; |
| 2830 | |
| 2831 | RsvgHandle |
| 2832 | *svg_handle; |
| 2833 | |
| 2834 | svg_handle=rsvg_handle_new(); |
| 2835 | if (svg_handle == (RsvgHandle *) NULL) |
| 2836 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2837 | rsvg_handle_set_base_uri(svg_handle,image_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2838 | rsvg_handle_set_size_callback(svg_handle,SVGSetImageSize,image,NULL); |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame^] | 2839 | if ((image->resolution.x != 72.0) && (image->resolution.y != 72.0)) |
| 2840 | rsvg_handle_set_dpi_x_y(svg_handle,image->resolution.x, |
| 2841 | image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2842 | while ((n=ReadBlob(image,MaxTextExtent,message)) != 0) |
| 2843 | { |
| 2844 | error=(GError *) NULL; |
| 2845 | (void) rsvg_handle_write(svg_handle,message,n,&error); |
| 2846 | if (error != (GError *) NULL) |
| 2847 | g_error_free(error); |
| 2848 | } |
| 2849 | error=(GError *) NULL; |
| 2850 | rsvg_handle_close(svg_handle,&error); |
| 2851 | if (error != (GError *) NULL) |
| 2852 | g_error_free(error); |
| 2853 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2854 | rsvg_handle_get_dimensions(svg_handle,&dimension_info); |
cristy | 3de0a96 | 2009-12-06 15:34:07 +0000 | [diff] [blame] | 2855 | image->columns=dimension_info.width; |
| 2856 | image->rows=dimension_info.height; |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2857 | pixels=(unsigned char *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2858 | #else |
| 2859 | pixel_info=rsvg_handle_get_pixbuf(svg_handle); |
| 2860 | rsvg_handle_free(svg_handle); |
| 2861 | image->columns=gdk_pixbuf_get_width(pixel_info); |
| 2862 | image->rows=gdk_pixbuf_get_height(pixel_info); |
| 2863 | #endif |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2864 | image->matte=MagickTrue; |
| 2865 | SetImageProperty(image,"svg:base-uri", |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 2866 | rsvg_handle_get_base_uri(svg_handle),exception); |
| 2867 | SetImageProperty(image,"svg:title",rsvg_handle_get_title(svg_handle), |
| 2868 | exception); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2869 | SetImageProperty(image,"svg:description", |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 2870 | rsvg_handle_get_desc(svg_handle),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2871 | if ((image->columns == 0) || (image->rows == 0)) |
| 2872 | { |
| 2873 | #if !defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2874 | g_object_unref(G_OBJECT(pixel_info)); |
| 2875 | #endif |
| 2876 | g_object_unref(svg_handle); |
| 2877 | ThrowReaderException(MissingDelegateError, |
| 2878 | "NoDecodeDelegateForThisImageFormat"); |
| 2879 | } |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2880 | if (image_info->ping == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2881 | { |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2882 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2883 | pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4* |
| 2884 | image->rows*sizeof(*pixels)); |
| 2885 | if (pixels == (unsigned char *) NULL) |
| 2886 | { |
| 2887 | g_object_unref(svg_handle); |
| 2888 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2889 | } |
| 2890 | #endif |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 2891 | (void) SetImageBackgroundColor(image,exception); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2892 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2893 | cairo_surface=cairo_image_surface_create_for_data(pixels, |
| 2894 | CAIRO_FORMAT_ARGB32,image->columns,image->rows,4*image->columns); |
| 2895 | if (cairo_surface == (cairo_surface_t *) NULL) |
| 2896 | { |
| 2897 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
| 2898 | g_object_unref(svg_handle); |
| 2899 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2900 | } |
| 2901 | cairo_info=cairo_create(cairo_surface); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2902 | cairo_set_operator(cairo_info,CAIRO_OPERATOR_CLEAR); |
| 2903 | cairo_paint(cairo_info); |
| 2904 | cairo_set_operator(cairo_info,CAIRO_OPERATOR_OVER); |
| 2905 | rsvg_handle_render_cairo(svg_handle,cairo_info); |
| 2906 | cairo_destroy(cairo_info); |
| 2907 | cairo_surface_destroy(cairo_surface); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2908 | g_object_unref(svg_handle); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2909 | p=pixels; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2910 | #else |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2911 | p=gdk_pixbuf_get_pixels(pixel_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2912 | #endif |
cristy | 33e9da6 | 2011-10-21 19:08:58 +0000 | [diff] [blame] | 2913 | GetPixelInfo(image,&fill_color); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2914 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | d97b6ed | 2009-11-20 01:02:19 +0000 | [diff] [blame] | 2915 | { |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2916 | q=GetAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 2917 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2918 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2919 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2920 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2921 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2922 | fill_color.blue=ScaleCharToQuantum(*p++); |
| 2923 | fill_color.green=ScaleCharToQuantum(*p++); |
| 2924 | fill_color.red=ScaleCharToQuantum(*p++); |
| 2925 | #else |
| 2926 | fill_color.red=ScaleCharToQuantum(*p++); |
| 2927 | fill_color.green=ScaleCharToQuantum(*p++); |
| 2928 | fill_color.blue=ScaleCharToQuantum(*p++); |
| 2929 | #endif |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2930 | fill_color.alpha=ScaleCharToQuantum(*p++); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2931 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2932 | { |
| 2933 | double |
| 2934 | gamma; |
| 2935 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2936 | gamma=1.0-QuantumScale*fill_color.alpha; |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2937 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 2938 | fill_color.blue*=gamma; |
| 2939 | fill_color.green*=gamma; |
| 2940 | fill_color.red*=gamma; |
| 2941 | } |
| 2942 | #endif |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2943 | CompositePixelOver(image,&fill_color,fill_color.alpha,q, |
| 2944 | (MagickRealType) GetPixelAlpha(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 2945 | q+=GetPixelChannels(image); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2946 | } |
| 2947 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2948 | break; |
| 2949 | if (image->previous == (Image *) NULL) |
| 2950 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2951 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 2952 | image->rows); |
cristy | e391a85 | 2009-11-21 14:50:33 +0000 | [diff] [blame] | 2953 | if (status == MagickFalse) |
| 2954 | break; |
| 2955 | } |
| 2956 | } |
| 2957 | } |
| 2958 | #if defined(MAGICKCORE_CAIRO_DELEGATE) |
| 2959 | if (pixels != (unsigned char *) NULL) |
| 2960 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2961 | #else |
| 2962 | g_object_unref(G_OBJECT(pixel_info)); |
| 2963 | #endif |
| 2964 | (void) CloseBlob(image); |
| 2965 | return(GetFirstImageInList(image)); |
| 2966 | #endif |
| 2967 | } |
| 2968 | /* |
| 2969 | Open draw file. |
| 2970 | */ |
| 2971 | file=(FILE *) NULL; |
| 2972 | unique_file=AcquireUniqueFileResource(filename); |
| 2973 | if (unique_file != -1) |
| 2974 | file=fdopen(unique_file,"w"); |
| 2975 | if ((unique_file == -1) || (file == (FILE *) NULL)) |
| 2976 | { |
| 2977 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 2978 | ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile", |
| 2979 | image->filename); |
| 2980 | image=DestroyImageList(image); |
| 2981 | return((Image *) NULL); |
| 2982 | } |
| 2983 | /* |
| 2984 | Parse SVG file. |
| 2985 | */ |
| 2986 | svg_info=AcquireSVGInfo(); |
| 2987 | if (svg_info == (SVGInfo *) NULL) |
| 2988 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2989 | svg_info->file=file; |
| 2990 | svg_info->exception=exception; |
| 2991 | svg_info->image=image; |
| 2992 | svg_info->image_info=image_info; |
| 2993 | svg_info->bounds.width=image->columns; |
| 2994 | svg_info->bounds.height=image->rows; |
| 2995 | if (image_info->size != (char *) NULL) |
| 2996 | (void) CloneString(&svg_info->size,image_info->size); |
| 2997 | if (image->debug != MagickFalse) |
| 2998 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"begin SAX"); |
| 2999 | xmlInitParser(); |
| 3000 | (void) xmlSubstituteEntitiesDefault(1); |
cristy | 5f6f01c | 2009-11-19 19:36:42 +0000 | [diff] [blame] | 3001 | (void) ResetMagickMemory(&sax_modules,0,sizeof(sax_modules)); |
| 3002 | sax_modules.internalSubset=SVGInternalSubset; |
| 3003 | sax_modules.isStandalone=SVGIsStandalone; |
| 3004 | sax_modules.hasInternalSubset=SVGHasInternalSubset; |
| 3005 | sax_modules.hasExternalSubset=SVGHasExternalSubset; |
| 3006 | sax_modules.resolveEntity=SVGResolveEntity; |
| 3007 | sax_modules.getEntity=SVGGetEntity; |
| 3008 | sax_modules.entityDecl=SVGEntityDeclaration; |
| 3009 | sax_modules.notationDecl=SVGNotationDeclaration; |
| 3010 | sax_modules.attributeDecl=SVGAttributeDeclaration; |
| 3011 | sax_modules.elementDecl=SVGElementDeclaration; |
| 3012 | sax_modules.unparsedEntityDecl=SVGUnparsedEntityDeclaration; |
| 3013 | sax_modules.setDocumentLocator=SVGSetDocumentLocator; |
| 3014 | sax_modules.startDocument=SVGStartDocument; |
| 3015 | sax_modules.endDocument=SVGEndDocument; |
| 3016 | sax_modules.startElement=SVGStartElement; |
| 3017 | sax_modules.endElement=SVGEndElement; |
| 3018 | sax_modules.reference=SVGReference; |
| 3019 | sax_modules.characters=SVGCharacters; |
| 3020 | sax_modules.ignorableWhitespace=SVGIgnorableWhitespace; |
| 3021 | sax_modules.processingInstruction=SVGProcessingInstructions; |
| 3022 | sax_modules.comment=SVGComment; |
| 3023 | sax_modules.warning=SVGWarning; |
| 3024 | sax_modules.error=SVGError; |
| 3025 | sax_modules.fatalError=SVGError; |
| 3026 | sax_modules.getParameterEntity=SVGGetParameterEntity; |
| 3027 | sax_modules.cdataBlock=SVGCDataBlock; |
| 3028 | sax_modules.externalSubset=SVGExternalSubset; |
| 3029 | sax_handler=(&sax_modules); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3030 | n=ReadBlob(image,MaxTextExtent,message); |
| 3031 | if (n > 0) |
| 3032 | { |
| 3033 | svg_info->parser=xmlCreatePushParserCtxt(sax_handler,svg_info,(char *) |
| 3034 | message,n,image->filename); |
| 3035 | while ((n=ReadBlob(image,MaxTextExtent,message)) != 0) |
| 3036 | { |
| 3037 | status=xmlParseChunk(svg_info->parser,(char *) message,(int) n,0); |
| 3038 | if (status != 0) |
| 3039 | break; |
| 3040 | } |
| 3041 | } |
| 3042 | (void) xmlParseChunk(svg_info->parser,(char *) message,0,1); |
| 3043 | xmlFreeParserCtxt(svg_info->parser); |
| 3044 | if (image->debug != MagickFalse) |
| 3045 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"end SAX"); |
| 3046 | xmlCleanupParser(); |
| 3047 | (void) fclose(file); |
| 3048 | (void) CloseBlob(image); |
| 3049 | image->columns=svg_info->width; |
| 3050 | image->rows=svg_info->height; |
| 3051 | if (exception->severity >= ErrorException) |
| 3052 | { |
| 3053 | image=DestroyImage(image); |
| 3054 | return((Image *) NULL); |
| 3055 | } |
| 3056 | if (image_info->ping == MagickFalse) |
| 3057 | { |
| 3058 | ImageInfo |
| 3059 | *read_info; |
| 3060 | |
| 3061 | /* |
| 3062 | Draw image. |
| 3063 | */ |
| 3064 | image=DestroyImage(image); |
| 3065 | image=(Image *) NULL; |
| 3066 | read_info=CloneImageInfo(image_info); |
| 3067 | SetImageInfoBlob(read_info,(void *) NULL,0); |
| 3068 | if (read_info->density != (char *) NULL) |
| 3069 | read_info->density=DestroyString(read_info->density); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3070 | (void) FormatLocaleString(read_info->filename,MaxTextExtent,"mvg:%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3071 | filename); |
| 3072 | image=ReadImage(read_info,exception); |
| 3073 | read_info=DestroyImageInfo(read_info); |
| 3074 | if (image != (Image *) NULL) |
| 3075 | (void) CopyMagickString(image->filename,image_info->filename, |
| 3076 | MaxTextExtent); |
| 3077 | } |
| 3078 | /* |
| 3079 | Relinquish resources. |
| 3080 | */ |
| 3081 | if (image != (Image *) NULL) |
| 3082 | { |
| 3083 | if (svg_info->title != (char *) NULL) |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 3084 | (void) SetImageProperty(image,"svg:title",svg_info->title,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3085 | if (svg_info->comment != (char *) NULL) |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 3086 | (void) SetImageProperty(image,"svg:comment",svg_info->comment, |
| 3087 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3088 | } |
| 3089 | svg_info=DestroySVGInfo(svg_info); |
| 3090 | (void) RelinquishUniqueFileResource(filename); |
| 3091 | return(GetFirstImageInList(image)); |
| 3092 | } |
| 3093 | #endif |
| 3094 | |
| 3095 | /* |
| 3096 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3097 | % % |
| 3098 | % % |
| 3099 | % % |
| 3100 | % R e g i s t e r S V G I m a g e % |
| 3101 | % % |
| 3102 | % % |
| 3103 | % % |
| 3104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3105 | % |
| 3106 | % RegisterSVGImage() adds attributes for the SVG image format to |
| 3107 | % the list of supported formats. The attributes include the image format |
| 3108 | % tag, a method to read and/or write the format, whether the format |
| 3109 | % supports the saving of more than one frame to the same file or blob, |
| 3110 | % whether the format supports native in-memory I/O, and a brief |
| 3111 | % description of the format. |
| 3112 | % |
| 3113 | % The format of the RegisterSVGImage method is: |
| 3114 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3115 | % size_t RegisterSVGImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3116 | % |
| 3117 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3118 | ModuleExport size_t RegisterSVGImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3119 | { |
| 3120 | char |
| 3121 | version[MaxTextExtent]; |
| 3122 | |
| 3123 | MagickInfo |
| 3124 | *entry; |
| 3125 | |
| 3126 | *version='\0'; |
| 3127 | #if defined(LIBXML_DOTTED_VERSION) |
| 3128 | (void) CopyMagickString(version,"XML " LIBXML_DOTTED_VERSION,MaxTextExtent); |
| 3129 | #endif |
| 3130 | #if defined(MAGICKCORE_RSVG_DELEGATE) |
| 3131 | rsvg_init(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3132 | (void) FormatLocaleString(version,MaxTextExtent,"RSVG %d.%d.%d", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3133 | LIBRSVG_MAJOR_VERSION,LIBRSVG_MINOR_VERSION,LIBRSVG_MICRO_VERSION); |
| 3134 | #endif |
| 3135 | entry=SetMagickInfo("SVG"); |
| 3136 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 3137 | entry->decoder=(DecodeImageHandler *) ReadSVGImage; |
| 3138 | #endif |
| 3139 | entry->encoder=(EncodeImageHandler *) WriteSVGImage; |
| 3140 | entry->blob_support=MagickFalse; |
| 3141 | entry->seekable_stream=MagickFalse; |
| 3142 | entry->description=ConstantString("Scalable Vector Graphics"); |
| 3143 | if (*version != '\0') |
| 3144 | entry->version=ConstantString(version); |
| 3145 | entry->magick=(IsImageFormatHandler *) IsSVG; |
| 3146 | entry->module=ConstantString("SVG"); |
| 3147 | (void) RegisterMagickInfo(entry); |
| 3148 | entry=SetMagickInfo("SVGZ"); |
| 3149 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 3150 | entry->decoder=(DecodeImageHandler *) ReadSVGImage; |
| 3151 | #endif |
| 3152 | entry->encoder=(EncodeImageHandler *) WriteSVGImage; |
| 3153 | entry->blob_support=MagickFalse; |
| 3154 | entry->seekable_stream=MagickFalse; |
| 3155 | entry->description=ConstantString("Compressed Scalable Vector Graphics"); |
| 3156 | if (*version != '\0') |
| 3157 | entry->version=ConstantString(version); |
| 3158 | entry->magick=(IsImageFormatHandler *) IsSVG; |
| 3159 | entry->module=ConstantString("SVG"); |
| 3160 | (void) RegisterMagickInfo(entry); |
| 3161 | entry=SetMagickInfo("MSVG"); |
| 3162 | #if defined(MAGICKCORE_XML_DELEGATE) |
| 3163 | entry->decoder=(DecodeImageHandler *) ReadSVGImage; |
| 3164 | #endif |
| 3165 | entry->encoder=(EncodeImageHandler *) WriteSVGImage; |
| 3166 | entry->blob_support=MagickFalse; |
| 3167 | entry->seekable_stream=MagickFalse; |
| 3168 | entry->description=ConstantString("ImageMagick's own SVG internal renderer"); |
| 3169 | entry->magick=(IsImageFormatHandler *) IsSVG; |
| 3170 | entry->module=ConstantString("SVG"); |
| 3171 | (void) RegisterMagickInfo(entry); |
| 3172 | return(MagickImageCoderSignature); |
| 3173 | } |
| 3174 | |
| 3175 | /* |
| 3176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3177 | % % |
| 3178 | % % |
| 3179 | % % |
| 3180 | % U n r e g i s t e r S V G I m a g e % |
| 3181 | % % |
| 3182 | % % |
| 3183 | % % |
| 3184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3185 | % |
| 3186 | % UnregisterSVGImage() removes format registrations made by the |
| 3187 | % SVG module from the list of supported formats. |
| 3188 | % |
| 3189 | % The format of the UnregisterSVGImage method is: |
| 3190 | % |
| 3191 | % UnregisterSVGImage(void) |
| 3192 | % |
| 3193 | */ |
| 3194 | ModuleExport void UnregisterSVGImage(void) |
| 3195 | { |
| 3196 | (void) UnregisterMagickInfo("SVGZ"); |
| 3197 | (void) UnregisterMagickInfo("SVG"); |
| 3198 | (void) UnregisterMagickInfo("MSVG"); |
| 3199 | #if defined(MAGICKCORE_RSVG_DELEGATE) |
| 3200 | rsvg_term(); |
| 3201 | #endif |
| 3202 | } |
| 3203 | |
| 3204 | /* |
| 3205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3206 | % % |
| 3207 | % % |
| 3208 | % % |
| 3209 | % W r i t e S V G I m a g e % |
| 3210 | % % |
| 3211 | % % |
| 3212 | % % |
| 3213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3214 | % |
| 3215 | % WriteSVGImage() writes a image in the SVG - XML based W3C standard |
| 3216 | % format. |
| 3217 | % |
| 3218 | % The format of the WriteSVGImage method is: |
| 3219 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 3220 | % MagickBooleanType WriteSVGImage(const ImageInfo *image_info, |
| 3221 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3222 | % |
| 3223 | % A description of each parameter follows. |
| 3224 | % |
| 3225 | % o image_info: the image info. |
| 3226 | % |
| 3227 | % o image: The image. |
| 3228 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 3229 | % o exception: return any errors or warnings in this structure. |
| 3230 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3231 | */ |
| 3232 | |
| 3233 | static void AffineToTransform(Image *image,AffineMatrix *affine) |
| 3234 | { |
| 3235 | char |
| 3236 | transform[MaxTextExtent]; |
| 3237 | |
| 3238 | if ((fabs(affine->tx) < MagickEpsilon) && (fabs(affine->ty) < MagickEpsilon)) |
| 3239 | { |
| 3240 | if ((fabs(affine->rx) < MagickEpsilon) && |
| 3241 | (fabs(affine->ry) < MagickEpsilon)) |
| 3242 | { |
| 3243 | if ((fabs(affine->sx-1.0) < MagickEpsilon) && |
| 3244 | (fabs(affine->sy-1.0) < MagickEpsilon)) |
| 3245 | { |
| 3246 | (void) WriteBlobString(image,"\">\n"); |
| 3247 | return; |
| 3248 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3249 | (void) FormatLocaleString(transform,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3250 | "\" transform=\"scale(%g,%g)\">\n",affine->sx,affine->sy); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3251 | (void) WriteBlobString(image,transform); |
| 3252 | return; |
| 3253 | } |
| 3254 | else |
| 3255 | { |
| 3256 | if ((fabs(affine->sx-affine->sy) < MagickEpsilon) && |
| 3257 | (fabs(affine->rx+affine->ry) < MagickEpsilon) && |
| 3258 | (fabs(affine->sx*affine->sx+affine->rx*affine->rx-1.0) < |
| 3259 | 2*MagickEpsilon)) |
| 3260 | { |
| 3261 | double |
| 3262 | theta; |
| 3263 | |
| 3264 | theta=(180.0/MagickPI)*atan2(affine->rx,affine->sx); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3265 | (void) FormatLocaleString(transform,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3266 | "\" transform=\"rotate(%g)\">\n",theta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3267 | (void) WriteBlobString(image,transform); |
| 3268 | return; |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | else |
| 3273 | { |
| 3274 | if ((fabs(affine->sx-1.0) < MagickEpsilon) && |
| 3275 | (fabs(affine->rx) < MagickEpsilon) && |
| 3276 | (fabs(affine->ry) < MagickEpsilon) && |
| 3277 | (fabs(affine->sy-1.0) < MagickEpsilon)) |
| 3278 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3279 | (void) FormatLocaleString(transform,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3280 | "\" transform=\"translate(%g,%g)\">\n",affine->tx,affine->ty); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3281 | (void) WriteBlobString(image,transform); |
| 3282 | return; |
| 3283 | } |
| 3284 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3285 | (void) FormatLocaleString(transform,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3286 | "\" transform=\"matrix(%g %g %g %g %g %g)\">\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 3287 | affine->sx,affine->rx,affine->ry,affine->sy,affine->tx,affine->ty); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3288 | (void) WriteBlobString(image,transform); |
| 3289 | } |
| 3290 | |
| 3291 | static MagickBooleanType IsPoint(const char *point) |
| 3292 | { |
| 3293 | char |
| 3294 | *p; |
| 3295 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3296 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3297 | value; |
| 3298 | |
| 3299 | value=strtol(point,&p,10); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 3300 | (void) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3301 | return(p != point ? MagickTrue : MagickFalse); |
| 3302 | } |
| 3303 | |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3304 | static MagickBooleanType TraceSVGImage(Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3305 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3306 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3307 | y; |
| 3308 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3309 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3310 | *p; |
| 3311 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3312 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3313 | x; |
| 3314 | |
| 3315 | #if defined(MAGICKCORE_AUTOTRACE_DELEGATE) |
| 3316 | { |
| 3317 | at_bitmap_type |
| 3318 | *trace; |
| 3319 | |
| 3320 | at_fitting_opts_type |
| 3321 | *fitting_options; |
| 3322 | |
| 3323 | at_output_opts_type |
| 3324 | *output_options; |
| 3325 | |
| 3326 | at_splines_type |
| 3327 | *splines; |
| 3328 | |
| 3329 | ImageType |
| 3330 | type; |
| 3331 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3332 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3333 | i; |
| 3334 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3335 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3336 | number_planes; |
| 3337 | |
| 3338 | /* |
| 3339 | Trace image and write as SVG. |
| 3340 | */ |
| 3341 | fitting_options=at_fitting_opts_new(); |
| 3342 | output_options=at_output_opts_new(); |
| 3343 | type=GetImageType(image,&image->exception); |
| 3344 | number_planes=3; |
| 3345 | if ((type == BilevelType) || (type == GrayscaleType)) |
| 3346 | number_planes=1; |
| 3347 | trace=at_bitmap_new(image->columns,image->rows,number_planes); |
| 3348 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3349 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3350 | { |
| 3351 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3352 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3353 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3354 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3355 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3356 | trace->bitmap[i++]=GetPixelRed(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3357 | if (number_planes == 3) |
| 3358 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3359 | trace->bitmap[i++]=GetPixelGreen(image,p); |
| 3360 | trace->bitmap[i++]=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3361 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3362 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | splines=at_splines_new_full(trace,fitting_options,NULL,NULL,NULL,NULL,NULL, |
| 3366 | NULL); |
| 3367 | at_splines_write(at_output_get_handler_by_suffix((char *) "svg"), |
| 3368 | GetBlobFileHandle(image),image->filename,output_options,splines,NULL, |
| 3369 | NULL); |
| 3370 | /* |
| 3371 | Free resources. |
| 3372 | */ |
| 3373 | at_splines_free(splines); |
| 3374 | at_bitmap_free(trace); |
| 3375 | at_output_opts_free(output_options); |
| 3376 | at_fitting_opts_free(fitting_options); |
| 3377 | } |
| 3378 | #else |
| 3379 | { |
| 3380 | char |
| 3381 | message[MaxTextExtent], |
| 3382 | tuple[MaxTextExtent]; |
| 3383 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3384 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3385 | pixel; |
| 3386 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3387 | (void) WriteBlobString(image,"<?xml version=\"1.0\" standalone=\"no\"?>\n"); |
| 3388 | (void) WriteBlobString(image, |
| 3389 | "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"); |
| 3390 | (void) WriteBlobString(image, |
| 3391 | " \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3392 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3393 | "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) image->columns, |
| 3394 | (double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3395 | (void) WriteBlobString(image,message); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3396 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3397 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3398 | { |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3399 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3400 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3401 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3402 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3403 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3404 | SetPixelInfo(image,p,&pixel); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3405 | (void) QueryColorname(image,&pixel,SVGCompliance,tuple,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3406 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3407 | " <circle cx=\"%.20g\" cy=\"%.20g\" r=\"1\" fill=\"%s\"/>\n", |
| 3408 | (double) x,(double) y,tuple); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3409 | (void) WriteBlobString(image,message); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3410 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | (void) WriteBlobString(image,"</svg>\n"); |
| 3414 | } |
| 3415 | #endif |
| 3416 | return(MagickTrue); |
| 3417 | } |
| 3418 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 3419 | static MagickBooleanType WriteSVGImage(const ImageInfo *image_info,Image *image, |
| 3420 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3421 | { |
| 3422 | #define BezierQuantum 200 |
| 3423 | |
| 3424 | AffineMatrix |
| 3425 | affine; |
| 3426 | |
| 3427 | char |
| 3428 | keyword[MaxTextExtent], |
| 3429 | message[MaxTextExtent], |
| 3430 | name[MaxTextExtent], |
| 3431 | *token, |
| 3432 | type[MaxTextExtent]; |
| 3433 | |
| 3434 | const char |
| 3435 | *p, |
| 3436 | *q, |
| 3437 | *value; |
| 3438 | |
| 3439 | int |
| 3440 | n; |
| 3441 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3442 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3443 | j; |
| 3444 | |
| 3445 | MagickBooleanType |
| 3446 | active, |
| 3447 | status; |
| 3448 | |
| 3449 | PointInfo |
| 3450 | point; |
| 3451 | |
| 3452 | PrimitiveInfo |
| 3453 | *primitive_info; |
| 3454 | |
| 3455 | PrimitiveType |
| 3456 | primitive_type; |
| 3457 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3458 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3459 | x; |
| 3460 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3461 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3462 | i; |
| 3463 | |
| 3464 | size_t |
| 3465 | length; |
| 3466 | |
| 3467 | SVGInfo |
| 3468 | svg_info; |
| 3469 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3470 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3471 | number_points; |
| 3472 | |
| 3473 | /* |
| 3474 | Open output image file. |
| 3475 | */ |
| 3476 | assert(image_info != (const ImageInfo *) NULL); |
| 3477 | assert(image_info->signature == MagickSignature); |
| 3478 | assert(image != (Image *) NULL); |
| 3479 | assert(image->signature == MagickSignature); |
| 3480 | if (image->debug != MagickFalse) |
| 3481 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 3482 | assert(exception != (ExceptionInfo *) NULL); |
| 3483 | assert(exception->signature == MagickSignature); |
| 3484 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3485 | if (status == MagickFalse) |
| 3486 | return(status); |
| 3487 | value=GetImageArtifact(image,"SVG"); |
| 3488 | if (value != (char *) NULL) |
| 3489 | { |
| 3490 | (void) WriteBlobString(image,value); |
| 3491 | (void) CloseBlob(image); |
| 3492 | return(MagickTrue); |
| 3493 | } |
| 3494 | value=GetImageArtifact(image,"MVG"); |
| 3495 | if (value == (char *) NULL) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3496 | return(TraceSVGImage(image,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3497 | /* |
| 3498 | Write SVG header. |
| 3499 | */ |
| 3500 | (void) WriteBlobString(image,"<?xml version=\"1.0\" standalone=\"no\"?>\n"); |
| 3501 | (void) WriteBlobString(image, |
| 3502 | "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"); |
| 3503 | (void) WriteBlobString(image, |
| 3504 | " \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3505 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 3506 | "<svg width=\"%.20g\" height=\"%.20g\">\n",(double) image->columns,(double) |
| 3507 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3508 | (void) WriteBlobString(image,message); |
| 3509 | /* |
| 3510 | Allocate primitive info memory. |
| 3511 | */ |
| 3512 | number_points=2047; |
| 3513 | primitive_info=(PrimitiveInfo *) AcquireQuantumMemory(number_points, |
| 3514 | sizeof(*primitive_info)); |
| 3515 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 3516 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 3517 | GetAffineMatrix(&affine); |
| 3518 | token=AcquireString(value); |
| 3519 | active=MagickFalse; |
| 3520 | n=0; |
| 3521 | status=MagickTrue; |
| 3522 | for (q=(const char *) value; *q != '\0'; ) |
| 3523 | { |
| 3524 | /* |
| 3525 | Interpret graphic primitive. |
| 3526 | */ |
| 3527 | GetMagickToken(q,&q,keyword); |
| 3528 | if (*keyword == '\0') |
| 3529 | break; |
| 3530 | if (*keyword == '#') |
| 3531 | { |
| 3532 | /* |
| 3533 | Comment. |
| 3534 | */ |
| 3535 | if (active != MagickFalse) |
| 3536 | { |
| 3537 | AffineToTransform(image,&affine); |
| 3538 | active=MagickFalse; |
| 3539 | } |
| 3540 | (void) WriteBlobString(image,"<desc>"); |
| 3541 | (void) WriteBlobString(image,keyword+1); |
| 3542 | for ( ; (*q != '\n') && (*q != '\0'); q++) |
| 3543 | switch (*q) |
| 3544 | { |
| 3545 | case '<': (void) WriteBlobString(image,"<"); break; |
| 3546 | case '>': (void) WriteBlobString(image,">"); break; |
| 3547 | case '&': (void) WriteBlobString(image,"&"); break; |
| 3548 | default: (void) WriteBlobByte(image,*q); break; |
| 3549 | } |
| 3550 | (void) WriteBlobString(image,"</desc>\n"); |
| 3551 | continue; |
| 3552 | } |
| 3553 | primitive_type=UndefinedPrimitive; |
| 3554 | switch (*keyword) |
| 3555 | { |
| 3556 | case ';': |
| 3557 | break; |
| 3558 | case 'a': |
| 3559 | case 'A': |
| 3560 | { |
| 3561 | if (LocaleCompare("affine",keyword) == 0) |
| 3562 | { |
| 3563 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3564 | affine.sx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3565 | GetMagickToken(q,&q,token); |
| 3566 | if (*token == ',') |
| 3567 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3568 | affine.rx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3569 | GetMagickToken(q,&q,token); |
| 3570 | if (*token == ',') |
| 3571 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3572 | affine.ry=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3573 | GetMagickToken(q,&q,token); |
| 3574 | if (*token == ',') |
| 3575 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3576 | affine.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3577 | GetMagickToken(q,&q,token); |
| 3578 | if (*token == ',') |
| 3579 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3580 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3581 | GetMagickToken(q,&q,token); |
| 3582 | if (*token == ',') |
| 3583 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3584 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3585 | break; |
| 3586 | } |
| 3587 | if (LocaleCompare("angle",keyword) == 0) |
| 3588 | { |
| 3589 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3590 | affine.rx=InterpretLocaleValue(token,(char **) NULL); |
| 3591 | affine.ry=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3592 | break; |
| 3593 | } |
| 3594 | if (LocaleCompare("arc",keyword) == 0) |
| 3595 | { |
| 3596 | primitive_type=ArcPrimitive; |
| 3597 | break; |
| 3598 | } |
| 3599 | status=MagickFalse; |
| 3600 | break; |
| 3601 | } |
| 3602 | case 'b': |
| 3603 | case 'B': |
| 3604 | { |
| 3605 | if (LocaleCompare("bezier",keyword) == 0) |
| 3606 | { |
| 3607 | primitive_type=BezierPrimitive; |
| 3608 | break; |
| 3609 | } |
| 3610 | status=MagickFalse; |
| 3611 | break; |
| 3612 | } |
| 3613 | case 'c': |
| 3614 | case 'C': |
| 3615 | { |
| 3616 | if (LocaleCompare("clip-path",keyword) == 0) |
| 3617 | { |
| 3618 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3619 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3620 | "clip-path:url(#%s);",token); |
| 3621 | (void) WriteBlobString(image,message); |
| 3622 | break; |
| 3623 | } |
| 3624 | if (LocaleCompare("clip-rule",keyword) == 0) |
| 3625 | { |
| 3626 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3627 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3628 | "clip-rule:%s;",token); |
| 3629 | (void) WriteBlobString(image,message); |
| 3630 | break; |
| 3631 | } |
| 3632 | if (LocaleCompare("clip-units",keyword) == 0) |
| 3633 | { |
| 3634 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3635 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3636 | "clipPathUnits=%s;",token); |
| 3637 | (void) WriteBlobString(image,message); |
| 3638 | break; |
| 3639 | } |
| 3640 | if (LocaleCompare("circle",keyword) == 0) |
| 3641 | { |
| 3642 | primitive_type=CirclePrimitive; |
| 3643 | break; |
| 3644 | } |
| 3645 | if (LocaleCompare("color",keyword) == 0) |
| 3646 | { |
| 3647 | primitive_type=ColorPrimitive; |
| 3648 | break; |
| 3649 | } |
| 3650 | status=MagickFalse; |
| 3651 | break; |
| 3652 | } |
| 3653 | case 'd': |
| 3654 | case 'D': |
| 3655 | { |
| 3656 | if (LocaleCompare("decorate",keyword) == 0) |
| 3657 | { |
| 3658 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3659 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3660 | "text-decoration:%s;",token); |
| 3661 | (void) WriteBlobString(image,message); |
| 3662 | break; |
| 3663 | } |
| 3664 | status=MagickFalse; |
| 3665 | break; |
| 3666 | } |
| 3667 | case 'e': |
| 3668 | case 'E': |
| 3669 | { |
| 3670 | if (LocaleCompare("ellipse",keyword) == 0) |
| 3671 | { |
| 3672 | primitive_type=EllipsePrimitive; |
| 3673 | break; |
| 3674 | } |
| 3675 | status=MagickFalse; |
| 3676 | break; |
| 3677 | } |
| 3678 | case 'f': |
| 3679 | case 'F': |
| 3680 | { |
| 3681 | if (LocaleCompare("fill",keyword) == 0) |
| 3682 | { |
| 3683 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3684 | (void) FormatLocaleString(message,MaxTextExtent,"fill:%s;", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3685 | token); |
| 3686 | (void) WriteBlobString(image,message); |
| 3687 | break; |
| 3688 | } |
| 3689 | if (LocaleCompare("fill-rule",keyword) == 0) |
| 3690 | { |
| 3691 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3692 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3693 | "fill-rule:%s;",token); |
| 3694 | (void) WriteBlobString(image,message); |
| 3695 | break; |
| 3696 | } |
| 3697 | if (LocaleCompare("fill-opacity",keyword) == 0) |
| 3698 | { |
| 3699 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3700 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3701 | "fill-opacity:%s;",token); |
| 3702 | (void) WriteBlobString(image,message); |
| 3703 | break; |
| 3704 | } |
| 3705 | if (LocaleCompare("font-family",keyword) == 0) |
| 3706 | { |
| 3707 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3708 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3709 | "font-family:%s;",token); |
| 3710 | (void) WriteBlobString(image,message); |
| 3711 | break; |
| 3712 | } |
| 3713 | if (LocaleCompare("font-stretch",keyword) == 0) |
| 3714 | { |
| 3715 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3716 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3717 | "font-stretch:%s;",token); |
| 3718 | (void) WriteBlobString(image,message); |
| 3719 | break; |
| 3720 | } |
| 3721 | if (LocaleCompare("font-style",keyword) == 0) |
| 3722 | { |
| 3723 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3724 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3725 | "font-style:%s;",token); |
| 3726 | (void) WriteBlobString(image,message); |
| 3727 | break; |
| 3728 | } |
| 3729 | if (LocaleCompare("font-size",keyword) == 0) |
| 3730 | { |
| 3731 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3732 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3733 | "font-size:%s;",token); |
| 3734 | (void) WriteBlobString(image,message); |
| 3735 | break; |
| 3736 | } |
| 3737 | if (LocaleCompare("font-weight",keyword) == 0) |
| 3738 | { |
| 3739 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3740 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3741 | "font-weight:%s;",token); |
| 3742 | (void) WriteBlobString(image,message); |
| 3743 | break; |
| 3744 | } |
| 3745 | status=MagickFalse; |
| 3746 | break; |
| 3747 | } |
| 3748 | case 'g': |
| 3749 | case 'G': |
| 3750 | { |
| 3751 | if (LocaleCompare("gradient-units",keyword) == 0) |
| 3752 | { |
| 3753 | GetMagickToken(q,&q,token); |
| 3754 | break; |
| 3755 | } |
| 3756 | if (LocaleCompare("text-align",keyword) == 0) |
| 3757 | { |
| 3758 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3759 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3760 | "text-align %s ",token); |
| 3761 | (void) WriteBlobString(image,message); |
| 3762 | break; |
| 3763 | } |
| 3764 | if (LocaleCompare("text-anchor",keyword) == 0) |
| 3765 | { |
| 3766 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3767 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3768 | "text-anchor %s ",token); |
| 3769 | (void) WriteBlobString(image,message); |
| 3770 | break; |
| 3771 | } |
| 3772 | status=MagickFalse; |
| 3773 | break; |
| 3774 | } |
| 3775 | case 'i': |
| 3776 | case 'I': |
| 3777 | { |
| 3778 | if (LocaleCompare("image",keyword) == 0) |
| 3779 | { |
| 3780 | GetMagickToken(q,&q,token); |
| 3781 | primitive_type=ImagePrimitive; |
| 3782 | break; |
| 3783 | } |
| 3784 | status=MagickFalse; |
| 3785 | break; |
| 3786 | } |
| 3787 | case 'l': |
| 3788 | case 'L': |
| 3789 | { |
| 3790 | if (LocaleCompare("line",keyword) == 0) |
| 3791 | { |
| 3792 | primitive_type=LinePrimitive; |
| 3793 | break; |
| 3794 | } |
| 3795 | status=MagickFalse; |
| 3796 | break; |
| 3797 | } |
| 3798 | case 'm': |
| 3799 | case 'M': |
| 3800 | { |
| 3801 | if (LocaleCompare("matte",keyword) == 0) |
| 3802 | { |
| 3803 | primitive_type=MattePrimitive; |
| 3804 | break; |
| 3805 | } |
| 3806 | status=MagickFalse; |
| 3807 | break; |
| 3808 | } |
| 3809 | case 'o': |
| 3810 | case 'O': |
| 3811 | { |
| 3812 | if (LocaleCompare("opacity",keyword) == 0) |
| 3813 | { |
| 3814 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3815 | (void) FormatLocaleString(message,MaxTextExtent,"opacity %s ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3816 | token); |
| 3817 | (void) WriteBlobString(image,message); |
| 3818 | break; |
| 3819 | } |
| 3820 | status=MagickFalse; |
| 3821 | break; |
| 3822 | } |
| 3823 | case 'p': |
| 3824 | case 'P': |
| 3825 | { |
| 3826 | if (LocaleCompare("path",keyword) == 0) |
| 3827 | { |
| 3828 | primitive_type=PathPrimitive; |
| 3829 | break; |
| 3830 | } |
| 3831 | if (LocaleCompare("point",keyword) == 0) |
| 3832 | { |
| 3833 | primitive_type=PointPrimitive; |
| 3834 | break; |
| 3835 | } |
| 3836 | if (LocaleCompare("polyline",keyword) == 0) |
| 3837 | { |
| 3838 | primitive_type=PolylinePrimitive; |
| 3839 | break; |
| 3840 | } |
| 3841 | if (LocaleCompare("polygon",keyword) == 0) |
| 3842 | { |
| 3843 | primitive_type=PolygonPrimitive; |
| 3844 | break; |
| 3845 | } |
| 3846 | if (LocaleCompare("pop",keyword) == 0) |
| 3847 | { |
| 3848 | GetMagickToken(q,&q,token); |
| 3849 | if (LocaleCompare("clip-path",token) == 0) |
| 3850 | { |
| 3851 | (void) WriteBlobString(image,"</clipPath>\n"); |
| 3852 | break; |
| 3853 | } |
| 3854 | if (LocaleCompare("defs",token) == 0) |
| 3855 | { |
| 3856 | (void) WriteBlobString(image,"</defs>\n"); |
| 3857 | break; |
| 3858 | } |
| 3859 | if (LocaleCompare("gradient",token) == 0) |
| 3860 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3861 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3862 | "</%sGradient>\n",type); |
| 3863 | (void) WriteBlobString(image,message); |
| 3864 | break; |
| 3865 | } |
| 3866 | if (LocaleCompare("graphic-context",token) == 0) |
| 3867 | { |
| 3868 | n--; |
| 3869 | if (n < 0) |
| 3870 | ThrowWriterException(DrawError, |
| 3871 | "UnbalancedGraphicContextPushPop"); |
| 3872 | (void) WriteBlobString(image,"</g>\n"); |
| 3873 | } |
| 3874 | if (LocaleCompare("pattern",token) == 0) |
| 3875 | { |
| 3876 | (void) WriteBlobString(image,"</pattern>\n"); |
| 3877 | break; |
| 3878 | } |
| 3879 | if (LocaleCompare("defs",token) == 0) |
| 3880 | (void) WriteBlobString(image,"</g>\n"); |
| 3881 | break; |
| 3882 | } |
| 3883 | if (LocaleCompare("push",keyword) == 0) |
| 3884 | { |
| 3885 | GetMagickToken(q,&q,token); |
| 3886 | if (LocaleCompare("clip-path",token) == 0) |
| 3887 | { |
| 3888 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3889 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3890 | "<clipPath id=\"%s\">\n",token); |
| 3891 | (void) WriteBlobString(image,message); |
| 3892 | break; |
| 3893 | } |
| 3894 | if (LocaleCompare("defs",token) == 0) |
| 3895 | { |
| 3896 | (void) WriteBlobString(image,"<defs>\n"); |
| 3897 | break; |
| 3898 | } |
| 3899 | if (LocaleCompare("gradient",token) == 0) |
| 3900 | { |
| 3901 | GetMagickToken(q,&q,token); |
| 3902 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 3903 | GetMagickToken(q,&q,token); |
| 3904 | (void) CopyMagickString(type,token,MaxTextExtent); |
| 3905 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3906 | svg_info.segment.x1=InterpretLocaleValue(token,(char **) NULL); |
| 3907 | svg_info.element.cx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3908 | GetMagickToken(q,&q,token); |
| 3909 | if (*token == ',') |
| 3910 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3911 | svg_info.segment.y1=InterpretLocaleValue(token,(char **) NULL); |
| 3912 | svg_info.element.cy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3913 | GetMagickToken(q,&q,token); |
| 3914 | if (*token == ',') |
| 3915 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3916 | svg_info.segment.x2=InterpretLocaleValue(token,(char **) NULL); |
| 3917 | svg_info.element.major=InterpretLocaleValue(token, |
| 3918 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3919 | GetMagickToken(q,&q,token); |
| 3920 | if (*token == ',') |
| 3921 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3922 | svg_info.segment.y2=InterpretLocaleValue(token,(char **) NULL); |
| 3923 | svg_info.element.minor=InterpretLocaleValue(token, |
| 3924 | (char **) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3925 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3926 | "<%sGradient id=\"%s\" x1=\"%g\" y1=\"%g\" x2=\"%g\" " |
| 3927 | "y2=\"%g\">\n",type,name,svg_info.segment.x1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3928 | svg_info.segment.y1,svg_info.segment.x2,svg_info.segment.y2); |
| 3929 | if (LocaleCompare(type,"radial") == 0) |
| 3930 | { |
| 3931 | GetMagickToken(q,&q,token); |
| 3932 | if (*token == ',') |
| 3933 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3934 | svg_info.element.angle=InterpretLocaleValue(token, |
| 3935 | (char **) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3936 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3937 | "<%sGradient id=\"%s\" cx=\"%g\" cy=\"%g\" r=\"%g\" " |
| 3938 | "fx=\"%g\" fy=\"%g\">\n",type,name, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 3939 | svg_info.element.cx,svg_info.element.cy, |
| 3940 | svg_info.element.angle,svg_info.element.major, |
| 3941 | svg_info.element.minor); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3942 | } |
| 3943 | (void) WriteBlobString(image,message); |
| 3944 | break; |
| 3945 | } |
| 3946 | if (LocaleCompare("graphic-context",token) == 0) |
| 3947 | { |
| 3948 | n++; |
| 3949 | if (active) |
| 3950 | { |
| 3951 | AffineToTransform(image,&affine); |
| 3952 | active=MagickFalse; |
| 3953 | } |
| 3954 | (void) WriteBlobString(image,"<g style=\""); |
| 3955 | active=MagickTrue; |
| 3956 | } |
| 3957 | if (LocaleCompare("pattern",token) == 0) |
| 3958 | { |
| 3959 | GetMagickToken(q,&q,token); |
| 3960 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 3961 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3962 | svg_info.bounds.x=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3963 | GetMagickToken(q,&q,token); |
| 3964 | if (*token == ',') |
| 3965 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3966 | svg_info.bounds.y=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3967 | GetMagickToken(q,&q,token); |
| 3968 | if (*token == ',') |
| 3969 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3970 | svg_info.bounds.width=InterpretLocaleValue(token, |
| 3971 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3972 | GetMagickToken(q,&q,token); |
| 3973 | if (*token == ',') |
| 3974 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 3975 | svg_info.bounds.height=InterpretLocaleValue(token, |
| 3976 | (char **) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3977 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 3978 | "<pattern id=\"%s\" x=\"%g\" y=\"%g\" width=\"%g\" " |
| 3979 | "height=\"%g\">\n",name,svg_info.bounds.x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 3980 | svg_info.bounds.y,svg_info.bounds.width, |
| 3981 | svg_info.bounds.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3982 | (void) WriteBlobString(image,message); |
| 3983 | break; |
| 3984 | } |
| 3985 | break; |
| 3986 | } |
| 3987 | status=MagickFalse; |
| 3988 | break; |
| 3989 | } |
| 3990 | case 'r': |
| 3991 | case 'R': |
| 3992 | { |
| 3993 | if (LocaleCompare("rectangle",keyword) == 0) |
| 3994 | { |
| 3995 | primitive_type=RectanglePrimitive; |
| 3996 | break; |
| 3997 | } |
| 3998 | if (LocaleCompare("roundRectangle",keyword) == 0) |
| 3999 | { |
| 4000 | primitive_type=RoundRectanglePrimitive; |
| 4001 | break; |
| 4002 | } |
| 4003 | if (LocaleCompare("rotate",keyword) == 0) |
| 4004 | { |
| 4005 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4006 | (void) FormatLocaleString(message,MaxTextExtent,"rotate(%s) ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4007 | token); |
| 4008 | (void) WriteBlobString(image,message); |
| 4009 | break; |
| 4010 | } |
| 4011 | status=MagickFalse; |
| 4012 | break; |
| 4013 | } |
| 4014 | case 's': |
| 4015 | case 'S': |
| 4016 | { |
| 4017 | if (LocaleCompare("scale",keyword) == 0) |
| 4018 | { |
| 4019 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4020 | affine.sx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4021 | GetMagickToken(q,&q,token); |
| 4022 | if (*token == ',') |
| 4023 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4024 | affine.sy=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4025 | break; |
| 4026 | } |
| 4027 | if (LocaleCompare("skewX",keyword) == 0) |
| 4028 | { |
| 4029 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4030 | (void) FormatLocaleString(message,MaxTextExtent,"skewX(%s) ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4031 | token); |
| 4032 | (void) WriteBlobString(image,message); |
| 4033 | break; |
| 4034 | } |
| 4035 | if (LocaleCompare("skewY",keyword) == 0) |
| 4036 | { |
| 4037 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4038 | (void) FormatLocaleString(message,MaxTextExtent,"skewY(%s) ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4039 | token); |
| 4040 | (void) WriteBlobString(image,message); |
| 4041 | break; |
| 4042 | } |
| 4043 | if (LocaleCompare("stop-color",keyword) == 0) |
| 4044 | { |
| 4045 | char |
| 4046 | color[MaxTextExtent]; |
| 4047 | |
| 4048 | GetMagickToken(q,&q,token); |
| 4049 | (void) CopyMagickString(color,token,MaxTextExtent); |
| 4050 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4051 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4052 | " <stop offset=\"%s\" stop-color=\"%s\" />\n",token,color); |
| 4053 | (void) WriteBlobString(image,message); |
| 4054 | break; |
| 4055 | } |
| 4056 | if (LocaleCompare("stroke",keyword) == 0) |
| 4057 | { |
| 4058 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4059 | (void) FormatLocaleString(message,MaxTextExtent,"stroke:%s;", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4060 | token); |
| 4061 | (void) WriteBlobString(image,message); |
| 4062 | break; |
| 4063 | } |
| 4064 | if (LocaleCompare("stroke-antialias",keyword) == 0) |
| 4065 | { |
| 4066 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4067 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4068 | "stroke-antialias:%s;",token); |
| 4069 | (void) WriteBlobString(image,message); |
| 4070 | break; |
| 4071 | } |
| 4072 | if (LocaleCompare("stroke-dasharray",keyword) == 0) |
| 4073 | { |
| 4074 | if (IsPoint(q)) |
| 4075 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4076 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4077 | k; |
| 4078 | |
| 4079 | p=q; |
| 4080 | GetMagickToken(p,&p,token); |
| 4081 | for (k=0; IsPoint(token); k++) |
| 4082 | GetMagickToken(p,&p,token); |
| 4083 | (void) WriteBlobString(image,"stroke-dasharray:"); |
| 4084 | for (j=0; j < k; j++) |
| 4085 | { |
| 4086 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4087 | (void) FormatLocaleString(message,MaxTextExtent,"%s ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4088 | token); |
| 4089 | (void) WriteBlobString(image,message); |
| 4090 | } |
| 4091 | (void) WriteBlobString(image,";"); |
| 4092 | break; |
| 4093 | } |
| 4094 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4095 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4096 | "stroke-dasharray:%s;",token); |
| 4097 | (void) WriteBlobString(image,message); |
| 4098 | break; |
| 4099 | } |
| 4100 | if (LocaleCompare("stroke-dashoffset",keyword) == 0) |
| 4101 | { |
| 4102 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4103 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4104 | "stroke-dashoffset:%s;",token); |
| 4105 | (void) WriteBlobString(image,message); |
| 4106 | break; |
| 4107 | } |
| 4108 | if (LocaleCompare("stroke-linecap",keyword) == 0) |
| 4109 | { |
| 4110 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4111 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4112 | "stroke-linecap:%s;",token); |
| 4113 | (void) WriteBlobString(image,message); |
| 4114 | break; |
| 4115 | } |
| 4116 | if (LocaleCompare("stroke-linejoin",keyword) == 0) |
| 4117 | { |
| 4118 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4119 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4120 | "stroke-linejoin:%s;",token); |
| 4121 | (void) WriteBlobString(image,message); |
| 4122 | break; |
| 4123 | } |
| 4124 | if (LocaleCompare("stroke-miterlimit",keyword) == 0) |
| 4125 | { |
| 4126 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4127 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4128 | "stroke-miterlimit:%s;",token); |
| 4129 | (void) WriteBlobString(image,message); |
| 4130 | break; |
| 4131 | } |
| 4132 | if (LocaleCompare("stroke-opacity",keyword) == 0) |
| 4133 | { |
| 4134 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4135 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4136 | "stroke-opacity:%s;",token); |
| 4137 | (void) WriteBlobString(image,message); |
| 4138 | break; |
| 4139 | } |
| 4140 | if (LocaleCompare("stroke-width",keyword) == 0) |
| 4141 | { |
| 4142 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4143 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4144 | "stroke-width:%s;",token); |
| 4145 | (void) WriteBlobString(image,message); |
| 4146 | continue; |
| 4147 | } |
| 4148 | status=MagickFalse; |
| 4149 | break; |
| 4150 | } |
| 4151 | case 't': |
| 4152 | case 'T': |
| 4153 | { |
| 4154 | if (LocaleCompare("text",keyword) == 0) |
| 4155 | { |
| 4156 | primitive_type=TextPrimitive; |
| 4157 | break; |
| 4158 | } |
| 4159 | if (LocaleCompare("text-antialias",keyword) == 0) |
| 4160 | { |
| 4161 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4162 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4163 | "text-antialias:%s;",token); |
| 4164 | (void) WriteBlobString(image,message); |
| 4165 | break; |
| 4166 | } |
| 4167 | if (LocaleCompare("tspan",keyword) == 0) |
| 4168 | { |
| 4169 | primitive_type=TextPrimitive; |
| 4170 | break; |
| 4171 | } |
| 4172 | if (LocaleCompare("translate",keyword) == 0) |
| 4173 | { |
| 4174 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4175 | affine.tx=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4176 | GetMagickToken(q,&q,token); |
| 4177 | if (*token == ',') |
| 4178 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4179 | affine.ty=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4180 | break; |
| 4181 | } |
| 4182 | status=MagickFalse; |
| 4183 | break; |
| 4184 | } |
| 4185 | case 'v': |
| 4186 | case 'V': |
| 4187 | { |
| 4188 | if (LocaleCompare("viewbox",keyword) == 0) |
| 4189 | { |
| 4190 | GetMagickToken(q,&q,token); |
| 4191 | if (*token == ',') |
| 4192 | GetMagickToken(q,&q,token); |
| 4193 | GetMagickToken(q,&q,token); |
| 4194 | if (*token == ',') |
| 4195 | GetMagickToken(q,&q,token); |
| 4196 | GetMagickToken(q,&q,token); |
| 4197 | if (*token == ',') |
| 4198 | GetMagickToken(q,&q,token); |
| 4199 | GetMagickToken(q,&q,token); |
| 4200 | break; |
| 4201 | } |
| 4202 | status=MagickFalse; |
| 4203 | break; |
| 4204 | } |
| 4205 | default: |
| 4206 | { |
| 4207 | status=MagickFalse; |
| 4208 | break; |
| 4209 | } |
| 4210 | } |
| 4211 | if (status == MagickFalse) |
| 4212 | break; |
| 4213 | if (primitive_type == UndefinedPrimitive) |
| 4214 | continue; |
| 4215 | /* |
| 4216 | Parse the primitive attributes. |
| 4217 | */ |
| 4218 | i=0; |
| 4219 | j=0; |
| 4220 | for (x=0; *q != '\0'; x++) |
| 4221 | { |
| 4222 | /* |
| 4223 | Define points. |
| 4224 | */ |
| 4225 | if (IsPoint(q) == MagickFalse) |
| 4226 | break; |
| 4227 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4228 | point.x=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4229 | GetMagickToken(q,&q,token); |
| 4230 | if (*token == ',') |
| 4231 | GetMagickToken(q,&q,token); |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 4232 | point.y=InterpretLocaleValue(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4233 | GetMagickToken(q,(const char **) NULL,token); |
| 4234 | if (*token == ',') |
| 4235 | GetMagickToken(q,&q,token); |
| 4236 | primitive_info[i].primitive=primitive_type; |
| 4237 | primitive_info[i].point=point; |
| 4238 | primitive_info[i].coordinates=0; |
| 4239 | primitive_info[i].method=FloodfillMethod; |
| 4240 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4241 | if (i < (ssize_t) (number_points-6*BezierQuantum-360)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4242 | continue; |
| 4243 | number_points+=6*BezierQuantum+360; |
| 4244 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 4245 | number_points,sizeof(*primitive_info)); |
| 4246 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 4247 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 4248 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4249 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 4250 | break; |
| 4251 | } |
| 4252 | } |
| 4253 | primitive_info[j].primitive=primitive_type; |
| 4254 | primitive_info[j].coordinates=x; |
| 4255 | primitive_info[j].method=FloodfillMethod; |
| 4256 | primitive_info[j].text=(char *) NULL; |
| 4257 | if (active) |
| 4258 | { |
| 4259 | AffineToTransform(image,&affine); |
| 4260 | active=MagickFalse; |
| 4261 | } |
| 4262 | active=MagickFalse; |
| 4263 | switch (primitive_type) |
| 4264 | { |
| 4265 | case PointPrimitive: |
| 4266 | default: |
| 4267 | { |
| 4268 | if (primitive_info[j].coordinates != 1) |
| 4269 | { |
| 4270 | status=MagickFalse; |
| 4271 | break; |
| 4272 | } |
| 4273 | break; |
| 4274 | } |
| 4275 | case LinePrimitive: |
| 4276 | { |
| 4277 | if (primitive_info[j].coordinates != 2) |
| 4278 | { |
| 4279 | status=MagickFalse; |
| 4280 | break; |
| 4281 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4282 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4283 | " <line x1=\"%g\" y1=\"%g\" x2=\"%g\" y2=\"%g\"/>\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4284 | primitive_info[j].point.x,primitive_info[j].point.y, |
| 4285 | primitive_info[j+1].point.x,primitive_info[j+1].point.y); |
| 4286 | (void) WriteBlobString(image,message); |
| 4287 | break; |
| 4288 | } |
| 4289 | case RectanglePrimitive: |
| 4290 | { |
| 4291 | if (primitive_info[j].coordinates != 2) |
| 4292 | { |
| 4293 | status=MagickFalse; |
| 4294 | break; |
| 4295 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4296 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4297 | " <rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\"/>\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4298 | primitive_info[j].point.x,primitive_info[j].point.y, |
| 4299 | primitive_info[j+1].point.x-primitive_info[j].point.x, |
| 4300 | primitive_info[j+1].point.y-primitive_info[j].point.y); |
| 4301 | (void) WriteBlobString(image,message); |
| 4302 | break; |
| 4303 | } |
| 4304 | case RoundRectanglePrimitive: |
| 4305 | { |
| 4306 | if (primitive_info[j].coordinates != 3) |
| 4307 | { |
| 4308 | status=MagickFalse; |
| 4309 | break; |
| 4310 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4311 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4312 | " <rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" " |
| 4313 | "ry=\"%g\"/>\n",primitive_info[j].point.x, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 4314 | primitive_info[j].point.y,primitive_info[j+1].point.x- |
| 4315 | primitive_info[j].point.x,primitive_info[j+1].point.y- |
| 4316 | primitive_info[j].point.y,primitive_info[j+2].point.x, |
| 4317 | primitive_info[j+2].point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4318 | (void) WriteBlobString(image,message); |
| 4319 | break; |
| 4320 | } |
| 4321 | case ArcPrimitive: |
| 4322 | { |
| 4323 | if (primitive_info[j].coordinates != 3) |
| 4324 | { |
| 4325 | status=MagickFalse; |
| 4326 | break; |
| 4327 | } |
| 4328 | break; |
| 4329 | } |
| 4330 | case EllipsePrimitive: |
| 4331 | { |
| 4332 | if (primitive_info[j].coordinates != 3) |
| 4333 | { |
| 4334 | status=MagickFalse; |
| 4335 | break; |
| 4336 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4337 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4338 | " <ellipse cx=\"%g\" cy=\"%g\" rx=\"%g\" ry=\"%g\"/>\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4339 | primitive_info[j].point.x,primitive_info[j].point.y, |
| 4340 | primitive_info[j+1].point.x,primitive_info[j+1].point.y); |
| 4341 | (void) WriteBlobString(image,message); |
| 4342 | break; |
| 4343 | } |
| 4344 | case CirclePrimitive: |
| 4345 | { |
| 4346 | double |
| 4347 | alpha, |
| 4348 | beta; |
| 4349 | |
| 4350 | if (primitive_info[j].coordinates != 2) |
| 4351 | { |
| 4352 | status=MagickFalse; |
| 4353 | break; |
| 4354 | } |
| 4355 | alpha=primitive_info[j+1].point.x-primitive_info[j].point.x; |
| 4356 | beta=primitive_info[j+1].point.y-primitive_info[j].point.y; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4357 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4358 | " <circle cx=\"%g\" cy=\"%g\" r=\"%g\"/>\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4359 | primitive_info[j].point.x,primitive_info[j].point.y, |
| 4360 | hypot(alpha,beta)); |
| 4361 | (void) WriteBlobString(image,message); |
| 4362 | break; |
| 4363 | } |
| 4364 | case PolylinePrimitive: |
| 4365 | { |
| 4366 | if (primitive_info[j].coordinates < 2) |
| 4367 | { |
| 4368 | status=MagickFalse; |
| 4369 | break; |
| 4370 | } |
| 4371 | (void) CopyMagickString(message," <polyline points=\"",MaxTextExtent); |
| 4372 | (void) WriteBlobString(image,message); |
| 4373 | length=strlen(message); |
| 4374 | for ( ; j < i; j++) |
| 4375 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4376 | (void) FormatLocaleString(message,MaxTextExtent,"%g,%g ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4377 | primitive_info[j].point.x,primitive_info[j].point.y); |
| 4378 | length+=strlen(message); |
| 4379 | if (length >= 80) |
| 4380 | { |
| 4381 | (void) WriteBlobString(image,"\n "); |
| 4382 | length=strlen(message)+5; |
| 4383 | } |
| 4384 | (void) WriteBlobString(image,message); |
| 4385 | } |
| 4386 | (void) WriteBlobString(image,"\"/>\n"); |
| 4387 | break; |
| 4388 | } |
| 4389 | case PolygonPrimitive: |
| 4390 | { |
| 4391 | if (primitive_info[j].coordinates < 3) |
| 4392 | { |
| 4393 | status=MagickFalse; |
| 4394 | break; |
| 4395 | } |
| 4396 | primitive_info[i]=primitive_info[j]; |
| 4397 | primitive_info[i].coordinates=0; |
| 4398 | primitive_info[j].coordinates++; |
| 4399 | i++; |
| 4400 | (void) CopyMagickString(message," <polygon points=\"",MaxTextExtent); |
| 4401 | (void) WriteBlobString(image,message); |
| 4402 | length=strlen(message); |
| 4403 | for ( ; j < i; j++) |
| 4404 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4405 | (void) FormatLocaleString(message,MaxTextExtent,"%g,%g ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4406 | primitive_info[j].point.x,primitive_info[j].point.y); |
| 4407 | length+=strlen(message); |
| 4408 | if (length >= 80) |
| 4409 | { |
| 4410 | (void) WriteBlobString(image,"\n "); |
| 4411 | length=strlen(message)+5; |
| 4412 | } |
| 4413 | (void) WriteBlobString(image,message); |
| 4414 | } |
| 4415 | (void) WriteBlobString(image,"\"/>\n"); |
| 4416 | break; |
| 4417 | } |
| 4418 | case BezierPrimitive: |
| 4419 | { |
| 4420 | if (primitive_info[j].coordinates < 3) |
| 4421 | { |
| 4422 | status=MagickFalse; |
| 4423 | break; |
| 4424 | } |
| 4425 | break; |
| 4426 | } |
| 4427 | case PathPrimitive: |
| 4428 | { |
| 4429 | int |
| 4430 | number_attributes; |
| 4431 | |
| 4432 | GetMagickToken(q,&q,token); |
| 4433 | number_attributes=1; |
| 4434 | for (p=token; *p != '\0'; p++) |
| 4435 | if (isalpha((int) *p)) |
| 4436 | number_attributes++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4437 | if (i > (ssize_t) (number_points-6*BezierQuantum*number_attributes-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4438 | { |
| 4439 | number_points+=6*BezierQuantum*number_attributes; |
| 4440 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 4441 | number_points,sizeof(*primitive_info)); |
| 4442 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 4443 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 4444 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4445 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 4446 | image->filename); |
| 4447 | break; |
| 4448 | } |
| 4449 | } |
| 4450 | (void) WriteBlobString(image," <path d=\""); |
| 4451 | (void) WriteBlobString(image,token); |
| 4452 | (void) WriteBlobString(image,"\"/>\n"); |
| 4453 | break; |
| 4454 | } |
| 4455 | case ColorPrimitive: |
| 4456 | case MattePrimitive: |
| 4457 | { |
| 4458 | if (primitive_info[j].coordinates != 1) |
| 4459 | { |
| 4460 | status=MagickFalse; |
| 4461 | break; |
| 4462 | } |
| 4463 | GetMagickToken(q,&q,token); |
| 4464 | if (LocaleCompare("point",token) == 0) |
| 4465 | primitive_info[j].method=PointMethod; |
| 4466 | if (LocaleCompare("replace",token) == 0) |
| 4467 | primitive_info[j].method=ReplaceMethod; |
| 4468 | if (LocaleCompare("floodfill",token) == 0) |
| 4469 | primitive_info[j].method=FloodfillMethod; |
| 4470 | if (LocaleCompare("filltoborder",token) == 0) |
| 4471 | primitive_info[j].method=FillToBorderMethod; |
| 4472 | if (LocaleCompare("reset",token) == 0) |
| 4473 | primitive_info[j].method=ResetMethod; |
| 4474 | break; |
| 4475 | } |
| 4476 | case TextPrimitive: |
| 4477 | { |
| 4478 | register char |
| 4479 | *p; |
| 4480 | |
| 4481 | if (primitive_info[j].coordinates != 1) |
| 4482 | { |
| 4483 | status=MagickFalse; |
| 4484 | break; |
| 4485 | } |
| 4486 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4487 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4488 | " <text x=\"%g\" y=\"%g\">",primitive_info[j].point.x, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4489 | primitive_info[j].point.y); |
| 4490 | (void) WriteBlobString(image,message); |
| 4491 | for (p=token; *p != '\0'; p++) |
| 4492 | switch (*p) |
| 4493 | { |
| 4494 | case '<': (void) WriteBlobString(image,"<"); break; |
| 4495 | case '>': (void) WriteBlobString(image,">"); break; |
| 4496 | case '&': (void) WriteBlobString(image,"&"); break; |
| 4497 | default: (void) WriteBlobByte(image,*p); break; |
| 4498 | } |
| 4499 | (void) WriteBlobString(image,"</text>\n"); |
| 4500 | break; |
| 4501 | } |
| 4502 | case ImagePrimitive: |
| 4503 | { |
| 4504 | if (primitive_info[j].coordinates != 2) |
| 4505 | { |
| 4506 | status=MagickFalse; |
| 4507 | break; |
| 4508 | } |
| 4509 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4510 | (void) FormatLocaleString(message,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 4511 | " <image x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" " |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4512 | "xlink:href=\"%s\"/>\n",primitive_info[j].point.x, |
| 4513 | primitive_info[j].point.y,primitive_info[j+1].point.x, |
| 4514 | primitive_info[j+1].point.y,token); |
| 4515 | (void) WriteBlobString(image,message); |
| 4516 | break; |
| 4517 | } |
| 4518 | } |
| 4519 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 4520 | break; |
| 4521 | primitive_info[i].primitive=UndefinedPrimitive; |
| 4522 | if (status == MagickFalse) |
| 4523 | break; |
| 4524 | } |
| 4525 | (void) WriteBlobString(image,"</svg>\n"); |
| 4526 | /* |
| 4527 | Relinquish resources. |
| 4528 | */ |
| 4529 | token=DestroyString(token); |
| 4530 | if (primitive_info != (PrimitiveInfo *) NULL) |
| 4531 | primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info); |
| 4532 | (void) CloseBlob(image); |
| 4533 | return(status); |
| 4534 | } |