[Y-devel] Font patch for fallback behaviour
Chris Amshey ychris at amshey.net
Tue Feb 24 19:47:51 GMT 2004
This is patch I came up with for dealing with the behaviour in the case
that a font is not found. Current behaviour (patch-22) is to grab the
first font and use it. When the first font is not scalable, this works
badly, so this patch just makes sure that we grab the first -scalable-
font. (Yes, this means if you want a fixed font, you'd better name it
correctly.) This is probably not the correct long-term solution, but it
increases the chances of readable widgets when fonts aren't doing the
right thing.
--Chris
-------------- next part --------------
diff -x '\{arch\}' -u -r clean/Y/text/font.c fontpatch/Y/text/font.c
--- clean/Y/text/font.c 2004-02-24 14:27:43.000000000 -0500
+++ fontpatch/Y/text/font.c 2004-02-24 14:27:20.000000000 -0500
@@ -25,7 +25,6 @@
static FT_Library ft_library;
static struct Index *faces;
-
struct Face
{
char *familyName;
@@ -245,6 +244,38 @@
struct FontString *cachedString;
};
+/* faceFirstScalable:
+ For emergency use only, searches through all the font faces we know about
+ and grabs the first one that is scalable.
+*/
+static struct Face *
+faceFirstScalable(void)
+{
+ struct Face *face = NULL;
+ FT_Face ft_face;
+ struct IndexIterator *iter = indexGetStartIterator (faces);
+
+ while (indexiteratorHasValue(iter))
+ {
+ face = indexiteratorGet (iter);
+ ft_face = faceObtain (face);
+ if(ft_face->face_flags & FT_FACE_FLAG_SCALABLE)
+ {
+ faceRelease(face);
+ indexiteratorDestroy (iter);
+ return face;
+ }
+ else
+ {
+ faceRelease(face);
+ indexiteratorNext (iter);
+ }
+ }
+
+ Y_ERROR ("No scalable fonts found on system!");
+ indexiteratorDestroy(iter);
+ return NULL;
+}
struct Font *
fontCreate (const char *family, const char *style, int ptSize)
{
@@ -259,25 +290,20 @@
if (face == NULL)
{
- struct IndexIterator *iter = indexGetStartIterator (faces);
- face = indexiteratorGet (iter);
- indexiteratorDestroy (iter);
- if (face == NULL)
- {
- Y_ERROR ("No fonts found on system!");
- return NULL;
- }
+ if((face = faceFirstScalable()) == NULL)
+ return NULL;
}
-
ft_face = faceObtain (face);
err = FT_New_Size (ft_face, &size);
if (err)
return NULL;
- FT_Activate_Size (size);
+ if(FT_Activate_Size (size) != 0)
+ Y_ERROR("activate size bad");
- FT_Set_Char_Size (ft_face, 0, ptSize << 6, 0, 0);
+ if(FT_Set_Char_Size (ft_face, 0, ptSize << 6, 0, 0) != 0)
+ Y_ERROR("set char size bad");
font = ymalloc (sizeof (struct Font));
font -> face = face;
More information about the Y-devel mailing list
2026 © www.Y-Windows.Org - All Rights Reserved