2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 % LLLLL A A BBBB EEEEE LLLLL %
13 % Read ASCII String As An Image. %
20 % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % R e a d L A B E L I m a g e %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % ReadLABELImage() reads a LABEL image file and returns it. It
73 % allocates the memory necessary for the new Image structure and returns a
74 % pointer to the new image.
76 % The format of the ReadLABELImage method is:
78 % Image *ReadLABELImage(const ImageInfo *image_info,
79 % ExceptionInfo *exception)
81 % A description of each parameter follows:
83 % o image_info: the image info.
85 % o exception: return any errors or warnings in this structure.
88 static Image *ReadLABELImage(const ImageInfo *image_info,
89 ExceptionInfo *exception)
92 geometry[MaxTextExtent],
115 Initialize Image structure.
117 assert(image_info != (const ImageInfo *) NULL);
118 assert(image_info->signature == MagickSignature);
119 if (image_info->debug != MagickFalse)
120 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
121 image_info->filename);
122 assert(exception != (ExceptionInfo *) NULL);
123 assert(exception->signature == MagickSignature);
124 image=AcquireImage(image_info);
125 (void) ResetImagePage(image,"0x0+0+0");
126 property=InterpretImageProperties(image_info,image,image_info->filename);
127 (void) SetImageProperty(image,"label",property);
128 property=DestroyString(property);
129 label=GetImageProperty(image,"label");
130 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
131 draw_info->text=ConstantString(label);
132 if (((image->columns != 0) || (image->rows != 0)) &&
133 (image_info->pointsize == 0.0))
136 Fit label to canvas size.
138 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
139 for ( ; status != MagickFalse; draw_info->pointsize*=2.0)
141 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
142 height=(size_t) floor(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))))
146 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
148 for ( ; status != MagickFalse; draw_info->pointsize--)
150 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
151 height=(size_t) floor(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))))
155 if ((image->rows != 0) && (height <= (image->rows+1)) &&
156 ((image->columns == 0) || (width <= (image->columns+1))))
158 if (draw_info->pointsize < 2.0)
160 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
163 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
164 if (status == MagickFalse)
166 InheritException(exception,&image->exception);
167 image=DestroyImageList(image);
168 return((Image *) NULL);
170 if (image->columns == 0)
171 image->columns=(size_t) (metrics.width+draw_info->stroke_width+1.5);
172 if (image->columns == 0)
173 image->columns=(size_t) (draw_info->pointsize+
174 draw_info->stroke_width+1.5);
175 if (draw_info->gravity == UndefinedGravity)
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);
182 if (image->rows == 0)
183 image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+
185 if (image->rows == 0)
186 image->rows=(size_t) floor(draw_info->pointsize+
187 draw_info->stroke_width+0.5);
188 if (SetImageBackgroundColor(image) == MagickFalse)
190 InheritException(exception,&image->exception);
191 image=DestroyImageList(image);
192 return((Image *) NULL);
194 (void) AnnotateImage(image,draw_info);
195 if (image_info->pointsize == 0.0)
198 pointsize[MaxTextExtent];
200 (void) FormatMagickString(pointsize,MaxTextExtent,"%.20g",
201 draw_info->pointsize);
202 (void) SetImageProperty(image,"label:pointsize",pointsize);
204 draw_info=DestroyDrawInfo(draw_info);
205 return(GetFirstImageInList(image));
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 % R e g i s t e r L A B E L I m a g e %
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % RegisterLABELImage() adds properties for the LABEL image format to
220 % the list of supported formats. The properties include the image format
221 % tag, a method to read and/or write the format, whether the format
222 % supports the saving of more than one frame to the same file or blob,
223 % whether the format supports native in-memory I/O, and a brief
224 % description of the format.
226 % The format of the RegisterLABELImage method is:
228 % size_t RegisterLABELImage(void)
231 ModuleExport size_t RegisterLABELImage(void)
236 entry=SetMagickInfo("LABEL");
237 entry->decoder=(DecodeImageHandler *) ReadLABELImage;
238 entry->adjoin=MagickFalse;
239 entry->format_type=ImplicitFormatType;
240 entry->description=ConstantString("Image label");
241 entry->module=ConstantString("LABEL");
242 (void) RegisterMagickInfo(entry);
243 return(MagickImageCoderSignature);
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % U n r e g i s t e r L A B E L I m a g e %
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 % UnregisterLABELImage() removes format registrations made by the
258 % LABEL module from the list of supported formats.
260 % The format of the UnregisterLABELImage method is:
262 % UnregisterLABELImage(void)
265 ModuleExport void UnregisterLABELImage(void)
267 (void) UnregisterMagickInfo("LABEL");