[cairo-commit] 3 commits - src/cairo-ft-font.c
Behdad Esfahbod
behdad at kemper.freedesktop.org
Fri Jul 5 15:54:09 PDT 2013
src/cairo-ft-font.c | 55 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 13 deletions(-)
New commits:
commit 2cc353c3dbe01b4d8f65d6de800f2b1d6004a1c2
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Nov 7 14:34:42 2012 -0800
Towards support loading color glyphs from FreeType
See comments.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 3d2ff27..28e361c 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1128,6 +1128,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
unsigned char *data;
int format = CAIRO_FORMAT_A8;
cairo_image_surface_t *image;
+ cairo_bool_t component_alpha = FALSE;
width = bitmap->width;
height = bitmap->rows;
@@ -1201,8 +1202,24 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
data = bitmap->buffer;
stride = bitmap->pitch;
format = CAIRO_FORMAT_ARGB32;
+ component_alpha = TRUE;
}
break;
+#ifdef FT_LOAD_COLOR
+ case FT_PIXEL_MODE_BGRA:
+ stride = width * 4;
+ if (own_buffer) {
+ data = bitmap->buffer;
+ } else {
+ data = _cairo_malloc_ab (height, stride);
+ if (!data)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
+ memcpy (data, bitmap->buffer, stride * height);
+ }
+ format = CAIRO_FORMAT_ARGB32;
+ break;
+#endif
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
/* These could be triggered by very rare types of TrueType fonts */
@@ -1222,7 +1239,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
return (*surface)->base.status;
}
- if (format == CAIRO_FORMAT_ARGB32)
+ if (component_alpha)
pixman_image_set_component_alpha (image->pixman_image, TRUE);
_cairo_image_surface_assume_ownership_of_data (image);
@@ -1480,7 +1497,7 @@ _transform_glyph_bitmap (cairo_matrix_t * shape,
* the "shape" portion of the font transform
*/
original_to_transformed = *shape;
-
+
cairo_surface_get_device_offset (&(*surface)->base, &origin_x, &origin_y);
orig_width = (*surface)->width;
orig_height = (*surface)->height;
@@ -1530,7 +1547,11 @@ _transform_glyph_bitmap (cairo_matrix_t * shape,
if (unlikely (status))
return status;
- image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
+ if (cairo_image_surface_get_format (*surface) == CAIRO_FORMAT_ARGB32 &&
+ !pixman_image_get_component_alpha ((*surface)->pixman_image))
+ image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ else
+ image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
if (unlikely (image->status))
return image->status;
@@ -2159,6 +2180,20 @@ _cairo_ft_scaled_glyph_init (void *abstract_font,
vertical_layout = TRUE;
}
+#ifdef FT_LOAD_COLOR
+ /* Color-glyph support:
+ *
+ * This flags needs plumbing through fontconfig (does it?), and
+ * maybe we should cache color and grayscale bitmaps separately
+ * such that users of the font (ie. the surface) can choose which
+ * version to use based on target content type.
+ *
+ * Moreover, none of our backends and compositors currently support
+ * color glyphs. As such, this is currently disabled.
+ */
+ /* load_flags |= FT_LOAD_COLOR; */
+#endif
+
error = FT_Load_Glyph (face,
_cairo_scaled_glyph_index(scaled_glyph),
load_flags);
commit e738079302a968b7b1fb9101cd4d92a8887bedce
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Jul 5 15:22:18 2013 -0600
[ft] Fix wrong assumptions
If subpixel rendering is enabled, but FT returns a 8bit gray bitmap
(perhaps because the font has 8bit embedded bitmaps) we were hitting
the assertions because the assumptions made were wrong. Fix up.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 3bba59e..3d2ff27 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1182,7 +1182,9 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_GRAY:
- if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL) {
+ if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL ||
+ bitmap->pixel_mode == FT_PIXEL_MODE_GRAY)
+ {
stride = bitmap->pitch;
if (own_buffer) {
data = bitmap->buffer;
@@ -1196,12 +1198,6 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
format = CAIRO_FORMAT_A8;
} else {
- /* if we get there, the data from the source bitmap
- * really comes from _fill_xrender_bitmap, and is
- * made of 32-bit ARGB or ABGR values */
- assert (own_buffer != 0);
- assert (bitmap->pixel_mode != FT_PIXEL_MODE_GRAY);
-
data = bitmap->buffer;
stride = bitmap->pitch;
format = CAIRO_FORMAT_ARGB32;
commit a0f556f37fb7016aa304b7cf0e811c0d38f0b969
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Jul 5 15:12:14 2013 -0600
[ft] Fix memory bug in copying bitmaps
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 1ab56be..3bba59e 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1158,9 +1158,7 @@ _get_bitmap_surface (FT_Bitmap *bitmap,
source = bitmap->buffer;
dest = data;
for (i = height; i; i--) {
- memcpy (dest, source, bitmap->pitch);
- memset (dest + bitmap->pitch, '\0', stride - bitmap->pitch);
-
+ memcpy (dest, source, stride);
source += bitmap->pitch;
dest += stride;
}
More information about the cairo-commit
mailing list