Ejemplo n.º 1
0
bool
try_pk (string family, int size, int dpi, int dsize,
	tex_font_metric& tfm, font_glyphs& pk)
{
  // cout << "Try pk " << family << size << " at " << dpi << " dpi\n";
#ifdef USE_FREETYPE
  // Substitute by True Type font ?
  int tt_size= size<333? size: (size+50)/100;
  int tt_dpi = size<333? dpi : (size * dpi) / (100 * tt_size);
  string tt_name= tt_find_name (family, tt_size);
  if (tt_name != "") {
    if (font_glyphs::instances -> contains (tt_name))
      pk= font_glyphs (tt_name);
    else pk= tt_font_glyphs (tt_name, tt_size, tt_dpi);
    return true;
  }
#endif // USE_FREETYPE

  // Open regular pk font
  string name_pk= family * as_string (size) * "." * as_string (dpi) * "pk";
  if (font_glyphs::instances -> contains (name_pk)) {
    pk = font_glyphs (name_pk);
    return true;
  }
  if (dsize == 0) {
    int old_size= size;
    size= tfm->size;
    dpi = mag (dpi, old_size, size);
  }
  string size_name (dsize==0? string (""): as_string (size));
  string name (family * size_name * "." * as_string (dpi) * "pk");
  if (DEBUG_STD) debug_fonts << "Open pk " << name << "\n";
  url u= resolve_tex (name);
  if (is_none (u)) {
    if (exists (url ("$TEXMACS_HOME_PATH/fonts/error", name))) {
      if (DEBUG_STD)
        debug_fonts << "Error during " << name << " loading\n";
      return false;
    }
    if (get_setting ("MAKEPK") != "false") {
      system_wait ("Generating font file", name);
      make_tex_pk (family * size_name, dpi, as_int (get_setting ("DPI")));
      system_wait ("");
      u= resolve_tex (name);
      if (is_none (u)) {
	reset_pk_path ();
	u= resolve_tex (name);
      }
    }
    if (is_none (u)) {
      save_string (url ("$TEXMACS_HOME_PATH/fonts/error", name), "");
      if (DEBUG_STD)
        debug_fonts << "Error during " << name << " loading\n";
      return false;
    }
  }
  pk = font_glyphs (tm_new<pk_font_glyphs_rep> (name_pk,
					    tm_new<pk_loader> (u, tfm, dpi)));
  return true;
}
Ejemplo n.º 2
0
bool
try_tfm (string family, int size, int osize, tex_font_metric& tfm, bool make) {
  // cout << "Try tfm " << family << size << " (" << osize << ")\n";
  make= make && get_setting ("MAKETFM") != "false";
  string name_tfm = family * as_string (osize) * ".tfm";
  if (tex_font_metric::instances -> contains (name_tfm)) {
    tfm= tex_font_metric (name_tfm);
    return true;
  }
  string name= family * (size==0? string (""): as_string (size)) * ".tfm";
  if (DEBUG_STD) debug_fonts << "Try tfm " << name << "\n";
  url u= resolve_tex (name);
  if (is_none (u)) {
    if (exists (url ("$TEXMACS_HOME_PATH/fonts/error", name))) {
      if (DEBUG_STD)
        debug_fonts << "Error during " << name << " loading\n";
      return false;
    }
    if (make) {
      system_wait ("Generating font file", name);
      make_tex_tfm (name);
      system_wait ("");
      u= resolve_tex (name);
      if (is_none (u)) {
	reset_tfm_path ();
	u= resolve_tex (name);
	save_string (url ("$TEXMACS_HOME_PATH/fonts/error", name), "");
      }
    }
    if (is_none (u)) return false;
  }
  // cout << "Tfm " << family << osize << " -> " << family << size << "\n";
  tfm= load_tfm (u, family, osize);
  if (size != osize)
    cache_set ("font_cache.scm",
	       "tfm:" * family * as_string (osize), as_string (size));
  if (size == 0) {
    size= tfm->size;
    if (DEBUG_STD) debug_fonts << "Design size = " << size << "\n";
  }
  if (size != osize)
    tfm->header[1]= mag (tfm->header[1], osize, size);
  return true;
}
Ejemplo n.º 3
0
void
edit_process_rep::generate_glossary (string gly) {
  system_wait ("Generating glossary, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating glossary [" << gly << "]\n";
  tree G= copy (buf->data->aux[gly]);
  if (buf->prj != NULL) G= copy (buf->prj->data->aux[gly]);
  if (N(G)>0) {
    int i, n= N(G);
    tree D (DOCUMENT);
    for (i=0; i<n; i++)
      if (is_func (G[i], TUPLE, 1)) D << G[i][0];
      else if (is_func (G[i], TUPLE, 3) && (G[i][0] == "normal")) {
        tree content= G[i][1];
        if (is_document (content) && N(content) == 1) content= content[0];;
	tree L= compound ("glossary-1", content, G[i][2]);
	D << L;
      }
      else if (is_func (G[i], TUPLE, 4) && (G[i][0] == "normal")) {
        tree content= G[i][1];
        if (is_document (content) && N(content) == 1) content= content[0];;
	tree L= compound ("glossary-2", content, G[i][2], G[i][3]);
	D << L;
      }
      else if (is_func (G[i], TUPLE, 3) && (G[i][0] == "dup")) {
	int j;
	for (j=0; j<N(D); j++)
	  if ((is_compound (D[j], "glossary-1") ||
	       is_compound (D[j], "glossary-2")) &&
	      (D[j][1] == G[i][1]))
	    {
	      tree C= D[j][N(D[j])-1];
	      if (!is_concat (C)) C= tree (CONCAT, C);
	      C << ", ";
	      C << G[i][2];
	      D[j][N(D[j])-1]= C;
	    }
      }
    insert_tree (remove_labels (D));
  }
}
Ejemplo n.º 4
0
void
edit_process_rep::generate_index (string idx) {
  system_wait ("Generating index, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating index [" << idx << "]\n";
  tree I= copy (buf->data->aux[idx]);
  if (buf->prj != NULL) I= copy (buf->prj->data->aux[idx]);
  if (N(I)>0) {
    followup= hashmap<string,tree> (TUPLE);
    int i, n= N(I);
    array<string> entry (n);
    for (i=0; i<n; i++)
      entry[i]= index_name (I[i]);
    merge_sort (entry);

    hashmap<string,tree> h (TUPLE);
    for (i=0; i<n; i++) {
      string name = index_name  (I[i]);
      tree   value= index_value (I[i]);
      if (!h->contains (name)) h (name)= tuple (value);
      else h (name) << value;
    }

    array<string> new_entry;
    for (i=0; i<n; i++) {
      if ((i>0) && (entry[i] == entry[i-1])) continue;
      insert_recursively (new_entry, entry[i], h);
    }
    entry= new_entry;
    n= N(entry);

    tree D (DOCUMENT);
    for (i=0; i<n; i++)
      make_entry (D, h (entry[i]));
    insert_tree (remove_labels (D));
  }
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
0
void
edit_process_rep::generate_bibliography (
  string bib, string style, string fname)
{
  system_wait ("Generating bibliography, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating bibliography"
                    << " [" << bib << ", " << style << ", " << fname << "]\n";
  tree bib_t= buf->data->aux[bib];
  if (buf->prj != NULL) bib_t= buf->prj->data->aux[bib];
  tree t;
  url bib_file= find_bib_file (buf->buf->name, fname);
  //cout << fname << " -> " << concretize (bib_file) << "\n";
  if (is_none (bib_file)) {
    url bbl_file= find_bib_file (buf->buf->name, fname, ".bbl");
    if (is_none (bbl_file)) {
      if (supports_db ()) {
        t= as_tree (call (string ("bib-compile"), bib, style, bib_t));
        call (string ("bib-attach"), bib, bib_t);
      }
      else {
	std_error << "Could not load BibTeX file " << fname;
        set_message ("Could not find bibliography file",
                     "compile bibliography");
        return;
      }
    }
    else t= bibtex_load_bbl (bib, bbl_file);
  }
  else {
    if (!bibtex_present () && !starts (style, "tm-")) {
      if (style == "abbrv") style= "tm-abbrv";
      else if (style == "acm") style= "tm-acm";
      else if (style == "alpha") style= "tm-alpha";
      else if (style == "elsart-num") style= "tm-elsart-num";
      else if (style == "ieeetr") style= "tm-ieeetr";
      else if (style == "siam") style= "tm-siam";
      else if (style == "unsrt") style= "tm-unsrt";
      else style= "tm-plain";
    }
    if (supports_db () && !is_rooted (bib_file))
      bib_file= find_bib_file (buf->buf->name, fname, ".bib", true);
    if (supports_db ()) {
      //(void) call (string ("bib-import-bibtex"), bib_file);
      t= as_tree (call (string ("bib-compile"), bib, style, bib_t, bib_file));
    }
    else if (starts (style, "tm-")) {
      string sbib;
      if (load_string (bib_file, sbib, false))
	std_error << "Could not load BibTeX file " << fname;
      tree te= bib_entries (parse_bib (sbib), bib_t);
      object ot= tree_to_stree (te);
      eval ("(use-modules (bibtex " * style (3, N(style)) * "))");
      t= stree_to_tree (call (string ("bib-process"),
                              bib, style (3, N(style)), ot));
    }
    else
      t= bibtex_run (bib, style, bib_file, bib_t);
    if (supports_db ())
      (void) call (string ("bib-attach"), bib, bib_t, bib_file);
  }
  if (is_atomic (t) && starts (t->label, "Error:"))
    set_message (t->label, "compile bibliography");
  else if (is_compound (t) && N(t) > 0) insert_tree (t);
}