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/annotate.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
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 static Image *
ReadCAPTIONImage(
const ImageInfo *image_info,
00086
ExceptionInfo *
exception)
00087 {
00088
char
00089 *caption,
00090 geometry[
MaxTextExtent];
00091
00092
DrawInfo
00093 *draw_info;
00094
00095
Image
00096 *image;
00097
00098
MagickBooleanType
00099 status;
00100
00101
register char
00102 *p,
00103 *q;
00104
00105
register long
00106 i;
00107
00108
TypeMetric
00109 metrics;
00110
00111
00112
00113
00114
assert(image_info != (
const ImageInfo *) NULL);
00115
assert(image_info->
signature ==
MagickSignature);
00116
if (image_info->
debug !=
MagickFalse)
00117 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image_info->
filename);
00118
assert(exception != (
ExceptionInfo *) NULL);
00119
assert(exception->
signature ==
MagickSignature);
00120 image=
AllocateImage(image_info);
00121
if (image->
columns == 0)
00122
ThrowReaderException(
OptionError,
"MustSpecifyImageSize");
00123
if (*image_info->
filename !=
'@')
00124 caption=
AcquireString(image_info->
filename);
00125
else
00126 {
00127 size_t
00128 length;
00129
00130
00131
00132
00133 (
void)
CopyMagickString(image->
filename,image_info->
filename+1,
00134
MaxTextExtent-2);
00135 status=
OpenBlob(image_info,image,
ReadBinaryBlobMode,exception);
00136
if (status ==
MagickFalse)
00137 {
00138
DestroyImageList(image);
00139
return((
Image *) NULL);
00140 }
00141 length=
MaxTextExtent;
00142 caption=
AcquireString((
char *) NULL);
00143 p=caption;
00144
while (
ReadBlobString(image,p) != (
char *) NULL)
00145 {
00146 p+=strlen(p);
00147
if ((size_t) (p-caption+
MaxTextExtent) < length)
00148
continue;
00149 length<<=1;
00150 caption=(
char *)
ResizeMagickMemory(caption,
00151 (length+
MaxTextExtent)*
sizeof(*caption));
00152
if (caption == (
char *) NULL)
00153
break;
00154 p=caption+strlen(caption);
00155 }
00156
if (caption == (
char *) NULL)
00157
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00158
CloseBlob(image);
00159 }
00160
00161
00162
00163 draw_info=
CloneDrawInfo(image_info,(
DrawInfo *) NULL);
00164 draw_info->
fill=image_info->
pen;
00165 draw_info->
text=
AcquireString(caption);
00166 p=caption;
00167 q=draw_info->
text;
00168
for (i=0; *p !=
'\0'; p++)
00169 {
00170 *q++=(*p);
00171 *q=
'\0';
00172 status=
GetTypeMetrics(image,draw_info,&metrics);
00173
if (status ==
MagickFalse)
00174
ThrowReaderException(
TypeError,
"UnableToGetTypeMetrics");
00175
if ((metrics.
width+metrics.
max_advance/2) < (
double) image->
columns)
00176
continue;
00177
for (p--; (isspace((
int) ((
unsigned char) *p)) == 0) && (p > caption); p--);
00178 *p++=
'\n';
00179 q=draw_info->
text;
00180 i++;
00181 }
00182
if (image->
rows == 0)
00183 image->
rows=(
unsigned long) ((i+1)*(metrics.
ascent-metrics.
descent));
00184
SetImage(image,
OpaqueOpacity);
00185
00186
00187
00188 (
void) strcpy(draw_info->
text,caption);
00189 (
void)
FormatMagickString(geometry,
MaxTextExtent,
"+%g+%g",
00190 metrics.
max_advance/4,metrics.
ascent);
00191 draw_info->
geometry=
AcquireString(geometry);
00192 (
void)
AnnotateImage(image,draw_info);
00193 draw_info=
DestroyDrawInfo(draw_info);
00194 caption=(
char *)
RelinquishMagickMemory(caption);
00195
return(
GetFirstImageInList(image));
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 ModuleExport void RegisterCAPTIONImage(
void)
00222 {
00223
MagickInfo
00224 *entry;
00225
00226 entry=
SetMagickInfo(
"CAPTION");
00227 entry->
decoder=(
DecoderHandler *)
ReadCAPTIONImage;
00228 entry->
adjoin=
MagickFalse;
00229 entry->
description=
AcquireString(
"Image caption");
00230 entry->
module=
AcquireString(
"CAPTION");
00231 (
void)
RegisterMagickInfo(entry);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 ModuleExport void UnregisterCAPTIONImage(
void)
00254 {
00255 (
void)
UnregisterMagickInfo(
"CAPTION");
00256 }