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