diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w | 111 |
1 files changed, 35 insertions, 76 deletions
diff --git a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w index 1f8319484e2..93096d025e5 100644 --- a/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w +++ b/Build/source/texk/web2c/luatexdir/pdf/pdfglyph.w @@ -19,24 +19,22 @@ @ @c - #include "ptexlib.h" #include "pdf/pdfpage.h" #define pdf2double(a) ((double) (a).m / ten_pow[(a).e]) @ eternal constants + @c -#define one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ -#define e_tj 3 /* must be 3; movements in []TJ are in fontsize/$10^3$ units */ +#define one_bp ((double) 65536 * (double) 72.27 / 72) /* number of sp per 1bp */ +#define e_tj 3 /* must be 3; movements in []TJ are in fontsize/$10^3$ units */ @ @c static int64_t pdf_char_width(pdfstructure * p, internal_font_number f, int i) { /* use exactly this formula also for calculating the /Width array values */ - return - i64round((double) char_width(f, i) / font_size(f) * - ten_pow[e_tj + p->cw.e]); + return i64round((double) char_width(f, i) / font_size(f) * ten_pow[e_tj + p->cw.e]); } @ @c @@ -56,9 +54,7 @@ static void setup_fontparameters(PDF pdf, internal_font_number f, int ex_glyph) float u = 1.0; pdfstructure *p = pdf->pstruct; /* fix mantis bug \# 0000200 (acroread "feature") */ - if ((font_format(f) == opentype_format || - (font_format(f) == type1_format && font_encodingbytes(f) == 2)) - && font_units_per_em(f) > 0) + if ((font_format(f) == opentype_format || (font_format(f) == type1_format && font_encodingbytes(f) == 2)) && font_units_per_em(f) > 0) u = font_units_per_em(f) / 1000.0; pdf->f_cur = f; p->f_pdf = pdf_set_font(pdf, f); @@ -68,19 +64,14 @@ static void setup_fontparameters(PDF pdf, internal_font_number f, int ex_glyph) expand = 1.0 + (ex_glyph/1) / 1000.0; p->tj_delta.e = p->cw.e - 1; /* "- 1" makes less corrections inside []TJ */ /* no need to be more precise than TeX (1sp) */ - while (p->tj_delta.e > 0 - && (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5) + while (p->tj_delta.e > 0 && (double) font_size(f) / ten_pow[p->tj_delta.e + e_tj] < 0.5) p->tj_delta.e--; /* happens for very tiny fonts */ - assert(p->cw.e >= p->tj_delta.e); /* else we would need, e. g., |ten_pow[-1]| */ p->tm[0].m = i64round(scale * expand * extend * ten_pow[p->tm[0].e]); p->tm[2].m = i64round(slant * ten_pow[p->tm[2].e]); p->tm[3].m = i64round(scale * ten_pow[p->tm[3].e]); - p->k2 = - ten_pow[e_tj + - p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) * - pdf2double(p->tm[0])); + p->k2 = ten_pow[e_tj + p->cw.e] * scale / (ten_pow[p->pdf.h.e] * pdf2double(p->fs) * pdf2double(p->tm[0])); p->cur_ex = ex_glyph ; /* we keep track of the state of ex */ -} +} @ @c @@ -95,7 +86,7 @@ static void set_font(PDF pdf) p->f_pdf_cur = p->f_pdf; p->fs_cur.m = p->fs.m; p->need_tf = false; - p->need_tm = true; /* always follow Tf by Tm */ + p->need_tm = true; /* always follow Tf by Tm */ } @ @c @@ -103,12 +94,13 @@ static void set_textmatrix(PDF pdf, scaledpos pos) { boolean move; pdfstructure *p = pdf->pstruct; - assert(is_textmode(p)); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in set_textmatrix"); move = calc_pdfpos(p, pos); if (p->need_tm || move) { print_pdf_matrix(pdf, p->tm); pdf_puts(pdf, " Tm "); - p->pdf.h.m = p->pdf_bt_pos.h.m + p->tm[4].m; /* Tm replaces */ + p->pdf.h.m = p->pdf_bt_pos.h.m + p->tm[4].m; /* Tm replaces */ p->pdf.v.m = p->pdf_bt_pos.v.m + p->tm[5].m; p->need_tm = false; } @@ -118,6 +110,7 @@ static void set_textmatrix(PDF pdf, scaledpos pos) @ Print out a character to PDF buffer; the character will be printed in octal form in the following cases: chars <= 32, backslash (92), left parenthesis (40), and right parenthesis (41). + @c static void pdf_print_char(PDF pdf, int c) { @@ -144,7 +137,8 @@ static void pdf_print_wide_char(PDF pdf, int c) @ @c static void begin_charmode(PDF pdf, internal_font_number f, pdfstructure * p) { - assert(is_chararraymode(p)); + if (!is_chararraymode(p)) + normal_error("pdf backend","char array mode expected in begin_char_mode"); if (font_encodingbytes(f) == 2) { p->ishex = 1; pdf_out(pdf, '<'); @@ -159,7 +153,8 @@ static void begin_charmode(PDF pdf, internal_font_number f, pdfstructure * p) void end_charmode(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_charmode(p)); + if (!is_charmode(p)) + normal_error("pdf backend","char mode expected in end_char_mode"); if (p->ishex == 1) { p->ishex = 0; pdf_out(pdf, '>'); @@ -173,7 +168,8 @@ void end_charmode(PDF pdf) static void begin_chararray(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_textmode(p)); + if (!is_textmode(p)) + normal_error("pdf backend","text mode expected in begin_char_array"); p->pdf_tj_pos = p->pdf; p->cw.m = 0; pdf_out(pdf, '['); @@ -184,58 +180,28 @@ static void begin_chararray(PDF pdf) void end_chararray(PDF pdf) { pdfstructure *p = pdf->pstruct; - assert(is_chararraymode(p)); + if (!is_chararraymode(p)) + normal_error("pdf backend","char array mode expected in end_char_array"); pdf_puts(pdf, "]TJ\n"); p->pdf = p->pdf_tj_pos; p->mode = PMODE_TEXT; } -@ @c +@ We need to adapt the tm when a font changes. A change can be a change in id +(frontend) or pdf reference (backend, as we share font resources). At such a +change we also need to adapt to the slant and extend. Initially we also need to +take the exfactor of a glyph into account. When the font is unchanged, we still +need to check each glyph for a change in exfactor. We store the current one on +the state record so that we can minimize testing. + +@c void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex) { boolean move; pdfstructure *p = pdf->pstruct; scaledpos pos = pdf->posstruct->pos; - if (!char_exists(f, c)) return; - -/* - p->need_tf : okay, set somewhere else - f != pdf->f_cur : font change - p->f_pdf != p->f_pdf_cur : font change - p->fs.m ~= p->fs_cur.m : move - is_pagemode(p) -> stream change - p->tm0_cur.m -> p->tm[0].m : also move -*/ - - /* fix issue 857 */ - /* /\* ensure to be within BT...ET *\/ */ - /* if (is_pagemode(p)) { */ - /* pdf_goto_textmode(pdf); */ - /* p->need_tf = true; */ - /* } */ - /* /\* all font setup *\/ */ - /* if (true || f != pdf->f_cur || p->need_tf) { */ - /* setup_fontparameters(pdf, f, ex); */ - /* if (p->need_tf || p->f_pdf != p->f_pdf_cur || p->fs.m != p->fs_cur.m) { */ - /* pdf_goto_textmode(pdf); */ - /* set_font(pdf); */ - /* } else if (p->tm0_cur.m != p->tm[0].m) { */ - /* /\* catch in-line HZ expand change due to efcode *\/ */ - /* p->need_tm = true; */ - /* } */ - /* } */ - - - /* LS/HH: We need to adapt the tm when a font changes. A change can be a change in - id (frontend) or pdf reference (backend, as we share font resources). At - such a change we also need to adapt to the slant and extend. Initially - we also need to take the exfactor of a glyph into account. When the font is - unchanged, we still need to check each glyph for a change in exfactor. We - store the current one on the state record so that we can minimize testing. */ - - /* is the p->need_tf test really needed ? */ if (p->need_tf || f != pdf->f_cur || p->f_pdf != p->f_pdf_cur || p->fs.m != p->fs_cur.m || is_pagemode(p)) { pdf_goto_textmode(pdf); setup_fontparameters(pdf, f, ex); @@ -243,37 +209,30 @@ void pdf_place_glyph(PDF pdf, internal_font_number f, int c, int ex) } else if (p->tm0_cur.m != p->tm[0].m || p->cur_ex != ex) { setup_fontparameters(pdf, f, ex); p->need_tm = true; - } - + } /* all movements */ move = calc_pdfpos(p, pos); /* within text or chararray or char mode */ if (move || p->need_tm) { - if (p->need_tm || (p->wmode == WMODE_H - && (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m) - || (p->wmode == WMODE_V - && (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m) - || abs(p->tj_delta.m) >= 1000000) { + if (p->need_tm || (p->wmode == WMODE_H && (p->pdf_bt_pos.v.m + p->tm[5].m) != p->pdf.v.m) + || (p->wmode == WMODE_V && (p->pdf_bt_pos.h.m + p->tm[4].m) != p->pdf.h.m) + || abs(p->tj_delta.m) >= 1000000) { pdf_goto_textmode(pdf); set_textmatrix(pdf, pos); begin_chararray(pdf); move = calc_pdfpos(p, pos); /* for fine adjustment */ } if (move) { - assert((p->wmode == WMODE_H - && (p->pdf_bt_pos.v.m + p->tm[5].m) == p->pdf.v.m) - || (p->wmode == WMODE_V - && (p->pdf_bt_pos.h.m + p->tm[4].m) == p->pdf.h.m)); if (is_charmode(p)) end_charmode(pdf); - assert(p->tj_delta.m != 0); print_pdffloat(pdf, p->tj_delta); p->cw.m -= p->tj_delta.m * ten_pow[p->cw.e - p->tj_delta.e]; } } /* glyph output */ - assert(is_chararraymode(p) || is_charmode(p)); if (is_chararraymode(p)) begin_charmode(pdf, f, p); + else if (!is_charmode(p)) + normal_error("pdf backend","char (array) mode expected in place_glyph"); pdf_mark_char(f, c); if (font_encodingbytes(f) == 2) pdf_print_wide_char(pdf, char_index(f, c)); |