blob: 6aa82cfbd466b50ea61fc192037ae2479da1a91e [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% L AAA BBBB EEEEE L %
7% L A A B B E L %
8% L AAAAA BBBB EEE L %
9% L A A B B E L %
10% LLLLL A A BBBB EEEEE LLLLL %
11% %
12% %
13% Read ASCII String As An Image. %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 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*/
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"
60
61/*
62%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63% %
64% %
65% %
66% R e a d L A B E L I m a g e %
67% %
68% %
69% %
70%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71%
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.
75%
76% The format of the ReadLABELImage method is:
77%
78% Image *ReadLABELImage(const ImageInfo *image_info,
79% ExceptionInfo *exception)
80%
81% A description of each parameter follows:
82%
83% o image_info: the image info.
84%
85% o exception: return any errors or warnings in this structure.
86%
87*/
88static Image *ReadLABELImage(const ImageInfo *image_info,
89 ExceptionInfo *exception)
90{
91 char
92 geometry[MaxTextExtent],
93 *property;
94
95 const char
96 *label;
97
98 DrawInfo
99 *draw_info;
100
101 Image
102 *image;
103
104 MagickBooleanType
105 status;
106
107 TypeMetric
108 metrics;
109
110 unsigned long
111 height,
112 width;
113
114 /*
115 Initialize Image structure.
116 */
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))
134 {
135 /*
136 Fit label to canvas size.
137 */
138 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
139 for ( ; status != MagickFalse; draw_info->pointsize*=2.0)
140 {
141 width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5);
142 height=(unsigned long) (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))))
145 break;
146 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
147 }
148 for ( ; status != MagickFalse; draw_info->pointsize--)
149 {
150 width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5);
151 height=(unsigned long) (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))))
154 break;
155 if ((image->rows != 0) && (height <= (image->rows+1)) &&
156 ((image->columns == 0) || (width <= (image->columns+1))))
157 break;
158 if (draw_info->pointsize < 2.0)
159 break;
160 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
161 }
162 }
163 status=GetMultilineTypeMetrics(image,draw_info,&metrics);
164 if (status == MagickFalse)
165 {
166 InheritException(exception,&image->exception);
167 image=DestroyImageList(image);
168 return((Image *) NULL);
169 }
170 if (image->columns == 0)
171 image->columns=(unsigned long) (metrics.width+draw_info->stroke_width+1.5);
172 if (image->columns == 0)
173 image->columns=(unsigned long) (draw_info->pointsize+
174 draw_info->stroke_width+1.5);
175 if (draw_info->gravity == UndefinedGravity)
176 {
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);
181 }
182 if (image->rows == 0)
183 image->rows=(unsigned long) (metrics.height+draw_info->stroke_width+0.5);
184 if (image->rows == 0)
185 image->rows=(unsigned long) (draw_info->pointsize+draw_info->stroke_width+
186 0.5);
187 (void) SetImageBackgroundColor(image);
188 (void) AnnotateImage(image,draw_info);
189 draw_info=DestroyDrawInfo(draw_info);
190 return(GetFirstImageInList(image));
191}
192
193/*
194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195% %
196% %
197% %
198% R e g i s t e r L A B E L I m a g e %
199% %
200% %
201% %
202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203%
204% RegisterLABELImage() adds properties for the LABEL image format to
205% the list of supported formats. The properties include the image format
206% tag, a method to read and/or write the format, whether the format
207% supports the saving of more than one frame to the same file or blob,
208% whether the format supports native in-memory I/O, and a brief
209% description of the format.
210%
211% The format of the RegisterLABELImage method is:
212%
213% unsigned long RegisterLABELImage(void)
214%
215*/
216ModuleExport unsigned long RegisterLABELImage(void)
217{
218 MagickInfo
219 *entry;
220
221 entry=SetMagickInfo("LABEL");
222 entry->decoder=(DecodeImageHandler *) ReadLABELImage;
223 entry->adjoin=MagickFalse;
224 entry->format_type=ExplicitFormatType;
225 entry->description=ConstantString("Image label");
226 entry->module=ConstantString("LABEL");
227 (void) RegisterMagickInfo(entry);
228 return(MagickImageCoderSignature);
229}
230
231/*
232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233% %
234% %
235% %
236% U n r e g i s t e r L A B E L I m a g e %
237% %
238% %
239% %
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241%
242% UnregisterLABELImage() removes format registrations made by the
243% LABEL module from the list of supported formats.
244%
245% The format of the UnregisterLABELImage method is:
246%
247% UnregisterLABELImage(void)
248%
249*/
250ModuleExport void UnregisterLABELImage(void)
251{
252 (void) UnregisterMagickInfo("LABEL");
253}