Branch: Tag:

2002-11-15

2002-11-15 05:04:27 by Martin Nilsson <mani@lysator.liu.se>

Added autodoc and fixed some minor details.

Rev: lib/modules/_Image_PS.pmod:1.6

1:   #pike __REAL_VERSION__    - string find_in_path( string file ) + //! Codec for the Adobe page description language PostScript. + //! Uses Ghostscript for decoding. +  + static string find_in_path( string file )   {    string path=getenv("PATH");    foreach(path ? path/":" : ({}) , path)
8:    return path;   }    + //! Decodes the postscript @[data] into an image object + //! using Ghostscript. + //! @param options + //! Optional decoding parameters. + //! @mapping + //! @member int "dpi" + //! The resolution the image should be rendered in. + //! Defaults to 100. + //! @member string "device" + //! The selected Ghostscript device. Defaults to "ppmraw". + //! @member string "binary" + //! Path to the Ghostscript binary to be used. If missing + //! the environment paths will be searched for a file "gs" + //! to be used instead. + //! @endmapping   object decode( string data, mapping|void options )   { -  +  if(data[0..3] != "%!PS") +  error("This is not a postscript file!\n"); +     if(!options) options = ([]); -  object fd, fd2; -  object fd3, fd4; -  string bbox; +     int llx, lly;    int urx, ury; -  fd = Stdio.File(); -  fd2 = fd->pipe(); +     -  fd3 = Stdio.File(); -  fd4 = fd3->pipe(); +  Stdio.File fd = Stdio.File(); +  object fd2 = fd->pipe();    -  if(data[0..3] != "%!PS") -  error("This is not a postscript file!\n"); +  Stdio.File fd3 = Stdio.File(); +  object fd4 = fd3->pipe();    -  if(sscanf(data, "%*s\n%%%%BoundingBox: %s\n", bbox) == 2) +  if(sscanf(data, "%*s\n%%%%BoundingBox: %s\n", string bbox) == 2)    {    int x0,x1,y0,y1;    sscanf(bbox, "%d %d %d %d", x0,y0,x1,y1 );
36:    }       array command = ({ -  find_in_path("gs")||("/bin/sh -c gs "), +  options->binary||find_in_path("gs")||("/bin/sh -c gs "),    "-quiet",    "-sDEVICE="+(options->device||"ppmraw"),    "-r"+(options->dpi||100),
46:    "-c quit 2>/dev/null"    });    - // werror("running "+(command*" ")+"\n"); +     Process.create_process( command, ([    "stdin":fd,    "stdout":fd3,
55:    destruct(fd);    destruct(fd3);    fd2->write( data ); -  if(search(data, "showpage") == -1) +  if(!has_value(data, "showpage"))    fd2->write( "\nshowpage\n" );    destruct(fd2);    object i= Image.PNM.decode( fd4->read() );
65:    return i;   }    + //! Calls decode and returns the image in the "image" + //! index of the mapping. This method is present for + //! API reasons.   mapping _decode( string data, mapping|void options )   {    return ([ "image":decode( data,options ) ]);
72:          -  + //! Encodes the image object @[img] as a postscript 3.0 file. + //! @param options + //! Optional extra encoding parameters. + //! @mapping + //! @member int "dpi" + //! The resolution of the encoded image. Defaults to 100. + //! @member int(0..1) "eps" + //! If the resulting image should be an eps instead of ps. + //! Defaults to 0, no. + //! @endmapping   string encode( object img, mapping|void options )   {    int w = img->xsize(), h = img->ysize();
102:    return res;   }    + //! Same as encode. Present for API reasons.   function _encode = encode;