cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC AAA PPPP TTTTT IIIII OOO N N % |
| 7 | % C A A P P T I O O NN N % |
| 8 | % C AAAAA PPPP T I O O N N N % |
| 9 | % C A A P T I O O N NN % |
| 10 | % CCCC A A P T IIIII OOO N N % |
| 11 | % % |
| 12 | % % |
| 13 | % Read Text Caption. % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % February 2002 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/annotate.h" |
cristy | 76ce6e1 | 2013-04-05 14:33:38 +0000 | [diff] [blame] | 44 | #include "MagickCore/artifact.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 45 | #include "MagickCore/blob.h" |
| 46 | #include "MagickCore/blob-private.h" |
cristy | 8a3ce7f | 2011-10-30 02:28:03 +0000 | [diff] [blame] | 47 | #include "MagickCore/composite-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickCore/draw.h" |
cristy | 8a3ce7f | 2011-10-30 02:28:03 +0000 | [diff] [blame] | 49 | #include "MagickCore/draw-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/exception.h" |
| 51 | #include "MagickCore/exception-private.h" |
| 52 | #include "MagickCore/image.h" |
| 53 | #include "MagickCore/image-private.h" |
| 54 | #include "MagickCore/list.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
cristy | 8a3ce7f | 2011-10-30 02:28:03 +0000 | [diff] [blame] | 57 | #include "MagickCore/module.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 58 | #include "MagickCore/option.h" |
| 59 | #include "MagickCore/property.h" |
| 60 | #include "MagickCore/quantum-private.h" |
| 61 | #include "MagickCore/static.h" |
| 62 | #include "MagickCore/string_.h" |
cristy | 8a3ce7f | 2011-10-30 02:28:03 +0000 | [diff] [blame] | 63 | #include "MagickCore/string-private.h" |
| 64 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 68 | % % |
| 69 | % % |
| 70 | % % |
| 71 | % R e a d C A P T I O N I m a g e % |
| 72 | % % |
| 73 | % % |
| 74 | % % |
| 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 76 | % |
| 77 | % ReadCAPTIONImage() reads a CAPTION image file and returns it. It |
| 78 | % allocates the memory necessary for the new Image structure and returns a |
| 79 | % pointer to the new image. |
| 80 | % |
| 81 | % The format of the ReadCAPTIONImage method is: |
| 82 | % |
| 83 | % Image *ReadCAPTIONImage(const ImageInfo *image_info, |
| 84 | % ExceptionInfo *exception) |
| 85 | % |
| 86 | % A description of each parameter follows: |
| 87 | % |
| 88 | % o image_info: the image info. |
| 89 | % |
| 90 | % o exception: return any errors or warnings in this structure. |
| 91 | % |
| 92 | */ |
| 93 | static Image *ReadCAPTIONImage(const ImageInfo *image_info, |
| 94 | ExceptionInfo *exception) |
| 95 | { |
| 96 | char |
| 97 | *caption, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 98 | geometry[MagickPathExtent], |
cristy | 54ec427 | 2013-03-14 14:24:14 +0000 | [diff] [blame] | 99 | *property, |
| 100 | *text; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | |
| 102 | const char |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 103 | *gravity, |
| 104 | *option; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 105 | |
| 106 | DrawInfo |
| 107 | *draw_info; |
| 108 | |
| 109 | Image |
| 110 | *image; |
| 111 | |
| 112 | MagickBooleanType |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 113 | split, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 114 | status; |
| 115 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 116 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 117 | i; |
| 118 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 119 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 120 | height, |
| 121 | width; |
| 122 | |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 123 | TypeMetric |
| 124 | metrics; |
| 125 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 126 | /* |
| 127 | Initialize Image structure. |
| 128 | */ |
| 129 | assert(image_info != (const ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 130 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | if (image_info->debug != MagickFalse) |
| 132 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 133 | image_info->filename); |
| 134 | assert(exception != (ExceptionInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 135 | assert(exception->signature == MagickCoreSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 136 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | (void) ResetImagePage(image,"0x0+0+0"); |
| 138 | /* |
| 139 | Format caption. |
| 140 | */ |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 141 | option=GetImageOption(image_info,"filename"); |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 142 | if (option == (const char *) NULL) |
cristy | e67f43f | 2013-04-29 10:27:50 +0000 | [diff] [blame] | 143 | property=InterpretImageProperties((ImageInfo *) image_info,image, |
| 144 | image_info->filename,exception); |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 145 | else |
| 146 | if (LocaleNCompare(option,"caption:",8) == 0) |
cristy | e67f43f | 2013-04-29 10:27:50 +0000 | [diff] [blame] | 147 | property=InterpretImageProperties((ImageInfo *) image_info,image,option+8, |
| 148 | exception); |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 149 | else |
cristy | e67f43f | 2013-04-29 10:27:50 +0000 | [diff] [blame] | 150 | property=InterpretImageProperties((ImageInfo *) image_info,image,option, |
| 151 | exception); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 152 | (void) SetImageProperty(image,"caption",property,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | property=DestroyString(property); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 154 | caption=ConstantString(GetImageProperty(image,"caption",exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); |
cristy | 6fc3929 | 2011-10-23 14:26:30 +0000 | [diff] [blame] | 156 | (void) CloneString(&draw_info->text,caption); |
cristy | 092ec8d | 2013-04-26 13:46:22 +0000 | [diff] [blame] | 157 | gravity=GetImageOption(image_info,"gravity"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | if (gravity != (char *) NULL) |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 159 | draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | MagickFalse,gravity); |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 161 | split=MagickFalse; |
cristy | 8db9ca4 | 2013-03-14 13:35:37 +0000 | [diff] [blame] | 162 | if (image->columns == 0) |
| 163 | { |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 164 | text=AcquireString(caption); |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 165 | i=FormatMagickCaption(image,draw_info,split,&metrics,&text, |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 166 | exception); |
| 167 | (void) CloneString(&draw_info->text,text); |
| 168 | text=DestroyString(text); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 169 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", |
cristy | b05c534 | 2015-02-19 16:01:46 +0000 | [diff] [blame] | 170 | -metrics.bounds.x1,metrics.ascent); |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 171 | if (draw_info->gravity == UndefinedGravity) |
| 172 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | b712c6e | 2013-04-14 21:43:41 +0000 | [diff] [blame] | 173 | status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception); |
cristy | a492593 | 2013-04-14 21:14:20 +0000 | [diff] [blame] | 174 | width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); |
cristy | 8db9ca4 | 2013-03-14 13:35:37 +0000 | [diff] [blame] | 175 | image->columns=width; |
| 176 | } |
| 177 | if (image->rows == 0) |
| 178 | { |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 179 | split=MagickTrue; |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 180 | text=AcquireString(caption); |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 181 | i=FormatMagickCaption(image,draw_info,split,&metrics,&text, |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 182 | exception); |
| 183 | (void) CloneString(&draw_info->text,text); |
| 184 | text=DestroyString(text); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 185 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", |
cristy | b05c534 | 2015-02-19 16:01:46 +0000 | [diff] [blame] | 186 | -metrics.bounds.x1,metrics.ascent); |
cristy | e275ada | 2013-04-14 22:29:40 +0000 | [diff] [blame] | 187 | if (draw_info->gravity == UndefinedGravity) |
| 188 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | a492593 | 2013-04-14 21:14:20 +0000 | [diff] [blame] | 189 | status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception); |
cristy | b05c534 | 2015-02-19 16:01:46 +0000 | [diff] [blame] | 190 | image->rows=(size_t) ((i+1)*(metrics.ascent-metrics.descent+ |
cristy | 54ec427 | 2013-03-14 14:24:14 +0000 | [diff] [blame] | 191 | draw_info->interline_spacing+draw_info->stroke_width)+0.5); |
cristy | 8db9ca4 | 2013-03-14 13:35:37 +0000 | [diff] [blame] | 192 | } |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 193 | status=SetImageExtent(image,image->columns,image->rows,exception); |
| 194 | if (status == MagickFalse) |
| 195 | { |
| 196 | draw_info=DestroyDrawInfo(draw_info); |
| 197 | return(DestroyImageList(image)); |
| 198 | } |
| 199 | if (SetImageBackgroundColor(image,exception) == MagickFalse) |
| 200 | { |
| 201 | draw_info=DestroyDrawInfo(draw_info); |
| 202 | image=DestroyImageList(image); |
| 203 | return((Image *) NULL); |
| 204 | } |
cristy | a492593 | 2013-04-14 21:14:20 +0000 | [diff] [blame] | 205 | if (fabs(image_info->pointsize) < MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | { |
cristy | bdf24b2 | 2012-05-24 12:20:45 +0000 | [diff] [blame] | 207 | double |
| 208 | high, |
| 209 | low; |
| 210 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | /* |
cristy | bdf24b2 | 2012-05-24 12:20:45 +0000 | [diff] [blame] | 212 | Auto fit text into bounding box. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | */ |
cristy | 8592b05 | 2013-02-07 01:24:54 +0000 | [diff] [blame] | 214 | for ( ; ; draw_info->pointsize*=2.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | { |
| 216 | text=AcquireString(caption); |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 217 | i=FormatMagickCaption(image,draw_info,split,&metrics,&text, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 218 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | (void) CloneString(&draw_info->text,text); |
| 220 | text=DestroyString(text); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 221 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", |
cristy | b05c534 | 2015-02-19 16:01:46 +0000 | [diff] [blame] | 222 | -metrics.bounds.x1,metrics.ascent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | if (draw_info->gravity == UndefinedGravity) |
| 224 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 225 | status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 226 | width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 227 | height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 228 | if ((image->columns != 0) && (image->rows != 0)) |
| 229 | { |
cristy | cae9c06 | 2013-05-13 11:46:22 +0000 | [diff] [blame] | 230 | if ((width >= image->columns) && (height >= image->rows)) |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 231 | break; |
| 232 | } |
| 233 | else |
cristy | cae9c06 | 2013-05-13 11:46:22 +0000 | [diff] [blame] | 234 | if (((image->columns != 0) && (width >= image->columns)) || |
| 235 | ((image->rows != 0) && (height >= image->rows))) |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 236 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 237 | } |
cristy | 0839c55 | 2013-04-14 21:45:02 +0000 | [diff] [blame] | 238 | high=draw_info->pointsize; |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 239 | for (low=1.0; (high-low) > 0.5; ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | { |
cristy | bdf24b2 | 2012-05-24 12:20:45 +0000 | [diff] [blame] | 241 | draw_info->pointsize=(low+high)/2.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 242 | text=AcquireString(caption); |
cristy | a530273 | 2013-05-30 22:26:58 +0000 | [diff] [blame] | 243 | i=FormatMagickCaption(image,draw_info,split,&metrics,&text, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 244 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 245 | (void) CloneString(&draw_info->text,text); |
| 246 | text=DestroyString(text); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 247 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", |
cristy | b05c534 | 2015-02-19 16:01:46 +0000 | [diff] [blame] | 248 | -metrics.bounds.x1,metrics.ascent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | if (draw_info->gravity == UndefinedGravity) |
| 250 | (void) CloneString(&draw_info->geometry,geometry); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 251 | status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 252 | width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); |
cristy | 4e82e51 | 2011-04-24 01:33:42 +0000 | [diff] [blame] | 253 | height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 254 | if ((image->columns != 0) && (image->rows != 0)) |
| 255 | { |
cristy | cae9c06 | 2013-05-13 11:46:22 +0000 | [diff] [blame] | 256 | if ((width < image->columns) && (height < image->rows)) |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 257 | low=draw_info->pointsize+0.5; |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 258 | else |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 259 | high=draw_info->pointsize-0.5; |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 260 | } |
cristy | bdf24b2 | 2012-05-24 12:20:45 +0000 | [diff] [blame] | 261 | else |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 262 | if (((image->columns != 0) && (width < image->columns)) || |
| 263 | ((image->rows != 0) && (height < image->rows))) |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 264 | low=draw_info->pointsize+0.5; |
cristy | 071c2e2 | 2013-05-11 01:05:45 +0000 | [diff] [blame] | 265 | else |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 266 | high=draw_info->pointsize-0.5; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | } |
cristy | 7426358 | 2013-05-30 23:47:06 +0000 | [diff] [blame] | 268 | draw_info->pointsize=(low+high)/2.0-0.5; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 270 | /* |
| 271 | Draw caption. |
| 272 | */ |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 273 | i=FormatMagickCaption(image,draw_info,split,&metrics,&caption,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 274 | (void) CloneString(&draw_info->text,caption); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 275 | (void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g", |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 276 | draw_info->direction == RightToLeftDirection ? image->columns- |
| 277 | metrics.bounds.x2 : -metrics.bounds.x1,draw_info->gravity == |
| 278 | UndefinedGravity ? metrics.ascent : 0.0); |
| 279 | draw_info->geometry=AcquireString(geometry); |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 280 | status=AnnotateImage(image,draw_info,exception); |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 281 | if (image_info->pointsize == 0.0) |
| 282 | { |
| 283 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 284 | pointsize[MagickPathExtent]; |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 285 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 286 | (void) FormatLocaleString(pointsize,MagickPathExtent,"%.20g", |
cristy | 176d1cd | 2015-02-20 17:44:44 +0000 | [diff] [blame] | 287 | draw_info->pointsize); |
| 288 | (void) SetImageProperty(image,"caption:pointsize",pointsize,exception); |
| 289 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 290 | draw_info=DestroyDrawInfo(draw_info); |
| 291 | caption=DestroyString(caption); |
cristy | ab272ac | 2012-03-04 22:08:07 +0000 | [diff] [blame] | 292 | if (status == MagickFalse) |
| 293 | { |
| 294 | image=DestroyImageList(image); |
| 295 | return((Image *) NULL); |
| 296 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | return(GetFirstImageInList(image)); |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | % R e g i s t e r C A P T I O N I m a g e % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % RegisterCAPTIONImage() adds attributes for the CAPTION image format to |
| 312 | % the list of supported formats. The attributes include the image format |
| 313 | % tag, a method to read and/or write the format, whether the format |
| 314 | % supports the saving of more than one frame to the same file or blob, |
| 315 | % whether the format supports native in-memory I/O, and a brief |
| 316 | % description of the format. |
| 317 | % |
| 318 | % The format of the RegisterCAPTIONImage method is: |
| 319 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 320 | % size_t RegisterCAPTIONImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 321 | % |
| 322 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 323 | ModuleExport size_t RegisterCAPTIONImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 324 | { |
| 325 | MagickInfo |
| 326 | *entry; |
| 327 | |
dirk | 06b627a | 2015-04-06 18:59:17 +0000 | [diff] [blame] | 328 | entry=AcquireMagickInfo("CAPTION","CAPTION","Caption"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | entry->decoder=(DecodeImageHandler *) ReadCAPTIONImage; |
dirk | 08e9a11 | 2015-02-22 01:51:41 +0000 | [diff] [blame] | 330 | entry->flags^=CoderAdjoinFlag; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 331 | (void) RegisterMagickInfo(entry); |
| 332 | return(MagickImageCoderSignature); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 337 | % % |
| 338 | % % |
| 339 | % % |
| 340 | % U n r e g i s t e r C A P T I O N I m a g e % |
| 341 | % % |
| 342 | % % |
| 343 | % % |
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 345 | % |
| 346 | % UnregisterCAPTIONImage() removes format registrations made by the |
| 347 | % CAPTION module from the list of supported formats. |
| 348 | % |
| 349 | % The format of the UnregisterCAPTIONImage method is: |
| 350 | % |
| 351 | % UnregisterCAPTIONImage(void) |
| 352 | % |
| 353 | */ |
| 354 | ModuleExport void UnregisterCAPTIONImage(void) |
| 355 | { |
| 356 | (void) UnregisterMagickInfo("CAPTION"); |
| 357 | } |