00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
#include "magick/studio.h"
00043
#include "magick/attribute.h"
00044
#include "magick/blob.h"
00045
#include "magick/blob_private.h"
00046
#include "magick/draw.h"
00047
#include "magick/error.h"
00048
#include "magick/error_private.h"
00049
#include "magick/image.h"
00050
#include "magick/image_private.h"
00051
#include "magick/list.h"
00052
#include "magick/magick.h"
00053
#include "magick/memory_.h"
00054
#include "magick/static.h"
00055
#include "magick/string_.h"
00056
00057
00058
00059
00060
static MagickBooleanType
00061
WriteMVGImage(
const ImageInfo *,
Image *);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static MagickBooleanType IsMVG(
const unsigned char *magick,
const size_t length)
00091 {
00092
if (length < 20)
00093
return(
MagickFalse);
00094
if (
LocaleNCompare((
char *) magick,
"push graphic-context",20) == 0)
00095
return(
MagickTrue);
00096
return(
MagickFalse);
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 static Image *
ReadMVGImage(
const ImageInfo *image_info,
ExceptionInfo *
exception)
00128 {
00129
#define BoundingBox "viewbox"
00130
00131
DrawInfo
00132 *draw_info;
00133
00134
Image
00135 *image;
00136
00137
MagickBooleanType
00138 status;
00139
00140 size_t
00141 length;
00142
00143
unsigned char
00144 *primitive;
00145
00146
00147
00148
00149
assert(image_info != (
const ImageInfo *) NULL);
00150
assert(image_info->
signature ==
MagickSignature);
00151
if (image_info->
debug !=
MagickFalse)
00152 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image_info->
filename);
00153
assert(exception != (
ExceptionInfo *) NULL);
00154
assert(exception->
signature ==
MagickSignature);
00155 image=
AllocateImage(image_info);
00156 status=
OpenBlob(image_info,image,
ReadBinaryBlobMode,exception);
00157
if (status ==
MagickFalse)
00158 {
00159
DestroyImageList(image);
00160
return((
Image *) NULL);
00161 }
00162
if ((image->
columns == 0) || (image->
rows == 0))
00163 {
00164
char
00165 primitive[
MaxTextExtent];
00166
00167
register char
00168 *p;
00169
00170
SegmentInfo
00171 bounds;
00172
00173
00174
00175
00176
while (
ReadBlobString(image,primitive) != (
char *) NULL)
00177 {
00178
for (p=primitive; (*p ==
' ') || (*p ==
'\t'); p++);
00179
if (
LocaleNCompare(
BoundingBox,p,strlen(
BoundingBox)) != 0)
00180
continue;
00181 (
void) sscanf(p,
"viewbox %lf %lf %lf %lf",&bounds.
x1,&bounds.
y1,
00182 &bounds.
x2,&bounds.
y2);
00183 image->
columns=(
unsigned long) ((bounds.
x2-bounds.
x1)+0.5);
00184 image->
rows=(
unsigned long) ((bounds.
y2-bounds.
y1)+0.5);
00185
break;
00186 }
00187 }
00188
if ((image->
columns == 0) || (image->
rows == 0))
00189
ThrowReaderException(
OptionError,
"MustSpecifyImageSize");
00190 draw_info=
CloneDrawInfo(image_info,(
DrawInfo *) NULL);
00191 draw_info->
affine.
sx=
00192 image->
x_resolution == 0.0 ? 1.0 : image->
x_resolution/72.0;
00193 draw_info->
affine.
sy=
00194 image->
y_resolution == 0.0 ? 1.0 : image->
y_resolution/72.0;
00195 image->
columns=(
unsigned long) (draw_info->
affine.
sx*image->
columns);
00196 image->
rows=(
unsigned long) (draw_info->
affine.
sy*image->
rows);
00197
SetImage(image,
OpaqueOpacity);
00198
00199
00200
00201 draw_info->
fill=image_info->
pen;
00202 primitive=
GetBlobStreamData(image);
00203
if (primitive != (
unsigned char) NULL)
00204 draw_info->
primitive=
AcquireString((
char *) primitive);
00205
else
00206 draw_info->
primitive=(
char *)
FileToBlob(image->
filename,&length,exception);
00207
if (draw_info->
primitive == (
char *) NULL)
00208
return((
Image *) NULL);
00209 (
void)
DrawImage(image,draw_info);
00210 draw_info=
DestroyDrawInfo(draw_info);
00211
CloseBlob(image);
00212
return(
GetFirstImageInList(image));
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 ModuleExport void RegisterMVGImage(
void)
00239 {
00240
MagickInfo
00241 *entry;
00242
00243 entry=
SetMagickInfo(
"MVG");
00244 entry->
decoder=(
DecoderHandler *)
ReadMVGImage;
00245 entry->
encoder=(
EncoderHandler *)
WriteMVGImage;
00246 entry->
magick=(
MagickHandler *)
IsMVG;
00247 entry->
adjoin=
MagickFalse;
00248 entry->
seekable_stream=
MagickTrue;
00249 entry->
description=
AcquireString(
"Magick Vector Graphics");
00250 entry->
module=
AcquireString(
"MVG");
00251 (
void)
RegisterMagickInfo(entry);
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 ModuleExport void UnregisterMVGImage(
void)
00274 {
00275 (
void)
UnregisterMagickInfo(
"MVG");
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 static MagickBooleanType WriteMVGImage(
const ImageInfo *image_info,
Image *image)
00304 {
00305
const ImageAttribute
00306 *attribute;
00307
00308
MagickBooleanType
00309 status;
00310
00311
00312
00313
00314
assert(image_info != (
const ImageInfo *) NULL);
00315
assert(image_info->
signature ==
MagickSignature);
00316
assert(image != (
Image *) NULL);
00317
assert(image->
signature ==
MagickSignature);
00318
if (image->
debug !=
MagickFalse)
00319 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image->
filename);
00320 attribute=
GetImageAttribute(image,
"[MVG]");
00321
if (attribute == (
ImageAttribute *) NULL)
00322
ThrowWriterException(
OptionError,
"NoImageVectorGraphics");
00323 status=
OpenBlob(image_info,image,
WriteBlobMode,&image->
exception);
00324
if (status ==
MagickFalse)
00325
return(status);
00326 (
void)
WriteBlob(image,strlen(attribute->
value),(
unsigned char *)
00327 attribute->
value);
00328
CloseBlob(image);
00329
return(
MagickTrue);
00330 }