blob: 320b559fed108bfb0bc22ed8c32cd488bfcf8181 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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 %
16% John Cristy %
17% February 2002 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
43#include "MagickCore/annotate.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
cristy8a3ce7f2011-10-30 02:28:03 +000046#include "MagickCore/composite-private.h"
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickCore/draw.h"
cristy8a3ce7f2011-10-30 02:28:03 +000048#include "MagickCore/draw-private.h"
cristy4c08aed2011-07-01 19:47:50 +000049#include "MagickCore/exception.h"
50#include "MagickCore/exception-private.h"
51#include "MagickCore/image.h"
52#include "MagickCore/image-private.h"
53#include "MagickCore/list.h"
54#include "MagickCore/magick.h"
55#include "MagickCore/memory_.h"
cristy8a3ce7f2011-10-30 02:28:03 +000056#include "MagickCore/module.h"
cristy4c08aed2011-07-01 19:47:50 +000057#include "MagickCore/option.h"
58#include "MagickCore/property.h"
59#include "MagickCore/quantum-private.h"
60#include "MagickCore/static.h"
61#include "MagickCore/string_.h"
cristy8a3ce7f2011-10-30 02:28:03 +000062#include "MagickCore/string-private.h"
63#include "MagickCore/utility.h"
64#if defined(MAGICKCORE_PANGOFT2_DELEGATE)
65#include <pango/pango.h>
66#include <pango/pangoft2.h>
67#include <pango/pango-features.h>
68#endif
cristy3ed852e2009-09-05 21:47:34 +000069
70/*
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
75% R e a d C A P T I O N I m a g e %
76% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% ReadCAPTIONImage() reads a CAPTION image file and returns it. It
82% allocates the memory necessary for the new Image structure and returns a
83% pointer to the new image.
84%
85% The format of the ReadCAPTIONImage method is:
86%
87% Image *ReadCAPTIONImage(const ImageInfo *image_info,
88% ExceptionInfo *exception)
89%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
94% o exception: return any errors or warnings in this structure.
95%
96*/
cristy8a3ce7f2011-10-30 02:28:03 +000097#if defined(MAGICKCORE_PANGOFT2_DELEGATE)
98static void PangoSubstitute(FcPattern *pattern,void *context)
99{
100 const char
101 *option;
102
103 option=(const char *) context;
104 if (option == (const char *) NULL)
105 return;
106 FcPatternDel(pattern,FC_HINTING);
107 FcPatternAddBool(pattern, FC_HINTING,LocaleCompare(option,"none") != 0);
108 FcPatternDel(pattern,FC_AUTOHINT);
109 FcPatternAddBool(pattern,FC_AUTOHINT,LocaleCompare(option,"auto") == 0);
110}
111
112static Image *ReadCAPTIONImage(const ImageInfo *image_info,
113 ExceptionInfo *exception)
114{
115 char
116 *caption,
117 *property;
118
119 const char
120 *option;
121
122 DrawInfo
123 *draw_info;
124
125 FT_Bitmap
126 *canvas;
127
128 Image
129 *image;
130
131 PangoAlignment
132 align;
133
134 PangoContext
135 *context;
136
137 PangoFontDescription
138 *description;
139
140 PangoFontMap
141 *fontmap;
142
143 PangoGravity
144 gravity;
145
146 PangoLayout
147 *layout;
148
149 PangoRectangle
150 extent;
151
152 PixelInfo
153 fill_color;
154
155 RectangleInfo
156 page;
157
158 register Quantum
159 *q;
160
161 register unsigned char
162 *p;
163
164 ssize_t
165 y;
166
167 /*
168 Initialize Image structure.
169 */
170 assert(image_info != (const ImageInfo *) NULL);
171 assert(image_info->signature == MagickSignature);
172 if (image_info->debug != MagickFalse)
173 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
174 image_info->filename);
175 assert(exception != (ExceptionInfo *) NULL);
176 assert(exception->signature == MagickSignature);
177 image=AcquireImage(image_info,exception);
178 (void) ResetImagePage(image,"0x0+0+0");
179 /*
180 Get context.
181 */
182 fontmap=(PangoFontMap *) pango_ft2_font_map_new();
183 pango_ft2_font_map_set_resolution((PangoFT2FontMap *) fontmap,
184 image->resolution.x,image->resolution.y);
185 option=GetImageOption(image_info,"caption:hinting");
186 pango_ft2_font_map_set_default_substitute((PangoFT2FontMap *) fontmap,
187 PangoSubstitute,(char *) option,NULL);
188 context=pango_font_map_create_context(fontmap);
189 option=GetImageOption(image_info,"caption:language");
190 if (option != (const char *) NULL)
191 pango_context_set_language(context,pango_language_from_string(option));
192 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
193 pango_context_set_base_dir(context,draw_info->direction ==
194 RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR);
195 switch (draw_info->gravity)
196 {
197 case NorthGravity: gravity=PANGO_GRAVITY_NORTH; break;
198 case WestGravity: gravity=PANGO_GRAVITY_WEST; break;
199 case EastGravity: gravity=PANGO_GRAVITY_EAST; break;
200 case SouthGravity: gravity=PANGO_GRAVITY_SOUTH; break;
201 default: gravity=PANGO_GRAVITY_AUTO; break;
202 }
203 pango_context_set_base_gravity(context,gravity);
204 option=GetImageOption(image_info,"caption:gravity-hint");
205 if (option != (const char *) NULL)
206 {
207 if (LocaleCompare(option,"line") == 0)
208 pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_LINE);
209 if (LocaleCompare(option,"natural") == 0)
210 pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_NATURAL);
211 if (LocaleCompare(option,"strong") == 0)
212 pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_STRONG);
213 }
214 /*
215 Configure layout.
216 */
217 layout=pango_layout_new(context);
218 option=GetImageOption(image_info,"caption:auto-dir");
219 if (option != (const char *) NULL)
220 pango_layout_set_auto_dir(layout,1);
221 option=GetImageOption(image_info,"caption:ellipsize");
222 if (option != (const char *) NULL)
223 {
224 if (LocaleCompare(option,"end") == 0)
225 pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_END);
226 if (LocaleCompare(option,"middle") == 0)
227 pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_MIDDLE);
228 if (LocaleCompare(option,"none") == 0)
229 pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_NONE);
230 if (LocaleCompare(option,"start") == 0)
231 pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START);
232 }
233 option=GetImageOption(image_info,"caption:justify");
234 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse))
235 pango_layout_set_justify(layout,1);
236 option=GetImageOption(image_info,"caption:single-paragraph");
237 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse))
238 pango_layout_set_single_paragraph_mode(layout,1);
239 option=GetImageOption(image_info,"caption:wrap");
240 if (option != (const char *) NULL)
241 {
242 if (LocaleCompare(option,"char") == 0)
243 pango_layout_set_wrap(layout,PANGO_WRAP_CHAR);
244 if (LocaleCompare(option,"word") == 0)
245 pango_layout_set_wrap(layout,PANGO_WRAP_WORD);
246 if (LocaleCompare(option,"word-char") == 0)
247 pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR);
248 }
249 option=GetImageOption(image_info,"caption:indent");
250 if (option != (const char *) NULL)
251 pango_layout_set_indent(layout,(StringToLong(option)*image->resolution.x*
252 PANGO_SCALE+36)/72);
253 switch (draw_info->align)
254 {
255 case CenterAlign: align=PANGO_ALIGN_CENTER; break;
256 case RightAlign: align=PANGO_ALIGN_RIGHT; break;
257 case LeftAlign:
258 default: align=PANGO_ALIGN_LEFT; break;
259 }
260 if ((align != PANGO_ALIGN_CENTER) &&
261 (draw_info->direction == RightToLeftDirection))
cristy3fac9ec2011-11-17 18:04:39 +0000262 align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align);
cristy8a3ce7f2011-10-30 02:28:03 +0000263 pango_layout_set_alignment(layout,align);
264 description=pango_font_description_from_string(draw_info->font ==
265 (char *) NULL ? "helvetica" : draw_info->font);
266 pango_font_description_set_size(description,PANGO_SCALE*draw_info->pointsize);
267 pango_layout_set_font_description(layout,description);
268 pango_font_description_free(description);
269 property=InterpretImageProperties(image_info,image,image_info->filename,
270 exception);
271 (void) SetImageProperty(image,"caption",property,exception);
272 property=DestroyString(property);
273 caption=ConstantString(GetImageProperty(image,"caption",exception));
274 /*
275 Render caption.
276 */
277 option=GetImageOption(image_info,"caption:markup");
278 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse))
279 pango_layout_set_markup(layout,caption,-1);
280 else
281 pango_layout_set_text(layout,caption,-1);
282 pango_layout_context_changed(layout);
283 page.x=0;
284 page.y=0;
285 if (image_info->page != (char *) NULL)
286 (void) ParseAbsoluteGeometry(image_info->page,&page);
287 if (image->columns == 0)
288 {
289 pango_layout_get_pixel_extents(layout,NULL,&extent);
290 image->columns=extent.x+extent.width;
291 }
292 else
293 {
294 image->columns-=2*page.x;
295 pango_layout_set_width(layout,(PANGO_SCALE*image->columns*
296 image->resolution.x+36.0)/72.0);
297 }
298 if (image->rows == 0)
299 {
300 pango_layout_get_pixel_extents(layout,NULL,&extent);
301 image->rows=extent.y+extent.height;
302 }
303 else
304 {
305 image->rows-=2*page.y;
306 pango_layout_set_height(layout,(PANGO_SCALE*image->rows*
307 image->resolution.y+36.0)/72.0);
308 }
309 /*
310 Create canvas.
311 */
312 canvas=(FT_Bitmap *) AcquireMagickMemory(sizeof(*canvas));
313 if (canvas == (FT_Bitmap *) NULL)
314 {
315 draw_info=DestroyDrawInfo(draw_info);
316 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
317 }
318 canvas->width=image->columns;
319 canvas->pitch=(canvas->width+3) & ~3;
320 canvas->rows=image->rows;
321 canvas->buffer=(unsigned char *) AcquireQuantumMemory(canvas->pitch,
322 canvas->rows*sizeof(*canvas->buffer));
323 if (canvas->buffer == (unsigned char *) NULL)
324 {
325 draw_info=DestroyDrawInfo(draw_info);
326 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas);
327 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
328 }
329 canvas->num_grays=256;
330 canvas->pixel_mode=ft_pixel_mode_grays;
331 ResetMagickMemory(canvas->buffer,0x00,canvas->pitch*canvas->rows);
332 pango_ft2_render_layout(canvas,layout,0,0);
333 /*
334 Convert caption to image.
335 */
336 image->columns+=2*page.x;
337 image->rows+=2*page.y;
338 if (SetImageBackgroundColor(image,exception) == MagickFalse)
339 {
340 draw_info=DestroyDrawInfo(draw_info);
341 canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer);
342 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas);
343 caption=DestroyString(caption);
344 image=DestroyImageList(image);
345 return((Image *) NULL);
346 }
347 GetPixelInfo(image,&fill_color);
348 p=canvas->buffer;
349 for (y=page.y; y < (ssize_t) (image->rows-page.y); y++)
350 {
351 register ssize_t
352 x;
353
354 q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
355 if (q == (Quantum *) NULL)
356 break;
357 q+=page.x*GetPixelChannels(image);
358 for (x=page.x; x < (ssize_t) (image->columns-page.x); x++)
359 {
360 MagickRealType
cristyf5d0a1a2012-02-03 12:33:10 +0000361 fill_alpha;
cristy8a3ce7f2011-10-30 02:28:03 +0000362
363 (void) GetFillColor(draw_info,x,y,&fill_color,exception);
cristyf5d0a1a2012-02-03 12:33:10 +0000364 fill_alpha=(MagickRealType) (*p)/(canvas->num_grays-1);
cristy8a3ce7f2011-10-30 02:28:03 +0000365 if (draw_info->text_antialias == MagickFalse)
cristyf5d0a1a2012-02-03 12:33:10 +0000366 fill_alpha=fill_alpha >= 0.5 ? 1.0 : 0.0;
367 fill_alpha=fill_alpha*fill_color.alpha;
368 CompositePixelOver(image,&fill_color,fill_alpha,q,GetPixelAlpha(image,q),
369 q);
cristy8a3ce7f2011-10-30 02:28:03 +0000370 p++;
371 q+=GetPixelChannels(image);
372 }
373 for ( ; x < (ssize_t) ((canvas->width+3) & ~3); x++)
374 p++;
375 }
376 /*
377 Relinquish resources.
378 */
379 draw_info=DestroyDrawInfo(draw_info);
380 canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer);
381 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas);
382 caption=DestroyString(caption);
383 return(GetFirstImageInList(image));
384}
385#else
cristy3ed852e2009-09-05 21:47:34 +0000386static Image *ReadCAPTIONImage(const ImageInfo *image_info,
387 ExceptionInfo *exception)
388{
389 char
390 *caption,
391 geometry[MaxTextExtent],
392 *property;
393
394 const char
395 *gravity;
396
397 DrawInfo
398 *draw_info;
399
400 Image
401 *image;
402
403 MagickBooleanType
404 status;
405
cristybb503372010-05-27 20:51:26 +0000406 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000407 i;
408
cristybb503372010-05-27 20:51:26 +0000409 size_t
cristy3ed852e2009-09-05 21:47:34 +0000410 height,
411 width;
412
cristy4e82e512011-04-24 01:33:42 +0000413 TypeMetric
414 metrics;
415
cristy3ed852e2009-09-05 21:47:34 +0000416 /*
417 Initialize Image structure.
418 */
419 assert(image_info != (const ImageInfo *) NULL);
420 assert(image_info->signature == MagickSignature);
421 if (image_info->debug != MagickFalse)
422 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
423 image_info->filename);
424 assert(exception != (ExceptionInfo *) NULL);
425 assert(exception->signature == MagickSignature);
cristy9950d572011-10-01 18:22:35 +0000426 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000427 if (image->columns == 0)
428 ThrowReaderException(OptionError,"MustSpecifyImageSize");
429 (void) ResetImagePage(image,"0x0+0+0");
430 /*
431 Format caption.
432 */
cristy018f07f2011-09-04 21:15:19 +0000433 property=InterpretImageProperties(image_info,image,image_info->filename,
434 exception);
cristyd15e6592011-10-15 00:13:06 +0000435 (void) SetImageProperty(image,"caption",property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000436 property=DestroyString(property);
cristyd15e6592011-10-15 00:13:06 +0000437 caption=ConstantString(GetImageProperty(image,"caption",exception));
cristy3ed852e2009-09-05 21:47:34 +0000438 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
cristy6fc39292011-10-23 14:26:30 +0000439 (void) CloneString(&draw_info->text,caption);
cristy3ed852e2009-09-05 21:47:34 +0000440 gravity=GetImageOption(image_info,"gravity");
441 if (gravity != (char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000442 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy3ed852e2009-09-05 21:47:34 +0000443 MagickFalse,gravity);
444 if ((*caption != '\0') && (image->rows != 0) &&
445 (image_info->pointsize == 0.0))
446 {
447 char
448 *text;
449
450 /*
451 Scale text to fit bounding box.
452 */
453 for ( ; ; )
454 {
455 text=AcquireString(caption);
cristy5cbc0162011-08-29 00:36:28 +0000456 i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
457 exception);
cristy3ed852e2009-09-05 21:47:34 +0000458 (void) CloneString(&draw_info->text,text);
459 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000460 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
cristy3ed852e2009-09-05 21:47:34 +0000461 -metrics.bounds.x1,metrics.ascent);
462 if (draw_info->gravity == UndefinedGravity)
463 (void) CloneString(&draw_info->geometry,geometry);
cristy5cbc0162011-08-29 00:36:28 +0000464 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
cristyda16f162011-02-19 23:52:17 +0000465 (void) status;
cristybb503372010-05-27 20:51:26 +0000466 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
cristy4e82e512011-04-24 01:33:42 +0000467 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000468 if ((width > (image->columns+1)) || (height > (image->rows+1)))
469 break;
470 draw_info->pointsize*=2.0;
471 }
472 draw_info->pointsize/=2.0;
473 for ( ; ; )
474 {
475 text=AcquireString(caption);
cristy5cbc0162011-08-29 00:36:28 +0000476 i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text,
477 exception);
cristy3ed852e2009-09-05 21:47:34 +0000478 (void) CloneString(&draw_info->text,text);
479 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000480 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
cristy3ed852e2009-09-05 21:47:34 +0000481 -metrics.bounds.x1,metrics.ascent);
482 if (draw_info->gravity == UndefinedGravity)
483 (void) CloneString(&draw_info->geometry,geometry);
cristy5cbc0162011-08-29 00:36:28 +0000484 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
cristybb503372010-05-27 20:51:26 +0000485 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
cristy4e82e512011-04-24 01:33:42 +0000486 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000487 if ((width > (image->columns+1)) || (height > (image->rows+1)))
488 break;
489 draw_info->pointsize++;
490 }
491 draw_info->pointsize--;
492 }
cristy5cbc0162011-08-29 00:36:28 +0000493 i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&caption,exception);
cristy3ed852e2009-09-05 21:47:34 +0000494 if (image->rows == 0)
cristybb503372010-05-27 20:51:26 +0000495 image->rows=(size_t) ((i+1)*(metrics.ascent-metrics.descent+
cristycc2fb022011-04-01 14:08:37 +0000496 draw_info->interline_spacing+draw_info->stroke_width)+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000497 if (image->rows == 0)
cristybb503372010-05-27 20:51:26 +0000498 image->rows=(size_t) ((i+1)*draw_info->pointsize+
cristycc2fb022011-04-01 14:08:37 +0000499 draw_info->interline_spacing+draw_info->stroke_width+0.5);
cristyea1a8aa2011-10-20 13:24:06 +0000500 if (SetImageBackgroundColor(image,exception) == MagickFalse)
cristy95524f92010-02-16 18:44:34 +0000501 {
cristy95524f92010-02-16 18:44:34 +0000502 image=DestroyImageList(image);
503 return((Image *) NULL);
504 }
cristy3ed852e2009-09-05 21:47:34 +0000505 /*
506 Draw caption.
507 */
508 (void) CloneString(&draw_info->text,caption);
cristy5cbc0162011-08-29 00:36:28 +0000509 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
cristy024843f2011-06-03 17:52:52 +0000510 if ((draw_info->gravity != UndefinedGravity) &&
511 (draw_info->direction != RightToLeftDirection))
cristybb503372010-05-27 20:51:26 +0000512 image->page.x=(ssize_t) (metrics.bounds.x1-draw_info->stroke_width/2.0);
cristy3ed852e2009-09-05 21:47:34 +0000513 else
514 {
cristyb51dff52011-05-19 16:55:47 +0000515 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
cristy3ed852e2009-09-05 21:47:34 +0000516 -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
517 draw_info->stroke_width/2.0);
cristy024843f2011-06-03 17:52:52 +0000518 if (draw_info->direction == RightToLeftDirection)
519 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
520 image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
521 metrics.ascent+draw_info->stroke_width/2.0);
522 draw_info->geometry=AcquireString(geometry);
cristy3ed852e2009-09-05 21:47:34 +0000523 }
cristy5cbc0162011-08-29 00:36:28 +0000524 (void) AnnotateImage(image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000525 draw_info=DestroyDrawInfo(draw_info);
526 caption=DestroyString(caption);
527 return(GetFirstImageInList(image));
528}
cristy8a3ce7f2011-10-30 02:28:03 +0000529#endif
cristy3ed852e2009-09-05 21:47:34 +0000530
531/*
532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533% %
534% %
535% %
536% R e g i s t e r C A P T I O N I m a g e %
537% %
538% %
539% %
540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541%
542% RegisterCAPTIONImage() adds attributes for the CAPTION image format to
543% the list of supported formats. The attributes include the image format
544% tag, a method to read and/or write the format, whether the format
545% supports the saving of more than one frame to the same file or blob,
546% whether the format supports native in-memory I/O, and a brief
547% description of the format.
548%
549% The format of the RegisterCAPTIONImage method is:
550%
cristybb503372010-05-27 20:51:26 +0000551% size_t RegisterCAPTIONImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000552%
553*/
cristybb503372010-05-27 20:51:26 +0000554ModuleExport size_t RegisterCAPTIONImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000555{
cristy8a3ce7f2011-10-30 02:28:03 +0000556 char
557 version[MaxTextExtent];
558
cristy3ed852e2009-09-05 21:47:34 +0000559 MagickInfo
560 *entry;
561
cristy8a3ce7f2011-10-30 02:28:03 +0000562 *version='\0';
563#if defined(PANGO_VERSION_STRING)
cristyc3f33352011-11-19 03:01:16 +0000564 (void) FormatLocaleString(version,MaxTextExtent,"Pangoft2 %s",
cristy8a3ce7f2011-10-30 02:28:03 +0000565 PANGO_VERSION_STRING);
566#endif
cristy3ed852e2009-09-05 21:47:34 +0000567 entry=SetMagickInfo("CAPTION");
568 entry->decoder=(DecodeImageHandler *) ReadCAPTIONImage;
cristy8a3ce7f2011-10-30 02:28:03 +0000569 entry->description=ConstantString("Caption");
570 if (*version != '\0')
571 entry->version=ConstantString(version);
cristy3ed852e2009-09-05 21:47:34 +0000572 entry->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000573 entry->module=ConstantString("CAPTION");
574 (void) RegisterMagickInfo(entry);
575 return(MagickImageCoderSignature);
576}
577
578/*
579%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
580% %
581% %
582% %
583% U n r e g i s t e r C A P T I O N I m a g e %
584% %
585% %
586% %
587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588%
589% UnregisterCAPTIONImage() removes format registrations made by the
590% CAPTION module from the list of supported formats.
591%
592% The format of the UnregisterCAPTIONImage method is:
593%
594% UnregisterCAPTIONImage(void)
595%
596*/
597ModuleExport void UnregisterCAPTIONImage(void)
598{
599 (void) UnregisterMagickInfo("CAPTION");
600}