From: cristy Date: Mon, 26 Mar 2012 19:33:21 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~5968 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19642b08da630947f68cde41cda3d456d0cc8e58;p=imagemagick --- diff --git a/coders/pango.c b/coders/pango.c index 361a1478d..cea5f5697 100644 --- a/coders/pango.c +++ b/coders/pango.c @@ -52,8 +52,10 @@ #include "MagickCore/image-private.h" #include "MagickCore/list.h" #include "MagickCore/magick.h" -#include "MagickCore/module.h" #include "MagickCore/memory_.h" +#include "MagickCore/module.h" +#include "MagickCore/monitor.h" +#include "MagickCore/monitor-private.h" #include "MagickCore/option.h" #include "MagickCore/pixel-accessor.h" #include "MagickCore/property.h" @@ -63,13 +65,13 @@ #include "MagickCore/string-private.h" #include "MagickCore/token.h" #include "MagickCore/utility.h" -#if defined(MAGICKCORE_PANGOFT2_DELEGATE) +#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) #include -#include +#include #include #endif -#if defined(MAGICKCORE_PANGOFT2_DELEGATE) +#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % @@ -95,49 +97,40 @@ % o exception: return any errors or warnings in this structure. % */ - -static void PangoSubstitute(FcPattern *pattern,void *context) -{ - const char - *option; - - option=(const char *) context; - if (option == (const char *) NULL) - return; - FcPatternDel(pattern,FC_HINTING); - FcPatternAddBool(pattern, FC_HINTING,LocaleCompare(option,"none") != 0); - FcPatternDel(pattern,FC_AUTOHINT); - FcPatternAddBool(pattern,FC_AUTOHINT,LocaleCompare(option,"auto") == 0); -} - static Image *ReadPANGOImage(const ImageInfo *image_info, ExceptionInfo *exception) { + cairo_font_options_t + *font_options; + + cairo_surface_t + *surface; + char *caption, *property; + cairo_t + *cairo_info; + const char *option; DrawInfo *draw_info; - FT_Bitmap - *canvas; - Image *image; + MagickBooleanType + status; + PangoAlignment align; PangoContext *context; - PangoFontDescription - *description; - PangoFontMap *fontmap; @@ -165,6 +158,9 @@ static Image *ReadPANGOImage(const ImageInfo *image_info, ssize_t y; + unsigned char + *pixels; + /* Initialize Image structure. */ @@ -195,13 +191,20 @@ static Image *ReadPANGOImage(const ImageInfo *image_info, /* Get context. */ - fontmap=(PangoFontMap *) pango_ft2_font_map_new(); - pango_ft2_font_map_set_resolution((PangoFT2FontMap *) fontmap, - image->resolution.x,image->resolution.y); + fontmap=pango_cairo_font_map_new(); + pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), + image->resolution.x); + font_options=cairo_font_options_create(); option=GetImageOption(image_info,"pango:hinting"); - pango_ft2_font_map_set_default_substitute((PangoFT2FontMap *) fontmap, - PangoSubstitute,(char *) option,NULL); + if (option != (const char *) NULL) + { + if (LocaleCompare(option,"none") != 0) + cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_NONE); + if (LocaleCompare(option,"full") != 0) + cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_FULL); + } context=pango_font_map_create_context(fontmap); + pango_cairo_context_set_font_options(context,font_options); option=GetImageOption(image_info,"pango:language"); if (option != (const char *) NULL) pango_context_set_language(context,pango_language_from_string(option)); @@ -286,12 +289,20 @@ static Image *ReadPANGOImage(const ImageInfo *image_info, (draw_info->direction == RightToLeftDirection)) align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align); pango_layout_set_alignment(layout,align); - description=pango_font_description_from_string(draw_info->font == - (char *) NULL ? "helvetica" : draw_info->font); - pango_font_description_set_size(description,(int) (PANGO_SCALE* - draw_info->pointsize+0.5)); - pango_layout_set_font_description(layout,description); - pango_font_description_free(description); + if (draw_info->font != (char *) NULL) + { + PangoFontDescription + *description; + + /* + Set font. + */ + description=pango_font_description_from_string(draw_info->font); + pango_font_description_set_size(description,(int) (PANGO_SCALE* + draw_info->pointsize+0.5)); + pango_layout_set_font_description(layout,description); + pango_font_description_free(description); + } option=GetImageOption(image_info,"pango:markup"); if ((option != (const char *) NULL) && (IsMagickTrue(option) == MagickFalse)) pango_layout_set_text(layout,caption,-1); @@ -336,76 +347,75 @@ static Image *ReadPANGOImage(const ImageInfo *image_info, /* Create canvas. */ - canvas=(FT_Bitmap *) AcquireMagickMemory(sizeof(*canvas)); - if (canvas == (FT_Bitmap *) NULL) - { - draw_info=DestroyDrawInfo(draw_info); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } - canvas->width=image->columns; - canvas->pitch=(canvas->width+3) & ~3; - canvas->rows=image->rows; - canvas->buffer=(unsigned char *) AcquireQuantumMemory(canvas->pitch, - canvas->rows*sizeof(*canvas->buffer)); - if (canvas->buffer == (unsigned char *) NULL) - { - draw_info=DestroyDrawInfo(draw_info); - canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); - } - canvas->num_grays=256; - canvas->pixel_mode=ft_pixel_mode_grays; - ResetMagickMemory(canvas->buffer,0x00,canvas->pitch*canvas->rows); - pango_ft2_render_layout(canvas,layout,0,0); + pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4* + image->rows*sizeof(*pixels)); + if (pixels == (unsigned char *) NULL) + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32, + image->columns,image->rows,4*image->columns); + cairo_info=cairo_create(surface); + cairo_set_operator(cairo_info,CAIRO_OPERATOR_CLEAR); + cairo_paint(cairo_info); + cairo_set_operator(cairo_info,CAIRO_OPERATOR_OVER); + if (draw_info->fill.matte == MagickFalse) + cairo_set_source_rgb(cairo_info,QuantumScale*draw_info->fill.red, + QuantumScale*draw_info->fill.green,QuantumScale*draw_info->fill.blue); + else + cairo_set_source_rgba(cairo_info,QuantumScale*draw_info->fill.red, + QuantumScale*draw_info->fill.green,QuantumScale*draw_info->fill.blue, + QuantumScale*draw_info->fill.alpha); + pango_cairo_show_layout(cairo_info,layout); + cairo_destroy(cairo_info); + cairo_surface_destroy(surface); + g_object_unref(fontmap); /* Convert caption to image. */ - image->columns+=2*page.x; - image->rows+=2*page.y; - if (SetImageBackgroundColor(image,exception) == MagickFalse) - { - draw_info=DestroyDrawInfo(draw_info); - canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); - canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); - caption=DestroyString(caption); - image=DestroyImageList(image); - return((Image *) NULL); - } + (void) SetImageBackgroundColor(image,exception); + p=pixels; GetPixelInfo(image,&fill_color); - p=canvas->buffer; - for (y=page.y; y < (ssize_t) (image->rows-page.y); y++) + for (y=0; y < (ssize_t) image->rows; y++) { - register ssize_t - x; + register ssize_t x; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; - q+=page.x*GetPixelChannels(image); - for (x=page.x; x < (ssize_t) (image->columns-page.x); x++) + for (x=0; x < (ssize_t) image->columns; x++) { - MagickRealType - fill_alpha; - - (void) GetFillColor(draw_info,x,y,&fill_color,exception); - fill_alpha=(MagickRealType) (*p)/(canvas->num_grays-1); - if (draw_info->text_antialias == MagickFalse) - fill_alpha=fill_alpha >= 0.5 ? 1.0 : 0.0; - fill_alpha=fill_alpha*fill_color.alpha; - CompositePixelOver(image,&fill_color,fill_alpha,q,GetPixelAlpha(image,q), - q); - p++; + fill_color.blue=ScaleCharToQuantum(*p++); + fill_color.green=ScaleCharToQuantum(*p++); + fill_color.red=ScaleCharToQuantum(*p++); + fill_color.alpha=ScaleCharToQuantum(*p++); + { + double + gamma; + + gamma=1.0-QuantumScale*fill_color.alpha; + gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); + fill_color.blue*=gamma; + fill_color.green*=gamma; + fill_color.red*=gamma; + } + CompositePixelOver(image,&fill_color,fill_color.alpha,q,(MagickRealType) + GetPixelAlpha(image,q),q); q+=GetPixelChannels(image); } - for ( ; x < (ssize_t) ((canvas->width+3) & ~3); x++) - p++; + if (SyncAuthenticPixels(image,exception) == MagickFalse) + break; + if (image->previous == (Image *) NULL) + { + status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, + image->rows); + if (status == MagickFalse) + break; + } } /* Relinquish resources. */ + pixels=(unsigned char *) RelinquishMagickMemory(pixels); draw_info=DestroyDrawInfo(draw_info); - canvas->buffer=(unsigned char *) RelinquishMagickMemory(canvas->buffer); - canvas=(FT_Bitmap *) RelinquishMagickMemory(canvas); caption=DestroyString(caption); return(GetFirstImageInList(image)); } @@ -444,11 +454,11 @@ ModuleExport size_t RegisterPANGOImage(void) *version='\0'; #if defined(PANGO_VERSION_STRING) - (void) FormatLocaleString(version,MaxTextExtent,"Pangoft2 %s", + (void) FormatLocaleString(version,MaxTextExtent,"Pangocairo %s", PANGO_VERSION_STRING); #endif entry=SetMagickInfo("PANGO"); -#if defined(MAGICKCORE_PANGOFT2_DELEGATE) +#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadPANGOImage; #endif entry->description=ConstantString("Pango Markup Language");