[cairo-commit] 10 commits - configure.in doc/public src/cairo-font-options.c src/cairo-ft-font.c src/cairo.h src/cairo-types-private.h src/cairo-xlib-screen.c src/Makefile.win32 test/font-options.c test/Makefile.am test/text-antialias-subpixel.c test/text-antialias-subpixel-ref.png test/text-lcd-filter-fir3.c test/text-lcd-filter-fir3-ref.png test/text-lcd-filter-fir5.c test/text-lcd-filter-fir5-ref.png test/text-lcd-filter-intra-pixel.c test/text-lcd-filter-intra-pixel-ref.png test/text-lcd-filter-none.c test/text-lcd-filter-none-ref.png

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Aug 5 13:36:40 PDT 2008


 configure.in                             |    2 
 doc/public/cairo-sections.txt            |    3 
 doc/public/tmpl/cairo-font-options.sgml  |   29 +
 doc/public/tmpl/cairo-text.sgml          |    2 
 src/Makefile.win32                       |   32 -
 src/cairo-font-options.c                 |   51 ++
 src/cairo-ft-font.c                      |  668 ++++++++++++++++++++++---------
 src/cairo-types-private.h                |    1 
 src/cairo-xlib-screen.c                  |   37 +
 src/cairo.h                              |   28 +
 test/Makefile.am                         |    4 
 test/font-options.c                      |    6 
 test/text-antialias-subpixel-ref.png     |binary
 test/text-antialias-subpixel.c           |    1 
 test/text-lcd-filter-fir3-ref.png        |binary
 test/text-lcd-filter-fir3.c              |   85 +++
 test/text-lcd-filter-fir5-ref.png        |binary
 test/text-lcd-filter-fir5.c              |   85 +++
 test/text-lcd-filter-intra-pixel-ref.png |binary
 test/text-lcd-filter-intra-pixel.c       |   85 +++
 test/text-lcd-filter-none-ref.png        |binary
 test/text-lcd-filter-none.c              |   85 +++
 22 files changed, 997 insertions(+), 207 deletions(-)

New commits:
commit 221599ab0fc1a2fa878659fe5bef88104e56a07c
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Aug 5 16:30:02 2008 -0400

    Finish off lcd-filter merge

diff --git a/configure.in b/configure.in
index 9d3b9cc..3e6a00e 100644
--- a/configure.in
+++ b/configure.in
@@ -621,7 +621,7 @@ if test "x$use_ft" = "xyes"; then
   AC_DEFINE_UNQUOTED(HAVE_FT_BITMAP_SIZE_Y_PPEM,$HAVE_FT_BITMAP_SIZE_Y_PPEM,
                      [FT_Bitmap_Size structure includes y_ppem field])
 
-  AC_CHECK_FUNCS(FT_GlyphSlot_Embolden FT_Load_Sfnt_Table)
+  AC_CHECK_FUNCS(FT_GlyphSlot_Embolden FT_Load_Sfnt_Table FT_Library_SetLcdFilter)
 
   LIBS="$temp_save_libs"
   CFLAGS="$temp_save_cflags"
diff --git a/doc/public/tmpl/cairo-font-options.sgml b/doc/public/tmpl/cairo-font-options.sgml
index 501abf4..42d9b76 100644
--- a/doc/public/tmpl/cairo-font-options.sgml
+++ b/doc/public/tmpl/cairo-font-options.sgml
@@ -137,6 +137,35 @@ output on a particular display.
 @Returns: 
 
 
+<!-- ##### ENUM cairo_lcd_filter_t ##### -->
+<para>
+
+</para>
+
+ at CAIRO_LCD_FILTER_DEFAULT:
+ at CAIRO_LCD_FILTER_NONE:
+ at CAIRO_LCD_FILTER_INTRA_PIXEL:
+ at CAIRO_LCD_FILTER_FIR3:
+ at CAIRO_LCD_FILTER_FIR5:
+
+<!-- ##### FUNCTION cairo_font_options_set_lcd_filter ##### -->
+<para>
+
+</para>
+
+ at options:
+ at lcd_filter:
+
+
+<!-- ##### FUNCTION cairo_font_options_get_lcd_filter ##### -->
+<para>
+
+</para>
+
+ at options:
+ at Returns:
+
+
 <!-- ##### ENUM cairo_hint_style_t ##### -->
 <para>
 
diff --git a/doc/public/tmpl/cairo-text.sgml b/doc/public/tmpl/cairo-text.sgml
index 925d29b..06e365c 100644
--- a/doc/public/tmpl/cairo-text.sgml
+++ b/doc/public/tmpl/cairo-text.sgml
@@ -50,6 +50,7 @@ Cairo has two sets of text rendering capabilities:
 
 </para>
 
+ at index:
 @x: 
 @y: 
 
@@ -195,6 +196,7 @@ Cairo has two sets of text rendering capabilities:
 </para>
 
 @cr: 
+ at Returns:
 
 
 <!-- ##### FUNCTION cairo_show_text_glyphs ##### -->
diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c
index 9e47a9c..c99902c 100644
--- a/src/cairo-font-options.c
+++ b/src/cairo-font-options.c
@@ -343,6 +343,8 @@ cairo_font_options_get_subpixel_order (const cairo_font_options_t *options)
  * specifies how pixels are filtered when rendered with an antialiasing
  * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for
  * #cairo_lcd_filter_t for full details.
+ *
+ * Since: 1.8
  **/
 void
 cairo_font_options_set_lcd_filter (cairo_font_options_t *options,
@@ -362,6 +364,8 @@ cairo_font_options_set_lcd_filter (cairo_font_options_t *options,
  * See the documentation for #cairo_lcd_filter_t for full details.
  *
  * Return value: the LCD filter for the font options object
+ *
+ * Since: 1.8
  **/
 cairo_lcd_filter_t
 cairo_font_options_get_lcd_filter (const cairo_font_options_t *options)
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 5d16f4e..bf69775 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -57,7 +57,26 @@
 #include FT_SYNTHESIS_H
 #endif
 
+#if HAVE_FT_LIBRARY_SETLCDFILTER
 #include FT_LCD_FILTER_H
+#endif
+
+/* Fontconfig version older than 2.6 didn't have these options */
+#ifndef FC_LCD_FILTER
+#define FC_LCD_FILTER	"lcdfilter"
+#define FC_LCD_NONE	0
+#define FC_LCD_DEFAULT	1
+#define FC_LCD_LIGHT	2
+#define FC_LCD_LEGACY	3
+#endif
+
+/* FreeType version older than 2.3.5(?) didn't have these options */
+#ifndef FT_LCD_FILTER_NONE
+#define FT_LCD_FILTER_NONE	0
+#define FT_LCD_FILTER_DEFAULT	1
+#define FT_LCD_FILTER_LIGHT	2
+#define FT_LCD_FILTER_LEGACY	16
+#endif
 
 #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
 #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
@@ -773,7 +792,7 @@ _compute_xrender_bitmap_size(FT_Bitmap      *target,
     if (slot->format != FT_GLYPH_FORMAT_BITMAP)
 	return -1;
 
-    // compute the size of the final bitmap
+    /* compute the size of the final bitmap */
     ftbit = &slot->bitmap;
 
     width = ftbit->width;
@@ -1101,9 +1120,9 @@ _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
+	    /* 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);
 
@@ -1274,11 +1293,15 @@ _render_glyph_outline (FT_Face                    face,
 	    break;
 	}
 
+#if HAVE_FT_LIBRARY_SETLCDFILTER
 	FT_Library_SetLcdFilter (library, lcd_filter);
+#endif
 
 	fterror = FT_Render_Glyph (face->glyph, render_mode);
 
+#if HAVE_FT_LIBRARY_SETLCDFILTER
 	FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE);
+#endif
 
 	if (fterror != 0)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1296,13 +1319,14 @@ _render_glyph_outline (FT_Face                    face,
 	_fill_xrender_bitmap (&bitmap, face->glyph, render_mode,
 			      (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR));
 
-	// NOTE: _get_bitmap_surface will free bitmap.buffer if there is an error
+	/* Note:
+	 * _get_bitmap_surface will free bitmap.buffer if there is an error
+	 */
 	status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
 	if (status)
 	    return status;
 
-	/*
-	 * Note: the font's coordinate system is upside down from ours, so the
+	/* Note: the font's coordinate system is upside down from ours, so the
 	 * Y coordinate of the control box needs to be negated.  Moreover, device
 	 * offsets are position of glyph origin relative to top left while xMin
 	 * and yMax are offsets of top left relative to origin.  Another negation.
@@ -1497,15 +1521,6 @@ typedef struct _cairo_ft_scaled_font {
 
 const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend;
 
-/* Fontconfig version older than 2.6 didn't have these options */
-#ifndef FC_LCD_FILTER
-#define FC_LCD_FILTER	"lcdfilter"
-#define FC_LCD_NONE	0
-#define FC_LCD_DEFAULT	1
-#define FC_LCD_LIGHT	2
-#define FC_LCD_LEGACY	3
-#endif
-
 /* The load flags passed to FT_Load_Glyph control aspects like hinting and
  * antialiasing. Here we compute them from the fields of a FcPattern.
  */
@@ -2687,6 +2702,7 @@ _cairo_ft_font_options_substitute (const cairo_font_options_t *options,
 	    case CAIRO_LCD_FILTER_FIR3:
 		lcd_filter = FT_LCD_FILTER_LIGHT;
 		break;
+	    default:
 	    case CAIRO_LCD_FILTER_FIR5:
 		lcd_filter = FT_LCD_FILTER_DEFAULT;
 		break;
diff --git a/src/cairo.h b/src/cairo.h
index 619de96..0829591 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -978,6 +978,8 @@ typedef enum _cairo_subpixel_order {
  *
  * The LCD filter specifies the low-pass filter applied to LCD-optimized
  * bitmaps generated with an antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
+ *
+ * Since: 1.8
  **/
 typedef enum _cairo_lcd_filter {
     CAIRO_LCD_FILTER_DEFAULT,
commit 19b36fb88757e34e8340de175f3723e882b92de7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Aug 5 14:54:55 2008 -0400

    [win32] Fix build

diff --git a/src/Makefile.win32 b/src/Makefile.win32
index 5c14add..5fcf605 100644
--- a/src/Makefile.win32
+++ b/src/Makefile.win32
@@ -6,18 +6,22 @@ include ../Makefile.win32
 srcdir = `pwd`
 
 SOURCES = \
+	cairo-analysis-surface.c \
 	cairo-arc.c \
 	cairo-array.c \
 	cairo-atomic.c \
+	cairo-base85-stream.c \
 	cairo-bentley-ottmann.c \
+	cairo.c \
 	cairo-cache.c \
+	cairo-cff-subset.c \
 	cairo-clip.c \
 	cairo-color.c \
 	cairo-debug.c \
 	cairo-deflate-stream.c \
 	cairo-fixed.c \
-	cairo-font-options.c \
 	cairo-font-face.c \
+	cairo-font-options.c \
 	cairo-freelist.c \
 	cairo-gstate.c \
 	cairo-hash.c \
@@ -29,44 +33,40 @@ SOURCES = \
 	cairo-misc.c \
 	cairo-mutex.c \
 	cairo-output-stream.c \
+	cairo-paginated-surface.c \
 	cairo-path-bounds.c \
-	cairo-path-fixed.c \
+	cairo-path.c \
 	cairo-path-fill.c \
+	cairo-path-fixed.c \
 	cairo-path-stroke.c \
-	cairo-path.c \
 	cairo-pattern.c \
-	cairo-pdf-surface.c \
 	cairo-pdf-operators.c \
+	cairo-pdf-surface.c \
 	cairo-pen.c \
-	cairo-polygon.c \
 	cairo-png.c \
+	cairo-polygon.c \
+	cairo-ps-surface.c \
 	cairo-rectangle.c \
 	cairo-region.c \
 	cairo-scaled-font.c \
+	cairo-scaled-font-subsets.c \
 	cairo-skiplist.c \
 	cairo-slope.c \
 	cairo-spline.c \
 	cairo-stroke-style.c \
-	cairo-surface-fallback.c \
 	cairo-surface.c \
+	cairo-surface-fallback.c \
+	cairo-svg-surface.c \
 	cairo-traps.c \
-	cairo-cff-subset.c \
 	cairo-truetype-subset.c \
 	cairo-type1-fallback.c \
+	cairo-type3-glyph-surface.c \
 	cairo-unicode.c \
 	cairo-user-font.c \
-	cairo-type3-glyph-surface.c \
 	cairo-wideint.c \
+	cairo-win32.c \
 	cairo-win32-font.c \
-	cairo.c \
-	cairo-svg-surface.c \
-	cairo-ps-surface.c \
-	cairo-scaled-font-subsets.c \
-	cairo-paginated-surface.c \
-	cairo-analysis-surface.c \
-	cairo-base85-stream.c \
 	cairo-win32-printing-surface.c \
-	cairo-win32.c \
 	$(NULL)
 
 STATIC_SOURCES = cairo-win32-surface.c 
commit 65d017a4063242d221365371301e1aab5b3c6299
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Tue Aug 5 13:52:13 2008 +0200

    Add tests for the new LCD filter API

diff --git a/test/Makefile.am b/test/Makefile.am
index 9554a28..c258223 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -149,6 +149,10 @@ text-antialias-gray$(EXEEXT)				\
 text-antialias-none$(EXEEXT)				\
 text-antialias-subpixel$(EXEEXT)			\
 text-cache-crash$(EXEEXT)				\
+text-lcd-filter-fir3$(EXEEXT)				\
+text-lcd-filter-fir5$(EXEEXT)				\
+text-lcd-filter-intra-pixel$(EXEEXT)			\
+text-lcd-filter-none$(EXEEXT)				\
 text-pattern$(EXEEXT)					\
 text-rotate$(EXEEXT)					\
 text-transform$(EXEEXT)					\
diff --git a/test/font-options.c b/test/font-options.c
index b0e111e..3e5194c 100644
--- a/test/font-options.c
+++ b/test/font-options.c
@@ -72,7 +72,11 @@ main (void)
 
     cairo_font_options_set_subpixel_order (NULL, CAIRO_SUBPIXEL_ORDER_DEFAULT);
     cairo_font_options_get_subpixel_order (NULL);
-    assert (cairo_font_options_get_subpixel_order (default_options) ==  CAIRO_SUBPIXEL_ORDER_DEFAULT);
+    assert (cairo_font_options_get_subpixel_order (default_options) == CAIRO_SUBPIXEL_ORDER_DEFAULT);
+
+    cairo_font_options_set_lcd_filter (NULL, CAIRO_LCD_FILTER_DEFAULT);
+    cairo_font_options_get_lcd_filter (NULL);
+    assert (cairo_font_options_get_lcd_filter (default_options) == CAIRO_LCD_FILTER_DEFAULT);
 
     cairo_font_options_set_hint_style (NULL, CAIRO_HINT_STYLE_DEFAULT);
     cairo_font_options_get_hint_style (NULL);
diff --git a/test/text-antialias-subpixel-ref.png b/test/text-antialias-subpixel-ref.png
index 88f76c0..2721a50 100644
Binary files a/test/text-antialias-subpixel-ref.png and b/test/text-antialias-subpixel-ref.png differ
diff --git a/test/text-antialias-subpixel.c b/test/text-antialias-subpixel.c
index af0112a..440c3a3 100644
--- a/test/text-antialias-subpixel.c
+++ b/test/text-antialias-subpixel.c
@@ -57,6 +57,7 @@ draw (cairo_t *cr, int width, int height)
     cairo_get_font_options (cr, font_options);
     cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
     cairo_font_options_set_subpixel_order (font_options, CAIRO_SUBPIXEL_ORDER_RGB);
+    cairo_font_options_set_lcd_filter (font_options, CAIRO_LCD_FILTER_NONE);
     cairo_set_font_options (cr, font_options);
 
     cairo_font_options_destroy (font_options);
diff --git a/test/text-lcd-filter-fir3-ref.png b/test/text-lcd-filter-fir3-ref.png
new file mode 100644
index 0000000..3521e63
Binary files /dev/null and b/test/text-lcd-filter-fir3-ref.png differ
diff --git a/test/text-lcd-filter-fir3.c b/test/text-lcd-filter-fir3.c
new file mode 100644
index 0000000..a6445b5
--- /dev/null
+++ b/test/text-lcd-filter-fir3.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define WIDTH  31
+#define HEIGHT 22
+#define TEXT_SIZE 12
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "text-lcd-filter-fir3",
+    "Tests text rendering with a 3x3 kernel FIR LCD filter",
+    WIDTH, HEIGHT,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_text_extents_t extents;
+    cairo_font_options_t *font_options;
+    static char black[] = "black", blue[] = "blue";
+
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_select_font_face (cr, "Bitstream Vera Sans",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, TEXT_SIZE);
+
+    font_options = cairo_font_options_create ();
+    cairo_get_font_options (cr, font_options);
+    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
+    cairo_font_options_set_lcd_filter (font_options, CAIRO_LCD_FILTER_FIR3);
+    cairo_set_font_options (cr, font_options);
+
+    cairo_font_options_destroy (font_options);
+
+    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
+    cairo_text_extents (cr, black, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, black);
+    cairo_translate (cr, 0, -extents.y_bearing + 1);
+
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_text_extents (cr, blue, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, blue);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/text-lcd-filter-fir5-ref.png b/test/text-lcd-filter-fir5-ref.png
new file mode 100644
index 0000000..319cdc1
Binary files /dev/null and b/test/text-lcd-filter-fir5-ref.png differ
diff --git a/test/text-lcd-filter-fir5.c b/test/text-lcd-filter-fir5.c
new file mode 100644
index 0000000..54bee80
--- /dev/null
+++ b/test/text-lcd-filter-fir5.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define WIDTH  31
+#define HEIGHT 22
+#define TEXT_SIZE 12
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "text-lcd-filter-fir5",
+    "Tests text rendering with a 5x5 kernel FIR LCD filter",
+    WIDTH, HEIGHT,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_text_extents_t extents;
+    cairo_font_options_t *font_options;
+    static char black[] = "black", blue[] = "blue";
+
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_select_font_face (cr, "Bitstream Vera Sans",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, TEXT_SIZE);
+
+    font_options = cairo_font_options_create ();
+    cairo_get_font_options (cr, font_options);
+    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
+    cairo_font_options_set_lcd_filter (font_options, CAIRO_LCD_FILTER_FIR5);
+    cairo_set_font_options (cr, font_options);
+
+    cairo_font_options_destroy (font_options);
+
+    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
+    cairo_text_extents (cr, black, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, black);
+    cairo_translate (cr, 0, -extents.y_bearing + 1);
+
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_text_extents (cr, blue, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, blue);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/text-lcd-filter-intra-pixel-ref.png b/test/text-lcd-filter-intra-pixel-ref.png
new file mode 100644
index 0000000..03a8afa
Binary files /dev/null and b/test/text-lcd-filter-intra-pixel-ref.png differ
diff --git a/test/text-lcd-filter-intra-pixel.c b/test/text-lcd-filter-intra-pixel.c
new file mode 100644
index 0000000..3f8b486
--- /dev/null
+++ b/test/text-lcd-filter-intra-pixel.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define WIDTH  31
+#define HEIGHT 22
+#define TEXT_SIZE 12
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "text-lcd-filter-intra-pixel",
+    "Tests text rendering with intra-pixel LCD filter",
+    WIDTH, HEIGHT,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_text_extents_t extents;
+    cairo_font_options_t *font_options;
+    static char black[] = "black", blue[] = "blue";
+
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_select_font_face (cr, "Bitstream Vera Sans",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, TEXT_SIZE);
+
+    font_options = cairo_font_options_create ();
+    cairo_get_font_options (cr, font_options);
+    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
+    cairo_font_options_set_lcd_filter (font_options, CAIRO_LCD_FILTER_INTRA_PIXEL);
+    cairo_set_font_options (cr, font_options);
+
+    cairo_font_options_destroy (font_options);
+
+    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
+    cairo_text_extents (cr, black, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, black);
+    cairo_translate (cr, 0, -extents.y_bearing + 1);
+
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_text_extents (cr, blue, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, blue);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
diff --git a/test/text-lcd-filter-none-ref.png b/test/text-lcd-filter-none-ref.png
new file mode 100644
index 0000000..3213833
Binary files /dev/null and b/test/text-lcd-filter-none-ref.png differ
diff --git a/test/text-lcd-filter-none.c b/test/text-lcd-filter-none.c
new file mode 100644
index 0000000..87e358a
--- /dev/null
+++ b/test/text-lcd-filter-none.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define WIDTH  31
+#define HEIGHT 22
+#define TEXT_SIZE 12
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "text-lcd-filter-none",
+    "Tests text rendering with no LCD filter",
+    WIDTH, HEIGHT,
+    draw
+};
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_text_extents_t extents;
+    cairo_font_options_t *font_options;
+    static char black[] = "black", blue[] = "blue";
+
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_select_font_face (cr, "Bitstream Vera Sans",
+			    CAIRO_FONT_SLANT_NORMAL,
+			    CAIRO_FONT_WEIGHT_NORMAL);
+    cairo_set_font_size (cr, TEXT_SIZE);
+
+    font_options = cairo_font_options_create ();
+    cairo_get_font_options (cr, font_options);
+    cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_SUBPIXEL);
+    cairo_font_options_set_lcd_filter (font_options, CAIRO_LCD_FILTER_NONE);
+    cairo_set_font_options (cr, font_options);
+
+    cairo_font_options_destroy (font_options);
+
+    cairo_set_source_rgb (cr, 0, 0, 0); /* black */
+    cairo_text_extents (cr, black, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, black);
+    cairo_translate (cr, 0, -extents.y_bearing + 1);
+
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_text_extents (cr, blue, &extents);
+    cairo_move_to (cr, -extents.x_bearing, -extents.y_bearing);
+    cairo_show_text (cr, blue);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit 45ec5e77bb26b0f93b0b1e11bd3055e8c9611111
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Wed Jan 23 00:05:00 2008 +0100

    Add symbols for setting the LCD filter type on font options

diff --git a/doc/public/cairo-sections.txt b/doc/public/cairo-sections.txt
index 7e60882..3954c45 100644
--- a/doc/public/cairo-sections.txt
+++ b/doc/public/cairo-sections.txt
@@ -319,6 +319,9 @@ cairo_font_options_get_antialias
 cairo_subpixel_order_t
 cairo_font_options_set_subpixel_order
 cairo_font_options_get_subpixel_order
+cairo_lcd_filter_t
+cairo_font_options_set_lcd_filter
+cairo_font_options_get_lcd_filter
 cairo_hint_style_t
 cairo_font_options_set_hint_style
 cairo_font_options_get_hint_style
commit a0cad6c398f5e30e3d10fb19fe51d4266b1c0b4c
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Wed Jan 23 00:03:01 2008 +0100

    [cairo-ft] Interaction with Fontconfig to deal with the LCD filter type

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 68c6ba9..5d16f4e 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1160,6 +1160,7 @@ _render_glyph_outline (FT_Face                    face,
 		       cairo_image_surface_t	**surface)
 {
     int rgba = FC_RGBA_UNKNOWN;
+    int lcd_filter = FT_LCD_FILTER_LEGACY;
     FT_GlyphSlot glyphslot = face->glyph;
     FT_Outline *outline = &glyphslot->outline;
     FT_Bitmap bitmap;
@@ -1189,6 +1190,22 @@ _render_glyph_outline (FT_Face                    face,
 		break;
 	}
 
+	switch (font_options->lcd_filter) {
+	case CAIRO_LCD_FILTER_NONE:
+	    lcd_filter = FT_LCD_FILTER_NONE;
+	    break;
+	case CAIRO_LCD_FILTER_DEFAULT:
+	case CAIRO_LCD_FILTER_INTRA_PIXEL:
+	    lcd_filter = FT_LCD_FILTER_LEGACY;
+	    break;
+	case CAIRO_LCD_FILTER_FIR3:
+	    lcd_filter = FT_LCD_FILTER_LIGHT;
+	    break;
+	case CAIRO_LCD_FILTER_FIR5:
+	    lcd_filter = FT_LCD_FILTER_DEFAULT;
+	    break;
+	}
+
 	break;
 
     case CAIRO_ANTIALIAS_DEFAULT:
@@ -1257,7 +1274,7 @@ _render_glyph_outline (FT_Face                    face,
 	    break;
 	}
 
-	FT_Library_SetLcdFilter (library, FT_LCD_FILTER_DEFAULT);
+	FT_Library_SetLcdFilter (library, lcd_filter);
 
 	fterror = FT_Render_Glyph (face->glyph, render_mode);
 
@@ -1522,6 +1539,7 @@ _get_pattern_ft_options (FcPattern *pattern, cairo_ft_options_t *ret)
     
     if (antialias) {
 	cairo_subpixel_order_t subpixel_order;
+	int lcd_filter;
 
 	/* disable hinting if requested */
 	if (FcPatternGetBool (pattern,
@@ -1557,6 +1575,25 @@ _get_pattern_ft_options (FcPattern *pattern, cairo_ft_options_t *ret)
 	    ft_options.base.antialias = CAIRO_ANTIALIAS_SUBPIXEL;
 	}
 
+	if (FcPatternGetInteger (pattern,
+				 FC_LCD_FILTER, 0, &lcd_filter) == FcResultMatch)
+	{
+	    switch (lcd_filter) {
+	    case FC_LCD_NONE:
+		ft_options.base.lcd_filter = CAIRO_LCD_FILTER_NONE;
+		break;
+	    case FC_LCD_DEFAULT:
+		ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR5;
+		break;
+	    case FC_LCD_LIGHT:
+		ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR3;
+		break;
+	    case FC_LCD_LEGACY:
+		ft_options.base.lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
+		break;
+	    }
+	}
+
 #ifdef FC_HINT_STYLE    
 	if (FcPatternGetInteger (pattern, 
 				 FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch)
@@ -1657,6 +1694,12 @@ _cairo_ft_options_merge (cairo_ft_options_t *options,
     if (other->base.hint_style == CAIRO_HINT_STYLE_NONE)
 	options->base.hint_style = CAIRO_HINT_STYLE_NONE;
 
+    if (options->base.lcd_filter == CAIRO_LCD_FILTER_DEFAULT)
+	options->base.lcd_filter = other->base.lcd_filter;
+
+    if (other->base.lcd_filter == CAIRO_LCD_FILTER_NONE)
+	options->base.lcd_filter = CAIRO_LCD_FILTER_NONE;
+
     if (options->base.antialias == CAIRO_ANTIALIAS_NONE) {
 	if (options->base.hint_style == CAIRO_HINT_STYLE_NONE)
 	    load_flags |= FT_LOAD_NO_HINTING;
@@ -2627,6 +2670,33 @@ _cairo_ft_font_options_substitute (const cairo_font_options_t *options,
 	}
     }
 
+    if (options->lcd_filter != CAIRO_LCD_FILTER_DEFAULT)
+    {
+	if (FcPatternGet (pattern, FC_LCD_FILTER, 0, &v) == FcResultNoMatch)
+	{
+	    int lcd_filter;
+
+	    switch (options->lcd_filter) {
+	    case CAIRO_LCD_FILTER_NONE:
+		lcd_filter = FT_LCD_FILTER_NONE;
+		break;
+	    case CAIRO_LCD_FILTER_DEFAULT:
+	    case CAIRO_LCD_FILTER_INTRA_PIXEL:
+		lcd_filter = FT_LCD_FILTER_LEGACY;
+		break;
+	    case CAIRO_LCD_FILTER_FIR3:
+		lcd_filter = FT_LCD_FILTER_LIGHT;
+		break;
+	    case CAIRO_LCD_FILTER_FIR5:
+		lcd_filter = FT_LCD_FILTER_DEFAULT;
+		break;
+	    }
+
+	    if (! FcPatternAddInteger (pattern, FC_LCD_FILTER, lcd_filter))
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	}
+    }
+
     if (options->hint_style != CAIRO_HINT_STYLE_DEFAULT)
     {
 	if (FcPatternGet (pattern, FC_HINTING, 0, &v) == FcResultNoMatch)
commit f64cf7fb098e8c9be8a454d4675e6a8b7fd22589
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Wed Jan 23 00:00:53 2008 +0100

    [cairo-xlib] Support to retrieve the LCD filter type from the Xrm database

diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index d7b609a..c3d2fd7 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -148,13 +148,22 @@ _cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *in
     cairo_bool_t xft_antialias;
     int xft_hintstyle;
     int xft_rgba;
+    int xft_lcdfilter;
     cairo_antialias_t antialias;
     cairo_subpixel_order_t subpixel_order;
+    cairo_lcd_filter_t lcd_filter;
     cairo_hint_style_t hint_style;
 
     if (!get_boolean_default (dpy, "antialias", &xft_antialias))
 	xft_antialias = TRUE;
 
+    if (!get_integer_default (dpy, "lcdfilter", &xft_lcdfilter)) {
+	/* -1 is an non-existant Fontconfig constant used to differentiate
+	 * the case when no lcdfilter property is available.
+	 */
+	xft_lcdfilter = -1;
+    }
+
     if (!get_boolean_default (dpy, "hinting", &xft_hinting))
 	xft_hinting = TRUE;
 
@@ -237,6 +246,24 @@ _cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *in
 	subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
     }
 
+    switch (xft_lcdfilter) {
+    case FC_LCD_NONE:
+	lcd_filter = CAIRO_LCD_FILTER_NONE;
+	break;
+    case FC_LCD_DEFAULT:
+	lcd_filter = CAIRO_LCD_FILTER_FIR5;
+	break;
+    case FC_LCD_LIGHT:
+	lcd_filter = CAIRO_LCD_FILTER_FIR3;
+	break;
+    case FC_LCD_LEGACY:
+	lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
+	break;
+    default:
+	lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
+	break;
+    }
+
     if (xft_antialias) {
 	if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT)
 	    antialias = CAIRO_ANTIALIAS_GRAY;
@@ -249,6 +276,7 @@ _cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *in
     cairo_font_options_set_hint_style (&info->font_options, hint_style);
     cairo_font_options_set_antialias (&info->font_options, antialias);
     cairo_font_options_set_subpixel_order (&info->font_options, subpixel_order);
+    cairo_font_options_set_lcd_filter (&info->font_options, lcd_filter);
     cairo_font_options_set_hint_metrics (&info->font_options, CAIRO_HINT_METRICS_ON);
 }
 
commit 28d18f3f936988483a47dd30f55ee2403bc006c3
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Tue Jan 22 23:59:36 2008 +0100

    [cairo-ft] Fontconfig defines for LCD constants when using Fontconfig < 2.6
    
    This adds define for compatibility when without the new lcd filtering
    constants (Fontconfig patch not yet applied, see bug 13566).

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index e79bb9e..68c6ba9 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1480,6 +1480,15 @@ typedef struct _cairo_ft_scaled_font {
 
 const cairo_scaled_font_backend_t _cairo_ft_scaled_font_backend;
 
+/* Fontconfig version older than 2.6 didn't have these options */
+#ifndef FC_LCD_FILTER
+#define FC_LCD_FILTER	"lcdfilter"
+#define FC_LCD_NONE	0
+#define FC_LCD_DEFAULT	1
+#define FC_LCD_LIGHT	2
+#define FC_LCD_LEGACY	3
+#endif
+
 /* The load flags passed to FT_Load_Glyph control aspects like hinting and
  * antialiasing. Here we compute them from the fields of a FcPattern.
  */
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 1b2340b..d7b609a 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -132,6 +132,15 @@ get_integer_default (Display    *dpy,
 #define FC_HINT_FULL        3
 #endif
 
+/* Fontconfig version older than 2.6 didn't have these options */
+#ifndef FC_LCD_FILTER
+#define FC_LCD_FILTER	"lcdfilter"
+#define FC_LCD_NONE	0
+#define FC_LCD_DEFAULT	1
+#define FC_LCD_LIGHT	2
+#define FC_LCD_LEGACY	3
+#endif
+
 static void
 _cairo_xlib_init_screen_font_options (Display *dpy, cairo_xlib_screen_info_t *info)
 {
commit 0013f2c2696146e71f043437a4727a1b18706b09
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Tue Jan 22 23:57:32 2008 +0100

    Add lcd filter type to the public API and font options
    
    New struct cairo_lcd_filter_t and new functions
    cairo_font_options_set_lcd_filter
    cairo_font_options_get_lcd_filter

diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c
index dedd337..9e47a9c 100644
--- a/src/cairo-font-options.c
+++ b/src/cairo-font-options.c
@@ -39,6 +39,7 @@
 static const cairo_font_options_t _cairo_font_options_nil = {
     CAIRO_ANTIALIAS_DEFAULT,
     CAIRO_SUBPIXEL_ORDER_DEFAULT,
+    CAIRO_LCD_FILTER_DEFAULT,
     CAIRO_HINT_STYLE_DEFAULT,
     CAIRO_HINT_METRICS_DEFAULT
 };
@@ -54,6 +55,7 @@ _cairo_font_options_init_default (cairo_font_options_t *options)
 {
     options->antialias = CAIRO_ANTIALIAS_DEFAULT;
     options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+    options->lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
     options->hint_style = CAIRO_HINT_STYLE_DEFAULT;
     options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
 }
@@ -64,6 +66,7 @@ _cairo_font_options_init_copy (cairo_font_options_t		*options,
 {
     options->antialias = other->antialias;
     options->subpixel_order = other->subpixel_order;
+    options->lcd_filter = other->lcd_filter;
     options->hint_style = other->hint_style;
     options->hint_metrics = other->hint_metrics;
 }
@@ -189,6 +192,8 @@ cairo_font_options_merge (cairo_font_options_t       *options,
 	options->antialias = other->antialias;
     if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
 	options->subpixel_order = other->subpixel_order;
+    if (other->lcd_filter != CAIRO_LCD_FILTER_DEFAULT)
+	options->lcd_filter = other->lcd_filter;
     if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT)
 	options->hint_style = other->hint_style;
     if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT)
@@ -221,6 +226,7 @@ cairo_font_options_equal (const cairo_font_options_t *options,
 
     return (options->antialias == other->antialias &&
 	    options->subpixel_order == other->subpixel_order &&
+	    options->lcd_filter == other->lcd_filter &&
 	    options->hint_style == other->hint_style &&
 	    options->hint_metrics == other->hint_metrics);
 }
@@ -246,7 +252,8 @@ cairo_font_options_hash (const cairo_font_options_t *options)
 
     return ((options->antialias) |
 	    (options->subpixel_order << 4) |
-	    (options->hint_style << 8) |
+	    (options->lcd_filter << 8) |
+	    (options->hint_style << 12) |
 	    (options->hint_metrics << 16));
 }
 slim_hidden_def (cairo_font_options_hash);
@@ -328,6 +335,44 @@ cairo_font_options_get_subpixel_order (const cairo_font_options_t *options)
 }
 
 /**
+ * cairo_font_options_set_lcd_filter:
+ * @options: a #cairo_font_options_t
+ * @lcd_filter: the new LCD filter
+ *
+ * Sets the LCD filter for the font options object. The LCD filter
+ * specifies how pixels are filtered when rendered with an antialiasing
+ * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for
+ * #cairo_lcd_filter_t for full details.
+ **/
+void
+cairo_font_options_set_lcd_filter (cairo_font_options_t *options,
+				   cairo_lcd_filter_t    lcd_filter)
+{
+    if (cairo_font_options_status (options))
+	return;
+
+    options->lcd_filter = lcd_filter;
+}
+
+/**
+ * cairo_font_options_get_lcd_filter:
+ * @options: a #cairo_font_options_t
+ *
+ * Gets the LCD filter for the font options object.
+ * See the documentation for #cairo_lcd_filter_t for full details.
+ *
+ * Return value: the LCD filter for the font options object
+ **/
+cairo_lcd_filter_t
+cairo_font_options_get_lcd_filter (const cairo_font_options_t *options)
+{
+    if (cairo_font_options_status ((cairo_font_options_t *) options))
+	return CAIRO_LCD_FILTER_DEFAULT;
+
+    return options->lcd_filter;
+}
+
+/**
  * cairo_font_options_set_hint_style:
  * @options: a #cairo_font_options_t
  * @hint_style: the new hint style
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 1baab26..02afdc0 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -108,6 +108,7 @@ struct _cairo_array {
 struct _cairo_font_options {
     cairo_antialias_t antialias;
     cairo_subpixel_order_t subpixel_order;
+    cairo_lcd_filter_t lcd_filter;
     cairo_hint_style_t hint_style;
     cairo_hint_metrics_t hint_metrics;
 };
diff --git a/src/cairo.h b/src/cairo.h
index f746924..619de96 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -968,6 +968,26 @@ typedef enum _cairo_subpixel_order {
 } cairo_subpixel_order_t;
 
 /**
+ * cairo_lcd_filter_t:
+ * @CAIRO_LCD_FILTER_DEFAULT: Use the default LCD filter for
+ *   font backend and target device
+ * @CAIRO_LCD_FILTER_NONE: Do not perform LCD filtering
+ * @CAIRO_LCD_FILTER_INTRA_PIXEL: Intra-pixel filter
+ * @CAIRO_LCD_FILTER_FIR3: FIR filter with a 3x3 kernel
+ * @CAIRO_LCD_FILTER_FIR5: FIR filter with a 5x5 kernel
+ *
+ * The LCD filter specifies the low-pass filter applied to LCD-optimized
+ * bitmaps generated with an antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
+ **/
+typedef enum _cairo_lcd_filter {
+    CAIRO_LCD_FILTER_DEFAULT,
+    CAIRO_LCD_FILTER_NONE,
+    CAIRO_LCD_FILTER_INTRA_PIXEL,
+    CAIRO_LCD_FILTER_FIR3,
+    CAIRO_LCD_FILTER_FIR5
+} cairo_lcd_filter_t;
+
+/**
  * cairo_hint_style_t:
  * @CAIRO_HINT_STYLE_DEFAULT: Use the default hint style for
  *   font backend and target device
@@ -1073,6 +1093,12 @@ cairo_public cairo_subpixel_order_t
 cairo_font_options_get_subpixel_order (const cairo_font_options_t *options);
 
 cairo_public void
+cairo_font_options_set_lcd_filter (cairo_font_options_t   *options,
+				   cairo_lcd_filter_t  lcd_filter);
+cairo_public cairo_lcd_filter_t
+cairo_font_options_get_lcd_filter (const cairo_font_options_t *options);
+
+cairo_public void
 cairo_font_options_set_hint_style (cairo_font_options_t *options,
 				   cairo_hint_style_t     hint_style);
 cairo_public cairo_hint_style_t
commit 4b5e0ba7200159f732c815bea616367fc851f245
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Tue Jan 22 23:53:17 2008 +0100

    [cairo-ft] LCD filtering patch coding style corrections

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 076d251..e79bb9e 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -763,67 +763,65 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
  * like trying to convert a gray bitmap into a monochrome one)
  */
 static int
-_compute_xrender_bitmap_size( FT_Bitmap*      target,
-                              FT_GlyphSlot    slot,
-                              FT_Render_Mode  mode )
+_compute_xrender_bitmap_size(FT_Bitmap      *target,
+			     FT_GlyphSlot    slot,
+			     FT_Render_Mode  mode)
 {
-    FT_Bitmap*  ftbit;
-    int         width, height, pitch;
+    FT_Bitmap *ftbit;
+    int width, height, pitch;
 
-    if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
-        return -1;
+    if (slot->format != FT_GLYPH_FORMAT_BITMAP)
+	return -1;
 
     // compute the size of the final bitmap
-    ftbit  = &slot->bitmap;
+    ftbit = &slot->bitmap;
 
-    width  = ftbit->width;
+    width = ftbit->width;
     height = ftbit->rows;
-    pitch  = (width+3) & ~3;
+    pitch = (width + 3) & ~3;
 
-    switch ( ftbit->pixel_mode )
-    {
+    switch (ftbit->pixel_mode) {
     case FT_PIXEL_MODE_MONO:
-        if ( mode == FT_RENDER_MODE_MONO )
-        {
-          pitch = (((width+31) & ~31) >> 3);
-          break;
-        }
-        /* fall-through */
+	if (mode == FT_RENDER_MODE_MONO) {
+	    pitch = (((width + 31) & ~31) >> 3);
+	    break;
+	}
+	/* fall-through */
 
     case FT_PIXEL_MODE_GRAY:
-        if ( mode == FT_RENDER_MODE_LCD   ||
-            mode == FT_RENDER_MODE_LCD_V )
-        {
-            /* each pixel is replicated into a 32-bit ARGB value */
-            pitch = width*4;
-        }
-        break;
+	if (mode == FT_RENDER_MODE_LCD ||
+	    mode == FT_RENDER_MODE_LCD_V)
+	{
+	    /* each pixel is replicated into a 32-bit ARGB value */
+	    pitch = width * 4;
+	}
+	break;
 
     case FT_PIXEL_MODE_LCD:
-        if ( mode != FT_RENDER_MODE_LCD )
-            return -1;
+	if (mode != FT_RENDER_MODE_LCD)
+	    return -1;
 
-      /* horz pixel triplets are packed into 32-bit ARGB values */
-      width   /= 3;
-      pitch    = width*4;
-      break;
+	/* horz pixel triplets are packed into 32-bit ARGB values */
+	width /= 3;
+	pitch = width * 4;
+	break;
 
     case FT_PIXEL_MODE_LCD_V:
-        if ( mode != FT_RENDER_MODE_LCD_V )
-            return -1;
+	if (mode != FT_RENDER_MODE_LCD_V)
+	    return -1;
 
-        /* vert pixel triplets are packed into 32-bit ARGB values */
-        height  /= 3;
-        pitch    = width*4;
-        break;
+	/* vert pixel triplets are packed into 32-bit ARGB values */
+	height /= 3;
+	pitch = width * 4;
+	break;
 
     default:  /* unsupported source format */
-        return -1;
+	return -1;
     }
 
-    target->width  = width;
-    target->rows   = height;
-    target->pitch  = pitch;
+    target->width = width;
+    target->rows = height;
+    target->pitch = pitch;
     target->buffer = NULL;
 
     return pitch * height;
@@ -844,192 +842,180 @@ _compute_xrender_bitmap_size( FT_Bitmap*      target,
  * bgr    :: boolean, set if BGR or VBGR pixel ordering is needed
  */
 static void
-_fill_xrender_bitmap( FT_Bitmap*      target,
-                      FT_GlyphSlot    slot,
-                      FT_Render_Mode  mode,
-                      int             bgr )
+_fill_xrender_bitmap(FT_Bitmap      *target,
+		     FT_GlyphSlot    slot,
+		     FT_Render_Mode  mode,
+		     int             bgr)
 {
-    FT_Bitmap*   ftbit = &slot->bitmap;
-    unsigned char*   srcLine   = ftbit->buffer;
-    unsigned char*   dstLine   = target->buffer;
-    int              src_pitch = ftbit->pitch;
-    int              width     = target->width;
-    int              height    = target->rows;
-    int              pitch     = target->pitch;
-    int              subpixel;
-    int              h;
-
-    subpixel = ( mode == FT_RENDER_MODE_LCD ||
-        mode == FT_RENDER_MODE_LCD_V );
-
-    if ( src_pitch < 0 )
-      srcLine -= src_pitch*(ftbit->rows-1);
+    FT_Bitmap *ftbit = &slot->bitmap;
+    unsigned char *srcLine = ftbit->buffer;
+    unsigned char *dstLine = target->buffer;
+    int src_pitch = ftbit->pitch;
+    int width = target->width;
+    int height = target->rows;
+    int pitch = target->pitch;
+    int subpixel;
+    int h;
+
+    subpixel = (mode == FT_RENDER_MODE_LCD ||
+		mode == FT_RENDER_MODE_LCD_V);
+
+    if (src_pitch < 0)
+	srcLine -= src_pitch * (ftbit->rows - 1);
 
     target->pixel_mode = ftbit->pixel_mode;
 
-    switch ( ftbit->pixel_mode )
-    {
+    switch (ftbit->pixel_mode) {
     case FT_PIXEL_MODE_MONO:
-        if ( subpixel )  /* convert mono to ARGB32 values */
-        {
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-            {
-                int  x;
-
-                for ( x = 0; x < width; x++ )
-                {
-                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
-                        ((unsigned int*)dstLine)[x] = 0xffffffffU;
-                }
-            }
-            target->pixel_mode = FT_PIXEL_MODE_LCD;
-        }
-        else if ( mode == FT_RENDER_MODE_NORMAL )  /* convert mono to 8-bit gray */
-        {
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-            {
-                int  x;
-
-                for ( x = 0; x < width; x++ )
-                {
-                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
-                        dstLine[x] = 0xff;
-                }
-            }
-            target->pixel_mode = FT_PIXEL_MODE_GRAY;
-        }
-        else  /* copy mono to mono */
-        {
-            int  bytes = (width+7) >> 3;
+	if (subpixel) {
+	    /* convert mono to ARGB32 values */
 
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-                memcpy( dstLine, srcLine, bytes );
-        }
-        break;
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
+		int x;
+
+		for (x = 0; x < width; x++) {
+		    if (srcLine[(x >> 3)] & (0x80 >> (x & 7)))
+			((unsigned int *) dstLine)[x] = 0xffffffffU;
+		}
+	    }
+	    target->pixel_mode = FT_PIXEL_MODE_LCD;
+
+	} else if (mode == FT_RENDER_MODE_NORMAL) {
+	    /* convert mono to 8-bit gray */
+
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
+		int x;
+
+		for (x = 0; x < width; x++) {
+		    if (srcLine[(x >> 3)] & (0x80 >> (x & 7)))
+			dstLine[x] = 0xff;
+		}
+	    }
+	    target->pixel_mode = FT_PIXEL_MODE_GRAY;
+
+	} else {
+	    /* copy mono to mono */
+
+	    int  bytes = (width + 7) >> 3;
+
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch)
+		memcpy (dstLine, srcLine, bytes);
+	}
+	break;
 
     case FT_PIXEL_MODE_GRAY:
-        if ( subpixel )  /* convert gray to ARGB32 values */
-        {
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-            {
-                int            x;
-                unsigned int*  dst = (unsigned int*)dstLine;
-
-                for ( x = 0; x < width; x++ )
-                {
-                    unsigned int  pix = srcLine[x];
-
-                    pix |= (pix << 8);
-                    pix |= (pix << 16);
-
-                    dst[x] = pix;
-                }
-            }
-            target->pixel_mode = FT_PIXEL_MODE_LCD;
-        }
-        else  /* copy gray into gray */
-        {
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-                memcpy( dstLine, srcLine, width );
+	if (subpixel) {
+	    /* convert gray to ARGB32 values */
+
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
+		int x;
+		unsigned int *dst = (unsigned int *) dstLine;
+
+		for (x = 0; x < width; x++) {
+		    unsigned int pix = srcLine[x];
+
+		    pix |= (pix << 8);
+		    pix |= (pix << 16);
+
+		    dst[x] = pix;
+		}
+	    }
+	    target->pixel_mode = FT_PIXEL_MODE_LCD;
+        } else {
+            /* copy gray into gray */
+
+            for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch)
+                memcpy (dstLine, srcLine, width);
         }
         break;
 
     case FT_PIXEL_MODE_LCD:
-        if ( !bgr )
-        {
-            /* convert horizontal RGB into ARGB32 */
-            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-            {
-                int            x;
-                unsigned char* src = srcLine;
-                unsigned int*  dst = (unsigned int*)dstLine;
-
-                for ( x = 0; x < width; x++, src += 3 )
-                {
-                    unsigned int  pix;
-
-                    pix = ((unsigned int)src[0] << 16) |
-                          ((unsigned int)src[1] <<  8) |
-                          ((unsigned int)src[2]      ) |
-                          ((unsigned int)src[1] << 24) ;
-
-                    dst[x] = pix;
-                }
-            }
-        }
-        else
-        {
-          /* convert horizontal BGR into ARGB32 */
-          for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
-          {
-              int            x;
-              unsigned char* src = srcLine;
-              unsigned int*  dst = (unsigned int*)dstLine;
-
-              for ( x = 0; x < width; x++, src += 3 )
-              {
-                  unsigned int  pix;
-
-                  pix = ((unsigned int)src[2] << 16) |
-                        ((unsigned int)src[1] <<  8) |
-                        ((unsigned int)src[0]      ) |
-                        ((unsigned int)src[1] << 24) ;
-
-                  dst[x] = pix;
-              }
-          }
-        }
-        break;
+	if (!bgr) {
+	    /* convert horizontal RGB into ARGB32 */
+
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
+		int x;
+		unsigned char *src = srcLine;
+		unsigned int *dst = (unsigned int *) dstLine;
+
+		for (x = 0; x < width; x++, src += 3) {
+		    unsigned int  pix;
+
+		    pix = ((unsigned int)src[0] << 16) |
+			  ((unsigned int)src[1] <<  8) |
+			  ((unsigned int)src[2]      ) |
+			  ((unsigned int)src[1] << 24) ;
+
+		    dst[x] = pix;
+		}
+	    }
+	} else {
+	    /* convert horizontal BGR into ARGB32 */
+
+	    for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
+
+		int x;
+		unsigned char *src = srcLine;
+		unsigned int *dst = (unsigned int *) dstLine;
+
+		for (x = 0; x < width; x++, src += 3) {
+		    unsigned int  pix;
+
+		    pix = ((unsigned int)src[2] << 16) |
+			  ((unsigned int)src[1] <<  8) |
+			  ((unsigned int)src[0]      ) |
+			  ((unsigned int)src[1] << 24) ;
+
+		    dst[x] = pix;
+		}
+	    }
+	}
+	break;
 
     default:  /* FT_PIXEL_MODE_LCD_V */
-        /* convert vertical RGB into ARGB32 */
-        if ( !bgr )
-        {
-            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
-            {
-                int            x;
-                unsigned char* src = srcLine;
-                unsigned int*  dst = (unsigned int*)dstLine;
-
-                for ( x = 0; x < width; x++, src += 1 )
-                {
-                    unsigned int  pix;
+	/* convert vertical RGB into ARGB32 */
+	if (!bgr) {
+
+	    for (h = height; h > 0; h--, srcLine += 3 * src_pitch, dstLine += pitch) {
+		int x;
+		unsigned char* src = srcLine;
+		unsigned int*  dst = (unsigned int *) dstLine;
+
+		for (x = 0; x < width; x++, src += 1) {
+		    unsigned int pix;
 #if 1
-                    pix = ((unsigned int)src[0]           << 16) |
-                          ((unsigned int)src[src_pitch]   <<  8) |
-                          ((unsigned int)src[src_pitch*2]      ) |
-                          0xFF000000 ;
+		    pix = ((unsigned int)src[0]           << 16) |
+			  ((unsigned int)src[src_pitch]   <<  8) |
+			  ((unsigned int)src[src_pitch*2]      ) |
+			  0xFF000000 ;
 #else
-                    pix = ((unsigned int)src[0]           << 16) |
-                          ((unsigned int)src[src_pitch]   <<  8) |
-                          ((unsigned int)src[src_pitch*2]      ) |
-                          ((unsigned int)src[src_pitch]   << 24) ;
+		    pix = ((unsigned int)src[0]           << 16) |
+			  ((unsigned int)src[src_pitch]   <<  8) |
+			  ((unsigned int)src[src_pitch*2]      ) |
+			  ((unsigned int)src[src_pitch]   << 24) ;
 #endif
-                    dst[x] = pix;
-                }
-            }
-        }
-        else
-        {
-            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
-            {
-                int            x;
-                unsigned char* src = srcLine;
-                unsigned int*  dst = (unsigned int*)dstLine;
-
-                for ( x = 0; x < width; x++, src += 1 )
-                {
-                    unsigned int  pix;
-
-                    pix = ((unsigned int)src[src_pitch*2] << 16) |
-                        ((unsigned int)src[src_pitch]   <<  8) |
-                        ((unsigned int)src[0]                ) |
-                        ((unsigned int)src[src_pitch]   << 24) ;
-
-                    dst[x] = pix;
-                }
-            }
-        }
+		    dst[x] = pix;
+		}
+	    }
+	} else {
+
+	    for (h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch) {
+		int x;
+		unsigned char *src = srcLine;
+		unsigned int *dst = (unsigned int *) dstLine;
+
+		for (x = 0; x < width; x++, src += 1) {
+		    unsigned int  pix;
+
+		    pix = ((unsigned int)src[src_pitch * 2] << 16) |
+			  ((unsigned int)src[src_pitch]     <<  8) |
+			  ((unsigned int)src[0]                  ) |
+			  ((unsigned int)src[src_pitch]     << 24) ;
+
+		    dst[x] = pix;
+		}
+	    }
+	}
     }
 }
 
@@ -1045,7 +1031,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
     int width, height, stride;
     unsigned char *data;
     int format = CAIRO_FORMAT_A8;
-    cairo_image_surface_t  *image;
+    cairo_image_surface_t *image;
 
     width = bitmap->width;
     height = bitmap->rows;
@@ -1084,6 +1070,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 		}
 	    }
 	}
+
 #ifndef WORDS_BIGENDIAN
 	{
 	    unsigned char   *d = data;
@@ -1095,15 +1082,13 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	    }
 	}
 #endif
-
 	format = CAIRO_FORMAT_A1;
 	break;
 
     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) {
 	    stride = bitmap->pitch;
 	    if (own_buffer) {
 		data = bitmap->buffer;
@@ -1115,14 +1100,14 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 		memcpy (data, bitmap->buffer, stride * height);
 	    }
 	    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);
+	} 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;
+	    data = bitmap->buffer;
 	    stride = bitmap->pitch;
 	    format = CAIRO_FORMAT_ARGB32;
 	}
@@ -1181,36 +1166,34 @@ _render_glyph_outline (FT_Face                    face,
     FT_BBox cbox;
     unsigned int width, height, stride;
     cairo_status_t status;
-    FT_Error  fterror;
-    FT_Library  library = glyphslot->library;
-    FT_Render_Mode  render_mode = FT_RENDER_MODE_NORMAL;
+    FT_Error fterror;
+    FT_Library library = glyphslot->library;
+    FT_Render_Mode render_mode = FT_RENDER_MODE_NORMAL;
 
-    switch (font_options->antialias)
-    {
+    switch (font_options->antialias) {
     case CAIRO_ANTIALIAS_NONE:
-        render_mode = FT_RENDER_MODE_MONO;
-        break;
+	render_mode = FT_RENDER_MODE_MONO;
+	break;
 
     case CAIRO_ANTIALIAS_SUBPIXEL:
-        switch (font_options->subpixel_order)
-        {
-            case CAIRO_SUBPIXEL_ORDER_DEFAULT:
-            case CAIRO_SUBPIXEL_ORDER_RGB:
-            case CAIRO_SUBPIXEL_ORDER_BGR:
-                render_mode = FT_RENDER_MODE_LCD;
-                break;
-
-            case CAIRO_SUBPIXEL_ORDER_VRGB:
-            case CAIRO_SUBPIXEL_ORDER_VBGR:
-                render_mode = FT_RENDER_MODE_LCD_V;
-                break;
-        }
+	switch (font_options->subpixel_order) {
+	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
+	    case CAIRO_SUBPIXEL_ORDER_RGB:
+	    case CAIRO_SUBPIXEL_ORDER_BGR:
+		render_mode = FT_RENDER_MODE_LCD;
+		break;
 
-        break;
+	    case CAIRO_SUBPIXEL_ORDER_VRGB:
+	    case CAIRO_SUBPIXEL_ORDER_VBGR:
+		render_mode = FT_RENDER_MODE_LCD_V;
+		break;
+	}
+
+	break;
 
     case CAIRO_ANTIALIAS_DEFAULT:
     case CAIRO_ANTIALIAS_GRAY:
-        render_mode = FT_RENDER_MODE_NORMAL;
+	render_mode = FT_RENDER_MODE_NORMAL;
     }
 
     FT_Outline_Get_CBox (outline, &cbox);
@@ -1274,29 +1257,27 @@ _render_glyph_outline (FT_Face                    face,
 	    break;
 	}
 
-	FT_Library_SetLcdFilter( library, FT_LCD_FILTER_DEFAULT );
+	FT_Library_SetLcdFilter (library, FT_LCD_FILTER_DEFAULT);
 
-	fterror = FT_Render_Glyph( face->glyph, render_mode );
+	fterror = FT_Render_Glyph (face->glyph, render_mode);
 
-	FT_Library_SetLcdFilter( library, FT_LCD_FILTER_NONE );
+	FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE);
 
 	if (fterror != 0)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-	bitmap_size = _compute_xrender_bitmap_size(&bitmap,
-						   face->glyph,
-						   render_mode);
-	if (bitmap_size < 0) {
+	bitmap_size = _compute_xrender_bitmap_size (&bitmap,
+						    face->glyph,
+						    render_mode);
+	if (bitmap_size < 0)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	}
 
-	bitmap.buffer = calloc(1, bitmap_size);
-	if (bitmap.buffer == NULL) {
+	bitmap.buffer = calloc (1, bitmap_size);
+	if (bitmap.buffer == NULL)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	}
 
-	_fill_xrender_bitmap(&bitmap, face->glyph, render_mode,
-			     (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR));
+	_fill_xrender_bitmap (&bitmap, face->glyph, render_mode,
+			      (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR));
 
 	// NOTE: _get_bitmap_surface will free bitmap.buffer if there is an error
 	status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
commit 7f870035177da7aa63fa33dce837528f442d9ffe
Author: Sylvain Pasche <sylvain.pasche at gmail.com>
Date:   Tue Jan 22 23:51:32 2008 +0100

    [cairo-ft] LCD filtering patch from David Turner
    
    This is the patch David Turner wrote some times ago and can be found on
    http://david.freetype.org/lcd/cairo-1.2.4-lcd-filter-1.patch. It was
    somewhat modified for compatibility with cairo 1.5

diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 293ca76..076d251 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -57,6 +57,8 @@
 #include FT_SYNTHESIS_H
 #endif
 
+#include FT_LCD_FILTER_H
+
 #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
 #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
 #define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
@@ -737,23 +739,300 @@ _cairo_ft_unscaled_font_set_scale (cairo_ft_unscaled_font_t *unscaled,
     return CAIRO_STATUS_SUCCESS;
 }
 
-/* Empirically-derived subpixel filtering values thanks to Keith
- * Packard and libXft. */
-static const int    filters[3][3] = {
-    /* red */
-#if 0
-    {    65538*4/7,65538*2/7,65538*1/7 },
-    /* green */
-    {    65536*1/4, 65536*2/4, 65537*1/4 },
-    /* blue */
-    {    65538*1/7,65538*2/7,65538*4/7 },
+/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot
+ * into a different format. For example, we want to convert a
+ * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit
+ * ARGB or ABGR bitmap.
+ *
+ * this function prepares a target descriptor for this operation.
+ *
+ * input :: target bitmap descriptor. The function will set its
+ *          'width', 'rows' and 'pitch' fields, and only these
+ *
+ * slot  :: the glyph slot containing the source bitmap. this
+ *          function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP
+ *
+ * mode  :: the requested final rendering mode. supported values are
+ *          MONO, NORMAL (i.e. gray), LCD and LCD_V
+ *
+ * the function returns the size in bytes of the corresponding buffer,
+ * it's up to the caller to allocate the corresponding memory block
+ * before calling _fill_xrender_bitmap
+ *
+ * it also returns -1 in case of error (e.g. incompatible arguments,
+ * like trying to convert a gray bitmap into a monochrome one)
+ */
+static int
+_compute_xrender_bitmap_size( FT_Bitmap*      target,
+                              FT_GlyphSlot    slot,
+                              FT_Render_Mode  mode )
+{
+    FT_Bitmap*  ftbit;
+    int         width, height, pitch;
+
+    if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
+        return -1;
+
+    // compute the size of the final bitmap
+    ftbit  = &slot->bitmap;
+
+    width  = ftbit->width;
+    height = ftbit->rows;
+    pitch  = (width+3) & ~3;
+
+    switch ( ftbit->pixel_mode )
+    {
+    case FT_PIXEL_MODE_MONO:
+        if ( mode == FT_RENDER_MODE_MONO )
+        {
+          pitch = (((width+31) & ~31) >> 3);
+          break;
+        }
+        /* fall-through */
+
+    case FT_PIXEL_MODE_GRAY:
+        if ( mode == FT_RENDER_MODE_LCD   ||
+            mode == FT_RENDER_MODE_LCD_V )
+        {
+            /* each pixel is replicated into a 32-bit ARGB value */
+            pitch = width*4;
+        }
+        break;
+
+    case FT_PIXEL_MODE_LCD:
+        if ( mode != FT_RENDER_MODE_LCD )
+            return -1;
+
+      /* horz pixel triplets are packed into 32-bit ARGB values */
+      width   /= 3;
+      pitch    = width*4;
+      break;
+
+    case FT_PIXEL_MODE_LCD_V:
+        if ( mode != FT_RENDER_MODE_LCD_V )
+            return -1;
+
+        /* vert pixel triplets are packed into 32-bit ARGB values */
+        height  /= 3;
+        pitch    = width*4;
+        break;
+
+    default:  /* unsupported source format */
+        return -1;
+    }
+
+    target->width  = width;
+    target->rows   = height;
+    target->pitch  = pitch;
+    target->buffer = NULL;
+
+    return pitch * height;
+}
+
+/* this functions converts the glyph bitmap found in a FT_GlyphSlot
+ * into a different format (see _compute_xrender_bitmap_size)
+ *
+ * you should call this function after _compute_xrender_bitmap_size
+ *
+ * target :: target bitmap descriptor. Note that its 'buffer' pointer
+ *           must point to memory allocated by the caller
+ *
+ * slot   :: the glyph slot containing the source bitmap
+ *
+ * mode   :: the requested final rendering mode
+ *
+ * bgr    :: boolean, set if BGR or VBGR pixel ordering is needed
+ */
+static void
+_fill_xrender_bitmap( FT_Bitmap*      target,
+                      FT_GlyphSlot    slot,
+                      FT_Render_Mode  mode,
+                      int             bgr )
+{
+    FT_Bitmap*   ftbit = &slot->bitmap;
+    unsigned char*   srcLine   = ftbit->buffer;
+    unsigned char*   dstLine   = target->buffer;
+    int              src_pitch = ftbit->pitch;
+    int              width     = target->width;
+    int              height    = target->rows;
+    int              pitch     = target->pitch;
+    int              subpixel;
+    int              h;
+
+    subpixel = ( mode == FT_RENDER_MODE_LCD ||
+        mode == FT_RENDER_MODE_LCD_V );
+
+    if ( src_pitch < 0 )
+      srcLine -= src_pitch*(ftbit->rows-1);
+
+    target->pixel_mode = ftbit->pixel_mode;
+
+    switch ( ftbit->pixel_mode )
+    {
+    case FT_PIXEL_MODE_MONO:
+        if ( subpixel )  /* convert mono to ARGB32 values */
+        {
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+            {
+                int  x;
+
+                for ( x = 0; x < width; x++ )
+                {
+                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
+                        ((unsigned int*)dstLine)[x] = 0xffffffffU;
+                }
+            }
+            target->pixel_mode = FT_PIXEL_MODE_LCD;
+        }
+        else if ( mode == FT_RENDER_MODE_NORMAL )  /* convert mono to 8-bit gray */
+        {
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+            {
+                int  x;
+
+                for ( x = 0; x < width; x++ )
+                {
+                    if ( srcLine[(x >> 3)] & (0x80 >> (x & 7)) )
+                        dstLine[x] = 0xff;
+                }
+            }
+            target->pixel_mode = FT_PIXEL_MODE_GRAY;
+        }
+        else  /* copy mono to mono */
+        {
+            int  bytes = (width+7) >> 3;
+
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+                memcpy( dstLine, srcLine, bytes );
+        }
+        break;
+
+    case FT_PIXEL_MODE_GRAY:
+        if ( subpixel )  /* convert gray to ARGB32 values */
+        {
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+            {
+                int            x;
+                unsigned int*  dst = (unsigned int*)dstLine;
+
+                for ( x = 0; x < width; x++ )
+                {
+                    unsigned int  pix = srcLine[x];
+
+                    pix |= (pix << 8);
+                    pix |= (pix << 16);
+
+                    dst[x] = pix;
+                }
+            }
+            target->pixel_mode = FT_PIXEL_MODE_LCD;
+        }
+        else  /* copy gray into gray */
+        {
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+                memcpy( dstLine, srcLine, width );
+        }
+        break;
+
+    case FT_PIXEL_MODE_LCD:
+        if ( !bgr )
+        {
+            /* convert horizontal RGB into ARGB32 */
+            for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+            {
+                int            x;
+                unsigned char* src = srcLine;
+                unsigned int*  dst = (unsigned int*)dstLine;
+
+                for ( x = 0; x < width; x++, src += 3 )
+                {
+                    unsigned int  pix;
+
+                    pix = ((unsigned int)src[0] << 16) |
+                          ((unsigned int)src[1] <<  8) |
+                          ((unsigned int)src[2]      ) |
+                          ((unsigned int)src[1] << 24) ;
+
+                    dst[x] = pix;
+                }
+            }
+        }
+        else
+        {
+          /* convert horizontal BGR into ARGB32 */
+          for ( h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch )
+          {
+              int            x;
+              unsigned char* src = srcLine;
+              unsigned int*  dst = (unsigned int*)dstLine;
+
+              for ( x = 0; x < width; x++, src += 3 )
+              {
+                  unsigned int  pix;
+
+                  pix = ((unsigned int)src[2] << 16) |
+                        ((unsigned int)src[1] <<  8) |
+                        ((unsigned int)src[0]      ) |
+                        ((unsigned int)src[1] << 24) ;
+
+                  dst[x] = pix;
+              }
+          }
+        }
+        break;
+
+    default:  /* FT_PIXEL_MODE_LCD_V */
+        /* convert vertical RGB into ARGB32 */
+        if ( !bgr )
+        {
+            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
+            {
+                int            x;
+                unsigned char* src = srcLine;
+                unsigned int*  dst = (unsigned int*)dstLine;
+
+                for ( x = 0; x < width; x++, src += 1 )
+                {
+                    unsigned int  pix;
+#if 1
+                    pix = ((unsigned int)src[0]           << 16) |
+                          ((unsigned int)src[src_pitch]   <<  8) |
+                          ((unsigned int)src[src_pitch*2]      ) |
+                          0xFF000000 ;
+#else
+                    pix = ((unsigned int)src[0]           << 16) |
+                          ((unsigned int)src[src_pitch]   <<  8) |
+                          ((unsigned int)src[src_pitch*2]      ) |
+                          ((unsigned int)src[src_pitch]   << 24) ;
 #endif
-    {    65538*9/13,65538*3/13,65538*1/13 },
-    /* green */
-    {    65538*1/6, 65538*4/6, 65538*1/6 },
-    /* blue */
-    {    65538*1/13,65538*3/13,65538*9/13 },
-};
+                    dst[x] = pix;
+                }
+            }
+        }
+        else
+        {
+            for ( h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch )
+            {
+                int            x;
+                unsigned char* src = srcLine;
+                unsigned int*  dst = (unsigned int*)dstLine;
+
+                for ( x = 0; x < width; x++, src += 1 )
+                {
+                    unsigned int  pix;
+
+                    pix = ((unsigned int)src[src_pitch*2] << 16) |
+                        ((unsigned int)src[src_pitch]   <<  8) |
+                        ((unsigned int)src[0]                ) |
+                        ((unsigned int)src[src_pitch]   << 24) ;
+
+                    dst[x] = pix;
+                }
+            }
+        }
+    }
+}
+
 
 /* Fills in val->image with an image surface created from @bitmap
  */
@@ -766,7 +1045,7 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
     int width, height, stride;
     unsigned char *data;
     int format = CAIRO_FORMAT_A8;
-    cairo_bool_t subpixel = FALSE;
+    cairo_image_surface_t  *image;
 
     width = bitmap->width;
     height = bitmap->rows;
@@ -805,7 +1084,6 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 		}
 	    }
 	}
-
 #ifndef WORDS_BIGENDIAN
 	{
 	    unsigned char   *d = data;
@@ -817,17 +1095,15 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	    }
 	}
 #endif
+
 	format = CAIRO_FORMAT_A1;
 	break;
 
     case FT_PIXEL_MODE_LCD:
     case FT_PIXEL_MODE_LCD_V:
     case FT_PIXEL_MODE_GRAY:
-	switch (font_options->antialias) {
-	case CAIRO_ANTIALIAS_DEFAULT:
-	case CAIRO_ANTIALIAS_GRAY:
-	case CAIRO_ANTIALIAS_NONE:
-	default:
+        if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL)
+        {
 	    stride = bitmap->pitch;
 	    if (own_buffer) {
 		data = bitmap->buffer;
@@ -839,104 +1115,16 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 		memcpy (data, bitmap->buffer, stride * height);
 	    }
 	    format = CAIRO_FORMAT_A8;
-	    break;
-	case CAIRO_ANTIALIAS_SUBPIXEL: {
-	    int		    x, y;
-	    unsigned char   *in_line, *out_line, *in;
-	    unsigned int    *out;
-	    unsigned int    red, green, blue;
-	    int		    rf, gf, bf;
-	    int		    s;
-	    int		    o, os;
-	    unsigned char   *data_rgba;
-	    unsigned int    width_rgba, stride_rgba;
-	    int		    vmul = 1;
-	    int		    hmul = 1;
-
-	    switch (font_options->subpixel_order) {
-	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
-	    case CAIRO_SUBPIXEL_ORDER_RGB:
-	    case CAIRO_SUBPIXEL_ORDER_BGR:
-	    default:
-		width /= 3;
-		hmul = 3;
-		break;
-	    case CAIRO_SUBPIXEL_ORDER_VRGB:
-	    case CAIRO_SUBPIXEL_ORDER_VBGR:
-		vmul = 3;
-		height /= 3;
-		break;
-	    }
-	    /*
-	     * Filter the glyph to soften the color fringes
-	     */
-	    width_rgba = width;
+        } 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;
-	    stride_rgba = (width_rgba * 4 + 3) & ~3;
-	    data_rgba = calloc (stride_rgba, height);
-	    if (data_rgba == NULL) {
-		if (own_buffer)
-		    free (bitmap->buffer);
-		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    }
-
-	    os = 1;
-	    switch (font_options->subpixel_order) {
-	    case CAIRO_SUBPIXEL_ORDER_VRGB:
-		os = stride;
-	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
-	    case CAIRO_SUBPIXEL_ORDER_RGB:
-	    default:
-		rf = 0;
-		gf = 1;
-		bf = 2;
-		break;
-	    case CAIRO_SUBPIXEL_ORDER_VBGR:
-		os = stride;
-	    case CAIRO_SUBPIXEL_ORDER_BGR:
-		bf = 0;
-		gf = 1;
-		rf = 2;
-		break;
-	    }
-	    in_line = bitmap->buffer;
-	    out_line = data_rgba;
-	    for (y = 0; y < height; y++)
-	    {
-		in = in_line;
-		out = (unsigned int *) out_line;
-		in_line += stride * vmul;
-		out_line += stride_rgba;
-		for (x = 0; x < width * hmul; x += hmul)
-		{
-		    red = green = blue = 0;
-		    o = 0;
-		    for (s = 0; s < 3; s++)
-		    {
-			red += filters[rf][s]*in[x+o];
-			green += filters[gf][s]*in[x+o];
-			blue += filters[bf][s]*in[x+o];
-			o += os;
-		    }
-		    red = red / 65536;
-		    green = green / 65536;
-		    blue = blue / 65536;
-		    *out++ = (green << 24) | (red << 16) | (green << 8) | blue;
-		}
-	    }
-
-	    /* Images here are stored in native format. The
-	     * backend must convert to its own format as needed
-	     */
-
-	    if (own_buffer)
-		free (bitmap->buffer);
-	    data = data_rgba;
-	    stride = stride_rgba;
 	    format = CAIRO_FORMAT_ARGB32;
-	    subpixel = TRUE;
-	    break;
-	}
 	}
 	break;
     case FT_PIXEL_MODE_GRAY2:
@@ -948,19 +1136,20 @@ _get_bitmap_surface (FT_Bitmap		     *bitmap,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
-    *surface = (cairo_image_surface_t *)
+    /* XXX */
+    *surface = image = (cairo_image_surface_t *)
 	cairo_image_surface_create_for_data (data,
 					     format,
 					     width, height, stride);
-    if ((*surface)->base.status) {
+    if (image->base.status) {
 	free (data);
 	return (*surface)->base.status;
     }
 
-    if (subpixel)
-	pixman_image_set_component_alpha ((*surface)->pixman_image, TRUE);
+    if (font_options->antialias == CAIRO_ANTIALIAS_SUBPIXEL)
+	pixman_image_set_component_alpha (image->pixman_image, TRUE);
 
-    _cairo_image_surface_assume_ownership_of_data ((*surface));
+    _cairo_image_surface_assume_ownership_of_data (image);
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -985,16 +1174,44 @@ _render_glyph_outline (FT_Face                    face,
 		       cairo_font_options_t	 *font_options,
 		       cairo_image_surface_t	**surface)
 {
+    int rgba = FC_RGBA_UNKNOWN;
     FT_GlyphSlot glyphslot = face->glyph;
     FT_Outline *outline = &glyphslot->outline;
     FT_Bitmap bitmap;
     FT_BBox cbox;
-    FT_Matrix matrix;
-    int hmul = 1;
-    int vmul = 1;
     unsigned int width, height, stride;
-    cairo_bool_t subpixel = FALSE;
     cairo_status_t status;
+    FT_Error  fterror;
+    FT_Library  library = glyphslot->library;
+    FT_Render_Mode  render_mode = FT_RENDER_MODE_NORMAL;
+
+    switch (font_options->antialias)
+    {
+    case CAIRO_ANTIALIAS_NONE:
+        render_mode = FT_RENDER_MODE_MONO;
+        break;
+
+    case CAIRO_ANTIALIAS_SUBPIXEL:
+        switch (font_options->subpixel_order)
+        {
+            case CAIRO_SUBPIXEL_ORDER_DEFAULT:
+            case CAIRO_SUBPIXEL_ORDER_RGB:
+            case CAIRO_SUBPIXEL_ORDER_BGR:
+                render_mode = FT_RENDER_MODE_LCD;
+                break;
+
+            case CAIRO_SUBPIXEL_ORDER_VRGB:
+            case CAIRO_SUBPIXEL_ORDER_VBGR:
+                render_mode = FT_RENDER_MODE_LCD_V;
+                break;
+        }
+
+        break;
+
+    case CAIRO_ANTIALIAS_DEFAULT:
+    case CAIRO_ANTIALIAS_GRAY:
+        render_mode = FT_RENDER_MODE_NORMAL;
+    }
 
     FT_Outline_Get_CBox (outline, &cbox);
 
@@ -1005,20 +1222,22 @@ _render_glyph_outline (FT_Face                    face,
 
     width = (unsigned int) ((cbox.xMax - cbox.xMin) >> 6);
     height = (unsigned int) ((cbox.yMax - cbox.yMin) >> 6);
-    stride = (width * hmul + 3) & ~3;
+    stride = (width + 3) & ~3;
 
     if (width * height == 0) {
 	cairo_format_t format;
 	/* Looks like fb handles zero-sized images just fine */
-	switch (font_options->antialias) {
-	case CAIRO_ANTIALIAS_NONE:
+	switch (render_mode) {
+	case FT_RENDER_MODE_MONO:
 	    format = CAIRO_FORMAT_A1;
 	    break;
-	case CAIRO_ANTIALIAS_SUBPIXEL:
+	case FT_RENDER_MODE_LCD:
+	case FT_RENDER_MODE_LCD_V:
 	    format= CAIRO_FORMAT_ARGB32;
 	    break;
-	case CAIRO_ANTIALIAS_DEFAULT:
-	case CAIRO_ANTIALIAS_GRAY:
+	case FT_RENDER_MODE_LIGHT:
+	case FT_RENDER_MODE_NORMAL:
+	case FT_RENDER_MODE_MAX:
 	default:
 	    format = CAIRO_FORMAT_A8;
 	    break;
@@ -1030,73 +1249,70 @@ _render_glyph_outline (FT_Face                    face,
 	    return (*surface)->base.status;
     } else  {
 
-	matrix.xx = matrix.yy = 0x10000L;
-	matrix.xy = matrix.yx = 0;
+	int bitmap_size;
 
-	switch (font_options->antialias) {
-	case CAIRO_ANTIALIAS_NONE:
-	    bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
-	    bitmap.num_grays  = 1;
-	    stride = ((width + 31) & -32) >> 3;
-	    break;
-	case CAIRO_ANTIALIAS_DEFAULT:
-	case CAIRO_ANTIALIAS_GRAY:
-	    bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
-	    bitmap.num_grays  = 256;
-	    stride = (width + 3) & -4;
+	switch (render_mode) {
+	case FT_RENDER_MODE_LCD:
+	    if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_BGR) {
+		rgba = FC_RGBA_BGR;
+	    } else {
+		rgba = FC_RGBA_RGB;
+	    }
 	    break;
-	case CAIRO_ANTIALIAS_SUBPIXEL:
-	    switch (font_options->subpixel_order) {
-	    case CAIRO_SUBPIXEL_ORDER_RGB:
-	    case CAIRO_SUBPIXEL_ORDER_BGR:
-	    case CAIRO_SUBPIXEL_ORDER_DEFAULT:
-	    default:
-		matrix.xx *= 3;
-		hmul = 3;
-		subpixel = TRUE;
-		break;
-	    case CAIRO_SUBPIXEL_ORDER_VRGB:
-	    case CAIRO_SUBPIXEL_ORDER_VBGR:
-		matrix.yy *= 3;
-		vmul = 3;
-		subpixel = TRUE;
-		break;
+	case FT_RENDER_MODE_LCD_V:
+	    if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_VBGR) {
+		rgba = FC_RGBA_VBGR;
+	    } else {
+		rgba = FC_RGBA_VRGB;
 	    }
-	    FT_Outline_Transform (outline, &matrix);
-
-	    bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
-	    bitmap.num_grays  = 256;
-	    stride = (width * hmul + 3) & -4;
+	    break;
+	case FT_RENDER_MODE_MONO:
+	case FT_RENDER_MODE_LIGHT:
+	case FT_RENDER_MODE_NORMAL:
+	case FT_RENDER_MODE_MAX:
+	default:
+	    break;
 	}
 
-	bitmap.pitch = stride;
-	bitmap.width = width * hmul;
-	bitmap.rows = height * vmul;
-	bitmap.buffer = calloc (stride, bitmap.rows);
-	if (bitmap.buffer == NULL)
+	FT_Library_SetLcdFilter( library, FT_LCD_FILTER_DEFAULT );
+
+	fterror = FT_Render_Glyph( face->glyph, render_mode );
+
+	FT_Library_SetLcdFilter( library, FT_LCD_FILTER_NONE );
+
+	if (fterror != 0)
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-	FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul);
+	bitmap_size = _compute_xrender_bitmap_size(&bitmap,
+						   face->glyph,
+						   render_mode);
+	if (bitmap_size < 0) {
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	}
 
-	if (FT_Outline_Get_Bitmap (glyphslot->library, outline, &bitmap) != 0) {
-	    free (bitmap.buffer);
+	bitmap.buffer = calloc(1, bitmap_size);
+	if (bitmap.buffer == NULL) {
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
+	_fill_xrender_bitmap(&bitmap, face->glyph, render_mode,
+			     (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR));
+
+	// NOTE: _get_bitmap_surface will free bitmap.buffer if there is an error
 	status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
 	if (status)
 	    return status;
-    }
 
-    /*
-     * Note: the font's coordinate system is upside down from ours, so the
-     * Y coordinate of the control box needs to be negated.  Moreover, device
-     * offsets are position of glyph origin relative to top left while xMin
-     * and yMax are offsets of top left relative to origin.  Another negation.
-     */
-    cairo_surface_set_device_offset (&(*surface)->base,
-				     floor (-(double) cbox.xMin / 64.0),
-				     floor (+(double) cbox.yMax / 64.0));
+	/*
+	 * Note: the font's coordinate system is upside down from ours, so the
+	 * Y coordinate of the control box needs to be negated.  Moreover, device
+	 * offsets are position of glyph origin relative to top left while xMin
+	 * and yMax are offsets of top left relative to origin.  Another negation.
+	 */
+	cairo_surface_set_device_offset (&(*surface)->base,
+					 (double)-glyphslot->bitmap_left,
+					 (double)+glyphslot->bitmap_top);
+    }
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -1474,11 +1690,11 @@ _cairo_ft_options_merge (cairo_ft_options_t *options,
 		case CAIRO_SUBPIXEL_ORDER_DEFAULT:
 		case CAIRO_SUBPIXEL_ORDER_RGB:
 		case CAIRO_SUBPIXEL_ORDER_BGR:
-		    load_target |= FT_LOAD_TARGET_LCD;
+		    load_target = FT_LOAD_TARGET_LCD;
 		    break;
 		case CAIRO_SUBPIXEL_ORDER_VRGB:
 		case CAIRO_SUBPIXEL_ORDER_VBGR:
-		    load_target |= FT_LOAD_TARGET_LCD_V;
+		    load_target = FT_LOAD_TARGET_LCD_V;
 		break;
 		}
 	    }


More information about the cairo-commit mailing list