Back to index

tetex-bin  3.0
Functions | Variables
writefont.c File Reference
#include "ptexlib.h"

Go to the source code of this file.

Functions

static void print_key (integer code, integer v)
static void print_italic_angle ()
static integer getstemv (void)
static void getbbox (void)
void update_enc (internalfontnumber f, char **glyph_names)
static void get_char_widths (void)
static void write_char_widths (void)
static void write_fontname (boolean as_reference)
static void write_fontobj (integer font_objnum)
static void write_fontfile (void)
static void write_fontdescriptor (void)
void dopdffont (integer font_objnum, internalfontnumber f)

Variables

static const char perforce_id [] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writefont.c#13 $"
key_entry font_keys [FONT_KEYS_NUM]
internalfontnumber tex_font
boolean fontfile_found
boolean is_otf_font
boolean write_ttf_glyph_names
char fontname_buf [FONTNAME_BUF_SIZE]
static int first_char
static int last_char
static integer char_widths [MAX_CHAR_CODE+1]
static boolean write_fontfile_only
static int char_widths_objnum
static int encoding_objnum
static char ** cur_glyph_names

Function Documentation

void dopdffont ( integer  font_objnum,
internalfontnumber  f 
)

Definition at line 280 of file writefont.c.

{
    int i;
    tex_font = f;
    cur_glyph_names = NULL;
    encoding_objnum = 0;
    write_ttf_glyph_names = false;
    write_fontfile_only = false;
    if (pdffontmap[tex_font] == NULL)
        pdftex_fail("pdffontmap not initialized for font %s", 
                    makecstring(fontname[tex_font]));
    if (hasfmentry(tex_font))
        fm_cur = (fm_entry *) pdffontmap[tex_font];
    else
        fm_cur = NULL;
    if (fm_cur == NULL || (fm_cur->ps_name == NULL && fm_cur->ff_name == NULL)) {
        writet3(font_objnum, tex_font);
        return;
    }

    get_char_widths(); /* update char widths; also check whether this font is
                          used in embedded PDF only; if so then set
                          write_fontfile_only to true */

    if (!write_fontfile_only) { /* encoding vector needed */
        if ((is_reencoded(fm_cur))) {
            read_enc(fm_cur->encoding);
            if (!is_truetype(fm_cur)) {
                write_enc(NULL, fm_cur->encoding, 0);
                encoding_objnum = (fm_cur->encoding)->objnum;
            }
            else
                write_ttf_glyph_names = true;
        }
        else if (is_fontfile(fm_cur) && !is_truetype(fm_cur)) {
            encoding_objnum = pdfnewobjnum();
        }
    }
    if (is_included(fm_cur))
        write_fontfile();
    if (fm_cur->fn_objnum != 0) {
        pdfbeginobj(fm_cur->fn_objnum);
        write_fontname(false);
        pdfendobj();
    }
    if (!write_fontfile_only)
        write_fontobj(font_objnum);
    if (is_basefont(fm_cur) && !is_included(fm_cur))
        return;
    if (!write_fontfile_only) {
        write_fontdescriptor();
        write_char_widths();
    }
    if (cur_glyph_names == t1_builtin_glyph_names) {
        if (!write_fontfile_only) {
            for (i = 0; i <= MAX_CHAR_CODE; i++)
                if (!pdfcharmarked(tex_font, i) && cur_glyph_names[i] != notdef) {
                    xfree(cur_glyph_names[i]);
                    cur_glyph_names[i] = (char*) notdef;
                }
            write_enc(cur_glyph_names, NULL, encoding_objnum);
        }
        for (i = 0; i <= MAX_CHAR_CODE; i++)
            if (cur_glyph_names[i] != notdef)
                xfree(cur_glyph_names[i]);
    }
}

Here is the call graph for this function:

static void get_char_widths ( void  ) [static]

Definition at line 115 of file writefont.c.

{
    int i;
    for (i = 0; i <= MAX_CHAR_CODE; i++) {
        if (i < fontbc[tex_font] || i > fontec[tex_font])
            char_widths[i] = 0;
        else
            char_widths[i] = getcharwidth(tex_font, i);
    }
    for (i = fontbc[tex_font]; i <= 32; i++)
        char_widths[pdfcharmap[tex_font][i]] = char_widths[i];
    for (i = fontbc[tex_font]; i <= MAX_CHAR_CODE; i++)
        if (pdfcharmarked(tex_font, i))
            break;
    first_char = i;
    for (i = MAX_CHAR_CODE; i > first_char;  i--)
        if (pdfcharmarked(tex_font, i))
            break;
    last_char = i;
    if ((first_char > last_char) ||
        (first_char == last_char && !pdfcharmarked(tex_font, first_char))) { 
        write_fontfile_only = true; /* the font is used in PDF images only */
        return;
    }
    for (i = first_char; i <= last_char; i++)
        if (pdfcharmarked(tex_font, i))
            char_widths[i] = dividescaled(char_widths[i], 
                                          pdffontsize[tex_font], 3);
        else
            char_widths[i] = 0;
    if (is_reencoded(fm_cur) && pdfmovechars > 0) {
        read_enc(fm_cur->encoding);
        update_enc(f, (fm_cur->encoding)->glyph_names);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void getbbox ( void  ) [static]

Definition at line 80 of file writefont.c.

{
    font_keys[FONTBBOX1_CODE].value = 0;
    font_keys[FONTBBOX2_CODE].value = 
        dividescaled(-getchardepth(tex_font, 'y'), pdffontsize[tex_font], 3);
    font_keys[FONTBBOX3_CODE].value =
        dividescaled(getquad(tex_font), pdffontsize[tex_font], 3);
    font_keys[FONTBBOX4_CODE].value =
        dividescaled(getcharheight(tex_font, 'H'), pdffontsize[tex_font], 3);
}

Here is the caller graph for this function:

static integer getstemv ( void  ) [static]

Definition at line 75 of file writefont.c.

{
    return getcharwidth(tex_font, '.')/3;
}

Here is the caller graph for this function:

static void print_italic_angle ( ) [static]

Definition at line 65 of file writefont.c.

{
    pdf_printf("/%s ", font_keys[ITALIC_ANGLE_CODE].pdfname);
    if (font_keys[ITALIC_ANGLE_CODE].valid)
        pdf_printf("%g", font_keys[ITALIC_ANGLE_CODE].value);
    else
        pdf_printf("%g", -atan(getslant(tex_font)/65536.0)*(180/M_PI));
    pdf_puts("\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_key ( integer  code,
integer  v 
) [static]

Definition at line 55 of file writefont.c.

{
    pdf_printf("/%s ", font_keys[code].pdfname);
    if (font_keys[code].valid)
        pdf_printf("%i", (int)font_keys[code].value);
    else
        pdf_printf("%i", (int)dividescaled(v, pdffontsize[tex_font], 3));
    pdf_puts("\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void update_enc ( internalfontnumber  f,
char **  glyph_names 
)

Definition at line 95 of file writefont.c.

{
    int i;
    fm_entry *fm = (fm_entry *) pdffontmap[f];
    if (fontec[f] > 127 || (hasfmentry(f) &&
         (is_reencoded(fm) && (fm->encoding)->updated)))
        return;
    for (i = fontbc[f]; i <= 32; i++)
        if (pdfcharmap[f][i] != i) {
            if (glyph_names[i + MOVE_CHARS_OFFSET] != notdef)
                xfree(glyph_names[i + MOVE_CHARS_OFFSET]);
            if (glyph_names[i] != notdef)
                glyph_names[i + MOVE_CHARS_OFFSET] = xstrdup(glyph_names[i]);
            else
                glyph_names[i + MOVE_CHARS_OFFSET] = (char*) notdef;
        }
    if (is_reencoded(fm))
        (fm->encoding)->updated = true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_char_widths ( void  ) [static]

Definition at line 151 of file writefont.c.

{
    int i;
    pdfbeginobj(char_widths_objnum); 
    pdf_puts("[");
    for (i = first_char; i <= last_char; i++)
        pdf_printf("%i ", char_widths[i]);
    pdf_puts("]\n");
    pdfendobj();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_fontdescriptor ( void  ) [static]

Definition at line 236 of file writefont.c.

{
    int i;
    pdfbegindict(fm_cur->fd_objnum); /* font descriptor */
    print_key(ASCENT_CODE, getcharheight(tex_font, 'h'));
    print_key(CAPHEIGHT_CODE, getcharheight(tex_font, 'H'));
    print_key(DESCENT_CODE, -getchardepth(tex_font, 'y'));
    pdf_printf("/FontName ");
    write_fontname(true);
    print_italic_angle();
    print_key(STEMV_CODE, getstemv());
    print_key(XHEIGHT_CODE, getxheight(tex_font));
    if (!font_keys[FONTBBOX1_CODE].valid) {
        getbbox();
    }
    pdf_printf("/%s [%i %i %i %i]\n",
               font_keys[FONTBBOX1_CODE].pdfname,
               (int)font_keys[FONTBBOX1_CODE].value,
               (int)font_keys[FONTBBOX2_CODE].value,
               (int)font_keys[FONTBBOX3_CODE].value,
               (int)font_keys[FONTBBOX4_CODE].value);
    if (!fontfile_found && fm_cur->flags == 4)
        pdf_puts("/Flags 34\n"); /* assumes a roman sans serif font */
    else
        pdf_printf("/Flags %i\n", (int)fm_cur->flags);
    if (is_included(fm_cur) && fontfile_found) {
        if (is_subsetted(fm_cur) && !is_truetype(fm_cur)) {
            cur_glyph_names = t1_glyph_names;
            pdf_puts("/CharSet (");
            for (i = 0; i <= MAX_CHAR_CODE; i++)
                if (pdfcharmarked(tex_font, i) && cur_glyph_names[i] != notdef)
                    pdf_printf("/%s", cur_glyph_names[i]);
            pdf_puts(")\n");
        }
        if (is_truetype(fm_cur))
            pdf_printf("/FontFile2 %i 0 R\n", fm_cur->ff_objnum);
        else if (is_otf_font)
            pdf_printf("/FontFile3 %i 0 R\n", fm_cur->ff_objnum);
        else
            pdf_printf("/FontFile %i 0 R\n", fm_cur->ff_objnum);
    }
    pdfenddict();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_fontfile ( void  ) [static]

Definition at line 207 of file writefont.c.

{
    int i;
    for (i = 0; i < FONT_KEYS_NUM; i++)
        font_keys[i].valid = false;
    fontfile_found = false;
    is_otf_font = false;
    if (is_truetype(fm_cur))
        writettf();
    else
        writet1();
    if (!fontfile_found || !is_included(fm_cur))
        return;
    if (fm_cur->ff_objnum == 0)
        pdftex_fail("font file object number for `%s' not initialized",
                    fm_cur->tfm_name);
    pdfbegindict(fm_cur->ff_objnum); /* font file stream */
    if (is_truetype(fm_cur))
        pdf_printf("/Length1 %i\n", (int)ttf_length);
    else if (is_otf_font) 
        pdf_printf("/Subtype /Type1C\n");
    else
        pdf_printf("/Length1 %i\n/Length2 %i\n/Length3 %i\n",
                   (int)t1_length1, (int)t1_length2, (int)t1_length3);
    pdfbeginstream();
    fb_flush();
    pdfendstream();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_fontname ( boolean  as_reference) [static]

Definition at line 162 of file writefont.c.

{
    if (as_reference && fm_cur->fn_objnum != 0) {
        pdf_printf("%i 0 R\n", (int)fm_cur->fn_objnum);
        return;
    }
    pdf_puts("/");
    if (fm_cur->subset_tag != NULL)
        pdf_printf("%s+", fm_cur->subset_tag);
    if (font_keys[FONTNAME_CODE].valid)
        pdf_printf("%s", fontname_buf);
    else if (fm_cur->ps_name != NULL)
        pdf_printf("%s", fm_cur->ps_name);
    else
        pdf_printf("%s", fm_cur->tfm_name);
    pdf_puts("\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void write_fontobj ( integer  font_objnum) [static]

Definition at line 180 of file writefont.c.

{
    pdfbegindict(font_objnum);
    pdf_puts("/Type /Font\n");
    pdf_printf("/Subtype /%s\n", is_truetype(fm_cur) ? "TrueType" : "Type1");
    if (encoding_objnum != 0)
        pdf_printf("/Encoding %i 0 R\n", (int)encoding_objnum);
    if (pdffontattr[tex_font] != getnullstr()) {
        pdfprint(pdffontattr[tex_font]);
        pdf_puts("\n");
    }
    if (is_basefont(fm_cur) && !is_included(fm_cur)) {
        pdf_printf("/BaseFont /%s\n", fm_cur->ps_name);
        pdfenddict();
        return;
    }
    char_widths_objnum = pdfnewobjnum();
    pdf_printf("/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
               first_char, last_char, char_widths_objnum);
    pdf_printf("/BaseFont ");
    write_fontname(true);
    if (fm_cur->fd_objnum == 0)
        fm_cur->fd_objnum = pdfnewobjnum();
    pdf_printf("/FontDescriptor %i 0 R\n", fm_cur->fd_objnum);
    pdfenddict();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file writefont.c.

Definition at line 51 of file writefont.c.

char** cur_glyph_names [static]

Definition at line 53 of file writefont.c.

int encoding_objnum [static]

Definition at line 51 of file writefont.c.

int first_char [static]

Definition at line 48 of file writefont.c.

Initial value:
 {
    {"Ascent",       "Ascender",     0, false},
    {"CapHeight",    "CapHeight",    0, false},
    {"Descent",      "Descender",    0, false},
    {"FontName",     "FontName",     0, false},
    {"ItalicAngle",  "ItalicAngle",  0, false},
    {"StemV",        "StdVW",        0, false},
    {"XHeight",      "XHeight",      0, false},
    {"FontBBox",     "FontBBox",     0, false},
    {"",             "",             0, false},
    {"",             "",             0, false},
    {"",             "",             0, false}
}

Definition at line 28 of file writefont.c.

Definition at line 43 of file writefont.c.

Definition at line 46 of file writefont.c.

Definition at line 44 of file writefont.c.

int last_char [static]

Definition at line 48 of file writefont.c.

const char perforce_id[] = "$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writefont.c#13 $" [static]

Definition at line 25 of file writefont.c.

internalfontnumber tex_font

Definition at line 42 of file writefont.c.

Definition at line 50 of file writefont.c.

Definition at line 45 of file writefont.c.