Changeset 7117
- Timestamp:
- 03/15/12 07:25:26 (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ImageMagick/branches/ImageMagick-6.7.6/coders/pango.c
r7115 r7117 6 6 % PPPP AAA N N GGGG OOO % 7 7 % P P A A NN N G O O % 8 % PPPP AAAAA N N N G GG O O %9 % P A A N NN G G O O %10 % P A A N N GGG OOO %11 % % 12 % % 13 % Read Text Caption.%8 % PPPP AAAAA N N N G GGG O O % 9 % P M A A N NN G G O O % 10 % P A A N N GGGG OOO % 11 % % 12 % % 13 % Read Pango Markup Language Format % 14 14 % % 15 15 % Software Design % 16 16 % John Cristy % 17 % February 2002%17 % March 2012 % 18 18 % % 19 19 % % … … 53 53 #include "magick/list.h" 54 54 #include "magick/magick.h" 55 #include "magick/module.h" 55 56 #include "magick/memory_.h" 56 #include "magick/module.h"57 57 #include "magick/option.h" 58 58 #include "magick/property.h" … … 68 68 #endif 69 69 70 #if defined(MAGICKCORE_PANGOFT2_DELEGATE) 70 71 /* 71 72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% … … 79 80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 80 81 % 81 % ReadPANGOImage() reads a PANGO image file and returns it. It 82 % allocates the memory necessary for the new Image structure and returns a 83 % pointer to the new image. 82 % ReadPANGOImage() reads an image in the Pango Markup Language Format. 84 83 % 85 84 % The format of the ReadPANGOImage method is: … … 95 94 % 96 95 */ 97 #if defined(MAGICKCORE_PANGOFT2_DELEGATE) 96 98 97 static void PangoSubstitute(FcPattern *pattern,void *context) 99 98 { … … 110 109 } 111 110 112 static MagickBooleanType PangoImage(const ImageInfo *image_info,Image *image,113 const DrawInfo *draw_info,ExceptionInfo *exception)111 static Image *ReadPANGOImage(const ImageInfo *image_info, 112 ExceptionInfo *exception) 114 113 { 114 char 115 *caption, 116 *property; 117 115 118 const char 116 119 *option; 117 120 121 DrawInfo 122 *draw_info; 123 118 124 FT_Bitmap 119 125 *canvas; 120 126 127 Image 128 *image; 129 121 130 PangoAlignment 122 131 align; … … 155 164 y; 156 165 166 /* 167 Initialize Image structure. 168 */ 169 assert(image_info != (const ImageInfo *) NULL); 170 assert(image_info->signature == MagickSignature); 171 if (image_info->debug != MagickFalse) 172 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 173 image_info->filename); 174 assert(exception != (ExceptionInfo *) NULL); 175 assert(exception->signature == MagickSignature); 176 image=AcquireImage(image_info); 177 (void) ResetImagePage(image,"0x0+0+0"); 157 178 /* 158 179 Get context. … … 161 182 pango_ft2_font_map_set_resolution((PangoFT2FontMap *) fontmap, 162 183 image->x_resolution,image->y_resolution); 163 option=GetImageOption(image_info," pango:hinting");184 option=GetImageOption(image_info,"caption:hinting"); 164 185 pango_ft2_font_map_set_default_substitute((PangoFT2FontMap *) fontmap, 165 186 PangoSubstitute,(char *) option,NULL); 166 187 context=pango_font_map_create_context(fontmap); 167 option=GetImageOption(image_info," pango:language");188 option=GetImageOption(image_info,"caption:language"); 168 189 if (option != (const char *) NULL) 169 190 pango_context_set_language(context,pango_language_from_string(option)); 191 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); 170 192 pango_context_set_base_dir(context,draw_info->direction == 171 193 RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR); … … 179 201 } 180 202 pango_context_set_base_gravity(context,gravity); 181 option=GetImageOption(image_info," pango:gravity-hint");203 option=GetImageOption(image_info,"caption:gravity-hint"); 182 204 if (option != (const char *) NULL) 183 205 { … … 193 215 */ 194 216 layout=pango_layout_new(context); 195 option=GetImageOption(image_info," pango:auto-dir");217 option=GetImageOption(image_info,"caption:auto-dir"); 196 218 if (option != (const char *) NULL) 197 219 pango_layout_set_auto_dir(layout,1); 198 option=GetImageOption(image_info," pango:ellipsize");220 option=GetImageOption(image_info,"caption:ellipsize"); 199 221 if (option != (const char *) NULL) 200 222 { … … 208 230 pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START); 209 231 } 210 option=GetImageOption(image_info," pango:justify");232 option=GetImageOption(image_info,"caption:justify"); 211 233 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) 212 234 pango_layout_set_justify(layout,1); 213 option=GetImageOption(image_info," pango:single-paragraph");235 option=GetImageOption(image_info,"caption:single-paragraph"); 214 236 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) 215 237 pango_layout_set_single_paragraph_mode(layout,1); 216 option=GetImageOption(image_info," pango:wrap");238 option=GetImageOption(image_info,"caption:wrap"); 217 239 if (option != (const char *) NULL) 218 240 { … … 224 246 pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR); 225 247 } 226 option=GetImageOption(image_info," pango:indent");248 option=GetImageOption(image_info,"caption:indent"); 227 249 if (option != (const char *) NULL) 228 250 pango_layout_set_indent(layout,(StringToLong(option)*image->x_resolution* … … 250 272 description=pango_font_description_from_string(draw_info->font == 251 273 (char *) NULL ? "helvetica" : draw_info->font); 252 pango_font_description_set_size(description,(int) (0.815*PANGO_SCALE* 253 draw_info->pointsize+0.5)); 274 pango_font_description_set_size(description,PANGO_SCALE*draw_info->pointsize); 254 275 pango_layout_set_font_description(layout,description); 255 276 pango_font_description_free(description); 277 property=InterpretImageProperties(image_info,image,image_info->filename); 278 (void) SetImageProperty(image,"caption",property); 279 property=DestroyString(property); 280 caption=ConstantString(GetImageProperty(image,"caption")); 256 281 /* 257 282 Render caption. 258 283 */ 284 option=GetImageOption(image_info,"caption:markup"); 259 285 if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) 260 pango_layout_set_markup(layout, draw_info->text,-1);286 pango_layout_set_markup(layout,caption,-1); 261 287 else 262 pango_layout_set_text(layout, draw_info->text,-1);288 pango_layout_set_text(layout,caption,-1); 263 289 pango_layout_context_changed(layout); 264 290 page.x=0; … … 293 319 canvas=(FT_Bitmap *) AcquireMagickMemory(sizeof(*canvas)); 294 320 if (canvas == (FT_Bitmap *) NULL) 295 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", 296 image->filename); 321 { 322 draw_info=DestroyDrawInfo(draw_info); 323 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 324 } 297 325 canvas->width=image->columns; 298 326 canvas->pitch=(canvas->width+3) & ~3; … … 302 330 if (canvas->buffer == (unsigned char *) NULL) 303 331 { 332 draw_info=DestroyDrawInfo(draw_info); 304 333 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 305 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", 306 image->filename); 334 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 307 335 } 308 336 canvas->num_grays=256; … … 317 345 if (SetImageBackgroundColor(image) == MagickFalse) 318 346 { 347 draw_info=DestroyDrawInfo(draw_info); 319 348 canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); 320 349 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 350 caption=DestroyString(caption); 321 351 image=DestroyImageList(image); 322 return( MagickFalse);352 return((Image *) NULL); 323 353 } 324 354 p=canvas->buffer; … … 352 382 Relinquish resources. 353 383 */ 384 draw_info=DestroyDrawInfo(draw_info); 354 385 canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); 355 386 canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 356 return(MagickTrue); 387 caption=DestroyString(caption); 388 return(GetFirstImageInList(image)); 357 389 } 358 390 #endif 359 360 static Image *ReadPANGOImage(const ImageInfo *image_info,361 ExceptionInfo *exception)362 {363 char364 *caption,365 geometry[MaxTextExtent],366 *property;367 368 const char369 *gravity,370 *option;371 372 DrawInfo373 *draw_info;374 375 Image376 *image;377 378 MagickBooleanType379 status;380 381 register ssize_t382 i;383 384 size_t385 height,386 width;387 388 TypeMetric389 metrics;390 391 /*392 Initialize Image structure.393 */394 assert(image_info != (const ImageInfo *) NULL);395 assert(image_info->signature == MagickSignature);396 if (image_info->debug != MagickFalse)397 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",398 image_info->filename);399 assert(exception != (ExceptionInfo *) NULL);400 assert(exception->signature == MagickSignature);401 image=AcquireImage(image_info);402 if (image->columns == 0)403 ThrowReaderException(OptionError,"MustSpecifyImageSize");404 (void) ResetImagePage(image,"0x0+0+0");405 /*406 Format caption.407 */408 property=InterpretImageProperties(image_info,image,image_info->filename);409 option=GetImageOption(image_info,"filename");410 if (option == (const char *) NULL)411 property=InterpretImageProperties(image_info,image,image_info->filename);412 else413 if (LocaleNCompare(option,"pango:",8) == 0)414 property=InterpretImageProperties(image_info,image,option+8);415 else416 property=InterpretImageProperties(image_info,image,option);417 (void) SetImageProperty(image,"caption",property);418 property=DestroyString(property);419 caption=ConstantString(GetImageProperty(image,"caption"));420 draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);421 (void) CloneString(&draw_info->text,caption);422 gravity=GetImageOption(image_info,"gravity");423 if (gravity != (char *) NULL)424 draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,425 MagickFalse,gravity);426 if ((*caption != '\0') && (image->rows != 0) &&427 (image_info->pointsize == 0.0))428 {429 char430 *text;431 432 /*433 Scale text to fit bounding box.434 */435 for ( ; ; )436 {437 text=AcquireString(caption);438 i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text);439 (void) CloneString(&draw_info->text,text);440 text=DestroyString(text);441 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",442 -metrics.bounds.x1,metrics.ascent);443 if (draw_info->gravity == UndefinedGravity)444 (void) CloneString(&draw_info->geometry,geometry);445 status=GetMultilineTypeMetrics(image,draw_info,&metrics);446 (void) status;447 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);448 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);449 if ((width > (image->columns+1)) || (height > (image->rows+1)))450 break;451 draw_info->pointsize*=2.0;452 }453 draw_info->pointsize/=2.0;454 for ( ; ; )455 {456 text=AcquireString(caption);457 i=FormatMagickCaption(image,draw_info,MagickFalse,&metrics,&text);458 (void) CloneString(&draw_info->text,text);459 text=DestroyString(text);460 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",461 -metrics.bounds.x1,metrics.ascent);462 if (draw_info->gravity == UndefinedGravity)463 (void) CloneString(&draw_info->geometry,geometry);464 status=GetMultilineTypeMetrics(image,draw_info,&metrics);465 width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);466 height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);467 if ((width > (image->columns+1)) || (height > (image->rows+1)))468 break;469 draw_info->pointsize++;470 }471 draw_info->pointsize--;472 }473 i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&caption);474 if (image->rows == 0)475 image->rows=(size_t) ((i+1)*(metrics.ascent-metrics.descent+476 draw_info->interline_spacing+draw_info->stroke_width)+0.5);477 if (image->rows == 0)478 image->rows=(size_t) ((i+1)*draw_info->pointsize+479 draw_info->interline_spacing+draw_info->stroke_width+0.5);480 if (SetImageBackgroundColor(image) == MagickFalse)481 {482 InheritException(exception,&image->exception);483 image=DestroyImageList(image);484 return((Image *) NULL);485 }486 /*487 Draw caption.488 */489 (void) CloneString(&draw_info->text,caption);490 status=GetMultilineTypeMetrics(image,draw_info,&metrics);491 if ((draw_info->gravity != UndefinedGravity) &&492 (draw_info->direction != RightToLeftDirection))493 image->page.x=(ssize_t) (metrics.bounds.x1-draw_info->stroke_width/2.0);494 else495 {496 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",497 -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+498 draw_info->stroke_width/2.0);499 if (draw_info->direction == RightToLeftDirection)500 (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",501 image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),502 metrics.ascent+draw_info->stroke_width/2.0);503 draw_info->geometry=AcquireString(geometry);504 }505 #if defined(MAGICKCORE_PANGOFT2_DELEGATE)506 status=PangoImage(image_info,image,draw_info,exception);507 #else508 status=AnnotateImage(image,draw_info);509 #endif510 draw_info=DestroyDrawInfo(draw_info);511 caption=DestroyString(caption);512 if (status == MagickFalse)513 {514 image=DestroyImageList(image);515 return((Image *) NULL);516 }517 return(GetFirstImageInList(image));518 }519 391 520 392 /* … … 529 401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 530 402 % 531 % RegisterPANGOImage() adds attributes for the P ANGO image format to403 % RegisterPANGOImage() adds attributes for the Pango Markup Language format to 532 404 % the list of supported formats. The attributes include the image format 533 405 % tag, a method to read and/or write the format, whether the format … … 551 423 *version='\0'; 552 424 #if defined(PANGO_VERSION_STRING) 553 (void) FormatLocaleString(version,MaxTextExtent," Pangoft2 %s",425 (void) FormatLocaleString(version,MaxTextExtent,"(Pangoft2 %s)", 554 426 PANGO_VERSION_STRING); 555 427 #endif 556 428 entry=SetMagickInfo("PANGO"); 429 #if defined(MAGICKCORE_PANGOFT2_DELEGATE) 557 430 entry->decoder=(DecodeImageHandler *) ReadPANGOImage; 558 entry->description=ConstantString("Caption"); 431 #endif 432 entry->description=ConstantString("Pango Markup Language"); 559 433 if (*version != '\0') 560 434 entry->version=ConstantString(version); … … 576 450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 577 451 % 578 % UnregisterPANGOImage() removes format registrations made by the 579 % PANGO modulefrom the list of supported formats.452 % UnregisterPANGOImage() removes format registrations made by the Pango module 453 % from the list of supported formats. 580 454 % 581 455 % The format of the UnregisterPANGOImage method is:
Note: See TracChangeset
for help on using the changeset viewer.
