From 534d0a353b31242ce2f7b26c4eb4fe53f914d0f5 Mon Sep 17 00:00:00 2001 From: cristy Date: Sat, 13 Apr 2013 16:27:24 +0000 Subject: [PATCH] --- MagickCore/annotate.c | 208 +----------------------- MagickCore/xwindow-private.h | 4 +- MagickCore/xwindow.c | 298 +++++++++++++++++++++++++++++++++-- 3 files changed, 287 insertions(+), 223 deletions(-) diff --git a/MagickCore/annotate.c b/MagickCore/annotate.c index 97ebf05e4..04434cd26 100644 --- a/MagickCore/annotate.c +++ b/MagickCore/annotate.c @@ -1890,220 +1890,16 @@ static MagickBooleanType RenderPostscript(Image *image, % o exception: return any errors or warnings in this structure. % */ -#if defined(MAGICKCORE_X11_DELEGATE) static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info, const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) { MagickBooleanType status; - static DrawInfo - cache_info; - - static Display - *display = (Display *) NULL; - - static XAnnotateInfo - annotate_info; - - static XFontStruct - *font_info; - - static XPixelInfo - pixel; - - static XResourceInfo - resource_info; - - static XrmDatabase - resource_database; - - static XStandardColormap - *map_info; - - static XVisualInfo - *visual_info; - - size_t - height, - width; - if (annotate_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&annotate_semaphore); LockSemaphoreInfo(annotate_semaphore); - if (display == (Display *) NULL) - { - const char - *client_name; - - ImageInfo - *image_info; - - /* - Open X server connection. - */ - display=XOpenDisplay(draw_info->server_name); - if (display == (Display *) NULL) - { - UnlockSemaphoreInfo(annotate_semaphore); - ThrowXWindowException(XServerError,"UnableToOpenXServer", - draw_info->server_name); - return(MagickFalse); - } - /* - Get user defaults from X resource database. - */ - (void) XSetErrorHandler(XError); - image_info=AcquireImageInfo(); - client_name=GetClientName(); - resource_database=XGetResourceDatabase(display,client_name); - XGetResourceInfo(image_info,resource_database,client_name, - &resource_info); - resource_info.close_server=MagickFalse; - resource_info.colormap=PrivateColormap; - resource_info.font=AcquireString(draw_info->font); - resource_info.background_color=AcquireString("#ffffffffffff"); - resource_info.foreground_color=AcquireString("#000000000000"); - map_info=XAllocStandardColormap(); - if (map_info == (XStandardColormap *) NULL) - { - UnlockSemaphoreInfo(annotate_semaphore); - ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", - image->filename); - return(MagickFalse); - } - /* - Initialize visual info. - */ - visual_info=XBestVisualInfo(display,map_info,&resource_info); - if (visual_info == (XVisualInfo *) NULL) - { - UnlockSemaphoreInfo(annotate_semaphore); - ThrowXWindowException(XServerError,"UnableToGetVisual", - image->filename); - return(MagickFalse); - } - map_info->colormap=(Colormap) NULL; - pixel.pixels=(unsigned long *) NULL; - /* - Initialize Standard Colormap info. - */ - XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen), - map_info); - XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL, - &pixel); - pixel.annotate_context=XDefaultGC(display,visual_info->screen); - /* - Initialize font info. - */ - font_info=XBestFont(display,&resource_info,MagickFalse); - if (font_info == (XFontStruct *) NULL) - { - UnlockSemaphoreInfo(annotate_semaphore); - ThrowXWindowException(XServerError,"UnableToLoadFont", - draw_info->font); - return(MagickFalse); - } - if ((map_info == (XStandardColormap *) NULL) || - (visual_info == (XVisualInfo *) NULL) || - (font_info == (XFontStruct *) NULL)) - { - UnlockSemaphoreInfo(annotate_semaphore); - XFreeResources(display,visual_info,map_info,&pixel,font_info, - &resource_info,(XWindowInfo *) NULL); - ThrowXWindowException(XServerError,"UnableToLoadFont", - image->filename); - return(MagickFalse); - } - cache_info=(*draw_info); - } + status=XRenderImage(image,draw_info,offset,metrics,exception); UnlockSemaphoreInfo(annotate_semaphore); - /* - Initialize annotate info. - */ - XGetAnnotateInfo(&annotate_info); - annotate_info.stencil=ForegroundStencil; - if (cache_info.font != draw_info->font) - { - /* - Type name has changed. - */ - (void) XFreeFont(display,font_info); - (void) CloneString(&resource_info.font,draw_info->font); - font_info=XBestFont(display,&resource_info,MagickFalse); - if (font_info == (XFontStruct *) NULL) - { - ThrowXWindowException(XServerError,"UnableToLoadFont", - draw_info->font); - return(MagickFalse); - } - } - if (image->debug != MagickFalse) - (void) LogMagickEvent(AnnotateEvent,GetMagickModule(), - "Font %s; pointsize %g",draw_info->font != (char *) NULL ? - draw_info->font : "none",draw_info->pointsize); - cache_info=(*draw_info); - annotate_info.font_info=font_info; - annotate_info.text=(char *) draw_info->text; - annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text, - (int) strlen(draw_info->text)); - annotate_info.height=(unsigned int) font_info->ascent+font_info->descent; - metrics->pixels_per_em.x=(double) font_info->max_bounds.width; - metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent; - metrics->ascent=(double) font_info->ascent+4; - metrics->descent=(double) (-font_info->descent); - metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine); - metrics->height=font_info->ascent+font_info->descent; - metrics->max_advance=(double) font_info->max_bounds.width; - metrics->bounds.x1=0.0; - metrics->bounds.y1=metrics->descent; - metrics->bounds.x2=metrics->ascent+metrics->descent; - metrics->bounds.y2=metrics->ascent+metrics->descent; - metrics->underline_position=(-2.0); - metrics->underline_thickness=1.0; - if (draw_info->render == MagickFalse) - return(MagickTrue); - if (draw_info->fill.alpha == TransparentAlpha) - return(MagickTrue); - /* - Render fill color. - */ - width=annotate_info.width; - height=annotate_info.height; - if ((fabs(draw_info->affine.rx) >= MagickEpsilon) || - (fabs(draw_info->affine.ry) >= MagickEpsilon)) - { - if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) && - (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon)) - annotate_info.degrees=(double) (180.0/MagickPI)* - atan2(draw_info->affine.rx,draw_info->affine.sx); - } - (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent, - "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height, - ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+ - draw_info->interline_spacing-0.5)); - pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red); - pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green); - pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue); - status=XAnnotateImage(display,&pixel,&annotate_info,image,exception); - if (status == 0) - { - ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", - image->filename); - return(MagickFalse); - } - return(MagickTrue); -} -#else -static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info, - const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) -{ - (void) draw_info; - (void) offset; - (void) metrics; - (void) ThrowMagickException(exception,GetMagickModule(), - MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)", - image->filename); - return(MagickFalse); + return(status); } -#endif diff --git a/MagickCore/xwindow-private.h b/MagickCore/xwindow-private.h index e355e17fb..5cec4c237 100644 --- a/MagickCore/xwindow-private.h +++ b/MagickCore/xwindow-private.h @@ -522,7 +522,9 @@ extern MagickPrivate MagickBooleanType const MagickSizeType,void *), XMakeImage(Display *,const XResourceInfo *,XWindowInfo *,Image *,unsigned int, unsigned int,ExceptionInfo *), - XQueryColorCompliance(const char *,XColor *); + XQueryColorCompliance(const char *,XColor *), + XRenderImage(Image *,const DrawInfo *,const PointInfo *,TypeMetric *, + ExceptionInfo *); extern MagickPrivate void XBestIconSize(Display *,XWindowInfo *,Image *), diff --git a/MagickCore/xwindow.c b/MagickCore/xwindow.c index 7db9ac398..f8bcb2cd2 100644 --- a/MagickCore/xwindow.c +++ b/MagickCore/xwindow.c @@ -7794,19 +7794,17 @@ MagickPrivate void XMakeStandardColormap(Display *display, { SetPixelRed(affinity_image,0,q); if (map_info->red_max != 0) - SetPixelRed(affinity_image, - ScaleXToQuantum((size_t) (i/map_info->red_mult), - map_info->red_max),q); + SetPixelRed(affinity_image,ScaleXToQuantum((size_t) + (i/map_info->red_mult),map_info->red_max),q); SetPixelGreen(affinity_image,0,q); if (map_info->green_max != 0) - SetPixelGreen(affinity_image, - ScaleXToQuantum((size_t) ((i/map_info->green_mult) % - (map_info->green_max+1)),map_info->green_max),q); + SetPixelGreen(affinity_image,ScaleXToQuantum((size_t) + ((i/map_info->green_mult) % (map_info->green_max+1)), + map_info->green_max),q); SetPixelBlue(affinity_image,0,q); if (map_info->blue_max != 0) - SetPixelBlue(affinity_image, - ScaleXToQuantum((size_t) (i % map_info->green_mult), - map_info->blue_max),q); + SetPixelBlue(affinity_image,ScaleXToQuantum((size_t) + (i % map_info->green_mult),map_info->blue_max),q); SetPixelAlpha(affinity_image, TransparentAlpha,q); q+=GetPixelChannels(affinity_image); @@ -8059,12 +8057,12 @@ MagickPrivate void XMakeStandardColormap(Display *display, for (; i < (ssize_t) image->colors; i++) { index=diversity[i].index; - color.red= - ScaleQuantumToShort(XRedGamma(image->colormap[index].red)); - color.green= - ScaleQuantumToShort(XGreenGamma(image->colormap[index].green)); - color.blue= - ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue)); + color.red=ScaleQuantumToShort( + XRedGamma(image->colormap[index].red)); + color.green=ScaleQuantumToShort( + XGreenGamma(image->colormap[index].green)); + color.blue=ScaleQuantumToShort( + XBlueGamma(image->colormap[index].blue)); if (visual_info->klass != PseudoColor) { gray_value=(unsigned short) XPixelIntensity(&color); @@ -8733,7 +8731,8 @@ MagickPrivate MagickBooleanType XQueryColorCompliance(const char *target, % window. % */ -MagickPrivate void XQueryPosition(Display *display,const Window window,int *x,int *y) +MagickPrivate void XQueryPosition(Display *display,const Window window,int *x, + int *y) { int x_root, @@ -8954,6 +8953,228 @@ MagickExport MagickBooleanType XRemoteCommand(Display *display, % % % % % % +% X R e n d e r I m a g e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% XRenderImage() renders text on the image with an X11 font. It also returns +% the bounding box of the text relative to the image. +% +% The format of the XRenderImage method is: +% +% MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info, +% const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o image: the image. +% +% o draw_info: the draw info. +% +% o offset: (x,y) location of text relative to image. +% +% o metrics: bounding box of text. +% +% o exception: return any errors or warnings in this structure. +% +*/ +MagickPrivate MagickBooleanType XRenderImage(Image *image, + const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics, + ExceptionInfo *exception) +{ + const char + *client_name; + + DrawInfo + cache_info; + + Display + *display; + + ImageInfo + *image_info; + + MagickBooleanType + status; + + size_t + height, + width; + + XAnnotateInfo + annotate_info; + + XFontStruct + *font_info; + + XPixelInfo + pixel; + + XResourceInfo + resource_info; + + XrmDatabase + resource_database; + + XStandardColormap + *map_info; + + XVisualInfo + *visual_info; + + /* + Open X server connection. + */ + display=XOpenDisplay(draw_info->server_name); + if (display == (Display *) NULL) + { + ThrowXWindowException(XServerError,"UnableToOpenXServer", + draw_info->server_name); + return(MagickFalse); + } + /* + Get user defaults from X resource database. + */ + (void) XSetErrorHandler(XError); + image_info=AcquireImageInfo(); + client_name=GetClientName(); + resource_database=XGetResourceDatabase(display,client_name); + XGetResourceInfo(image_info,resource_database,client_name,&resource_info); + resource_info.close_server=MagickFalse; + resource_info.colormap=PrivateColormap; + resource_info.font=AcquireString(draw_info->font); + resource_info.background_color=AcquireString("#ffffffffffff"); + resource_info.foreground_color=AcquireString("#000000000000"); + map_info=XAllocStandardColormap(); + if (map_info == (XStandardColormap *) NULL) + { + ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", + image->filename); + return(MagickFalse); + } + /* + Initialize visual info. + */ + visual_info=XBestVisualInfo(display,map_info,&resource_info); + if (visual_info == (XVisualInfo *) NULL) + { + ThrowXWindowException(XServerError,"UnableToGetVisual", + image->filename); + return(MagickFalse); + } + map_info->colormap=(Colormap) NULL; + pixel.pixels=(unsigned long *) NULL; + /* + Initialize Standard Colormap info. + */ + XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen), + map_info); + XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL, + &pixel); + pixel.annotate_context=XDefaultGC(display,visual_info->screen); + /* + Initialize font info. + */ + font_info=XBestFont(display,&resource_info,MagickFalse); + if (font_info == (XFontStruct *) NULL) + { + ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font); + return(MagickFalse); + } + if ((map_info == (XStandardColormap *) NULL) || + (visual_info == (XVisualInfo *) NULL) || + (font_info == (XFontStruct *) NULL)) + { + XFreeResources(display,visual_info,map_info,&pixel,font_info, + &resource_info,(XWindowInfo *) NULL); + ThrowXWindowException(XServerError,"UnableToLoadFont",image->filename); + return(MagickFalse); + } + cache_info=(*draw_info); + /* + Initialize annotate info. + */ + XGetAnnotateInfo(&annotate_info); + annotate_info.stencil=ForegroundStencil; + if (cache_info.font != draw_info->font) + { + /* + Type name has changed. + */ + (void) XFreeFont(display,font_info); + (void) CloneString(&resource_info.font,draw_info->font); + font_info=XBestFont(display,&resource_info,MagickFalse); + if (font_info == (XFontStruct *) NULL) + { + ThrowXWindowException(XServerError,"UnableToLoadFont", + draw_info->font); + return(MagickFalse); + } + } + if (image->debug != MagickFalse) + (void) LogMagickEvent(AnnotateEvent,GetMagickModule(), + "Font %s; pointsize %g",draw_info->font != (char *) NULL ? + draw_info->font : "none",draw_info->pointsize); + cache_info=(*draw_info); + annotate_info.font_info=font_info; + annotate_info.text=(char *) draw_info->text; + annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int) + strlen(draw_info->text)); + annotate_info.height=(unsigned int) font_info->ascent+font_info->descent; + metrics->pixels_per_em.x=(double) font_info->max_bounds.width; + metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent; + metrics->ascent=(double) font_info->ascent+4; + metrics->descent=(double) (-font_info->descent); + metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine); + metrics->height=font_info->ascent+font_info->descent; + metrics->max_advance=(double) font_info->max_bounds.width; + metrics->bounds.x1=0.0; + metrics->bounds.y1=metrics->descent; + metrics->bounds.x2=metrics->ascent+metrics->descent; + metrics->bounds.y2=metrics->ascent+metrics->descent; + metrics->underline_position=(-2.0); + metrics->underline_thickness=1.0; + if (draw_info->render == MagickFalse) + return(MagickTrue); + if (draw_info->fill.alpha == TransparentAlpha) + return(MagickTrue); + /* + Render fill color. + */ + width=annotate_info.width; + height=annotate_info.height; + if ((fabs(draw_info->affine.rx) >= MagickEpsilon) || + (fabs(draw_info->affine.ry) >= MagickEpsilon)) + { + if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) && + (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon)) + annotate_info.degrees=(double) (180.0/MagickPI)* + atan2(draw_info->affine.rx,draw_info->affine.sx); + } + (void) FormatLocaleString(annotate_info.geometry,MaxTextExtent, + "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height, + ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+ + draw_info->interline_spacing-0.5)); + pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red); + pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green); + pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue); + status=XAnnotateImage(display,&pixel,&annotate_info,image,exception); + if (status == 0) + { + ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed", + image->filename); + return(MagickFalse); + } + return(MagickTrue); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % X R e t a i n W i n d o w C o l o r s % % % % % @@ -9730,6 +9951,51 @@ MagickExport Image *XImportImage(const ImageInfo *image_info, assert(exception->signature == MagickSignature); return((Image *) NULL); } + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% X R e n d e r X 1 1 % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% XRenderImage() renders text on the image with an X11 font. It also returns +% the bounding box of the text relative to the image. +% +% The format of the XRenderImage method is: +% +% MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info, +% const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o image: the image. +% +% o draw_info: the draw info. +% +% o offset: (x,y) location of text relative to image. +% +% o metrics: bounding box of text. +% +% o exception: return any errors or warnings in this structure. +% +*/ +MagickPrivate MagickBooleanType XRenderImage(Image *image, + const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics, + ExceptionInfo *exception) +{ + (void) draw_info; + (void) offset; + (void) metrics; + (void) ThrowMagickException(exception,GetMagickModule(), + MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)", + image->filename); + return(MagickFalse); +} #endif /* -- 2.50.1