-static int compare_double(const void *_a, const void *_b)
-{
- const double*a = (const double*)_a;
- const double*b = (const double*)_b;
- if(*a < *b)
- return -1;
- if(*a > *b)
- return 1;
- return 0;
-}
-
-double GlyphInfo::estimateAdvance()
-{
- AdvanceSample*a = advance_samples;
- int n=0;
- while(a) {
- n++;
- a = a->next;
- }
- if(!n)
- return -1;
- double*list = (double*)malloc(sizeof(double)*n);
- n = 0;
- a = advance_samples;
- while(a) {
- list[n++] = a->advance;
- a = a->next;
- }
- // FIXME: a true median algorithm would be faster
- qsort(list, n, sizeof(double), compare_double);
- double median = list[n/2];
- free(list);
- return median;
-}
-