pdf-operators: fix bug that was causing unnecessary repositioning of text

This optimizes the output to increase the maximum amount of text that
is emitted with a single Tj operator.
This commit is contained in:
Adrian Johnson 2010-10-01 19:18:28 +09:30
parent af3b550bc1
commit 165a14b564
2 changed files with 7 additions and 1 deletions

View file

@ -83,6 +83,7 @@ typedef struct _cairo_pdf_operators {
int hex_width; int hex_width;
cairo_bool_t is_latin; cairo_bool_t is_latin;
int num_glyphs; int num_glyphs;
double glyph_buf_x_pos;
cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE]; cairo_pdf_glyph_t glyphs[PDF_GLYPH_BUFFER_SIZE];
/* PDF line style */ /* PDF line style */

View file

@ -1016,6 +1016,7 @@ _cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t *pdf_operators)
} }
pdf_operators->num_glyphs = 0; pdf_operators->num_glyphs = 0;
pdf_operators->glyph_buf_x_pos = pdf_operators->cur_x;
status2 = _cairo_output_stream_destroy (word_wrap_stream); status2 = _cairo_output_stream_destroy (word_wrap_stream);
if (status == CAIRO_STATUS_SUCCESS) if (status == CAIRO_STATUS_SUCCESS)
status = status2; status = status2;
@ -1038,6 +1039,7 @@ _cairo_pdf_operators_add_glyph (cairo_pdf_operators_t *pdf_operators
pdf_operators->glyphs[pdf_operators->num_glyphs].x_position = x_position; pdf_operators->glyphs[pdf_operators->num_glyphs].x_position = x_position;
pdf_operators->glyphs[pdf_operators->num_glyphs].glyph_index = glyph->subset_glyph_index; pdf_operators->glyphs[pdf_operators->num_glyphs].glyph_index = glyph->subset_glyph_index;
pdf_operators->glyphs[pdf_operators->num_glyphs].x_advance = x; pdf_operators->glyphs[pdf_operators->num_glyphs].x_advance = x;
pdf_operators->glyph_buf_x_pos += x;
pdf_operators->num_glyphs++; pdf_operators->num_glyphs++;
if (pdf_operators->num_glyphs == PDF_GLYPH_BUFFER_SIZE) if (pdf_operators->num_glyphs == PDF_GLYPH_BUFFER_SIZE)
return _cairo_pdf_operators_flush_glyphs (pdf_operators); return _cairo_pdf_operators_flush_glyphs (pdf_operators);
@ -1062,6 +1064,7 @@ _cairo_pdf_operators_set_text_matrix (cairo_pdf_operators_t *pdf_operators,
pdf_operators->text_matrix = *matrix; pdf_operators->text_matrix = *matrix;
pdf_operators->cur_x = 0; pdf_operators->cur_x = 0;
pdf_operators->cur_y = 0; pdf_operators->cur_y = 0;
pdf_operators->glyph_buf_x_pos = 0;
_cairo_output_stream_printf (pdf_operators->stream, _cairo_output_stream_printf (pdf_operators->stream,
"%f %f %f %f %f %f Tm\n", "%f %f %f %f %f %f Tm\n",
pdf_operators->text_matrix.xx, pdf_operators->text_matrix.xx,
@ -1117,6 +1120,7 @@ _cairo_pdf_operators_set_text_position (cairo_pdf_operators_t *pdf_operators,
translate.y0); translate.y0);
pdf_operators->cur_x = 0; pdf_operators->cur_x = 0;
pdf_operators->cur_y = 0; pdf_operators->cur_y = 0;
pdf_operators->glyph_buf_x_pos = 0;
pdf_operators->cairo_to_pdftext = pdf_operators->text_matrix; pdf_operators->cairo_to_pdftext = pdf_operators->text_matrix;
status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext); status = cairo_matrix_invert (&pdf_operators->cairo_to_pdftext);
@ -1167,6 +1171,7 @@ _cairo_pdf_operators_begin_text (cairo_pdf_operators_t *pdf_operators)
pdf_operators->in_text_object = TRUE; pdf_operators->in_text_object = TRUE;
pdf_operators->num_glyphs = 0; pdf_operators->num_glyphs = 0;
pdf_operators->glyph_buf_x_pos = 0;
return _cairo_output_stream_get_status (pdf_operators->stream); return _cairo_output_stream_get_status (pdf_operators->stream);
} }
@ -1271,7 +1276,7 @@ _cairo_pdf_operators_emit_glyph (cairo_pdf_operators_t *pdf_operator
* PDF consumers that do not handle very large position * PDF consumers that do not handle very large position
* adjustments in TJ. * adjustments in TJ.
*/ */
if (fabs(x - pdf_operators->cur_x) > 10 || if (fabs(x - pdf_operators->glyph_buf_x_pos) > 10 ||
fabs(y - pdf_operators->cur_y) > GLYPH_POSITION_TOLERANCE) fabs(y - pdf_operators->cur_y) > GLYPH_POSITION_TOLERANCE)
{ {
status = _cairo_pdf_operators_flush_glyphs (pdf_operators); status = _cairo_pdf_operators_flush_glyphs (pdf_operators);