| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* afangles.c */ | 3 /* afangles.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* Routines used to compute vector angles with limited accuracy */ | 5 /* Routines used to compute vector angles with limited accuracy */ |
| 6 /* and very high speed. It also contains sorting routines (body). */ | 6 /* and very high speed. It also contains sorting routines (body). */ |
| 7 /* */ | 7 /* */ |
| 8 /* Copyright 2003-2006, 2011 by */ | 8 /* Copyright 2003-2006, 2011-2012 by */ |
| 9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 10 /* */ | 10 /* */ |
| 11 /* This file is part of the FreeType project, and may only be used, */ | 11 /* This file is part of the FreeType project, and may only be used, */ |
| 12 /* modified, and distributed under the terms of the FreeType project */ | 12 /* modified, and distributed under the terms of the FreeType project */ |
| 13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 14 /* this file you indicate that you have read the license and */ | 14 /* this file you indicate that you have read the license and */ |
| 15 /* understand and accept it fully. */ | 15 /* understand and accept it fully. */ |
| 16 /* */ | 16 /* */ |
| 17 /***************************************************************************/ | 17 /***************************************************************************/ |
| 18 | 18 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 FT_Pos* table ) | 248 FT_Pos* table ) |
| 249 { | 249 { |
| 250 FT_UInt i, j; | 250 FT_UInt i, j; |
| 251 FT_Pos swap; | 251 FT_Pos swap; |
| 252 | 252 |
| 253 | 253 |
| 254 for ( i = 1; i < count; i++ ) | 254 for ( i = 1; i < count; i++ ) |
| 255 { | 255 { |
| 256 for ( j = i; j > 0; j-- ) | 256 for ( j = i; j > 0; j-- ) |
| 257 { | 257 { |
| 258 if ( table[j] > table[j - 1] ) | 258 if ( table[j] >= table[j - 1] ) |
| 259 break; | 259 break; |
| 260 | 260 |
| 261 swap = table[j]; | 261 swap = table[j]; |
| 262 table[j] = table[j - 1]; | 262 table[j] = table[j - 1]; |
| 263 table[j - 1] = swap; | 263 table[j - 1] = swap; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 | 268 |
| 269 FT_LOCAL_DEF( void ) | 269 FT_LOCAL_DEF( void ) |
| 270 af_sort_widths( FT_UInt count, | 270 af_sort_and_quantize_widths( FT_UInt* count, |
| 271 AF_Width table ) | 271 AF_Width table, |
| 272 FT_Pos threshold ) |
| 272 { | 273 { |
| 273 FT_UInt i, j; | 274 FT_UInt i, j; |
| 275 FT_UInt cur_idx; |
| 276 FT_Pos cur_val; |
| 277 FT_Pos sum; |
| 274 AF_WidthRec swap; | 278 AF_WidthRec swap; |
| 275 | 279 |
| 276 | 280 |
| 277 for ( i = 1; i < count; i++ ) | 281 if ( *count == 1 ) |
| 282 return; |
| 283 |
| 284 /* sort */ |
| 285 for ( i = 1; i < *count; i++ ) |
| 278 { | 286 { |
| 279 for ( j = i; j > 0; j-- ) | 287 for ( j = i; j > 0; j-- ) |
| 280 { | 288 { |
| 281 if ( table[j].org > table[j - 1].org ) | 289 if ( table[j].org >= table[j - 1].org ) |
| 282 break; | 290 break; |
| 283 | 291 |
| 284 swap = table[j]; | 292 swap = table[j]; |
| 285 table[j] = table[j - 1]; | 293 table[j] = table[j - 1]; |
| 286 table[j - 1] = swap; | 294 table[j - 1] = swap; |
| 287 } | 295 } |
| 288 } | 296 } |
| 297 |
| 298 cur_idx = 0; |
| 299 cur_val = table[cur_idx].org; |
| 300 |
| 301 /* compute and use mean values for clusters not larger than */ |
| 302 /* `threshold'; this is very primitive and might not yield */ |
| 303 /* the best result, but normally, using reference character */ |
| 304 /* `o', `*count' is 2, so the code below is fully sufficient */ |
| 305 for ( i = 1; i < *count; i++ ) |
| 306 { |
| 307 if ( table[i].org - cur_val > threshold || |
| 308 i == *count - 1 ) |
| 309 { |
| 310 sum = 0; |
| 311 |
| 312 /* fix loop for end of array */ |
| 313 if ( table[i].org - cur_val <= threshold && |
| 314 i == *count - 1 ) |
| 315 i++; |
| 316 |
| 317 for ( j = cur_idx; j < i; j++ ) |
| 318 { |
| 319 sum += table[j].org; |
| 320 table[j].org = 0; |
| 321 } |
| 322 table[cur_idx].org = sum / j; |
| 323 |
| 324 if ( i < *count - 1 ) |
| 325 { |
| 326 cur_idx = i + 1; |
| 327 cur_val = table[cur_idx].org; |
| 328 } |
| 329 } |
| 330 } |
| 331 |
| 332 cur_idx = 1; |
| 333 |
| 334 /* compress array to remove zero values */ |
| 335 for ( i = 1; i < *count; i++ ) |
| 336 { |
| 337 if ( table[i].org ) |
| 338 table[cur_idx++] = table[i]; |
| 339 } |
| 340 |
| 341 *count = cur_idx; |
| 289 } | 342 } |
| 290 | 343 |
| 291 | 344 |
| 292 /* END */ | 345 /* END */ |
| OLD | NEW |