123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "h_roman8.h"
- #define SHIFT_OUT 14
- #define SHIFT_IN 15
- typedef enum { LOWER_HALF, UPPER_HALF } state_type;
- #define HP_ROMAN_8_MINUS_CHAR 0366
- double
- _pl_h_paint_text_string (R___(Plotter *_plotter) const unsigned char *s, int h_just, int v_just)
- {
- bool created_temp_string = false;
- bool reencode_iso_as_roman8 = false;
- double hp_offset;
- double theta, costheta, sintheta;
- int master_font_index;
- unsigned char *t;
- unsigned char instruction_buf[4];
-
-
- if (*s == (unsigned char)'\0')
- return 0.0;
-
- if (v_just != PL_JUST_BASE || h_just != PL_JUST_LEFT)
- return 0.0;
-
- #ifndef USE_PS_FONTS_IN_PCL
- if (_plotter->drawstate->font_type != PL_F_PCL
- && _plotter->drawstate->font_type != PL_F_STICK)
- return 0.0;
- #else
- if (_plotter->drawstate->font_type != PL_F_POSTSCRIPT
- && _plotter->drawstate->font_type != PL_F_PCL
- && _plotter->drawstate->font_type != PL_F_STICK)
- return 0.0;
- #endif
-
- if (_plotter->drawstate->true_font_size == 0.0)
- return 0.0;
-
- if (_plotter->hpgl_p1.x == _plotter->hpgl_p2.x
- || _plotter->hpgl_p1.y == _plotter->hpgl_p2.y)
- return _plotter->get_text_width (R___(_plotter) s);
-
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_PCL:
- default:
- master_font_index =
- (_pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_POSTSCRIPT:
- master_font_index =
- (_pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_STICK:
- master_font_index =
- (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- }
-
- theta = M_PI * _plotter->drawstate->text_rotation / 180.0;
- sintheta = sin (theta);
- costheta = cos (theta);
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_PCL:
- default:
- if (_pl_g_pcl_font_info[master_font_index].hpgl_symbol_set == PCL_ROMAN_8
- && _pl_g_pcl_font_info[master_font_index].iso8859_1)
-
- {
- state_type dfa_state = LOWER_HALF;
- unsigned const char *sptr = s;
- unsigned char *tptr;
-
- t = (unsigned char *)_pl_xmalloc (3 * strlen ((const char *)s) + 1);
- tptr = t;
- created_temp_string = true;
-
- while (*sptr)
- {
- unsigned char c;
- c = *sptr++;
- if (c < 0x80)
-
- {
- if (c == '-')
- c = HP_ROMAN_8_MINUS_CHAR;
- if (dfa_state == UPPER_HALF)
- {
- *tptr++ = SHIFT_IN;
- dfa_state = LOWER_HALF;
- }
- *tptr++ = c;
- }
- else
-
- {
- if (dfa_state == LOWER_HALF)
- {
- *tptr++ = SHIFT_OUT;
- dfa_state = UPPER_HALF;
- }
- *tptr++ = c;
- }
- }
-
- if (dfa_state == UPPER_HALF)
- *tptr++ = SHIFT_IN;
- *tptr = '\0';
- }
- else
-
- t = (unsigned char *)s;
- break;
- case PL_F_POSTSCRIPT:
-
- t = (unsigned char *)s;
- break;
- case PL_F_STICK:
- if (_pl_g_stick_font_info[master_font_index].hpgl_symbol_set == PCL_ROMAN_8
- && _pl_g_stick_font_info[master_font_index].iso8859_1)
-
- reencode_iso_as_roman8 = true;
- if (_plotter->hpgl_version <= 1)
-
- {
- bool bogus_upper_half = false;
- state_type dfa_state = LOWER_HALF;
- unsigned const char *sptr = s;
- unsigned char *tptr;
-
- if (_pl_g_stick_font_info[master_font_index].hpgl_charset_upper < 0)
- bogus_upper_half = true;
-
- t = (unsigned char *)_pl_xmalloc (3 * strlen ((const char *)s) + 1);
- tptr = t;
- created_temp_string = true;
-
-
- while (*sptr)
- {
- unsigned char c;
- c = *sptr++;
- if (c >= 0x80 && reencode_iso_as_roman8)
-
- c = iso_to_roman8[c - 0x80];
- if (c < 0x80)
-
- {
- if (dfa_state == UPPER_HALF)
- {
- *tptr++ = SHIFT_IN;
- dfa_state = LOWER_HALF;
- }
- *tptr++ = c;
- }
- else
-
- if (bogus_upper_half == false)
- {
- if (dfa_state == LOWER_HALF)
- {
- *tptr++ = SHIFT_OUT;
- dfa_state = UPPER_HALF;
- }
- *tptr++ = c - 0x80;
- }
- }
-
-
- if (dfa_state == UPPER_HALF)
- *tptr++ = SHIFT_IN;
- *tptr = '\0';
- }
- else
-
- {
- unsigned const char *sptr = s;
- unsigned char *tptr;
-
- t = (unsigned char *)_pl_xmalloc (strlen ((const char *)s) + 1);
- tptr = t;
- created_temp_string = true;
- while (*sptr)
- {
- if (*sptr < 0x80)
- *tptr++ = *sptr++;
- else
- {
- if (reencode_iso_as_roman8)
-
- *tptr++ = iso_to_roman8[(*sptr++) - 0x80];
- else
- *tptr++ = *sptr++;
- }
- }
- *tptr = '\0';
- }
- break;
- }
-
-
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_PCL:
- default:
-
- hp_offset = _pl_g_pcl_font_info[master_font_index].offset[*((unsigned char *)s)] / 1000.0;
- break;
- case PL_F_POSTSCRIPT:
-
- hp_offset = _pl_g_ps_font_info[master_font_index].offset[*((unsigned char *)s)] / 1000.0;
- break;
- case PL_F_STICK:
-
-
- hp_offset = (((double)(_pl_g_stick_font_info[master_font_index].offset)) /
- (2.0 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- break;
- }
-
- _plotter->drawstate->pos.x +=
- costheta * _plotter->drawstate->true_font_size * hp_offset;
- _plotter->drawstate->pos.y +=
- sintheta * _plotter->drawstate->true_font_size * hp_offset;
-
- _pl_h_set_font (S___(_plotter));
- _pl_h_set_position (S___(_plotter));
-
- _pl_h_set_pen_color (R___(_plotter) HPGL_OBJECT_LABEL);
- if (t[0] != '\0'
- && _plotter->hpgl_bad_pen == false)
-
- {
- strcpy (_plotter->data->page->point, "LB");
- _update_buffer (_plotter->data->page);
- strcpy (_plotter->data->page->point, (const char *)t);
- _update_buffer (_plotter->data->page);
- instruction_buf[0] = (unsigned char)3;
- instruction_buf[1] = ';';
- instruction_buf[2] = '\0';
- strcpy (_plotter->data->page->point, (const char *)instruction_buf);
- _update_buffer (_plotter->data->page);
-
- _plotter->hpgl_position_is_unknown = true;
- }
- if (created_temp_string)
-
- free (t);
-
- _plotter->drawstate->pos.x -=
- costheta * _plotter->drawstate->true_font_size * hp_offset;
- _plotter->drawstate->pos.y -=
- sintheta * _plotter->drawstate->true_font_size * hp_offset;
- return _plotter->get_text_width (R___(_plotter) s);
- }
|