Beispiel #1
0
// This conversion is appropriate for eps images
// (originally implemented in pdf_image_rep::flush)
void  
gs_to_pdf (url image, url pdf, int w, int h) {
  string cmd;
  if (DEBUG_CONVERT) debug_convert << "(eps) gs_to_pdf"<<LF;
  string s= suffix (image);    
  // take care of properly handling the bounding box
  // the resulting pdf image will always start at 0,0.

  int bx1, by1, bx2, by2; // bounding box
  ps_bounding_box(image, bx1, by1, bx2, by2);
  double scale_x = w/((double)(bx2-bx1));
  double scale_y = h/((double)(by2-by1));

  cmd= gs_prefix();
  cmd << " -dQUIET -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite ";
  cmd << "-dAutoRotatePages=/None ";
  cmd << "-dCompatibilityLevel=" << pdf_version () << " ";
  cmd << " -sOutputFile=" << sys_concretize(pdf) << " ";
  cmd << " -c \" << /PageSize [ " << as_string(bx2-bx1) << " " << as_string(by2-by1)
    << " ] >> setpagedevice gsave  "
    << as_string(-bx1) << " " << as_string(-by1) << " translate "
    << as_string(scale_x) << " " << as_string(scale_y) << " scale \"";
  cmd << " -f " << sys_concretize (image);
  cmd << " -c \" grestore \"  ";
  // debug_convert << cmd << LF;
  system(cmd);
  if (DEBUG_CONVERT)
    debug_convert << cmd << LF << "pdf generated? " << exists(pdf) << LF;
}
static bool
use_converts (url image) {
#if defined(__MINGW__) || defined(__MINGW32__)
  (void) image; return false;
#else
  // NOTE: determine whether we should use image magick.
  // Indeed, EPSCrop unfortunately does not correctly handle
  // non trivial offsets of bounding boxes
  static bool has_image_magick= exists_in_path ("convert");
  int bx1, by1, bx2, by2;
  ps_bounding_box (image, bx1, by1, bx2, by2);
  return has_image_magick && (bx1 != 0 || by1 != 0);
#endif
}
Beispiel #3
0
bool
gs_to_png (url image, url png, int w, int h) { //Achtung! w,h in pixels
  string cmd;
  if (DEBUG_CONVERT) debug_convert << "gs_to_png using gs"<<LF;
  cmd= gs_prefix ();
  cmd << "-dQUIET -dNOPAUSE -dBATCH -dSAFER ";
  cmd << "-sDEVICE=png16m -dGraphicsAlphaBits=4 -dTextAlphaBits=4 ";
  cmd << "-g" << as_string (w) << "x" << as_string (h) << " ";
  cmd << "-sOutputFile=" << sys_concretize (png) << " ";
  int bbw, bbh;
  int rw, rh;
  int bx1, by1, bx2, by2;
  if (suffix(image) == "pdf") 
    image_size (image, bbw, bbh);
    //don't call gs_PDFimage_size 
    //in order to benefit from caching
  else {
    ps_bounding_box (image, bx1, by1, bx2, by2); //same comment
    bbw=bx2-bx1;
    bbh=by2-by1;
  }
  rw=(w*72)/bbw;
  rh=(h*72)/bbh;
  cmd << "-r" << as_string (rw) << "x" << as_string (rh) << " ";  
  
  if (DEBUG_CONVERT) debug_convert << "w="<<w<<" h="<<h<<LF
      << "bbw="<<bbw<<" bbh="<<bbh<<LF
      <<" res ="<<rw<<" * "<<rh <<LF;
  
  if (suffix(image) == "pdf") {
    cmd << "-dUseCropBox "; // old gs versions (<9.0 ?) fail if CropBox not explicitly defined
    cmd << sys_concretize (image);
  }
  else {
    //don't use -dEPSCrop which works incorrectly if (bx1 != 0 || by1 != 0)
    cmd << "-c \" "<< as_string (-bx1) << " "<< as_string (-by1) <<" translate gsave \"  -f "
            << sys_concretize (image) << " -c \" grestore \"";    
  }
  string ans= eval_system (cmd);
  if (DEBUG_CONVERT) debug_convert << cmd <<LF
    <<"answer :"<<ans <<LF;
  if (! exists(png)) {
    convert_error << "gs_to_png failed for "<< image <<LF;
    return false;
  }
  return true;
}
Beispiel #4
0
void
gs_to_eps (url image, url eps) { //this should be used mostly for pdf->eps conversion.
  string cmd;
  int bx1, by1, bx2, by2; // bounding box
  if (DEBUG_CONVERT) debug_convert << "gs_to_eps"<<LF;
  cmd= gs_prefix ();
  cmd << "-dQUIET -dNOPAUSE -dBATCH -dSAFER ";
  cmd << "-sDEVICE="<<eps_device ();
  cmd << " -sOutputFile=" << sys_concretize (eps) << " ";
  if (suffix(image) == "pdf") {
    image_size (image, bx2, by2);
    bx1=by1=0;
    cmd << "-dUseCropBox "
      << " -dDEVICEWIDTHPOINTS=" << as_string (bx2)
      << " -dDEVICEHEIGHTPOINTS=" << as_string (by2)<<" "
      << sys_concretize (image);
  }  
  else {
    ps_bounding_box (image, bx1, by1, bx2, by2);
    cmd << " -dDEVICEWIDTHPOINTS=" << as_string (bx2-bx1)
      << " -dDEVICEHEIGHTPOINTS=" << as_string (by2-by1)<<" ";
    //don't use -dEPSCrop which works incorrectly if (bx1 != 0 || by1 != 0)
    cmd << "-c \" "<< as_string (-bx1) << " " << as_string (-by1) 
      << " translate gsave \" "
      << sys_concretize (image)
      << " -c \" grestore \"";     
  }
  string ans= eval_system (cmd);
  if (DEBUG_CONVERT) debug_convert << cmd <<LF
    <<"answer :"<<ans <<LF
    <<"eps generated? "<< exists(eps)<<LF;
  // eps(2)write and bbox devices do a "smart" job of finding the boundingbox on their own,
  // possibly changing the original margins/aspect ratio defined by the pdf CropBox|MediaBox
  // here were restore the original size.
  gs_fix_bbox (eps, 0, 0, bx2-bx1, by2-by1);
}