summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e10118c)
the "fi" and "fl" ligatures to the built-in fonts, but doesn't add support
for reading ligature information from AFM files because that requires coping
with forward references to glyph names, which is tricky.
git-svn-id: svn://svn.tartarus.org/sgt/halibut@7045
cda61777-01e9-0310-a592-
d414129be87e
word_PageXref = word_NotWordType + 1
};
word_PageXref = word_NotWordType + 1
};
+/* Flags for render_string() */
+#define RS_NOLIG 1
+
static font_data *make_std_font(font_list *fontlist, char const *name);
static void wrap_paragraph(para_data *pdata, word *words,
int w, int i1, int i2, paper_conf *conf);
static page_data *page_breaks(line_data *first, line_data *last,
int page_height, int ncols, int headspace);
static int render_string(page_data *page, font_data *font, int fontsize,
static font_data *make_std_font(font_list *fontlist, char const *name);
static void wrap_paragraph(para_data *pdata, word *words,
int w, int i1, int i2, paper_conf *conf);
static page_data *page_breaks(line_data *first, line_data *last,
int page_height, int ncols, int headspace);
static int render_string(page_data *page, font_data *font, int fontsize,
- int x, int y, wchar_t *str);
+ int x, int y, wchar_t *str, unsigned flags);
static int render_line(line_data *ldata, int left_x, int top_y,
xref_dest *dest, keywordlist *keywords, indexdata *idx,
paper_conf *conf);
static void render_para(para_data *pdata, paper_conf *conf,
keywordlist *keywords, indexdata *idx,
paragraph *index_placeholder, page_data *index_page);
static int render_line(line_data *ldata, int left_x, int top_y,
xref_dest *dest, keywordlist *keywords, indexdata *idx,
paper_conf *conf);
static void render_para(para_data *pdata, paper_conf *conf,
keywordlist *keywords, indexdata *idx,
paragraph *index_placeholder, page_data *index_page);
-static int string_width(font_data *font, wchar_t const *string, int *errs);
+static int string_width(font_data *font, wchar_t const *string, int *errs,
+ unsigned flags);
static int paper_width_simple(para_data *pdata, word *text, paper_conf *conf);
static para_data *code_paragraph(int indent, word *words, paper_conf *conf);
static para_data *rule_paragraph(int indent, paper_conf *conf);
static int paper_width_simple(para_data *pdata, word *text, paper_conf *conf);
static para_data *code_paragraph(int indent, word *words, paper_conf *conf);
static para_data *rule_paragraph(int indent, paper_conf *conf);
va_start(ap, string);
while ( (font = va_arg(ap, font_data *)) != NULL) {
int errs;
va_start(ap, string);
while ( (font = va_arg(ap, font_data *)) != NULL) {
int errs;
- (void) string_width(font, string, &errs);
+ (void) string_width(font, string, &errs, 0);
if (errs) {
ret = FALSE;
break;
if (errs) {
ret = FALSE;
break;
width = conf->pagenum_fontsize *
string_width(conf->fbase.fonts[FONT_NORMAL], page->number,
width = conf->pagenum_fontsize *
string_width(conf->fbase.fonts[FONT_NORMAL], page->number,
render_string(page, conf->fbase.fonts[FONT_NORMAL],
conf->pagenum_fontsize,
conf->left_margin + (conf->base_width - width)/2,
conf->bottom_margin - conf->footer_distance,
render_string(page, conf->fbase.fonts[FONT_NORMAL],
conf->pagenum_fontsize,
conf->left_margin + (conf->base_width - width)/2,
conf->bottom_margin - conf->footer_distance,
+int lig_cmp(void *a, void *b)
+{
+ ligature const *la = a, *lb = b;
+
+ if (la->left < lb->left)
+ return -1;
+ if (la->left > lb->left)
+ return 1;
+ if (la->right < lb->right)
+ return -1;
+ if (la->right > lb->right)
+ return 1;
+ return 0;
+}
+
/* This wouldn't be necessary if C had closures. */
static font_info *glyph_cmp_fi;
/* This wouldn't be necessary if C had closures. */
static font_info *glyph_cmp_fi;
-int find_glyph(font_info *fi, char const *name) {
+int find_glyph(font_info const *fi, char const *name) {
-static int string_width(font_data *font, wchar_t const *string, int *errs)
+static int find_lig(font_data *font, int lindex, int rindex)
+{
+ ligature wantlig;
+ ligature const *lig;
+
+ if (lindex == 0xFFFF || rindex == 0xFFFF)
+ return 0xFFFF;
+ wantlig.left = lindex;
+ wantlig.right = rindex;
+ lig = find234(font->info->ligs, &wantlig, NULL);
+ if (lig == NULL)
+ return 0xFFFF;
+ return lig->lig;
+}
+
+static int utoglyph(font_info const *fi, wchar_t u) {
+ return (u < 0 || u > 0xFFFF ? 0xFFFF : fi->bmp[u]);
+}
+
+static int string_width(font_data *font, wchar_t const *string, int *errs,
+ unsigned flags)
+ int nindex, index, oindex, lindex;
if (errs)
*errs = 0;
oindex = 0xFFFF;
if (errs)
*errs = 0;
oindex = 0xFFFF;
+ index = utoglyph(font->info, *string);
for (; *string; string++) {
for (; *string; string++) {
- index = (*string < 0 || *string > 0xFFFF ? 0xFFFF :
- font->info->bmp[*string]);
+ nindex = utoglyph(font->info, string[1]);
if (index == 0xFFFF) {
if (errs)
*errs = 1;
} else {
if (index == 0xFFFF) {
if (errs)
*errs = 1;
} else {
+ if (!(flags & RS_NOLIG) &&
+ (lindex = find_lig(font, index, nindex)) != 0xFFFF) {
+ index = lindex;
+ continue;
+ }
width += find_kern(font, oindex, index) +
font->info->widths[index];
}
oindex = index;
width += find_kern(font, oindex, index) +
font->info->widths[index];
}
oindex = index;
struct paper_width_ctx *ctx = (struct paper_width_ctx *)vctx;
int style, type, findex, width, errs;
wchar_t *str;
struct paper_width_ctx *ctx = (struct paper_width_ctx *)vctx;
int style, type, findex, width, errs;
wchar_t *str;
switch (word->type) {
case word_HyperLink:
switch (word->type) {
case word_HyperLink:
style == word_Emph ? FONT_EMPH :
FONT_CODE);
style == word_Emph ? FONT_EMPH :
FONT_CODE);
+ if (style == word_Code || style == word_WeakCode) flags |= RS_NOLIG;
+
if (type == word_Normal) {
str = word->text;
} else if (type == word_WhiteSpace) {
if (type == word_Normal) {
str = word->text;
} else if (type == word_WhiteSpace) {
str = ctx->conf->rquote;
}
str = ctx->conf->rquote;
}
- width = string_width(ctx->pdata->fonts[findex], str, &errs);
+ width = string_width(ctx->pdata->fonts[findex], str, &errs, flags);
if (errs && word->alt)
return paper_width_list(vctx, word->alt, NULL, nspaces);
if (errs && word->alt)
return paper_width_list(vctx, word->alt, NULL, nspaces);
ctx.pdata = pdata;
ctx.minspacewidth =
(pdata->sizes[FONT_NORMAL] *
ctx.pdata = pdata;
ctx.minspacewidth =
(pdata->sizes[FONT_NORMAL] *
- string_width(pdata->fonts[FONT_NORMAL], L" ", NULL));
+ string_width(pdata->fonts[FONT_NORMAL], L" ", NULL, 0));
ctx.conf = conf;
return paper_width_list(&ctx, text, NULL, NULL);
ctx.conf = conf;
return paper_width_list(&ctx, text, NULL, NULL);
}
spacewidth = (pdata->sizes[FONT_NORMAL] *
}
spacewidth = (pdata->sizes[FONT_NORMAL] *
- string_width(pdata->fonts[FONT_NORMAL], L" ", NULL));
+ string_width(pdata->fonts[FONT_NORMAL], L" ", NULL, 0));
if (spacewidth == 0) {
/*
* A font without a space?! Disturbing. I hope this never
if (spacewidth == 0) {
/*
* A font without a space?! Disturbing. I hope this never
* Returns the updated x coordinate.
*/
static int render_string(page_data *page, font_data *font, int fontsize,
* Returns the updated x coordinate.
*/
static int render_string(page_data *page, font_data *font, int fontsize,
- int x, int y, wchar_t *str)
+ int x, int y, wchar_t *str, unsigned flags)
- int textpos, textwid, kern, glyph, oglyph;
+ int textpos, textwid, kern, nglyph, glyph, oglyph, lig;
font_encoding *subfont = NULL, *sf;
text = snewn(1 + ustrlen(str), char);
textpos = textwid = 0;
glyph = 0xFFFF;
font_encoding *subfont = NULL, *sf;
text = snewn(1 + ustrlen(str), char);
textpos = textwid = 0;
glyph = 0xFFFF;
+ nglyph = utoglyph(font->info, *str);
while (*str) {
oglyph = glyph;
while (*str) {
oglyph = glyph;
- glyph = (*str < 0 || *str > 0xFFFF ? 0xFFFF :
- font->info->bmp[*str]);
+ glyph = nglyph;
+ nglyph = utoglyph(font->info, str[1]);
if (glyph == 0xFFFF) {
str++;
continue; /* nothing more we can do here */
}
if (glyph == 0xFFFF) {
str++;
continue; /* nothing more we can do here */
}
+ if (!(flags & RS_NOLIG) &&
+ (lig = find_lig(font, glyph, nglyph)) != 0xFFFF) {
+ nglyph = lig;
+ str++;
+ continue;
+ }
+
/*
* Find which subfont this character is going in.
*/
/*
* Find which subfont this character is going in.
*/
int style, type, findex, errs;
wchar_t *str;
xref_dest dest;
int style, type, findex, errs;
wchar_t *str;
xref_dest dest;
style == word_Emph ? FONT_EMPH :
FONT_CODE);
style == word_Emph ? FONT_EMPH :
FONT_CODE);
+ if (style == word_Code || style == word_WeakCode) flags |= RS_NOLIG;
+
if (type == word_Normal) {
str = text->text;
} else if (type == word_WhiteSpace) {
x += pdata->sizes[findex] *
if (type == word_Normal) {
str = text->text;
} else if (type == word_WhiteSpace) {
x += pdata->sizes[findex] *
- string_width(pdata->fonts[findex], L" ", NULL);
+ string_width(pdata->fonts[findex], L" ", NULL, 0);
if (nspaces && findex != FONT_CODE) {
x += (*nspace+1) * shortfall / nspaces;
x -= *nspace * shortfall / nspaces;
if (nspaces && findex != FONT_CODE) {
x += (*nspace+1) * shortfall / nspaces;
x -= *nspace * shortfall / nspaces;
- (void) string_width(pdata->fonts[findex], str, &errs);
+ (void) string_width(pdata->fonts[findex], str, &errs, flags);
if (errs && text->alt)
x = render_text(page, pdata, ldata, x, y, text->alt, NULL,
if (errs && text->alt)
x = render_text(page, pdata, ldata, x, y, text->alt, NULL,
conf);
else
x = render_string(page, pdata->fonts[findex],
conf);
else
x = render_string(page, pdata->fonts[findex],
- pdata->sizes[findex], x, y, str);
+ pdata->sizes[findex], x, y, str, flags);
pdata->sizes[FONT_NORMAL],
conf->left_margin + x,
(conf->paper_height - conf->top_margin -
pdata->sizes[FONT_NORMAL],
conf->left_margin + x,
(conf->paper_height - conf->top_margin -
- pdata->last->ypos), L".");
+ pdata->last->ypos), L".", 0);
render_string(pdata->last->page,
pdata->fonts[FONT_NORMAL],
pdata->sizes[FONT_NORMAL],
conf->paper_width - conf->right_margin - wid,
(conf->paper_height - conf->top_margin -
render_string(pdata->last->page,
pdata->fonts[FONT_NORMAL],
pdata->sizes[FONT_NORMAL],
conf->paper_width - conf->right_margin - wid,
(conf->paper_height - conf->top_margin -
- pdata->last->ypos), num);
+ pdata->last->ypos), num, 0);
fi->widths = NULL;
fi->fp = NULL;
fi->kerns = newtree234(kern_cmp);
fi->widths = NULL;
fi->fp = NULL;
fi->kerns = newtree234(kern_cmp);
+ fi->ligs = newtree234(lig_cmp);
fi->fontbbox[0] = fi->fontbbox[1] = fi->fontbbox[2] = fi->fontbbox[3] = 0;
fi->capheight = fi->xheight = fi->ascent = fi->descent = 0;
fi->stemh = fi->stemv = fi->italicangle = 0;
fi->fontbbox[0] = fi->fontbbox[1] = fi->fontbbox[2] = fi->fontbbox[3] = 0;
fi->capheight = fi->xheight = fi->ascent = fi->descent = 0;
fi->stemh = fi->stemv = fi->italicangle = 0;
typedef struct document_Tag document;
typedef struct kern_pair_Tag kern_pair;
typedef struct document_Tag document;
typedef struct kern_pair_Tag kern_pair;
+typedef struct ligature_Tag ligature;
typedef struct font_info_Tag font_info;
typedef struct font_data_Tag font_data;
typedef struct font_encoding_Tag font_encoding;
typedef struct font_info_Tag font_info;
typedef struct font_data_Tag font_data;
typedef struct font_encoding_Tag font_encoding;
+ * ... and this one represents a ligature.
+ */
+struct ligature_Tag {
+ unsigned short left, right, lig;
+};
+
+/*
* This data structure holds static information about a font that doesn't
* depend on the particular document. It gets generated when the font's
* metrics are read in.
* This data structure holds static information about a font that doesn't
* depend on the particular document. It gets generated when the font's
* metrics are read in.
unsigned short *glyphsbyname;
/* A tree of kern_pairs */
tree234 *kerns;
unsigned short *glyphsbyname;
/* A tree of kern_pairs */
tree234 *kerns;
+ /* ... and one of ligatures */
+ tree234 *ligs;
/*
* For reasonably speedy lookup, we set up a 65536-element
* table representing the Unicode BMP (I can conveniently
/*
* For reasonably speedy lookup, we set up a 65536-element
* table representing the Unicode BMP (I can conveniently
* Functions exported from bk_paper.c
*/
int kern_cmp(void *, void *); /* use when setting up kern_pairs */
* Functions exported from bk_paper.c
*/
int kern_cmp(void *, void *); /* use when setting up kern_pairs */
+int lig_cmp(void *, void *); /* use when setting up ligatures */
void font_index_glyphs(font_info *fi);
void font_index_glyphs(font_info *fi);
-int find_glyph(font_info *fi, char const *name);
+int find_glyph(font_info const *fi, char const *name);
+/*
+ * Rough kludge to get ligatures in until this is all rewritten. All
+ * the standard fonts have the same ligatures anyway.
+ */
+static ligature const ps_std_ligs[] = {
+ {31,34,160}, {31,37,162}, {0xFFFF,0xFFFF,0xFFFF}
+};
+
void init_std_fonts(void) {
int i, j;
void init_std_fonts(void) {
int i, j;
kern_pair const *kern;
static int done = FALSE;
kern_pair const *kern;
static int done = FALSE;
fi->kerns = newtree234(kern_cmp);
for (kern = ps_std_fonts[i].kerns; kern->left != 0xFFFF; kern++)
add234(fi->kerns, (void *)kern);
fi->kerns = newtree234(kern_cmp);
for (kern = ps_std_fonts[i].kerns; kern->left != 0xFFFF; kern++)
add234(fi->kerns, (void *)kern);
+ fi->ligs = newtree234(lig_cmp);
+ for (lig = ps_std_ligs; lig->left != 0xFFFF; lig++)
+ add234(fi->ligs, (void *)lig);
for (j = 0; j < (int)lenof(fi->bmp); j++)
fi->bmp[j] = 0xFFFF;
for (j = 0; j < fi->nglyphs; j++) {
for (j = 0; j < (int)lenof(fi->bmp); j++)
fi->bmp[j] = 0xFFFF;
for (j = 0; j < fi->nglyphs; j++) {