<commit_before>/* $Id$

   PLplot pstex (Postscript/LaTeX) device driver.
*/

#include "plDevs.h"

#ifdef PLD_pstex

#include "plplotP.h"
#include "drivers.h"
#include "ps.h"

/* Device info */
char* plD_DEVICE_INFO_pstex =
  "pstex:Combined Postscript/LaTeX files:0:pstex:41:pstex";

/*--------------------------------------------------------------------------*\
 * plD_init_pstex()
 *
 * Initialize device.
\*--------------------------------------------------------------------------*/


static void parse_str(const char *str, char *dest);
static void proc_str (PLStream *pls, EscText *args);
static long cur_pos;
static FILE *fp;
static int  color = 1;

static DrvOpt pstex_options[] = {{"color", DRV_INT, &color,
				  "Color Postscript/LaTeX (color=1|0)"},
				 {NULL, DRV_INT, NULL, NULL}};

void plD_dispatch_init_pstex( PLDispatchTable *pdt )
{
#ifndef ENABLE_DYNDRIVERS
    pdt->pl_MenuStr  ="Combined Postscript/LaTeX files" ;
    pdt->pl_DevName  = "pstex";
#endif
    pdt->pl_type     = plDevType_FileOriented;
    pdt->pl_seq      = 41;
    pdt->pl_init     = (plD_init_fp)     plD_init_pstex;
    pdt->pl_line     = (plD_line_fp)     plD_line_ps;
    pdt->pl_polyline = (plD_polyline_fp) plD_polyline_ps;
    pdt->pl_eop      = (plD_eop_fp)      plD_eop_ps;
    pdt->pl_bop      = (plD_bop_fp)      plD_bop_pstex;
    pdt->pl_tidy     = (plD_tidy_fp)     plD_tidy_pstex;
    pdt->pl_state    = (plD_state_fp)    plD_state_ps;
    pdt->pl_esc      = (plD_esc_fp)      plD_esc_pstex;
}

void
plD_init_pstex(PLStream *pls)
{
  char ofile[80];

  plParseDrvOpts(pstex_options);
  if (color)
    plD_init_psc(pls); /* init color postscript driver */
  else
    plD_init_psm(pls); /* init monochrome postscript driver */

  pls->dev_text = 1; /* want to draw text */
	pls->dev_unicode = 0; /* don't want unicode */

  /* open latex output file */
  strncpy(ofile, pls->FileName, 80);
  strcat(ofile, "_t");
  fp = fopen(ofile, "w");

  fprintf(fp,"\\begin{picture}(0,0)(0,0)%%\n");
  fprintf(fp,"\\includegraphics[scale=1.,clip]{%s}%%\n",pls->FileName); 
  fprintf(fp,"\\end{picture}%%\n");
  fprintf(fp,"\\setlength{\\unitlength}{%fbp}%%\n", 72./25.4/pls->xpmm);
  fprintf(fp,"\\begingroup\\makeatletter\\ifx\\SetFigFont\\undefined%%\n");
  fprintf(fp,"\\gdef\\SetFigFont#1#2#3#4#5{%%\n");
  fprintf(fp,"\\reset@font\\fontsize{#1}{#2pt}%%\n");
  fprintf(fp,"\\fontfamily{#3}\\fontseries{#4}\\fontshape{#5}%%\n");
  fprintf(fp,"\\selectfont}%%\n");
  fprintf(fp,"\\fi\\endgroup%%\n"); 

  cur_pos = ftell(fp);
  fprintf(fp,"\\begin{picture}(xxxxxx,xxxxxx)(xxxxxx,xxxxxx)%%\n");
}
<commit_msg>AWI for <NAME>.  Apply scale error fix suggested by <NAME> in 2004-09-30.  (Better late than never!  ;-) ).  I did not follow his comments (below) in detail, but I confirmed that the fix solved an obvious alignment problem now we have this device driver working again so that is why I am finally committing it.<commit_after>/* $Id$

   PLplot pstex (Postscript/LaTeX) device driver.
*/

#include "plDevs.h"

#ifdef PLD_pstex

#include "plplotP.h"
#include "drivers.h"
#include "ps.h"

/* Device info */
char* plD_DEVICE_INFO_pstex =
  "pstex:Combined Postscript/LaTeX files:0:pstex:41:pstex";

/*--------------------------------------------------------------------------*\
 * plD_init_pstex()
 *
 * Initialize device.
\*--------------------------------------------------------------------------*/


static void parse_str(const char *str, char *dest);
static void proc_str (PLStream *pls, EscText *args);
static long cur_pos;
static FILE *fp;
static int  color = 1;

static DrvOpt pstex_options[] = {{"color", DRV_INT, &color,
				  "Color Postscript/LaTeX (color=1|0)"},
				 {NULL, DRV_INT, NULL, NULL}};

void plD_dispatch_init_pstex( PLDispatchTable *pdt )
{
#ifndef ENABLE_DYNDRIVERS
    pdt->pl_MenuStr  ="Combined Postscript/LaTeX files" ;
    pdt->pl_DevName  = "pstex";
#endif
    pdt->pl_type     = plDevType_FileOriented;
    pdt->pl_seq      = 41;
    pdt->pl_init     = (plD_init_fp)     plD_init_pstex;
    pdt->pl_line     = (plD_line_fp)     plD_line_ps;
    pdt->pl_polyline = (plD_polyline_fp) plD_polyline_ps;
    pdt->pl_eop      = (plD_eop_fp)      plD_eop_ps;
    pdt->pl_bop      = (plD_bop_fp)      plD_bop_pstex;
    pdt->pl_tidy     = (plD_tidy_fp)     plD_tidy_pstex;
    pdt->pl_state    = (plD_state_fp)    plD_state_ps;
    pdt->pl_esc      = (plD_esc_fp)      plD_esc_pstex;
}

void
plD_init_pstex(PLStream *pls)
{
  char ofile[80];

  plParseDrvOpts(pstex_options);
  if (color)
    plD_init_psc(pls); /* init color postscript driver */
  else
    plD_init_psm(pls); /* init monochrome postscript driver */

  pls->dev_text = 1; /* want to draw text */
	pls->dev_unicode = 0; /* don't want unicode */

  /* open latex output file */
  strncpy(ofile, pls->FileName, 80);
  strcat(ofile, "_t");
  fp = fopen(ofile, "w");

  fprintf(fp,"\\begin{picture}(0,0)(0,0)%%\n");
  fprintf(fp,"\\includegraphics[scale=1.,clip]{%s}%%\n",pls->FileName); 
  fprintf(fp,"\\end{picture}%%\n");
/*  fprintf(fp,"\\setlength{\\unitlength}{%fbp}%%\n", 72./25.4/pls->xpmm); */
  fprintf(fp,"\\setlength{\\unitlength}{%fbp}%%\n", 1.0/ENLARGE);
  fprintf(fp,"\\begingroup\\makeatletter\\ifx\\SetFigFont\\undefined%%\n");
  fprintf(fp,"\\gdef\\SetFigFont#1#2#3#4#5{%%\n");
  fprintf(fp,"\\reset@font\\fontsize{#1}{#2pt}%%\n");
  fprintf(fp,"\\fontfamily{#3}\\fontseries{#4}\\fontshape{#5}%%\n");
  fprintf(fp,"\\selectfont}%%\n");
  fprintf(fp,"\\fi\\endgroup%%\n"); 

  cur_pos = ftell(fp);
  fprintf(fp,"\\begin{picture}(xxxxxx,xxxxxx)(xxxxxx,xxxxxx)%%\n");
}

{'fraction_non_alphanumeric': 0.22485632183908047, 'fraction_numerical': 0.014008620689655173, 'mean_word_length': 2.9665242165242165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4352807', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2247, 'n_words': 376}