| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | #include "magick/studio.h" |
|---|
| 43 | #include "magick/annotate.h" |
|---|
| 44 | #include "magick/blob.h" |
|---|
| 45 | #include "magick/blob-private.h" |
|---|
| 46 | #include "magick/draw.h" |
|---|
| 47 | #include "magick/exception.h" |
|---|
| 48 | #include "magick/exception-private.h" |
|---|
| 49 | #include "magick/image.h" |
|---|
| 50 | #include "magick/image-private.h" |
|---|
| 51 | #include "magick/list.h" |
|---|
| 52 | #include "magick/magick.h" |
|---|
| 53 | #include "magick/memory_.h" |
|---|
| 54 | #include "magick/option.h" |
|---|
| 55 | #include "magick/property.h" |
|---|
| 56 | #include "magick/quantum-private.h" |
|---|
| 57 | #include "magick/static.h" |
|---|
| 58 | #include "magick/string_.h" |
|---|
| 59 | #include "magick/module.h" |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | static Image *ReadCAPTIONImage(const ImageInfo *image_info, |
|---|
| 89 | ExceptionInfo *exception) |
|---|
| 90 | { |
|---|
| 91 | char |
|---|
| 92 | *caption, |
|---|
| 93 | geometry[MaxTextExtent], |
|---|
| 94 | *property; |
|---|
| 95 | |
|---|
| 96 | const char |
|---|
| 97 | *gravity; |
|---|
| 98 | |
|---|
| 99 | DrawInfo |
|---|
| 100 | *draw_info; |
|---|
| 101 | |
|---|
| 102 | Image |
|---|
| 103 | *image; |
|---|
| 104 | |
|---|
| 105 | MagickBooleanType |
|---|
| 106 | status; |
|---|
| 107 | |
|---|
| 108 | register long |
|---|
| 109 | i; |
|---|
| 110 | |
|---|
| 111 | TypeMetric |
|---|
| 112 | metrics; |
|---|
| 113 | |
|---|
| 114 | unsigned long |
|---|
| 115 | height, |
|---|
| 116 | width; |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 122 | assert(image_info->signature == MagickSignature); |
|---|
| 123 | if (image_info->debug != MagickFalse) |
|---|
| 124 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 125 | image_info->filename); |
|---|
| 126 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 127 | assert(exception->signature == MagickSignature); |
|---|
| 128 | image=AcquireImage(image_info); |
|---|
| 129 | if (image->columns == 0) |
|---|
| 130 | ThrowReaderException(OptionError,"MustSpecifyImageSize"); |
|---|
| 131 | (void) ResetImagePage(image,"0x0+0+0"); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | property=InterpretImageProperties(image_info,image,image_info->filename); |
|---|
| 136 | (void) SetImageProperty(image,"caption",property); |
|---|
| 137 | property=DestroyString(property); |
|---|
| 138 | caption=ConstantString(GetImageProperty(image,"caption")); |
|---|
| 139 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
|---|
| 140 | draw_info->text=ConstantString(caption); |
|---|
| 141 | gravity=GetImageOption(image_info,"gravity"); |
|---|
| 142 | if (gravity != (char *) NULL) |
|---|
| 143 | draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions, |
|---|
| 144 | MagickFalse,gravity); |
|---|
| 145 | if ((*caption != '\0') && (image->rows != 0) && |
|---|
| 146 | (image_info->pointsize == 0.0)) |
|---|
| 147 | { |
|---|
| 148 | char |
|---|
| 149 | *text; |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | for ( ; ; ) |
|---|
| 155 | { |
|---|
| 156 | text=AcquireString(caption); |
|---|
| 157 | i=FormatMagickCaption(image,draw_info,text,&metrics); |
|---|
| 158 | (void) CloneString(&draw_info->text,text); |
|---|
| 159 | text=DestroyString(text); |
|---|
| 160 | (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", |
|---|
| 161 | -metrics.bounds.x1,metrics.ascent); |
|---|
| 162 | if (draw_info->gravity == UndefinedGravity) |
|---|
| 163 | (void) CloneString(&draw_info->geometry,geometry); |
|---|
| 164 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 165 | width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); |
|---|
| 166 | height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); |
|---|
| 167 | if ((width > (image->columns+1)) || (height > (image->rows+1))) |
|---|
| 168 | break; |
|---|
| 169 | draw_info->pointsize*=2.0; |
|---|
| 170 | } |
|---|
| 171 | draw_info->pointsize/=2.0; |
|---|
| 172 | for ( ; ; ) |
|---|
| 173 | { |
|---|
| 174 | text=AcquireString(caption); |
|---|
| 175 | i=FormatMagickCaption(image,draw_info,text,&metrics); |
|---|
| 176 | (void) CloneString(&draw_info->text,text); |
|---|
| 177 | text=DestroyString(text); |
|---|
| 178 | (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", |
|---|
| 179 | -metrics.bounds.x1,metrics.ascent); |
|---|
| 180 | if (draw_info->gravity == UndefinedGravity) |
|---|
| 181 | (void) CloneString(&draw_info->geometry,geometry); |
|---|
| 182 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 183 | width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); |
|---|
| 184 | height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); |
|---|
| 185 | if ((width > (image->columns+1)) || (height > (image->rows+1))) |
|---|
| 186 | break; |
|---|
| 187 | draw_info->pointsize++; |
|---|
| 188 | } |
|---|
| 189 | draw_info->pointsize--; |
|---|
| 190 | } |
|---|
| 191 | i=FormatMagickCaption(image,draw_info,caption,&metrics); |
|---|
| 192 | if (image->rows == 0) |
|---|
| 193 | image->rows=(unsigned long) ((i+1)*(metrics.ascent-metrics.descent+ |
|---|
| 194 | draw_info->stroke_width)+0.5); |
|---|
| 195 | if (image->rows == 0) |
|---|
| 196 | image->rows=(unsigned long) ((i+1)*draw_info->pointsize+ |
|---|
| 197 | draw_info->stroke_width+0.5); |
|---|
| 198 | (void) SetImageBackgroundColor(image); |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | (void) CloneString(&draw_info->text,caption); |
|---|
| 203 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 204 | (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", |
|---|
| 205 | -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+ |
|---|
| 206 | draw_info->stroke_width/2.0); |
|---|
| 207 | if (draw_info->gravity == UndefinedGravity) |
|---|
| 208 | (void) CloneString(&draw_info->geometry,geometry); |
|---|
| 209 | (void) AnnotateImage(image,draw_info); |
|---|
| 210 | draw_info=DestroyDrawInfo(draw_info); |
|---|
| 211 | caption=DestroyString(caption); |
|---|
| 212 | return(GetFirstImageInList(image)); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | ModuleExport unsigned long RegisterCAPTIONImage(void) |
|---|
| 239 | { |
|---|
| 240 | MagickInfo |
|---|
| 241 | *entry; |
|---|
| 242 | |
|---|
| 243 | entry=SetMagickInfo("CAPTION"); |
|---|
| 244 | entry->decoder=(DecodeImageHandler *) ReadCAPTIONImage; |
|---|
| 245 | entry->adjoin=MagickFalse; |
|---|
| 246 | entry->format_type=ImplicitFormatType; |
|---|
| 247 | entry->description=ConstantString("Image caption"); |
|---|
| 248 | entry->module=ConstantString("CAPTION"); |
|---|
| 249 | (void) RegisterMagickInfo(entry); |
|---|
| 250 | return(MagickImageCoderSignature); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | ModuleExport void UnregisterCAPTIONImage(void) |
|---|
| 273 | { |
|---|
| 274 | (void) UnregisterMagickInfo("CAPTION"); |
|---|
| 275 | } |
|---|