Example #1
0
void
edit_main_rep::print_buffer (string first, string last) {
  url target;
#ifdef OS_MINGW
  target= use_pdf ()? url_temp (".pdf"): url_temp (".ps");
#else
  target= url_temp (".ps");
#endif
  print_doc (target, false, as_int (first), as_int (last));
  system (get_printing_cmd (), target);  // Send the document to the printer
  set_message ("Done printing", "print buffer");
  ::remove (target);
}
Example #2
0
void
edit_main_rep::print_buffer (string first, string last) {
   url target;
#if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__))
   {
     target= url_temp (".pdf"); 
     WINPrint wprt(to_qstring(as_string(target)),env->page_landscape);
     if(wprt.doit) print (target, false,wprt.first_page,wprt.last_page);
   }
#else
  target= url_temp (".ps"); 
  print (target, false, as_int (first), as_int (last));
  system (printing_cmd, target);  // Send the document to the printer
 #endif
  ::remove (target);
}
Example #3
0
url
get_from_web (url name) {
    if (!is_rooted_web (name)) return url_none ();
    url res= get_cache (name);
    if (!is_none (res)) return res;

#ifdef OS_WIN32
    string urlString = as_string (name);
    url tmp = url_temp();

    if (starts (urlString, "www."))
        urlString = "http://" * urlString;
    else if (starts (urlString, "ftp."))
        urlString = "ftp://" * urlString;
    else if (starts (urlString, "ftp://"))
        urlPath = NULL;
    else if (starts (urlString, "http://"))
        urlPath = NULL;
    else
        urlString = "http://" * urlString;
    urlString= web_encode (urlString);

    c_string urlPath (urlString);
    c_string tempFilePath (as_string (tmp));

    if(!URL_Get(urlPath, tempFilePath))
        return url_none();
    else return set_cache (name, tmp);
#else
    string test= var_eval_system ("which wget");
    if (!ends (test, "wget")) return url_none ();
    url tmp= url_temp ();
    string tmp_s= escape_sh (concretize (tmp));
    string cmd= "wget --header='User-Agent: TeXmacs-" TEXMACS_VERSION "' -q";
    cmd << " -O " << tmp_s << " " << escape_sh (web_encode (as_string (name)));
    // cout << cmd << "\n";
    system (cmd);
    // cout << "got " << name << " as " << tmp << "\n";

    if (var_eval_system ("cat " * tmp_s * " 2> /dev/null") == "") {
        remove (tmp);
        return url_none ();
    }
    else return set_cache (name, tmp);
#endif
}
Example #4
0
url
get_from_ramdisc (url u) {
    if (!is_ramdisc (u)) return url_none ();
    url res= get_cache (u);
    if (!is_none (res)) return (res);
    url tmp= url_temp (string (".") * suffix (u));
    save_string (tmp, u[1][2]->t->label);
    return set_cache (u, tmp);
}
Example #5
0
int
unix_system (string cmd, string& result) {
  url temp= url_temp ();
  string temp_s= escape_sh (concretize (temp));
  c_string _cmd (cmd * " > " * temp_s * " 2>&1");
  int ret= system (_cmd);
  bool flag= load_string (temp, result, false);
  remove (temp);
  if (flag) result= "";
  return ret;
}
Example #6
0
void
edit_main_rep::print_buffer (string first, string last) {
  // in Qt this is the main entry point to the printing subsystem.
  // the other routines (print_to_file, ...) are overriden since all fine tuning 
  // is made here via the Qt print dialog
  bool to_file, landscape;
  url name = url_none();
  string printer;
  string paper_type;
  if (qt_print (to_file, landscape, printer, name, first, last, paper_type)) {
      if (!to_file) name = url_temp (".ps");
      print (name, false, as_int (first), as_int (last));
      if (!to_file) {
        string cmd = printing_cmd * " -P" * printer;
        system (cmd, name);  
        ::remove (name);
      }
  }
}
Example #7
0
array<int>
edit_main_rep::print_snippet (url name, tree t, bool conserve_preamble) {
  tree buft= subtree (et, rp);
  if (conserve_preamble)
    if (is_document (buft) && is_compound (buft[0], "hide-preamble"))
      t= tree (SURROUND, buft[0], "", t);

  string s= suffix (name);
  bool ps= (s == "ps" || s == "eps");
  if (use_pdf ()) ps= (ps || s == "pdf");
  typeset_prepare ();
  int dpi= as_int (printing_dpi);
  //if (!ps) t= tree (WITH, MAGNIFICATION, "2", PAGE_WIDTH, "40cm", t);
  //if (!ps) t= tree (WITH, MAGNIFICATION, "1.6", PAGE_WIDTH, "40cm", t);
  double mag= ( 1.0 * dpi) / 600;
  double wid= (25.0 * dpi) / 600;
  if (!ps) {
    mag *= 1.6;
    wid *= 1.6;
  }
  t= tree (WITH, MAGNIFICATION, as_string (mag),
           PAGE_WIDTH, as_string (wid) * "cm", t);
  box b= typeset_as_box (env, t, path ());
  if (b->x4 - b->x3 >= 5*PIXEL && b->y4 - b->y3 >= 5*PIXEL) {
    if (ps) make_eps (name, b, dpi);
    else {
      url temp= url_temp (use_pdf ()? ".pdf": ".eps");
      make_eps (temp, b, dpi);
      ::remove (name);
      if (!call_scm_converter (temp, name)) {
        call_imagemagick_convert (temp, name);
        if (!exists (name))
          convert_error << "could not convert snippet " << temp
                        << " into :" << name << "\n";
      }
      ::remove (temp);
    }
  }
  array<int> a;
  a << b->x3 << b->y3 << b->x4 << b->y4;
  return a;
}
Example #8
0
url
get_from_server (url u) {
    if (!is_rooted_tmfs (u)) return url_none ();
    url res= get_cache (u);
    if (!is_none (res)) return res;

    string name= as_string (u);
    if (ends (name, "~") || ends (name, "#")) {
        if (!is_rooted_tmfs (name)) return url_none ();
        if (!as_bool (call ("tmfs-can-autosave?", unglue (u, 1))))
            return url_none ();
    }
    string r= as_string (call ("tmfs-load", object (name)));
    if (r == "") return url_none ();
    url tmp= url_temp ();
    (void) save_string (tmp, r, true);

    //return set_cache (u, tmp);
    return tmp;
    // FIXME: certain files could be cached, but others not
    // for instance, files which are loaded in a delayed fashion
    // would always be cached as empty files, which is erroneous.
}
Example #9
0
array<int>
edit_main_rep::print_snippet (url name, tree t) {
  bool ps= suffix (name) == "ps" || suffix (name) == "eps";
  typeset_prepare ();
  int dpi= as_int (printing_dpi);
  //if (!ps) t= tree (WITH, MAGNIFICATION, "2", PAGE_WIDTH, "40cm", t);
  if (!ps) t= tree (WITH, MAGNIFICATION, "1.6", PAGE_WIDTH, "40cm", t);
  box b= typeset_as_box (env, t, path ());
  if (b->x4 - b->x3 >= 5*PIXEL && b->y4 - b->y3 >= 5*PIXEL) {
    if (ps) make_eps (name, b, dpi);
    else {
      url temp= url_temp (".eps");
      make_eps (temp, b, dpi);
      ::remove (name);
      system ("convert", temp, name);
      if (!exists (name))
        cout << "TeXmacs] warning, failed to create image " << name << "\n";
      ::remove (temp);
    }
  }
  array<int> a;
  a << b->x3 << b->y3 << b->x4 << b->y4;
  return a;
}
Example #10
0
void
edit_main_rep::print (url name, bool conform, int first, int last) {
  bool ps  = (suffix (name) == "ps");
  bool pdf = (suffix (name) == "pdf");
  url  orig= resolve (name, "");

#ifdef USE_GS
  if (!use_pdf () && pdf)
    name= url_temp (".ps");
  if (!use_ps () && ps)
    name= url_temp (".pdf");
#endif
  
  string medium = env->get_string (PAGE_MEDIUM);
  if (conform && (medium != "paper")) conform= false;
  // FIXME: better command for conform printing

  // Set environment variables for printing

  typeset_prepare ();
  env->write (DPI, printing_dpi);
  env->write (PAGE_SHOW_HF, "true");
  env->write (PAGE_SCREEN_MARGIN, "false");
  if (!conform) {
    env->write (PAGE_MEDIUM, "paper");
    env->write (PAGE_PRINTED, "true");
  }

  // Typeset pages for printing

  box the_box= typeset_as_document (env, subtree (et, rp), reverse (rp));

  // Determine parameters for printer

  string page_type = env->get_string (PAGE_TYPE);
  double w         = env->page_width;
  double h         = env->page_height;
  double cm        = env->as_length (string ("1cm"));
  bool   landsc    = env->page_landscape;
  int    dpi       = as_int (printing_dpi);
  int    start     = max (0, first-1);
  int    end       = min (N(the_box[0]), last);
  int    pages     = end-start;
  if (conform) {
    page_type= "user";
    SI bw= the_box[0][0]->w();
    SI bh= the_box[0][0]->h();
    string bws= as_string (bw) * "tmpt";
    string bhs= as_string (bh) * "tmpt";
    w= env->as_length (bws);
    h= env->as_length (bhs);
  }

  // Print pages
  renderer ren;
#ifdef PDF_RENDERER
  if (use_pdf () && (pdf || !use_ps ()))
    ren= pdf_hummus_renderer (name, dpi, pages, page_type, landsc, w/cm, h/cm);
  else
    ren= printer (name, dpi, pages, page_type, landsc, w/cm, h/cm);
#else
  ren= printer (name, dpi, pages, page_type, landsc, w/cm, h/cm);
#endif
  
  if (ren->is_started ()) {
    int i;
    ren->set_metadata ("title", get_metadata ("title"));
    ren->set_metadata ("author", get_metadata ("author"));
    ren->set_metadata ("subject", get_metadata ("subject"));
    for (i=start; i<end; i++) {
      tree bg= env->read (BG_COLOR);
      ren->set_background (bg);
      if (bg != "white")
        ren->clear_pattern (0, (SI) -h, (SI) w, 0);

      rectangles rs;
      the_box[0]->sx(i)= 0;
      the_box[0]->sy(i)= 0;
      the_box[0][i]->redraw (ren, path (0), rs);
      if (i<end-1) ren->next_page ();
    }
  }
  tm_delete (ren);

#ifdef USE_GS
  if (!use_pdf () && pdf) {
    gs_to_pdf (name, orig, landsc, h/cm, w/cm);
    ::remove (name);
  }
  if (!use_ps () && ps) {
    gs_to_ps (name, orig, landsc, h/cm, w/cm);
    ::remove (name);
  }
  if (ps || pdf)
    if (get_preference ("texmacs->pdf:check", "off") == "on") {
      system_wait ("Checking exported file for correctness", "please wait");
      gs_check (orig);
    }
#endif
}