ref: f4520d8d9cd1d06e3a26e04d7eb6731ec9229623
parent: 578b5799dfa87c8fc1611cea32a6d95b6685af90
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Apr 18 05:39:30 EDT 2014
trfn: decide character type based on the previous glyphs
--- a/mktrfn.c
+++ b/mktrfn.c
@@ -29,7 +29,7 @@
}
if (!strcmp("char", cmd)) { scanf("%s width %s", ch, wid);- trfn_char(ch, NULL, atoi(wid), -1, 0, 0, 0, 0);
+ trfn_char(ch, NULL, atoi(wid), 0, 0, 0, 0);
}
if (!strcmp("kernpair", cmd)) { scanf("%s %s width %s", c1, c2, wid);@@ -107,7 +107,7 @@
break;
}
if (ch[0] && pos[0] && wid[0])
- trfn_char(ch, pos, atoi(wid), -1,
+ trfn_char(ch, pos, atoi(wid),
atoi(llx), atoi(lly), atoi(urx), atoi(ury));
}
while (fgets(ln, sizeof(ln), stdin)) {--- a/trfn.c
+++ b/trfn.c
@@ -30,6 +30,9 @@
static char subs_src[NSUBS][GNLEN];
static char subs_dst[NSUBS][GNLEN];
static int subs_n;
+/* character type */
+static int trfn_asc; /* minimum height of glyphs with ascender */
+static int trfn_desc; /* minimum depth of glyphs with descender */
/* adobe glyphlist mapping */
static char agl_key[AGLLEN][GNLEN];
@@ -39,7 +42,6 @@
/* lookup tables */
static struct tab *tab_agl;
static struct tab *tab_alts;
-static struct tab *tab_ctyp;
static int utf8len(int c)
{@@ -280,13 +282,28 @@
sprintf(strchr(trfn_ligs, '\0'), "%s ", c);
}
-static int trfn_type(char *c)
+static int trfn_type(char *s, int lly, int ury)
{- struct ctype *t = tab_get(tab_ctyp, c);
- return t ? t->type : 3;
+ int typ = 0;
+ int c = !s[0] || s[1] ? 0 : (unsigned char) *s;
+ if (c == 't' && !trfn_asc)
+ trfn_asc = ury;
+ if ((c == 'g' || c == 'j' || c == 'p' || c == 'q' || c == 'y') &&
+ (!trfn_desc || trfn_desc < lly))
+ trfn_desc = lly;
+ if (!trfn_desc || !trfn_asc) {+ if (c > 0 && c < 128)
+ return ctype_ascii[c];
+ return 3;
+ }
+ if (!trfn_desc || lly <= trfn_desc)
+ typ |= 1;
+ if (!trfn_asc || ury >= trfn_asc)
+ typ |= 2;
+ return typ;
}
-void trfn_char(char *psname, char *n, int wid, int typ,
+void trfn_char(char *psname, char *n, int wid,
int llx, int lly, int urx, int ury)
{char uc[GNLEN]; /* mapping unicode character */
@@ -294,6 +311,7 @@
char **a_tr; /* troff character names */
char pos[GNLEN] = ""; /* postscript character position/name */
int i_ps = 0; /* current name in a_ps */
+ int typ; /* character type */
/* initializing character attributes */
if (trfn_name(uc, psname))
strcpy(uc, "---");
@@ -301,8 +319,7 @@
strcpy(pos, n);
if (!n && !strchr(psname, '.') && !uc[1] && uc[0] >= 32 && uc[0] <= 125)
sprintf(pos, "%d", uc[0]);
- if (typ < 0)
- typ = trfn_type(!strchr(psname, '.') ? uc : "");
+ typ = trfn_type(!strchr(psname, '.') ? uc : "", lly, ury);
/* printing troff charset */
trfn_subs(psname, a_ps);
for (i_ps = 0; !i_ps || a_ps[i_ps]; i_ps++) {@@ -370,11 +387,8 @@
sbuf_init(&sbuf_char);
sbuf_init(&sbuf_kern);
tab_alts = tab_alloc(LEN(alts));
- tab_ctyp = tab_alloc(LEN(ctype));
for (i = 0; i < LEN(alts); i++)
tab_put(tab_alts, alts[i][0], alts[i] + 1);
- for (i = 0; i < LEN(ctype); i++)
- tab_put(tab_ctyp, ctype[i].ch, &ctype[i]);
}
void trfn_done(void)
@@ -382,7 +396,6 @@
sbuf_done(&sbuf_char);
sbuf_done(&sbuf_kern);
tab_free(tab_alts);
- tab_free(tab_ctyp);
if (tab_agl)
tab_free(tab_agl);
}
--- a/trfn.h
+++ b/trfn.h
@@ -3,7 +3,6 @@
void trfn_trfont(char *name);
void trfn_psfont(char *fontname);
void trfn_print(void);
-void trfn_char(char *c, char *n, int wid, int typ,
- int llx, int lly, int urx, int ury);
+void trfn_char(char *c, char *n, int wid, int llx, int lly, int urx, int ury);
void trfn_kern(char *c1, char *c2, int x);
void trfn_sub(char *c1, char *c2);
--- a/trfn_ch.h
+++ b/trfn_ch.h
@@ -15,7 +15,7 @@
/* troff aliases */
static char *alts[][8] = {- {"\\", "bs"},+ {"\\", "bs", "rs"}, {"`", "ga"}, {"¡", "!!"}, {"¢", "c|", "ct"},@@ -206,7 +206,7 @@
{"⁄", "fr"}, {"∞", "if"}, {"ƒ", "fn",},- {"↔", "ab"},+ {"↔", "ab", "<>"}, {"←", "<-"}, {"↑", "ua"}, {"→", "->"},@@ -213,10 +213,12 @@
{"↓", "da"}, {"°", "de"}, {"±", "+-"},+ {"∓", "-+"}, {"≥", ">="}, {"∝", "pt"}, {"∂", "pd"}, {"•", "bu"},+ {"○", "ci"}, {"÷", "di"}, {"≠", "!="}, {"≡", "=="},@@ -281,6 +283,8 @@
{"_", "ru", "ul"}, {"”", "''"}, {"“", "``"},+ {"⟨", "la"},+ {"⟩", "ra"}, {"†", "dg"}, {"‡", "dd"}, {"–", "en", "\\-"},@@ -383,333 +387,24 @@
{"zerojoin", 0x200d},};
-static struct ctype {- char *ch; /* character name */
- int type; /* ascender/descender type */
-} ctype[] = {- {"Ï", 2},- {"²", 2},- {"ì", 2},- {"u", 0},- {"Ì", 2},- {"U", 2},- {"∞", 0},- {"ú", 2},- {"∫", 3},- {"Ú", 2},- {"a", 0},- {"ι", 0},- {"û", 2},- {"A", 2},- {"Ι", 2},- {"Û", 2},- {"á", 2},- {"j", 3},- {"ü", 2},- {"Á", 2},- {"J", 3},- {"Ü", 2},- {"â", 2},- {"k", 2},- {"ù", 2},- {"Â", 2},- {"K", 2},- {"Ù", 2},- {"´", 2},- {"κ", 0},- {"ű", 2},- {"ä", 2},- {"Κ", 2},- {"Ű", 2},- {"Ä", 2},- {"l", 2},- {"_", 1},- {"æ", 0},- {"L", 2},- {"υ", 0},- {"Æ", 2},- {"λ", 2},- {"Υ", 2},- {"à", 2},- {"Λ", 2},- {"ů", 2},- {"À", 2},- {"<", 0},- {"Ů", 2},- {"α", 0},- {"≤", 2},- {"v", 0},- {"Α", 2},- {"¬", 0},- {"V", 2},- {"&", 2},- {"◊", 2},- {"w", 0},- {"≈", 0},- {"m", 0},- {"W", 2},- {"å", 2},- {"M", 2},- {"x", 0},- {"Å", 2},- {"¯", 2},- {"X", 2},- {"^", 2},- {"−", 0},- {"ξ", 3},- {"~", 0},- {"µ", 1},- {"Ξ", 2},- {"*", 2},- {"Μ", 2},- {"y", 1},- {"@", 3},- {"×", 0},- {"Y", 2},- {"ã", 2},- {"n", 0},- {"ý", 3},- {"Ã", 2},- {"N", 2},- {"Ý", 2},- {"b", 2},- {"ň", 2},- {"ÿ", 3},- {"B", 2},- {"9", 2},- {"¥", 2},- {"\\", 2},- {"≠", 0},- {"z", 0},- {"|", 3},- {"ñ", 2},- {"Z", 2},- {"β", 3},- {"Ñ", 2},- {"ž", 2},- {"Β", 2},- {"ν", 0},- {"Ž", 2},- {"{", 3},- {"Ν", 2},- {"0", 2},- {"}", 3},- {"#", 2},- {"ζ", 3},- {"[", 3},- {"o", 0},- {"Ζ", 2},- {"]", 3},- {"O", 2},- {"", 3},- {"˘", 2},- {"ó", 2},- {"", 2},- {"¦", 3},- {"Ó", 2},- {"", 3},- {"•", 0},- {"ô", 2},- {"", 2},- {"c", 0},- {"Ô", 2},- {"", 2},- {"C", 2},- {"ö", 2},- {"", 2},- {"ˇ", 2},- {"Ö", 2},- {"", 2},- {"č", 2},- {"˛", 1},- {"", 2},- {"Č", 2},- {"ò", 2},- {"", 2},- {"ç", 1},- {"Ò", 2},- {"،", 0},- {"Ç", 3},- {"ő", 2},- {"؛", 2},- {"¸", 1},- {"Ő", 2},- {"؟", 2},- {"¢", 2},- {"ω", 0},- {"٠", 0},- {"χ", 1},- {"Ω", 2},- {"١", 2},- {"Χ", 2},- {"ο", 0},- {"٢", 2},- {"ˆ", 2},- {"Ο", 2},- {"٣", 2},- {":", 0},- {"1", 2},- {"٤", 2},- {",", 1},- {"½", 2},- {"٥", 2},- {"©", 2},- {"¼", 2},- {"٦", 2},- {"¤", 2},- {"¹", 2},- {"٧", 2},- {"d", 2},- {"ª", 2},- {"٨", 2},- {"D", 2},- {"º", 2},- {"٩", 2},- {"ď", 2},- {"ø", 0},- {"۰", 0},- {"Ď", 2},- {"Ø", 2},- {"۱", 2},- {"°", 2},- {"õ", 2},- {"۲", 2},- {"δ", 2},- {"Õ", 2},- {"۳", 2},- {"∆", 2},- {"p", 1},- {"۴", 2},- {"¨", 2},- {"P", 2},- {"۵", 2},- {"÷", 0},- {"¶", 3},- {"۶", 2},- {"$", 2},- {"(", 3},- {"۷", 2},- {"˙", 2},- {")", 3},- {"۸", 2},- {"e", 0},- {"∂", 2},- {"۹", 2},- {"E", 2},- {"%", 2},- {"٪", 2},- {"é", 2},- {".", 0},- {"", 0},- {"É", 2},- {"·", 0},- {"", 0},- {"ě", 2},- {"φ", 3},- {"ê", 2},- {"Φ", 2},- {"Ê", 2},- {"π", 0},- {"ë", 2},- {"Π", 2},- {"Ë", 2},- {"+", 0},- {"è", 2},- {"±", 2},- {"È", 2},- {"∏", 2},- {"8", 2},- {"ψ", 3},- {"…", 0},- {"Ψ", 2},- {"ε", 0},- {"q", 1},- {"Ε", 2},- {"Q", 3},- {"=", 0},- {"?", 2},- {"η", 1},- {"¿", 1},- {"Η", 2},- {"\"", 2},- {"ð", 2},- {"‘", 2},- {"Ð", 2},- {"’", 2},- {"!", 2},- {"r", 0},- {"¡", 1},- {"R", 2},- {"f", 2},- {"√", 2},- {"F", 2},- {"ř", 2},- {"ff", 2},- {"Ř", 2},- {"ffi", 2},- {"®", 2},- {"ffj", 3},- {"ρ", 1},- {"ffl", 2},- {"Ρ", 2},- {"fi", 2},- {"˚", 2},- {"fi", 2},- {"s", 0},- {"5", 2},- {"S", 2},- {"fj", 3},- {"š", 2},- {"fl", 2},- {"Š", 2},- {"fl", 2},- {"§", 2},- {"ƒ", 3},- {";", 1},- {"4", 2},- {"7", 2},- {"⁄", 2},- {"σ", 0},- {"g", 1},- {"Σ", 2},- {"G", 2},- {"6", 2},- {"γ", 1},- {"/", 2},- {"Γ", 2},- {"£", 2},- {"ß", 2},- {"∑", 2},- {"`", 2},- {"t", 2},- {">", 0},- {"T", 2},- {"≥", 2},- {"τ", 0},- {"«", 0},- {"Τ", 2},- {"»", 0},- {"ť", 2},- {"h", 2},- {"Ť", 2},- {"H", 2},- {"Th", 2},- {"˝", 2},- {"θ", 2},- {"-", 0},- {"Θ", 2},- {"i", 2},- {"þ", 3},- {"I", 2},- {"Þ", 2},- {"í", 2},- {"3", 2},- {"Í", 2},- {"¾", 2},- {"î", 2},- {"³", 2},- {"Î", 2},- {"˜", 2},- {"ï", 2},- {"2", 2},+int ctype_ascii[128] = {+ ['!'] = 2, ['"'] = 2, ['#'] = 2, ['$'] = 2, ['%'] = 2,
+ ['&'] = 2, ['\''] = 2, ['('] = 3, [')'] = 3, ['*'] = 2,+ ['+'] = 0, [','] = 1, ['-'] = 0, ['.'] = 0, ['/'] = 2,
+ ['0'] = 2, ['1'] = 2, ['2'] = 2, ['3'] = 2, ['4'] = 2,
+ ['5'] = 2, ['6'] = 2, ['7'] = 2, ['8'] = 2, ['9'] = 2,
+ [':'] = 0, [';'] = 1, ['<'] = 0, ['='] = 0, ['>'] = 0,
+ ['?'] = 2, ['@'] = 3, ['A'] = 2, ['B'] = 2, ['C'] = 2,
+ ['D'] = 2, ['E'] = 2, ['F'] = 2, ['G'] = 2, ['H'] = 2,
+ ['I'] = 2, ['J'] = 3, ['K'] = 2, ['L'] = 2, ['M'] = 2,
+ ['N'] = 2, ['O'] = 2, ['P'] = 2, ['Q'] = 3, ['R'] = 2,
+ ['S'] = 2, ['T'] = 2, ['U'] = 2, ['V'] = 2, ['W'] = 2,
+ ['X'] = 2, ['Y'] = 2, ['Z'] = 2, ['['] = 3, ['\\'] = 2,
+ [']'] = 3, ['^'] = 2, ['_'] = 1, ['a'] = 0, ['b'] = 2,
+ ['c'] = 0, ['d'] = 2, ['e'] = 0, ['f'] = 2, ['g'] = 1,
+ ['h'] = 2, ['i'] = 2, ['j'] = 3, ['k'] = 2, ['l'] = 2,
+ ['m'] = 0, ['n'] = 0, ['o'] = 0, ['p'] = 1, ['q'] = 1,
+ ['r'] = 0, ['s'] = 0, ['t'] = 2, ['u'] = 0, ['v'] = 0,
+ ['w'] = 0, ['x'] = 0, ['y'] = 1, ['z'] = 0, ['{'] = 3,+ ['|'] = 3, ['}'] = 3, ['~'] = 0,
};
--
⑨