pixel-size from QCdpi property of PREFER or from the Y-resolution
of FRAME before sorting.
- If BEST-ONLY is nonzero, return the best matching entity. Otherwise,
- return the sorted VEC. */
+ If BEST-ONLY is nonzero, return the best matching entity (that
+ supports the character BEST-ONLY if BEST-ONLY is positive, or any
+ if BEST-ONLY is negative). Otherwise, return the sorted VEC.
+
+ This function does no optimization for the case that the length of
+ VEC is 1. The caller should avoid calling this in such a case. */
static Lisp_Object
font_sort_entites (vec, prefer, frame, best_only)
USE_SAFE_ALLOCA;
len = ASIZE (vec);
- if (len <= 1)
- return best_only ? AREF (vec, 0) : vec;
-
for (i = FONT_WEIGHT_INDEX; i <= FONT_DPI_INDEX; i++)
prefer_prop[i] = AREF (prefer, i);
if (FLOATP (prefer_prop[FONT_SIZE_INDEX]))
/* Scoring and sorting. */
SAFE_ALLOCA (data, struct font_sort_data *, (sizeof *data) * len);
- best_score = 0xFFFFFFFF;
/* We are sure that the length of VEC > 1. */
driver_type = AREF (AREF (vec, 0), FONT_TYPE_INDEX);
for (driver_order = 0, list = f->font_driver_list; list;
driver_order++, list = list->next)
if (EQ (driver_type, list->driver->type))
break;
- best_entity = data[0].entity = AREF (vec, 0);
- best_score = data[0].score
- = font_score (data[0].entity, prefer_prop) | driver_order;
+ best_score = 0xFFFFFFFF;
+ best_entity = Qnil;
for (i = 0; i < len; i++)
{
if (!EQ (driver_type, AREF (AREF (vec, i), FONT_TYPE_INDEX)))
if (EQ (driver_type, list->driver->type))
break;
data[i].entity = AREF (vec, i);
- data[i].score = font_score (data[i].entity, prefer_prop) | driver_order;
+ data[i].score
+ = (best_only <= 0 || font_has_char (f, data[i].entity, best_only) > 0
+ ? font_score (data[i].entity, prefer_prop) | driver_order
+ : 0xFFFFFFFF);
if (best_only && best_score > data[i].score)
{
best_score = data[i].score;
if (NILP (AREF (prefer, FONT_WIDTH_INDEX)))
FONT_SET_STYLE (prefer, FONT_WIDTH_INDEX, attrs[LFACE_SWIDTH_INDEX]);
ASET (prefer, FONT_SIZE_INDEX, make_number (pixel_size));
- entities = font_sort_entites (entities, prefer, frame, c < 0);
-
- if (c < 0)
- return entities;
-
- for (i = 0; i < ASIZE (entities); i++)
- {
- int j;
- font_entity = AREF (entities, i);
-#if 0
- /* The following code is intended to avoid checking of
- font_has_char repeatedly for bitmap fonts that differs only
- in pixelsize. But, it doesn't work well if fontconfig is
- configured to find BDF/PFC fonts. */
- if (i > 0)
- {
- for (j = FONT_FOUNDRY_INDEX; j <= FONT_REGISTRY_INDEX; j++)
- if (! EQ (AREF (font_entity, j), props[j]))
- break;
- if (j > FONT_REGISTRY_INDEX)
- continue;
- }
- for (j = FONT_FOUNDRY_INDEX; j <= FONT_REGISTRY_INDEX; j++)
- props[j] = AREF (font_entity, j);
-#endif
- result = font_has_char (f, font_entity, c);
- if (result > 0)
- return font_entity;
- }
- return Qnil;
+ return font_sort_entites (entities, prefer, frame, c);
}
/* Return a font-entity satisfying SPEC and best matching with face's