1 diff -Naur cairo-1.8.6.orig/src/cairo-font-options.c cairo-1.8.6/src/cairo-font-options.c
2 --- cairo-1.8.6.orig/src/cairo-font-options.c Wed Feb 18 15:51:43 2009
3 +++ cairo-1.8.6/src/cairo-font-options.c Wed Feb 18 15:53:59 2009
5 static const cairo_font_options_t _cairo_font_options_nil = {
6 CAIRO_ANTIALIAS_DEFAULT,
7 CAIRO_SUBPIXEL_ORDER_DEFAULT,
8 + CAIRO_LCD_FILTER_DEFAULT,
9 CAIRO_HINT_STYLE_DEFAULT,
10 CAIRO_HINT_METRICS_DEFAULT
14 options->antialias = CAIRO_ANTIALIAS_DEFAULT;
15 options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
16 + options->lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
17 options->hint_style = CAIRO_HINT_STYLE_DEFAULT;
18 options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
22 options->antialias = other->antialias;
23 options->subpixel_order = other->subpixel_order;
24 + options->lcd_filter = other->lcd_filter;
25 options->hint_style = other->hint_style;
26 options->hint_metrics = other->hint_metrics;
29 options->antialias = other->antialias;
30 if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
31 options->subpixel_order = other->subpixel_order;
32 + if (other->lcd_filter != CAIRO_LCD_FILTER_DEFAULT)
33 + options->lcd_filter = other->lcd_filter;
34 if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT)
35 options->hint_style = other->hint_style;
36 if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT)
39 return (options->antialias == other->antialias &&
40 options->subpixel_order == other->subpixel_order &&
41 + options->lcd_filter == other->lcd_filter &&
42 options->hint_style == other->hint_style &&
43 options->hint_metrics == other->hint_metrics);
47 return ((options->antialias) |
48 (options->subpixel_order << 4) |
49 - (options->hint_style << 8) |
50 + (options->lcd_filter << 8) |
51 + (options->hint_style << 12) |
52 (options->hint_metrics << 16));
54 slim_hidden_def (cairo_font_options_hash);
56 return CAIRO_SUBPIXEL_ORDER_DEFAULT;
58 return options->subpixel_order;
62 + * _cairo_font_options_set_lcd_filter:
63 + * @options: a #cairo_font_options_t
64 + * @lcd_filter: the new LCD filter
66 + * Sets the LCD filter for the font options object. The LCD filter
67 + * specifies how pixels are filtered when rendered with an antialiasing
68 + * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for
69 + * #cairo_lcd_filter_t for full details.
74 +_cairo_font_options_set_lcd_filter (cairo_font_options_t *options,
75 + cairo_lcd_filter_t lcd_filter)
77 + if (cairo_font_options_status (options))
80 + options->lcd_filter = lcd_filter;
84 + * _cairo_font_options_get_lcd_filter:
85 + * @options: a #cairo_font_options_t
87 + * Gets the LCD filter for the font options object.
88 + * See the documentation for #cairo_lcd_filter_t for full details.
90 + * Return value: the LCD filter for the font options object
95 +_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options)
97 + if (cairo_font_options_status ((cairo_font_options_t *) options))
98 + return CAIRO_LCD_FILTER_DEFAULT;
100 + return options->lcd_filter;
104 diff -Naur cairo-1.8.6.orig/src/cairo-ft-font.c cairo-1.8.6/src/cairo-ft-font.c
105 --- cairo-1.8.6.orig/src/cairo-ft-font.c Wed Feb 18 15:52:15 2009
106 +++ cairo-1.8.6/src/cairo-ft-font.c Wed Feb 18 15:53:59 2009
108 #include FT_SYNTHESIS_H
111 +#if HAVE_FT_LIBRARY_SETLCDFILTER
112 +#include FT_LCD_FILTER_H
115 +/* Fontconfig version older than 2.6 didn't have these options */
116 +#ifndef FC_LCD_FILTER
117 +#define FC_LCD_FILTER "lcdfilter"
119 +/* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */
121 +#define FC_LCD_NONE 0
122 +#define FC_LCD_DEFAULT 1
123 +#define FC_LCD_LIGHT 2
124 +#define FC_LCD_LEGACY 3
127 +/* FreeType version older than 2.3.5(?) didn't have these options */
128 +#ifndef FT_LCD_FILTER_NONE
129 +#define FT_LCD_FILTER_NONE 0
130 +#define FT_LCD_FILTER_DEFAULT 1
131 +#define FT_LCD_FILTER_LIGHT 2
132 +#define FT_LCD_FILTER_LEGACY 16
135 #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
136 #define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
137 #define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
138 @@ -738,23 +762,286 @@
139 return CAIRO_STATUS_SUCCESS;
142 -/* Empirically-derived subpixel filtering values thanks to Keith
143 - * Packard and libXft. */
144 -static const int filters[3][3] = {
147 - { 65538*4/7,65538*2/7,65538*1/7 },
149 - { 65536*1/4, 65536*2/4, 65537*1/4 },
151 - { 65538*1/7,65538*2/7,65538*4/7 },
152 +/* we sometimes need to convert the glyph bitmap in a FT_GlyphSlot
153 + * into a different format. For example, we want to convert a
154 + * FT_PIXEL_MODE_LCD or FT_PIXEL_MODE_LCD_V bitmap into a 32-bit
155 + * ARGB or ABGR bitmap.
157 + * this function prepares a target descriptor for this operation.
159 + * input :: target bitmap descriptor. The function will set its
160 + * 'width', 'rows' and 'pitch' fields, and only these
162 + * slot :: the glyph slot containing the source bitmap. this
163 + * function assumes that slot->format == FT_GLYPH_FORMAT_BITMAP
165 + * mode :: the requested final rendering mode. supported values are
166 + * MONO, NORMAL (i.e. gray), LCD and LCD_V
168 + * the function returns the size in bytes of the corresponding buffer,
169 + * it's up to the caller to allocate the corresponding memory block
170 + * before calling _fill_xrender_bitmap
172 + * it also returns -1 in case of error (e.g. incompatible arguments,
173 + * like trying to convert a gray bitmap into a monochrome one)
176 +_compute_xrender_bitmap_size(FT_Bitmap *target,
178 + FT_Render_Mode mode)
181 + int width, height, pitch;
183 + if (slot->format != FT_GLYPH_FORMAT_BITMAP)
186 + /* compute the size of the final bitmap */
187 + ftbit = &slot->bitmap;
189 + width = ftbit->width;
190 + height = ftbit->rows;
191 + pitch = (width + 3) & ~3;
193 + switch (ftbit->pixel_mode) {
194 + case FT_PIXEL_MODE_MONO:
195 + if (mode == FT_RENDER_MODE_MONO) {
196 + pitch = (((width + 31) & ~31) >> 3);
201 + case FT_PIXEL_MODE_GRAY:
202 + if (mode == FT_RENDER_MODE_LCD ||
203 + mode == FT_RENDER_MODE_LCD_V)
205 + /* each pixel is replicated into a 32-bit ARGB value */
210 + case FT_PIXEL_MODE_LCD:
211 + if (mode != FT_RENDER_MODE_LCD)
214 + /* horz pixel triplets are packed into 32-bit ARGB values */
219 + case FT_PIXEL_MODE_LCD_V:
220 + if (mode != FT_RENDER_MODE_LCD_V)
223 + /* vert pixel triplets are packed into 32-bit ARGB values */
228 + default: /* unsupported source format */
232 + target->width = width;
233 + target->rows = height;
234 + target->pitch = pitch;
235 + target->buffer = NULL;
237 + return pitch * height;
240 +/* this functions converts the glyph bitmap found in a FT_GlyphSlot
241 + * into a different format (see _compute_xrender_bitmap_size)
243 + * you should call this function after _compute_xrender_bitmap_size
245 + * target :: target bitmap descriptor. Note that its 'buffer' pointer
246 + * must point to memory allocated by the caller
248 + * slot :: the glyph slot containing the source bitmap
250 + * mode :: the requested final rendering mode
252 + * bgr :: boolean, set if BGR or VBGR pixel ordering is needed
255 +_fill_xrender_bitmap(FT_Bitmap *target,
257 + FT_Render_Mode mode,
260 + FT_Bitmap *ftbit = &slot->bitmap;
261 + unsigned char *srcLine = ftbit->buffer;
262 + unsigned char *dstLine = target->buffer;
263 + int src_pitch = ftbit->pitch;
264 + int width = target->width;
265 + int height = target->rows;
266 + int pitch = target->pitch;
270 + subpixel = (mode == FT_RENDER_MODE_LCD ||
271 + mode == FT_RENDER_MODE_LCD_V);
274 + srcLine -= src_pitch * (ftbit->rows - 1);
276 + target->pixel_mode = ftbit->pixel_mode;
278 + switch (ftbit->pixel_mode) {
279 + case FT_PIXEL_MODE_MONO:
281 + /* convert mono to ARGB32 values */
283 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
286 + for (x = 0; x < width; x++) {
287 + if (srcLine[(x >> 3)] & (0x80 >> (x & 7)))
288 + ((unsigned int *) dstLine)[x] = 0xffffffffU;
291 + target->pixel_mode = FT_PIXEL_MODE_LCD;
293 + } else if (mode == FT_RENDER_MODE_NORMAL) {
294 + /* convert mono to 8-bit gray */
296 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
299 + for (x = 0; x < width; x++) {
300 + if (srcLine[(x >> 3)] & (0x80 >> (x & 7)))
304 + target->pixel_mode = FT_PIXEL_MODE_GRAY;
307 + /* copy mono to mono */
309 + int bytes = (width + 7) >> 3;
311 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch)
312 + memcpy (dstLine, srcLine, bytes);
316 + case FT_PIXEL_MODE_GRAY:
318 + /* convert gray to ARGB32 values */
320 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
322 + unsigned int *dst = (unsigned int *) dstLine;
324 + for (x = 0; x < width; x++) {
325 + unsigned int pix = srcLine[x];
328 + pix |= (pix << 16);
333 + target->pixel_mode = FT_PIXEL_MODE_LCD;
335 + /* copy gray into gray */
337 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch)
338 + memcpy (dstLine, srcLine, width);
342 + case FT_PIXEL_MODE_LCD:
344 + /* convert horizontal RGB into ARGB32 */
346 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
348 + unsigned char *src = srcLine;
349 + unsigned int *dst = (unsigned int *) dstLine;
351 + for (x = 0; x < width; x++, src += 3) {
354 + pix = ((unsigned int)src[0] << 16) |
355 + ((unsigned int)src[1] << 8) |
356 + ((unsigned int)src[2] ) |
357 + ((unsigned int)src[1] << 24) ;
363 + /* convert horizontal BGR into ARGB32 */
365 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
368 + unsigned char *src = srcLine;
369 + unsigned int *dst = (unsigned int *) dstLine;
371 + for (x = 0; x < width; x++, src += 3) {
374 + pix = ((unsigned int)src[2] << 16) |
375 + ((unsigned int)src[1] << 8) |
376 + ((unsigned int)src[0] ) |
377 + ((unsigned int)src[1] << 24) ;
385 + default: /* FT_PIXEL_MODE_LCD_V */
386 + /* convert vertical RGB into ARGB32 */
389 + for (h = height; h > 0; h--, srcLine += 3 * src_pitch, dstLine += pitch) {
391 + unsigned char* src = srcLine;
392 + unsigned int* dst = (unsigned int *) dstLine;
394 + for (x = 0; x < width; x++, src += 1) {
397 + pix = ((unsigned int)src[0] << 16) |
398 + ((unsigned int)src[src_pitch] << 8) |
399 + ((unsigned int)src[src_pitch*2] ) |
402 + pix = ((unsigned int)src[0] << 16) |
403 + ((unsigned int)src[src_pitch] << 8) |
404 + ((unsigned int)src[src_pitch*2] ) |
405 + ((unsigned int)src[src_pitch] << 24) ;
407 - { 65538*9/13,65538*3/13,65538*1/13 },
409 - { 65538*1/6, 65538*4/6, 65538*1/6 },
411 - { 65538*1/13,65538*3/13,65538*9/13 },
418 + for (h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch) {
420 + unsigned char *src = srcLine;
421 + unsigned int *dst = (unsigned int *) dstLine;
423 + for (x = 0; x < width; x++, src += 1) {
426 + pix = ((unsigned int)src[src_pitch * 2] << 16) |
427 + ((unsigned int)src[src_pitch] << 8) |
428 + ((unsigned int)src[0] ) |
429 + ((unsigned int)src[src_pitch] << 24) ;
439 /* Fills in val->image with an image surface created from @bitmap
442 int width, height, stride;
444 int format = CAIRO_FORMAT_A8;
445 - cairo_bool_t subpixel = FALSE;
446 + cairo_image_surface_t *image;
448 width = bitmap->width;
449 height = bitmap->rows;
450 @@ -824,11 +1111,7 @@
451 case FT_PIXEL_MODE_LCD:
452 case FT_PIXEL_MODE_LCD_V:
453 case FT_PIXEL_MODE_GRAY:
454 - switch (font_options->antialias) {
455 - case CAIRO_ANTIALIAS_DEFAULT:
456 - case CAIRO_ANTIALIAS_GRAY:
457 - case CAIRO_ANTIALIAS_NONE:
459 + if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL) {
460 stride = bitmap->pitch;
462 data = bitmap->buffer;
463 @@ -840,104 +1123,16 @@
464 memcpy (data, bitmap->buffer, stride * height);
466 format = CAIRO_FORMAT_A8;
468 - case CAIRO_ANTIALIAS_SUBPIXEL: {
470 - unsigned char *in_line, *out_line, *in;
472 - unsigned int red, green, blue;
476 - unsigned char *data_rgba;
477 - unsigned int width_rgba, stride_rgba;
481 + /* if we get there, the data from the source bitmap
482 + * really comes from _fill_xrender_bitmap, and is
483 + * made of 32-bit ARGB or ABGR values */
484 + assert (own_buffer != 0);
485 + assert (bitmap->pixel_mode != FT_PIXEL_MODE_GRAY);
487 - switch (font_options->subpixel_order) {
488 - case CAIRO_SUBPIXEL_ORDER_DEFAULT:
489 - case CAIRO_SUBPIXEL_ORDER_RGB:
490 - case CAIRO_SUBPIXEL_ORDER_BGR:
495 - case CAIRO_SUBPIXEL_ORDER_VRGB:
496 - case CAIRO_SUBPIXEL_ORDER_VBGR:
502 - * Filter the glyph to soften the color fringes
504 - width_rgba = width;
505 + data = bitmap->buffer;
506 stride = bitmap->pitch;
507 - stride_rgba = (width_rgba * 4 + 3) & ~3;
508 - data_rgba = calloc (stride_rgba, height);
509 - if (data_rgba == NULL) {
511 - free (bitmap->buffer);
512 - return _cairo_error (CAIRO_STATUS_NO_MEMORY);
516 - switch (font_options->subpixel_order) {
517 - case CAIRO_SUBPIXEL_ORDER_VRGB:
519 - case CAIRO_SUBPIXEL_ORDER_DEFAULT:
520 - case CAIRO_SUBPIXEL_ORDER_RGB:
526 - case CAIRO_SUBPIXEL_ORDER_VBGR:
528 - case CAIRO_SUBPIXEL_ORDER_BGR:
534 - in_line = bitmap->buffer;
535 - out_line = data_rgba;
536 - for (y = 0; y < height; y++)
539 - out = (unsigned int *) out_line;
540 - in_line += stride * vmul;
541 - out_line += stride_rgba;
542 - for (x = 0; x < width * hmul; x += hmul)
544 - red = green = blue = 0;
546 - for (s = 0; s < 3; s++)
548 - red += filters[rf][s]*in[x+o];
549 - green += filters[gf][s]*in[x+o];
550 - blue += filters[bf][s]*in[x+o];
554 - green = green / 65536;
555 - blue = blue / 65536;
556 - *out++ = (green << 24) | (red << 16) | (green << 8) | blue;
560 - /* Images here are stored in native format. The
561 - * backend must convert to its own format as needed
565 - free (bitmap->buffer);
567 - stride = stride_rgba;
568 format = CAIRO_FORMAT_ARGB32;
574 case FT_PIXEL_MODE_GRAY2:
575 @@ -949,19 +1144,20 @@
576 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
579 - *surface = (cairo_image_surface_t *)
581 + *surface = image = (cairo_image_surface_t *)
582 cairo_image_surface_create_for_data (data,
584 width, height, stride);
585 - if ((*surface)->base.status) {
586 + if (image->base.status) {
588 return (*surface)->base.status;
592 - pixman_image_set_component_alpha ((*surface)->pixman_image, TRUE);
593 + if (font_options->antialias == CAIRO_ANTIALIAS_SUBPIXEL)
594 + pixman_image_set_component_alpha (image->pixman_image, TRUE);
596 - _cairo_image_surface_assume_ownership_of_data ((*surface));
597 + _cairo_image_surface_assume_ownership_of_data (image);
599 return CAIRO_STATUS_SUCCESS;
601 @@ -986,16 +1182,59 @@
602 cairo_font_options_t *font_options,
603 cairo_image_surface_t **surface)
605 + int rgba = FC_RGBA_UNKNOWN;
606 + int lcd_filter = FT_LCD_FILTER_LEGACY;
607 FT_GlyphSlot glyphslot = face->glyph;
608 FT_Outline *outline = &glyphslot->outline;
614 - unsigned int width, height, stride;
615 - cairo_bool_t subpixel = FALSE;
616 + unsigned int width, height;
617 cairo_status_t status;
619 + FT_Library library = glyphslot->library;
620 + FT_Render_Mode render_mode = FT_RENDER_MODE_NORMAL;
622 + switch (font_options->antialias) {
623 + case CAIRO_ANTIALIAS_NONE:
624 + render_mode = FT_RENDER_MODE_MONO;
627 + case CAIRO_ANTIALIAS_SUBPIXEL:
628 + switch (font_options->subpixel_order) {
629 + case CAIRO_SUBPIXEL_ORDER_DEFAULT:
630 + case CAIRO_SUBPIXEL_ORDER_RGB:
631 + case CAIRO_SUBPIXEL_ORDER_BGR:
632 + render_mode = FT_RENDER_MODE_LCD;
635 + case CAIRO_SUBPIXEL_ORDER_VRGB:
636 + case CAIRO_SUBPIXEL_ORDER_VBGR:
637 + render_mode = FT_RENDER_MODE_LCD_V;
641 + switch (font_options->lcd_filter) {
642 + case CAIRO_LCD_FILTER_NONE:
643 + lcd_filter = FT_LCD_FILTER_NONE;
645 + case CAIRO_LCD_FILTER_DEFAULT:
646 + case CAIRO_LCD_FILTER_INTRA_PIXEL:
647 + lcd_filter = FT_LCD_FILTER_LEGACY;
649 + case CAIRO_LCD_FILTER_FIR3:
650 + lcd_filter = FT_LCD_FILTER_LIGHT;
652 + case CAIRO_LCD_FILTER_FIR5:
653 + lcd_filter = FT_LCD_FILTER_DEFAULT;
659 + case CAIRO_ANTIALIAS_DEFAULT:
660 + case CAIRO_ANTIALIAS_GRAY:
661 + render_mode = FT_RENDER_MODE_NORMAL;
664 FT_Outline_Get_CBox (outline, &cbox);
666 @@ -1006,20 +1245,21 @@
668 width = (unsigned int) ((cbox.xMax - cbox.xMin) >> 6);
669 height = (unsigned int) ((cbox.yMax - cbox.yMin) >> 6);
670 - stride = (width * hmul + 3) & ~3;
672 if (width * height == 0) {
673 cairo_format_t format;
674 /* Looks like fb handles zero-sized images just fine */
675 - switch (font_options->antialias) {
676 - case CAIRO_ANTIALIAS_NONE:
677 + switch (render_mode) {
678 + case FT_RENDER_MODE_MONO:
679 format = CAIRO_FORMAT_A1;
681 - case CAIRO_ANTIALIAS_SUBPIXEL:
682 + case FT_RENDER_MODE_LCD:
683 + case FT_RENDER_MODE_LCD_V:
684 format= CAIRO_FORMAT_ARGB32;
686 - case CAIRO_ANTIALIAS_DEFAULT:
687 - case CAIRO_ANTIALIAS_GRAY:
688 + case FT_RENDER_MODE_LIGHT:
689 + case FT_RENDER_MODE_NORMAL:
690 + case FT_RENDER_MODE_MAX:
692 format = CAIRO_FORMAT_A8;
694 @@ -1031,73 +1271,73 @@
695 return (*surface)->base.status;
698 - matrix.xx = matrix.yy = 0x10000L;
699 - matrix.xy = matrix.yx = 0;
702 - switch (font_options->antialias) {
703 - case CAIRO_ANTIALIAS_NONE:
704 - bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
705 - bitmap.num_grays = 1;
706 - stride = ((width + 31) & -32) >> 3;
708 - case CAIRO_ANTIALIAS_DEFAULT:
709 - case CAIRO_ANTIALIAS_GRAY:
710 - bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
711 - bitmap.num_grays = 256;
712 - stride = (width + 3) & -4;
713 + switch (render_mode) {
714 + case FT_RENDER_MODE_LCD:
715 + if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_BGR) {
716 + rgba = FC_RGBA_BGR;
718 + rgba = FC_RGBA_RGB;
721 - case CAIRO_ANTIALIAS_SUBPIXEL:
722 - switch (font_options->subpixel_order) {
723 - case CAIRO_SUBPIXEL_ORDER_RGB:
724 - case CAIRO_SUBPIXEL_ORDER_BGR:
725 - case CAIRO_SUBPIXEL_ORDER_DEFAULT:
731 - case CAIRO_SUBPIXEL_ORDER_VRGB:
732 - case CAIRO_SUBPIXEL_ORDER_VBGR:
737 + case FT_RENDER_MODE_LCD_V:
738 + if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_VBGR) {
739 + rgba = FC_RGBA_VBGR;
741 + rgba = FC_RGBA_VRGB;
743 - FT_Outline_Transform (outline, &matrix);
745 - bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
746 - bitmap.num_grays = 256;
747 - stride = (width * hmul + 3) & -4;
749 + case FT_RENDER_MODE_MONO:
750 + case FT_RENDER_MODE_LIGHT:
751 + case FT_RENDER_MODE_NORMAL:
752 + case FT_RENDER_MODE_MAX:
757 - bitmap.pitch = stride;
758 - bitmap.width = width * hmul;
759 - bitmap.rows = height * vmul;
760 - bitmap.buffer = calloc (stride, bitmap.rows);
761 - if (bitmap.buffer == NULL)
762 +#if HAVE_FT_LIBRARY_SETLCDFILTER
763 + FT_Library_SetLcdFilter (library, lcd_filter);
766 + fterror = FT_Render_Glyph (face->glyph, render_mode);
768 +#if HAVE_FT_LIBRARY_SETLCDFILTER
769 + FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE);
773 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
775 - FT_Outline_Translate (outline, -cbox.xMin*hmul, -cbox.yMin*vmul);
776 + bitmap_size = _compute_xrender_bitmap_size (&bitmap,
779 + if (bitmap_size < 0)
780 + return _cairo_error (CAIRO_STATUS_NO_MEMORY);
782 - if (FT_Outline_Get_Bitmap (glyphslot->library, outline, &bitmap) != 0) {
783 - free (bitmap.buffer);
784 + bitmap.buffer = calloc (1, bitmap_size);
785 + if (bitmap.buffer == NULL)
786 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
789 + _fill_xrender_bitmap (&bitmap, face->glyph, render_mode,
790 + (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR));
793 + * _get_bitmap_surface will free bitmap.buffer if there is an error
795 status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
801 - * Note: the font's coordinate system is upside down from ours, so the
802 - * Y coordinate of the control box needs to be negated. Moreover, device
803 - * offsets are position of glyph origin relative to top left while xMin
804 - * and yMax are offsets of top left relative to origin. Another negation.
806 - cairo_surface_set_device_offset (&(*surface)->base,
807 - floor (-(double) cbox.xMin / 64.0),
808 - floor (+(double) cbox.yMax / 64.0));
809 + /* Note: the font's coordinate system is upside down from ours, so the
810 + * Y coordinate of the control box needs to be negated. Moreover, device
811 + * offsets are position of glyph origin relative to top left while xMin
812 + * and yMax are offsets of top left relative to origin. Another negation.
814 + cairo_surface_set_device_offset (&(*surface)->base,
815 + (double)-glyphslot->bitmap_left,
816 + (double)+glyphslot->bitmap_top);
819 return CAIRO_STATUS_SUCCESS;
821 @@ -1317,6 +1557,7 @@
824 cairo_subpixel_order_t subpixel_order;
827 /* disable hinting if requested */
828 if (FcPatternGetBool (pattern,
829 @@ -1352,6 +1593,25 @@
830 ft_options.base.antialias = CAIRO_ANTIALIAS_SUBPIXEL;
833 + if (FcPatternGetInteger (pattern,
834 + FC_LCD_FILTER, 0, &lcd_filter) == FcResultMatch)
836 + switch (lcd_filter) {
838 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_NONE;
840 + case FC_LCD_DEFAULT:
841 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR5;
844 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR3;
846 + case FC_LCD_LEGACY:
847 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
853 if (FcPatternGetInteger (pattern,
854 FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch)
855 @@ -1452,6 +1712,12 @@
856 if (other->base.hint_style == CAIRO_HINT_STYLE_NONE)
857 options->base.hint_style = CAIRO_HINT_STYLE_NONE;
859 + if (options->base.lcd_filter == CAIRO_LCD_FILTER_DEFAULT)
860 + options->base.lcd_filter = other->base.lcd_filter;
862 + if (other->base.lcd_filter == CAIRO_LCD_FILTER_NONE)
863 + options->base.lcd_filter = CAIRO_LCD_FILTER_NONE;
865 if (options->base.antialias == CAIRO_ANTIALIAS_NONE) {
866 if (options->base.hint_style == CAIRO_HINT_STYLE_NONE)
867 load_flags |= FT_LOAD_NO_HINTING;
868 @@ -1475,11 +1741,11 @@
869 case CAIRO_SUBPIXEL_ORDER_DEFAULT:
870 case CAIRO_SUBPIXEL_ORDER_RGB:
871 case CAIRO_SUBPIXEL_ORDER_BGR:
872 - load_target |= FT_LOAD_TARGET_LCD;
873 + load_target = FT_LOAD_TARGET_LCD;
875 case CAIRO_SUBPIXEL_ORDER_VRGB:
876 case CAIRO_SUBPIXEL_ORDER_VBGR:
877 - load_target |= FT_LOAD_TARGET_LCD_V;
878 + load_target = FT_LOAD_TARGET_LCD_V;
882 @@ -2420,6 +2686,34 @@
885 if (! FcPatternAddInteger (pattern, FC_RGBA, rgba))
886 + return _cairo_error (CAIRO_STATUS_NO_MEMORY);
890 + if (options->lcd_filter != CAIRO_LCD_FILTER_DEFAULT)
892 + if (FcPatternGet (pattern, FC_LCD_FILTER, 0, &v) == FcResultNoMatch)
896 + switch (options->lcd_filter) {
897 + case CAIRO_LCD_FILTER_NONE:
898 + lcd_filter = FT_LCD_FILTER_NONE;
900 + case CAIRO_LCD_FILTER_DEFAULT:
901 + case CAIRO_LCD_FILTER_INTRA_PIXEL:
902 + lcd_filter = FT_LCD_FILTER_LEGACY;
904 + case CAIRO_LCD_FILTER_FIR3:
905 + lcd_filter = FT_LCD_FILTER_LIGHT;
908 + case CAIRO_LCD_FILTER_FIR5:
909 + lcd_filter = FT_LCD_FILTER_DEFAULT;
913 + if (! FcPatternAddInteger (pattern, FC_LCD_FILTER, lcd_filter))
914 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
917 diff -Naur cairo-1.8.6.orig/src/cairo-surface.c cairo-1.8.6/src/cairo-surface.c
918 --- cairo-1.8.6.orig/src/cairo-surface.c Wed Feb 18 15:51:43 2009
919 +++ cairo-1.8.6/src/cairo-surface.c Wed Feb 18 15:53:59 2009
921 FALSE, /* has_font_options */ \
922 { CAIRO_ANTIALIAS_DEFAULT, /* antialias */ \
923 CAIRO_SUBPIXEL_ORDER_DEFAULT, /* subpixel_order */ \
924 + CAIRO_LCD_FILTER_DEFAULT, /* lcd_filter */ \
925 CAIRO_HINT_STYLE_DEFAULT, /* hint_style */ \
926 CAIRO_HINT_METRICS_DEFAULT /* hint_metrics */ \
927 } /* font_options */ \
928 diff -Naur cairo-1.8.6.orig/src/cairo-types-private.h cairo-1.8.6/src/cairo-types-private.h
929 --- cairo-1.8.6.orig/src/cairo-types-private.h Wed Feb 18 15:51:43 2009
930 +++ cairo-1.8.6/src/cairo-types-private.h Wed Feb 18 15:53:59 2009
932 cairo_bool_t is_snapshot;
937 + * cairo_lcd_filter_t:
938 + * @CAIRO_LCD_FILTER_DEFAULT: Use the default LCD filter for
939 + * font backend and target device
940 + * @CAIRO_LCD_FILTER_NONE: Do not perform LCD filtering
941 + * @CAIRO_LCD_FILTER_INTRA_PIXEL: Intra-pixel filter
942 + * @CAIRO_LCD_FILTER_FIR3: FIR filter with a 3x3 kernel
943 + * @CAIRO_LCD_FILTER_FIR5: FIR filter with a 5x5 kernel
945 + * The LCD filter specifies the low-pass filter applied to LCD-optimized
946 + * bitmaps generated with an antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
948 + * Note: This API was temporarily made available in the public
949 + * interface during the 1.7.x development series, but was made private
952 +typedef enum _cairo_lcd_filter {
953 + CAIRO_LCD_FILTER_DEFAULT,
954 + CAIRO_LCD_FILTER_NONE,
955 + CAIRO_LCD_FILTER_INTRA_PIXEL,
956 + CAIRO_LCD_FILTER_FIR3,
957 + CAIRO_LCD_FILTER_FIR5
958 +} cairo_lcd_filter_t;
960 struct _cairo_font_options {
961 cairo_antialias_t antialias;
962 cairo_subpixel_order_t subpixel_order;
963 + cairo_lcd_filter_t lcd_filter;
964 cairo_hint_style_t hint_style;
965 cairo_hint_metrics_t hint_metrics;
967 diff -Naur cairo-1.8.6.orig/src/cairo-xlib-screen.c cairo-1.8.6/src/cairo-xlib-screen.c
968 --- cairo-1.8.6.orig/src/cairo-xlib-screen.c Wed Feb 18 15:51:43 2009
969 +++ cairo-1.8.6/src/cairo-xlib-screen.c Wed Feb 18 15:53:59 2009
970 @@ -150,13 +150,22 @@
971 cairo_bool_t xft_antialias;
975 cairo_antialias_t antialias;
976 cairo_subpixel_order_t subpixel_order;
977 + cairo_lcd_filter_t lcd_filter;
978 cairo_hint_style_t hint_style;
980 if (!get_boolean_default (dpy, "antialias", &xft_antialias))
981 xft_antialias = TRUE;
983 + if (!get_integer_default (dpy, "lcdfilter", &xft_lcdfilter)) {
984 + /* -1 is an non-existant Fontconfig constant used to differentiate
985 + * the case when no lcdfilter property is available.
987 + xft_lcdfilter = -1;
990 if (!get_boolean_default (dpy, "hinting", &xft_hinting))
994 subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
997 + switch (xft_lcdfilter) {
999 + lcd_filter = CAIRO_LCD_FILTER_NONE;
1001 + case FC_LCD_DEFAULT:
1002 + lcd_filter = CAIRO_LCD_FILTER_FIR5;
1004 + case FC_LCD_LIGHT:
1005 + lcd_filter = CAIRO_LCD_FILTER_FIR3;
1007 + case FC_LCD_LEGACY:
1008 + lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
1011 + lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
1015 if (xft_antialias) {
1016 if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT)
1017 antialias = CAIRO_ANTIALIAS_GRAY;
1019 cairo_font_options_set_hint_style (&info->font_options, hint_style);
1020 cairo_font_options_set_antialias (&info->font_options, antialias);
1021 cairo_font_options_set_subpixel_order (&info->font_options, subpixel_order);
1022 + _cairo_font_options_set_lcd_filter (&info->font_options, lcd_filter);
1023 cairo_font_options_set_hint_metrics (&info->font_options, CAIRO_HINT_METRICS_ON);
1026 diff -Naur cairo-1.8.6.orig/src/cairoint.h cairo-1.8.6/src/cairoint.h
1027 --- cairo-1.8.6.orig/src/cairoint.h Wed Feb 18 15:51:43 2009
1028 +++ cairo-1.8.6/src/cairoint.h Wed Feb 18 15:53:59 2009
1029 @@ -1366,6 +1366,13 @@
1030 _cairo_font_options_init_copy (cairo_font_options_t *options,
1031 const cairo_font_options_t *other);
1034 +_cairo_font_options_set_lcd_filter (cairo_font_options_t *options,
1035 + cairo_lcd_filter_t lcd_filter);
1037 +cairo_private cairo_lcd_filter_t
1038 +_cairo_font_options_get_lcd_filter (const cairo_font_options_t *options);
1041 cairo_private cairo_status_t
1042 _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices);