| 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/property.h" |
|---|
| 55 | #include "magick/quantum-private.h" |
|---|
| 56 | #include "magick/static.h" |
|---|
| 57 | #include "magick/string_.h" |
|---|
| 58 | #include "magick/module.h" |
|---|
| 59 | #include "magick/utility.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 | |
|---|
| 89 | static Image *ReadLABELImage(const ImageInfo *image_info, |
|---|
| 90 | ExceptionInfo *exception) |
|---|
| 91 | { |
|---|
| 92 | char |
|---|
| 93 | geometry[MaxTextExtent], |
|---|
| 94 | *property; |
|---|
| 95 | |
|---|
| 96 | const char |
|---|
| 97 | *label; |
|---|
| 98 | |
|---|
| 99 | DrawInfo |
|---|
| 100 | *draw_info; |
|---|
| 101 | |
|---|
| 102 | Image |
|---|
| 103 | *image; |
|---|
| 104 | |
|---|
| 105 | MagickBooleanType |
|---|
| 106 | status; |
|---|
| 107 | |
|---|
| 108 | TypeMetric |
|---|
| 109 | metrics; |
|---|
| 110 | |
|---|
| 111 | unsigned long |
|---|
| 112 | height, |
|---|
| 113 | width; |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 119 | assert(image_info->signature == MagickSignature); |
|---|
| 120 | if (image_info->debug != MagickFalse) |
|---|
| 121 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 122 | image_info->filename); |
|---|
| 123 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 124 | assert(exception->signature == MagickSignature); |
|---|
| 125 | image=AcquireImage(image_info); |
|---|
| 126 | (void) ResetImagePage(image,"0x0+0+0"); |
|---|
| 127 | property=InterpretImageProperties(image_info,image,image_info->filename); |
|---|
| 128 | (void) SetImageProperty(image,"label",property); |
|---|
| 129 | property=DestroyString(property); |
|---|
| 130 | label=GetImageProperty(image,"label"); |
|---|
| 131 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
|---|
| 132 | draw_info->text=ConstantString(label); |
|---|
| 133 | if ((image->columns != 0) || (image->rows != 0)) |
|---|
| 134 | { |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 139 | for ( ; status != MagickFalse; draw_info->pointsize*=2.0) |
|---|
| 140 | { |
|---|
| 141 | width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); |
|---|
| 142 | height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); |
|---|
| 143 | if (((image->columns != 0) && (width > (image->columns+1))) || |
|---|
| 144 | ((image->rows != 0) && (height > (image->rows+1)))) |
|---|
| 145 | break; |
|---|
| 146 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 147 | } |
|---|
| 148 | for ( ; status != MagickFalse; draw_info->pointsize--) |
|---|
| 149 | { |
|---|
| 150 | width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); |
|---|
| 151 | height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); |
|---|
| 152 | if ((image->columns != 0) && (width <= (image->columns+1)) && |
|---|
| 153 | ((image->rows == 0) || (height <= (image->rows+1)))) |
|---|
| 154 | break; |
|---|
| 155 | if ((image->rows != 0) && (height <= (image->rows+1)) && |
|---|
| 156 | ((image->columns == 0) || (width <= (image->columns+1)))) |
|---|
| 157 | break; |
|---|
| 158 | if (draw_info->pointsize < 2.0) |
|---|
| 159 | break; |
|---|
| 160 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | status=GetMultilineTypeMetrics(image,draw_info,&metrics); |
|---|
| 164 | if (status == MagickFalse) |
|---|
| 165 | { |
|---|
| 166 | InheritException(exception,&image->exception); |
|---|
| 167 | image=DestroyImageList(image); |
|---|
| 168 | return((Image *) NULL); |
|---|
| 169 | } |
|---|
| 170 | if (image->columns == 0) |
|---|
| 171 | image->columns=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); |
|---|
| 172 | if (image->columns == 0) |
|---|
| 173 | image->columns=(unsigned long) (draw_info->pointsize+ |
|---|
| 174 | draw_info->stroke_width+0.5); |
|---|
| 175 | if (draw_info->gravity == UndefinedGravity) |
|---|
| 176 | { |
|---|
| 177 | (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", |
|---|
| 178 | -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+ |
|---|
| 179 | draw_info->stroke_width/2.0); |
|---|
| 180 | draw_info->geometry=AcquireString(geometry); |
|---|
| 181 | } |
|---|
| 182 | if (image->rows == 0) |
|---|
| 183 | image->rows=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); |
|---|
| 184 | if (image->rows == 0) |
|---|
| 185 | image->rows=(unsigned long) (draw_info->pointsize+draw_info->stroke_width+ |
|---|
| 186 | 0.5); |
|---|
| 187 | if (SetImageExtent(image,0,0) == MagickFalse) |
|---|
| 188 | { |
|---|
| 189 | InheritException(exception,&image->exception); |
|---|
| 190 | return(DestroyImageList(image)); |
|---|
| 191 | } |
|---|
| 192 | (void) SetImageBackgroundColor(image); |
|---|
| 193 | (void) AnnotateImage(image,draw_info); |
|---|
| 194 | draw_info=DestroyDrawInfo(draw_info); |
|---|
| 195 | return(GetFirstImageInList(image)); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | ModuleExport unsigned long RegisterLABELImage(void) |
|---|
| 222 | { |
|---|
| 223 | MagickInfo |
|---|
| 224 | *entry; |
|---|
| 225 | |
|---|
| 226 | entry=SetMagickInfo("LABEL"); |
|---|
| 227 | entry->decoder=(DecodeImageHandler *) ReadLABELImage; |
|---|
| 228 | entry->adjoin=MagickFalse; |
|---|
| 229 | entry->format_type=ImplicitFormatType; |
|---|
| 230 | entry->description=ConstantString("Image label"); |
|---|
| 231 | entry->module=ConstantString("LABEL"); |
|---|
| 232 | (void) RegisterMagickInfo(entry); |
|---|
| 233 | return(MagickImageCoderSignature); |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | ModuleExport void UnregisterLABELImage(void) |
|---|
| 256 | { |
|---|
| 257 | (void) UnregisterMagickInfo("LABEL"); |
|---|
| 258 | } |
|---|