Changeset 7117


Ignore:
Timestamp:
03/15/12 07:25:26 (14 months ago)
Author:
cristy
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ImageMagick/branches/ImageMagick-6.7.6/coders/pango.c

    r7115 r7117  
    66%                     PPPP    AAA   N   N   GGGG   OOO                        % 
    77%                     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                       % 
    1414%                                                                             % 
    1515%                              Software Design                                % 
    1616%                                John Cristy                                  % 
    17 %                               February 2002                                 % 
     17%                                 March 2012                                  % 
    1818%                                                                             % 
    1919%                                                                             % 
     
    5353#include "magick/list.h" 
    5454#include "magick/magick.h" 
     55#include "magick/module.h" 
    5556#include "magick/memory_.h" 
    56 #include "magick/module.h" 
    5757#include "magick/option.h" 
    5858#include "magick/property.h" 
     
    6868#endif 
    6969 
     70#if defined(MAGICKCORE_PANGOFT2_DELEGATE) 
    7071/* 
    7172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     
    7980%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    8081% 
    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. 
    8483% 
    8584%  The format of the ReadPANGOImage method is: 
     
    9594% 
    9695*/ 
    97 #if defined(MAGICKCORE_PANGOFT2_DELEGATE) 
     96 
    9897static void PangoSubstitute(FcPattern *pattern,void *context) 
    9998{ 
     
    110109} 
    111110 
    112 static MagickBooleanType PangoImage(const ImageInfo *image_info,Image *image, 
    113   const DrawInfo *draw_info,ExceptionInfo *exception) 
     111static Image *ReadPANGOImage(const ImageInfo *image_info, 
     112  ExceptionInfo *exception) 
    114113{ 
     114  char 
     115    *caption, 
     116    *property; 
     117 
    115118  const char 
    116119    *option; 
    117120 
     121  DrawInfo 
     122    *draw_info; 
     123 
    118124  FT_Bitmap 
    119125    *canvas; 
    120126 
     127  Image 
     128    *image; 
     129 
    121130  PangoAlignment 
    122131    align; 
     
    155164    y; 
    156165 
     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"); 
    157178  /* 
    158179    Get context. 
     
    161182  pango_ft2_font_map_set_resolution((PangoFT2FontMap *) fontmap, 
    162183    image->x_resolution,image->y_resolution); 
    163   option=GetImageOption(image_info,"pango:hinting"); 
     184  option=GetImageOption(image_info,"caption:hinting"); 
    164185  pango_ft2_font_map_set_default_substitute((PangoFT2FontMap *) fontmap, 
    165186    PangoSubstitute,(char *) option,NULL); 
    166187  context=pango_font_map_create_context(fontmap); 
    167   option=GetImageOption(image_info,"pango:language"); 
     188  option=GetImageOption(image_info,"caption:language"); 
    168189  if (option != (const char *) NULL) 
    169190    pango_context_set_language(context,pango_language_from_string(option)); 
     191  draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); 
    170192  pango_context_set_base_dir(context,draw_info->direction == 
    171193    RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR); 
     
    179201  } 
    180202  pango_context_set_base_gravity(context,gravity); 
    181   option=GetImageOption(image_info,"pango:gravity-hint"); 
     203  option=GetImageOption(image_info,"caption:gravity-hint"); 
    182204  if (option != (const char *) NULL) 
    183205    { 
     
    193215  */ 
    194216  layout=pango_layout_new(context); 
    195   option=GetImageOption(image_info,"pango:auto-dir"); 
     217  option=GetImageOption(image_info,"caption:auto-dir"); 
    196218  if (option != (const char *) NULL) 
    197219    pango_layout_set_auto_dir(layout,1); 
    198   option=GetImageOption(image_info,"pango:ellipsize"); 
     220  option=GetImageOption(image_info,"caption:ellipsize"); 
    199221  if (option != (const char *) NULL) 
    200222    { 
     
    208230        pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START); 
    209231    } 
    210   option=GetImageOption(image_info,"pango:justify"); 
     232  option=GetImageOption(image_info,"caption:justify"); 
    211233  if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) 
    212234    pango_layout_set_justify(layout,1); 
    213   option=GetImageOption(image_info,"pango:single-paragraph"); 
     235  option=GetImageOption(image_info,"caption:single-paragraph"); 
    214236  if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse)) 
    215237    pango_layout_set_single_paragraph_mode(layout,1); 
    216   option=GetImageOption(image_info,"pango:wrap"); 
     238  option=GetImageOption(image_info,"caption:wrap"); 
    217239  if (option != (const char *) NULL) 
    218240    { 
     
    224246        pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR); 
    225247    } 
    226   option=GetImageOption(image_info,"pango:indent"); 
     248  option=GetImageOption(image_info,"caption:indent"); 
    227249  if (option != (const char *) NULL) 
    228250    pango_layout_set_indent(layout,(StringToLong(option)*image->x_resolution* 
     
    250272  description=pango_font_description_from_string(draw_info->font == 
    251273    (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); 
    254275  pango_layout_set_font_description(layout,description); 
    255276  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")); 
    256281  /* 
    257282    Render caption. 
    258283  */ 
     284  option=GetImageOption(image_info,"caption:markup"); 
    259285  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); 
    261287  else 
    262     pango_layout_set_text(layout,draw_info->text,-1); 
     288    pango_layout_set_text(layout,caption,-1); 
    263289  pango_layout_context_changed(layout); 
    264290  page.x=0; 
     
    293319  canvas=(FT_Bitmap *) AcquireMagickMemory(sizeof(*canvas)); 
    294320  if (canvas == (FT_Bitmap *) NULL) 
    295     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", 
    296       image->filename); 
     321    { 
     322      draw_info=DestroyDrawInfo(draw_info); 
     323      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 
     324    } 
    297325  canvas->width=image->columns; 
    298326  canvas->pitch=(canvas->width+3) & ~3; 
     
    302330  if (canvas->buffer == (unsigned char *) NULL) 
    303331    { 
     332      draw_info=DestroyDrawInfo(draw_info); 
    304333      canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 
    305       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", 
    306         image->filename); 
     334      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); 
    307335    } 
    308336  canvas->num_grays=256; 
     
    317345  if (SetImageBackgroundColor(image) == MagickFalse) 
    318346    { 
     347      draw_info=DestroyDrawInfo(draw_info); 
    319348      canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); 
    320349      canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 
     350      caption=DestroyString(caption); 
    321351      image=DestroyImageList(image); 
    322       return(MagickFalse); 
     352      return((Image *) NULL); 
    323353    } 
    324354  p=canvas->buffer; 
     
    352382    Relinquish resources. 
    353383  */ 
     384  draw_info=DestroyDrawInfo(draw_info); 
    354385  canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); 
    355386  canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); 
    356   return(MagickTrue); 
     387  caption=DestroyString(caption); 
     388  return(GetFirstImageInList(image)); 
    357389} 
    358390#endif 
    359  
    360 static Image *ReadPANGOImage(const ImageInfo *image_info, 
    361   ExceptionInfo *exception) 
    362 { 
    363   char 
    364     *caption, 
    365     geometry[MaxTextExtent], 
    366     *property; 
    367  
    368   const char 
    369     *gravity, 
    370     *option; 
    371  
    372   DrawInfo 
    373     *draw_info; 
    374  
    375   Image 
    376     *image; 
    377  
    378   MagickBooleanType 
    379     status; 
    380  
    381   register ssize_t 
    382     i; 
    383  
    384   size_t 
    385     height, 
    386     width; 
    387  
    388   TypeMetric 
    389     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   else 
    413     if (LocaleNCompare(option,"pango:",8) == 0) 
    414       property=InterpretImageProperties(image_info,image,option+8); 
    415     else 
    416       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       char 
    430         *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   else 
    495     { 
    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 #else 
    508   status=AnnotateImage(image,draw_info); 
    509 #endif 
    510   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 } 
    519391 
    520392/* 
     
    529401%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    530402% 
    531 %  RegisterPANGOImage() adds attributes for the PANGO image format to 
     403%  RegisterPANGOImage() adds attributes for the Pango Markup Language format to 
    532404%  the list of supported formats.  The attributes include the image format 
    533405%  tag, a method to read and/or write the format, whether the format 
     
    551423  *version='\0'; 
    552424#if defined(PANGO_VERSION_STRING) 
    553   (void) FormatLocaleString(version,MaxTextExtent,"Pangoft2 %s", 
     425  (void) FormatLocaleString(version,MaxTextExtent,"(Pangoft2 %s)", 
    554426    PANGO_VERSION_STRING); 
    555427#endif 
    556428  entry=SetMagickInfo("PANGO"); 
     429#if defined(MAGICKCORE_PANGOFT2_DELEGATE) 
    557430  entry->decoder=(DecodeImageHandler *) ReadPANGOImage; 
    558   entry->description=ConstantString("Caption"); 
     431#endif 
     432  entry->description=ConstantString("Pango Markup Language"); 
    559433  if (*version != '\0') 
    560434    entry->version=ConstantString(version); 
     
    576450%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
    577451% 
    578 %  UnregisterPANGOImage() removes format registrations made by the 
    579 PANGO module from the list of supported formats. 
     452%  UnregisterPANGOImage() removes format registrations made by the Pango module 
     453from the list of supported formats. 
    580454% 
    581455%  The format of the UnregisterPANGOImage method is: 
Note: See TracChangeset for help on using the changeset viewer.