| 1 |
diff -rup libcairo-1.2.4.orig/src/cairo-ft-font.c libcairo-1.2.4/src/cairo-ft-font.c
|
| 2 |
--- libcairo-1.2.4.orig/src/cairo-ft-font.c 2006-08-22 21:40:02.802247352 +0800
|
| 3 |
+++ libcairo-1.2.4/src/cairo-ft-font.c 2006-08-22 21:40:39.443677008 +0800
|
| 4 |
@@ -53,6 +53,8 @@
|
| 5 |
#include FT_SYNTHESIS_H
|
| 6 |
#endif
|
| 7 |
|
| 8 |
+#define FIR_FILTER 1
|
| 9 |
+
|
| 10 |
#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
|
| 11 |
#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
|
| 12 |
#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
|
| 13 |
@@ -492,6 +494,8 @@ _cairo_ft_unscaled_font_destroy (void *a
|
| 14 |
}
|
| 15 |
}
|
| 16 |
|
| 17 |
+static const int fir_filter[5] = { 0x1C, 0x38, 0x55, 0x38, 0x1C };
|
| 18 |
+
|
| 19 |
static cairo_bool_t
|
| 20 |
_has_unlocked_face (void *entry)
|
| 21 |
{
|
| 22 |
@@ -779,7 +783,220 @@ _get_bitmap_surface (FT_Bitmap *bi
|
| 23 |
}
|
| 24 |
format = CAIRO_FORMAT_A8;
|
| 25 |
break;
|
| 26 |
- case CAIRO_ANTIALIAS_SUBPIXEL: {
|
| 27 |
+ case CAIRO_ANTIALIAS_SUBPIXEL:
|
| 28 |
+#ifdef FIR_FILTER
|
| 29 |
+ {
|
| 30 |
+ unsigned char* line;
|
| 31 |
+ unsigned char* bufBitmap;
|
| 32 |
+ int pitch;
|
| 33 |
+ unsigned char *data_rgba;
|
| 34 |
+ unsigned int width_rgba, stride_rgba;
|
| 35 |
+ int vmul = 1;
|
| 36 |
+ int hmul = 1;
|
| 37 |
+
|
| 38 |
+ switch (font_options->subpixel_order) {
|
| 39 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT:
|
| 40 |
+ case CAIRO_SUBPIXEL_ORDER_RGB:
|
| 41 |
+ case CAIRO_SUBPIXEL_ORDER_BGR:
|
| 42 |
+ default:
|
| 43 |
+ width /= 3;
|
| 44 |
+ hmul = 3;
|
| 45 |
+ break;
|
| 46 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB:
|
| 47 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR:
|
| 48 |
+ vmul = 3;
|
| 49 |
+ height /= 3;
|
| 50 |
+ break;
|
| 51 |
+ }
|
| 52 |
+ /*
|
| 53 |
+ * Filter the glyph to soften the color fringes
|
| 54 |
+ */
|
| 55 |
+ width_rgba = width;
|
| 56 |
+ stride = bitmap->pitch;
|
| 57 |
+ stride_rgba = (width_rgba * 4 + 3) & ~3;
|
| 58 |
+ data_rgba = calloc (1, stride_rgba * height);
|
| 59 |
+
|
| 60 |
+ /* perform in-place FIR filtering in either the horizontal or
|
| 61 |
+ * vertical direction. We're going to modify the RGB graymap,
|
| 62 |
+ * but that's ok, because we either own it, or its part of
|
| 63 |
+ * the FreeType glyph slot, which will not be used anymore.
|
| 64 |
+ */
|
| 65 |
+ pitch = bitmap->pitch;
|
| 66 |
+ line = (unsigned char*)bitmap->buffer;
|
| 67 |
+ if ( pitch < 0 )
|
| 68 |
+ line -= pitch*(height-1);
|
| 69 |
+
|
| 70 |
+ bufBitmap = line;
|
| 71 |
+
|
| 72 |
+ switch (font_options->subpixel_order) {
|
| 73 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT:
|
| 74 |
+ case CAIRO_SUBPIXEL_ORDER_RGB:
|
| 75 |
+ case CAIRO_SUBPIXEL_ORDER_BGR:
|
| 76 |
+ {
|
| 77 |
+ int h;
|
| 78 |
+
|
| 79 |
+ for ( h = height; h > 0; h--, line += pitch ) {
|
| 80 |
+ int pix[6] = { 0, 0, 0, 0, 0, 0 };
|
| 81 |
+ unsigned char* p = line;
|
| 82 |
+ unsigned char* limit = line + width*3;
|
| 83 |
+ int nn, val, val2;
|
| 84 |
+
|
| 85 |
+ val = p[0];
|
| 86 |
+ for (nn = 0; nn < 3; nn++)
|
| 87 |
+ pix[2 + nn] += val * fir_filter[nn];
|
| 88 |
+
|
| 89 |
+ val = p[1];
|
| 90 |
+ for (nn = 0; nn < 4; nn++)
|
| 91 |
+ pix[1 + nn] += val * fir_filter[nn];
|
| 92 |
+
|
| 93 |
+ p += 2;
|
| 94 |
+
|
| 95 |
+ for ( ; p < limit; p++ ) {
|
| 96 |
+ val = p[0];
|
| 97 |
+ for (nn = 0; nn < 5; nn++)
|
| 98 |
+ pix[nn] += val * fir_filter[nn];
|
| 99 |
+
|
| 100 |
+ val2 = pix[0] / 256;
|
| 101 |
+ val2 |= -(val2 >> 8);
|
| 102 |
+ p[-2] = (unsigned char)val2;
|
| 103 |
+
|
| 104 |
+ for (nn = 0; nn < 5; nn++)
|
| 105 |
+ pix[nn] = pix[nn + 1];
|
| 106 |
+ }
|
| 107 |
+ for (nn = 0; nn < 2; nn++ ) {
|
| 108 |
+ val2 = pix[nn] / 256;
|
| 109 |
+ val2 |= -(val2 >> 8);
|
| 110 |
+ p[nn - 2] = (unsigned char)val2;
|
| 111 |
+ }
|
| 112 |
+ }
|
| 113 |
+ }
|
| 114 |
+ break;
|
| 115 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB:
|
| 116 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR:
|
| 117 |
+ {
|
| 118 |
+ int w;
|
| 119 |
+
|
| 120 |
+ for (w = 0; w < width; w++ ) {
|
| 121 |
+ int pix[6] = { 0, 0, 0, 0, 0, 0 };
|
| 122 |
+ unsigned char* p = bufBitmap + w;
|
| 123 |
+ unsigned char* limit = bufBitmap + w + height*3*pitch;
|
| 124 |
+ int nn, val, val2;
|
| 125 |
+
|
| 126 |
+ val = p[0];
|
| 127 |
+ for (nn = 0; nn < 3; nn++)
|
| 128 |
+ pix[2 + nn] += val*fir_filter[nn];
|
| 129 |
+
|
| 130 |
+ val = p[pitch];
|
| 131 |
+ for (nn = 0; nn < 4; nn++ )
|
| 132 |
+ pix[1 + nn] += val * fir_filter[nn];
|
| 133 |
+
|
| 134 |
+ p += 2*pitch;
|
| 135 |
+ for ( ; p < limit; p += pitch ) {
|
| 136 |
+ val = p[0];
|
| 137 |
+ for (nn = 0; nn < 5; nn++ )
|
| 138 |
+ pix[nn] += val * fir_filter[nn];
|
| 139 |
+
|
| 140 |
+ val2 = pix[0] / 256;
|
| 141 |
+ val2 |= -(val2 >> 8);
|
| 142 |
+ p[-2 * pitch] = (unsigned char)val2;
|
| 143 |
+
|
| 144 |
+ for (nn = 0; nn < 5; nn++)
|
| 145 |
+ pix[nn] = pix[nn+1];
|
| 146 |
+ }
|
| 147 |
+
|
| 148 |
+ for (nn = 0; nn < 2; nn++) {
|
| 149 |
+ val2 = pix[nn] / 256;
|
| 150 |
+ val2 |= -(val2 >> 8);
|
| 151 |
+ p[(nn - 2) * pitch] = (unsigned char)val2;
|
| 152 |
+ }
|
| 153 |
+ }
|
| 154 |
+ }
|
| 155 |
+ break;
|
| 156 |
+ default: /* shouldn't happen */
|
| 157 |
+ break;
|
| 158 |
+ }
|
| 159 |
+
|
| 160 |
+ /* now copy the resulting graymap into an ARGB32 image */
|
| 161 |
+ {
|
| 162 |
+ unsigned char* in_line = bufBitmap;
|
| 163 |
+ unsigned char* out_line = data_rgba;
|
| 164 |
+ int h = height;
|
| 165 |
+
|
| 166 |
+ switch (font_options->subpixel_order) {
|
| 167 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT:
|
| 168 |
+ case CAIRO_SUBPIXEL_ORDER_RGB:
|
| 169 |
+ for ( ; h > 0; h--, in_line += pitch, out_line += stride_rgba) {
|
| 170 |
+ unsigned char* in = in_line;
|
| 171 |
+ int* out = (int*)out_line;
|
| 172 |
+ int w;
|
| 173 |
+
|
| 174 |
+ for (w = width; w > 0; w--, in += 3, out += 1) {
|
| 175 |
+ int r = in[0];
|
| 176 |
+ int g = in[1];
|
| 177 |
+ int b = in[2];
|
| 178 |
+
|
| 179 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b;
|
| 180 |
+ }
|
| 181 |
+ }
|
| 182 |
+ break;
|
| 183 |
+ case CAIRO_SUBPIXEL_ORDER_BGR:
|
| 184 |
+ for ( ; h > 0; h--, in_line += pitch, out_line += stride_rgba) {
|
| 185 |
+ unsigned char* in = in_line;
|
| 186 |
+ int* out = (int*)out_line;
|
| 187 |
+ int w;
|
| 188 |
+
|
| 189 |
+ for (w = width; w > 0; w--, in += 3, out += 1) {
|
| 190 |
+ int r = in[2];
|
| 191 |
+ int g = in[1];
|
| 192 |
+ int b = in[0];
|
| 193 |
+
|
| 194 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b;
|
| 195 |
+ }
|
| 196 |
+ }
|
| 197 |
+ break;
|
| 198 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB:
|
| 199 |
+ for ( ; h > 0; h--, in_line += pitch*3, out_line += stride_rgba) {
|
| 200 |
+ unsigned char* in = in_line;
|
| 201 |
+ int* out = (int*)out_line;
|
| 202 |
+ int w;
|
| 203 |
+
|
| 204 |
+ for (w = width; w > 0; w--, in += 1, out += 1) {
|
| 205 |
+ int r = in[0];
|
| 206 |
+ int g = in[pitch];
|
| 207 |
+ int b = in[pitch*2];
|
| 208 |
+
|
| 209 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b;
|
| 210 |
+ }
|
| 211 |
+ }
|
| 212 |
+ break;
|
| 213 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR:
|
| 214 |
+ for ( ; h > 0; h--, in_line += pitch*3, out_line += stride_rgba) {
|
| 215 |
+ unsigned char* in = in_line;
|
| 216 |
+ int* out = (int*)out_line;
|
| 217 |
+ int w;
|
| 218 |
+
|
| 219 |
+ for (w = width; w > 0; w--, in += 1, out += 1) {
|
| 220 |
+ int r = in[2*pitch];
|
| 221 |
+ int g = in[pitch];
|
| 222 |
+ int b = in[0];
|
| 223 |
+
|
| 224 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b;
|
| 225 |
+ }
|
| 226 |
+ }
|
| 227 |
+ break;
|
| 228 |
+ }
|
| 229 |
+ }
|
| 230 |
+
|
| 231 |
+ if (own_buffer)
|
| 232 |
+ free (bitmap->buffer);
|
| 233 |
+ data = data_rgba;
|
| 234 |
+ stride = stride_rgba;
|
| 235 |
+ format = CAIRO_FORMAT_ARGB32;
|
| 236 |
+ subpixel = TRUE;
|
| 237 |
+ break;
|
| 238 |
+ }
|
| 239 |
+#else /* !FIR_FILTER */
|
| 240 |
+ {
|
| 241 |
int x, y;
|
| 242 |
unsigned char *in_line, *out_line, *in;
|
| 243 |
unsigned int *out;
|
| 244 |
@@ -871,6 +1088,7 @@ _get_bitmap_surface (FT_Bitmap *bi
|
| 245 |
subpixel = TRUE;
|
| 246 |
break;
|
| 247 |
}
|
| 248 |
+#endif /* !FIR_FILTER */
|
| 249 |
}
|
| 250 |
break;
|
| 251 |
case FT_PIXEL_MODE_GRAY2:
|
| 252 |
@@ -986,12 +1204,22 @@ _render_glyph_outline (FT_Face
|
| 253 |
matrix.xx *= 3;
|
| 254 |
hmul = 3;
|
| 255 |
subpixel = TRUE;
|
| 256 |
+#ifdef FIR_FILTER
|
| 257 |
+ cbox.xMin -= 64;
|
| 258 |
+ cbox.xMax += 64;
|
| 259 |
+ width += 2;
|
| 260 |
+#endif
|
| 261 |
break;
|
| 262 |
case CAIRO_SUBPIXEL_ORDER_VRGB:
|
| 263 |
case CAIRO_SUBPIXEL_ORDER_VBGR:
|
| 264 |
matrix.yy *= 3;
|
| 265 |
vmul = 3;
|
| 266 |
subpixel = TRUE;
|
| 267 |
+#ifdef FIR_FILTER
|
| 268 |
+ cbox.yMin -= 64;
|
| 269 |
+ cbox.yMax += 64;
|
| 270 |
+ height += 2;
|
| 271 |
+#endif
|
| 272 |
break;
|
| 273 |
}
|
| 274 |
FT_Outline_Transform (outline, &matrix);
|
| 275 |
Only in libcairo-1.2.4/src: cairo-ft-font.c.orig
|