/plugins/ImageMagick-6.3.2/coders/svg.c
C | 4256 lines | 3759 code | 192 blank | 305 comment | 954 complexity | 52537d1ad8c6371a664884897946fa37 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % SSSSS V V GGGG %
- % SS V V G %
- % SSS V V G GG %
- % SS V V G G %
- % SSSSS V GGG %
- % %
- % %
- % Read/Write Scalable Vector Graphics Format. %
- % %
- % Software Design %
- % John Cristy %
- % William Radcliffe %
- % March 2000 %
- % %
- % %
- % Copyright 1999-2006 ImageMagick Studio LLC, a non-profit organization %
- % dedicated to making software imaging solutions freely available. %
- % %
- % You may not use this file except in compliance with the License. You may %
- % obtain a copy of the License at %
- % %
- % http://www.imagemagick.org/script/license.php %
- % %
- % Unless required by applicable law or agreed to in writing, software %
- % distributed under the License is distributed on an "AS IS" BASIS, %
- % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
- % See the License for the specific language governing permissions and %
- % limitations under the License. %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- %
- */
- /*
- Include declarations.
- */
- #include "magick/studio.h"
- #include "magick/annotate.h"
- #include "magick/blob.h"
- #include "magick/blob-private.h"
- #include "magick/constitute.h"
- #include "magick/composite-private.h"
- #include "magick/draw.h"
- #include "magick/exception.h"
- #include "magick/exception-private.h"
- #include "magick/gem.h"
- #include "magick/image.h"
- #include "magick/image-private.h"
- #include "magick/list.h"
- #include "magick/log.h"
- #include "magick/magick.h"
- #include "magick/memory_.h"
- #include "magick/quantum.h"
- #include "magick/property.h"
- #include "magick/resource_.h"
- #include "magick/static.h"
- #include "magick/string_.h"
- #include "magick/token.h"
- #include "magick/utility.h"
- #if defined(HasXML)
- # if defined(__WINDOWS__)
- # if defined(__MINGW32__)
- # define _MSC_VER
- # endif
- # include <win32config.h>
- # endif
- # include <libxml/parser.h>
- # include <libxml/xmlmemory.h>
- # include <libxml/parserInternals.h>
- # include <libxml/xmlerror.h>
- #endif
- #if defined(HasAUTOTRACE)
- #include "types.h"
- #include "image-header.h"
- #include "fit.h"
- #include "output.h"
- #include "pxl-outline.h"
- #include "atquantize.h"
- #include "thin-image.h"
- char
- *version_string = "AutoTrace version 0.24a";
- #endif
- #if defined(HasRSVG)
- #include "librsvg/rsvg.h"
- #endif
- /*
- Define declarations.
- */
- #define MVGPrintf (void) fprintf
- /*
- Typedef declarations.
- */
- typedef struct _BoundingBox
- {
- double
- x,
- y,
- width,
- height;
- } BoundingBox;
- typedef struct _ElementInfo
- {
- double
- cx,
- cy,
- major,
- minor,
- angle;
- } ElementInfo;
- typedef struct _SVGInfo
- {
- FILE
- *file;
- ExceptionInfo
- *exception;
- Image
- *image;
- const ImageInfo
- *image_info;
- AffineMatrix
- affine;
- unsigned long
- width,
- height;
- char
- *size,
- *title,
- *comment;
- int
- n;
- double
- *scale,
- pointsize;
- ElementInfo
- element;
- SegmentInfo
- segment;
- BoundingBox
- bounds,
- view_box;
- PointInfo
- radius;
- char
- *stop_color,
- *offset,
- *text,
- *vertices,
- *url;
- #if defined(HasXML)
- xmlParserCtxtPtr
- parser;
- xmlDocPtr
- document;
- #endif
- } SVGInfo;
- /*
- Forward declarations.
- */
- static MagickBooleanType
- WriteSVGImage(const ImageInfo *,Image *);
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % I s S V G %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % IsSVG()() returns MagickTrue if the image format type, identified by the
- % magick string, is SVG.
- %
- % The format of the ReadSVGImage method is:
- %
- % MagickBooleanType IsSVG(const unsigned char *magick,const size_t length)
- %
- % A description of each parameter follows:
- %
- % o magick: This string is generally the first few bytes of an image file
- % or blob.
- %
- % o length: Specifies the length of the magick string.
- %
- %
- */
- static MagickBooleanType IsSVG(const unsigned char *magick,const size_t length)
- {
- if (length < 4)
- return(MagickFalse);
- if (LocaleNCompare((char *) magick,"?xml",4) == 0)
- return(MagickTrue);
- return(MagickFalse);
- }
- #if defined(HasXML)
- /*
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % %
- % %
- % %
- % R e a d S V G I m a g e %
- % %
- % %
- % %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % ReadSVGImage() reads a Scalable Vector Gaphics file and returns it. It
- % allocates the memory necessary for the new Image structure and returns a
- % pointer to the new image.
- %
- % The format of the ReadSVGImage method is:
- %
- % Image *ReadSVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
- %
- % A description of each parameter follows:
- %
- % o image_info: The image info.
- %
- % o exception: return any errors or warnings in this structure.
- %
- */
- static double GetUserSpaceCoordinateValue(const SVGInfo *svg_info,int type,
- const char *string)
- {
- char
- *p,
- token[MaxTextExtent];
- double
- value;
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",string);
- assert(string != (const char *) NULL);
- p=(char *) string;
- GetMagickToken(p,&p,token);
- value=atof(token);
- if (strchr(token,'%') != (char *) NULL)
- {
- double
- alpha,
- beta;
- if (type > 0)
- return(svg_info->view_box.width*value/100.0);
- if (type < 0)
- return(svg_info->view_box.height*value/100.0);
- alpha=value-svg_info->view_box.width;
- beta=value-svg_info->view_box.height;
- return(hypot(alpha,beta)/sqrt(2.0)/100.0);
- }
- GetMagickToken(p,&p,token);
- if (LocaleNCompare(token,"cm",2) == 0)
- return(DefaultResolution*svg_info->scale[0]/2.54*value);
- if (LocaleNCompare(token,"em",2) == 0)
- return(svg_info->pointsize*value);
- if (LocaleNCompare(token,"ex",2) == 0)
- return(svg_info->pointsize*value/2.0);
- if (LocaleNCompare(token,"in",2) == 0)
- return(DefaultResolution*svg_info->scale[0]*value);
- if (LocaleNCompare(token,"mm",2) == 0)
- return(DefaultResolution*svg_info->scale[0]/25.4*value);
- if (LocaleNCompare(token,"pc",2) == 0)
- return(DefaultResolution*svg_info->scale[0]/6.0*value);
- if (LocaleNCompare(token,"pt",2) == 0)
- return(svg_info->scale[0]*value);
- if (LocaleNCompare(token,"px",2) == 0)
- return(value);
- return(value);
- }
- static char **GetStyleTokens(void *context,const char *text,int *number_tokens)
- {
- char
- **tokens;
- register const char
- *p,
- *q;
- register long
- i;
- SVGInfo
- *svg_info;
- svg_info=(SVGInfo *) context;
- *number_tokens=0;
- if (text == (const char *) NULL)
- return((char **) NULL);
- /*
- Determine the number of arguments.
- */
- for (p=text; *p != '\0'; p++)
- if ((*p == ':') || (*p == ';'))
- (*number_tokens)++;
- tokens=(char **) AcquireMagickMemory((*number_tokens+2)*sizeof(*tokens));
- if (tokens == (char **) NULL)
- {
- (void) ThrowMagickException(svg_info->exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",text);
- return((char **) NULL);
- }
- /*
- Convert string to an ASCII list.
- */
- i=0;
- p=text;
- for (q=p; *q != '\0'; q++)
- {
- if ((*q != ':') && (*q != ';') && (*q != '\0'))
- continue;
- tokens[i]=AcquireString(p);
- (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1));
- StripString(tokens[i++]);
- p=q+1;
- }
- tokens[i]=AcquireString(p);
- (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1));
- StripString(tokens[i++]);
- tokens[i]=(char *) NULL;
- return(tokens);
- }
- static char **GetTransformTokens(void *context,const char *text,
- int *number_tokens)
- {
- char
- **tokens;
- register const char
- *p,
- *q;
- register long
- i;
- SVGInfo
- *svg_info;
- svg_info=(SVGInfo *) context;
- *number_tokens=0;
- if (text == (const char *) NULL)
- return((char **) NULL);
- /*
- Determine the number of arguments.
- */
- for (p=text; *p != '\0'; p++)
- {
- if (*p == '(')
- (*number_tokens)+=2;
- }
- tokens=(char **) AcquireMagickMemory((*number_tokens+2)*sizeof(*tokens));
- if (tokens == (char **) NULL)
- {
- (void) ThrowMagickException(svg_info->exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",text);
- return((char **) NULL);
- }
- /*
- Convert string to an ASCII list.
- */
- i=0;
- p=text;
- for (q=p; *q != '\0'; q++)
- {
- if ((*q != '(') && (*q != ')') && (*q != '\0'))
- continue;
- tokens[i]=AcquireString(p);
- (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1));
- StripString(tokens[i++]);
- p=q+1;
- }
- tokens[i]=AcquireString(p);
- (void) CopyMagickString(tokens[i],p,(size_t) (q-p+1));
- StripString(tokens[i++]);
- tokens[i]=(char *) NULL;
- return(tokens);
- }
- #if defined(__cplusplus) || defined(c_plusplus)
- extern "C" {
- #endif
- static int SVGIsStandalone(void *context)
- {
- SVGInfo
- *svg_info;
- /*
- Is this document tagged standalone?
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.SVGIsStandalone()");
- svg_info=(SVGInfo *) context;
- return(svg_info->document->standalone == 1);
- }
- static int SVGHasInternalSubset(void *context)
- {
- SVGInfo
- *svg_info;
- /*
- Does this document has an internal subset?
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.SVGHasInternalSubset()");
- svg_info=(SVGInfo *) context;
- return(svg_info->document->intSubset != NULL);
- }
- static int SVGHasExternalSubset(void *context)
- {
- SVGInfo
- *svg_info;
- /*
- Does this document has an external subset?
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.SVGHasExternalSubset()");
- svg_info=(SVGInfo *) context;
- return(svg_info->document->extSubset != NULL);
- }
- static void SVGInternalSubset(void *context,const xmlChar *name,
- const xmlChar *external_id,const xmlChar *system_id)
- {
- SVGInfo
- *svg_info;
- /*
- Does this document has an internal subset?
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.internalSubset(%s, %s, %s)",(char *) name,
- (external_id != (const xmlChar *) NULL ? (char *) external_id : "none"),
- (system_id != (const xmlChar *) NULL ? (char *) system_id : "none"));
- svg_info=(SVGInfo *) context;
- (void) xmlCreateIntSubset(svg_info->document,name,external_id,system_id);
- }
- static xmlParserInputPtr SVGResolveEntity(void *context,
- const xmlChar *public_id,const xmlChar *system_id)
- {
- SVGInfo
- *svg_info;
- xmlParserInputPtr
- stream;
- /*
- Special entity resolver, better left to the parser, it has more
- context than the application layer. The default behaviour is to
- not resolve the entities, in that case the ENTITY_REF nodes are
- built in the structure (and the parameter values).
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.resolveEntity(%s, %s)",
- (public_id != (const xmlChar *) NULL ? (char *) public_id : "none"),
- (system_id != (const xmlChar *) NULL ? (char *) system_id : "none"));
- svg_info=(SVGInfo *) context;
- stream=xmlLoadExternalEntity((const char *) system_id,(const char *)
- public_id,svg_info->parser);
- return(stream);
- }
- static xmlEntityPtr SVGGetEntity(void *context,const xmlChar *name)
- {
- SVGInfo
- *svg_info;
- /*
- Get an entity by name.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.SVGGetEntity(%s)",
- name);
- svg_info=(SVGInfo *) context;
- return(xmlGetDocEntity(svg_info->document,name));
- }
- static xmlEntityPtr SVGGetParameterEntity(void *context,const xmlChar *name)
- {
- SVGInfo
- *svg_info;
- /*
- Get a parameter entity by name.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.getParameterEntity(%s)",name);
- svg_info=(SVGInfo *) context;
- return(xmlGetParameterEntity(svg_info->document,name));
- }
- static void SVGEntityDeclaration(void *context,const xmlChar *name,int type,
- const xmlChar *public_id,const xmlChar *system_id,xmlChar *content)
- {
- SVGInfo
- *svg_info;
- /*
- An entity definition has been parsed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.entityDecl(%s, %d, %s, %s, %s)",name,type,
- public_id != (xmlChar *) NULL ? (char *) public_id : "none",
- system_id != (xmlChar *) NULL ? (char *) system_id : "none",content);
- svg_info=(SVGInfo *) context;
- if (svg_info->parser->inSubset == 1)
- (void) xmlAddDocEntity(svg_info->document,name,type,public_id,system_id,
- content);
- else
- if (svg_info->parser->inSubset == 2)
- (void) xmlAddDtdEntity(svg_info->document,name,type,public_id,system_id,
- content);
- }
- static void SVGAttributeDeclaration(void *context,const xmlChar *element,
- const xmlChar *name,int type,int value,const xmlChar *default_value,
- xmlEnumerationPtr tree)
- {
- SVGInfo
- *svg_info;
- xmlChar
- *fullname,
- *prefix;
- xmlParserCtxtPtr
- parser;
- /*
- An attribute definition has been parsed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.attributeDecl(%s, %s, %d, %d, %s, ...)",element,name,type,value,
- default_value);
- svg_info=(SVGInfo *) context;
- fullname=(xmlChar *) NULL;
- prefix=(xmlChar *) NULL;
- parser=svg_info->parser;
- fullname=(xmlChar *) xmlSplitQName(parser,name,&prefix);
- if (parser->inSubset == 1)
- (void) xmlAddAttributeDecl(&parser->vctxt,svg_info->document->intSubset,
- element,fullname,prefix,(xmlAttributeType) type,
- (xmlAttributeDefault) value,default_value,tree);
- else
- if (parser->inSubset == 2)
- (void) xmlAddAttributeDecl(&parser->vctxt,svg_info->document->extSubset,
- element,fullname,prefix,(xmlAttributeType) type,
- (xmlAttributeDefault) value,default_value,tree);
- if (prefix != (xmlChar *) NULL)
- xmlFree(prefix);
- if (fullname != (xmlChar *) NULL)
- xmlFree(fullname);
- }
- static void SVGElementDeclaration(void *context,const xmlChar *name,int type,
- xmlElementContentPtr content)
- {
- SVGInfo
- *svg_info;
- xmlParserCtxtPtr
- parser;
- /*
- An element definition has been parsed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.elementDecl(%s, %d, ...)",name,type);
- svg_info=(SVGInfo *) context;
- parser=svg_info->parser;
- if (parser->inSubset == 1)
- (void) xmlAddElementDecl(&parser->vctxt,svg_info->document->intSubset,
- name,(xmlElementTypeVal) type,content);
- else
- if (parser->inSubset == 2)
- (void) xmlAddElementDecl(&parser->vctxt,svg_info->document->extSubset,
- name,(xmlElementTypeVal) type,content);
- }
- static void SVGNotationDeclaration(void *context,const xmlChar *name,
- const xmlChar *public_id,const xmlChar *system_id)
- {
- SVGInfo
- *svg_info;
- xmlParserCtxtPtr
- parser;
- /*
- What to do when a notation declaration has been parsed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.notationDecl(%s, %s, %s)",name,
- public_id != (const xmlChar *) NULL ? (char *) public_id : "none",
- system_id != (const xmlChar *) NULL ? (char *) system_id : "none");
- svg_info=(SVGInfo *) context;
- parser=svg_info->parser;
- if (parser->inSubset == 1)
- (void) xmlAddNotationDecl(&parser->vctxt,svg_info->document->intSubset,
- name,public_id,system_id);
- else
- if (parser->inSubset == 2)
- (void) xmlAddNotationDecl(&parser->vctxt,svg_info->document->intSubset,
- name,public_id,system_id);
- }
- static void SVGUnparsedEntityDeclaration(void *context,const xmlChar *name,
- const xmlChar *public_id,const xmlChar *system_id,const xmlChar *notation)
- {
- SVGInfo
- *svg_info;
- /*
- What to do when an unparsed entity declaration is parsed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.unparsedEntityDecl(%s, %s, %s, %s)",name,
- public_id != (xmlChar *) NULL ? (char *) public_id : "none",
- system_id != (xmlChar *) NULL ? (char *) system_id : "none",notation);
- svg_info=(SVGInfo *) context;
- (void) xmlAddDocEntity(svg_info->document,name,
- XML_EXTERNAL_GENERAL_UNPARSED_ENTITY,public_id,system_id,notation);
- }
- static void SVGSetDocumentLocator(void *context,xmlSAXLocatorPtr location)
- {
- SVGInfo
- *svg_info;
- /*
- Receive the document locator at startup, actually xmlDefaultSAXLocator.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " SAX.setDocumentLocator()");
- svg_info=(SVGInfo *) context;
- }
- static void SVGStartDocument(void *context)
- {
- SVGInfo
- *svg_info;
- xmlParserCtxtPtr
- parser;
- /*
- Called when the document start being processed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.startDocument()");
- svg_info=(SVGInfo *) context;
- GetExceptionInfo(svg_info->exception);
- parser=svg_info->parser;
- svg_info->document=xmlNewDoc(parser->version);
- if (svg_info->document == (xmlDocPtr) NULL)
- return;
- if (parser->encoding == NULL)
- svg_info->document->encoding=(const xmlChar *) NULL;
- else
- svg_info->document->encoding=xmlStrdup(parser->encoding);
- svg_info->document->standalone=parser->standalone;
- }
- static void SVGEndDocument(void *context)
- {
- SVGInfo
- *svg_info;
- /*
- Called when the document end has been detected.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.endDocument()");
- svg_info=(SVGInfo *) context;
- if (svg_info->offset != (char *) NULL)
- svg_info->offset=(char *) RelinquishMagickMemory(svg_info->offset);
- if (svg_info->stop_color != (char *) NULL)
- svg_info->stop_color=(char *) RelinquishMagickMemory(svg_info->stop_color);
- if (svg_info->scale != (double *) NULL)
- svg_info->scale=(double *) RelinquishMagickMemory(svg_info->scale);
- if (svg_info->text != (char *) NULL)
- svg_info->text=(char *) RelinquishMagickMemory(svg_info->text);
- if (svg_info->vertices != (char *) NULL)
- svg_info->vertices=(char *) RelinquishMagickMemory(svg_info->vertices);
- if (svg_info->url != (char *) NULL)
- svg_info->url=(char *) RelinquishMagickMemory(svg_info->url);
- #if defined(HasXML)
- if (svg_info->document != (xmlDocPtr) NULL)
- {
- xmlFreeDoc(svg_info->document);
- svg_info->document=(xmlDocPtr) NULL;
- }
- #endif
- }
- static void SVGStartElement(void *context,const xmlChar *name,
- const xmlChar **attributes)
- {
- char
- *color,
- id[MaxTextExtent],
- *p,
- token[MaxTextExtent],
- **tokens,
- *units;
- const char
- *keyword,
- *value;
- int
- number_tokens;
- SVGInfo
- *svg_info;
- register long
- i,
- j;
- /*
- Called when an opening tag has been processed.
- */
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," SAX.startElement(%s",
- name);
- svg_info=(SVGInfo *) context;
- svg_info->n++;
- svg_info->scale=(double *) ResizeMagickMemory(svg_info->scale,
- (svg_info->n+1)*sizeof(*svg_info->scale));
- if (svg_info->scale == (double *) NULL)
- {
- (void) ThrowMagickException(svg_info->exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",name);
- return;
- }
- svg_info->scale[svg_info->n]=svg_info->scale[svg_info->n-1];
- color=AcquireString("none");
- units=AcquireString("userSpaceOnUse");
- value=(const char *) NULL;
- if (attributes != (const xmlChar **) NULL)
- for (i=0; (attributes[i] != (const xmlChar *) NULL); i+=2)
- {
- keyword=(const char *) attributes[i];
- value=(const char *) attributes[i+1];
- switch (*keyword)
- {
- case 'C':
- case 'c':
- {
- if (LocaleCompare(keyword,"cx") == 0)
- {
- svg_info->element.cx=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"cy") == 0)
- {
- svg_info->element.cy=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'F':
- case 'f':
- {
- if (LocaleCompare(keyword,"fx") == 0)
- {
- svg_info->element.major=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"fy") == 0)
- {
- svg_info->element.minor=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'H':
- case 'h':
- {
- if (LocaleCompare(keyword,"height") == 0)
- {
- svg_info->bounds.height=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'I':
- case 'i':
- {
- if (LocaleCompare(keyword,"id") == 0)
- {
- (void) CopyMagickString(id,value,MaxTextExtent);
- break;
- }
- break;
- }
- case 'R':
- case 'r':
- {
- if (LocaleCompare(keyword,"r") == 0)
- {
- svg_info->element.angle=
- GetUserSpaceCoordinateValue(svg_info,0,value);
- break;
- }
- break;
- }
- case 'W':
- case 'w':
- {
- if (LocaleCompare(keyword,"width") == 0)
- {
- svg_info->bounds.width=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- break;
- }
- case 'X':
- case 'x':
- {
- if (LocaleCompare(keyword,"x") == 0)
- {
- svg_info->bounds.x=GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"x1") == 0)
- {
- svg_info->segment.x1=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"x2") == 0)
- {
- svg_info->segment.x2=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- break;
- }
- case 'Y':
- case 'y':
- {
- if (LocaleCompare(keyword,"y") == 0)
- {
- svg_info->bounds.y=GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- if (LocaleCompare(keyword,"y1") == 0)
- {
- svg_info->segment.y1=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- if (LocaleCompare(keyword,"y2") == 0)
- {
- svg_info->segment.y2=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- switch (*name)
- {
- case 'C':
- case 'c':
- {
- if (LocaleCompare((char *) name,"circle") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- if (LocaleCompare((char *) name,"clipPath") == 0)
- {
- MVGPrintf(svg_info->file,"push clip-path '%s'\n",id);
- break;
- }
- break;
- }
- case 'D':
- case 'd':
- {
- if (LocaleCompare((char *) name,"defs") == 0)
- {
- MVGPrintf(svg_info->file,"push defs\n");
- break;
- }
- break;
- }
- case 'E':
- case 'e':
- {
- if (LocaleCompare((char *) name,"ellipse") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'G':
- case 'g':
- {
- if (LocaleCompare((char *) name,"g") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'I':
- case 'i':
- {
- if (LocaleCompare((char *) name,"image") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'L':
- case 'l':
- {
- if (LocaleCompare((char *) name,"line") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- if (LocaleCompare((char *) name,"linearGradient") == 0)
- {
- MVGPrintf(svg_info->file,"push gradient '%s' linear %g,%g %g,%g\n",id,
- svg_info->segment.x1,svg_info->segment.y1,svg_info->segment.x2,
- svg_info->segment.y2);
- break;
- }
- break;
- }
- case 'P':
- case 'p':
- {
- if (LocaleCompare((char *) name,"path") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- if (LocaleCompare((char *) name,"pattern") == 0)
- {
- MVGPrintf(svg_info->file,"push pattern '%s' %g,%g %g,%g\n",id,
- svg_info->bounds.x,svg_info->bounds.y,svg_info->bounds.width,
- svg_info->bounds.height);
- break;
- }
- if (LocaleCompare((char *) name,"polygon") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- if (LocaleCompare((char *) name,"polyline") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'R':
- case 'r':
- {
- if (LocaleCompare((char *) name,"radialGradient") == 0)
- {
- MVGPrintf(svg_info->file,"push gradient '%s' radial %g,%g %g,%g %g\n",
- id,svg_info->element.cx,svg_info->element.cy,
- svg_info->element.major,svg_info->element.minor,
- svg_info->element.angle);
- break;
- }
- if (LocaleCompare((char *) name,"rect") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'S':
- case 's':
- {
- if (LocaleCompare((char *) name,"svg") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- case 'T':
- case 't':
- {
- if (LocaleCompare((char *) name,"text") == 0)
- {
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- if (LocaleCompare((char *) name,"tspan") == 0)
- {
- if (*svg_info->text != '\0')
- {
- DrawInfo
- *draw_info;
- TypeMetric
- metrics;
- char
- *text;
- text=EscapeString(svg_info->text,'\'');
- MVGPrintf(svg_info->file,"text %g,%g '%s'\n",svg_info->bounds.x,
- svg_info->bounds.y,text);
- text=(char *) RelinquishMagickMemory(text);
- draw_info=CloneDrawInfo(svg_info->image_info,(DrawInfo *) NULL);
- draw_info->pointsize=svg_info->pointsize;
- draw_info->text=AcquireString(svg_info->text);
- (void) ConcatenateString(&draw_info->text," ");
- GetTypeMetrics(svg_info->image,draw_info,&metrics);
- svg_info->bounds.x+=metrics.width;
- draw_info=DestroyDrawInfo(draw_info);
- *svg_info->text='\0';
- }
- MVGPrintf(svg_info->file,"push graphic-context\n");
- break;
- }
- break;
- }
- default:
- break;
- }
- if (attributes != (const xmlChar **) NULL)
- for (i=0; (attributes[i] != (const xmlChar *) NULL); i+=2)
- {
- keyword=(const char *) attributes[i];
- value=(const char *) attributes[i+1];
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " %s = %s",keyword,value);
- switch (*keyword)
- {
- case 'A':
- case 'a':
- {
- if (LocaleCompare(keyword,"angle") == 0)
- {
- MVGPrintf(svg_info->file,"angle %g\n",
- GetUserSpaceCoordinateValue(svg_info,0,value));
- break;
- }
- break;
- }
- case 'C':
- case 'c':
- {
- if (LocaleCompare(keyword,"clip-path") == 0)
- {
- MVGPrintf(svg_info->file,"clip-path '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"clip-rule") == 0)
- {
- MVGPrintf(svg_info->file,"clip-rule '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"clipPathUnits") == 0)
- {
- (void) CloneString(&units,value);
- MVGPrintf(svg_info->file,"clip-units '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"color") == 0)
- {
- (void) CloneString(&color,value);
- break;
- }
- if (LocaleCompare(keyword,"cx") == 0)
- {
- svg_info->element.cx=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"cy") == 0)
- {
- svg_info->element.cy=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'D':
- case 'd':
- {
- if (LocaleCompare(keyword,"d") == 0)
- {
- (void) CloneString(&svg_info->vertices,value);
- break;
- }
- if (LocaleCompare(keyword,"dx") == 0)
- {
- svg_info->bounds.x+=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"dy") == 0)
- {
- svg_info->bounds.y+=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'F':
- case 'f':
- {
- if (LocaleCompare(keyword,"fill") == 0)
- {
- if (LocaleCompare(value,"currentColor") == 0)
- {
- MVGPrintf(svg_info->file,"fill '%s'\n",color);
- break;
- }
- MVGPrintf(svg_info->file,"fill '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fillcolor") == 0)
- {
- MVGPrintf(svg_info->file,"fill '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fill-rule") == 0)
- {
- MVGPrintf(svg_info->file,"fill-rule '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fill-opacity") == 0)
- {
- MVGPrintf(svg_info->file,"fill-opacity '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-family") == 0)
- {
- MVGPrintf(svg_info->file,"font-family '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-stretch") == 0)
- {
- MVGPrintf(svg_info->file,"font-stretch '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-style") == 0)
- {
- MVGPrintf(svg_info->file,"font-style '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-size") == 0)
- {
- svg_info->pointsize=GetUserSpaceCoordinateValue(svg_info,0,value);
- MVGPrintf(svg_info->file,"font-size %g\n",svg_info->pointsize);
- break;
- }
- if (LocaleCompare(keyword,"font-weight") == 0)
- {
- MVGPrintf(svg_info->file,"font-weight '%s'\n",value);
- break;
- }
- break;
- }
- case 'G':
- case 'g':
- {
- if (LocaleCompare(keyword,"gradientTransform") == 0)
- {
- AffineMatrix
- affine,
- current,
- transform;
- GetAffineMatrix(&transform);
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," ");
- tokens=GetTransformTokens(context,value,&number_tokens);
- for (j=0; j < (number_tokens-1); j+=2)
- {
- keyword=(char *) tokens[j];
- if (keyword == (char *) NULL)
- continue;
- value=(char *) tokens[j+1];
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " %s: %s",keyword,value);
- current=transform;
- GetAffineMatrix(&affine);
- switch (*keyword)
- {
- case 'M':
- case 'm':
- {
- if (LocaleCompare(keyword,"matrix") == 0)
- {
- p=(char *) value;
- GetMagickToken(p,&p,token);
- affine.sx=atof(value);
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- affine.rx=atof(token);
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- affine.ry=atof(token);
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- affine.sy=atof(token);
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- affine.tx=atof(token);
- GetMagickToken(p,&p,token);
- if (*token == ',')
- GetMagickToken(p,&p,token);
- affine.ty=atof(token);
- break;
- }
- break;
- }
- case 'R':
- case 'r':
- {
- if (LocaleCompare(keyword,"rotate") == 0)
- {
- double
- angle;
- angle=GetUserSpaceCoordinateValue(svg_info,0,value);
- affine.sx=cos(DegreesToRadians(fmod(angle,360.0)));
- affine.rx=sin(DegreesToRadians(fmod(angle,360.0)));
- affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0))));
- affine.sy=cos(DegreesToRadians(fmod(angle,360.0)));
- break;
- }
- break;
- }
- case 'S':
- case 's':
- {
- if (LocaleCompare(keyword,"scale") == 0)
- {
- for (p=(char *) value; *p != '\0'; p++)
- if ((isspace((int) ((unsigned char) *p)) != 0) ||
- (*p == ','))
- break;
- affine.sx=GetUserSpaceCoordinateValue(svg_info,1,value);
- affine.sy=affine.sx;
- if (*p != '\0')
- affine.sy=
- GetUserSpaceCoordinateValue(svg_info,-1,p+1);
- svg_info->scale[svg_info->n]=ExpandAffine(&affine);
- break;
- }
- if (LocaleCompare(keyword,"skewX") == 0)
- {
- affine.sx=svg_info->affine.sx;
- affine.ry=tan(DegreesToRadians(fmod(
- GetUserSpaceCoordinateValue(svg_info,1,value),
- 360.0)));
- affine.sy=svg_info->affine.sy;
- break;
- }
- if (LocaleCompare(keyword,"skewY") == 0)
- {
- affine.sx=svg_info->affine.sx;
- affine.rx=tan(DegreesToRadians(fmod(
- GetUserSpaceCoordinateValue(svg_info,-1,value),
- 360.0)));
- affine.sy=svg_info->affine.sy;
- break;
- }
- break;
- }
- case 'T':
- case 't':
- {
- if (LocaleCompare(keyword,"translate") == 0)
- {
- for (p=(char *) value; *p != '\0'; p++)
- if ((isspace((int) ((unsigned char) *p)) != 0) ||
- (*p == ','))
- break;
- affine.tx=GetUserSpaceCoordinateValue(svg_info,1,value);
- affine.ty=affine.tx;
- if (*p != '\0')
- affine.ty=
- GetUserSpaceCoordinateValue(svg_info,-1,p+1);
- break;
- }
- break;
- }
- default:
- break;
- }
- transform.sx=current.sx*affine.sx+current.ry*affine.rx;
- transform.rx=current.rx*affine.sx+current.sy*affine.rx;
- transform.ry=current.sx*affine.ry+current.ry*affine.sy;
- transform.sy=current.rx*affine.ry+current.sy*affine.sy;
- transform.tx=current.sx*affine.tx+current.ry*affine.ty+
- current.tx;
- transform.ty=current.rx*affine.tx+current.sy*affine.ty+
- current.ty;
- }
- MVGPrintf(svg_info->file,"affine %g %g %g %g %g %g\n",
- transform.sx,transform.rx,transform.ry,transform.sy,
- transform.tx,transform.ty);
- for (j=0; tokens[j] != (char *) NULL; j++)
- tokens[j]=(char *) RelinquishMagickMemory(tokens[j]);
- tokens=(char **) RelinquishMagickMemory(tokens);
- break;
- }
- if (LocaleCompare(keyword,"gradientUnits") == 0)
- {
- (void) CloneString(&units,value);
- MVGPrintf(svg_info->file,"gradient-units '%s'\n",value);
- break;
- }
- break;
- }
- case 'H':
- case 'h':
- {
- if (LocaleCompare(keyword,"height") == 0)
- {
- svg_info->bounds.height=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- if (LocaleCompare(keyword,"href") == 0)
- {
- (void) CloneString(&svg_info->url,value);
- break;
- }
- break;
- }
- case 'M':
- case 'm':
- {
- if (LocaleCompare(keyword,"major") == 0)
- {
- svg_info->element.major=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"minor") == 0)
- {
- svg_info->element.minor=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'O':
- case 'o':
- {
- if (LocaleCompare(keyword,"offset") == 0)
- {
- (void) CloneString(&svg_info->offset,value);
- break;
- }
- if (LocaleCompare(keyword,"opacity") == 0)
- {
- MVGPrintf(svg_info->file,"opacity '%s'\n",value);
- break;
- }
- break;
- }
- case 'P':
- case 'p':
- {
- if (LocaleCompare(keyword,"path") == 0)
- {
- (void) CloneString(&svg_info->url,value);
- break;
- }
- if (LocaleCompare(keyword,"points") == 0)
- {
- (void) CloneString(&svg_info->vertices,value);
- break;
- }
- break;
- }
- case 'R':
- case 'r':
- {
- if (LocaleCompare(keyword,"r") == 0)
- {
- svg_info->element.major=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- svg_info->element.minor=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- if (LocaleCompare(keyword,"rotate") == 0)
- {
- double
- angle;
- angle=GetUserSpaceCoordinateValue(svg_info,0,value);
- MVGPrintf(svg_info->file,"translate %g,%g\n",svg_info->bounds.x,
- svg_info->bounds.y);
- svg_info->bounds.x=0;
- svg_info->bounds.y=0;
- MVGPrintf(svg_info->file,"rotate %g\n",angle);
- break;
- }
- if (LocaleCompare(keyword,"rx") == 0)
- {
- if (LocaleCompare((char *) name,"ellipse") == 0)
- svg_info->element.major=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- else
- svg_info->radius.x=
- GetUserSpaceCoordinateValue(svg_info,1,value);
- break;
- }
- if (LocaleCompare(keyword,"ry") == 0)
- {
- if (LocaleCompare((char *) name,"ellipse") == 0)
- svg_info->element.minor=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- else
- svg_info->radius.y=
- GetUserSpaceCoordinateValue(svg_info,-1,value);
- break;
- }
- break;
- }
- case 'S':
- case 's':
- {
- if (LocaleCompare(keyword,"stop-color") == 0)
- {
- (void) CloneString(&svg_info->stop_color,value);
- break;
- }
- if (LocaleCompare(keyword,"stroke") == 0)
- {
- if (LocaleCompare(value,"currentColor") == 0)
- {
- MVGPrintf(svg_info->file,"stroke '%s'\n",color);
- break;
- }
- MVGPrintf(svg_info->file,"stroke '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-antialiasing") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-antialias %d\n",
- LocaleCompare(value,"true") == 0);
- break;
- }
- if (LocaleCompare(keyword,"stroke-dasharray") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-dasharray %s\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-dashoffset") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-dashoffset %s\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-linecap") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-linecap '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-linejoin") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-linejoin '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-miterlimit") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-miterlimit '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-opacity") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-opacity '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"stroke-width") == 0)
- {
- MVGPrintf(svg_info->file,"stroke-width %g\n",
- GetUserSpaceCoordinateValue(svg_info,1,value));
- break;
- }
- if (LocaleCompare(keyword,"style") == 0)
- {
- (void) LogMagickEvent(CoderEvent,GetMagickModule()," ");
- tokens=GetStyleTokens(context,value,&number_tokens);
- for (j=0; j < (number_tokens-1); j+=2)
- {
- keyword=(char *) tokens[j];
- value=(char *) tokens[j+1];
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " %s: %s",keyword,value);
- switch (*keyword)
- {
- case 'C':
- case 'c':
- {
- if (LocaleCompare(keyword,"clip-path") == 0)
- {
- MVGPrintf(svg_info->file,"clip-path '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"clip-rule") == 0)
- {
- MVGPrintf(svg_info->file,"clip-rule '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"clipPathUnits") == 0)
- {
- (void) CloneString(&units,value);
- MVGPrintf(svg_info->file,"clip-units '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"color") == 0)
- {
- (void) CloneString(&color,value);
- break;
- }
- break;
- }
- case 'F':
- case 'f':
- {
- if (LocaleCompare(keyword,"fill") == 0)
- {
- if (LocaleCompare(value,"currentColor") == 0)
- {
- MVGPrintf(svg_info->file,"fill '%s'\n",color);
- break;
- }
- MVGPrintf(svg_info->file,"fill '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fillcolor") == 0)
- {
- MVGPrintf(svg_info->file,"fill '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fill-rule") == 0)
- {
- MVGPrintf(svg_info->file,"fill-rule '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"fill-opacity") == 0)
- {
- MVGPrintf(svg_info->file,"fill-opacity '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-family") == 0)
- {
- MVGPrintf(svg_info->file,"font-family '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-stretch") == 0)
- {
- MVGPrintf(svg_info->file,"font-stretch '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-style") == 0)
- {
- MVGPrintf(svg_info->file,"font-style '%s'\n",value);
- break;
- }
- if (LocaleCompare(keyword,"font-size") == 0)
- {
- svg_info->pointsize=GetUserSpaceCoordinateValue(
- svg_info,0,value);
- MVGPrintf(svg_info->file,"font-size %g\n",
- …
Large files files are truncated, but you can click here to view the full file