static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception) { char filename[MaxTextExtent]; int unique_file; FILE *file; Image *image; ImageInfo *read_info; MagickBooleanType status; unsigned long flags; wmfAPI *wmf_info; wmfAPI_Options options; wmfD_Rect bounding_box; wmf_eps_t *eps_info; wmf_error_t wmf_status; /* Read WMF image. */ image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } wmf_info=(wmfAPI *) NULL; flags=0; flags|=WMF_OPT_IGNORE_NONFATAL; flags|=WMF_OPT_FUNCTION; options.function=wmf_eps_function; wmf_status=wmf_api_create(&wmf_info,flags,&options); if (wmf_status != wmf_E_None) { if (wmf_info != (wmfAPI *) NULL) wmf_api_destroy(wmf_info); ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary"); } wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob, (void *) image); if (wmf_status != wmf_E_None) { wmf_api_destroy(wmf_info); ThrowFileException(exception,FileOpenError,"UnableToOpenFile", image->filename); image=DestroyImageList(image); return((Image *) NULL); } wmf_status=wmf_scan(wmf_info,0,&bounding_box); if (wmf_status != wmf_E_None) { wmf_api_destroy(wmf_info); ThrowReaderException(DelegateError,"FailedToScanFile"); } eps_info=WMF_EPS_GetData(wmf_info); file=(FILE *) NULL; unique_file=AcquireUniqueFileResource(filename); if (unique_file != -1) file=fdopen(unique_file,"wb"); if ((unique_file == -1) || (file == (FILE *) NULL)) { wmf_api_destroy(wmf_info); ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile"); } eps_info->out=wmf_stream_create(wmf_info,file); eps_info->bbox=bounding_box; wmf_status=wmf_play(wmf_info,0,&bounding_box); if (wmf_status != wmf_E_None) { wmf_api_destroy(wmf_info); ThrowReaderException(DelegateError,"FailedToRenderFile"); } (void) fclose(file); wmf_api_destroy(wmf_info); (void) CloseBlob(image); image=DestroyImage(image); /* Read EPS image. */ read_info=CloneImageInfo(image_info); (void) FormatMagickString(read_info->filename,MaxTextExtent,"eps:%.1024s", filename); image=ReadImage(read_info,exception); read_info=DestroyImageInfo(read_info); if (image != (Image *) NULL) { (void) CopyMagickString(image->filename,image_info->filename, MaxTextExtent); (void) CopyMagickString(image->magick_filename,image_info->filename, MaxTextExtent); (void) CopyMagickString(image->magick,"WMF",MaxTextExtent); } (void) RelinquishUniqueFileResource(filename); return(GetFirstImageInList(image)); }
/* Write out postscript path, *minus* the ultimate `fill', then call eps_path_fill * Note: I KNOW there is a better way to do patterns, but my ghostscript hangs when I try! * * Assumes that lbStyle != BS_NULL */ static void eps_path_fill (wmfAPI* API,wmfDC* dc,wmfD_Rect* bbox) { wmf_eps_t* ddata = WMF_EPS_GetData (API); wmfStream* out = ddata->out; wmfBrush* brush; wmfRGB* rgb; wmfBMP* bmp; float red; float green; float blue; float side; WMF_DEBUG (API,"~~~~~~~~eps_path_fill"); if (out == 0) return; brush = WMF_DC_BRUSH (dc); switch (WMF_BRUSH_STYLE (brush)) { case BS_NULL: WMF_ERROR (API,"Attempt to set null fill-style!"); API->err = wmf_E_Glitch; break; case BS_HATCHED: wmf_stream_printf (API,out,"clip "); if (WMF_DC_OPAQUE (dc)) { rgb = WMF_DC_BACKGROUND (dc); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor ",red,green,blue); wmf_stream_printf (API,out,"fill "); } wmf_stream_printf (API,out,"\n"); wmf_stream_printf (API,out,"1 setlinewidth "); wmf_stream_printf (API,out,"[] 0 setdash "); rgb = WMF_BRUSH_COLOR (brush); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor\n",red,green,blue); switch (WMF_BRUSH_HATCH (brush)) { case HS_HORIZONTAL: wmf_stream_printf (API,out,"%f 5 %f { newpath dup %f exch moveto %f exch lineto stroke } for\n", bbox->TL.y,bbox->BR.y,bbox->TL.x,bbox->BR.x); break; case HS_VERTICAL: wmf_stream_printf (API,out,"%f 5 %f { newpath dup %f moveto %f lineto stroke } for\n", bbox->TL.x,bbox->BR.x,bbox->TL.y,bbox->BR.y); break; case HS_FDIAGONAL: wmf_stream_printf (API,out,"gsave %% HS_FDIAGONAL\n"); wmf_stream_printf (API,out,"%f %f translate -45 rotate ", bbox->TL.x-(bbox->BR.y-bbox->TL.y)/2,(bbox->TL.y+bbox->BR.y)/2); side = ((bbox->BR.x-bbox->TL.x) + (bbox->BR.y-bbox->TL.y)) / 1.41421356237309504880; wmf_stream_printf (API,out,"0 5 %f { newpath dup 0 moveto %f lineto stroke } for ", side,side); wmf_stream_printf (API,out,"grestore\n"); break; case HS_BDIAGONAL: wmf_stream_printf (API,out,"gsave %% HS_BDIAGONAL\n"); wmf_stream_printf (API,out,"%f %f translate -45 rotate ", bbox->TL.x-(bbox->BR.y-bbox->TL.y)/2,(bbox->TL.y+bbox->BR.y)/2); side = ((bbox->BR.x-bbox->TL.x) + (bbox->BR.y-bbox->TL.y)) / 1.41421356237309504880; wmf_stream_printf (API,out,"0 5 %f { newpath dup 0 exch moveto %f exch lineto stroke } for ", side,side); wmf_stream_printf (API,out,"grestore\n"); break; case HS_CROSS: wmf_stream_printf (API,out,"%f 5 %f { newpath dup %f exch moveto %f exch lineto stroke } for\n", bbox->TL.y,bbox->BR.y,bbox->TL.x,bbox->BR.x); wmf_stream_printf (API,out,"%f 5 %f { newpath dup %f moveto %f lineto stroke } for\n", bbox->TL.x,bbox->BR.x,bbox->TL.y,bbox->BR.y); break; case HS_DIAGCROSS: wmf_stream_printf (API,out,"gsave %% HS_DIAGCROSS\n"); wmf_stream_printf (API,out,"%f %f translate -45 rotate ", bbox->TL.x-(bbox->BR.y-bbox->TL.y)/2,(bbox->TL.y+bbox->BR.y)/2); side = ((bbox->BR.x-bbox->TL.x) + (bbox->BR.y-bbox->TL.y)) / 1.41421356237309504880; wmf_stream_printf (API,out,"0 5 %f { newpath dup 0 moveto %f lineto stroke } for ", side,side); wmf_stream_printf (API,out,"0 5 %f { newpath dup 0 exch moveto %f exch lineto stroke } for ", side,side); wmf_stream_printf (API,out,"grestore\n"); break; default: if (API->flags & WMF_OPT_IGNORE_NONFATAL) { WMF_DEBUG (API,"Unsupported brush/hatch style!"); } else { WMF_ERROR (API,"Unsupported brush/hatch style!"); API->err = wmf_E_Glitch; } break; } break; case BS_DIBPATTERN: bmp = WMF_BRUSH_BITMAP (brush); if (bmp->data == 0) { if (API->flags & WMF_OPT_IGNORE_NONFATAL) { WMF_DEBUG (API,"Attempt to fill with non-existent pattern!"); } else { WMF_ERROR (API,"Attempt to fill with non-existent pattern!"); API->err = wmf_E_Glitch; break; } } /* no break here - TODO: implement bitmap fill */ default: if (API->flags & WMF_OPT_IGNORE_NONFATAL) { WMF_DEBUG (API,"Unsupported brush style!"); /* no break here */ } else { WMF_ERROR (API,"Unsupported brush style!"); API->err = wmf_E_Glitch; break; } case BS_SOLID: rgb = WMF_BRUSH_COLOR (brush); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor fill\n",red,green,blue); break; } }
/* Write out postscript path, *minus* the ultimate `stroke', then call eps_path_stroke * * Assumes that lopnStyle != PS_NULL */ static void eps_path_stroke (wmfAPI* API,wmfDC* dc,float linewidth) { wmf_eps_t* ddata = WMF_EPS_GetData (API); wmfStream* out = ddata->out; wmfPen* pen = 0; wmfRGB* rgb = 0; float red; float green; float blue; WMF_DEBUG (API,"~~~~~~~~eps_path_stroke"); if (out == 0) return; wmf_stream_printf (API,out,"\n"); wmf_stream_printf (API,out,"%f setlinewidth ",linewidth); pen = WMF_DC_PEN (dc); rgb = WMF_PEN_COLOR (pen); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor ",red,green,blue); switch (WMF_PEN_ENDCAP (pen)) { case PS_ENDCAP_SQUARE: wmf_stream_printf (API,out,"2 setlinecap "); break; case PS_ENDCAP_ROUND: wmf_stream_printf (API,out,"1 setlinecap "); break; case PS_ENDCAP_FLAT: default: wmf_stream_printf (API,out,"0 setlinecap "); break; } switch (WMF_PEN_JOIN (pen)) { case PS_JOIN_BEVEL: wmf_stream_printf (API,out,"2 setlinejoin "); break; case PS_JOIN_ROUND: wmf_stream_printf (API,out,"1 setlinejoin "); break; case PS_JOIN_MITER: default: wmf_stream_printf (API,out,"0 setlinejoin "); break; } switch (WMF_PEN_STYLE (pen)) { case PS_DASH: /* DASH_LINE */ wmf_stream_printf (API,out,"[ %f %f ] 0 setdash ", linewidth*10,linewidth*10); break; case PS_ALTERNATE: case PS_DOT: /* DOTTED_LINE */ wmf_stream_printf (API,out,"[ %f %f ] 0 setdash ", linewidth,linewidth*2); break; case PS_DASHDOT: /* DASH_DOT_LINE */ wmf_stream_printf (API,out,"[ %f %f %f %f ] 0 setdash ", linewidth*10,linewidth*2,linewidth,linewidth*2); break; case PS_DASHDOTDOT: /* DASH_2_DOTS_LINE */ wmf_stream_printf (API,out,"[ %f %f %f %f %f %f ] 0 setdash ", linewidth*10,linewidth*2,linewidth,linewidth*2,linewidth,linewidth*2); break; case PS_INSIDEFRAME: /* There is nothing to do in this case... */ case PS_SOLID: default: wmf_stream_printf (API,out,"[] 0 setdash "); break; } wmf_stream_printf (API,out,"stroke\n"); }
static void wmf_eps_draw_text (wmfAPI* API,wmfDrawText_t* draw_text) { wmf_eps_t* ddata = WMF_EPS_GetData (API); wmfStream* out = ddata->out; wmfFont* font = 0; wmfRGB* rgb = 0; float red; float green; float blue; float size; float ratio; float theta; unsigned int i; unsigned int length; WMF_DEBUG (API,"~~~~~~~~wmf_[eps_]draw_text"); if (out == 0) return; size = (float) draw_text->font_height; ratio = (float) draw_text->font_ratio; font = WMF_DC_FONT (draw_text->dc); theta = (float) (WMF_TEXT_ANGLE (font) * 180 / PI); wmf_stream_printf (API,out,"gsave %% wmf_[eps_]draw_text\n"); wmf_stream_printf (API,out,"/%s findfont %f scalefont setfont\n",WMF_FONT_PSNAME (font),size); wmf_stream_printf (API,out,"%f %f translate 1 -1 scale %f rotate ",draw_text->pt.x,draw_text->pt.y,theta); wmf_stream_printf (API,out,"%f 1 scale\n",ratio); wmf_stream_printf (API,out,"("); length = strlen (draw_text->str); for (i = 0; i < length; i++) { if (draw_text->str[i] == ')') wmf_stream_printf (API,out,"\\)"); else if (draw_text->str[i] == '(') wmf_stream_printf (API,out,"\\("); else wmf_stream_printf (API,out,"%c",draw_text->str[i]); } wmf_stream_printf (API,out,")\n"); if (WMF_DC_OPAQUE (draw_text->dc)) { wmf_stream_printf (API,out,"dup stringwidth pop dup "); wmf_stream_printf (API,out,"newpath 0 %f moveto 0 rlineto 0 %f rlineto neg 0 rlineto closepath ", - 0.29 * size,1.07 * size); rgb = WMF_DC_BACKGROUND (draw_text->dc); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor fill ",red,green,blue); } rgb = WMF_DC_TEXTCOLOR (draw_text->dc); red = (float) ((int) rgb->r) / 255; green = (float) ((int) rgb->g) / 255; blue = (float) ((int) rgb->b) / 255; wmf_stream_printf (API,out,"%f %f %f setrgbcolor ",red,green,blue); wmf_stream_printf (API,out,"0 0 moveto show\n"); wmf_stream_printf (API,out,"grestore\n"); }