Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/fcbitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
#include "fcint.h"
#include <stdlib.h>

struct _FcBitset {
size_t size;
size_t ones;
FcChar8 data[];
};

FcBitset *
FcBitsetCreate (size_t size)
{
Expand Down
12 changes: 12 additions & 0 deletions src/fcdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ FcFontSetPrint (const FcFontSet *s)
}
}

void
FcBitsetPrint (const FcBitset *s)
{
int i;
printf ("Bitset of size %d (%d ones): ", s->size, s->ones);
for (i = 0; i < (s->size + 7) / 8; i++)
{
printf ("%02x ", s->data[i]);
}
printf ("\n");
}

int FcDebugVal;

void
Expand Down
9 changes: 8 additions & 1 deletion src/fcint.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,11 @@ struct _FcValuePromotionBuffer {

/* fcbitset.c */

typedef struct _FcBitset FcBitset;
typedef struct _FcBitset {
size_t size;
size_t ones;
FcChar8 data[];
} FcBitset;

FcPrivate FcBitset *
FcBitsetCreate (size_t size);
Expand Down Expand Up @@ -865,6 +869,9 @@ FcCharSetPrint (const FcCharSet *c);
FcPrivate void
FcPatternPrint2 (FcPattern *p1, FcPattern *p2, const FcObjectSet *os);

FcPrivate void
FcBitsetPrint (const FcBitset *s);

extern FcPrivate int FcDebugVal;

#define FcDebug() (FcDebugVal)
Expand Down
48 changes: 40 additions & 8 deletions src/fcmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,32 @@ FcFontSetMatchInternal (FcFontSet **sets,
FcResult *result)
{
FcPattern *best = NULL;
int set;
int index;
int f;

if (FcDebug () & FC_DBG_MATCH)
{
printf ("Match ");
FcPatternPrint (p);
}

if (FcDebug () & FC_DBG_MATCHV)
{
index = 0;
for (set = 0; set < nsets; set++)
for (f = 0; f < sets[set]->nfont; f++, index++)
{
printf ("Font %d ", index);
FcPatternPrint (sets[set]->fonts[f]);
}
}

// Preprocess pattern
FcPreprocessPattern(p);

// Count fonts in all sets
size_t font_count = 0;
int set;
for (set = 0; set < nsets; set++)
font_count += sets[set]->nfont;

Expand Down Expand Up @@ -735,6 +748,9 @@ FcFontSetMatchInternal (FcFontSet **sets,
int priority;
for (priority = 0; priority < PRI_END; priority++)
{
if (FcDebug () & FC_DBG_MATCHV)
printf ("Priority %d:\n", priority);

// Find the matcher for given priority
const FcMatcher *matcher = NULL;
for (matcher = &_FcMatchers[0]; matcher->weak != priority && matcher->strong != priority; matcher++);
Expand All @@ -749,10 +765,15 @@ FcFontSetMatchInternal (FcFontSet **sets,
FcBitsetClear(best_matches_so_far, FcFalse);
double best_score_so_far = 1e99;

// For each priority we are only interested in getting one score.
// Its strength is only determinied by the priority, so do it right now.
double score = 0.0;
double *value_strong = likely(matcher->strong == priority) ? &score : NULL;
double *value_weak = likely(matcher->weak == priority) ? &score : NULL;
assert(value_strong || value_weak);

// Iterate over all fonts in all sets
int index = 0;
int set;
for (set = 0; set < nsets; set++)
for (set = 0, index = 0; set < nsets; set++)
{
FcFontSet *s = sets[set];
if (!s)
Expand All @@ -769,23 +790,21 @@ FcFontSetMatchInternal (FcFontSet **sets,

// Compare the font's value lists to the pattern's value list and measure distance.
// If the font doesn't contain such object, it is considered as distance 0 (best).
double score_strong = 0.0, score_weak = 0.0;
score = 0.0;
const FcPatternElt *font_elt = FcPatternObjectFindElt(font, matcher->object);
if (font_elt)
{
if (!FcCompareValueList (matcher->object, matcher,
FcPatternEltValues(p_elt),
FcPatternEltValues(font_elt),
NULL, &score_strong, &score_weak,
NULL, value_strong, value_weak,
NULL, result))
{
best = NULL;
goto out2;
}
}

double score = (FcPatternEltValues(p_elt)->binding == FcValueBindingStrong ? score_strong : score_weak);

// If this font was better match than the best so far, forget them and remember new best.
if (score < best_score_so_far)
{
Expand All @@ -803,6 +822,13 @@ FcFontSetMatchInternal (FcFontSet **sets,
}
}

if (FcDebug () & FC_DBG_MATCHV)
{
printf ("Best ");
FcBitsetPrint (best_matches_so_far);
}


// If we managed to narrow the search down to one font, it is stored in `best` variable, go out.
if (FcBitsetCountOnes(best_matches_so_far) <= 1)
break;
Expand All @@ -814,6 +840,12 @@ FcFontSetMatchInternal (FcFontSet **sets,
possible_matches = tmp;
}

if (FcDebug () & FC_DBG_MATCH)
{
printf ("Best ");
FcPatternPrint (best);
}

/* assuming that 'result' is initialized with FcResultNoMatch
* outside this function */
if (best)
Expand Down