Commit ea932921 authored by Matthias Clasen's avatar Matthias Clasen Committed by Behdad Esfahbod

image compositor: Support subpixel positioning

Support subpixel positioning with a 4x4 subpixel grid.

When compositing glyphs in the image compositor,
we store the subpixel phases in the high bits of the
glyph index. The _cairo_scaled_glyph_index() macro
has been updated to discard these bits. By storing
the phases in the glyph index, the glyph cache just
keeps working. When loading a glyph, the Freetype
font backend shifts the outline according to the
phases.
parent bab53d91
......@@ -2455,6 +2455,16 @@ _cairo_ft_scaled_glyph_load_glyph (cairo_ft_scaled_font_t *scaled_font,
if (vertical_layout)
_cairo_ft_scaled_glyph_vertical_layout_bearing_fix (scaled_font, face->glyph);
if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
FT_Pos xshift, yshift;
xshift = _cairo_scaled_glyph_xphase (scaled_glyph) << 4;
yshift = _cairo_scaled_glyph_yphase (scaled_glyph) << 4;
FT_Outline_Translate (&face->glyph->outline, xshift, yshift);
}
return CAIRO_STATUS_SUCCESS;
}
......
......@@ -847,6 +847,9 @@ _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font,
CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex);
}
#define PHASE(x) ((int)(floor (4 * (x + 0.125)) - 4 * floor (x + 0.125)))
#define POSITION(x) ((int) floor (x + 0.125))
static cairo_int_status_t
composite_glyphs (void *_dst,
cairo_operator_t op,
......@@ -888,6 +891,12 @@ composite_glyphs (void *_dst,
for (i = 0; i < info->num_glyphs; i++) {
unsigned long index = info->glyphs[i].index;
const void *glyph;
int xphase, yphase;
xphase = PHASE(info->glyphs[i].x);
yphase = PHASE(info->glyphs[i].y);
index = index | (xphase << 24) | (yphase << 26);
glyph = pixman_glyph_cache_lookup (glyph_cache, info->font, (void *)index);
if (!glyph) {
......@@ -917,8 +926,8 @@ composite_glyphs (void *_dst,
}
}
pg->x = _cairo_lround (info->glyphs[i].x);
pg->y = _cairo_lround (info->glyphs[i].y);
pg->x = POSITION (info->glyphs[i].x);
pg->y = POSITION (info->glyphs[i].y);
pg->glyph = glyph;
pg++;
}
......
......@@ -428,7 +428,10 @@ _cairo_hash_bytes (unsigned long hash,
const void *bytes,
unsigned int length);
#define _cairo_scaled_glyph_index(g) ((g)->hash_entry.hash)
/* We use bits 24-27 to store phases for subpixel positions */
#define _cairo_scaled_glyph_index(g) ((g)->hash_entry.hash & 0xffffff)
#define _cairo_scaled_glyph_xphase(g) (int)(((g)->hash_entry.hash >> 24) & 3)
#define _cairo_scaled_glyph_yphase(g) (int)(((g)->hash_entry.hash >> 26) & 3)
#define _cairo_scaled_glyph_set_index(g, i) ((g)->hash_entry.hash = (i))
#include "cairo-scaled-font-private.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment