20 #define AWAR_APRINT "tmp/aprint/"
21 #define AWAR_APRINT_TITLE AWAR_APRINT "title"
22 #define AWAR_APRINT_TEXT AWAR_APRINT "text"
23 #define AWAR_APRINT_PAPER_SIZE AWAR_APRINT "paper_size"
24 #define AWAR_APRINT_MAGNIFICATION AWAR_APRINT "magnification"
25 #define AWAR_APRINT_SX AWAR_APRINT "source_columns"
26 #define AWAR_APRINT_SY AWAR_APRINT "source_rows"
27 #define AWAR_APRINT_DX AWAR_APRINT "dest_cols"
28 #define AWAR_APRINT_DY AWAR_APRINT "dest_rows"
29 #define AWAR_APRINT_ORIENTATION AWAR_APRINT "orientation"
30 #define AWAR_APRINT_PAGES AWAR_APRINT "pages"
31 #define AWAR_APRINT_PRINTTO AWAR_APRINT "printto"
32 #define AWAR_APRINT_PRINTER AWAR_APRINT "printer"
33 #define AWAR_APRINT_FILE AWAR_APRINT "file"
102 int default_cpp =
int(default_lpp * xy_ratio);
120 if (dx > 99) dx = 99;
124 int default_cpp =
int(default_lpp * xy_ratio);
125 int mag = 100 * default_cpp * dx / x;
135 if (dy > 99) dy = 99;
138 int mag = 100 * default_lpp * dy /
y;
160 for (s = text;
s; s=ns) {
161 ns = strchr(s,
'\n');
166 int slen = strlen(s);
179 static void write_file(
const char *filename,
const char *file) {
180 fprintf(stderr,
"Printing to ASCII file '%s'\n", filename);
181 FILE *f = fopen(filename,
"r");
188 f = fopen(filename,
"w");
193 fprintf(f,
"%s", file);
229 char *y_begin = text;
236 int default_cpp =
int(default_lpp * xy_ratio);
237 default_cpp = default_cpp * 100 / mag;
238 default_lpp = default_lpp * 100 / mag;
246 for (y = 0; y < text_height; y += default_lpp) {
249 y_begin = strchr(y_begin,
'\n');
255 for (x = 0; x < text_width; x += default_cpp) {
256 char *
line = y_begin;
258 for (i=0; i<default_lpp; i++) {
260 char *next_line = strchr(line,
'\n');
263 line_length = next_line -
line;
267 line_length = strlen(line);
269 if (line_length > x + default_cpp) {
270 line_length = x + default_cpp;
272 if (line_length > x) {
273 fwrite(line + x,
sizeof(
char), line_length - x, tmpf);
283 char *a2ps_call =
NULp;
286 const char *oristring =
"";
289 oristring =
"-p -1 ";
292 oristring =
"-l -1 ";
295 oristring =
"-p -2 ";
301 quotedHeaderArg, oristring, default_lpp, tmp_file);
302 free(quotedHeaderArg);
305 const char *scall =
NULp;
316 fprintf(stderr,
"Printing to PS file %s\n", quotedFile);
334 a2ps_call, tmp_file2,
336 tmp_file, tmp_file2);
355 static void cutExt(
char *name,
const char *removeExt) {
356 char *found = strstr(name, removeExt);
357 if (found && strcmp(found, removeExt) == 0) {
366 char *
result = ARB_alloc<char>(strlen(noExt)+strlen(newExt)+1);
367 strcpy(result, noExt);
368 strcat(result, newExt);
369 if (strcmp(name, result) == 0) freenull(result);
380 char *new_name =
NULp;
397 static AW_window_simple *aws =
NULp;
407 aws =
new AW_window_simple;
408 aws->init(awr,
"PRINT",
"PRINT");
409 aws->load_xfig(
"awt/ascii_print.fig");
430 if (getenv(
"PRINTER")) {
445 aws->create_button(
"CLOSE",
"CLOSE");
449 aws->create_button(
"HELP",
"HELP");
453 aws->create_button(
"PRINT",
"PRINT");
461 aws->button_length(5);
468 aws->at(
"magnification");
471 aws->at(
"paper_size");
474 aws->insert_toggle(
"A4",
"A",
int(AWT_APRINT_PAPERSIZE_A4));
476 aws->update_toggle_field();
479 aws->at(
"orientation");
482 aws->insert_toggle(
"#print/portrait.xpm",
"P",
int(AWT_APRINT_ORIENTATION_PORTRAIT));
484 aws->update_toggle_field();
506 aws->update_toggle_field();
GB_ERROR GBK_system(const char *system_command)
#define AWAR_APRINT_PRINTER
static int awt_aps_get_default_lines_per_page(AW_root *awr)
static void aps_correct_filename(AW_root *aw_root)
#define AWAR_APRINT_PAGES
void AWT_show_file(AW_root *awr, const char *filename)
static void awt_aps_calc_pages_needed(AW_root *awr)
static double awt_aps_get_xy_ratio(AW_root *awr)
char * ARB_strdup(const char *str)
#define AWAR_APRINT_PAPER_SIZE
const char * GBS_global_string(const char *templat,...)
void AW_POPDOWN(AW_window *window)
char * GBS_replace_tabs_by_spaces(const char *text)
GB_CSTR GB_getenvARB_GS(void)
AW_awar * add_callback(const RootCallback &cb)
#define AWAR_APRINT_TITLE
void AWT_create_ascii_print_window(AW_root *awr, const char *text_to_print, const char *title)
static char * correct_extension(const char *name, const char *newExt)
const char * read_char_pntr() const
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
char * GB_create_tempfile(const char *name)
static void cutExt(char *name, const char *removeExt)
AWT_asciiprint_paper_size
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
static void error(const char *msg)
FILE * GB_fopen_tempfile(const char *filename, const char *fmode, char **res_fullname)
static void awt_aps_go(AW_window *aww)
static char * printFile(AW_root *awr)
AWT_asciiprint_destination
char * read_string() const
AW_awar * awar(const char *awar)
#define AWAR_APRINT_ORIENTATION
GB_CSTR GB_getenv(const char *env)
char * GB_unique_filename(const char *name_prefix, const char *suffix)
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
char * GBK_singlequote(const char *arg)
#define AWAR_APRINT_MAGNIFICATION
const char * name_only(const char *fullpath)
static void write_file(const char *filename, const char *file)
void aw_message(const char *msg)
static void awt_aps_set_magnification_to_fit_ypage(AW_root *awr)
char * GBS_eval_env(GB_CSTR p)
void GB_split_full_path(const char *fullpath, char **res_dir, char **res_fullname, char **res_name_only, char **res_suffix)
GB_ERROR write_string(const char *aw_string)
static void awt_aps_text_changed(AW_root *awr)
#define AWAR_APRINT_PRINTTO
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
GB_ERROR write_float(float aw_float)
AWT_asciiprint_orientation
GB_ERROR write_int(long aw_int)
char * GBS_global_string_copy(const char *templat,...)
char * GB_read_file(const char *path)
static void awt_aps_set_magnification_to_fit_xpage(AW_root *awr)
GB_write_int const char s