mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 01:48:07 +02:00
[script] Use a compact representation for horizontal offsets between glyphs
Kerning is quite frequent, that is to apply a horizontal but no vertical offset to a glyph. For instance by discarding the vertical coordinate where it remains the same and only encoding the horizontal offset we reduce the file size by ~12.5% when tracing poppler.
This commit is contained in:
parent
cbee97f0e3
commit
bb919584c0
2 changed files with 55 additions and 23 deletions
|
|
@ -2763,6 +2763,9 @@ _cairo_script_surface_show_text_glyphs (void *abstract_surface,
|
|||
_cairo_scaled_font_thaw_cache (scaled_font);
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((long unsigned) scaled_glyph->surface_private > 256)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2783,26 +2786,45 @@ _cairo_script_surface_show_text_glyphs (void *abstract_surface,
|
|||
break;
|
||||
|
||||
if (fabs (glyphs[n].x - x) > 1e-5 || fabs (glyphs[n].y - y) > 1e-5) {
|
||||
ix = x = glyphs[n].x;
|
||||
iy = y = glyphs[n].y;
|
||||
cairo_matrix_transform_point (&matrix, &ix, &iy);
|
||||
ix -= scaled_font->font_matrix.x0;
|
||||
iy -= scaled_font->font_matrix.y0;
|
||||
if (base85_stream != NULL) {
|
||||
status = _cairo_output_stream_destroy (base85_stream);
|
||||
if (unlikely (status)) {
|
||||
base85_stream = NULL;
|
||||
break;
|
||||
if (fabs (glyphs[n].y - y) < 1e-5) {
|
||||
if (base85_stream != NULL) {
|
||||
status = _cairo_output_stream_destroy (base85_stream);
|
||||
if (unlikely (status)) {
|
||||
base85_stream = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" %f <~", glyphs[n].x - x);
|
||||
base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
|
||||
} else {
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" ] %f [ ", glyphs[n].x - x);
|
||||
}
|
||||
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" %f %f <~",
|
||||
ix, iy);
|
||||
base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
|
||||
x = glyphs[n].x;
|
||||
} else {
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" ] %f %f [ ",
|
||||
ix, iy);
|
||||
ix = x = glyphs[n].x;
|
||||
iy = y = glyphs[n].y;
|
||||
cairo_matrix_transform_point (&matrix, &ix, &iy);
|
||||
ix -= scaled_font->font_matrix.x0;
|
||||
iy -= scaled_font->font_matrix.y0;
|
||||
if (base85_stream != NULL) {
|
||||
status = _cairo_output_stream_destroy (base85_stream);
|
||||
if (unlikely (status)) {
|
||||
base85_stream = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" %f %f <~",
|
||||
ix, iy);
|
||||
base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
|
||||
} else {
|
||||
_cairo_output_stream_printf (surface->ctx->stream,
|
||||
" ] %f %f [ ",
|
||||
ix, iy);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (base85_stream != NULL) {
|
||||
|
|
|
|||
|
|
@ -2351,7 +2351,7 @@ _glyph_string (csi_t *ctx,
|
|||
cairo_scaled_font_t *scaled_font,
|
||||
cairo_glyph_t *glyphs)
|
||||
{
|
||||
double x,y;
|
||||
double x,y, dx;
|
||||
csi_integer_t nglyphs, i, j;
|
||||
struct glyph_advance_cache *cache;
|
||||
cairo_status_t status;
|
||||
|
|
@ -2448,12 +2448,22 @@ _glyph_string (csi_t *ctx,
|
|||
}
|
||||
|
||||
case CSI_OBJECT_TYPE_INTEGER:
|
||||
case CSI_OBJECT_TYPE_REAL: /* dx */
|
||||
x = csi_number_get_value (obj);
|
||||
if (++i == array->stack.len)
|
||||
case CSI_OBJECT_TYPE_REAL: /* dx or x*/
|
||||
dx = csi_number_get_value (obj);
|
||||
if (i+1 == array->stack.len)
|
||||
break;
|
||||
y = csi_number_get_value (&array->stack.objects[i]);
|
||||
break;
|
||||
|
||||
switch ((int) csi_object_get_type (&array->stack.objects[i+1])) {
|
||||
case CSI_OBJECT_TYPE_INTEGER:
|
||||
case CSI_OBJECT_TYPE_REAL: /* y */
|
||||
y = csi_number_get_value (&array->stack.objects[i+1]);
|
||||
x = dx;
|
||||
i++;
|
||||
break;
|
||||
|
||||
default:
|
||||
x += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue