123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- #include "sys-defines.h"
- #include "extern.h"
- #include "g_control.h"
- #include "g_cntrlify.h"
- #include "g_jis.h"
- #define NUM_OCCIDENTAL_HERSHEY_GLYPHS 4400
- #define NUM_ORIENTAL_HERSHEY_GLYPHS 5500
- unsigned short *
- _pl_g_controlify (R___(Plotter *_plotter) const unsigned char *src)
- {
- unsigned short *dest;
- unsigned char c, d;
- unsigned char esc[3];
- int j = 0;
- int raw_fontnum, raw_symbol_fontnum;
- int previous_raw_fontnum;
- unsigned short fontword, symbol_fontword;
-
-
- dest = (unsigned short *)_pl_xmalloc ((6 * strlen ((char *)src) + 1) * sizeof(unsigned short));
-
-
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_POSTSCRIPT:
- default:
- raw_fontnum = _pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts[_plotter->drawstate->font_index];
- raw_symbol_fontnum = _pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts[0];
- break;
- case PL_F_PCL:
- raw_fontnum = _pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts[_plotter->drawstate->font_index];
- raw_symbol_fontnum = _pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts[0];
- break;
- case PL_F_STICK:
- raw_fontnum = _pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts[_plotter->drawstate->font_index];
- raw_symbol_fontnum = _pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts[0];
- break;
- case PL_F_HERSHEY:
- raw_fontnum = _pl_g_hershey_typeface_info[_plotter->drawstate->typeface_index].fonts[_plotter->drawstate->font_index];
- raw_symbol_fontnum = _pl_g_hershey_typeface_info[_plotter->drawstate->typeface_index].fonts[0];
- break;
- case PL_F_OTHER:
-
- raw_fontnum = 1;
- raw_symbol_fontnum = 0;
- break;
- }
-
- fontword = ((unsigned short)raw_fontnum) << FONT_SHIFT;
- symbol_fontword = ((unsigned short)raw_symbol_fontnum) << FONT_SHIFT;
-
- previous_raw_fontnum = raw_fontnum;
- while (*src != (unsigned char)'\0')
- {
-
- if ((raw_fontnum == PL_HERSHEY_EUC)
- && (*src & 0x80) && (*(src + 1) & 0x80))
- {
- unsigned char jis_row = *src & ~(0x80);
- unsigned char jis_col = *(src + 1) & ~(0x80);
- if (GOOD_JIS_INDEX(jis_row, jis_col))
- {
- int jis_glyphindex = 256 * jis_row + jis_col;
-
- if (jis_glyphindex >= BEGINNING_OF_KANJI)
-
- {
- #ifndef NO_KANJI
- const struct kanjipair *kanji = _builtin_kanji_glyphs;
- bool matched = false;
-
- while (kanji->jis != 0)
- {
- if (jis_glyphindex == kanji->jis)
- {
- matched = true;
- break;
- }
- kanji++;
- }
- if (matched)
- {
- dest[j++] = RAW_ORIENTAL_HERSHEY_GLYPH | (kanji->nelson);
- src += 2;
- continue;
- }
- else
- {
-
- dest[j++] = RAW_HERSHEY_GLYPH | UNDE;
- src += 2;
- continue;
- }
- #endif
- }
- else
-
- {
- const struct jis_entry *char_mapping = _builtin_jis_chars;
- bool matched = false;
-
- while (char_mapping->jis != 0)
- {
- if (jis_glyphindex == char_mapping->jis)
- {
- matched = true;
- break;
- }
- char_mapping++;
- }
- if (matched)
-
- {
- int fontnum = char_mapping->font;
- unsigned short charnum = char_mapping->charnum;
-
- if (charnum & RAW_HERSHEY_GLYPH)
-
- dest[j++] = RAW_HERSHEY_GLYPH | charnum;
- else
-
- dest[j++] = (((unsigned short)fontnum) << FONT_SHIFT) | charnum;
- src += 2;
- continue;
- }
- else
- {
-
- dest[j++] = RAW_HERSHEY_GLYPH | UNDE;
- src += 2;
- continue;
- }
- }
- }
- else
-
- {
- src += 2;
- continue;
- }
- }
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
- {
- int i;
- bool matched = false;
-
- for (i = 0; i < NUM_LIGATURES; i++)
- if ((_ligature_tbl[i].font == raw_fontnum)
- && (strncmp ((char *)src, _ligature_tbl[i].from,
- strlen (_ligature_tbl[i].from)) == 0))
- {
- matched = true;
- break;
- }
-
- if (matched)
- {
- dest[j++] = fontword | (unsigned short)_ligature_tbl[i].byte;
- src += strlen (_ligature_tbl[i].from);
- continue;
- }
- }
- c = *(src++);
- if (c != (unsigned char)'\\')
- {
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY
- && _pl_g_hershey_font_info[raw_fontnum].iso8859_1)
- {
- int i;
- bool matched = false;
-
- for (i = 0; i < NUM_RAISED_CHARS; i++)
- if (c == _raised_char_tbl[i].from)
- {
- matched = true;
- break;
- }
- if (matched)
- {
-
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_BEGIN_SUPERSCRIPT);
- if (_raised_char_tbl[i].underscored)
- {
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_PUSH_LOCATION);
- dest[j++] =
- fontword | (unsigned short)_raised_char_tbl[i].to;
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_POP_LOCATION);
-
- dest[j++] =
- symbol_fontword | (unsigned short)VECTOR_SYMBOL_FONT_UNDERSCORE;
- }
- else
- dest[j++] =
- fontword | (unsigned short)_raised_char_tbl[i].to;
-
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_END_SUPERSCRIPT);
-
- continue;
- }
-
- for (i = 0; i < NUM_DELIGATURED_CHARS; i++)
- if (c == _deligature_char_tbl[i].from)
- {
- matched = true;
- break;
- }
- if (matched)
- {
- if (_deligature_char_tbl[i].except_font != raw_fontnum)
- {
- dest[j++] = fontword
- | (unsigned short)_deligature_char_tbl[i].to[0];
- dest[j++] = fontword
- | (unsigned short)_deligature_char_tbl[i].to[1];
- continue;
- }
- }
- }
-
-
- dest[j++] = fontword | (unsigned short)c;
- continue;
- }
- else
- {
- c = *(src++);
- if (c == (unsigned char)'\0')
- {
- dest[j++] = fontword | (unsigned short)'\\';
- break;
- }
-
- if (c == (unsigned char)'\\')
- {
- dest[j++] = fontword | (unsigned short)'\\';
- dest[j++] = fontword | (unsigned short)'\\';
- continue;
- }
- d = *(src++);
- if (d == (unsigned char)'\0')
- {
- dest[j++] = fontword | (unsigned short)'\\';
- dest[j++] = fontword | (unsigned short)c;
- break;
- }
- esc[0] = c;
- esc[1] = d;
- esc[2] = (unsigned char)'\0';
-
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY
- && esc[0] == '#' && esc[1] == 'H'
- && src[0] >= '0' && src[0] <= '9'
- && src[1] >= '0' && src[1] <= '9'
- && src[2] >= '0' && src[2] <= '9'
- && src[3] >= '0' && src[3] <= '9')
- {
- int glyphindex;
- glyphindex = (src[3] - '0') + 10 * (src[2] - '0')
- + 100 * (src[1] - '0') + 1000 * (src[0] - '0');
- if (glyphindex < NUM_OCCIDENTAL_HERSHEY_GLYPHS)
- {
- dest[j++] = RAW_HERSHEY_GLYPH | glyphindex;
- src += 4;
- continue;
- }
- }
- #ifndef NO_KANJI
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY
- && esc[0] == '#' && esc[1] == 'N'
- && src[0] >= '0' && src[0] <= '9'
- && src[1] >= '0' && src[1] <= '9'
- && src[2] >= '0' && src[2] <= '9'
- && src[3] >= '0' && src[3] <= '9')
- {
- int glyphindex;
- glyphindex = (src[3] - '0') + 10 * (src[2] - '0')
- + 100 * (src[1] - '0') + 1000 * (src[0] - '0');
- if (glyphindex < NUM_ORIENTAL_HERSHEY_GLYPHS)
- {
- dest[j++] = RAW_ORIENTAL_HERSHEY_GLYPH | glyphindex;
- src += 4;
- continue;
- }
- }
- #endif
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY
- && esc[0] == '#' && esc[1] == 'J'
- && ((src[0] >= '0' && src[0] <= '9')
- || (src[0] >= 'a' && src[0] <= 'f')
- || (src[0] >= 'A' && src[0] <= 'F'))
- && ((src[1] >= '0' && src[1] <= '9')
- || (src[1] >= 'a' && src[1] <= 'f')
- || (src[1] >= 'A' && src[1] <= 'F'))
- && ((src[2] >= '0' && src[2] <= '9')
- || (src[2] >= 'a' && src[2] <= 'f')
- || (src[2] >= 'A' && src[2] <= 'F'))
- && ((src[3] >= '0' && src[3] <= '9')
- || (src[3] >= 'a' && src[3] <= 'f')
- || (src[3] >= 'A' && src[3] <= 'F')))
- {
- int jis_glyphindex;
- int i, hexnum[4];
- int jis_row, jis_col;
-
- for (i = 0; i < 4; i++)
- if (src[i] >= 'a' && src[i] <= 'f')
- hexnum[i] = 10 + src[i] - 'a';
- else if (src[i] >= 'A' && src[i] <= 'F')
- hexnum[i] = 10 + src[i] - 'A';
- else
- hexnum[i] = src[i] - '0';
- jis_glyphindex = (hexnum[3] + 16 * hexnum[2]
- + 256 * hexnum[1] + 4096 * hexnum[0]);
- jis_row = hexnum[1] + 16 * hexnum[0];
- jis_col = hexnum[3] + 16 * hexnum[2];
- if (GOOD_JIS_INDEX(jis_row, jis_col))
- {
- if (jis_glyphindex >= BEGINNING_OF_KANJI)
-
- {
- #ifndef NO_KANJI
- const struct kanjipair *kanji = _builtin_kanji_glyphs;
- bool matched = false;
-
- while (kanji->jis != 0)
- {
- if (jis_glyphindex == kanji->jis)
- {
- matched = true;
- break;
- }
- kanji++;
- }
- if (matched)
- {
- dest[j++] = RAW_ORIENTAL_HERSHEY_GLYPH | (kanji->nelson);
- src += 4;
- continue;
- }
- else
- {
-
- dest[j++] = RAW_HERSHEY_GLYPH | UNDE;
- src += 4;
- continue;
- }
- #endif
- }
- else
-
- {
- const struct jis_entry *char_mapping = _builtin_jis_chars;
- bool matched = false;
-
- while (char_mapping->jis != 0)
- {
- if (jis_glyphindex == char_mapping->jis)
- {
- matched = true;
- break;
- }
- char_mapping++;
- }
- if (matched)
-
- {
- int fontnum = char_mapping->font;
- unsigned short charnum = char_mapping->charnum;
-
- if (charnum & RAW_HERSHEY_GLYPH)
-
- dest[j++] = RAW_HERSHEY_GLYPH | charnum;
- else
-
- dest[j++] = (((unsigned short)fontnum) << FONT_SHIFT) | charnum;
- src += 4;
- continue;
- }
- else
- {
-
- dest[j++] = RAW_HERSHEY_GLYPH | UNDE;
- src += 4;
- continue;
- }
- }
- }
- }
- {
- int i;
- bool matched = false;
-
- for (i = 0; i < NUM_CONTROLS; i++)
- if (strcmp ((char *)esc, _control_tbl[i]) == 0)
- {
- matched = true;
- break;
- }
- if (matched)
- {
- dest[j++] = CONTROL_CODE | i;
- continue;
- }
- }
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY
- && _pl_g_hershey_font_info[raw_fontnum].iso8859_1)
- {
- int i;
- bool matched = false;
-
- for (i = 0; i < NUM_DELIGATURED_ESCAPES; i++)
- if (strcmp ((char *)esc, _deligature_escape_tbl[i].from) == 0)
- {
- matched = true;
- break;
- }
- if (matched)
- {
- if (_deligature_escape_tbl[i].except_font != raw_fontnum)
- {
- dest[j++] = fontword
- | (unsigned short)_deligature_escape_tbl[i].to[0];
- dest[j++] = fontword
- | (unsigned short)_deligature_escape_tbl[i].to[1];
- continue;
- }
- }
- }
-
- if ((_plotter->drawstate->font_type == PL_F_POSTSCRIPT
- && _pl_g_ps_font_info[raw_fontnum].iso8859_1)
- || (_plotter->drawstate->font_type == PL_F_HERSHEY
- && _pl_g_hershey_font_info[raw_fontnum].iso8859_1)
- || (_plotter->drawstate->font_type == PL_F_PCL
- && _pl_g_pcl_font_info[raw_fontnum].iso8859_1)
- || (_plotter->drawstate->font_type == PL_F_STICK
- && _pl_g_stick_font_info[raw_fontnum].iso8859_1)
- || (_plotter->drawstate->font_type == PL_F_OTHER
- && _plotter->drawstate->font_is_iso8859_1
- && raw_fontnum == 1))
- {
- int i;
- bool matched = false;
- for (i = 0; i < NUM_ISO_ESCAPES; i++)
- if (strcmp ((char *)esc, _iso_escape_tbl[i].string) == 0)
- {
- matched = true;
- break;
- }
- if (matched)
- {
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
- {
- int k;
- bool matched2 = false;
-
-
- for (k = 0; k < NUM_RAISED_CHARS; k++)
- if (_iso_escape_tbl[i].byte == _raised_char_tbl[k].from)
- {
- matched2 = true;
- break;
- }
- if (matched2)
- {
-
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_BEGIN_SUPERSCRIPT);
- if (_raised_char_tbl[k].underscored)
- {
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_PUSH_LOCATION);
- dest[j++] =
- fontword | (unsigned short)_raised_char_tbl[k].to;
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_POP_LOCATION);
-
- dest[j++] =
- symbol_fontword | (unsigned short)VECTOR_SYMBOL_FONT_UNDERSCORE;
- }
- else
- {
- dest[j++] =
- fontword | (unsigned short)_raised_char_tbl[k].to;
- }
- dest[j++] =
- (unsigned short) (CONTROL_CODE | C_END_SUPERSCRIPT);
- continue;
- }
- }
-
- dest[j++] = fontword | (unsigned short)(_iso_escape_tbl[i].byte);
- continue;
- }
- }
-
- if (_plotter->drawstate->font_type == PL_F_HERSHEY)
- {
- int i;
- bool matched = false;
- for (i = 0; i < NUM_SPECIAL_ESCAPES; i++)
- if (strcmp ((char *)esc, _special_escape_tbl[i].string) == 0)
- {
- matched = true;
- break;
- }
- if (matched)
- {
-
- if (_special_escape_tbl[i].byte == FINAL_LOWERCASE_S)
- dest[j++] =
- fontword | (unsigned short)(_special_escape_tbl[i].byte);
- else
-
- dest[j++] = symbol_fontword | (unsigned short)(_special_escape_tbl[i].byte);
- continue;
- }
- }
- {
- int i;
- bool matched = false;
-
-
- for (i = 0; i < NUM_SYMBOL_ESCAPES; i++)
- if (strcmp (_symbol_escape_tbl[i].string, "NO_ABBREV") != 0
- && strcmp ((char *)esc, _symbol_escape_tbl[i].string) == 0)
- {
- matched = true;
- break;
- }
- if (matched)
- {
-
- dest[j++] = symbol_fontword | (unsigned short)(_symbol_escape_tbl[i].byte);
- continue;
- }
- }
-
- if (strcmp ((char *)esc, "rn") == 0)
- {
- if (_plotter->drawstate->font_type == PL_F_POSTSCRIPT
- || _plotter->drawstate->font_type == PL_F_PCL)
- {
- dest[j++]
- = (unsigned short)(CONTROL_CODE | C_LEFT_RADICAL_SHIFT);
-
- dest[j++]
- = symbol_fontword | (unsigned short)RADICALEX;
- dest[j++]
- = (unsigned short)(CONTROL_CODE | C_RIGHT_RADICAL_SHIFT);
- continue;
- }
- }
-
- if (esc[0] == 'f' && ((esc[1] >= '0' && esc[1] <= '9')
- || esc[1] == 'P' || esc[1] == 'R'
- || esc[1] == 'I' || esc[1] == 'B'))
- {
-
- if (_plotter->drawstate->font_type == PL_F_OTHER
- && ((esc[1] >= '2' && esc[1] <= '9')
- || esc[1] == 'I' || esc[1] == 'B'))
- esc[1] = '1';
-
-
- if (esc[1] == 'R')
- esc[1] = '1';
- else if (esc[1] == 'I')
- esc[1] = '2';
- else if (esc[1] == 'B')
- esc[1] = '3';
- if (esc[1] == 'P')
- raw_fontnum = previous_raw_fontnum;
- else
- {
- int new_font_index = esc[1] - '0';
-
- previous_raw_fontnum = raw_fontnum;
- switch (_plotter->drawstate->font_type)
- {
- case PL_F_HERSHEY:
- if ((new_font_index >= _pl_g_hershey_typeface_info[_plotter->drawstate->typeface_index].numfonts)
- || new_font_index < 0)
- new_font_index = 1;
- raw_fontnum = _pl_g_hershey_typeface_info[_plotter->drawstate->typeface_index].fonts[new_font_index];
- break;
- case PL_F_PCL:
- if ((new_font_index >= _pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].numfonts)
- || new_font_index < 0)
- new_font_index = 1;
- raw_fontnum = _pl_g_pcl_typeface_info[_plotter->drawstate->typeface_index].fonts[new_font_index];
- break;
- case PL_F_STICK:
- if ((new_font_index >= _pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].numfonts)
- || new_font_index < 0)
- new_font_index = 1;
- raw_fontnum = _pl_g_stick_typeface_info[_plotter->drawstate->typeface_index].fonts[new_font_index];
- break;
- case PL_F_POSTSCRIPT:
- default:
- if ((new_font_index >= _pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].numfonts)
- || new_font_index < 0)
- new_font_index = 1;
- raw_fontnum = _pl_g_ps_typeface_info[_plotter->drawstate->typeface_index].fonts[new_font_index];
- break;
- case PL_F_OTHER:
- if (new_font_index != 0 && new_font_index != 1)
- new_font_index = 1;
- raw_fontnum = new_font_index;
- break;
- }
- }
- fontword = ((unsigned short)raw_fontnum) << FONT_SHIFT;
- continue;
- }
-
-
- dest[j++] = fontword | (unsigned short)'\\';
- dest[j++] = fontword | (unsigned short)c;
- dest[j++] = fontword | (unsigned short)d;
- }
- }
- dest[j] = (unsigned short)'\0';
- return dest;
- }
- int
- _codestring_len (const unsigned short *codestring)
- {
- int i = 0;
- while (*codestring)
- {
- i++;
- codestring++;
- }
-
- return i;
- }
|