cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % AAA N N N N OOO TTTTT AAA TTTTT EEEEE % |
| 7 | % A A NN N NN N O O T A A T E % |
| 8 | % AAAAA N N N N N N O O T AAAAA T EEE % |
| 9 | % A A N NN N NN O O T A A T E % |
| 10 | % A A N N N N OOO T A A T EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Annotation Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % 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 | % Digital Applications (www.digapp.com) contributed the stroked text algorithm. |
| 37 | % It was written by Leonard Rosenthol. |
| 38 | % |
| 39 | % |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | Include declarations. |
| 44 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 45 | #include "MagickCore/studio.h" |
| 46 | #include "MagickCore/annotate.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 47 | #include "MagickCore/annotate-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 48 | #include "MagickCore/attribute.h" |
| 49 | #include "MagickCore/cache-view.h" |
| 50 | #include "MagickCore/client.h" |
| 51 | #include "MagickCore/color.h" |
| 52 | #include "MagickCore/color-private.h" |
cristy | 54b9262 | 2012-04-09 18:42:06 +0000 | [diff] [blame] | 53 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 54 | #include "MagickCore/composite.h" |
| 55 | #include "MagickCore/composite-private.h" |
| 56 | #include "MagickCore/constitute.h" |
| 57 | #include "MagickCore/draw.h" |
| 58 | #include "MagickCore/draw-private.h" |
| 59 | #include "MagickCore/exception.h" |
| 60 | #include "MagickCore/exception-private.h" |
| 61 | #include "MagickCore/gem.h" |
| 62 | #include "MagickCore/geometry.h" |
| 63 | #include "MagickCore/image-private.h" |
| 64 | #include "MagickCore/log.h" |
| 65 | #include "MagickCore/quantum.h" |
| 66 | #include "MagickCore/quantum-private.h" |
| 67 | #include "MagickCore/pixel-accessor.h" |
| 68 | #include "MagickCore/property.h" |
| 69 | #include "MagickCore/resource_.h" |
| 70 | #include "MagickCore/semaphore.h" |
| 71 | #include "MagickCore/statistic.h" |
| 72 | #include "MagickCore/string_.h" |
| 73 | #include "MagickCore/token-private.h" |
| 74 | #include "MagickCore/transform.h" |
| 75 | #include "MagickCore/type.h" |
| 76 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 77 | #include "MagickCore/utility-private.h" |
cristy | bcbda3f | 2011-09-03 13:01:22 +0000 | [diff] [blame] | 78 | #include "MagickCore/xwindow.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 79 | #include "MagickCore/xwindow-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | #if defined(MAGICKCORE_FREETYPE_DELEGATE) |
| 81 | #if defined(__MINGW32__) |
| 82 | # undef interface |
| 83 | #endif |
cristy | 637d950 | 2011-10-03 18:47:13 +0000 | [diff] [blame] | 84 | #if defined(MAGICKCORE_HAVE_FT2BUILD_H) |
| 85 | # include <ft2build.h> |
| 86 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 87 | #if defined(FT_FREETYPE_H) |
| 88 | # include FT_FREETYPE_H |
| 89 | #else |
| 90 | # include <freetype/freetype.h> |
| 91 | #endif |
| 92 | #if defined(FT_GLYPH_H) |
| 93 | # include FT_GLYPH_H |
| 94 | #else |
| 95 | # include <freetype/ftglyph.h> |
| 96 | #endif |
| 97 | #if defined(FT_OUTLINE_H) |
| 98 | # include FT_OUTLINE_H |
| 99 | #else |
| 100 | # include <freetype/ftoutln.h> |
| 101 | #endif |
| 102 | #if defined(FT_BBOX_H) |
| 103 | # include FT_BBOX_H |
| 104 | #else |
| 105 | # include <freetype/ftbbox.h> |
| 106 | #endif /* defined(FT_BBOX_H) */ |
| 107 | #endif |
| 108 | |
| 109 | /* |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 110 | Annotate semaphores. |
| 111 | */ |
| 112 | static SemaphoreInfo |
| 113 | *annotate_semaphore = (SemaphoreInfo *) NULL; |
| 114 | |
| 115 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | Forward declarations. |
| 117 | */ |
| 118 | static MagickBooleanType |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 119 | RenderType(Image *,const DrawInfo *,const PointInfo *,TypeMetric *, |
| 120 | ExceptionInfo *), |
| 121 | RenderPostscript(Image *,const DrawInfo *,const PointInfo *,TypeMetric *, |
| 122 | ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | RenderFreetype(Image *,const DrawInfo *,const char *,const PointInfo *, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 124 | TypeMetric *,ExceptionInfo *), |
| 125 | RenderX11(Image *,const DrawInfo *,const PointInfo *,TypeMetric *, |
| 126 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 130 | % % |
| 131 | % % |
| 132 | % % |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 133 | + A n n o t a t e C o m p o n e n t G e n e s i s % |
| 134 | % % |
| 135 | % % |
| 136 | % % |
| 137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 | % |
| 139 | % AnnotateComponentGenesis() instantiates the annotate component. |
| 140 | % |
| 141 | % The format of the AnnotateComponentGenesis method is: |
| 142 | % |
| 143 | % MagickBooleanType AnnotateComponentGenesis(void) |
| 144 | % |
| 145 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 146 | MagickPrivate MagickBooleanType AnnotateComponentGenesis(void) |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 147 | { |
| 148 | AcquireSemaphoreInfo(&annotate_semaphore); |
| 149 | return(MagickTrue); |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 154 | % % |
| 155 | % % |
| 156 | % % |
| 157 | + A n n o t a t e C o m p o n e n t T e r m i n u s % |
| 158 | % % |
| 159 | % % |
| 160 | % % |
| 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 162 | % |
| 163 | % AnnotateComponentTerminus() destroys the annotate component. |
| 164 | % |
| 165 | % The format of the AnnotateComponentTerminus method is: |
| 166 | % |
| 167 | % AnnotateComponentTerminus(void) |
| 168 | % |
| 169 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 170 | MagickPrivate void AnnotateComponentTerminus(void) |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 171 | { |
| 172 | if (annotate_semaphore == (SemaphoreInfo *) NULL) |
| 173 | AcquireSemaphoreInfo(&annotate_semaphore); |
| 174 | DestroySemaphoreInfo(&annotate_semaphore); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 179 | % % |
| 180 | % % |
| 181 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | % A n n o t a t e I m a g e % |
| 183 | % % |
| 184 | % % |
| 185 | % % |
| 186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 187 | % |
| 188 | % AnnotateImage() annotates an image with text. Optionally you can include |
| 189 | % any of the following bits of information about the image by embedding |
| 190 | % the appropriate special characters: |
| 191 | % |
| 192 | % %b file size in bytes. |
| 193 | % %c comment. |
| 194 | % %d directory in which the image resides. |
| 195 | % %e extension of the image file. |
| 196 | % %f original filename of the image. |
| 197 | % %h height of image. |
| 198 | % %i filename of the image. |
| 199 | % %k number of unique colors. |
| 200 | % %l image label. |
| 201 | % %m image file format. |
| 202 | % %n number of images in a image sequence. |
| 203 | % %o output image filename. |
| 204 | % %p page number of the image. |
| 205 | % %q image depth (8 or 16). |
| 206 | % %q image depth (8 or 16). |
| 207 | % %s image scene number. |
| 208 | % %t image filename without any extension. |
| 209 | % %u a unique temporary filename. |
| 210 | % %w image width. |
| 211 | % %x x resolution of the image. |
| 212 | % %y y resolution of the image. |
| 213 | % |
| 214 | % The format of the AnnotateImage method is: |
| 215 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 216 | % MagickBooleanType AnnotateImage(Image *image,DrawInfo *draw_info, |
| 217 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 218 | % |
| 219 | % A description of each parameter follows: |
| 220 | % |
| 221 | % o image: the image. |
| 222 | % |
| 223 | % o draw_info: the draw info. |
| 224 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 225 | % o exception: return any errors or warnings in this structure. |
| 226 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | */ |
| 228 | MagickExport MagickBooleanType AnnotateImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 229 | const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 230 | { |
| 231 | char |
| 232 | primitive[MaxTextExtent], |
| 233 | **textlist; |
| 234 | |
| 235 | DrawInfo |
| 236 | *annotate, |
| 237 | *annotate_info; |
| 238 | |
| 239 | GeometryInfo |
| 240 | geometry_info; |
| 241 | |
| 242 | MagickBooleanType |
| 243 | status; |
| 244 | |
| 245 | PointInfo |
| 246 | offset; |
| 247 | |
| 248 | RectangleInfo |
| 249 | geometry; |
| 250 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 251 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | i; |
| 253 | |
| 254 | size_t |
| 255 | length; |
| 256 | |
| 257 | TypeMetric |
| 258 | metrics; |
| 259 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 260 | size_t |
cristy | 5846039 | 2009-09-09 01:52:06 +0000 | [diff] [blame] | 261 | height, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 262 | number_lines; |
| 263 | |
| 264 | assert(image != (Image *) NULL); |
| 265 | assert(image->signature == MagickSignature); |
| 266 | if (image->debug != MagickFalse) |
| 267 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 268 | assert(draw_info != (DrawInfo *) NULL); |
| 269 | assert(draw_info->signature == MagickSignature); |
| 270 | if (draw_info->text == (char *) NULL) |
| 271 | return(MagickFalse); |
| 272 | if (*draw_info->text == '\0') |
| 273 | return(MagickTrue); |
| 274 | textlist=StringToList(draw_info->text); |
| 275 | if (textlist == (char **) NULL) |
| 276 | return(MagickFalse); |
| 277 | length=strlen(textlist[0]); |
| 278 | for (i=1; textlist[i] != (char *) NULL; i++) |
| 279 | if (strlen(textlist[i]) > length) |
| 280 | length=strlen(textlist[i]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 281 | number_lines=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | annotate=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 283 | annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 284 | SetGeometry(image,&geometry); |
| 285 | SetGeometryInfo(&geometry_info); |
| 286 | if (annotate_info->geometry != (char *) NULL) |
| 287 | { |
| 288 | (void) ParsePageGeometry(image,annotate_info->geometry,&geometry, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 289 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 290 | (void) ParseGeometry(annotate_info->geometry,&geometry_info); |
| 291 | } |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 292 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | return(MagickFalse); |
cristy | 574c5b0 | 2012-04-09 16:33:15 +0000 | [diff] [blame] | 294 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
cristy | b09db11 | 2012-07-11 12:04:31 +0000 | [diff] [blame^] | 295 | (void) TransformImageColorspace(image,RGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | status=MagickTrue; |
| 297 | for (i=0; textlist[i] != (char *) NULL; i++) |
| 298 | { |
| 299 | /* |
| 300 | Position text relative to image. |
| 301 | */ |
| 302 | annotate_info->affine.tx=geometry_info.xi-image->page.x; |
| 303 | annotate_info->affine.ty=geometry_info.psi-image->page.y; |
| 304 | (void) CloneString(&annotate->text,textlist[i]); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 305 | (void) GetTypeMetrics(image,annotate,&metrics,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 306 | height=(ssize_t) (metrics.ascent-metrics.descent+ |
cristy | 5846039 | 2009-09-09 01:52:06 +0000 | [diff] [blame] | 307 | draw_info->interline_spacing+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | switch (annotate->gravity) |
| 309 | { |
| 310 | case UndefinedGravity: |
| 311 | default: |
| 312 | { |
| 313 | offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height; |
| 314 | offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height; |
| 315 | break; |
| 316 | } |
| 317 | case NorthWestGravity: |
| 318 | { |
| 319 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i* |
| 320 | annotate_info->affine.ry*height+annotate_info->affine.ry* |
| 321 | (metrics.ascent+metrics.descent); |
| 322 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i* |
| 323 | annotate_info->affine.sy*height+annotate_info->affine.sy* |
| 324 | metrics.ascent; |
| 325 | break; |
| 326 | } |
| 327 | case NorthGravity: |
| 328 | { |
| 329 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+ |
| 330 | geometry.width/2.0+i*annotate_info->affine.ry*height- |
| 331 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0+ |
| 332 | annotate_info->affine.ry*(metrics.ascent+metrics.descent); |
| 333 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i* |
| 334 | annotate_info->affine.sy*height+annotate_info->affine.sy* |
| 335 | metrics.ascent-annotate_info->affine.rx*(metrics.width- |
| 336 | metrics.bounds.x1)/2.0; |
| 337 | break; |
| 338 | } |
| 339 | case NorthEastGravity: |
| 340 | { |
| 341 | offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+ |
| 342 | geometry.width+i*annotate_info->affine.ry*height- |
| 343 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)+ |
| 344 | annotate_info->affine.ry*(metrics.ascent+metrics.descent)-1.0; |
| 345 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+i* |
| 346 | annotate_info->affine.sy*height+annotate_info->affine.sy* |
| 347 | metrics.ascent-annotate_info->affine.rx*(metrics.width- |
| 348 | metrics.bounds.x1); |
| 349 | break; |
| 350 | } |
| 351 | case WestGravity: |
| 352 | { |
| 353 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i* |
| 354 | annotate_info->affine.ry*height+annotate_info->affine.ry* |
| 355 | (metrics.ascent+metrics.descent-(number_lines-1.0)*height)/2.0; |
| 356 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+ |
| 357 | geometry.height/2.0+i*annotate_info->affine.sy*height+ |
| 358 | annotate_info->affine.sy*(metrics.ascent+metrics.descent- |
| 359 | (number_lines-1.0)*height)/2.0; |
| 360 | break; |
| 361 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 362 | case CenterGravity: |
| 363 | { |
| 364 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+ |
| 365 | geometry.width/2.0+i*annotate_info->affine.ry*height- |
| 366 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0+ |
| 367 | annotate_info->affine.ry*(metrics.ascent+metrics.descent- |
| 368 | (number_lines-1)*height)/2.0; |
| 369 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+ |
| 370 | geometry.height/2.0+i*annotate_info->affine.sy*height- |
| 371 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0+ |
| 372 | annotate_info->affine.sy*(metrics.ascent+metrics.descent- |
| 373 | (number_lines-1.0)*height)/2.0; |
| 374 | break; |
| 375 | } |
| 376 | case EastGravity: |
| 377 | { |
| 378 | offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+ |
| 379 | geometry.width+i*annotate_info->affine.ry*height- |
| 380 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)+ |
| 381 | annotate_info->affine.ry*(metrics.ascent+metrics.descent- |
| 382 | (number_lines-1.0)*height)/2.0-1.0; |
| 383 | offset.y=(geometry.height == 0 ? -1.0 : 1.0)*annotate_info->affine.ty+ |
| 384 | geometry.height/2.0+i*annotate_info->affine.sy*height- |
| 385 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)+ |
| 386 | annotate_info->affine.sy*(metrics.ascent+metrics.descent- |
| 387 | (number_lines-1.0)*height)/2.0; |
| 388 | break; |
| 389 | } |
| 390 | case SouthWestGravity: |
| 391 | { |
| 392 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+i* |
| 393 | annotate_info->affine.ry*height-annotate_info->affine.ry* |
| 394 | (number_lines-1.0)*height; |
| 395 | offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+ |
| 396 | geometry.height+i*annotate_info->affine.sy*height- |
| 397 | annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent; |
| 398 | break; |
| 399 | } |
| 400 | case SouthGravity: |
| 401 | { |
| 402 | offset.x=(geometry.width == 0 ? -1.0 : 1.0)*annotate_info->affine.tx+ |
| 403 | geometry.width/2.0+i*annotate_info->affine.ry*height- |
| 404 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0- |
| 405 | annotate_info->affine.ry*(number_lines-1.0)*height/2.0; |
| 406 | offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+ |
| 407 | geometry.height+i*annotate_info->affine.sy*height- |
| 408 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0- |
| 409 | annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent; |
| 410 | break; |
| 411 | } |
| 412 | case SouthEastGravity: |
| 413 | { |
| 414 | offset.x=(geometry.width == 0 ? 1.0 : -1.0)*annotate_info->affine.tx+ |
| 415 | geometry.width+i*annotate_info->affine.ry*height- |
| 416 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)- |
| 417 | annotate_info->affine.ry*(number_lines-1.0)*height-1.0; |
| 418 | offset.y=(geometry.height == 0 ? 1.0 : -1.0)*annotate_info->affine.ty+ |
| 419 | geometry.height+i*annotate_info->affine.sy*height- |
| 420 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)- |
| 421 | annotate_info->affine.sy*(number_lines-1.0)*height+metrics.descent; |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | switch (annotate->align) |
| 426 | { |
| 427 | case LeftAlign: |
| 428 | { |
| 429 | offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height; |
| 430 | offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height; |
| 431 | break; |
| 432 | } |
| 433 | case CenterAlign: |
| 434 | { |
| 435 | offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height- |
| 436 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1)/2.0; |
| 437 | offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height- |
| 438 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1)/2.0; |
| 439 | break; |
| 440 | } |
| 441 | case RightAlign: |
| 442 | { |
| 443 | offset.x=annotate_info->affine.tx+i*annotate_info->affine.ry*height- |
| 444 | annotate_info->affine.sx*(metrics.width+metrics.bounds.x1); |
| 445 | offset.y=annotate_info->affine.ty+i*annotate_info->affine.sy*height- |
| 446 | annotate_info->affine.rx*(metrics.width+metrics.bounds.x1); |
| 447 | break; |
| 448 | } |
| 449 | default: |
| 450 | break; |
| 451 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 452 | if (draw_info->undercolor.alpha != TransparentAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | { |
| 454 | DrawInfo |
| 455 | *undercolor_info; |
| 456 | |
| 457 | /* |
| 458 | Text box. |
| 459 | */ |
| 460 | undercolor_info=CloneDrawInfo((ImageInfo *) NULL,(DrawInfo *) NULL); |
| 461 | undercolor_info->fill=draw_info->undercolor; |
| 462 | undercolor_info->affine=draw_info->affine; |
| 463 | undercolor_info->affine.tx=offset.x-draw_info->affine.ry*metrics.ascent; |
| 464 | undercolor_info->affine.ty=offset.y-draw_info->affine.sy*metrics.ascent; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 465 | (void) FormatLocaleString(primitive,MaxTextExtent, |
cristy | a8549b1 | 2011-05-18 19:05:08 +0000 | [diff] [blame] | 466 | "rectangle 0,0 %g,%.20g",metrics.origin.x,(double) height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 467 | (void) CloneString(&undercolor_info->primitive,primitive); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 468 | (void) DrawImage(image,undercolor_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | (void) DestroyDrawInfo(undercolor_info); |
| 470 | } |
| 471 | annotate_info->affine.tx=offset.x; |
| 472 | annotate_info->affine.ty=offset.y; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 473 | (void) FormatLocaleString(primitive,MaxTextExtent,"stroke-width %g " |
cristy | a8549b1 | 2011-05-18 19:05:08 +0000 | [diff] [blame] | 474 | "line 0,0 %g,0",metrics.underline_thickness,metrics.width); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | if (annotate->decorate == OverlineDecoration) |
| 476 | { |
| 477 | annotate_info->affine.ty-=(draw_info->affine.sy*(metrics.ascent+ |
| 478 | metrics.descent-metrics.underline_position)); |
| 479 | (void) CloneString(&annotate_info->primitive,primitive); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 480 | (void) DrawImage(image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | } |
| 482 | else |
| 483 | if (annotate->decorate == UnderlineDecoration) |
| 484 | { |
| 485 | annotate_info->affine.ty-=(draw_info->affine.sy* |
| 486 | metrics.underline_position); |
| 487 | (void) CloneString(&annotate_info->primitive,primitive); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 488 | (void) DrawImage(image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | } |
| 490 | /* |
| 491 | Annotate image with text. |
| 492 | */ |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 493 | status=RenderType(image,annotate,&offset,&metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 494 | if (status == MagickFalse) |
| 495 | break; |
| 496 | if (annotate->decorate == LineThroughDecoration) |
| 497 | { |
| 498 | annotate_info->affine.ty-=(draw_info->affine.sy*(height+ |
| 499 | metrics.underline_position+metrics.descent)/2.0); |
| 500 | (void) CloneString(&annotate_info->primitive,primitive); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 501 | (void) DrawImage(image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | /* |
| 505 | Relinquish resources. |
| 506 | */ |
| 507 | annotate_info=DestroyDrawInfo(annotate_info); |
| 508 | annotate=DestroyDrawInfo(annotate); |
| 509 | for (i=0; textlist[i] != (char *) NULL; i++) |
| 510 | textlist[i]=DestroyString(textlist[i]); |
| 511 | textlist=(char **) RelinquishMagickMemory(textlist); |
| 512 | return(status); |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 517 | % % |
| 518 | % % |
| 519 | % % |
| 520 | % F o r m a t M a g i c k C a p t i o n % |
| 521 | % % |
| 522 | % % |
| 523 | % % |
| 524 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 525 | % |
| 526 | % FormatMagickCaption() formats a caption so that it fits within the image |
| 527 | % width. It returns the number of lines in the formatted caption. |
| 528 | % |
| 529 | % The format of the FormatMagickCaption method is: |
| 530 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 531 | % ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 532 | % const MagickBooleanType split,TypeMetric *metrics,char **caption, |
| 533 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | % |
| 535 | % A description of each parameter follows. |
| 536 | % |
| 537 | % o image: The image. |
| 538 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 539 | % o draw_info: the draw info. |
| 540 | % |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 541 | % o split: when no convenient line breaks-- insert newline. |
| 542 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | % o metrics: Return the font metrics in this structure. |
| 544 | % |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 545 | % o caption: the caption. |
| 546 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 547 | % o exception: return any errors or warnings in this structure. |
| 548 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 549 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 550 | MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 551 | const MagickBooleanType split,TypeMetric *metrics,char **caption, |
| 552 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 553 | { |
cristy | 74966db | 2011-09-20 19:37:21 +0000 | [diff] [blame] | 554 | char |
| 555 | *text; |
| 556 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 557 | MagickBooleanType |
| 558 | status; |
| 559 | |
| 560 | register char |
| 561 | *p, |
| 562 | *q, |
| 563 | *s; |
| 564 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 565 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 566 | i; |
| 567 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 568 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 569 | width; |
| 570 | |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 571 | ssize_t |
| 572 | n; |
| 573 | |
cristy | 74966db | 2011-09-20 19:37:21 +0000 | [diff] [blame] | 574 | text=AcquireString(draw_info->text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 575 | q=draw_info->text; |
| 576 | s=(char *) NULL; |
| 577 | for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p)) |
| 578 | { |
| 579 | if (IsUTFSpace(GetUTFCode(p)) != MagickFalse) |
| 580 | s=p; |
cristy | 2911f2d | 2011-08-20 23:04:43 +0000 | [diff] [blame] | 581 | if (GetUTFCode(p) == '\n') |
cristy | e2c81ad | 2011-08-20 22:54:14 +0000 | [diff] [blame] | 582 | q=draw_info->text; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 583 | for (i=0; i < (ssize_t) GetUTFOctets(p); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | *q++=(*(p+i)); |
| 585 | *q='\0'; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 586 | status=GetTypeMetrics(image,draw_info,metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 587 | if (status == MagickFalse) |
| 588 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 589 | width=(size_t) floor(metrics->width+0.5); |
cristy | 74966db | 2011-09-20 19:37:21 +0000 | [diff] [blame] | 590 | if ((width <= image->columns) || (strcmp(text,draw_info->text) == 0)) |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 591 | continue; |
cristy | 74966db | 2011-09-20 19:37:21 +0000 | [diff] [blame] | 592 | (void) strcpy(text,draw_info->text); |
cristy | 4aa314e | 2011-08-19 13:59:45 +0000 | [diff] [blame] | 593 | if ((s != (char *) NULL) && (GetUTFOctets(s) == 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 594 | { |
| 595 | *s='\n'; |
| 596 | p=s; |
| 597 | } |
| 598 | else |
cristy | 4aa314e | 2011-08-19 13:59:45 +0000 | [diff] [blame] | 599 | if ((s != (char *) NULL) || (split != MagickFalse)) |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 600 | { |
| 601 | char |
| 602 | *target; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 603 | |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 604 | /* |
| 605 | No convenient line breaks-- insert newline. |
| 606 | */ |
| 607 | target=AcquireString(*caption); |
| 608 | n=p-(*caption); |
| 609 | CopyMagickString(target,*caption,n+1); |
| 610 | ConcatenateMagickString(target,"\n",strlen(*caption)+1); |
| 611 | ConcatenateMagickString(target,p,strlen(*caption)+2); |
| 612 | (void) DestroyString(*caption); |
| 613 | *caption=target; |
| 614 | p=(*caption)+n; |
| 615 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | q=draw_info->text; |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 617 | s=(char *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | } |
cristy | 74966db | 2011-09-20 19:37:21 +0000 | [diff] [blame] | 619 | text=DestroyString(text); |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 620 | n=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 621 | for (p=(*caption); GetUTFCode(p) != 0; p+=GetUTFOctets(p)) |
| 622 | if (GetUTFCode(p) == '\n') |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 623 | n++; |
| 624 | return(n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* |
| 628 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 629 | % % |
| 630 | % % |
| 631 | % % |
| 632 | % G e t M u l t i l i n e T y p e M e t r i c s % |
| 633 | % % |
| 634 | % % |
| 635 | % % |
| 636 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 637 | % |
| 638 | % GetMultilineTypeMetrics() returns the following information for the |
| 639 | % specified font and text: |
| 640 | % |
| 641 | % character width |
| 642 | % character height |
| 643 | % ascender |
| 644 | % descender |
| 645 | % text width |
| 646 | % text height |
| 647 | % maximum horizontal advance |
| 648 | % bounds: x1 |
| 649 | % bounds: y1 |
| 650 | % bounds: x2 |
| 651 | % bounds: y2 |
| 652 | % origin: x |
| 653 | % origin: y |
| 654 | % underline position |
| 655 | % underline thickness |
| 656 | % |
| 657 | % This method is like GetTypeMetrics() but it returns the maximum text width |
| 658 | % and height for multiple lines of text. |
| 659 | % |
| 660 | % The format of the GetMultilineTypeMetrics method is: |
| 661 | % |
| 662 | % MagickBooleanType GetMultilineTypeMetrics(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 663 | % const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 664 | % |
| 665 | % A description of each parameter follows: |
| 666 | % |
| 667 | % o image: the image. |
| 668 | % |
| 669 | % o draw_info: the draw info. |
| 670 | % |
| 671 | % o metrics: Return the font metrics in this structure. |
| 672 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 673 | % o exception: return any errors or warnings in this structure. |
| 674 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 675 | */ |
| 676 | MagickExport MagickBooleanType GetMultilineTypeMetrics(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 677 | const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 678 | { |
| 679 | char |
| 680 | **textlist; |
| 681 | |
| 682 | DrawInfo |
| 683 | *annotate_info; |
| 684 | |
| 685 | MagickBooleanType |
| 686 | status; |
| 687 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 688 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | i; |
| 690 | |
| 691 | TypeMetric |
| 692 | extent; |
| 693 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | assert(image != (Image *) NULL); |
| 695 | assert(image->signature == MagickSignature); |
| 696 | if (image->debug != MagickFalse) |
| 697 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 698 | assert(draw_info != (DrawInfo *) NULL); |
| 699 | assert(draw_info->text != (char *) NULL); |
| 700 | assert(draw_info->signature == MagickSignature); |
| 701 | if (*draw_info->text == '\0') |
| 702 | return(MagickFalse); |
| 703 | annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 704 | annotate_info->text=DestroyString(annotate_info->text); |
| 705 | /* |
| 706 | Convert newlines to multiple lines of text. |
| 707 | */ |
| 708 | textlist=StringToList(draw_info->text); |
| 709 | if (textlist == (char **) NULL) |
| 710 | return(MagickFalse); |
| 711 | annotate_info->render=MagickFalse; |
cristy | 024843f | 2011-06-03 17:52:52 +0000 | [diff] [blame] | 712 | annotate_info->direction=UndefinedDirection; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | (void) ResetMagickMemory(metrics,0,sizeof(*metrics)); |
| 714 | (void) ResetMagickMemory(&extent,0,sizeof(extent)); |
| 715 | /* |
| 716 | Find the widest of the text lines. |
| 717 | */ |
| 718 | annotate_info->text=textlist[0]; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 719 | status=GetTypeMetrics(image,annotate_info,&extent,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | *metrics=extent; |
| 721 | for (i=1; textlist[i] != (char *) NULL; i++) |
| 722 | { |
| 723 | annotate_info->text=textlist[i]; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 724 | status=GetTypeMetrics(image,annotate_info,&extent,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 725 | if (extent.width > metrics->width) |
| 726 | *metrics=extent; |
| 727 | } |
cristy | e2c81ad | 2011-08-20 22:54:14 +0000 | [diff] [blame] | 728 | metrics->height=(double) (i*(size_t) (metrics->ascent-metrics->descent+0.5)+ |
| 729 | (i-1)*draw_info->interline_spacing); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | /* |
| 731 | Relinquish resources. |
| 732 | */ |
| 733 | annotate_info->text=(char *) NULL; |
| 734 | annotate_info=DestroyDrawInfo(annotate_info); |
| 735 | for (i=0; textlist[i] != (char *) NULL; i++) |
| 736 | textlist[i]=DestroyString(textlist[i]); |
| 737 | textlist=(char **) RelinquishMagickMemory(textlist); |
| 738 | return(status); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 743 | % % |
| 744 | % % |
| 745 | % % |
| 746 | % G e t T y p e M e t r i c s % |
| 747 | % % |
| 748 | % % |
| 749 | % % |
| 750 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 751 | % |
| 752 | % GetTypeMetrics() returns the following information for the specified font |
| 753 | % and text: |
| 754 | % |
| 755 | % character width |
| 756 | % character height |
| 757 | % ascender |
| 758 | % descender |
| 759 | % text width |
| 760 | % text height |
| 761 | % maximum horizontal advance |
| 762 | % bounds: x1 |
| 763 | % bounds: y1 |
| 764 | % bounds: x2 |
| 765 | % bounds: y2 |
| 766 | % origin: x |
| 767 | % origin: y |
| 768 | % underline position |
| 769 | % underline thickness |
| 770 | % |
| 771 | % The format of the GetTypeMetrics method is: |
| 772 | % |
| 773 | % MagickBooleanType GetTypeMetrics(Image *image,const DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 774 | % TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 775 | % |
| 776 | % A description of each parameter follows: |
| 777 | % |
| 778 | % o image: the image. |
| 779 | % |
| 780 | % o draw_info: the draw info. |
| 781 | % |
| 782 | % o metrics: Return the font metrics in this structure. |
| 783 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 784 | % o exception: return any errors or warnings in this structure. |
| 785 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 786 | */ |
| 787 | MagickExport MagickBooleanType GetTypeMetrics(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 788 | const DrawInfo *draw_info,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 789 | { |
| 790 | DrawInfo |
| 791 | *annotate_info; |
| 792 | |
| 793 | MagickBooleanType |
| 794 | status; |
| 795 | |
| 796 | PointInfo |
| 797 | offset; |
| 798 | |
| 799 | assert(image != (Image *) NULL); |
| 800 | assert(image->signature == MagickSignature); |
| 801 | if (image->debug != MagickFalse) |
| 802 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 803 | assert(draw_info != (DrawInfo *) NULL); |
| 804 | assert(draw_info->text != (char *) NULL); |
| 805 | assert(draw_info->signature == MagickSignature); |
| 806 | annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 807 | annotate_info->render=MagickFalse; |
cristy | 024843f | 2011-06-03 17:52:52 +0000 | [diff] [blame] | 808 | annotate_info->direction=UndefinedDirection; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 809 | (void) ResetMagickMemory(metrics,0,sizeof(*metrics)); |
| 810 | offset.x=0.0; |
| 811 | offset.y=0.0; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 812 | status=RenderType(image,annotate_info,&offset,metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 813 | if (image->debug != MagickFalse) |
| 814 | (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Metrics: text: %s; " |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 815 | "width: %g; height: %g; ascent: %g; descent: %g; max advance: %g; " |
cristy | a8549b1 | 2011-05-18 19:05:08 +0000 | [diff] [blame] | 816 | "bounds: %g,%g %g,%g; origin: %g,%g; pixels per em: %g,%g; " |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 817 | "underline position: %g; underline thickness: %g",annotate_info->text, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 818 | metrics->width,metrics->height,metrics->ascent,metrics->descent, |
| 819 | metrics->max_advance,metrics->bounds.x1,metrics->bounds.y1, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 820 | metrics->bounds.x2,metrics->bounds.y2,metrics->origin.x,metrics->origin.y, |
| 821 | metrics->pixels_per_em.x,metrics->pixels_per_em.y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 822 | metrics->underline_position,metrics->underline_thickness); |
| 823 | annotate_info=DestroyDrawInfo(annotate_info); |
| 824 | return(status); |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 829 | % % |
| 830 | % % |
| 831 | % % |
| 832 | + R e n d e r T y p e % |
| 833 | % % |
| 834 | % % |
| 835 | % % |
| 836 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 837 | % |
| 838 | % RenderType() renders text on the image. It also returns the bounding box of |
| 839 | % the text relative to the image. |
| 840 | % |
| 841 | % The format of the RenderType method is: |
| 842 | % |
| 843 | % MagickBooleanType RenderType(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 844 | % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 845 | % |
| 846 | % A description of each parameter follows: |
| 847 | % |
| 848 | % o image: the image. |
| 849 | % |
| 850 | % o draw_info: the draw info. |
| 851 | % |
| 852 | % o offset: (x,y) location of text relative to image. |
| 853 | % |
| 854 | % o metrics: bounding box of text. |
| 855 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 856 | % o exception: return any errors or warnings in this structure. |
| 857 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | */ |
| 859 | static MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 860 | const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 861 | { |
| 862 | const TypeInfo |
| 863 | *type_info; |
| 864 | |
| 865 | DrawInfo |
| 866 | *annotate_info; |
| 867 | |
| 868 | MagickBooleanType |
| 869 | status; |
| 870 | |
| 871 | type_info=(const TypeInfo *) NULL; |
| 872 | if (draw_info->font != (char *) NULL) |
| 873 | { |
| 874 | if (*draw_info->font == '@') |
| 875 | { |
| 876 | status=RenderFreetype(image,draw_info,draw_info->encoding,offset, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 877 | metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 878 | return(status); |
| 879 | } |
| 880 | if (*draw_info->font == '-') |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 881 | return(RenderX11(image,draw_info,offset,metrics,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 882 | if (IsPathAccessible(draw_info->font) != MagickFalse) |
| 883 | { |
| 884 | status=RenderFreetype(image,draw_info,draw_info->encoding,offset, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 885 | metrics,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 886 | return(status); |
| 887 | } |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 888 | type_info=GetTypeInfo(draw_info->font,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 889 | if (type_info == (const TypeInfo *) NULL) |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 890 | (void) ThrowMagickException(exception,GetMagickModule(),TypeWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 891 | "UnableToReadFont","'%s'",draw_info->font); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 892 | } |
| 893 | if ((type_info == (const TypeInfo *) NULL) && |
| 894 | (draw_info->family != (const char *) NULL)) |
| 895 | { |
| 896 | type_info=GetTypeInfoByFamily(draw_info->family,draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 897 | draw_info->stretch,draw_info->weight,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 898 | if (type_info == (const TypeInfo *) NULL) |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 899 | (void) ThrowMagickException(exception,GetMagickModule(),TypeWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 900 | "UnableToReadFont","'%s'",draw_info->family); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 901 | } |
| 902 | if (type_info == (const TypeInfo *) NULL) |
cristy | d984f27 | 2010-03-16 01:46:12 +0000 | [diff] [blame] | 903 | type_info=GetTypeInfoByFamily("Arial",draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 904 | draw_info->stretch,draw_info->weight,exception); |
cristy | d984f27 | 2010-03-16 01:46:12 +0000 | [diff] [blame] | 905 | if (type_info == (const TypeInfo *) NULL) |
cristy | cbb34a4 | 2010-03-16 01:45:18 +0000 | [diff] [blame] | 906 | type_info=GetTypeInfoByFamily("Helvetica",draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 907 | draw_info->stretch,draw_info->weight,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 908 | if (type_info == (const TypeInfo *) NULL) |
cristy | 704acaa | 2010-03-23 13:08:21 +0000 | [diff] [blame] | 909 | type_info=GetTypeInfoByFamily("Century Schoolbook",draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 910 | draw_info->stretch,draw_info->weight,exception); |
cristy | 704acaa | 2010-03-23 13:08:21 +0000 | [diff] [blame] | 911 | if (type_info == (const TypeInfo *) NULL) |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 912 | type_info=GetTypeInfoByFamily("Sans",draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 913 | draw_info->stretch,draw_info->weight,exception); |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 914 | if (type_info == (const TypeInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 915 | type_info=GetTypeInfoByFamily((const char *) NULL,draw_info->style, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 916 | draw_info->stretch,draw_info->weight,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 917 | if (type_info == (const TypeInfo *) NULL) |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 918 | type_info=GetTypeInfo("*",exception); |
cristy | 704acaa | 2010-03-23 13:08:21 +0000 | [diff] [blame] | 919 | if (type_info == (const TypeInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 920 | { |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 921 | status=RenderFreetype(image,draw_info,draw_info->encoding,offset,metrics, |
| 922 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 923 | return(status); |
| 924 | } |
| 925 | annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 926 | annotate_info->face=type_info->face; |
| 927 | if (type_info->metrics != (char *) NULL) |
| 928 | (void) CloneString(&annotate_info->metrics,type_info->metrics); |
| 929 | if (type_info->glyphs != (char *) NULL) |
| 930 | (void) CloneString(&annotate_info->font,type_info->glyphs); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 931 | status=RenderFreetype(image,annotate_info,type_info->encoding,offset,metrics, |
| 932 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 933 | annotate_info=DestroyDrawInfo(annotate_info); |
| 934 | return(status); |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 939 | % % |
| 940 | % % |
| 941 | % % |
| 942 | + R e n d e r F r e e t y p e % |
| 943 | % % |
| 944 | % % |
| 945 | % % |
| 946 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 947 | % |
| 948 | % RenderFreetype() renders text on the image with a Truetype font. It also |
| 949 | % returns the bounding box of the text relative to the image. |
| 950 | % |
| 951 | % The format of the RenderFreetype method is: |
| 952 | % |
| 953 | % MagickBooleanType RenderFreetype(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 954 | % const char *encoding,const PointInfo *offset,TypeMetric *metrics, |
| 955 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 956 | % |
| 957 | % A description of each parameter follows: |
| 958 | % |
| 959 | % o image: the image. |
| 960 | % |
| 961 | % o draw_info: the draw info. |
| 962 | % |
| 963 | % o encoding: the font encoding. |
| 964 | % |
| 965 | % o offset: (x,y) location of text relative to image. |
| 966 | % |
| 967 | % o metrics: bounding box of text. |
| 968 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 969 | % o exception: return any errors or warnings in this structure. |
| 970 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 971 | */ |
| 972 | |
| 973 | #if defined(MAGICKCORE_FREETYPE_DELEGATE) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 974 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 975 | static int TraceCubicBezier(FT_Vector *p,FT_Vector *q,FT_Vector *to, |
| 976 | DrawInfo *draw_info) |
| 977 | { |
| 978 | AffineMatrix |
| 979 | affine; |
| 980 | |
| 981 | char |
| 982 | path[MaxTextExtent]; |
| 983 | |
| 984 | affine=draw_info->affine; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 985 | (void) FormatLocaleString(path,MaxTextExtent, |
cristy | a8549b1 | 2011-05-18 19:05:08 +0000 | [diff] [blame] | 986 | "C%g,%g %g,%g %g,%g",affine.tx+p->x/64.0,affine.ty- |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 987 | p->y/64.0,affine.tx+q->x/64.0,affine.ty-q->y/64.0,affine.tx+to->x/64.0, |
| 988 | affine.ty-to->y/64.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 989 | (void) ConcatenateString(&draw_info->primitive,path); |
| 990 | return(0); |
| 991 | } |
| 992 | |
| 993 | static int TraceLineTo(FT_Vector *to,DrawInfo *draw_info) |
| 994 | { |
| 995 | AffineMatrix |
| 996 | affine; |
| 997 | |
| 998 | char |
| 999 | path[MaxTextExtent]; |
| 1000 | |
| 1001 | affine=draw_info->affine; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1002 | (void) FormatLocaleString(path,MaxTextExtent,"L%g,%g",affine.tx+ |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1003 | to->x/64.0,affine.ty-to->y/64.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1004 | (void) ConcatenateString(&draw_info->primitive,path); |
| 1005 | return(0); |
| 1006 | } |
| 1007 | |
| 1008 | static int TraceMoveTo(FT_Vector *to,DrawInfo *draw_info) |
| 1009 | { |
| 1010 | AffineMatrix |
| 1011 | affine; |
| 1012 | |
| 1013 | char |
| 1014 | path[MaxTextExtent]; |
| 1015 | |
| 1016 | affine=draw_info->affine; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1017 | (void) FormatLocaleString(path,MaxTextExtent,"M%g,%g",affine.tx+ |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1018 | to->x/64.0,affine.ty-to->y/64.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | (void) ConcatenateString(&draw_info->primitive,path); |
| 1020 | return(0); |
| 1021 | } |
| 1022 | |
| 1023 | static int TraceQuadraticBezier(FT_Vector *control,FT_Vector *to, |
| 1024 | DrawInfo *draw_info) |
| 1025 | { |
| 1026 | AffineMatrix |
| 1027 | affine; |
| 1028 | |
| 1029 | char |
| 1030 | path[MaxTextExtent]; |
| 1031 | |
| 1032 | affine=draw_info->affine; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1033 | (void) FormatLocaleString(path,MaxTextExtent,"Q%g,%g %g,%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1034 | affine.tx+control->x/64.0,affine.ty-control->y/64.0,affine.tx+to->x/64.0, |
| 1035 | affine.ty-to->y/64.0); |
| 1036 | (void) ConcatenateString(&draw_info->primitive,path); |
| 1037 | return(0); |
| 1038 | } |
| 1039 | |
| 1040 | static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1041 | const char *encoding,const PointInfo *offset,TypeMetric *metrics, |
| 1042 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1043 | { |
| 1044 | #if !defined(FT_OPEN_PATHNAME) |
| 1045 | #define FT_OPEN_PATHNAME ft_open_pathname |
| 1046 | #endif |
| 1047 | |
| 1048 | typedef struct _GlyphInfo |
| 1049 | { |
| 1050 | FT_UInt |
| 1051 | id; |
| 1052 | |
| 1053 | FT_Vector |
| 1054 | origin; |
| 1055 | |
| 1056 | FT_Glyph |
| 1057 | image; |
| 1058 | } GlyphInfo; |
| 1059 | |
| 1060 | const char |
| 1061 | *value; |
| 1062 | |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 1063 | double |
| 1064 | direction; |
| 1065 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1066 | DrawInfo |
| 1067 | *annotate_info; |
| 1068 | |
| 1069 | FT_BBox |
| 1070 | bounds; |
| 1071 | |
| 1072 | FT_BitmapGlyph |
| 1073 | bitmap; |
| 1074 | |
| 1075 | FT_Encoding |
| 1076 | encoding_type; |
| 1077 | |
| 1078 | FT_Error |
| 1079 | status; |
| 1080 | |
| 1081 | FT_Face |
| 1082 | face; |
| 1083 | |
| 1084 | FT_Int32 |
| 1085 | flags; |
| 1086 | |
| 1087 | FT_Library |
| 1088 | library; |
| 1089 | |
| 1090 | FT_Matrix |
| 1091 | affine; |
| 1092 | |
| 1093 | FT_Open_Args |
| 1094 | args; |
| 1095 | |
| 1096 | FT_Vector |
| 1097 | origin; |
| 1098 | |
| 1099 | GlyphInfo |
| 1100 | glyph, |
| 1101 | last_glyph; |
| 1102 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1103 | PointInfo |
| 1104 | point, |
| 1105 | resolution; |
| 1106 | |
| 1107 | register char |
| 1108 | *p; |
| 1109 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1110 | ssize_t |
| 1111 | code, |
| 1112 | y; |
| 1113 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1114 | static FT_Outline_Funcs |
| 1115 | OutlineMethods = |
| 1116 | { |
| 1117 | (FT_Outline_MoveTo_Func) TraceMoveTo, |
| 1118 | (FT_Outline_LineTo_Func) TraceLineTo, |
| 1119 | (FT_Outline_ConicTo_Func) TraceQuadraticBezier, |
| 1120 | (FT_Outline_CubicTo_Func) TraceCubicBezier, |
| 1121 | 0, 0 |
| 1122 | }; |
| 1123 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1124 | unsigned char |
| 1125 | *utf8; |
| 1126 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1127 | /* |
| 1128 | Initialize Truetype library. |
| 1129 | */ |
| 1130 | status=FT_Init_FreeType(&library); |
| 1131 | if (status != 0) |
| 1132 | ThrowBinaryException(TypeError,"UnableToInitializeFreetypeLibrary", |
| 1133 | image->filename); |
| 1134 | args.flags=FT_OPEN_PATHNAME; |
| 1135 | if (draw_info->font == (char *) NULL) |
| 1136 | args.pathname=ConstantString("helvetica"); |
| 1137 | else |
| 1138 | if (*draw_info->font != '@') |
| 1139 | args.pathname=ConstantString(draw_info->font); |
| 1140 | else |
| 1141 | args.pathname=ConstantString(draw_info->font+1); |
| 1142 | face=(FT_Face) NULL; |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 1143 | status=FT_Open_Face(library,&args,(long) draw_info->face,&face); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1144 | args.pathname=DestroyString(args.pathname); |
| 1145 | if (status != 0) |
| 1146 | { |
| 1147 | (void) FT_Done_FreeType(library); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1148 | (void) ThrowMagickException(exception,GetMagickModule(),TypeError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1149 | "UnableToReadFont","'%s'",draw_info->font); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1150 | return(RenderPostscript(image,draw_info,offset,metrics,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1151 | } |
| 1152 | if ((draw_info->metrics != (char *) NULL) && |
| 1153 | (IsPathAccessible(draw_info->metrics) != MagickFalse)) |
| 1154 | (void) FT_Attach_File(face,draw_info->metrics); |
| 1155 | encoding_type=ft_encoding_unicode; |
| 1156 | status=FT_Select_Charmap(face,encoding_type); |
| 1157 | if ((status != 0) && (face->num_charmaps != 0)) |
| 1158 | status=FT_Set_Charmap(face,face->charmaps[0]); |
| 1159 | if (encoding != (const char *) NULL) |
| 1160 | { |
| 1161 | if (LocaleCompare(encoding,"AdobeCustom") == 0) |
| 1162 | encoding_type=ft_encoding_adobe_custom; |
| 1163 | if (LocaleCompare(encoding,"AdobeExpert") == 0) |
| 1164 | encoding_type=ft_encoding_adobe_expert; |
| 1165 | if (LocaleCompare(encoding,"AdobeStandard") == 0) |
| 1166 | encoding_type=ft_encoding_adobe_standard; |
| 1167 | if (LocaleCompare(encoding,"AppleRoman") == 0) |
| 1168 | encoding_type=ft_encoding_apple_roman; |
| 1169 | if (LocaleCompare(encoding,"BIG5") == 0) |
| 1170 | encoding_type=ft_encoding_big5; |
| 1171 | if (LocaleCompare(encoding,"GB2312") == 0) |
| 1172 | encoding_type=ft_encoding_gb2312; |
| 1173 | if (LocaleCompare(encoding,"Johab") == 0) |
| 1174 | encoding_type=ft_encoding_johab; |
| 1175 | #if defined(ft_encoding_latin_1) |
| 1176 | if (LocaleCompare(encoding,"Latin-1") == 0) |
| 1177 | encoding_type=ft_encoding_latin_1; |
| 1178 | #endif |
| 1179 | if (LocaleCompare(encoding,"Latin-2") == 0) |
| 1180 | encoding_type=ft_encoding_latin_2; |
| 1181 | if (LocaleCompare(encoding,"None") == 0) |
| 1182 | encoding_type=ft_encoding_none; |
| 1183 | if (LocaleCompare(encoding,"SJIScode") == 0) |
| 1184 | encoding_type=ft_encoding_sjis; |
| 1185 | if (LocaleCompare(encoding,"Symbol") == 0) |
| 1186 | encoding_type=ft_encoding_symbol; |
| 1187 | if (LocaleCompare(encoding,"Unicode") == 0) |
| 1188 | encoding_type=ft_encoding_unicode; |
| 1189 | if (LocaleCompare(encoding,"Wansung") == 0) |
| 1190 | encoding_type=ft_encoding_wansung; |
| 1191 | status=FT_Select_Charmap(face,encoding_type); |
| 1192 | if (status != 0) |
| 1193 | ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding); |
| 1194 | } |
| 1195 | /* |
| 1196 | Set text size. |
| 1197 | */ |
| 1198 | resolution.x=DefaultResolution; |
| 1199 | resolution.y=DefaultResolution; |
| 1200 | if (draw_info->density != (char *) NULL) |
| 1201 | { |
| 1202 | GeometryInfo |
| 1203 | geometry_info; |
| 1204 | |
| 1205 | MagickStatusType |
| 1206 | flags; |
| 1207 | |
| 1208 | flags=ParseGeometry(draw_info->density,&geometry_info); |
| 1209 | resolution.x=geometry_info.rho; |
| 1210 | resolution.y=geometry_info.sigma; |
| 1211 | if ((flags & SigmaValue) == 0) |
| 1212 | resolution.y=resolution.x; |
| 1213 | } |
| 1214 | status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize), |
| 1215 | (FT_F26Dot6) (64.0*draw_info->pointsize),(FT_UInt) resolution.x, |
| 1216 | (FT_UInt) resolution.y); |
| 1217 | metrics->pixels_per_em.x=face->size->metrics.x_ppem; |
| 1218 | metrics->pixels_per_em.y=face->size->metrics.y_ppem; |
| 1219 | metrics->ascent=(double) face->size->metrics.ascender/64.0; |
| 1220 | metrics->descent=(double) face->size->metrics.descender/64.0; |
| 1221 | metrics->width=0; |
| 1222 | metrics->origin.x=0; |
| 1223 | metrics->origin.y=0; |
| 1224 | metrics->height=(double) face->size->metrics.height/64.0; |
| 1225 | metrics->max_advance=0.0; |
| 1226 | if (face->size->metrics.max_advance > MagickEpsilon) |
| 1227 | metrics->max_advance=(double) face->size->metrics.max_advance/64.0; |
| 1228 | metrics->bounds.x1=0.0; |
| 1229 | metrics->bounds.y1=metrics->descent; |
| 1230 | metrics->bounds.x2=metrics->ascent+metrics->descent; |
| 1231 | metrics->bounds.y2=metrics->ascent+metrics->descent; |
| 1232 | metrics->underline_position=face->underline_position/64.0; |
| 1233 | metrics->underline_thickness=face->underline_thickness/64.0; |
cristy | 71709bf | 2011-09-25 13:10:29 +0000 | [diff] [blame] | 1234 | if ((draw_info->text == (char *) NULL) || (*draw_info->text == '\0')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1235 | { |
| 1236 | (void) FT_Done_Face(face); |
| 1237 | (void) FT_Done_FreeType(library); |
| 1238 | return(MagickTrue); |
| 1239 | } |
| 1240 | /* |
| 1241 | Compute bounding box. |
| 1242 | */ |
| 1243 | if (image->debug != MagickFalse) |
| 1244 | (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),"Font %s; " |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1245 | "font-encoding %s; text-encoding %s; pointsize %g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1246 | draw_info->font != (char *) NULL ? draw_info->font : "none", |
| 1247 | encoding != (char *) NULL ? encoding : "none", |
| 1248 | draw_info->encoding != (char *) NULL ? draw_info->encoding : "none", |
| 1249 | draw_info->pointsize); |
| 1250 | flags=FT_LOAD_NO_BITMAP; |
cristy | 55a804e | 2012-01-13 17:46:11 +0000 | [diff] [blame] | 1251 | if (draw_info->text_antialias == MagickFalse) |
cristy | 4f9709e | 2012-06-10 01:54:51 +0000 | [diff] [blame] | 1252 | flags|=FT_LOAD_TARGET_MONO; |
cristy | 55a804e | 2012-01-13 17:46:11 +0000 | [diff] [blame] | 1253 | else |
| 1254 | { |
cristy | a89189d | 2012-01-13 17:54:57 +0000 | [diff] [blame] | 1255 | #if defined(FT_LOAD_TARGET_LIGHT) |
cristy | 55a804e | 2012-01-13 17:46:11 +0000 | [diff] [blame] | 1256 | flags|=FT_LOAD_TARGET_LIGHT; |
cristy | a89189d | 2012-01-13 17:54:57 +0000 | [diff] [blame] | 1257 | #elif defined(FT_LOAD_TARGET_LCD) |
| 1258 | flags|=FT_LOAD_TARGET_LCD; |
cristy | 55a804e | 2012-01-13 17:46:11 +0000 | [diff] [blame] | 1259 | #endif |
| 1260 | } |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1261 | value=GetImageProperty(image,"type:hinting",exception); |
cristy | 3320424 | 2010-10-07 23:17:12 +0000 | [diff] [blame] | 1262 | if ((value != (const char *) NULL) && (LocaleCompare(value,"off") == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1263 | flags|=FT_LOAD_NO_HINTING; |
| 1264 | glyph.id=0; |
| 1265 | glyph.image=NULL; |
| 1266 | last_glyph.id=0; |
| 1267 | last_glyph.image=NULL; |
| 1268 | origin.x=0; |
| 1269 | origin.y=0; |
| 1270 | affine.xx=65536L; |
| 1271 | affine.yx=0L; |
| 1272 | affine.xy=0L; |
| 1273 | affine.yy=65536L; |
| 1274 | if (draw_info->render != MagickFalse) |
| 1275 | { |
| 1276 | affine.xx=(FT_Fixed) (65536L*draw_info->affine.sx+0.5); |
| 1277 | affine.yx=(FT_Fixed) (-65536L*draw_info->affine.rx+0.5); |
| 1278 | affine.xy=(FT_Fixed) (-65536L*draw_info->affine.ry+0.5); |
| 1279 | affine.yy=(FT_Fixed) (65536L*draw_info->affine.sy+0.5); |
| 1280 | } |
| 1281 | annotate_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1282 | (void) CloneString(&annotate_info->primitive,"path '"); |
| 1283 | if (draw_info->render != MagickFalse) |
| 1284 | { |
| 1285 | if (image->storage_class != DirectClass) |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1286 | (void) SetImageStorageClass(image,DirectClass,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1287 | if (image->matte == MagickFalse) |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1288 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1289 | } |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 1290 | direction=1.0; |
cristy | cf5467b | 2010-03-28 16:22:06 +0000 | [diff] [blame] | 1291 | if (draw_info->direction == RightToLeftDirection) |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 1292 | direction=(-1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1293 | point.x=0.0; |
| 1294 | point.y=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1295 | for (p=draw_info->text; GetUTFCode(p) != 0; p+=GetUTFOctets(p)) |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1296 | if (GetUTFCode(p) < 0) |
| 1297 | break; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1298 | utf8=(unsigned char *) NULL; |
cristy | d913ea1 | 2010-02-13 02:32:57 +0000 | [diff] [blame] | 1299 | if (GetUTFCode(p) == 0) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1300 | p=draw_info->text; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1301 | else |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1302 | { |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1303 | utf8=ConvertLatin1ToUTF8((unsigned char *) draw_info->text); |
| 1304 | if (utf8 != (unsigned char *) NULL) |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 1305 | p=(char *) utf8; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1306 | } |
| 1307 | for (code=0; GetUTFCode(p) != 0; p+=GetUTFOctets(p)) |
| 1308 | { |
| 1309 | /* |
| 1310 | Render UTF-8 sequence. |
| 1311 | */ |
| 1312 | glyph.id=FT_Get_Char_Index(face,GetUTFCode(p)); |
| 1313 | if (glyph.id == 0) |
| 1314 | glyph.id=FT_Get_Char_Index(face,'?'); |
| 1315 | if ((glyph.id != 0) && (last_glyph.id != 0)) |
| 1316 | { |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1317 | if (fabs(draw_info->kerning) >= MagickEpsilon) |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 1318 | origin.x+=(FT_Pos) (64.0*direction*draw_info->kerning); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1319 | else |
| 1320 | if (FT_HAS_KERNING(face)) |
| 1321 | { |
| 1322 | FT_Vector |
| 1323 | kerning; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1324 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1325 | status=FT_Get_Kerning(face,last_glyph.id,glyph.id, |
| 1326 | ft_kerning_default,&kerning); |
| 1327 | if (status == 0) |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 1328 | origin.x+=(FT_Pos) (direction*kerning.x); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | glyph.origin=origin; |
| 1332 | status=FT_Load_Glyph(face,glyph.id,flags); |
| 1333 | if (status != 0) |
| 1334 | continue; |
| 1335 | status=FT_Get_Glyph(face->glyph,&glyph.image); |
| 1336 | if (status != 0) |
| 1337 | continue; |
| 1338 | status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline, |
| 1339 | &bounds); |
| 1340 | if (status != 0) |
| 1341 | continue; |
| 1342 | if ((p == draw_info->text) || (bounds.xMin < metrics->bounds.x1)) |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1343 | metrics->bounds.x1=(double) bounds.xMin; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1344 | if ((p == draw_info->text) || (bounds.yMin < metrics->bounds.y1)) |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1345 | metrics->bounds.y1=(double) bounds.yMin; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1346 | if ((p == draw_info->text) || (bounds.xMax > metrics->bounds.x2)) |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1347 | metrics->bounds.x2=(double) bounds.xMax; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1348 | if ((p == draw_info->text) || (bounds.yMax > metrics->bounds.y2)) |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1349 | metrics->bounds.y2=(double) bounds.yMax; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1350 | if (draw_info->render != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1351 | if ((draw_info->stroke.alpha != TransparentAlpha) || |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1352 | (draw_info->stroke_pattern != (Image *) NULL)) |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1353 | { |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1354 | /* |
| 1355 | Trace the glyph. |
| 1356 | */ |
| 1357 | annotate_info->affine.tx=glyph.origin.x/64.0; |
| 1358 | annotate_info->affine.ty=glyph.origin.y/64.0; |
| 1359 | (void) FT_Outline_Decompose(&((FT_OutlineGlyph) glyph.image)-> |
| 1360 | outline,&OutlineMethods,annotate_info); |
| 1361 | } |
| 1362 | FT_Vector_Transform(&glyph.origin,&affine); |
| 1363 | (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin); |
| 1364 | status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal, |
| 1365 | (FT_Vector *) NULL,MagickTrue); |
| 1366 | if (status != 0) |
| 1367 | continue; |
| 1368 | bitmap=(FT_BitmapGlyph) glyph.image; |
| 1369 | point.x=offset->x+bitmap->left; |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1370 | if (bitmap->bitmap.pixel_mode == ft_pixel_mode_mono) |
| 1371 | point.x=offset->x+(origin.x >> 6); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1372 | point.y=offset->y-bitmap->top; |
| 1373 | if (draw_info->render != MagickFalse) |
| 1374 | { |
| 1375 | CacheView |
| 1376 | *image_view; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1377 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1378 | MagickBooleanType |
| 1379 | status; |
| 1380 | |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1381 | register unsigned char |
| 1382 | *p; |
| 1383 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1384 | /* |
| 1385 | Rasterize the glyph. |
| 1386 | */ |
| 1387 | status=MagickTrue; |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 1388 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1389 | p=bitmap->bitmap.buffer; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1390 | for (y=0; y < (ssize_t) bitmap->bitmap.rows; y++) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1391 | { |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1392 | MagickBooleanType |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1393 | active, |
| 1394 | sync; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1395 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1396 | MagickRealType |
| 1397 | fill_opacity; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1398 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1399 | PixelInfo |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1400 | fill_color; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1401 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1402 | register Quantum |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1403 | *restrict q; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1404 | |
cristy | 8815806 | 2011-06-09 00:31:43 +0000 | [diff] [blame] | 1405 | register ssize_t |
| 1406 | x; |
| 1407 | |
cristy | 73ce31b | 2010-06-13 23:17:39 +0000 | [diff] [blame] | 1408 | ssize_t |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1409 | n, |
cristy | 73ce31b | 2010-06-13 23:17:39 +0000 | [diff] [blame] | 1410 | x_offset, |
| 1411 | y_offset; |
| 1412 | |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1413 | if (status == MagickFalse) |
| 1414 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1415 | x_offset=(ssize_t) ceil(point.x-0.5); |
| 1416 | y_offset=(ssize_t) ceil(point.y+y-0.5); |
| 1417 | if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows)) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1418 | continue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1419 | q=(Quantum *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1420 | if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns)) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1421 | active=MagickFalse; |
| 1422 | else |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1423 | { |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1424 | q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset, |
| 1425 | bitmap->bitmap.width,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1426 | active=q != (Quantum *) NULL ? MagickTrue : MagickFalse; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1427 | } |
cristy | 854209a | 2011-09-19 17:02:57 +0000 | [diff] [blame] | 1428 | n=y*bitmap->bitmap.pitch-1; |
| 1429 | for (x=0; x < (ssize_t) bitmap->bitmap.width; x++) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1430 | { |
cristy | 854209a | 2011-09-19 17:02:57 +0000 | [diff] [blame] | 1431 | n++; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1432 | x_offset++; |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1433 | if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns)) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1434 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1435 | q+=GetPixelChannels(image); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1436 | continue; |
| 1437 | } |
cristy | 2f5b5c7 | 2011-09-16 16:52:00 +0000 | [diff] [blame] | 1438 | if (bitmap->bitmap.pixel_mode != ft_pixel_mode_mono) |
| 1439 | fill_opacity=(MagickRealType) (p[n])/(bitmap->bitmap.num_grays-1); |
| 1440 | else |
| 1441 | fill_opacity=((p[(x >> 3)+y*bitmap->bitmap.pitch] & |
| 1442 | (1 << (~x & 0x07)))) == 0 ? 0.0 : 1.0; |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1443 | if (draw_info->text_antialias == MagickFalse) |
| 1444 | fill_opacity=fill_opacity >= 0.5 ? 1.0 : 0.0; |
| 1445 | if (active == MagickFalse) |
| 1446 | q=GetCacheViewAuthenticPixels(image_view,x_offset,y_offset,1,1, |
| 1447 | exception); |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 1448 | if (q == (Quantum *) NULL) |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1449 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1450 | q+=GetPixelChannels(image); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1451 | continue; |
| 1452 | } |
cristy | ec061ec | 2011-10-21 17:41:17 +0000 | [diff] [blame] | 1453 | GetPixelInfo(image,&fill_color); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 1454 | (void) GetFillColor(draw_info,x_offset,y_offset,&fill_color, |
| 1455 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1456 | fill_opacity=fill_opacity*fill_color.alpha; |
| 1457 | CompositePixelOver(image,&fill_color,fill_opacity,q, |
| 1458 | GetPixelAlpha(image,q),q); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1459 | if (active == MagickFalse) |
| 1460 | { |
| 1461 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 1462 | if (sync == MagickFalse) |
| 1463 | status=MagickFalse; |
| 1464 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1465 | q+=GetPixelChannels(image); |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1466 | } |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1467 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 1468 | if (sync == MagickFalse) |
| 1469 | status=MagickFalse; |
cristy | bd51246 | 2010-02-13 02:13:14 +0000 | [diff] [blame] | 1470 | } |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1471 | image_view=DestroyCacheView(image_view); |
| 1472 | } |
| 1473 | if ((bitmap->left+bitmap->bitmap.width) > metrics->width) |
| 1474 | metrics->width=bitmap->left+bitmap->bitmap.width; |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1475 | if ((fabs(draw_info->interword_spacing) >= MagickEpsilon) && |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1476 | (IsUTFSpace(GetUTFCode(p)) != MagickFalse) && |
| 1477 | (IsUTFSpace(code) == MagickFalse)) |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 1478 | origin.x+=(FT_Pos) (64.0*direction*draw_info->interword_spacing); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1479 | else |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 1480 | origin.x+=(FT_Pos) (direction*face->glyph->advance.x); |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1481 | metrics->origin.x=(double) origin.x; |
| 1482 | metrics->origin.y=(double) origin.y; |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 1483 | if (last_glyph.id != 0) |
| 1484 | FT_Done_Glyph(last_glyph.image); |
cristy | 2857ffc | 2010-03-27 23:44:00 +0000 | [diff] [blame] | 1485 | last_glyph=glyph; |
| 1486 | code=GetUTFCode(p); |
| 1487 | } |
| 1488 | if (utf8 != (unsigned char *) NULL) |
| 1489 | utf8=(unsigned char *) RelinquishMagickMemory(utf8); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 1490 | if (last_glyph.id != 0) |
| 1491 | FT_Done_Glyph(last_glyph.image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1492 | if ((draw_info->stroke.alpha != TransparentAlpha) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1493 | (draw_info->stroke_pattern != (Image *) NULL)) |
| 1494 | { |
| 1495 | if (draw_info->render != MagickFalse) |
| 1496 | { |
| 1497 | /* |
| 1498 | Draw text stroke. |
| 1499 | */ |
| 1500 | annotate_info->linejoin=RoundJoin; |
| 1501 | annotate_info->affine.tx=offset->x; |
| 1502 | annotate_info->affine.ty=offset->y; |
| 1503 | (void) ConcatenateString(&annotate_info->primitive,"'"); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1504 | (void) DrawImage(image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | /* |
| 1508 | Determine font metrics. |
| 1509 | */ |
| 1510 | glyph.id=FT_Get_Char_Index(face,'_'); |
| 1511 | glyph.origin=origin; |
| 1512 | status=FT_Load_Glyph(face,glyph.id,flags); |
| 1513 | if (status == 0) |
| 1514 | { |
| 1515 | status=FT_Get_Glyph(face->glyph,&glyph.image); |
| 1516 | if (status == 0) |
| 1517 | { |
cristy | a367d94 | 2012-01-20 17:06:21 +0000 | [diff] [blame] | 1518 | status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline, |
| 1519 | &bounds); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1520 | if (status == 0) |
| 1521 | { |
| 1522 | FT_Vector_Transform(&glyph.origin,&affine); |
| 1523 | (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin); |
| 1524 | status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal, |
| 1525 | (FT_Vector *) NULL,MagickTrue); |
| 1526 | bitmap=(FT_BitmapGlyph) glyph.image; |
| 1527 | if (bitmap->left > metrics->width) |
| 1528 | metrics->width=bitmap->left; |
| 1529 | } |
| 1530 | } |
cristy | e2c81ad | 2011-08-20 22:54:14 +0000 | [diff] [blame] | 1531 | FT_Done_Glyph(glyph.image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1532 | } |
| 1533 | metrics->width-=metrics->bounds.x1/64.0; |
| 1534 | metrics->bounds.x1/=64.0; |
| 1535 | metrics->bounds.y1/=64.0; |
| 1536 | metrics->bounds.x2/=64.0; |
| 1537 | metrics->bounds.y2/=64.0; |
| 1538 | metrics->origin.x/=64.0; |
| 1539 | metrics->origin.y/=64.0; |
| 1540 | /* |
| 1541 | Relinquish resources. |
| 1542 | */ |
| 1543 | annotate_info=DestroyDrawInfo(annotate_info); |
| 1544 | (void) FT_Done_Face(face); |
| 1545 | (void) FT_Done_FreeType(library); |
| 1546 | return(MagickTrue); |
| 1547 | } |
| 1548 | #else |
| 1549 | static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info, |
| 1550 | const char *magick_unused(encoding),const PointInfo *offset, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1551 | TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | { |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1553 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1554 | MissingDelegateWarning,"DelegateLibrarySupportNotBuiltIn","'%s' (Freetype)", |
cristy | ee08182 | 2011-02-02 19:07:30 +0000 | [diff] [blame] | 1555 | draw_info->font != (char *) NULL ? draw_info->font : "none"); |
cristy | e3b062a | 2011-12-17 18:34:52 +0000 | [diff] [blame] | 1556 | return(RenderPostscript(image,draw_info,offset,metrics,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1557 | } |
| 1558 | #endif |
| 1559 | |
| 1560 | /* |
| 1561 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1562 | % % |
| 1563 | % % |
| 1564 | % % |
| 1565 | + R e n d e r P o s t s c r i p t % |
| 1566 | % % |
| 1567 | % % |
| 1568 | % % |
| 1569 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1570 | % |
| 1571 | % RenderPostscript() renders text on the image with a Postscript font. It |
| 1572 | % also returns the bounding box of the text relative to the image. |
| 1573 | % |
| 1574 | % The format of the RenderPostscript method is: |
| 1575 | % |
| 1576 | % MagickBooleanType RenderPostscript(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1577 | % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1578 | % |
| 1579 | % A description of each parameter follows: |
| 1580 | % |
| 1581 | % o image: the image. |
| 1582 | % |
| 1583 | % o draw_info: the draw info. |
| 1584 | % |
| 1585 | % o offset: (x,y) location of text relative to image. |
| 1586 | % |
| 1587 | % o metrics: bounding box of text. |
| 1588 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1589 | % o exception: return any errors or warnings in this structure. |
| 1590 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1591 | */ |
| 1592 | |
| 1593 | static inline size_t MagickMin(const size_t x,const size_t y) |
| 1594 | { |
| 1595 | if (x < y) |
| 1596 | return(x); |
| 1597 | return(y); |
| 1598 | } |
| 1599 | |
| 1600 | static char *EscapeParenthesis(const char *text) |
| 1601 | { |
| 1602 | char |
| 1603 | *buffer; |
| 1604 | |
| 1605 | register char |
| 1606 | *p; |
| 1607 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1608 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1609 | i; |
| 1610 | |
| 1611 | size_t |
| 1612 | escapes; |
| 1613 | |
| 1614 | escapes=0; |
| 1615 | buffer=AcquireString(text); |
| 1616 | p=buffer; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1617 | for (i=0; i < (ssize_t) MagickMin(strlen(text),MaxTextExtent-escapes-1); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1618 | { |
| 1619 | if ((text[i] == '(') || (text[i] == ')')) |
| 1620 | { |
| 1621 | *p++='\\'; |
| 1622 | escapes++; |
| 1623 | } |
| 1624 | *p++=text[i]; |
| 1625 | } |
| 1626 | *p='\0'; |
| 1627 | return(buffer); |
| 1628 | } |
| 1629 | |
| 1630 | static MagickBooleanType RenderPostscript(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1631 | const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics, |
| 1632 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1633 | { |
| 1634 | char |
| 1635 | filename[MaxTextExtent], |
| 1636 | geometry[MaxTextExtent], |
| 1637 | *text; |
| 1638 | |
| 1639 | FILE |
| 1640 | *file; |
| 1641 | |
| 1642 | Image |
| 1643 | *annotate_image; |
| 1644 | |
| 1645 | ImageInfo |
| 1646 | *annotate_info; |
| 1647 | |
| 1648 | int |
| 1649 | unique_file; |
| 1650 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1651 | MagickBooleanType |
| 1652 | identity; |
| 1653 | |
| 1654 | PointInfo |
| 1655 | extent, |
| 1656 | point, |
| 1657 | resolution; |
| 1658 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1659 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1660 | i; |
| 1661 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1662 | size_t |
| 1663 | length; |
| 1664 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1665 | ssize_t |
| 1666 | y; |
| 1667 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1668 | /* |
| 1669 | Render label with a Postscript font. |
| 1670 | */ |
| 1671 | if (image->debug != MagickFalse) |
| 1672 | (void) LogMagickEvent(AnnotateEvent,GetMagickModule(), |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 1673 | "Font %s; pointsize %g",draw_info->font != (char *) NULL ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1674 | draw_info->font : "none",draw_info->pointsize); |
| 1675 | file=(FILE *) NULL; |
| 1676 | unique_file=AcquireUniqueFileResource(filename); |
| 1677 | if (unique_file != -1) |
| 1678 | file=fdopen(unique_file,"wb"); |
| 1679 | if ((unique_file == -1) || (file == (FILE *) NULL)) |
| 1680 | { |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1681 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile",filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1682 | return(MagickFalse); |
| 1683 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1684 | (void) FormatLocaleFile(file,"%%!PS-Adobe-3.0\n"); |
| 1685 | (void) FormatLocaleFile(file,"/ReencodeType\n"); |
| 1686 | (void) FormatLocaleFile(file,"{\n"); |
| 1687 | (void) FormatLocaleFile(file," findfont dup length\n"); |
| 1688 | (void) FormatLocaleFile(file, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | " dict begin { 1 index /FID ne {def} {pop pop} ifelse } forall\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1690 | (void) FormatLocaleFile(file, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1691 | " /Encoding ISOLatin1Encoding def currentdict end definefont pop\n"); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1692 | (void) FormatLocaleFile(file,"} bind def\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1693 | /* |
| 1694 | Sample to compute bounding box. |
| 1695 | */ |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 1696 | identity=(fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) && |
| 1697 | (fabs(draw_info->affine.rx) < MagickEpsilon) && |
| 1698 | (fabs(draw_info->affine.ry) < MagickEpsilon) ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1699 | extent.x=0.0; |
| 1700 | extent.y=0.0; |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1701 | length=strlen(draw_info->text); |
| 1702 | for (i=0; i <= (ssize_t) (length+2); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1703 | { |
| 1704 | point.x=fabs(draw_info->affine.sx*i*draw_info->pointsize+ |
| 1705 | draw_info->affine.ry*2.0*draw_info->pointsize); |
| 1706 | point.y=fabs(draw_info->affine.rx*i*draw_info->pointsize+ |
| 1707 | draw_info->affine.sy*2.0*draw_info->pointsize); |
| 1708 | if (point.x > extent.x) |
| 1709 | extent.x=point.x; |
| 1710 | if (point.y > extent.y) |
| 1711 | extent.y=point.y; |
| 1712 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1713 | (void) FormatLocaleFile(file,"%g %g moveto\n",identity != MagickFalse ? 0.0 : |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1714 | extent.x/2.0,extent.y/2.0); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1715 | (void) FormatLocaleFile(file,"%g %g scale\n",draw_info->pointsize, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1716 | draw_info->pointsize); |
| 1717 | if ((draw_info->font == (char *) NULL) || (*draw_info->font == '\0') || |
| 1718 | (strchr(draw_info->font,'/') != (char *) NULL)) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1719 | (void) FormatLocaleFile(file, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1720 | "/Times-Roman-ISO dup /Times-Roman ReencodeType findfont setfont\n"); |
| 1721 | else |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1722 | (void) FormatLocaleFile(file, |
| 1723 | "/%s-ISO dup /%s ReencodeType findfont setfont\n",draw_info->font, |
| 1724 | draw_info->font); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1725 | (void) FormatLocaleFile(file,"[%g %g %g %g 0 0] concat\n", |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 1726 | draw_info->affine.sx,-draw_info->affine.rx,-draw_info->affine.ry, |
| 1727 | draw_info->affine.sy); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1728 | text=EscapeParenthesis(draw_info->text); |
| 1729 | if (identity == MagickFalse) |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1730 | (void) FormatLocaleFile(file,"(%s) stringwidth pop -0.5 mul -0.5 rmoveto\n", |
| 1731 | text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1732 | (void) FormatLocaleFile(file,"(%s) show\n",text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1733 | text=DestroyString(text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1734 | (void) FormatLocaleFile(file,"showpage\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1735 | (void) fclose(file); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1736 | (void) FormatLocaleString(geometry,MaxTextExtent,"%.20gx%.20g+0+0!", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1737 | floor(extent.x+0.5),floor(extent.y+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1738 | annotate_info=AcquireImageInfo(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1739 | (void) FormatLocaleString(annotate_info->filename,MaxTextExtent,"ps:%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | filename); |
| 1741 | (void) CloneString(&annotate_info->page,geometry); |
| 1742 | if (draw_info->density != (char *) NULL) |
| 1743 | (void) CloneString(&annotate_info->density,draw_info->density); |
| 1744 | annotate_info->antialias=draw_info->text_antialias; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1745 | annotate_image=ReadImage(annotate_info,exception); |
| 1746 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1747 | annotate_info=DestroyImageInfo(annotate_info); |
| 1748 | (void) RelinquishUniqueFileResource(filename); |
| 1749 | if (annotate_image == (Image *) NULL) |
| 1750 | return(MagickFalse); |
| 1751 | resolution.x=DefaultResolution; |
| 1752 | resolution.y=DefaultResolution; |
| 1753 | if (draw_info->density != (char *) NULL) |
| 1754 | { |
| 1755 | GeometryInfo |
| 1756 | geometry_info; |
| 1757 | |
| 1758 | MagickStatusType |
| 1759 | flags; |
| 1760 | |
| 1761 | flags=ParseGeometry(draw_info->density,&geometry_info); |
| 1762 | resolution.x=geometry_info.rho; |
| 1763 | resolution.y=geometry_info.sigma; |
| 1764 | if ((flags & SigmaValue) == 0) |
| 1765 | resolution.y=resolution.x; |
| 1766 | } |
| 1767 | if (identity == MagickFalse) |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 1768 | (void) TransformImage(&annotate_image,"0x0",(char *) NULL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1769 | else |
| 1770 | { |
| 1771 | RectangleInfo |
| 1772 | crop_info; |
| 1773 | |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1774 | crop_info=GetImageBoundingBox(annotate_image,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1775 | crop_info.height=(size_t) ((resolution.y/DefaultResolution)* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1776 | ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1777 | crop_info.y=(ssize_t) ceil((resolution.y/DefaultResolution)*extent.y/8.0- |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 1778 | 0.5); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1779 | (void) FormatLocaleString(geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 1780 | "%.20gx%.20g%+.20g%+.20g",(double) crop_info.width,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1781 | crop_info.height,(double) crop_info.x,(double) crop_info.y); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 1782 | (void) TransformImage(&annotate_image,geometry,(char *) NULL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1783 | } |
| 1784 | metrics->pixels_per_em.x=(resolution.y/DefaultResolution)* |
| 1785 | ExpandAffine(&draw_info->affine)*draw_info->pointsize; |
| 1786 | metrics->pixels_per_em.y=metrics->pixels_per_em.x; |
| 1787 | metrics->ascent=metrics->pixels_per_em.x; |
| 1788 | metrics->descent=metrics->pixels_per_em.y/-5.0; |
| 1789 | metrics->width=(double) annotate_image->columns/ |
| 1790 | ExpandAffine(&draw_info->affine); |
| 1791 | metrics->height=1.152*metrics->pixels_per_em.x; |
| 1792 | metrics->max_advance=metrics->pixels_per_em.x; |
| 1793 | metrics->bounds.x1=0.0; |
| 1794 | metrics->bounds.y1=metrics->descent; |
| 1795 | metrics->bounds.x2=metrics->ascent+metrics->descent; |
| 1796 | metrics->bounds.y2=metrics->ascent+metrics->descent; |
| 1797 | metrics->underline_position=(-2.0); |
| 1798 | metrics->underline_thickness=1.0; |
| 1799 | if (draw_info->render == MagickFalse) |
| 1800 | { |
| 1801 | annotate_image=DestroyImage(annotate_image); |
| 1802 | return(MagickTrue); |
| 1803 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1804 | if (draw_info->fill.alpha != TransparentAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1805 | { |
cristy | bd65948 | 2011-10-09 23:19:32 +0000 | [diff] [blame] | 1806 | CacheView |
| 1807 | *annotate_view; |
| 1808 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1809 | MagickBooleanType |
| 1810 | sync; |
| 1811 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1812 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1813 | fill_color; |
| 1814 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1815 | /* |
| 1816 | Render fill color. |
| 1817 | */ |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 1818 | if (image->matte == MagickFalse) |
| 1819 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
| 1820 | if (annotate_image->matte == MagickFalse) |
| 1821 | (void) SetImageAlphaChannel(annotate_image,OpaqueAlphaChannel, |
| 1822 | exception); |
| 1823 | fill_color=draw_info->fill; |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 1824 | annotate_view=AcquireAuthenticCacheView(annotate_image,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1825 | for (y=0; y < (ssize_t) annotate_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1826 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1827 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1828 | x; |
| 1829 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1830 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1831 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1832 | |
| 1833 | q=GetCacheViewAuthenticPixels(annotate_view,0,y,annotate_image->columns, |
| 1834 | 1,exception); |
cristy | 6193b86 | 2011-08-06 16:33:59 +0000 | [diff] [blame] | 1835 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1836 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1837 | for (x=0; x < (ssize_t) annotate_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1838 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 1839 | (void) GetFillColor(draw_info,x,y,&fill_color,exception); |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 1840 | SetPixelAlpha(annotate_image,ClampToQuantum((((double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1841 | GetPixelIntensity(annotate_image,q)*fill_color.alpha)/ |
| 1842 | QuantumRange)),q); |
| 1843 | SetPixelRed(annotate_image,fill_color.red,q); |
| 1844 | SetPixelGreen(annotate_image,fill_color.green,q); |
| 1845 | SetPixelBlue(annotate_image,fill_color.blue,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1846 | q+=GetPixelChannels(annotate_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1847 | } |
| 1848 | sync=SyncCacheViewAuthenticPixels(annotate_view,exception); |
| 1849 | if (sync == MagickFalse) |
| 1850 | break; |
| 1851 | } |
| 1852 | annotate_view=DestroyCacheView(annotate_view); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 1853 | (void) CompositeImage(image,annotate_image,OverCompositeOp,MagickTrue, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1854 | (ssize_t) ceil(offset->x-0.5),(ssize_t) ceil(offset->y-(metrics->ascent+ |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 1855 | metrics->descent)-0.5),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1856 | } |
| 1857 | annotate_image=DestroyImage(annotate_image); |
| 1858 | return(MagickTrue); |
| 1859 | } |
| 1860 | |
| 1861 | /* |
| 1862 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1863 | % % |
| 1864 | % % |
| 1865 | % % |
| 1866 | + R e n d e r X 1 1 % |
| 1867 | % % |
| 1868 | % % |
| 1869 | % % |
| 1870 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1871 | % |
| 1872 | % RenderX11() renders text on the image with an X11 font. It also returns the |
| 1873 | % bounding box of the text relative to the image. |
| 1874 | % |
| 1875 | % The format of the RenderX11 method is: |
| 1876 | % |
| 1877 | % MagickBooleanType RenderX11(Image *image,DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1878 | % const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1879 | % |
| 1880 | % A description of each parameter follows: |
| 1881 | % |
| 1882 | % o image: the image. |
| 1883 | % |
| 1884 | % o draw_info: the draw info. |
| 1885 | % |
| 1886 | % o offset: (x,y) location of text relative to image. |
| 1887 | % |
| 1888 | % o metrics: bounding box of text. |
| 1889 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1890 | % o exception: return any errors or warnings in this structure. |
| 1891 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | */ |
| 1893 | #if defined(MAGICKCORE_X11_DELEGATE) |
| 1894 | static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 1895 | const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1896 | { |
| 1897 | MagickBooleanType |
| 1898 | status; |
| 1899 | |
| 1900 | static DrawInfo |
| 1901 | cache_info; |
| 1902 | |
| 1903 | static Display |
| 1904 | *display = (Display *) NULL; |
| 1905 | |
| 1906 | static XAnnotateInfo |
| 1907 | annotate_info; |
| 1908 | |
| 1909 | static XFontStruct |
| 1910 | *font_info; |
| 1911 | |
| 1912 | static XPixelInfo |
| 1913 | pixel; |
| 1914 | |
| 1915 | static XResourceInfo |
| 1916 | resource_info; |
| 1917 | |
| 1918 | static XrmDatabase |
| 1919 | resource_database; |
| 1920 | |
| 1921 | static XStandardColormap |
| 1922 | *map_info; |
| 1923 | |
| 1924 | static XVisualInfo |
| 1925 | *visual_info; |
| 1926 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1927 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1928 | height, |
| 1929 | width; |
| 1930 | |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 1931 | if (annotate_semaphore == (SemaphoreInfo *) NULL) |
| 1932 | AcquireSemaphoreInfo(&annotate_semaphore); |
| 1933 | LockSemaphoreInfo(annotate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1934 | if (display == (Display *) NULL) |
| 1935 | { |
cristy | 104cea8 | 2009-10-25 02:26:51 +0000 | [diff] [blame] | 1936 | const char |
| 1937 | *client_name; |
| 1938 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1939 | ImageInfo |
| 1940 | *image_info; |
| 1941 | |
| 1942 | /* |
| 1943 | Open X server connection. |
| 1944 | */ |
| 1945 | display=XOpenDisplay(draw_info->server_name); |
| 1946 | if (display == (Display *) NULL) |
| 1947 | { |
| 1948 | ThrowXWindowException(XServerError,"UnableToOpenXServer", |
| 1949 | draw_info->server_name); |
| 1950 | return(MagickFalse); |
| 1951 | } |
| 1952 | /* |
| 1953 | Get user defaults from X resource database. |
| 1954 | */ |
| 1955 | (void) XSetErrorHandler(XError); |
| 1956 | image_info=AcquireImageInfo(); |
cristy | 104cea8 | 2009-10-25 02:26:51 +0000 | [diff] [blame] | 1957 | client_name=GetClientName(); |
cristy | 309c861 | 2009-10-25 13:16:09 +0000 | [diff] [blame] | 1958 | resource_database=XGetResourceDatabase(display,client_name); |
cristy | f9d6dc0 | 2012-01-19 02:14:44 +0000 | [diff] [blame] | 1959 | XGetResourceInfo(image_info,resource_database,client_name, |
| 1960 | &resource_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1961 | resource_info.close_server=MagickFalse; |
| 1962 | resource_info.colormap=PrivateColormap; |
| 1963 | resource_info.font=AcquireString(draw_info->font); |
| 1964 | resource_info.background_color=AcquireString("#ffffffffffff"); |
| 1965 | resource_info.foreground_color=AcquireString("#000000000000"); |
| 1966 | map_info=XAllocStandardColormap(); |
| 1967 | if (map_info == (XStandardColormap *) NULL) |
| 1968 | { |
| 1969 | ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", |
| 1970 | image->filename); |
| 1971 | return(MagickFalse); |
| 1972 | } |
| 1973 | /* |
| 1974 | Initialize visual info. |
| 1975 | */ |
| 1976 | visual_info=XBestVisualInfo(display,map_info,&resource_info); |
| 1977 | if (visual_info == (XVisualInfo *) NULL) |
| 1978 | { |
| 1979 | ThrowXWindowException(XServerError,"UnableToGetVisual", |
| 1980 | image->filename); |
| 1981 | return(MagickFalse); |
| 1982 | } |
| 1983 | map_info->colormap=(Colormap) NULL; |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 1984 | pixel.pixels=(unsigned long *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1985 | /* |
| 1986 | Initialize Standard Colormap info. |
| 1987 | */ |
| 1988 | XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen), |
| 1989 | map_info); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1990 | XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL, |
| 1991 | &pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1992 | pixel.annotate_context=XDefaultGC(display,visual_info->screen); |
| 1993 | /* |
| 1994 | Initialize font info. |
| 1995 | */ |
| 1996 | font_info=XBestFont(display,&resource_info,MagickFalse); |
| 1997 | if (font_info == (XFontStruct *) NULL) |
| 1998 | { |
| 1999 | ThrowXWindowException(XServerError,"UnableToLoadFont", |
| 2000 | draw_info->font); |
| 2001 | return(MagickFalse); |
| 2002 | } |
| 2003 | if ((map_info == (XStandardColormap *) NULL) || |
| 2004 | (visual_info == (XVisualInfo *) NULL) || |
| 2005 | (font_info == (XFontStruct *) NULL)) |
| 2006 | { |
| 2007 | XFreeResources(display,visual_info,map_info,&pixel,font_info, |
| 2008 | &resource_info,(XWindowInfo *) NULL); |
| 2009 | ThrowXWindowException(XServerError,"UnableToLoadFont", |
| 2010 | image->filename); |
| 2011 | return(MagickFalse); |
| 2012 | } |
| 2013 | cache_info=(*draw_info); |
| 2014 | } |
cristy | d7ecaca | 2011-01-24 14:14:53 +0000 | [diff] [blame] | 2015 | UnlockSemaphoreInfo(annotate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2016 | /* |
| 2017 | Initialize annotate info. |
| 2018 | */ |
| 2019 | XGetAnnotateInfo(&annotate_info); |
| 2020 | annotate_info.stencil=ForegroundStencil; |
| 2021 | if (cache_info.font != draw_info->font) |
| 2022 | { |
| 2023 | /* |
| 2024 | Type name has changed. |
| 2025 | */ |
| 2026 | (void) XFreeFont(display,font_info); |
| 2027 | (void) CloneString(&resource_info.font,draw_info->font); |
| 2028 | font_info=XBestFont(display,&resource_info,MagickFalse); |
| 2029 | if (font_info == (XFontStruct *) NULL) |
| 2030 | { |
| 2031 | ThrowXWindowException(XServerError,"UnableToLoadFont", |
| 2032 | draw_info->font); |
| 2033 | return(MagickFalse); |
| 2034 | } |
| 2035 | } |
| 2036 | if (image->debug != MagickFalse) |
| 2037 | (void) LogMagickEvent(AnnotateEvent,GetMagickModule(), |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2038 | "Font %s; pointsize %g",draw_info->font != (char *) NULL ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2039 | draw_info->font : "none",draw_info->pointsize); |
| 2040 | cache_info=(*draw_info); |
| 2041 | annotate_info.font_info=font_info; |
| 2042 | annotate_info.text=(char *) draw_info->text; |
| 2043 | annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text, |
| 2044 | (int) strlen(draw_info->text)); |
| 2045 | annotate_info.height=(unsigned int) font_info->ascent+font_info->descent; |
| 2046 | metrics->pixels_per_em.x=(double) font_info->max_bounds.width; |
| 2047 | metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent; |
| 2048 | metrics->ascent=(double) font_info->ascent+4; |
| 2049 | metrics->descent=(double) (-font_info->descent); |
| 2050 | metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine); |
| 2051 | metrics->height=font_info->ascent+font_info->descent; |
| 2052 | metrics->max_advance=(double) font_info->max_bounds.width; |
| 2053 | metrics->bounds.x1=0.0; |
| 2054 | metrics->bounds.y1=metrics->descent; |
| 2055 | metrics->bounds.x2=metrics->ascent+metrics->descent; |
| 2056 | metrics->bounds.y2=metrics->ascent+metrics->descent; |
| 2057 | metrics->underline_position=(-2.0); |
| 2058 | metrics->underline_thickness=1.0; |
| 2059 | if (draw_info->render == MagickFalse) |
| 2060 | return(MagickTrue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2061 | if (draw_info->fill.alpha == TransparentAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2062 | return(MagickTrue); |
| 2063 | /* |
| 2064 | Render fill color. |
| 2065 | */ |
| 2066 | width=annotate_info.width; |
| 2067 | height=annotate_info.height; |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 2068 | if ((fabs(draw_info->affine.rx) >= MagickEpsilon) || |
| 2069 | (fabs(draw_info->affine.ry) >= MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2070 | { |
cristy | aa83c2c | 2011-09-21 13:36:25 +0000 | [diff] [blame] | 2071 | if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) && |
| 2072 | (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon)) |
| 2073 | annotate_info.degrees=(double) (180.0/MagickPI)* |
cristy | 854209a | 2011-09-19 17:02:57 +0000 | [diff] [blame] | 2074 | atan2(draw_info->affine.rx,draw_info->affine.sx); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2075 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2076 | (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 2077 | "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 2078 | ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+ |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2079 | draw_info->interline_spacing-0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2080 | pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red); |
| 2081 | pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green); |
| 2082 | pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue); |
cristy | 7c3af95 | 2011-10-20 16:04:16 +0000 | [diff] [blame] | 2083 | status=XAnnotateImage(display,&pixel,&annotate_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2084 | if (status == 0) |
| 2085 | { |
| 2086 | ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", |
| 2087 | image->filename); |
| 2088 | return(MagickFalse); |
| 2089 | } |
| 2090 | return(MagickTrue); |
| 2091 | } |
| 2092 | #else |
| 2093 | static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 2094 | const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2095 | { |
| 2096 | (void) draw_info; |
| 2097 | (void) offset; |
| 2098 | (void) metrics; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 2099 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 2100 | MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2101 | image->filename); |
| 2102 | return(MagickFalse); |
| 2103 | } |
| 2104 | #endif |