Skip to content

Commit

Permalink
pdf-operators: output (abc) style strings when font is latin
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Johnson committed Oct 1, 2010
1 parent f1ca978 commit 807e690
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/cairo-pdf-operators-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct _cairo_pdf_operators {
double cur_x; /* Current position in PDF text space (Tm in the PDF reference) */
double cur_y;
int hex_width;
cairo_bool_t is_latin;
int num_glyphs;
cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE];

Expand Down
57 changes: 42 additions & 15 deletions src/cairo-pdf-operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,26 @@ _cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t *pdf_operators,
operator);
}

static void
_cairo_pdf_operators_emit_glyph_index (cairo_pdf_operators_t *pdf_operators,
cairo_output_stream_t *stream,
unsigned int glyph)
{
if (pdf_operators->is_latin) {
if (glyph == '(' || glyph == ')' || glyph == '\\')
_cairo_output_stream_printf (stream, "\\%c", glyph);
else if (glyph >= 0x20 && glyph <= 0x7e)
_cairo_output_stream_printf (stream, "%c", glyph);
else
_cairo_output_stream_printf (stream, "\\%03o", glyph);
} else {
_cairo_output_stream_printf (stream,
"%0*x",
pdf_operators->hex_width,
glyph);
}
}

#define GLYPH_POSITION_TOLERANCE 0.001

/* Emit the string of glyphs using the 'Tj' operator. This requires
Expand All @@ -890,15 +910,14 @@ _cairo_pdf_operators_emit_glyph_string (cairo_pdf_operators_t *pdf_operators,
{
int i;

_cairo_output_stream_printf (stream, "<");
_cairo_output_stream_printf (stream, "%s", pdf_operators->is_latin ? "(" : "<");
for (i = 0; i < pdf_operators->num_glyphs; i++) {
_cairo_output_stream_printf (stream,
"%0*x",
pdf_operators->hex_width,
pdf_operators->glyphs[i].glyph_index);
_cairo_pdf_operators_emit_glyph_index (pdf_operators,
stream,
pdf_operators->glyphs[i].glyph_index);
pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance;
}
_cairo_output_stream_printf (stream, ">Tj\n");
_cairo_output_stream_printf (stream, "%sTj\n", pdf_operators->is_latin ? ")" : ">");

return _cairo_output_stream_get_status (stream);
}
Expand All @@ -918,7 +937,7 @@ _cairo_pdf_operators_emit_glyph_string_with_positioning (
{
int i;

_cairo_output_stream_printf (stream, "[<");
_cairo_output_stream_printf (stream, "[%s", pdf_operators->is_latin ? "(" : "<");
for (i = 0; i < pdf_operators->num_glyphs; i++) {
if (pdf_operators->glyphs[i].x_position != pdf_operators->cur_x)
{
Expand All @@ -934,10 +953,18 @@ _cairo_pdf_operators_emit_glyph_string_with_positioning (
* calculating subsequent deltas.
*/
rounded_delta = _cairo_lround (delta);
if (abs(rounded_delta) < 3)
rounded_delta = 0;
if (rounded_delta != 0) {
_cairo_output_stream_printf (stream,
">%d<",
rounded_delta);
if (pdf_operators->is_latin) {
_cairo_output_stream_printf (stream,
")%d(",
rounded_delta);
} else {
_cairo_output_stream_printf (stream,
">%d<",
rounded_delta);
}
}

/* Convert the rounded delta back to text
Expand All @@ -947,13 +974,12 @@ _cairo_pdf_operators_emit_glyph_string_with_positioning (
pdf_operators->cur_x += delta;
}

_cairo_output_stream_printf (stream,
"%0*x",
pdf_operators->hex_width,
pdf_operators->glyphs[i].glyph_index);
_cairo_pdf_operators_emit_glyph_index (pdf_operators,
stream,
pdf_operators->glyphs[i].glyph_index);
pdf_operators->cur_x += pdf_operators->glyphs[i].x_advance;
}
_cairo_output_stream_printf (stream, ">]TJ\n");
_cairo_output_stream_printf (stream, "%s]TJ\n", pdf_operators->is_latin ? ")" : ">");

return _cairo_output_stream_get_status (stream);
}
Expand Down Expand Up @@ -1124,6 +1150,7 @@ _cairo_pdf_operators_set_font_subset (cairo_pdf_operators_t *pdf_ope
}
pdf_operators->font_id = subset_glyph->font_id;
pdf_operators->subset_id = subset_glyph->subset_id;
pdf_operators->is_latin = subset_glyph->is_latin;

if (subset_glyph->is_composite)
pdf_operators->hex_width = 4;
Expand Down

0 comments on commit 807e690

Please sign in to comment.