forked from external/yambar
font: force a pixel fixup factor for scalable bitmap fonts
That is, for color bitmap fonts (typically emoji fonts). Use the same calculation used by fontconfig's 10-scale-bitmap-fonts.conf. Note: if the user has enabled bitmap font scaling in general, we'll pick it up and scale the final glyph image, regardless of whether the font is a regular bitmap font, or a color bitmap font. But, if the user has disabled bitmap font scaling, we only force a fixup factor on color bitmap fonts.
This commit is contained in:
parent
7e8617f090
commit
c72893637c
1 changed files with 30 additions and 4 deletions
34
font.c
34
font.c
|
@ -177,8 +177,11 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx,
|
|||
if (FcPatternGetDouble(final_pattern, FC_DPI, 0, &dpi) != FcResultMatch)
|
||||
dpi = 96;
|
||||
|
||||
double size;
|
||||
double pixel_size;
|
||||
if (FcPatternGetDouble(final_pattern, FC_PIXEL_SIZE, 0, &pixel_size)) {
|
||||
if (FcPatternGetDouble(final_pattern, FC_SIZE, 0, &size) != FcResultMatch ||
|
||||
FcPatternGetDouble(final_pattern, FC_PIXEL_SIZE, 0, &pixel_size) != FcResultMatch)
|
||||
{
|
||||
LOG_ERR("%s: failed to get size", face_file);
|
||||
FcPatternDestroy(final_pattern);
|
||||
return false;
|
||||
|
@ -188,9 +191,32 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx,
|
|||
if (FcPatternGetBool(final_pattern, FC_SCALABLE, 0, &scalable) != FcResultMatch)
|
||||
scalable = FcTrue;
|
||||
|
||||
FcBool outline;
|
||||
if (FcPatternGetBool(final_pattern, FC_OUTLINE, 0, &outline) != FcResultMatch)
|
||||
outline = FcTrue;
|
||||
|
||||
double pixel_fixup;
|
||||
if (FcPatternGetDouble(final_pattern, "pixelsizefixupfactor", 0, &pixel_fixup) != FcResultMatch)
|
||||
pixel_fixup = 1.;
|
||||
if (FcPatternGetDouble(final_pattern, "pixelsizefixupfactor", 0, &pixel_fixup) != FcResultMatch) {
|
||||
/*
|
||||
* Force a fixup factor on scalable bitmap fonts (typically
|
||||
* emoji fonts). The fixup factor is
|
||||
* requested-pixel-size / actual-pixels-size
|
||||
*/
|
||||
if (scalable && !outline) {
|
||||
double original_pixel_size;
|
||||
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &original_pixel_size) != FcResultMatch) {
|
||||
double original_size;
|
||||
if (FcPatternGetDouble(pattern, FC_SIZE, 0, &original_size) != FcResultMatch)
|
||||
original_size = size;
|
||||
original_pixel_size = original_size * dpi / 72;
|
||||
}
|
||||
pixel_fixup = original_pixel_size / pixel_size;
|
||||
|
||||
LOG_DBG("estimated fixup factor to %f (requested pixel size: %f, actual: %f)",
|
||||
pixel_fixup, original_pixel_size, pixel_size);
|
||||
} else
|
||||
pixel_fixup = 1.;
|
||||
}
|
||||
|
||||
LOG_DBG("loading: %s", face_file);
|
||||
|
||||
|
@ -285,7 +311,7 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx,
|
|||
font->face = ft_face;
|
||||
font->load_flags = load_flags | FT_LOAD_COLOR;
|
||||
font->render_flags = render_flags;
|
||||
font->pixel_size_fixup = scalable ? pixel_fixup : 1.;
|
||||
font->pixel_size_fixup = pixel_fixup;
|
||||
font->bgr = fc_rgba == FC_RGBA_BGR || fc_rgba == FC_RGBA_VBGR;
|
||||
font->fc_idx = font_idx;
|
||||
font->is_fallback = is_fallback;
|
||||
|
|
Loading…
Add table
Reference in a new issue