干掉 app-dicts
[gentoo-china-overlay.git] / x11-libs / cairo / files / cairo-ubuntu-04_lcd_filter.patch
blob2b9ef05800051e214a086613059b37799226c004
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
4 @@ -39,6 +39,7 @@
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
12 @@ -54,6 +55,7 @@
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;
20 @@ -64,6 +66,7 @@
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;
28 @@ -189,6 +192,8 @@
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)
37 @@ -221,6 +226,7 @@
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);
45 @@ -246,7 +252,8 @@
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);
55 @@ -325,6 +332,48 @@
56 return CAIRO_SUBPIXEL_ORDER_DEFAULT;
58 return options->subpixel_order;
61 +/**
62 + * _cairo_font_options_set_lcd_filter:
63 + * @options: a #cairo_font_options_t
64 + * @lcd_filter: the new LCD filter
65 + *
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.
70 + *
71 + * Since: 1.8
72 + **/
73 +void
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))
78 + return;
80 + options->lcd_filter = lcd_filter;
83 +/**
84 + * _cairo_font_options_get_lcd_filter:
85 + * @options: a #cairo_font_options_t
86 + *
87 + * Gets the LCD filter for the font options object.
88 + * See the documentation for #cairo_lcd_filter_t for full details.
89 + *
90 + * Return value: the LCD filter for the font options object
91 + *
92 + * Since: 1.8
93 + **/
94 +cairo_lcd_filter_t
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
107 @@ -57,6 +57,30 @@
108 #include FT_SYNTHESIS_H
109 #endif
111 +#if HAVE_FT_LIBRARY_SETLCDFILTER
112 +#include FT_LCD_FILTER_H
113 +#endif
115 +/* Fontconfig version older than 2.6 didn't have these options */
116 +#ifndef FC_LCD_FILTER
117 +#define FC_LCD_FILTER "lcdfilter"
118 +#endif
119 +/* Some Ubuntu versions defined FC_LCD_FILTER without defining the following */
120 +#ifndef FC_LCD_NONE
121 +#define FC_LCD_NONE 0
122 +#define FC_LCD_DEFAULT 1
123 +#define FC_LCD_LIGHT 2
124 +#define FC_LCD_LEGACY 3
125 +#endif
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
133 +#endif
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] = {
145 - /* red */
146 -#if 0
147 - { 65538*4/7,65538*2/7,65538*1/7 },
148 - /* green */
149 - { 65536*1/4, 65536*2/4, 65537*1/4 },
150 - /* blue */
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)
174 + */
175 +static int
176 +_compute_xrender_bitmap_size(FT_Bitmap *target,
177 + FT_GlyphSlot slot,
178 + FT_Render_Mode mode)
180 + FT_Bitmap *ftbit;
181 + int width, height, pitch;
183 + if (slot->format != FT_GLYPH_FORMAT_BITMAP)
184 + return -1;
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);
197 + break;
199 + /* fall-through */
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 */
206 + pitch = width * 4;
208 + break;
210 + case FT_PIXEL_MODE_LCD:
211 + if (mode != FT_RENDER_MODE_LCD)
212 + return -1;
214 + /* horz pixel triplets are packed into 32-bit ARGB values */
215 + width /= 3;
216 + pitch = width * 4;
217 + break;
219 + case FT_PIXEL_MODE_LCD_V:
220 + if (mode != FT_RENDER_MODE_LCD_V)
221 + return -1;
223 + /* vert pixel triplets are packed into 32-bit ARGB values */
224 + height /= 3;
225 + pitch = width * 4;
226 + break;
228 + default: /* unsupported source format */
229 + return -1;
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
253 + */
254 +static void
255 +_fill_xrender_bitmap(FT_Bitmap *target,
256 + FT_GlyphSlot slot,
257 + FT_Render_Mode mode,
258 + int bgr)
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;
267 + int subpixel;
268 + int h;
270 + subpixel = (mode == FT_RENDER_MODE_LCD ||
271 + mode == FT_RENDER_MODE_LCD_V);
273 + if (src_pitch < 0)
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:
280 + if (subpixel) {
281 + /* convert mono to ARGB32 values */
283 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
284 + int x;
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) {
297 + int x;
299 + for (x = 0; x < width; x++) {
300 + if (srcLine[(x >> 3)] & (0x80 >> (x & 7)))
301 + dstLine[x] = 0xff;
304 + target->pixel_mode = FT_PIXEL_MODE_GRAY;
306 + } else {
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);
314 + break;
316 + case FT_PIXEL_MODE_GRAY:
317 + if (subpixel) {
318 + /* convert gray to ARGB32 values */
320 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
321 + int x;
322 + unsigned int *dst = (unsigned int *) dstLine;
324 + for (x = 0; x < width; x++) {
325 + unsigned int pix = srcLine[x];
327 + pix |= (pix << 8);
328 + pix |= (pix << 16);
330 + dst[x] = pix;
333 + target->pixel_mode = FT_PIXEL_MODE_LCD;
334 + } else {
335 + /* copy gray into gray */
337 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch)
338 + memcpy (dstLine, srcLine, width);
340 + break;
342 + case FT_PIXEL_MODE_LCD:
343 + if (!bgr) {
344 + /* convert horizontal RGB into ARGB32 */
346 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
347 + int x;
348 + unsigned char *src = srcLine;
349 + unsigned int *dst = (unsigned int *) dstLine;
351 + for (x = 0; x < width; x++, src += 3) {
352 + unsigned int pix;
354 + pix = ((unsigned int)src[0] << 16) |
355 + ((unsigned int)src[1] << 8) |
356 + ((unsigned int)src[2] ) |
357 + ((unsigned int)src[1] << 24) ;
359 + dst[x] = pix;
362 + } else {
363 + /* convert horizontal BGR into ARGB32 */
365 + for (h = height; h > 0; h--, srcLine += src_pitch, dstLine += pitch) {
367 + int x;
368 + unsigned char *src = srcLine;
369 + unsigned int *dst = (unsigned int *) dstLine;
371 + for (x = 0; x < width; x++, src += 3) {
372 + unsigned int pix;
374 + pix = ((unsigned int)src[2] << 16) |
375 + ((unsigned int)src[1] << 8) |
376 + ((unsigned int)src[0] ) |
377 + ((unsigned int)src[1] << 24) ;
379 + dst[x] = pix;
383 + break;
385 + default: /* FT_PIXEL_MODE_LCD_V */
386 + /* convert vertical RGB into ARGB32 */
387 + if (!bgr) {
389 + for (h = height; h > 0; h--, srcLine += 3 * src_pitch, dstLine += pitch) {
390 + int x;
391 + unsigned char* src = srcLine;
392 + unsigned int* dst = (unsigned int *) dstLine;
394 + for (x = 0; x < width; x++, src += 1) {
395 + unsigned int pix;
396 +#if 1
397 + pix = ((unsigned int)src[0] << 16) |
398 + ((unsigned int)src[src_pitch] << 8) |
399 + ((unsigned int)src[src_pitch*2] ) |
400 + 0xFF000000 ;
401 +#else
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) ;
406 #endif
407 - { 65538*9/13,65538*3/13,65538*1/13 },
408 - /* green */
409 - { 65538*1/6, 65538*4/6, 65538*1/6 },
410 - /* blue */
411 - { 65538*1/13,65538*3/13,65538*9/13 },
413 + dst[x] = pix;
416 + } else {
418 + for (h = height; h > 0; h--, srcLine += 3*src_pitch, dstLine += pitch) {
419 + int x;
420 + unsigned char *src = srcLine;
421 + unsigned int *dst = (unsigned int *) dstLine;
423 + for (x = 0; x < width; x++, src += 1) {
424 + unsigned int pix;
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) ;
431 + dst[x] = pix;
439 /* Fills in val->image with an image surface created from @bitmap
441 @@ -767,7 +1054,7 @@
442 int width, height, stride;
443 unsigned char *data;
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:
458 - default:
459 + if (font_options->antialias != CAIRO_ANTIALIAS_SUBPIXEL) {
460 stride = bitmap->pitch;
461 if (own_buffer) {
462 data = bitmap->buffer;
463 @@ -840,104 +1123,16 @@
464 memcpy (data, bitmap->buffer, stride * height);
466 format = CAIRO_FORMAT_A8;
467 - break;
468 - case CAIRO_ANTIALIAS_SUBPIXEL: {
469 - int x, y;
470 - unsigned char *in_line, *out_line, *in;
471 - unsigned int *out;
472 - unsigned int red, green, blue;
473 - int rf, gf, bf;
474 - int s;
475 - int o, os;
476 - unsigned char *data_rgba;
477 - unsigned int width_rgba, stride_rgba;
478 - int vmul = 1;
479 - int hmul = 1;
480 + } else {
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:
491 - default:
492 - width /= 3;
493 - hmul = 3;
494 - break;
495 - case CAIRO_SUBPIXEL_ORDER_VRGB:
496 - case CAIRO_SUBPIXEL_ORDER_VBGR:
497 - vmul = 3;
498 - height /= 3;
499 - break;
501 - /*
502 - * Filter the glyph to soften the color fringes
503 - */
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) {
510 - if (own_buffer)
511 - free (bitmap->buffer);
512 - return _cairo_error (CAIRO_STATUS_NO_MEMORY);
515 - os = 1;
516 - switch (font_options->subpixel_order) {
517 - case CAIRO_SUBPIXEL_ORDER_VRGB:
518 - os = stride;
519 - case CAIRO_SUBPIXEL_ORDER_DEFAULT:
520 - case CAIRO_SUBPIXEL_ORDER_RGB:
521 - default:
522 - rf = 0;
523 - gf = 1;
524 - bf = 2;
525 - break;
526 - case CAIRO_SUBPIXEL_ORDER_VBGR:
527 - os = stride;
528 - case CAIRO_SUBPIXEL_ORDER_BGR:
529 - bf = 0;
530 - gf = 1;
531 - rf = 2;
532 - break;
534 - in_line = bitmap->buffer;
535 - out_line = data_rgba;
536 - for (y = 0; y < height; y++)
538 - in = in_line;
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;
545 - o = 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];
551 - o += os;
553 - red = red / 65536;
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
562 - */
564 - if (own_buffer)
565 - free (bitmap->buffer);
566 - data = data_rgba;
567 - stride = stride_rgba;
568 format = CAIRO_FORMAT_ARGB32;
569 - subpixel = TRUE;
570 - break;
573 break;
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 *)
580 + /* XXX */
581 + *surface = image = (cairo_image_surface_t *)
582 cairo_image_surface_create_for_data (data,
583 format,
584 width, height, stride);
585 - if ((*surface)->base.status) {
586 + if (image->base.status) {
587 free (data);
588 return (*surface)->base.status;
591 - if (subpixel)
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;
609 FT_Bitmap bitmap;
610 FT_BBox cbox;
611 - FT_Matrix matrix;
612 - int hmul = 1;
613 - int vmul = 1;
614 - unsigned int width, height, stride;
615 - cairo_bool_t subpixel = FALSE;
616 + unsigned int width, height;
617 cairo_status_t status;
618 + FT_Error fterror;
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;
625 + break;
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;
633 + break;
635 + case CAIRO_SUBPIXEL_ORDER_VRGB:
636 + case CAIRO_SUBPIXEL_ORDER_VBGR:
637 + render_mode = FT_RENDER_MODE_LCD_V;
638 + break;
641 + switch (font_options->lcd_filter) {
642 + case CAIRO_LCD_FILTER_NONE:
643 + lcd_filter = FT_LCD_FILTER_NONE;
644 + break;
645 + case CAIRO_LCD_FILTER_DEFAULT:
646 + case CAIRO_LCD_FILTER_INTRA_PIXEL:
647 + lcd_filter = FT_LCD_FILTER_LEGACY;
648 + break;
649 + case CAIRO_LCD_FILTER_FIR3:
650 + lcd_filter = FT_LCD_FILTER_LIGHT;
651 + break;
652 + case CAIRO_LCD_FILTER_FIR5:
653 + lcd_filter = FT_LCD_FILTER_DEFAULT;
654 + break;
657 + break;
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;
680 break;
681 - case CAIRO_ANTIALIAS_SUBPIXEL:
682 + case FT_RENDER_MODE_LCD:
683 + case FT_RENDER_MODE_LCD_V:
684 format= CAIRO_FORMAT_ARGB32;
685 break;
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:
691 default:
692 format = CAIRO_FORMAT_A8;
693 break;
694 @@ -1031,73 +1271,73 @@
695 return (*surface)->base.status;
696 } else {
698 - matrix.xx = matrix.yy = 0x10000L;
699 - matrix.xy = matrix.yx = 0;
700 + int bitmap_size;
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;
707 - break;
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;
717 + } else {
718 + rgba = FC_RGBA_RGB;
720 break;
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:
726 - default:
727 - matrix.xx *= 3;
728 - hmul = 3;
729 - subpixel = TRUE;
730 - break;
731 - case CAIRO_SUBPIXEL_ORDER_VRGB:
732 - case CAIRO_SUBPIXEL_ORDER_VBGR:
733 - matrix.yy *= 3;
734 - vmul = 3;
735 - subpixel = TRUE;
736 - break;
737 + case FT_RENDER_MODE_LCD_V:
738 + if (font_options->subpixel_order == CAIRO_SUBPIXEL_ORDER_VBGR) {
739 + rgba = FC_RGBA_VBGR;
740 + } else {
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;
748 + break;
749 + case FT_RENDER_MODE_MONO:
750 + case FT_RENDER_MODE_LIGHT:
751 + case FT_RENDER_MODE_NORMAL:
752 + case FT_RENDER_MODE_MAX:
753 + default:
754 + break;
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);
764 +#endif
766 + fterror = FT_Render_Glyph (face->glyph, render_mode);
768 +#if HAVE_FT_LIBRARY_SETLCDFILTER
769 + FT_Library_SetLcdFilter (library, FT_LCD_FILTER_NONE);
770 +#endif
772 + if (fterror != 0)
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,
777 + face->glyph,
778 + render_mode);
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));
792 + /* Note:
793 + * _get_bitmap_surface will free bitmap.buffer if there is an error
794 + */
795 status = _get_bitmap_surface (&bitmap, TRUE, font_options, surface);
796 if (status)
797 return status;
800 - /*
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.
805 - */
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.
813 + */
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 @@
823 if (antialias) {
824 cairo_subpixel_order_t subpixel_order;
825 + int lcd_filter;
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) {
837 + case FC_LCD_NONE:
838 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_NONE;
839 + break;
840 + case FC_LCD_DEFAULT:
841 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR5;
842 + break;
843 + case FC_LCD_LIGHT:
844 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_FIR3;
845 + break;
846 + case FC_LCD_LEGACY:
847 + ft_options.base.lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
848 + break;
852 #ifdef FC_HINT_STYLE
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;
874 break;
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;
879 break;
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)
894 + int lcd_filter;
896 + switch (options->lcd_filter) {
897 + case CAIRO_LCD_FILTER_NONE:
898 + lcd_filter = FT_LCD_FILTER_NONE;
899 + break;
900 + case CAIRO_LCD_FILTER_DEFAULT:
901 + case CAIRO_LCD_FILTER_INTRA_PIXEL:
902 + lcd_filter = FT_LCD_FILTER_LEGACY;
903 + break;
904 + case CAIRO_LCD_FILTER_FIR3:
905 + lcd_filter = FT_LCD_FILTER_LIGHT;
906 + break;
907 + default:
908 + case CAIRO_LCD_FILTER_FIR5:
909 + lcd_filter = FT_LCD_FILTER_DEFAULT;
910 + break;
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
920 @@ -73,6 +73,7 @@
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
931 @@ -113,9 +113,35 @@
932 cairo_bool_t is_snapshot;
936 +/**
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
950 + * before 1.8.
951 + **/
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;
972 int xft_hintstyle;
973 int xft_rgba;
974 + int xft_lcdfilter;
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.
986 + */
987 + xft_lcdfilter = -1;
990 if (!get_boolean_default (dpy, "hinting", &xft_hinting))
991 xft_hinting = TRUE;
993 @@ -239,6 +248,24 @@
994 subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
997 + switch (xft_lcdfilter) {
998 + case FC_LCD_NONE:
999 + lcd_filter = CAIRO_LCD_FILTER_NONE;
1000 + break;
1001 + case FC_LCD_DEFAULT:
1002 + lcd_filter = CAIRO_LCD_FILTER_FIR5;
1003 + break;
1004 + case FC_LCD_LIGHT:
1005 + lcd_filter = CAIRO_LCD_FILTER_FIR3;
1006 + break;
1007 + case FC_LCD_LEGACY:
1008 + lcd_filter = CAIRO_LCD_FILTER_INTRA_PIXEL;
1009 + break;
1010 + default:
1011 + lcd_filter = CAIRO_LCD_FILTER_DEFAULT;
1012 + break;
1015 if (xft_antialias) {
1016 if (subpixel_order == CAIRO_SUBPIXEL_ORDER_DEFAULT)
1017 antialias = CAIRO_ANTIALIAS_GRAY;
1018 @@ -251,6 +278,7 @@
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);
1033 +cairo_private void
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);
1040 /* cairo-hull.c */
1041 cairo_private cairo_status_t
1042 _cairo_hull_compute (cairo_pen_vertex_t *vertices, int *num_vertices);