]> uap-core.de Git - uwplayer.git/commitdiff
add support for font substitution in the sidebar
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 15 Aug 2025 16:42:11 +0000 (18:42 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 15 Aug 2025 16:42:11 +0000 (18:42 +0200)
application/Sidebar.c
application/nfont.c
application/nfont.h

index fa086024f55b20829781e7d820a779a316ceafb8..481caf2b9618a7b15f6869d9a12bce78595ef293 100644 (file)
@@ -316,7 +316,7 @@ static void sidebar_expose(Widget widget, XEvent *event, Region     region) {
             XftDrawRect(s->sidebar.d, &s->sidebar.select2_bg, 0, i.index*height, s->core.width, height);
         }
         
-        XftDrawString8(s->sidebar.d, cg, s->sidebar.font->fonts->font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
+        FontDrawString8(s->sidebar.d, cg, s->sidebar.font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
     }
 }
 
index bf677a0e5d6c24edc9e042d053945929a9c83a1b..cce3666c282ab219cdb71dbb2161d030d0eea256 100644 (file)
@@ -212,4 +212,72 @@ void FontUnref(NFont *font) {
     if(--font->ref == 0) {
         FontDestroy(font);
     }
-}
\ No newline at end of file
+}
+
+void FontDrawString8(
+        XftDraw *draw,
+        const XftColor *color,
+        NFont *font,
+        int x,
+        int y,
+        const FcChar8 *string,
+        int len)
+{
+    FcChar32 static_buffer[128];
+    FcChar32 *buf = static_buffer;
+    if(len >= 128) {
+        buf = calloc(len, sizeof(FcChar32));
+    }
+    
+    // convert string from utf8 to utf32
+    int c = 0;
+    for(int i=0;i<len;) {
+        int n = FcUtf8ToUcs4(string+i, &buf[c++], len-i);
+        i += n;
+    }
+    
+    FontDrawString32(draw, color, font, x, y, buf, c);
+    
+    if(buf != static_buffer) {
+        free(buf);
+    }
+}
+
+void FontDrawString32(
+        XftDraw *draw,
+        const XftColor *color,
+        NFont *font,
+        int x,
+        int y,
+        const FcChar32 *string,
+        int len)
+{
+    XftFont *currentFont = FontDefault(font);
+    int pos = 0;
+    for(int i=0;i<len;i++) {
+        XftFont *cFont = FindFont(font, string[i]);
+        if(cFont != currentFont && i > pos) {
+            const FcChar32 *segStr = string+pos;
+            int segLen = i-pos;
+            
+            // get extents of string segment
+            XGlyphInfo extents;
+            XftTextExtents32(XftDrawDisplay(draw), currentFont, segStr, segLen, &extents);
+            
+            // draw previous characters
+            XftDrawString32(draw, color, currentFont, x, y, segStr, segLen);
+            
+            x += extents.xOff;
+            pos = i;
+        }
+        currentFont = cFont;
+    }
+    
+    if(pos < len) {
+        const FcChar32 *segStr = string+pos;
+        int segLen = len-pos;
+        // draw previous characters
+        XftDrawString32(draw, color, currentFont, x, y, segStr, segLen);
+    }
+
+}
index 179d289f869c28c6c5175f2b57cee0f49720ecd4..cbefd86edb967c25a74b223e313f05145055f00d 100644 (file)
@@ -63,6 +63,23 @@ void FontDestroy(NFont *f);
 NFont *FontRef(NFont *font);
 void FontUnref(NFont *font);
 
+void FontDrawString8(
+        XftDraw *draw,
+        const XftColor *color,
+        NFont *font,
+        int x,
+        int y,
+        const FcChar8 *string,
+        int len);
+
+void FontDrawString32(
+        XftDraw *draw,
+        const XftColor *color,
+        NFont *font,
+        int x,
+        int y,
+        const FcChar32 *string,
+        int len);
 
 #ifdef __cplusplus
 }