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/artifact.h"
45 #include "MagickCore/blob.h"
46 #include "MagickCore/blob-private.h"
47 #include "MagickCore/draw.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/magick.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/property.h"
56 #include "MagickCore/quantum-private.h"
57 #include "MagickCore/static.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/module.h"
60 #include "MagickCore/utility.h"
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % R e a d L A B E L I m a g e %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % ReadLABELImage() reads a LABEL image file and returns it. It
74 % allocates the memory necessary for the new Image structure and returns a
75 % pointer to the new image.
77 % The format of the ReadLABELImage method is:
79 % Image *ReadLABELImage(const ImageInfo *image_info,
80 % ExceptionInfo *exception)
82 % A description of each parameter follows:
84 % o image_info: the image info.
86 % o exception: return any errors or warnings in this structure.
89 static Image *ReadLABELImage(const ImageInfo *image_info,
90 ExceptionInfo *exception)
93 geometry[MaxTextExtent],
116 Initialize Image structure.
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,exception);
126 (void) ResetImagePage(image,"0x0+0+0");
127 property=InterpretImageProperties(image_info,image,image_info->filename,
129 (void) SetImageProperty(image,"label",property,exception);
130 property=DestroyString(property);
131 label=GetImageProperty(image,"label",exception);
132 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
133 draw_info->text=ConstantString(label);
134 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
135 if (image->columns == 0)
137 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
138 -metrics.bounds.x1,metrics.ascent);
139 if (draw_info->gravity == UndefinedGravity)
140 (void) CloneString(&draw_info->geometry,geometry);
141 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
143 image->columns=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
145 if (image->rows == 0)
147 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
148 -metrics.bounds.x1,metrics.ascent);
149 if (draw_info->gravity == UndefinedGravity)
150 (void) CloneString(&draw_info->geometry,geometry);
151 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
152 image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
154 if (image_info->pointsize == 0.0)
161 Auto fit text into bounding box.
163 for ( ; ; draw_info->pointsize*=2.0)
165 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
166 -metrics.bounds.x1,metrics.ascent);
167 if (draw_info->gravity == UndefinedGravity)
168 (void) CloneString(&draw_info->geometry,geometry);
169 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
170 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
171 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
172 if ((width >= image->columns) && (height >= image->rows))
174 if ((width >= (image->columns << 1)) || (height >= (image->rows << 1)))
177 high=draw_info->pointsize/2.0;
178 for (low=high/2.0; (high-low) > 1.0; )
180 draw_info->pointsize=(low+high)/2.0;
181 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
182 -metrics.bounds.x1,metrics.ascent);
183 if (draw_info->gravity == UndefinedGravity)
184 (void) CloneString(&draw_info->geometry,geometry);
185 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
186 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
187 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
188 if ((width <= image->columns) && (height <= image->rows))
189 low=draw_info->pointsize+1.0;
191 high=draw_info->pointsize-1.0;
193 for (draw_info->pointsize=(low+high)/2.0; (high-low) > 1.0; )
195 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
196 -metrics.bounds.x1,metrics.ascent);
197 if (draw_info->gravity == UndefinedGravity)
198 (void) CloneString(&draw_info->geometry,geometry);
199 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
200 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
201 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
202 if ((width <= image->columns) && (height <= image->rows))
204 draw_info->pointsize--;
206 draw_info->pointsize--;
208 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
209 if (status == MagickFalse)
211 image=DestroyImageList(image);
212 return((Image *) NULL);
214 if (draw_info->gravity == UndefinedGravity)
216 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
217 -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
218 draw_info->stroke_width/2.0);
219 (void) CloneString(&draw_info->geometry,geometry);
221 if (draw_info->direction == RightToLeftDirection)
223 if (draw_info->direction == RightToLeftDirection)
224 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
225 image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
226 metrics.ascent+draw_info->stroke_width/2.0);
227 (void) CloneString(&draw_info->geometry,geometry);
229 if (SetImageBackgroundColor(image,exception) == MagickFalse)
231 image=DestroyImageList(image);
232 return((Image *) NULL);
234 (void) AnnotateImage(image,draw_info,exception);
235 if (image_info->pointsize == 0.0)
238 pointsize[MaxTextExtent];
240 (void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g",
241 draw_info->pointsize);
242 (void) SetImageProperty(image,"label:pointsize",pointsize,exception);
244 draw_info=DestroyDrawInfo(draw_info);
245 return(GetFirstImageInList(image));
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % R e g i s t e r L A B E L I m a g e %
257 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 % RegisterLABELImage() adds properties for the LABEL image format to
260 % the list of supported formats. The properties include the image format
261 % tag, a method to read and/or write the format, whether the format
262 % supports the saving of more than one frame to the same file or blob,
263 % whether the format supports native in-memory I/O, and a brief
264 % description of the format.
266 % The format of the RegisterLABELImage method is:
268 % size_t RegisterLABELImage(void)
271 ModuleExport size_t RegisterLABELImage(void)
276 entry=SetMagickInfo("LABEL");
277 entry->decoder=(DecodeImageHandler *) ReadLABELImage;
278 entry->adjoin=MagickFalse;
279 entry->format_type=ImplicitFormatType;
280 entry->description=ConstantString("Image label");
281 entry->module=ConstantString("LABEL");
282 (void) RegisterMagickInfo(entry);
283 return(MagickImageCoderSignature);
287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291 % U n r e g i s t e r L A B E L I m a g e %
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 % UnregisterLABELImage() removes format registrations made by the
298 % LABEL module from the list of supported formats.
300 % The format of the UnregisterLABELImage method is:
302 % UnregisterLABELImage(void)
305 ModuleExport void UnregisterLABELImage(void)
307 (void) UnregisterMagickInfo("LABEL");