summaryrefslogtreecommitdiffstats
path: root/testing/freetype-infinality/02-ftsmooth-2.5.5.patch
blob: 10ec0c036a1f7c7c7510267af43ec3c9c76668d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
Temporarily reverting upstream commits (Infinality patch `08` needs a bit of tweaking):

1. From 465ab99585cb748f9de0087d369677cc9e196785 Mon Sep 17 00:00:00 2001
   From: Alexei Podtelezhnikov <apodtele@gmail.com>
   Date: Wed, 29 Oct 2014 23:45:23 -0400
   Subject: [PATCH] [smooth] Improve code readability.

2. From e1efe0a2fc877c198d72cb0c877db3a17e956f63 Mon Sep 17 00:00:00 2001
   From: Alexei Podtelezhnikov <apodtele@gmail.com>
   Date: Fri, 31 Oct 2014 00:07:14 -0400
   Subject: [PATCH] [smooth] Reduce outline translations during rendering.

3. From 525d4876bea4a56adc0b3c9aab2082f84f050e32 Mon Sep 17 00:00:00 2001
   From: Alexei Podtelezhnikov <apodtele@gmail.com>
   Date: Fri, 31 Oct 2014 22:12:37 -0400
   Subject: [PATCH] [smooth] Improve code readability.

4. From 2676e07aa45761d00ff0cb0101bf0aeb0d95ad05 Mon Sep 17 00:00:00 2001
   From: suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
   Date: Fri, 28 Nov 2014 00:58:25 +0900
   Subject: [PATCH] * src/smooth/ftsmooth.c (ft_smooth_render_generic): Remove
   unrequired negative value check for `width' and `height'.

Applying a bug fix:

From c7fd93565c2f9f967aa24fe8dee028c2600c459d Mon Sep 17 00:00:00 2001
From: Alexei Podtelezhnikov <apodtele@gmail.com>
Date: Thu, 30 Oct 2014 22:43:01 -0400
Subject: [PATCH] [smooth] Fix Savannah bug #35604 (cont'd).

---

--- a/src/smooth/ftsmooth.c	2014-11-27 19:17:01.009987078 +0100
+++ b/src/smooth/ftsmooth.c	2013-06-05 12:12:47.000000000 +0200
@@ -103,24 +103,25 @@
                             FT_Render_Mode    required_mode )
   {
     FT_Error     error;
-    FT_Outline*  outline = &slot->outline;
-    FT_Bitmap*   bitmap  = &slot->bitmap;
-    FT_Memory    memory  = render->root.memory;
+    FT_Outline*  outline = NULL;
     FT_BBox      cbox;
-    FT_Pos       x_shift = 0;
-    FT_Pos       y_shift = 0;
-    FT_Pos       x_left, y_top;
     FT_Pos       width, height, pitch;
 #ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
     FT_Pos       height_org, width_org;
 #endif
+    FT_Bitmap*   bitmap  = &slot->bitmap;
+    FT_Memory    memory  = render->root.memory;
     FT_Int       hmul    = mode == FT_RENDER_MODE_LCD;
     FT_Int       vmul    = mode == FT_RENDER_MODE_LCD_V;
+    FT_Pos       x_shift = 0;
+    FT_Pos       y_shift = 0;
+    FT_Pos       x_left, y_top;
 
     FT_Raster_Params  params;
 
-    FT_Bool  have_outline_shifted = FALSE;
-    FT_Bool  have_buffer          = FALSE;
+    FT_Bool  have_translated_origin = FALSE;
+    FT_Bool  have_outline_shifted   = FALSE;
+    FT_Bool  have_buffer            = FALSE;
 
 
     /* check glyph image format */
@@ -137,45 +138,73 @@
       goto Exit;
     }
 
+    outline = &slot->outline;
+
+    /* translate the outline to the new origin if needed */
     if ( origin )
     {
-      x_shift = origin->x;
-      y_shift = origin->y;
+      FT_Outline_Translate( outline, origin->x, origin->y );
+      have_translated_origin = TRUE;
     }
 
     /* compute the control box, and grid fit it */
-    /* taking into account the origin shift     */
     FT_Outline_Get_CBox( outline, &cbox );
 
-    cbox.xMin = FT_PIX_FLOOR( cbox.xMin + x_shift );
-    cbox.yMin = FT_PIX_FLOOR( cbox.yMin + y_shift );
-    cbox.xMax = FT_PIX_CEIL( cbox.xMax + x_shift );
-    cbox.yMax = FT_PIX_CEIL( cbox.yMax + y_shift );
-
-    x_shift -= cbox.xMin;
-    y_shift -= cbox.yMin;
-
-    x_left  = cbox.xMin >> 6;
-    y_top   = cbox.yMax >> 6;
+    cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
+    cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
+    cbox.xMax = FT_PIX_CEIL( cbox.xMax );
+    cbox.yMax = FT_PIX_CEIL( cbox.yMax );
+
+    if ( cbox.xMin < 0 && cbox.xMax > FT_INT_MAX + cbox.xMin )
+    {
+      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
+                 " xMin = %d, xMax = %d\n",
+                 cbox.xMin >> 6, cbox.xMax >> 6 ));
+      error = FT_THROW( Raster_Overflow );
+      goto Exit;
+    }
+    else
+      width = ( cbox.xMax - cbox.xMin ) >> 6;
 
-    width  = (FT_ULong)( cbox.xMax - cbox.xMin ) >> 6;
-    height = (FT_ULong)( cbox.yMax - cbox.yMin ) >> 6;
+    if ( cbox.yMin < 0 && cbox.yMax > FT_INT_MAX + cbox.yMin )
+    {
+      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
+                 " yMin = %d, yMax = %d\n",
+                 cbox.yMin >> 6, cbox.yMax >> 6 ));
+      error = FT_THROW( Raster_Overflow );
+      goto Exit;
+    }
+    else
+      height = ( cbox.yMax - cbox.yMin ) >> 6;
 
 #ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
     width_org  = width;
     height_org = height;
 #endif
 
+    /* release old bitmap buffer */
+    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+    {
+      FT_FREE( bitmap->buffer );
+      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+    }
+
+    /* allocate new one */
     pitch = width;
     if ( hmul )
     {
-      width *= 3;
-      pitch  = FT_PAD_CEIL( width, 4 );
+      width = width * 3;
+      pitch = FT_PAD_CEIL( width, 4 );
     }
 
     if ( vmul )
       height *= 3;
 
+    x_shift = (FT_Int) cbox.xMin;
+    y_shift = (FT_Int) cbox.yMin;
+    x_left  = (FT_Int)( cbox.xMin >> 6 );
+    y_top   = (FT_Int)( cbox.yMax >> 6 );
+
 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
 
     if ( slot->library->lcd_filter_func )
@@ -185,32 +214,23 @@
 
       if ( hmul )
       {
-        x_shift += 64 * ( extra >> 1 );
-        x_left  -= extra >> 1;
+        x_shift -= 64 * ( extra >> 1 );
         width   += 3 * extra;
         pitch    = FT_PAD_CEIL( width, 4 );
+        x_left  -= extra >> 1;
       }
 
       if ( vmul )
       {
-        y_shift += 64 * ( extra >> 1 );
-        y_top   += extra >> 1;
+        y_shift -= 64 * ( extra >> 1 );
         height  += 3 * extra;
+        y_top   += extra >> 1;
       }
     }
 
 #endif
 
-    /*
-     * XXX: on 16bit system, we return an error for huge bitmap
-     * to prevent an overflow.
-     */
-    if ( x_left > FT_INT_MAX || y_top > FT_INT_MAX ||
-         x_left < FT_INT_MIN || y_top < FT_INT_MIN )
-    {
-      error = FT_THROW( Invalid_Pixel_Size );
-      goto Exit;
-    }
+#if FT_UINT_MAX > 0xFFFFU
 
     /* Required check is (pitch * height < FT_ULONG_MAX),        */
     /* but we care realistic cases only.  Always pitch <= width. */
@@ -222,24 +242,7 @@
       goto Exit;
     }
 
-    /* release old bitmap buffer */
-    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
-    {
-      FT_FREE( bitmap->buffer );
-      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
-    }
-
-    /* allocate new one */
-    if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
-      goto Exit;
-    else
-      have_buffer = TRUE;
-
-    slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
-
-    slot->format      = FT_GLYPH_FORMAT_BITMAP;
-    slot->bitmap_left = (FT_Int)x_left;
-    slot->bitmap_top  = (FT_Int)y_top;
+#endif
 
     bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
     bitmap->num_grays  = 256;
@@ -248,11 +251,15 @@
     bitmap->pitch      = pitch;
 
     /* translate outline to render it into the bitmap */
-    if ( x_shift || y_shift )
-    {
-      FT_Outline_Translate( outline, x_shift, y_shift );
-      have_outline_shifted = TRUE;
-    }
+    FT_Outline_Translate( outline, -x_shift, -y_shift );
+    have_outline_shifted = TRUE;
+
+    if ( FT_ALLOC( bitmap->buffer, (FT_ULong)pitch * height ) )
+      goto Exit;
+    else
+      have_buffer = TRUE;
+
+    slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
 
     /* set up parameters */
     params.target = bitmap;
@@ -359,6 +366,20 @@
 
 #endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
 
+    /*
+     * XXX: on 16bit system, we return an error for huge bitmap
+     * to prevent an overflow.
+     */
+    if ( x_left > FT_INT_MAX || y_top > FT_INT_MAX )
+    {
+      error = FT_THROW( Invalid_Pixel_Size );
+      goto Exit;
+    }
+
+    slot->format      = FT_GLYPH_FORMAT_BITMAP;
+    slot->bitmap_left = (FT_Int)x_left;
+    slot->bitmap_top  = (FT_Int)y_top;
+
     /* everything is fine; don't deallocate buffer */
     have_buffer = FALSE;
 
@@ -366,7 +387,9 @@
 
   Exit:
     if ( have_outline_shifted )
-      FT_Outline_Translate( outline, -x_shift, -y_shift );
+      FT_Outline_Translate( outline, x_shift, y_shift );
+    if ( have_translated_origin )
+      FT_Outline_Translate( outline, -origin->x, -origin->y );
     if ( have_buffer )
     {
       FT_FREE( bitmap->buffer );
--- a/src/smooth/ftsmooth.c	2013-06-05 12:12:47.000000000 +0200
+++ b/src/smooth/ftsmooth.c	2014-12-04 23:05:42.723095358 +0100
@@ -155,27 +155,8 @@
     cbox.xMax = FT_PIX_CEIL( cbox.xMax );
     cbox.yMax = FT_PIX_CEIL( cbox.yMax );
 
-    if ( cbox.xMin < 0 && cbox.xMax > FT_INT_MAX + cbox.xMin )
-    {
-      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
-                 " xMin = %d, xMax = %d\n",
-                 cbox.xMin >> 6, cbox.xMax >> 6 ));
-      error = FT_THROW( Raster_Overflow );
-      goto Exit;
-    }
-    else
-      width = ( cbox.xMax - cbox.xMin ) >> 6;
-
-    if ( cbox.yMin < 0 && cbox.yMax > FT_INT_MAX + cbox.yMin )
-    {
-      FT_ERROR(( "ft_smooth_render_generic: glyph too large:"
-                 " yMin = %d, yMax = %d\n",
-                 cbox.yMin >> 6, cbox.yMax >> 6 ));
-      error = FT_THROW( Raster_Overflow );
-      goto Exit;
-    }
-    else
-      height = ( cbox.yMax - cbox.yMin ) >> 6;
+    width  = (FT_ULong)( cbox.xMax - cbox.xMin ) >> 6;
+    height = (FT_ULong)( cbox.yMax - cbox.yMin ) >> 6;
 
 #ifndef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
     width_org  = width;
@@ -200,10 +181,10 @@
     if ( vmul )
       height *= 3;
 
-    x_shift = (FT_Int) cbox.xMin;
-    y_shift = (FT_Int) cbox.yMin;
-    x_left  = (FT_Int)( cbox.xMin >> 6 );
-    y_top   = (FT_Int)( cbox.yMax >> 6 );
+    x_shift = cbox.xMin;
+    y_shift = cbox.yMin;
+    x_left  = cbox.xMin >> 6;
+    y_top   = cbox.yMax >> 6;
 
 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
 
@@ -230,8 +211,6 @@
 
 #endif
 
-#if FT_UINT_MAX > 0xFFFFU
-
     /* Required check is (pitch * height < FT_ULONG_MAX),        */
     /* but we care realistic cases only.  Always pitch <= width. */
     if ( width > 0x7FFF || height > 0x7FFF )
@@ -242,8 +221,6 @@
       goto Exit;
     }
 
-#endif
-
     bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
     bitmap->num_grays  = 256;
     bitmap->width      = width;