2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 % LLLLL A A BBBB EEEEE LLLLL %
13 % Read ASCII String As An Image. %
20 % Copyright 1999-2013 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 "MagickCore/studio.h"
43 #include "MagickCore/annotate.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/draw.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/property.h"
55 #include "MagickCore/quantum-private.h"
56 #include "MagickCore/static.h"
57 #include "MagickCore/string_.h"
58 #include "MagickCore/module.h"
59 #include "MagickCore/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,exception);
125 (void) ResetImagePage(image,"0x0+0+0");
126 property=InterpretImageProperties(image_info,image,image_info->filename,
128 (void) SetImageProperty(image,"label",property,exception);
129 property=DestroyString(property);
130 label=GetImageProperty(image,"label",exception);
131 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
132 draw_info->text=ConstantString(label);
133 if ((*label != '\0') && (image->rows != 0) && (image_info->pointsize == 0.0))
140 Auto fit text into bounding box.
142 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
145 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
146 -metrics.bounds.x1,metrics.ascent);
147 if (draw_info->gravity == UndefinedGravity)
148 (void) CloneString(&draw_info->geometry,geometry);
149 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
151 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
152 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
153 if (((image->columns != 0) && (width > image->columns)) ||
154 ((image->rows != 0) && (height > image->rows)))
156 draw_info->pointsize*=2.0;
158 high=draw_info->pointsize/2.0;
160 while ((high-low) > 1.0)
162 draw_info->pointsize=(low+high)/2.0;
163 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
164 -metrics.bounds.x1,metrics.ascent);
165 if (draw_info->gravity == UndefinedGravity)
166 (void) CloneString(&draw_info->geometry,geometry);
167 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
168 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
169 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
170 if (((image->columns != 0) && (width <= image->columns)) ||
171 ((image->rows != 0) && (height <= image->rows)))
172 low=draw_info->pointsize+1.0;
174 high=draw_info->pointsize-1.0;
176 for (draw_info->pointsize=(low+high)/2.0; ; )
178 (void) FormatLocaleString(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,exception);
183 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
184 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
185 if (((image->columns != 0) && (width <= image->columns)) ||
186 ((image->rows != 0) && (height <= image->rows)))
188 draw_info->pointsize--;
190 draw_info->pointsize=floor(draw_info->pointsize);
192 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
193 if (status == MagickFalse)
195 image=DestroyImageList(image);
196 return((Image *) NULL);
198 if (image->columns == 0)
199 image->columns=(size_t) (metrics.width+draw_info->stroke_width+1.5);
200 if (image->columns == 0)
201 image->columns=(size_t) (draw_info->pointsize+draw_info->stroke_width+1.5);
202 if (draw_info->gravity == UndefinedGravity)
204 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
205 -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
206 draw_info->stroke_width/2.0);
207 (void) CloneString(&draw_info->geometry,geometry);
209 if (draw_info->direction == RightToLeftDirection)
211 if (draw_info->direction == RightToLeftDirection)
212 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
213 image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
214 metrics.ascent+draw_info->stroke_width/2.0);
215 (void) CloneString(&draw_info->geometry,geometry);
217 if (image->rows == 0)
218 image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
219 if (image->rows == 0)
220 image->rows=(size_t) floor(draw_info->pointsize+draw_info->stroke_width+
222 if (SetImageBackgroundColor(image,exception) == MagickFalse)
224 image=DestroyImageList(image);
225 return((Image *) NULL);
227 (void) AnnotateImage(image,draw_info,exception);
228 if (image_info->pointsize == 0.0)
231 pointsize[MaxTextExtent];
233 (void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g",
234 draw_info->pointsize);
235 (void) SetImageProperty(image,"label:pointsize",pointsize,exception);
237 draw_info=DestroyDrawInfo(draw_info);
238 return(GetFirstImageInList(image));
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 % R e g i s t e r L A B E L I m a g e %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % RegisterLABELImage() adds properties for the LABEL image format to
253 % the list of supported formats. The properties include the image format
254 % tag, a method to read and/or write the format, whether the format
255 % supports the saving of more than one frame to the same file or blob,
256 % whether the format supports native in-memory I/O, and a brief
257 % description of the format.
259 % The format of the RegisterLABELImage method is:
261 % size_t RegisterLABELImage(void)
264 ModuleExport size_t RegisterLABELImage(void)
269 entry=SetMagickInfo("LABEL");
270 entry->decoder=(DecodeImageHandler *) ReadLABELImage;
271 entry->adjoin=MagickFalse;
272 entry->format_type=ImplicitFormatType;
273 entry->description=ConstantString("Image label");
274 entry->module=ConstantString("LABEL");
275 (void) RegisterMagickInfo(entry);
276 return(MagickImageCoderSignature);
280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 % U n r e g i s t e r L A B E L I m a g e %
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 % UnregisterLABELImage() removes format registrations made by the
291 % LABEL module from the list of supported formats.
293 % The format of the UnregisterLABELImage method is:
295 % UnregisterLABELImage(void)
298 ModuleExport void UnregisterLABELImage(void)
300 (void) UnregisterMagickInfo("LABEL");