... |
... |
@@ -1137,9 +1137,10 @@ |
1137
|
1137
|
FT_Int max_splits,
|
1138
|
1138
|
SDF_Edge** out )
|
1139
|
1139
|
{
|
1140
|
|
- FT_Error error = FT_Err_Ok;
|
1141
|
|
- FT_26D6_Vec cpos[7];
|
1142
|
|
- SDF_Edge* left,* right;
|
|
1140
|
+ FT_Error error = FT_Err_Ok;
|
|
1141
|
+ FT_26D6_Vec cpos[7];
|
|
1142
|
+ SDF_Edge* left,* right;
|
|
1143
|
+ const FT_26D6 threshold = ONE_PIXEL / 4;
|
1143
|
1144
|
|
1144
|
1145
|
|
1145
|
1146
|
if ( !memory || !out )
|
... |
... |
@@ -1148,12 +1149,25 @@ |
1148
|
1149
|
goto Exit;
|
1149
|
1150
|
}
|
1150
|
1151
|
|
1151
|
|
- /* split the conic */
|
|
1152
|
+ /* split the cubic */
|
1152
|
1153
|
cpos[0] = control_points[0];
|
1153
|
1154
|
cpos[1] = control_points[1];
|
1154
|
1155
|
cpos[2] = control_points[2];
|
1155
|
1156
|
cpos[3] = control_points[3];
|
1156
|
1157
|
|
|
1158
|
+ /* If the segment is flat enough, we won't get any benifit by */
|
|
1159
|
+ /* splitting it further, so we can just stop splitting. Here, */
|
|
1160
|
+ /* we check the deviation of the bezier and stop if it is */
|
|
1161
|
+ /* lower than a pre-defined `threhold` value. */
|
|
1162
|
+ if ( FT_ABS( 2 * cpos[0].x - 3 * cpos[1].x + cpos[3].x ) < threshold &&
|
|
1163
|
+ FT_ABS( 2 * cpos[0].y - 3 * cpos[1].y + cpos[3].y ) < threshold &&
|
|
1164
|
+ FT_ABS( cpos[0].x - 3 * cpos[2].x + 2 * cpos[3].x ) < threshold &&
|
|
1165
|
+ FT_ABS( cpos[0].y - 3 * cpos[2].y + 2 * cpos[3].y ) < threshold )
|
|
1166
|
+ {
|
|
1167
|
+ split_cubic( cpos );
|
|
1168
|
+ goto Append;
|
|
1169
|
+ }
|
|
1170
|
+
|
1157
|
1171
|
split_cubic( cpos );
|
1158
|
1172
|
|
1159
|
1173
|
/* If max number of splits is done */
|
... |
... |
@@ -1250,13 +1264,31 @@ |
1250
|
1264
|
/* Subdivide the curve and add it to the list. */
|
1251
|
1265
|
{
|
1252
|
1266
|
FT_26D6_Vec ctrls[3];
|
|
1267
|
+ FT_26D6 dx, dy;
|
|
1268
|
+ FT_UInt num_splits;
|
1253
|
1269
|
|
1254
|
1270
|
|
1255
|
1271
|
ctrls[0] = edge->start_pos;
|
1256
|
1272
|
ctrls[1] = edge->control_a;
|
1257
|
1273
|
ctrls[2] = edge->end_pos;
|
1258
|
1274
|
|
1259
|
|
- error = split_sdf_conic( memory, ctrls, 32, &new_edges );
|
|
1275
|
+ dx = FT_ABS( ctrls[2].x + ctrls[0].x - 2 * ctrls[1].x );
|
|
1276
|
+ dy = FT_ABS( ctrls[2].y + ctrls[0].y - 2 * ctrls[1].y );
|
|
1277
|
+ if ( dx < dy )
|
|
1278
|
+ dx = dy;
|
|
1279
|
+
|
|
1280
|
+ /* Here we calculate the number of necessary bisections. Each */
|
|
1281
|
+ /* bisection reduces the deviation by exactly 4-fold, hence */
|
|
1282
|
+ /* we bisect the bezier until the deviation becomes less than */
|
|
1283
|
+ /* 1/8th of a pixel. For more details check `ftgrays.c`. */
|
|
1284
|
+ num_splits = 1;
|
|
1285
|
+ while ( dx > ONE_PIXEL / 8 )
|
|
1286
|
+ {
|
|
1287
|
+ dx >>= 2;
|
|
1288
|
+ num_splits <<= 1;
|
|
1289
|
+ }
|
|
1290
|
+
|
|
1291
|
+ error = split_sdf_conic( memory, ctrls, num_splits, &new_edges );
|
1260
|
1292
|
}
|
1261
|
1293
|
break;
|
1262
|
1294
|
|