[cairo-commit] 2 commits - src/win32
Chris Wilson
ickle at kemper.freedesktop.org
Thu Mar 22 05:30:29 PDT 2012
src/win32/cairo-win32-font.c | 267 +++++++++----------------------------------
1 file changed, 61 insertions(+), 206 deletions(-)
New commits:
commit be8a5f13b712920940c4819af59b77a291153870
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Mar 22 12:25:58 2012 +0000
win32: Remove obsolete font rendering routines
These are now done by cairo-win32-gdi-compositor.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/win32/cairo-win32-font.c b/src/win32/cairo-win32-font.c
index 5602fd7..d85d5c9 100644
--- a/src/win32/cairo-win32-font.c
+++ b/src/win32/cairo-win32-font.c
@@ -1296,74 +1296,6 @@ _draw_glyphs_on_surface (cairo_win32_surface_t *surface,
return status;
}
-#if 0
-/* Duplicate the green channel of a 4-channel mask in the alpha channel, then
- * invert the whole mask.
- */
-static void
-_compute_argb32_mask_alpha (cairo_win32_surface_t *mask_surface)
-{
- cairo_image_surface_t *image = (cairo_image_surface_t *)mask_surface->image;
- int i, j;
-
- for (i = 0; i < image->height; i++) {
- uint32_t *p = (uint32_t *) (image->data + i * image->stride);
- for (j = 0; j < image->width; j++) {
- *p = 0xffffffff ^ (*p | ((*p & 0x0000ff00) << 16));
- p++;
- }
- }
-}
-
-/* Invert a mask
- */
-static void
-_invert_argb32_mask (cairo_win32_surface_t *mask_surface)
-{
- cairo_image_surface_t *image = (cairo_image_surface_t *)mask_surface->image;
- int i, j;
-
- for (i = 0; i < image->height; i++) {
- uint32_t *p = (uint32_t *) (image->data + i * image->stride);
- for (j = 0; j < image->width; j++) {
- *p = 0xffffffff ^ *p;
- p++;
- }
- }
-}
-
-/* Compute an alpha-mask from a monochrome RGB24 image
- */
-static cairo_surface_t *
-_compute_a8_mask (cairo_win32_surface_t *mask_surface)
-{
- cairo_image_surface_t *image24 = (cairo_image_surface_t *)mask_surface->image;
- cairo_image_surface_t *image8;
- int i, j;
-
- if (image24->base.status)
- return cairo_surface_reference (&image24->base);
-
- image8 = (cairo_image_surface_t *)cairo_image_surface_create (CAIRO_FORMAT_A8,
- image24->width, image24->height);
- if (image8->base.status)
- return &image8->base;
-
- for (i = 0; i < image24->height; i++) {
- uint32_t *p = (uint32_t *) (image24->data + i * image24->stride);
- unsigned char *q = (unsigned char *) (image8->data + i * image8->stride);
-
- for (j = 0; j < image24->width; j++) {
- *q = 255 - ((*p & 0x0000ff00) >> 8);
- p++;
- q++;
- }
- }
-
- return &image8->base;
-}
-#endif
-
static cairo_int_status_t
_cairo_win32_scaled_font_glyph_init (void *abstract_font,
cairo_scaled_glyph_t *scaled_glyph,
@@ -1393,125 +1325,6 @@ _cairo_win32_scaled_font_glyph_init (void *abstract_font,
return CAIRO_STATUS_SUCCESS;
}
-#if 0
-static cairo_int_status_t
-_cairo_win32_scaled_font_show_glyphs (void *abstract_font,
- cairo_operator_t op,
- const cairo_pattern_t *pattern,
- cairo_surface_t *generic_surface,
- int source_x,
- int source_y,
- int dest_x,
- int dest_y,
- unsigned int width,
- unsigned int height,
- cairo_glyph_t *glyphs,
- int num_glyphs,
- cairo_region_t *clip_region,
- int *remaining_glyphs)
-{
- cairo_win32_scaled_font_t *scaled_font = abstract_font;
- cairo_win32_surface_t *surface = (cairo_win32_surface_t *)generic_surface;
- cairo_status_t status;
-
- if (width == 0 || height == 0)
- return CAIRO_STATUS_SUCCESS;
-
- if (_cairo_surface_is_win32 (generic_surface) &&
- surface->format == CAIRO_FORMAT_RGB24 &&
- op == CAIRO_OPERATOR_OVER &&
- _cairo_pattern_is_opaque_solid (pattern)) {
-
- cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)pattern;
-
- /* When compositing OVER on a GDI-understood surface, with a
- * solid opaque color, we can just call ExtTextOut directly.
- */
- COLORREF new_color;
-
- status = _cairo_win32_surface_set_clip_region (surface, clip_region);
- if (unlikely (status))
- return status;
-
- new_color = RGB (((int)solid_pattern->color.red_short) >> 8,
- ((int)solid_pattern->color.green_short) >> 8,
- ((int)solid_pattern->color.blue_short) >> 8);
-
- return _draw_glyphs_on_surface (surface, scaled_font, new_color,
- 0, 0,
- glyphs, num_glyphs);
- } else {
- /* Otherwise, we need to draw using software fallbacks. We create a mask
- * surface by drawing the the glyphs onto a DIB, black-on-white then
- * inverting. GDI outputs gamma-corrected images so inverted black-on-white
- * is very different from white-on-black. We favor the more common
- * case where the final output is dark-on-light.
- */
- cairo_win32_surface_t *tmp_surface;
- cairo_surface_t *mask_surface;
- cairo_surface_pattern_t mask;
- RECT r;
-
- tmp_surface = (cairo_win32_surface_t *)cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, width, height);
- if (tmp_surface->base.status)
- return tmp_surface->base.status;
-
- r.left = 0;
- r.top = 0;
- r.right = width;
- r.bottom = height;
- FillRect (tmp_surface->dc, &r, GetStockObject (WHITE_BRUSH));
-
- status = _draw_glyphs_on_surface (tmp_surface,
- scaled_font, RGB (0, 0, 0),
- dest_x, dest_y,
- glyphs, num_glyphs);
- if (status) {
- cairo_surface_destroy (&tmp_surface->base);
- return status;
- }
-
- if (scaled_font->quality == CLEARTYPE_QUALITY) {
- /* For ClearType, we need a 4-channel mask. If we are compositing on
- * a surface with alpha, we need to compute the alpha channel of
- * the mask (we just copy the green channel). But for a destination
- * surface without alpha the alpha channel of the mask is ignored
- */
-
- if (surface->format != CAIRO_FORMAT_RGB24)
- _compute_argb32_mask_alpha (tmp_surface);
- else
- _invert_argb32_mask (tmp_surface);
-
- mask_surface = &tmp_surface->base;
- } else {
- mask_surface = _compute_a8_mask (tmp_surface);
- cairo_surface_destroy (&tmp_surface->base);
- status = mask_surface->status;
- if (status)
- return status;
- }
-
- /* For op == OVER, no-cleartype, a possible optimization here is to
- * draw onto an intermediate ARGB32 surface and alpha-blend that with the
- * destination
- */
- _cairo_pattern_init_for_surface (&mask, mask_surface);
- cairo_surface_destroy (mask_surface);
-
- if (scaled_font->quality == CLEARTYPE_QUALITY)
- mask.base.has_component_alpha = TRUE;
-
- status = _cairo_surface_mask (&surface->base, op, pattern, &mask.base,
- clip_region);
-
- _cairo_pattern_fini (&mask.base);
-
- return status;
- }
-}
-#endif
-
static cairo_int_status_t
_cairo_win32_scaled_font_load_truetype_table (void *abstract_font,
unsigned long tag,
commit 28b38312235c73aa436e8c1887db3d31620158ec
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Mar 22 12:07:06 2012 +0000
win32: Hook up glyph creation again
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/win32/cairo-win32-font.c b/src/win32/cairo-win32-font.c
index 92658ba..5602fd7 100644
--- a/src/win32/cairo-win32-font.c
+++ b/src/win32/cairo-win32-font.c
@@ -1719,14 +1719,65 @@ _cairo_win32_scaled_font_load_type1_data (void *abstract_font,
length);
}
+static cairo_surface_t *
+_compute_mask (cairo_surface_t *surface,
+ int quality)
+{
+ cairo_image_surface_t *glyph;
+ cairo_image_surface_t *mask;
+ int i, j;
+
+ glyph = (cairo_image_surface_t *)cairo_surface_map_to_image (surface, NULL);
+ if (unlikely (glyph->base.status))
+ return &glyph->base;
+
+ if (quality == CLEARTYPE_QUALITY) {
+ /* Duplicate the green channel of a 4-channel mask into the
+ * alpha channel, then invert the whole mask.
+ */
+ mask = (cairo_image_surface_t *)
+ cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ glyph->width, glyph->height);
+ if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) {
+ for (i = 0; i < glyph->height; i++) {
+ uint32_t *p = (uint32_t *) (glyph->data + i * glyph->stride);
+ uint32_t *q = (uint32_t *) (mask->data + i * mask->stride);
+
+ for (j = 0; j < glyph->width; j++) {
+ *q++ = 0xffffffff ^ (*p | ((*p & 0x0000ff00) << 16));
+ p++;
+ }
+ }
+ }
+ } else {
+ /* Compute an alpha-mask from a using the green channel of a
+ * (presumed monochrome) RGB24 image.
+ */
+ mask = (cairo_image_surface_t *)
+ cairo_image_surface_create (CAIRO_FORMAT_A8,
+ glyph->width, glyph->height);
+ if (likely (mask->base.status == CAIRO_STATUS_SUCCESS)) {
+ for (i = 0; i < glyph->height; i++) {
+ uint32_t *p = (uint32_t *) (glyph->data + i * glyph->stride);
+ uint8_t *q = (uint8_t *) (mask->data + i * mask->stride);
+
+ for (j = 0; j < glyph->width; j++)
+ *q++ = 255 - ((*p++ & 0x0000ff00) >> 8);
+ }
+ }
+ }
+
+ cairo_surface_unmap_image (surface, &glyph->base);
+ return &mask->base;
+}
+
static cairo_status_t
_cairo_win32_scaled_font_init_glyph_surface (cairo_win32_scaled_font_t *scaled_font,
cairo_scaled_glyph_t *scaled_glyph)
{
cairo_status_t status;
cairo_glyph_t glyph;
- cairo_win32_surface_t *surface;
- cairo_t *cr;
+ cairo_surface_t *surface;
cairo_surface_t *image;
int width, height;
int x1, y1, x2, y2;
@@ -1738,33 +1789,24 @@ _cairo_win32_scaled_font_init_glyph_surface (cairo_win32_scaled_font_t *scaled_f
width = x2 - x1;
height = y2 - y1;
- surface = (cairo_win32_surface_t *)
- cairo_win32_surface_create_with_dib (CAIRO_FORMAT_RGB24, width, height);
-
- cr = cairo_create (&surface->base);
- cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_paint (cr);
- status = cairo_status (cr);
- cairo_destroy(cr);
+ surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_RGB24,
+ width, height);
+ status = _cairo_surface_paint (surface, CAIRO_OPERATOR_SOURCE,
+ &_cairo_pattern_white.base, NULL);
if (status)
goto FAIL;
glyph.index = _cairo_scaled_glyph_index (scaled_glyph);
glyph.x = -x1;
glyph.y = -y1;
- status = _draw_glyphs_on_surface (surface, scaled_font, RGB(0,0,0),
+ status = _draw_glyphs_on_surface (to_win32_surface (surface),
+ scaled_font, RGB(0,0,0),
0, 0, &glyph, 1);
if (status)
goto FAIL;
- GdiFlush();
-
-#if 0
- image = _compute_a8_mask (surface);
+ image = _compute_mask (surface, scaled_font->quality);
status = image->status;
-#else
- status = CAIRO_STATUS_NO_MEMORY;
-#endif
if (status)
goto FAIL;
@@ -1774,7 +1816,7 @@ _cairo_win32_scaled_font_init_glyph_surface (cairo_win32_scaled_font_t *scaled_f
(cairo_image_surface_t *) image);
FAIL:
- cairo_surface_destroy (&surface->base);
+ cairo_surface_destroy (surface);
return status;
}
More information about the cairo-commit
mailing list