diff options
author | Henry Stiles <henry.stiles@artifex.com> | 1998-07-23 03:39:24 +0000 |
---|---|---|
committer | Henry Stiles <henry.stiles@artifex.com> | 1998-07-23 03:39:24 +0000 |
commit | 4fa714729a294132cc99d4b3eab7e88325ea79ff (patch) | |
tree | e12292496ce2e339282bebd416c78993bfac7e4d | |
parent | 277471ffdea113eb7b9c5692592f28b21eb0d867 (diff) | |
download | ghostpdl-4fa714729a294132cc99d4b3eab7e88325ea79ff.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r78,
which included commits to RCS files with non-trunk default branches.
git-svn-id: http://svn.ghostscript.com/ghostpcl/trunk/ghostpcl@79 06663e23-700e-0410-b217-a244a6096597
-rw-r--r-- | pcl/pccpalet.c | 4 | ||||
-rw-r--r-- | pcl/pcfont.c | 78 | ||||
-rw-r--r-- | pcl/pcmacros.c | 4 | ||||
-rw-r--r-- | pcl/pcmain.c | 13 | ||||
-rw-r--r-- | pcl/pcpage.c | 2 | ||||
-rw-r--r-- | pcl/pcprint.c | 4 | ||||
-rw-r--r-- | pcl/pcsymbol.c | 4 | ||||
-rw-r--r-- | pcl/pgchar.c | 148 | ||||
-rw-r--r-- | pcl/pgconfig.c | 32 | ||||
-rw-r--r-- | pcl/pgdraw.c | 315 | ||||
-rw-r--r-- | pcl/pgdraw.h | 11 | ||||
-rw-r--r-- | pcl/pgframe.c | 4 | ||||
-rw-r--r-- | pcl/pgmand.h | 2 | ||||
-rw-r--r-- | pcl/pgmisc.c | 5 | ||||
-rw-r--r-- | pcl/pgmisc.h | 101 | ||||
-rw-r--r-- | pcl/pgpoly.c | 35 | ||||
-rw-r--r-- | pcl/pgstate.h | 74 | ||||
-rw-r--r-- | pcl/pgvector.c | 56 | ||||
-rw-r--r-- | pcl/rtcolor.c | 12 | ||||
-rw-r--r-- | pcl/rtmisc.c | 10 | ||||
-rw-r--r-- | pcl/rtraster.c | 7 |
21 files changed, 561 insertions, 360 deletions
diff --git a/pcl/pccpalet.c b/pcl/pccpalet.c index 12134d188..30ed2781f 100644 --- a/pcl/pccpalet.c +++ b/pcl/pccpalet.c @@ -1,10 +1,10 @@ -/* Copyright (C) 1996 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1996, 1997 Aladdin Enterprises. All rights reserved. Unauthorized use, copying, and/or distribution prohibited. */ /* pccpalet.c */ /* PCL5c palette commands */ -#include "std.h" +#include "stdio_.h" /* std.h + NULL */ #include "pcommand.h" #include "pcstate.h" diff --git a/pcl/pcfont.c b/pcl/pcfont.c index 1f134229b..9f6c16a3c 100644 --- a/pcl/pcfont.c +++ b/pcl/pcfont.c @@ -4,7 +4,7 @@ /* pcfont.c */ /* PCL5 font selection and text printing commands */ -#include "std.h" +#include "memory_.h" /* XXX #include tangle: We need pl_load_tt_font, which is only supplied * by plfont.h if stdio.h is included, but pcstate.h back-door includes * plfont.h, so we have to pull in stdio.h here even though it should only @@ -861,18 +861,15 @@ pcfont_do_reset(pcl_state_t *pcls, pcl_reset_type_t type) * very little of this code can be salvaged for later. */ bool -pcl_load_built_in_fonts(pcl_state_t *pcls) -{ -#include <sys/types.h> -#include <dirent.h> -#include <string.h> - -#define FONTDIR "." +pcl_load_built_in_fonts(pcl_state_t *pcls, const char *prefixes[]) +{ const char **pprefix; +#include "string_.h" +#include "gp.h" typedef struct font_hack { char *ext_name; pl_font_params_t params; } font_hack_t; - font_hack_t hack_table[] = { + static const font_hack_t hack_table[] = { /* Typeface family values are faked; they do not (necessarily) * match the actual fonts. */ {"arial", {0, 1, 0, 0, 0, 0, 16602} }, @@ -889,13 +886,8 @@ pcl_load_built_in_fonts(pcl_state_t *pcls) {"timesi", {0, 1, 0, 0, 1, 0, 16901} }, {NULL, {0, 0, 0, 0, 0, 0, 0} } }; - DIR *dp; - struct dirent *dep; - FILE *fnp; - pl_font_t *plfont; - font_hack_t *hackp; - int id = 0; - byte key[2]; + const font_hack_t *hackp; + byte font_found[countof(hack_table)]; bool found_some = false; /* This initialization was moved from the do_reset procedures to @@ -906,45 +898,34 @@ pcl_load_built_in_fonts(pcl_state_t *pcls) pl_dict_init(&pcls->soft_fonts, pcls->memory, pl_free_font); pl_dict_set_parent(&pcls->soft_fonts, &pcls->built_in_fonts); - if ( (dp=opendir(FONTDIR)) == NULL ) - { -#ifdef DEBUG - perror(FONTDIR); -#endif - return false; - } - while ( (dep=readdir(dp)) != NULL ) - { int dirlen = strlen(dep->d_name); - if ( strcmp(".ttf", &dep->d_name[dirlen - 4]) == 0 ) - { - if ( (fnp=fopen(dep->d_name, "r")) == NULL ) - { -#ifdef DEBUG - perror(dep->d_name); -#endif - continue; - } + /* Load only those fonts we know about. */ + memset(font_found, 0, sizeof(font_found)); + for ( pprefix = prefixes; *pprefix != 0; ++pprefix ) + for ( hackp = hack_table; hackp->ext_name != 0; ++hackp ) + if ( !font_found[hackp - hack_table] ) + { char fname[150]; + FILE *fnp; + pl_font_t *plfont; + int id = 0; + byte key[2]; + + strcpy(fname, *pprefix); + strcat(fname, hackp->ext_name); + strcat(fname, ".ttf"); + if ( (fnp=fopen(fname, gp_fmode_rb)) == NULL ) + continue; if ( pl_load_tt_font(fnp, pcls->font_dir, pcls->memory, - gs_next_ids(1), &plfont) < 0 ) + gs_next_ids(1), &plfont) < 0 ) { #ifdef DEBUG - lprintf1("Failed loading font %s\n", dep->d_name); + lprintf1("Failed loading font %s\n", fname); #endif - return false; + continue; } #ifdef DEBUG - dprintf1("Loaded %s\n", dep->d_name); + dprintf1("Loaded %s\n", fname); #endif plfont->storage = pcds_internal; - /* extraordinary hack: get the font characteristics from a - * hardwired table; ignore the font if we don't know it. */ - for ( hackp=hack_table; hackp->ext_name; hackp++ ) - { - if ( strncmp(hackp->ext_name, dep->d_name, dirlen-4) == 0 ) - break; - } - if ( hackp->ext_name == NULL ) - continue; /* not in table */ /* Don't smash the pitch_100ths, which was obtained * from the actual font. */ { uint save_pitch = plfont->params.pitch_100ths; @@ -955,10 +936,9 @@ pcl_load_built_in_fonts(pcl_state_t *pcls) key[0] = id >> 8; key[1] = id; pl_dict_put(&pcls->built_in_fonts, key, 2, plfont); + font_found[hackp - hack_table] = 1; found_some = true; } - } - closedir(dp); return found_some; } diff --git a/pcl/pcmacros.c b/pcl/pcmacros.c index 3aed4fd0f..823cbd094 100644 --- a/pcl/pcmacros.c +++ b/pcl/pcmacros.c @@ -1,10 +1,10 @@ -/* Copyright (C) 1996 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1996, 1997 Aladdin Enterprises. All rights reserved. Unauthorized use, copying, and/or distribution prohibited. */ /* pcmacros.c */ /* PCL5 macro commands */ -#include "std.h" +#include "stdio_.h" /* std.h + NULL */ #include "pcommand.h" #include "pcstate.h" #include "pcparse.h" diff --git a/pcl/pcmain.c b/pcl/pcmain.c index 5d57f1e18..690342ec6 100644 --- a/pcl/pcmain.c +++ b/pcl/pcmain.c @@ -4,6 +4,8 @@ /* pcmain.c */ /* PCL5 main program */ +#undef DEBUG +#define DEBUG /* always enable debug output */ #include "malloc_.h" #include "math_.h" #include "memory_.h" @@ -22,8 +24,8 @@ #include "gscoord.h" #include "gspath.h" #include "gxalloc.h" -# include "gxdevice.h" -# include "gdevbbox.h" +#include "gxdevice.h" +#include "gdevbbox.h" #include "pjparse.h" #include "plmain.h" @@ -46,7 +48,10 @@ const pcl_init_t *pcl_init_table[] = { }; /* Interim font initialization procedure */ -extern bool pcl_load_built_in_fonts(pcl_state_t *); +extern bool pcl_load_built_in_fonts(P2(pcl_state_t *, const char *[])); +private const char *built_in_font_prefixes[] = { + "", "/windows/system/", "/windows/fonts/", "/win95/fonts/", 0 +}; /* Built-in symbol set initialization procedure */ extern bool pcl_load_built_in_symbol_sets(pcl_state_t *); @@ -139,7 +144,7 @@ main(int argc, char *argv[]) /* Intermediate initialization: after state is initialized, may * allocate memory, but we won't re-run this level of init. */ - if ( !pcl_load_built_in_fonts(&state) ) + if ( !pcl_load_built_in_fonts(&state, built_in_font_prefixes) ) { lprintf("No built-in fonts found during initialization\n"); exit(1); diff --git a/pcl/pcpage.c b/pcl/pcpage.c index f131e3575..986a11f9a 100644 --- a/pcl/pcpage.c +++ b/pcl/pcpage.c @@ -92,7 +92,7 @@ private void reset_text_length(pcl_state_t *pcls) { if ( pcls->vmi != 0 ) { int len = (int)((pcls->logical_page_height - pcls->top_margin - - inch2coord(0.5)) * 48.0 / pcls->vmi); + inch2coord(0.5)) / pcls->vmi); /* We suppose that the minimum text length is 1.... */ pcls->text_length = max(len, 1); } diff --git a/pcl/pcprint.c b/pcl/pcprint.c index 136b4005f..33bd06134 100644 --- a/pcl/pcprint.c +++ b/pcl/pcprint.c @@ -1,10 +1,10 @@ -/* Copyright (C) 1996 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1996, 1997 Aladdin Enterprises. All rights reserved. Unauthorized use, copying, and/or distribution prohibited. */ /* pcprint.c */ /* PCL5 print model commands */ -#include "std.h" +#include "stdio_.h" /* std.h + NULL */ #include "plvalue.h" #include "pcommand.h" #include "pcstate.h" diff --git a/pcl/pcsymbol.c b/pcl/pcsymbol.c index 5e6df363f..8f7663f27 100644 --- a/pcl/pcsymbol.c +++ b/pcl/pcsymbol.c @@ -1,10 +1,10 @@ -/* Copyright (C) 1996 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1996, 1997 Aladdin Enterprises. All rights reserved. Unauthorized use, copying, and/or distribution prohibited. */ /* pcsymbol.c */ /* PCL5 user-defined symbol set commands */ -#include "std.h" +#include "stdio_.h" /* std.h + NULL */ #include "plvalue.h" #include "pcommand.h" #include "pcstate.h" diff --git a/pcl/pgchar.c b/pcl/pgchar.c index 3cb5ef86d..c846e6888 100644 --- a/pcl/pgchar.c +++ b/pcl/pgchar.c @@ -94,7 +94,6 @@ hpgl_font_definition(hpgl_args_t *pargs, hpgl_state_t *pgls, int index) hpgl_default_font_params(pfs); return 0; } - /* Define label drawing direction (DI, DR). */ private int hpgl_label_direction(hpgl_args_t *pargs, hpgl_state_t *pgls, bool relative) @@ -163,6 +162,20 @@ hpgl_CF(hpgl_args_t *pargs, hpgl_state_t *pgls) } private int +hpgl_get_carriage_return_pos(hpgl_state_t *pgls, gs_point *pt) +{ + *pt = pgls->g.carriage_return_pos; + return 0; +} + +private int +hpgl_set_carriage_return_pos(hpgl_state_t *pgls, gs_point *pt) +{ + pgls->g.carriage_return_pos = *pt; + return 0; +} + +private int hpgl_get_current_cell_width(hpgl_state_t *pgls, hpgl_real_t *width) { /* HAS - just supports current font */ @@ -190,48 +203,90 @@ hpgl_CP(hpgl_args_t *pargs, hpgl_state_t *pgls) { hpgl_real_t spaces = 0.0; hpgl_real_t lines = 1.0; - + hpgl_pen_state_t saved_pen_state; + bool crlf = false; + + /* HAS ***HACK **** HACK **** HACK */ + /* save the current render mode and temporarily set it to + vector mode. This allows the HPGL/2 graphics not to apply + the character ctm for the label position move. This must + be handled more "pleasantly" in the future */ + + hpgl_rendering_mode_t rm = pgls->g.current_render_mode; + + pgls->g.current_render_mode = hpgl_rm_vector; + /* CP does its work with the pen up -- we restore the current - state at the end of the routine */ - hpgl_save_pen_down_state(pgls); - /* We will take advantage of PR so save the current relative - state as well */ - hpgl_save_pen_relative_state(pgls); + state at the end of the routine. We will take advantage of + PR so save the current relative state as well */ + hpgl_save_pen_state(pgls, + &saved_pen_state, + hpgl_pen_down | hpgl_pen_relative); if ( hpgl_arg_c_real(pargs, &spaces) ) - { if ( !hpgl_arg_c_real(pargs, &lines) ) + { + if ( !hpgl_arg_c_real(pargs, &lines) ) return e_Range; } + else - { + /* if there are no arguments a carriage return and line feed + is executed */ + crlf = true; + { hpgl_real_t width, height; hpgl_args_t args; + gs_point pt, crpt, relpos; /* current pos and carriage return pos */ /* get the character cell height and width */ hpgl_call(hpgl_get_current_cell_width(pgls, &width)); hpgl_call(hpgl_get_current_cell_height(pgls, &height)); - - /* set the pen up */ - hpgl_args_set_real(&args, pgls->g.pos.x); - hpgl_args_add_real(&args, pgls->g.pos.y); - hpgl_PU(&args, pgls); - /* relative move to new position, not forgetting ES */ - hpgl_args_set_real(&args, ((spaces + pgls->g.character.extra_space.x) * - width)); - hpgl_args_add_real(&args, -((lines + pgls->g.character.extra_space.y) * - height)); + /* get the current position and carriage return position */ + hpgl_call(hpgl_get_current_position(pgls, &pt)); + hpgl_call(hpgl_get_carriage_return_pos(pgls, &crpt)); + + /* calculate the next label position in relative + coordinates. If CR/LF the calculate the y coordinate and + the X position is simply the x coordinate of the current + carriage return point. We use relative coordinates for + the movement in either case. */ + if (crlf) + relpos.x = -(pt.x - crpt.x); + else + relpos.x = ((spaces + pgls->g.character.extra_space.x) * width); + + /* the y coordinate is independant of CR/LF status */ + relpos.y = -((lines + pgls->g.character.extra_space.y) * height); + + /* move to the current position */ + hpgl_args_setup(&args); + hpgl_PU(&args, pgls); + + /* a relative move to the new position */ + hpgl_args_set_real(&args, relpos.x); + hpgl_args_add_real(&args, relpos.y); hpgl_PR(&args, pgls); - /* save the current position in GL/2's state */ - hpgl_call(hpgl_set_current_position(pgls, (gs_point *) NULL)); + /* update the carriage return point - the Y is the Y of + the current position and the X is the X of the current + carriage return point position */ + hpgl_call(hpgl_get_current_position(pgls, &pt)); + hpgl_call(hpgl_get_carriage_return_pos(pgls, &crpt)); + crpt.y = pt.y; + + /* set the value in the state */ + hpgl_call(hpgl_set_carriage_return_pos(pgls, &crpt)); } + /* put the pen back the way it was, of course we do not want to restore the pen's position */ - hpgl_restore_pen_relative_state(pgls); - hpgl_restore_pen_down_state(pgls); + hpgl_restore_pen_state(pgls, + &saved_pen_state, + hpgl_pen_down | hpgl_pen_relative); + pgls->g.current_render_mode = rm; return 0; } @@ -341,6 +396,14 @@ hpgl_update_label_pos(hpgl_state_t *pgls, byte ch) break; case LF : spaces = 0; + lines = 1; + break; + case CR : + /* do a CR/LF and a -1 line move */ + hpgl_args_setup(&args); + hpgl_CP(&args, pgls); + spaces = 0; + lines = -1; break; default : break; @@ -357,20 +420,18 @@ hpgl_print_char(hpgl_state_t *pgls, hpgl_character_point *character) { hpgl_rendering_mode_t rm = pgls->g.current_render_mode; - /* set the current gs point to the origin */ - hpgl_call(hpgl_set_current_position(pgls, (gs_point *)NULL)); - /* clear the current path, if there is one */ hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); pgls->g.current_render_mode = hpgl_rm_character; - + /* all character data is absolute */ + pgls->g.relative = false; while (character->operation != hpgl_char_end) { hpgl_args_t args; /* setup the arguments */ hpgl_args_setup(&args); - /* all operations supply arguments except: */ + /* all character operations supply numeric arguments except: */ if (character->operation != hpgl_char_pen_down_no_args) { hpgl_args_add_real(&args, character->vertex.x); @@ -405,11 +466,15 @@ hpgl_print_char(hpgl_state_t *pgls, hpgl_character_point *character) static int hpgl_process_char(hpgl_state_t *pgls, byte ch) { - + hpgl_pen_state_t saved_pen_state; + /* we need to keep this pen position, as updating the label + origin is relative to the current origin vs. the pen's + position after the character is rendered */ + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); if ( isprint(ch) ) /* ascii is all we have right now */ hpgl_call(hpgl_print_char(pgls, hpgl_ascii_char_set[ch - 0x20])); - + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_update_label_pos(pgls, ch)); return 0; @@ -421,13 +486,17 @@ hpgl_LB(hpgl_args_t *pargs, hpgl_state_t *pgls) { const byte *p = pargs->source.ptr; const byte *rlimit = pargs->source.limit; - /* we use the hpgl drawing machinery to stroke the glyph so we - need to save the state of the pen and restore it after the - glyph is printed. HAS needs work */ - bool rel = pgls->g.relative; - bool down = pgls->g.pen_down; - gs_point pos = pgls->g.pos; - + /* HAS need to figure out what gets saved here -- relative, + pen_down, position ?? */ + hpgl_call(hpgl_clear_current_path(pgls)); + /* set the carriage return point */ + { + /* HAS this should only happen the first time that we call + LB ?? */ + gs_point pt; + hpgl_call(hpgl_get_current_position(pgls, &pt)); + hpgl_call(hpgl_set_carriage_return_pos(pgls, &pt)); + } while ( p < rlimit ) { byte ch = *++p; if_debug1('I', @@ -440,15 +509,14 @@ hpgl_LB(hpgl_args_t *pargs, hpgl_state_t *pgls) hpgl_call(hpgl_process_char(pgls, ch)); /* restore pen's state */ - pgls->g.relative = rel; - pgls->g.pen_down = down; - pgls->g.pos = pos; + /* hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); */ pargs->source.ptr = p; return 0; } hpgl_call(hpgl_process_char(pgls, ch)); } pargs->source.ptr = p; + /* hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); */ return e_NeedData; } diff --git a/pcl/pgconfig.c b/pcl/pgconfig.c index 8fa1b0742..e4109137c 100644 --- a/pcl/pgconfig.c +++ b/pcl/pgconfig.c @@ -89,7 +89,9 @@ hpgl_DF(hpgl_args_t *pargs, hpgl_state_t *pgls) hpgl_LT(&args, pgls); hpgl_args_setup(&args); - hpgl_args_add_real(&args, 0.0); + hpgl_SC(&args, pgls); + + hpgl_args_set_real(&args, 0.0); hpgl_args_add_real(&args, 0.0); hpgl_PA(&args, pgls); @@ -99,14 +101,9 @@ hpgl_DF(hpgl_args_t *pargs, hpgl_state_t *pgls) hpgl_args_set_int(&args,2); hpgl_PM(&args, pgls); - /* hpgl_args_setup(&args); - hpgl_RF(&args, pgls); */ - hpgl_args_set_int(&args,0); hpgl_SB(&args, pgls); - hpgl_args_setup(&args); - hpgl_SC(&args, pgls); hpgl_args_setup(&args); hpgl_SV(&args, pgls); @@ -149,15 +146,6 @@ hpgl_IN(hpgl_args_t *pargs, hpgl_state_t *pgls) /* restore defaults */ hpgl_DF(&args, pgls); - /* pen up position */ - hpgl_args_setup(&args); - hpgl_PU(&args, pgls); - - /* absolute positioning at the lower left of the picture frame */ - hpgl_args_set_real(&args, 0.0); - hpgl_args_add_real(&args, 0.0); - hpgl_PA(&args, pgls); - /* cancel rotation */ hpgl_args_setup(&args); hpgl_RO(&args, pgls); @@ -188,6 +176,15 @@ hpgl_IN(hpgl_args_t *pargs, hpgl_state_t *pgls) hpgl_args_set_int(&args,2); hpgl_NP(&args, pgls); #endif + /* pen up position */ + hpgl_args_setup(&args); + hpgl_PU(&args, pgls); + + /* absolute positioning at the lower left of the picture frame */ + hpgl_args_set_real(&args, 0.0); + hpgl_args_add_real(&args, 0.0); + hpgl_PA(&args, pgls); + return 0; } @@ -385,6 +382,7 @@ hpgl_SC(hpgl_args_t *pargs, hpgl_state_t *pgls) default: return e_Range; case 4: + type = hpgl_scaling_anisotropic; hpgl_arg_c_int(pargs, &type); switch ( type ) { @@ -392,8 +390,8 @@ hpgl_SC(hpgl_args_t *pargs, hpgl_state_t *pgls) if ( xy[0] == xy[1] || xy[2] == xy[3] ) return e_Range; pxy: pgls->g.scaling_params.pmin.x = xy[0]; - pgls->g.scaling_params.pmin.y = xy[1]; - pgls->g.scaling_params.pmax.x = xy[2]; + pgls->g.scaling_params.pmax.x = xy[1]; + pgls->g.scaling_params.pmin.y = xy[2]; pgls->g.scaling_params.pmax.y = xy[3]; break; case hpgl_scaling_isotropic: /* 1 */ diff --git a/pcl/pgdraw.c b/pcl/pgdraw.c index 7917ff8b9..1f2060c14 100644 --- a/pcl/pgdraw.c +++ b/pcl/pgdraw.c @@ -110,12 +110,16 @@ hpgl_set_graphics_line_attribute_state(hpgl_state_t *pgls, { case hpgl_rm_character: case hpgl_rm_polygon: - hpgl_call(gs_setlinejoin(pgls->pgs, gs_cap_round)); - hpgl_call(gs_setlinecap(pgls->pgs, gs_join_round)); + hpgl_call(gs_setlinejoin(pgls->pgs, + gs_join_round)); + hpgl_call(gs_setlinecap(pgls->pgs, + gs_cap_round)); break; case hpgl_rm_vector: -vector: hpgl_call(gs_setlinejoin(pgls->pgs, cap_map[pgls->g.line.cap])); - hpgl_call(gs_setlinecap(pgls->pgs, join_map[pgls->g.line.join])); +vector: hpgl_call(gs_setlinejoin(pgls->pgs, + join_map[pgls->g.line.join])); + hpgl_call(gs_setlinecap(pgls->pgs, + cap_map[pgls->g.line.cap])); break; default: /* shouldn't happen as we must have a mode to properly @@ -164,28 +168,22 @@ hpgl_set_clipping_region(hpgl_state_t *pgls) return 0; } -/* change pcl's transformation. HAS hpgl's coordinate system rotates - with pcl's orientation but not pcl's current print direction. */ private int -hpgl_set_ctm(hpgl_state_t *pgls) +hpgl_set_plu_to_device_ctm(hpgl_state_t *pgls) { - /* set the default matrix */ pcl_set_ctm(pgls, false); - /* translate the coordinate system to the anchor point */ hpgl_call(gs_translate(pgls->pgs, pgls->g.picture_frame.anchor_point.x, pgls->g.picture_frame.anchor_point.y)); - /* scale for x and y plu's with a flip for y */ - hpgl_call(gs_scale(pgls->pgs, (7200.0/1016.0), -(7200.0 / 1016.0))); { /* picture frame dimensinsions in plu */ - hpgl_real_t pic_w = centipoints_2_plu(pgls->g.picture_frame.width); - hpgl_real_t pic_h = centipoints_2_plu(pgls->g.picture_frame.height); + hpgl_real_t pic_w = (pgls->g.picture_frame.width); + hpgl_real_t pic_h = (pgls->g.picture_frame.height); /* move the origin */ - hpgl_call(gs_translate(pgls->pgs, 0, -(pic_h))); + hpgl_call(gs_translate(pgls->pgs, 0, (pic_h))); hpgl_call(gs_rotate(pgls->pgs, pgls->g.rotation)); @@ -206,6 +204,9 @@ hpgl_set_ctm(hpgl_state_t *pgls) break; } } + /* scale to plotter units and a flip for y */ + hpgl_call(gs_scale(pgls->pgs, (7200.0/1016.0), -(7200.0/1016.0))); + /* set up scaling wrt plot size and picture frame size. HAS we still have the line width issue when scaling is assymetric !! */ @@ -222,10 +223,133 @@ hpgl_set_ctm(hpgl_state_t *pgls) pgls->g.plot_height), (pgls->g.picture_frame.width / pgls->g.plot_width))); - + + return 0; + + +} + +private int +hpgl_set_label_to_plu_ctm(hpgl_state_t *pgls) +{ + /* if we are not in character mode do nothing -- identity + transformation */ + /* HAS font is selection not complete */ + hpgl_real_t height_points = + pgls->g.font_selection[0].params.height_4ths / 4.0; + hpgl_real_t width_points = + 1.0 / (pgls->g.font_selection[0].params.pitch_100ths / 100.0); + /* HAS -- Only LO1 is currently supported -- need to add others */ + hpgl_call(gs_translate(pgls->pgs, pgls->g.pos.x, pgls->g.pos.y)); + /* HAS -- only support standard font */ + hpgl_call(gs_scale(pgls->pgs, + points_2_plu(height_points), + inches_2_plu(width_points))); + return 0; +} + + +private int +hpgl_set_user_units_to_plu_ctm(hpgl_state_t *pgls) +{ + + hpgl_call(gs_translate(pgls->pgs, pgls->g.P1.x, -pgls->g.P1.y)); + + /* finally scale to user units. HAS this only handles the + simple scaling scale for the moment. */ + if ( pgls->g.scaling_type == hpgl_scaling_anisotropic ) + { + floatp scale_x = (pgls->g.P2.x - pgls->g.P1.x) / + (pgls->g.scaling_params.pmax.x - pgls->g.scaling_params.pmin.x); + floatp scale_y = (pgls->g.P2.y - pgls->g.P1.y) / + (pgls->g.scaling_params.pmax.y - pgls->g.scaling_params.pmin.y); + hpgl_call(gs_scale(pgls->pgs, scale_x, scale_y)); + } + else if ( pgls->g.scaling_type != hpgl_scaling_none ) + dprintf1("unsuported scaling type %d:\n", pgls->g.scaling_type); + + return 0; +} + +/* set up ctm's. Uses the current render mode to figure out which ctm + is appropriate */ +private int +hpgl_set_ctm(hpgl_state_t *pgls) +{ + /* convert pcl->device to plu->device */ + hpgl_call(hpgl_set_plu_to_device_ctm(pgls)); + + /* concatenate on user units ctm or character ctm based on + current mode */ + if ( pgls->g.current_render_mode == hpgl_rm_character ) + hpgl_call(hpgl_set_label_to_plu_ctm(pgls)); + else + hpgl_call(hpgl_set_user_units_to_plu_ctm(pgls)); + return 0; } + +/* maps current hpgl fill type to pcl pattern type. */ +private pcl_pattern_type_t +hpgl_map_fill_type(hpgl_state_t *pgls) +{ + switch (pgls->g.fill.type) + { + case hpgl_fill_solid : return pcpt_solid_black; + case hpgl_fill_solid2 : return pcpt_solid_black; + case hpgl_fill_pcl_crosshatch : return pcpt_cross_hatch; + case hpgl_fill_shaded : return pcpt_shading; + case hpgl_fill_pcl_user_defined : + dprintf("No key mapping support flling back to solid"); + break; + default : + dprintf1("Unsupported fill type %d falling back to solid\n", + pgls->g.fill.type); + } + + return pcpt_solid_black; +} +/* HAS I don't much care for the idea of overloading pcl_id with + shading and hatching information, but that appears to be the way + pcl_set_drawing_color() is set up. */ +private pcl_id_t * +hpgl_map_id_type(hpgl_state_t *pgls, pcl_id_t *id) +{ + switch (pgls->g.fill.type) + { + case hpgl_fill_solid : + case hpgl_fill_solid2 : + id = NULL; + break; + case hpgl_fill_pcl_crosshatch : + id_set_value(*id, pgls->g.fill.param.pattern_type); + break; + case hpgl_fill_shaded : + id_set_value(*id, (int)((pgls->g.fill.param.shading) * 100.0)); + break; + case hpgl_fill_pcl_user_defined : + id = NULL; + dprintf("No key mapping support yet"); + break; + default : + id = NULL; + dprintf1("Unsupported fill type %d falling back to pcl solid\n", + pgls->g.fill.type); + } + return id; +} + +private int +hpgl_set_drawing_color(hpgl_state_t *pgls) +{ + pcl_id_t pcl_id; + + hpgl_call(pcl_set_drawing_color(pgls, + hpgl_map_fill_type(pgls), + hpgl_map_id_type(pgls, &pcl_id))); + return 0; +} private int hpgl_set_graphics_state(hpgl_state_t *pgls, hpgl_rendering_mode_t render_mode) @@ -236,50 +360,42 @@ hpgl_set_graphics_state(hpgl_state_t *pgls, hpgl_rendering_mode_t render_mode) etc. */ hpgl_call(hpgl_set_ctm(pgls)); - /* do dash stuff */ + /* do dash stuff. */ hpgl_call(hpgl_set_graphics_dash_state(pgls)); - /* joins, caps, and line width */ + /* joins, caps, and line width. */ hpgl_call(hpgl_set_graphics_line_attribute_state(pgls, render_mode)); + /* set up the hpgl fills. */ + hpgl_call(hpgl_set_drawing_color(pgls)); + + /* set up a clipping region */ hpgl_call(hpgl_set_clipping_region(pgls)); return 0; } -/* transformations for the current character. These are concatenated - with current ctm. This routine is only called for rendering - characters with LB */ -private int -hpgl_concatenate_character_transformations(hpgl_state_t *pgls) +int +hpgl_get_current_position(hpgl_state_t *pgls, gs_point *pt) { - /* HAS -- Only LO1 is currently supported -- need to add others */ - hpgl_call(gs_translate(pgls->pgs, pgls->g.pos.x, pgls->g.pos.y)); - /* HAS -- only support standard font */ - hpgl_call(gs_scale(pgls->pgs, - points_2_plu((pgls->g.font_selection[0].params.height_4ths) - /4.0), - inches_2_plu((1.0 / - (pgls->g.font_selection[0].params.pitch_100ths - / 100.0))))); + + *pt = pgls->g.pos; return 0; -} +} -/* function that simply sets the current pen position based on the - current point */ int hpgl_set_current_position(hpgl_state_t *pgls, gs_point *pt) { - /* HAS - this will be a performance problem */ - hpgl_call(hpgl_set_ctm(pgls)); - - /* if no point is supplied use the current point */ - if (!pt) + if ( pgls->g.relative ) { - hpgl_call(gs_currentpoint(pgls->pgs, &pgls->g.pos)); + pgls->g.pos.x += pt->x; + pgls->g.pos.y += pt->y; } else - pgls->g.pos = *pt; + { + pgls->g.pos.x = pt->x; + pgls->g.pos.y = pt->y; + } return 0; } @@ -287,40 +403,31 @@ int hpgl_add_point_to_path(hpgl_state_t *pgls, floatp x, floatp y, int (*gs_func)(gs_state *pgs, floatp x, floatp y)) { + gs_point point; + point.x = x; + point.y = y; + if ( !(pgls->g.have_first_moveto) ) { /* initialize the first point so we can implicitly close the path when we stroke and set up the ctm */ - pgls->g.first_point.x = x; - pgls->g.first_point.y = y; - /* indicate that there is a current path */ - pgls->g.have_first_moveto = true; - /* initialize the current transformation matrix -- see - notes above on performance */ + pgls->g.first_point = point; + /* initialize the current transformation matrix */ hpgl_call(hpgl_set_ctm(pgls)); - if (pgls->g.current_render_mode == hpgl_rm_character) - { - /* apply necessary character transformations as well */ - hpgl_call(hpgl_concatenate_character_transformations(pgls)); - } hpgl_call(gs_newpath(pgls->pgs)); - hpgl_call_check_lost(gs_moveto(pgls->pgs, x, y)); - - /* HAS HACK *** HACK **** HACK */ - /* we really do not want to indicate that we have a path - as the using gs graphics a path is not truly created - with the first moveto. So we must indicate that we - have added the first moveto and subsequently check for - that condition. Then we may set the "have_path" state */ - } - else - { - hpgl_call_check_lost((*gs_func)(pgls->pgs, x, y)); - /* update hpgl's state position */ - pgls->g.have_path = true; + hpgl_call_check_lost(gs_moveto(pgls->pgs, point.x, point.y)); + /* indicate that there is a current path */ + /* we do not want to indicate a first moveto if we went + into lost mode */ + if (!hpgl_lost) pgls->g.have_first_moveto = true; } + + hpgl_call_check_lost((*gs_func)(pgls->pgs, point.x, point.y)); + + /* update hpgl's state position */ + hpgl_call(hpgl_set_current_position(pgls, &point)); return 0; } @@ -329,6 +436,7 @@ hpgl_add_point_to_path(hpgl_state_t *pgls, floatp x, floatp y, int hpgl_clear_current_path(hpgl_state_t *pgls) { + /* if a current path exists set the current state position */ hpgl_call(gs_newpath(pgls->pgs)); pgls->g.have_first_moveto = false; return 0; @@ -342,14 +450,26 @@ hpgl_close_current_path(hpgl_state_t *pgls) return 0; } +/* converts pcl coordinate to device space and back to hpgl space */ +int +hpgl_add_pcl_point_to_path(hpgl_state_t *pgls, gs_point *pcl_pt) +{ + gs_point dev_pt, hpgl_pt; + hpgl_call(hpgl_clear_current_path(pgls)); + pcl_set_ctm(pgls, false); + hpgl_call(gs_transform(pgls->pgs, pcl_pt->x, pcl_pt->y, &dev_pt)); + hpgl_call(hpgl_set_ctm(pgls)); + hpgl_call(gs_itransform(pgls->pgs, dev_pt.x, dev_pt.y, &hpgl_pt)); + hpgl_call(hpgl_add_point_to_path(pgls, hpgl_pt.x, hpgl_pt.y, gs_moveto)); + return 0; +} int hpgl_add_arc_to_path(hpgl_state_t *pgls, floatp center_x, floatp center_y, floatp radius, floatp start_angle, floatp sweep_angle, floatp chord_angle) { int num_chords= - hpgl_compute_number_of_chords(sweep_angle * (180.0 / M_PI), - chord_angle); + hpgl_compute_number_of_chords(sweep_angle, chord_angle); floatp start_angle_radians = start_angle * (M_PI/180.0); floatp chord_angle_radians = chord_angle * (M_PI/180.0); int i; @@ -373,9 +493,6 @@ hpgl_add_arc_to_path(hpgl_state_t *pgls, floatp center_x, floatp center_y, ((pgls->g.pen_down) ? gs_lineto : gs_moveto))); } - - hpgl_call(hpgl_set_current_position(pgls, (gs_point *)NULL)); - return 0; } @@ -388,11 +505,31 @@ hpgl_add_bezier_to_path(hpgl_state_t *pgls, floatp x1, floatp y1, /* HAS we may need to flatten this here */ hpgl_call(gs_curveto(pgls->pgs, x2, y2, x3, y3, x4, y4)); /* set the state position */ - hpgl_call(hpgl_set_current_position(pgls, (gs_point *)NULL)); - + { + gs_point last_point; + last_point.x = x4; + last_point.y = y4; + hpgl_call(hpgl_set_current_position(pgls, (gs_point *)&last_point)); + } return 0; } +/* an implicit gl/2 style closepath. If the first and last point are + the same the path gets closed */ +private int +hpgl_close_path(hpgl_state_t *pgls) +{ + gs_point last_point; + hpgl_call(hpgl_get_current_position(pgls, &last_point)); + + if ( (pgls->g.first_point.x == last_point.x) && + (pgls->g.first_point.y == last_point.y) ) + hpgl_call(gs_closepath(pgls->pgs)); + + return 0; +} + + /* HAS -- There will need to be compression phase here note that extraneous PU's do not result in separate subpaths. */ @@ -401,34 +538,23 @@ hpgl_add_bezier_to_path(hpgl_state_t *pgls, floatp x1, floatp y1, int hpgl_draw_current_path(hpgl_state_t *pgls, hpgl_rendering_mode_t render_mode) { - gs_point pt; + if ( !pgls->g.have_first_moveto ) return 0; - if ( !pgls->g.have_path ) return 0; - - /* get current point */ - hpgl_call(gs_currentpoint(pgls->pgs, &pt)); - - /* If the first point is coincident with the final point the - path is closed implicitly. HAS -- add epsilon */ - - if ( (pt.x == pgls->g.first_point.x) && - (pt.y == pgls->g.first_point.y) ) - { - hpgl_call(gs_closepath(pgls->pgs)); - } + hpgl_call(hpgl_close_path(pgls)); hpgl_call(hpgl_set_graphics_state(pgls, render_mode)); - /* HAS - yes they are exclusive but the hpgl_call macro is - kooky about "else" right now */ + /* we reset the ctm before stroking to preserve the line width + information */ + hpgl_call(hpgl_set_plu_to_device_ctm(pgls)); + + /* we fill polygons and stroke in character and vector mode */ if ( render_mode == hpgl_rm_polygon ) hpgl_call(gs_fill(pgls->pgs)); - - if ( (render_mode == hpgl_rm_vector) || (render_mode == hpgl_rm_character) ) + else hpgl_call(gs_stroke(pgls->pgs)); pgls->g.have_first_moveto = false; - pgls->g.have_path = false; /* the page has been marked */ pgls->have_page = true; return 0; @@ -443,11 +569,7 @@ hpgl_draw_line(hpgl_state_t *pgls, floatp x1, floatp y1, floatp x2, floatp y2) hpgl_call(hpgl_add_point_to_path(pgls, x2, y2, ((pgls->g.pen_down) ? gs_lineto : gs_moveto))); - - hpgl_call(hpgl_set_current_position(pgls, (gs_point *)NULL)); - hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); - return 0; } @@ -457,7 +579,6 @@ hpgl_draw_dot(hpgl_state_t *pgls, floatp x1, floatp y1) hpgl_call(hpgl_add_point_to_path(pgls, x1, y1, ((pgls->g.pen_down) ? gs_lineto : gs_moveto))); - hpgl_call(hpgl_set_current_position(pgls, (gs_point *)NULL)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); return 0; diff --git a/pcl/pgdraw.h b/pcl/pgdraw.h index bdef9b9ff..b0d901197 100644 --- a/pcl/pgdraw.h +++ b/pcl/pgdraw.h @@ -8,8 +8,9 @@ #ifndef pgdraw_INCLUDED # define pgdraw_INCLUDED -/* function to set the gl's current position -- point derived from gs - using gs_currentpoint. */ +/* function to get and set the current hpgl/2 state position */ +int hpgl_get_current_position(P2(hpgl_state_t *pgls, gs_point *pt)); + int hpgl_set_current_position(P2(hpgl_state_t *pgls, gs_point *pt)); /* puts a point into the path using the operation specified by @@ -48,8 +49,10 @@ int hpgl_clear_current_path(P1(hpgl_state_t *pgls)); /* closes the current path, making the first point and last point coincident */ int hpgl_close_current_path(P1(hpgl_state_t *pgls)); +/* adds a pcl point to the current path */ +int hpgl_add_pcl_point_to_path(P2(hpgl_state_t *pgls, gs_point *pcl_point)); + /* initialize the path machinery */ -#define hpgl_init_path(state) ((state)->g.have_path = false) +#define hpgl_init_path(state) ((state)->g.have_first_moveto = false) #endif /* pgdraw_INCLUDED */ - diff --git a/pcl/pgframe.c b/pcl/pgframe.c index a2f800271..7ed50960a 100644 --- a/pcl/pgframe.c +++ b/pcl/pgframe.c @@ -4,7 +4,6 @@ /* pgframe.c */ /* PCL5/HP-GL/2 picture frame commands */ -#include "std.h" #include "math_.h" #include "pgmand.h" #include "pgdraw.h" @@ -64,8 +63,7 @@ pcl_vert_pic_frame_size_decipoints(pcl_args_t *pargs, pcl_state_t *pcls) /* default to pcl logical page */ if ( almost_equal(size, 0.0) ) - pcls->g.picture_frame.height = pcls->text_length * - (float)(pcls->vmi / 48.0); + pcls->g.picture_frame.height = pcls->text_length * (float)(pcls->vmi); else pcls->g.picture_frame.height = size; diff --git a/pcl/pgmand.h b/pcl/pgmand.h index b2c9eace5..0584093fc 100644 --- a/pcl/pgmand.h +++ b/pcl/pgmand.h @@ -7,8 +7,8 @@ #ifndef pgmand_INCLUDED # define pgmand_INCLUDED -#include <setjmp.h> #include "stdio_.h" /* for gdebug.h */ +#include <setjmp.h> /* must come after std.h */ #include "gdebug.h" #include "pcommand.h" #include "pcstate.h" diff --git a/pcl/pgmisc.c b/pcl/pgmisc.c index e2c207a6d..d405ea264 100644 --- a/pcl/pgmisc.c +++ b/pcl/pgmisc.c @@ -13,13 +13,16 @@ hpgl_set_lost_mode(hpgl_state_t *pgls, hpgl_lost_mode_t lost_mode) { if ( lost_mode == hpgl_lost_mode_entered ) { +#ifdef INFINITE_LOOP hpgl_args_t args; /* raise the pen. Note this should handle the pcl oddity that when lost mode is cleared with an absolute PD we draw a line from the last valid position to the first - args of pen down. */ + args of pen down. The following appends a moveto the + current point in the gs path */ hpgl_args_setup(&args); hpgl_PU(&args, pgls); +#endif #ifdef DEBUG dprintf("entering lost mode\n"); #endif diff --git a/pcl/pgmisc.h b/pcl/pgmisc.h index ef4c3fd94..046b76d80 100644 --- a/pcl/pgmisc.h +++ b/pcl/pgmisc.h @@ -8,74 +8,67 @@ #ifndef pgmisc_INCLUDED # define pgmisc_INCLUDED -extern void hpgl_set_lost_mode(hpgl_state_t *pgls, hpgl_lost_mode_t lost_mode); +extern void hpgl_set_lost_mode(P2(hpgl_state_t *pgls, hpgl_lost_mode_t lost_mode)); + +/* macro to see if we are in lost mode */ +#define hpgl_lost (pgls->g.lost_mode == hpgl_lost_mode_entered) /* a macro that calls a function and returns an error code if the code returned is less than 0. Most of the hpgl and gs functions return if the calling function is less than 0 so this avoids cluttering up - the code with the if statement and debug code. HAS The current - function name is gcc specific. HAS this is getting a bit bloated!! */ + the code with the if statement and debug code. */ #ifdef DEBUG -extern void hpgl_error(void); -#define hpgl_call(call) \ -{ \ +extern void hpgl_error(P0()); + +# ifdef __GNUC__ +# define hpgl_call_note_error()\ + dprintf4("hpgl call failed\n\tcalled from: %s\n\tfile: %s\n\tline: %d\n\terror code: %d\n",\ + __FUNCTION__, __FILE__, __LINE__, code);\ + hpgl_error(); +# else +# define hpgl_call_note_error()\ + dprintf3("hpgl call failed\n\tcalled from:\n\tfile: %s\n\tline: %d\n\terror code: %d\n",\ + __FILE__, __LINE__, code);\ + hpgl_error(); +# endif + +#else /* !DEBUG */ + +#define hpgl_call_note_error() /* */ + +#endif + +/* We use the do ... while(0) in order to make the call be a statement */ +/* syntactically. */ + +#define hpgl_call_and_check(call, if_check_else)\ +do { \ int code; \ - if ((code = (call)) != 0) \ - { \ - dprintf4("hpgl call failed\n\tcalled from: %s\n\tfile: %s\n\tline: %d\n\terror code: %d\n", \ - __FUNCTION__, __FILE__, __LINE__, code); \ - hpgl_error(); \ - return(code); \ - } \ -} -#else -#define hpgl_call(call) \ -{ \ - int code; \ if ((code = (call)) < 0) \ - { \ - return(code); \ + { if_check_else() \ + { hpgl_call_note_error(); \ + return(code); \ + } \ } \ -} -#endif +} while (0) -/* yet another macro for function calls that can set lost mode. */ +/* Ordinary function calls */ -#ifdef DEBUG -extern void hpgl_error(void); +#define hpgl_no_check() /* */ -#define hpgl_call_check_lost(call) \ -{ \ - int code; \ - if ( (code = (call)) != 0 ) \ - { \ - if ( code == gs_error_limitcheck ) \ - { \ - hpgl_set_lost_mode(pgls, hpgl_lost_mode_entered); \ - } \ - else { \ - dprintf4("hpgl call failed\n\tcalled from: %s\n\tfile: %s\n\tline: %d\n\terror code: %d\n", \ - __FUNCTION__, __FILE__, __LINE__, code); \ - hpgl_error(); \ - return(code); \ - } \ - } \ -} -#else -#define hpgl_call_check_lost(call) \ -{ \ - int code; \ - if ((code = (call)) < 0) \ - { \ - if ( code == gs_error_limitcheck ) \ - hpgl_set_lost_mode(pgls, hpgl_lost_mode_entered); \ - else {printf("henry");return(code);} \ - } \ -} -#endif +#define hpgl_call(call)\ + hpgl_call_and_check(call, hpgl_no_check) + +/* Function calls that can set LOST mode */ +#define hpgl_limitcheck_set_lost()\ + if ( code == gs_error_limitcheck )\ + hpgl_set_lost_mode(pgls, hpgl_lost_mode_entered);\ + else +#define hpgl_call_check_lost(call)\ + hpgl_call_and_check(call, hpgl_limitcheck_set_lost) #endif /* pgmisc_INCLUDED */ diff --git a/pcl/pgpoly.c b/pcl/pgpoly.c index c8bcf690f..349b470bc 100644 --- a/pcl/pgpoly.c +++ b/pcl/pgpoly.c @@ -125,10 +125,11 @@ int hpgl_EA(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_rectangle(pargs, pgls, DO_EDGE)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -136,9 +137,10 @@ hpgl_EA(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_EP(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -146,10 +148,11 @@ hpgl_EP(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_ER(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_rectangle(pargs, pgls, DO_RELATIVE)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -157,10 +160,11 @@ hpgl_ER(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_EW(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_wedge(pargs, pgls)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -220,10 +224,11 @@ hpgl_PM(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_RA(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_rectangle(pargs, pgls, 0)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_polygon)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -231,10 +236,11 @@ hpgl_RA(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_RR(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_rectangle(pargs, pgls, DO_RELATIVE)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_polygon)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } @@ -242,10 +248,11 @@ hpgl_RR(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_WG(hpgl_args_t *pargs, hpgl_state_t *pgls) { - hpgl_save_pen_state(pgls); + hpgl_pen_state_t saved_pen_state; + hpgl_save_pen_state(pgls, &saved_pen_state, hpgl_pen_all); hpgl_call(hpgl_wedge(pargs, pgls)); hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_polygon)); - hpgl_restore_pen_state(pgls); + hpgl_restore_pen_state(pgls, &saved_pen_state, hpgl_pen_all); return 0; } diff --git a/pcl/pgstate.h b/pcl/pgstate.h index c8b6f61b0..1c84256bc 100644 --- a/pcl/pgstate.h +++ b/pcl/pgstate.h @@ -28,7 +28,7 @@ typedef struct hpgl_line_type_s { typedef enum { hpgl_rm_vector, hpgl_rm_character, - hpgl_rm_polygon + hpgl_rm_polygon, } hpgl_rendering_mode_t; /* state of lost mode */ @@ -77,15 +77,10 @@ typedef struct pcl_hpgl_state_s { bool pen_down; bool have_first_moveto; - bool last_pen_down; /* previous state of pen */ bool relative; /* true if relative coordinates */ - bool last_relative; /* previous relative state of pen */ gs_point pos; - gs_point last_pos; /* used to track the line drawing state in hpgl */ gs_point first_point; - bool have_path; - /* Chapter 21 (pgpoly.c) */ /**** polygon buffer ****/ @@ -185,6 +180,7 @@ typedef struct pcl_hpgl_state_s { bool transparent_data; uint font_id[2]; bool bitmap_fonts_allowed; + gs_point carriage_return_pos; /* Chapter C7 (pgcolor.c) */ @@ -195,37 +191,37 @@ typedef struct pcl_hpgl_state_s { hpgl_rendering_mode_t current_render_mode; /* HAS revisit */ } pcl_hpgl_state_t; - -/* HAS this can be done better, either the state should be saved in - local variables or a stack should be used. The difficulty with - this state arrangement is it does not support nested saves */ -#define hpgl_save_pen_relative_state(pgls) \ - ((pgls)->g.last_relative = (pgls)->g.relative) - -#define hpgl_restore_pen_relative_state(pgls) \ - ((pgls)->g.relative = (pgls)->g.last_relative) - -#define hpgl_save_pen_down_state(pgls) \ - ((pgls)->g.last_pen_down = (pgls)->g.pen_down) - -#define hpgl_restore_pen_down_state(pgls) \ - ((pgls)->g.pen_down = (pgls)->g.last_pen_down) - -/* HAS requires structure copy on assingment */ -#define hpgl_save_pen_position(pgls) \ - ((pgls)->g.last_pos = (pgls)->g.pos) - -#define hpgl_restore_pen_position(pgls) \ - ((pgls)->g.pos = (pgls)->g.last_pos) - -#define hpgl_save_pen_state(pgls) \ - (hpgl_save_pen_down_state(pgls), \ - hpgl_save_pen_position(pgls), \ - hpgl_save_pen_relative_state(pgls)) - -#define hpgl_restore_pen_state(pgls) \ - (hpgl_restore_pen_down_state(pgls), \ - hpgl_restore_pen_position(pgls), \ - hpgl_restore_pen_relative_state(pgls)) - +/* HAS: note don't mix and match save a restores. peharps there + should be a type check field in the structure. */ +typedef struct hpgl_pen_state_s { + bool relative; + bool pen_down; + gs_point pos; +} hpgl_pen_state_t; + +#define hpgl_pen_relative (1) +#define hpgl_pen_down (1<<1) +#define hpgl_pen_pos (1<<2) +#define hpgl_pen_all (hpgl_pen_relative | hpgl_pen_down | hpgl_pen_pos) + +/* HAS we may wish to make these functions to save on code space */ +#define hpgl_save_pen_state(pgls, save, save_flags)\ +do {\ + if ( (save_flags) & hpgl_pen_relative )\ + ((save)->relative = (pgls)->g.relative);\ + if ( (save_flags) & hpgl_pen_down )\ + ((save)->pen_down = (pgls)->g.pen_down);\ + if ( (save_flags) & hpgl_pen_pos )\ + ((save)->pos = (pgls)->g.pos);\ +} while (0) + +#define hpgl_restore_pen_state(pgls, save, restore_flags)\ +do {\ + if ( (restore_flags) & hpgl_pen_relative )\ + ((pgls)->g.relative = (save)->relative);\ + if ( (restore_flags) & hpgl_pen_down )\ + ((pgls)->g.pen_down = (save)->pen_down);\ + if ( (restore_flags) & hpgl_pen_pos )\ + ((pgls)->g.pos = (save)->pos);\ +} while (0) #endif /* pgstate_INCLUDED */ diff --git a/pcl/pgvector.c b/pcl/pgvector.c index 4e3a7975f..3f64c1b49 100644 --- a/pcl/pgvector.c +++ b/pcl/pgvector.c @@ -32,6 +32,8 @@ hpgl_arc(hpgl_args_t *pargs, hpgl_state_t *pgls, bool relative) hpgl_arg_c_real(pargs, &chord_angle); + hpgl_call(hpgl_draw_current_path(pgls, hpgl_rm_vector)); + x_current = pgls->g.pos.x; y_current = pgls->g.pos.y; @@ -50,8 +52,7 @@ hpgl_arc(hpgl_args_t *pargs, hpgl_state_t *pgls, bool relative) hpgl_add_arc_to_path(pgls, x_center, y_center, radius, start_angle, sweep, chord_angle); - /* HAS check this */ - /* hpgl_draw_current_path(pgls, hpgl_rm_vector); */ + hpgl_draw_current_path(pgls, hpgl_rm_vector); return 0; } @@ -203,8 +204,8 @@ hpgl_plot_and_clear(hpgl_state_t *pgls, floatp x, floatp y, int (*gs_func)(gs_state *pgs, floatp x, floatp y)) { int ret = hpgl_add_point_to_path(pgls, x, y, gs_func); - if (( !pgls->g.relative ) && - ( ret != gs_error_limitcheck )) + if ( (!pgls->g.relative) && + (ret != gs_error_limitcheck) ) hpgl_set_lost_mode(pgls, hpgl_lost_mode_cleared); return ret; @@ -237,10 +238,18 @@ hpgl_plot(hpgl_args_t *pargs, hpgl_state_t *pgls, /* no argument case */ if ( !got_args) { - gs_point cur_point; - hpgl_call(gs_currentpoint(pgls->pgs, &cur_point)); - hpgl_call(hpgl_plot_and_clear(pgls, cur_point.x, + /* HAS needs investigation -- NO ARGS case in relative mode */ + if (pgls->g.relative) + { + hpgl_call(hpgl_plot_and_clear(pgls, 0.0, 0.0, gs_func)); + } + else + { + gs_point cur_point; + hpgl_call(hpgl_get_current_position(pgls, &cur_point)); + hpgl_call(hpgl_plot_and_clear(pgls, cur_point.x, cur_point.y, gs_func)); + } } /* set the current state position */ @@ -290,8 +299,16 @@ hpgl_CI(hpgl_args_t *pargs, hpgl_state_t *pgls) { hpgl_args_t args; bool down = pgls->g.pen_down; + + hpgl_clear_current_path(pgls); + /* implicit pen down */ - hpgl_args_setup(&args); hpgl_PD(&args, pgls); + hpgl_args_setup(&args); + hpgl_PU(&args, pgls); + + hpgl_args_setup(&args); + hpgl_PD(&args, pgls); + /* draw the arc/circle */ hpgl_add_arc_to_path(pgls, pgls->g.pos.x, pgls->g.pos.y, radius, 0.0, 360.0, chord); @@ -312,15 +329,11 @@ hpgl_CI(hpgl_args_t *pargs, hpgl_state_t *pgls) int hpgl_PA(hpgl_args_t *pargs, hpgl_state_t *pgls) { - /* plot the point and save the return value */ - int ret = hpgl_plot(pargs, pgls, - (pgls->g.pen_down) ? gs_lineto : gs_moveto); - /* set the state flag */ pgls->g.relative = false; - - - return ret; + /* plot the point and save the return value */ + return hpgl_plot(pargs, pgls, + (pgls->g.pen_down) ? gs_lineto : gs_moveto); } /* PD (d)x,(d)y...; */ @@ -328,7 +341,8 @@ int hpgl_PD(hpgl_args_t *pargs, hpgl_state_t *pgls) { pgls->g.pen_down = true; - return hpgl_plot(pargs, pgls, (pgls->g.relative) ? gs_rlineto : gs_lineto); + return hpgl_plot(pargs, pgls, + (pgls->g.relative) ? gs_rlineto : gs_lineto); } /* PE (flag|value|coord)*; */ @@ -371,7 +385,7 @@ hpgl_PE(hpgl_args_t *pargs, hpgl_state_t *pgls) hpgl_args_set_int(&args, pen); /* Note SP is illegal in polygon mode we must handle that here */ if ( !pgls->g.polygon_mode ) - hpgl_call(hpgl_SP(&args, pgls)) + hpgl_call(hpgl_SP(&args, pgls)); } } p = pargs->source.ptr; @@ -430,18 +444,18 @@ hpgl_PE(hpgl_args_t *pargs, hpgl_state_t *pgls) /* set up the up and down state */ hpgl_args_setup(&args); if ( pargs->phase & pe_pen_up ) - hpgl_call(hpgl_PU(&args, pgls)) + hpgl_call(hpgl_PU(&args, pgls)); else - hpgl_call(hpgl_PD(&args, pgls)) + hpgl_call(hpgl_PD(&args, pgls)); hpgl_args_set_real(&args, (floatp)xy[0]); hpgl_args_add_real(&args, (floatp)xy[1]); /* arbitrarily use PA or PR */ if ( pargs->phase & pe_absolute ) - hpgl_call(hpgl_PA(&args, pgls)) + hpgl_call(hpgl_PA(&args, pgls)); else - hpgl_call(hpgl_PR(&args, pgls)) + hpgl_call(hpgl_PR(&args, pgls)); } } pargs->phase &= ~(pe_pen_up | pe_absolute); diff --git a/pcl/rtcolor.c b/pcl/rtcolor.c index 8c12529c5..4df2c2280 100644 --- a/pcl/rtcolor.c +++ b/pcl/rtcolor.c @@ -12,14 +12,17 @@ /* ---------------- Chapter 2 ---------------- */ /* Define the simple color palettes. */ +/****** ALL THESE VALUES SHOULD BE pcl_fixed. ******/ private const int32 palette_simple_CMY[8*3] = -{ +{ 0xff,0xff,0xff, 0,0xff,0xff, 0xff,0,0xff, 0,0,0xff, + 0xff,0xff,0, 0,0xff,0, 0xff,0,0, 0,0,0 }; -private const int32 palette_simple_K[1*3] = -{ +private const int32 palette_simple_K[2*3] = +{ 0xff,0xff,0xff, 0,0,0 }; private const int32 palette_simple_RGB[8*3] = -{ +{ 0,0,0, 0xff,0,0, 0,0xff,0, 0xff,0xff,0, + 0,0,0xff, 0xff,0,0xff, 0,0xff,0xff, 0xff,0xff,0xff }; private int /* ESC * r <cs_enum> U */ @@ -49,6 +52,7 @@ pal3: psize = 8; return e_Range; } /**** DESTROY OLD pcls->palette.data ****/ + /****** const MISMATCH ******/ pcls->palette.data = pdata; pcls->palette.size = psize; return 0; diff --git a/pcl/rtmisc.c b/pcl/rtmisc.c index 3db510403..f1455b844 100644 --- a/pcl/rtmisc.c +++ b/pcl/rtmisc.c @@ -8,7 +8,7 @@ #include "gsmemory.h" #include "pgmand.h" #include "gsrop.h" - +#include "pgdraw.h" /* for hpgl_add_pcl_point_to_path() */ /* ---------------- Chapter 4 ---------------- */ /* Import the table of pointers to initialization data. */ @@ -67,6 +67,14 @@ rtl_enter_hpgl_mode(pcl_args_t *pargs, pcl_state_t *pcls) return_error(e_Memory); hpgl_process_init(pcls->parse_data); pcls->parse_other = hpgl_process; + /* add the pcl cap to hpgl/2's path */ + if ( i == 1 ) + { + gs_point pcl_pt; + pcl_pt.x = (hpgl_real_t)pcls->cap.x; + pcl_pt.y = (hpgl_real_t)pcls->cap.y; + hpgl_add_pcl_point_to_path(pcls, &pcl_pt); + } return 0; } diff --git a/pcl/rtraster.c b/pcl/rtraster.c index c4cf0b1a9..cda0577b8 100644 --- a/pcl/rtraster.c +++ b/pcl/rtraster.c @@ -281,15 +281,18 @@ pcl_begin_raster_graphics(pcl_state_t *pcls, int setting) { gs_point cap_dev, cap_image; /* Convert CAP to device coordinates, since it mustn't move. */ + pcl_set_graphics_state(pcls, true); /* with print direction */ gs_transform(pcls->pgs, (float)pcls->cap.x, (float)pcls->cap.y, &cap_dev); - pcl_set_graphics_state(pcls, false); /* false => ignore print direction */ + pcl_set_graphics_state(pcls, false); /* ignore print direction */ if ( across ) /* across_physical_page & landscape */ gs_rotate(pcls->pgs, -90.0); gs_itransform(pcls->pgs, cap_dev.x, cap_dev.y, &cap_image); pcls->cap.x = (coord)cap_image.x; pcls->cap.y = (coord)cap_image.y; } + else + pcl_set_graphics_state(pcls, false); /* ignore print direction */ /* See PCL5 manual, p. 15-10, for the following algorithm. */ if ( !(setting & 1 ) ) { if ( across ) @@ -612,7 +615,7 @@ end_raster_graphics(pcl_state_t *pcls) /* Convert CAP to device coordinates, since it mustn't move. */ gs_transform(pcls->pgs, (float)pcls->cap.x, (float)pcls->cap.y, &cap_dev); - pcl_set_graphics_state(pcls, true); /* false => ignore print direction */ + pcl_set_graphics_state(pcls, true); /* with print direction */ gs_itransform(pcls->pgs, cap_dev.x, cap_dev.y, &cap_image); pcls->cap.x = (coord)cap_image.x; pcls->cap.y = (coord)cap_image.y; |