123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "g_control.h"
- #define SCRIPTSIZE 0.6
- #define SUBSCRIPT_DX 0.0
- #define SUBSCRIPT_DY (-0.2)
- #define SUPERSCRIPT_DX 0.0
- #define SUPERSCRIPT_DY 0.375
- #define SYMBOL_FONT "Symbol"
- #define ARCMATH 8
- #define STICKMATH 17
- #define IS_MATH_FONT(fontnum) ((fontnum) == ARCMATH || (fontnum) == STICKMATH)
- #define IS_CENTERED_SYMBOL(c) (((c) >= 'A' && (c) <= 'O') || (c) == 'e')
- /* forward references */
- static unsigned char *esc_esc_string (const unsigned char *s);
- static bool simple_string (const unsigned short *codestring);
- static bool clean_iso_string (unsigned char *s);
- /* The flabelwidth() and falabel() methods. After checking for control
- characters in the input string (not allowed), we invoke either a
- Hershey-specific or a non-Hershey-specific method. */
- int
- _API_alabel (R___(Plotter *_plotter) int x_justify, int y_justify, const char *s)
- {
- char *t;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "alabel: invalid operation");
- return -1;
- }
- _API_endpath (S___(_plotter));
- if (s == NULL)
- return 0;
-
- t = (char *)_pl_xmalloc (strlen (s) + 1);
- strcpy (t, s);
-
- {
- bool was_clean;
-
- was_clean = clean_iso_string ((unsigned char *)t);
- if (!was_clean)
- _plotter->warning (R___(_plotter)
- "ignoring control character (e.g. CR or LF) in label");
- }
-
-
- _pl_g_set_font (S___(_plotter));
- if (_plotter->data->have_escaped_string_support)
-
- _plotter->paint_text_string_with_escapes (R___(_plotter)
- (unsigned char *)t,
- x_justify, y_justify);
- else
-
- {
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
-
- _pl_g_alabel_hershey (R___(_plotter)
- (unsigned char *)t, x_justify, y_justify);
- else
-
- _pl_g_render_non_hershey_string (R___(_plotter)
- t, true, x_justify, y_justify);
- }
- free (t);
- return 0;
- }
- int
- _API_label (R___(Plotter *_plotter) const char *s)
- {
-
- return _API_alabel (R___(_plotter) 'l', 'x', s);
- }
- double
- _API_flabelwidth (R___(Plotter *_plotter) const char *s)
- {
- double width = 0.0;
- char *t;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "flabelwidth: invalid operation");
- return -1;
- }
- if (s == NULL)
- return 0.0;
-
- t = (char *)_pl_xmalloc (strlen (s) + 1);
- strcpy (t, s);
-
- {
- bool was_clean;
-
- was_clean = clean_iso_string ((unsigned char *)t);
- if (!was_clean)
- _plotter->warning (R___(_plotter)
- "ignoring control character (e.g. CR or LF) in label");
- }
-
-
- _pl_g_set_font (S___(_plotter));
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
-
- width = _pl_g_flabelwidth_hershey (R___(_plotter)
- (unsigned char *)t);
- else
-
- width = _pl_g_render_non_hershey_string (R___(_plotter)
- t, false, 'c', 'c');
- free (t);
- return width;
- }
- double
- _pl_g_render_non_hershey_string (R___(Plotter *_plotter) const char *s, bool do_render, int x_justify, int y_justify)
- {
- int h_just = PL_JUST_LEFT;
- int v_just = PL_JUST_BASE;
- unsigned short *codestring;
- unsigned short *cptr;
- double width = 0.0, added_width;
- double pushed_width = 0.0;
- int current_font_index;
-
- double initial_font_size;
- const char *initial_font_name;
- int initial_font_type;
-
- double initial_position_x = _plotter->drawstate->pos.x;
- double initial_position_y = _plotter->drawstate->pos.y;
- double pushed_position_x = _plotter->drawstate->pos.x;
- double pushed_position_y = _plotter->drawstate->pos.y;
-
- char x_justify_c, y_justify_c;
- double x_offset, y_offset;
- double x_displacement = 1.0, x_displacement_internal = 1.0;
- double overall_width = 0.0;
- double cap_height, ascent, descent;
- double userdx, userdy, theta, sintheta = 0.0, costheta = 1.0;
-
-
- codestring = _pl_g_controlify (R___(_plotter) (const unsigned char *)s);
- if (do_render)
- {
-
- overall_width = _pl_g_render_non_hershey_string (R___(_plotter)
- s, false, 'c', 'c');
-
-
- x_justify_c = (char)x_justify;
- y_justify_c = (char)y_justify;
- switch (x_justify_c)
- {
- case 'l':
- default:
- h_just = PL_JUST_LEFT;
- x_offset = 0.0;
- x_displacement = 1.0;
- x_displacement_internal = 1.0;
-
- break;
-
- case 'c':
- h_just = PL_JUST_CENTER;
- x_offset = -0.5;
- x_displacement = 0.0;
- x_displacement_internal = 0.0;
-
- break;
-
- case 'r':
- h_just = PL_JUST_RIGHT;
- x_offset = -1.0;
- x_displacement = -1.0;
- x_displacement_internal = -1.0;
-
- break;
- }
-
- cap_height = _plotter->drawstate->font_cap_height;
- ascent = _plotter->drawstate->font_ascent;
- descent = _plotter->drawstate->font_descent;
-
- switch (y_justify_c)
- {
- case 'b':
- v_just = PL_JUST_BOTTOM;
- y_offset = descent;
- break;
-
- case 'x':
- default:
- v_just = PL_JUST_BASE;
- y_offset = 0.0;
- break;
-
- case 'c':
- v_just = PL_JUST_HALF;
- y_offset = 0.5 * (descent - ascent);
- break;
-
- case 'C':
- v_just = PL_JUST_CAP;
- y_offset = - cap_height;
- break;
-
- case 't':
- v_just = PL_JUST_TOP;
- y_offset = - ascent;
- break;
- }
-
- if ((_plotter->drawstate->font_type == PL_F_HERSHEY
- || _plotter->data->have_horizontal_justification)
- && simple_string (codestring))
-
- x_offset = 0.0;
- else
-
- {
- h_just = PL_JUST_LEFT;
- x_displacement_internal = 1.0;
- }
-
-
- if ((_plotter->drawstate->font_type == PL_F_HERSHEY
- || _plotter->data->have_vertical_justification)
- && simple_string (codestring))
-
- y_offset = 0.0;
- else
-
- v_just = PL_JUST_BASE;
-
-
- userdx = x_offset * overall_width;
- userdy = y_offset;
-
-
- theta = M_PI * _plotter->drawstate->text_rotation / 180.0;
- sintheta = sin (theta);
- costheta = cos (theta);
-
- _plotter->drawstate->pos.x += costheta * userdx - sintheta * userdy;
- _plotter->drawstate->pos.y += sintheta * userdx + costheta * userdy;
- }
-
- {
- char *font_name;
-
- initial_font_name = _plotter->drawstate->font_name;
- font_name = (char *)_pl_xmalloc (1 + strlen (initial_font_name));
- strcpy (font_name, initial_font_name);
- _plotter->drawstate->font_name = font_name;
- }
-
- initial_font_size = _plotter->drawstate->font_size;
-
- initial_font_type = _plotter->drawstate->font_type;
-
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_HERSHEY:
- current_font_index =
- (_pl_g_hershey_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_POSTSCRIPT:
- current_font_index =
- (_pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_PCL:
- current_font_index =
- (_pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_STICK:
- current_font_index =
- (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
- break;
- case PL_F_OTHER:
- current_font_index = 1;
- break;
- default:
- return 0.0;
- }
-
- cptr = codestring;
- while (*cptr)
- {
- unsigned short c;
-
- c = *cptr;
- if (c & CONTROL_CODE)
-
- {
- switch (c & ~CONTROL_CODE)
- {
- case C_BEGIN_SUBSCRIPT:
- width += SUBSCRIPT_DX * _plotter->drawstate->true_font_size;
- if (do_render)
- {
- _plotter->drawstate->pos.x +=
- (costheta * SUBSCRIPT_DX - sintheta * SUBSCRIPT_DY)
- * _plotter->drawstate->true_font_size;
- _plotter->drawstate->pos.y +=
- (sintheta * SUBSCRIPT_DX + costheta * SUBSCRIPT_DY)
- * _plotter->drawstate->true_font_size;
- }
- _plotter->drawstate->font_size *= SCRIPTSIZE;
- _pl_g_set_font (S___(_plotter));
- break;
- case C_BEGIN_SUPERSCRIPT :
- width += SUPERSCRIPT_DX * _plotter->drawstate->true_font_size;
- if (do_render)
- {
- _plotter->drawstate->pos.x +=
- (costheta * SUPERSCRIPT_DX - sintheta * SUPERSCRIPT_DY)
- * _plotter->drawstate->true_font_size;
- _plotter->drawstate->pos.y +=
- (sintheta * SUPERSCRIPT_DX + costheta * SUPERSCRIPT_DY)
- * _plotter->drawstate->true_font_size;
- }
- _plotter->drawstate->font_size *= SCRIPTSIZE;
- _pl_g_set_font (S___(_plotter));
- break;
- case C_END_SUBSCRIPT:
- width -= SUBSCRIPT_DX * _plotter->drawstate->true_font_size;
- _plotter->drawstate->font_size /= SCRIPTSIZE;
- _pl_g_set_font (S___(_plotter));
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= (costheta * SUBSCRIPT_DX
- - sintheta * SUBSCRIPT_DY) * _plotter->drawstate->true_font_size;
- (_plotter->drawstate->pos).y -= (sintheta * SUBSCRIPT_DX
- + costheta * SUBSCRIPT_DY) * _plotter->drawstate->true_font_size;
- }
- break;
-
- case C_END_SUPERSCRIPT:
- width -= SUPERSCRIPT_DX * _plotter->drawstate->true_font_size;
- _plotter->drawstate->font_size /= SCRIPTSIZE;
- _pl_g_set_font (S___(_plotter));
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= (costheta * SUPERSCRIPT_DX
- - sintheta * SUPERSCRIPT_DY) * _plotter->drawstate->true_font_size;
- (_plotter->drawstate->pos).y -= (sintheta * SUPERSCRIPT_DX
- + costheta * SUPERSCRIPT_DY) * _plotter->drawstate->true_font_size;
- }
- break;
-
- case C_PUSH_LOCATION:
- pushed_position_x = _plotter->drawstate->pos.x;
- pushed_position_y = _plotter->drawstate->pos.y;
- pushed_width = width;
- break;
-
- case C_POP_LOCATION:
- if (do_render)
- {
- _plotter->drawstate->pos.x = pushed_position_x;
- _plotter->drawstate->pos.y = pushed_position_y;
- }
- width = pushed_width;
- break;
-
- case C_RIGHT_ONE_EM:
- if (do_render)
- {
- _plotter->drawstate->pos.x += costheta * _plotter->drawstate->true_font_size;
- _plotter->drawstate->pos.y += sintheta * _plotter->drawstate->true_font_size;
- }
- width += _plotter->drawstate->true_font_size;
- break;
-
- case C_RIGHT_HALF_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size / 2.0;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size / 2.0;
- }
-
- width += _plotter->drawstate->true_font_size / 2.0;
- break;
- case C_RIGHT_QUARTER_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size / 4.0;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size / 4.0;
- }
-
- width += _plotter->drawstate->true_font_size / 4.0;
- break;
- case C_RIGHT_SIXTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size / 6.0;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size / 6.0;
- }
-
- width += _plotter->drawstate->true_font_size / 6.0;
- break;
- case C_RIGHT_EIGHTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size / 8.0;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size / 8.0;
- }
-
- width += _plotter->drawstate->true_font_size / 8.0;
- break;
- case C_RIGHT_TWELFTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size / 12.0;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size / 12.0;
- }
-
- width += _plotter->drawstate->true_font_size / 8.0;
- break;
-
- case C_RIGHT_RADICAL_SHIFT:
- if (do_render)
- {
- if (_plotter->drawstate->font_type == PL_F_PCL)
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size * PCL_RADICAL_WIDTH;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size * PCL_RADICAL_WIDTH;
- }
- else
- {
- (_plotter->drawstate->pos).x += costheta * _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- (_plotter->drawstate->pos).y += sintheta * _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- }
-
- }
- width += _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- break;
- case C_LEFT_ONE_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size;
- }
-
- width -= _plotter->drawstate->true_font_size;
- break;
-
- case C_LEFT_HALF_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size / 2.0;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size / 2.0;
- }
-
- width -= _plotter->drawstate->true_font_size / 2.0;
- break;
- case C_LEFT_QUARTER_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size / 4.0;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size / 4.0;
- }
-
- width -= _plotter->drawstate->true_font_size / 4.0;
- break;
- case C_LEFT_SIXTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size / 6.0;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size / 6.0;
- }
-
- width -= _plotter->drawstate->true_font_size / 6.0;
- break;
- case C_LEFT_EIGHTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size / 8.0;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size / 8.0;
- }
-
- width -= _plotter->drawstate->true_font_size / 8.0;
- break;
- case C_LEFT_TWELFTH_EM:
- if (do_render)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size / 12.0;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size / 12.0;
- }
-
- width -= _plotter->drawstate->true_font_size / 8.0;
- break;
-
- case C_LEFT_RADICAL_SHIFT:
- if (do_render)
- {
- if (_plotter->drawstate->font_type == PL_F_PCL)
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size * PCL_RADICAL_WIDTH;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size * PCL_RADICAL_WIDTH;
- }
- else
- {
- (_plotter->drawstate->pos).x -= costheta * _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- (_plotter->drawstate->pos).y -= sintheta * _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- }
- }
-
- width -= _plotter->drawstate->true_font_size * PS_RADICAL_WIDTH;
- break;
-
-
- default:
- break;
- }
- cptr++;
- }
-
- else
- {
- unsigned char *s, *sptr;
- int new_font_index = (c >> FONT_SHIFT) & ONE_BYTE;
-
- if (new_font_index != current_font_index)
- {
-
- switch (initial_font_type)
- {
- case PL_F_HERSHEY:
- free ((char *)_plotter->drawstate->font_name);
- {
- char *font_name;
-
- font_name =
- (char *)_pl_xmalloc(1 + strlen (_pl_g_hershey_font_info[new_font_index].name));
- strcpy (font_name, _pl_g_hershey_font_info[new_font_index].name);
- _plotter->drawstate->font_name = font_name;
- }
- break;
- case PL_F_POSTSCRIPT:
- free ((char *)_plotter->drawstate->font_name);
- {
- char *font_name;
-
- font_name =
- (char *)_pl_xmalloc(1 + strlen (_pl_g_ps_font_info[new_font_index].ps_name));
- strcpy (font_name, _pl_g_ps_font_info[new_font_index].ps_name);
- _plotter->drawstate->font_name = font_name;
- }
- break;
- case PL_F_PCL:
- free ((char *)_plotter->drawstate->font_name);
- {
- char *font_name;
- font_name =
- (char *)_pl_xmalloc(1 + strlen (_pl_g_pcl_font_info[new_font_index].ps_name));
- strcpy (font_name, _pl_g_pcl_font_info[new_font_index].ps_name);
- _plotter->drawstate->font_name = font_name;
- }
- break;
- case PL_F_STICK:
- free ((char *)_plotter->drawstate->font_name);
- {
- char *font_name;
- font_name =
- (char *)_pl_xmalloc(1 + strlen (_pl_g_stick_font_info[new_font_index].ps_name));
- strcpy (font_name, _pl_g_stick_font_info[new_font_index].ps_name);
- _plotter->drawstate->font_name = font_name;
- }
- break;
- case PL_F_OTHER:
- free ((char *)_plotter->drawstate->font_name);
- {
- char *font_name;
- if (new_font_index == 0)
- {
- font_name =
- (char *)_pl_xmalloc(1 + strlen (SYMBOL_FONT));
- strcpy (font_name, SYMBOL_FONT);
- }
- else
-
- {
- font_name =
- (char *)_pl_xmalloc(1 + strlen (initial_font_name));
- strcpy (font_name, initial_font_name);
- }
- _plotter->drawstate->font_name = font_name;
- }
- break;
- default:
- break;
- }
- _pl_g_set_font (S___(_plotter));
- current_font_index = new_font_index;
- }
-
-
- sptr = s
- = (unsigned char *)_pl_xmalloc ((4 * _codestring_len (cptr) + 1) * sizeof(char));
- while (*cptr
- && (*cptr & CONTROL_CODE) == 0
- && ((*cptr >> FONT_SHIFT) & ONE_BYTE) == current_font_index)
- *sptr++ = (*cptr++) & ONE_BYTE;
- *sptr = (unsigned char)'\0';
-
- added_width = _pl_g_render_simple_string (R___(_plotter)
- s, do_render, h_just, v_just);
- width += added_width;
- if (do_render)
- {
-
- _plotter->drawstate->pos.x +=
- costheta * x_displacement_internal * added_width;
- _plotter->drawstate->pos.y +=
- sintheta * x_displacement_internal * added_width;
- }
- free (s);
- }
- }
-
- free (codestring);
-
- free ((char *)_plotter->drawstate->font_name);
- _plotter->drawstate->font_name = initial_font_name;
- _plotter->drawstate->font_size = initial_font_size;
- _pl_g_set_font (S___(_plotter));
-
- if (do_render)
- {
-
- _plotter->drawstate->pos.x = initial_position_x;
- _plotter->drawstate->pos.y = initial_position_y;
-
- _plotter->drawstate->pos.x += costheta * x_displacement * overall_width;
- _plotter->drawstate->pos.y += sintheta * x_displacement * overall_width;
- }
- return width;
- }
- double
- _pl_g_render_simple_string (R___(Plotter *_plotter) const unsigned char *s, bool do_render, int h_just, int v_just)
- {
- double width;
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
-
- {
- unsigned char *t;
-
- t = esc_esc_string (s);
- width = _pl_g_flabelwidth_hershey (R___(_plotter) t);
- if (do_render)
- {
- plPoint initial_pos;
- initial_pos = _plotter->drawstate->pos;
- _pl_g_alabel_hershey (R___(_plotter) t, h_just, v_just);
- _plotter->drawstate->pos = initial_pos;
- }
- free (t);
- }
- else
-
- {
- if (do_render)
- width = _plotter->paint_text_string (R___(_plotter) s, h_just, v_just);
- else
- width = _plotter->get_text_width (R___(_plotter) s);
- }
- return width;
- }
- double
- _pl_g_get_text_width (R___(Plotter *_plotter) const unsigned char *s)
- {
- int index;
- int width = 0;
- double swidth = 0.0;
- unsigned char current_char;
- int master_font_index;
- double retval;
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_POSTSCRIPT:
-
- master_font_index =
- (_pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
-
- for (index=0; s[index]!='\0'; index++)
- {
- current_char = (unsigned int)s[index];
- width
- += ((_pl_g_ps_font_info[master_font_index]).width)[current_char];
- }
-
- retval = _plotter->drawstate->true_font_size * (double)width / 1000.0;
- break;
-
- case PL_F_PCL:
-
- master_font_index =
- (_pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
-
- for (index=0; s[index]!='\0'; index++)
- {
- current_char = (unsigned int)s[index];
- width
- += ((_pl_g_pcl_font_info[master_font_index]).width)[current_char];
- }
-
- retval = _plotter->drawstate->true_font_size * (double)width / 1000.0;
- break;
-
- case PL_F_STICK:
-
- master_font_index =
- (_pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts)[_plotter->drawstate->font_index];
-
- if (_plotter->data->kern_stick_fonts)
-
- {
- const struct plStickFontSpacingTableStruct *ktable_lower, *ktable_upper;
- const struct plStickCharSpacingTableStruct *stable_lower, *stable_upper;
- const short *lower_spacing, *upper_spacing;
- int lower_cols, upper_cols;
- const char *lower_char_to_row, *lower_char_to_col;
- const char *upper_char_to_row, *upper_char_to_col;
- bool halves_use_different_tables;
-
-
- ktable_lower = &(_pl_g_stick_kerning_tables[_pl_g_stick_font_info[master_font_index].kerning_table_lower]);
- ktable_upper = &(_pl_g_stick_kerning_tables[_pl_g_stick_font_info[master_font_index].kerning_table_upper]);
- stable_lower = &(_pl_g_stick_spacing_tables[ktable_lower->spacing_table]);
- stable_upper = &(_pl_g_stick_spacing_tables[ktable_upper->spacing_table]);
-
-
- halves_use_different_tables
- = (stable_lower != stable_upper ? true : false);
-
-
- lower_cols = stable_lower->cols;
- upper_cols = stable_upper->cols;
-
-
- lower_char_to_row = ktable_lower->row;
- lower_char_to_col = ktable_lower->col;
- upper_char_to_row = ktable_upper->row;
- upper_char_to_col = ktable_upper->col;
-
-
- lower_spacing = stable_lower->kerns;
- upper_spacing = stable_upper->kerns;
-
-
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
-
-
- for (index=0; s[index]!='\0'; index++)
- {
- unsigned char c, d;
-
- c = (unsigned int)s[index];
-
- if (c < 0x80)
-
- {
- double spacefactor, char_width;
-
-
- if (c == ' ')
- spacefactor = 1.5;
- else
- spacefactor = 1.0;
-
-
- char_width
- = (((double)(_pl_g_stick_font_info[master_font_index].width[c]))
- * spacefactor
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- swidth += char_width;
-
- if ((d = (unsigned int)s[index+1]) != '\0')
-
- {
- int row, col;
- int spacing;
-
-
- row = lower_char_to_row[c];
-
-
- if (d < 0x80)
- {
- col = lower_char_to_col[d];
- spacing = lower_spacing[row * lower_cols + col];
- }
- else if (!halves_use_different_tables)
- {
- col = upper_char_to_col[d - 0x80];
- spacing = lower_spacing[row * lower_cols + col];
- }
- else if (c == ' ' || (d == ' ' + 0x80))
-
- spacing = 0;
- else
-
- spacing =
- - IROUND(spacefactor * _pl_g_stick_font_info[master_font_index].width[c])
- + IROUND(1.5 * _pl_g_stick_font_info[master_font_index].width[' ']);
-
- swidth
- += ((double)spacing)
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower);
- }
- }
- else
-
- {
- double spacefactor, char_width;
-
- if (c == ' ' + 0x80)
- spacefactor = 1.5;
- else
- spacefactor = 1.0;
-
-
- char_width
- = (((double)(_pl_g_stick_font_info[master_font_index].width[c]))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_upper));
- swidth += char_width;
-
- if ((d = (unsigned int)s[index+1]) != '\0')
-
- {
- int row, col;
- int spacing;
-
-
- row = upper_char_to_row[c - 0x80];
-
-
- if (d >= 0x80)
- {
- col = upper_char_to_col[d - 0x80];
- spacing = upper_spacing[row * upper_cols + col];
- }
- else if (!halves_use_different_tables)
- {
- col = lower_char_to_col[d];
- spacing = upper_spacing[row * upper_cols + col];
- }
- else if ((c == ' ' + 0x80) || d == ' ')
-
- spacing = 0;
- else
-
- spacing =
- - IROUND(spacefactor * _pl_g_stick_font_info[master_font_index].width[c])
- + IROUND(1.5 * _pl_g_stick_font_info[master_font_index].width[' ']);
-
- swidth
- += ((double)spacing)
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_upper);
- }
- }
- }
-
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- }
- else
-
- {
-
- for (index=0; s[index]!='\0'; index++)
- {
- unsigned char c;
-
- c = (unsigned int)s[index];
-
- #if 0
-
-
- if (IS_MATH_FONT(master_font_index) && IS_CENTERED_SYMBOL(c))
- continue;
- #endif
- if (c < 0x80)
-
- {
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].width[c]))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_lower));
- }
- else
-
- {
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_upper));
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].width[c]))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_upper));
- swidth
- += (((double)(_pl_g_stick_font_info[master_font_index].offset))
- /(2 * _pl_g_stick_font_info[master_font_index].raster_width_upper));
- }
- }
- }
-
-
- retval = _plotter->drawstate->true_font_size * (double)swidth;
- break;
-
- case PL_F_OTHER:
- retval = 0.0;
- break;
-
- default:
- retval = 0.0;
- break;
- }
- return retval;
- }
- static bool
- simple_string (const unsigned short *codestring)
- {
- const unsigned short *cptr = codestring;
- unsigned short c, d;
- int font_index;
- if (*codestring == 0)
- return true;
- c = *codestring;
- if (c & CONTROL_CODE)
- return false;
- font_index = (c >> FONT_SHIFT) & ONE_BYTE;
- while ((d = *cptr++) != 0)
- {
- int local_font_index;
- if (d & CONTROL_CODE)
- return false;
- local_font_index = (d >> FONT_SHIFT) & ONE_BYTE;
- if (local_font_index != font_index)
- return false;
- }
- return true;
- }
- #define GOOD_ISO(c) (((c >= 0x20) && (c <= 0x7E)) || ((c >= 0xA0) && (c <= 0xFF)))
- static bool
- clean_iso_string (unsigned char *s)
- {
- bool was_clean = true;
- unsigned char *t;
-
- for (t = s; *s; s++)
- {
- if (GOOD_ISO(*s))
- {
- *t = *s;
- t++;
- }
- else
- was_clean = false;
-
- }
- *t = (unsigned char)'\0';
-
- return was_clean;
- }
- /* escape all backslashes in a string; the returned string is allocated on
- the heap and can be freed. */
- static unsigned char *
- esc_esc_string (const unsigned char *s)
- {
- const unsigned char *sptr;
- unsigned char *t, *tptr;
- t = (unsigned char *)_pl_xmalloc (2 * strlen ((char *)s) + 1);
- sptr = s;
- tptr = t;
- while (*sptr)
- {
- *tptr++ = *sptr;
- if (*sptr == '\\')
- *tptr++ = *sptr;
- sptr++;
- }
- *tptr = '\0';
- return t;
- }
- /* Versions of the falabel() method that do nothing; derived (non-generic)
- Plotters must override them if they wish to use them. */
- void
- _pl_g_paint_text_string_with_escapes (R___(Plotter *_plotter) const unsigned char *s, int h_just, int v_just)
- {
- return;
- }
- double
- _pl_g_paint_text_string (R___(Plotter *_plotter) const unsigned char *s, int h_just, int v_just)
- {
- return 0.0;
- }
|