+/* get which font contains a given code point */
+static XftFont *
+getfontucode(FcChar32 ucode)
+{
+ FcCharSet *fccharset = NULL;
+ FcPattern *fcpattern = NULL;
+ FcPattern *match = NULL;
+ XftFont *retfont = NULL;
+ XftResult result;
+ size_t i;
+
+ for (i = 0; i < dc.nfonts; i++)
+ if (XftCharExists(dpy, dc.fonts[i], ucode) == FcTrue)
+ return dc.fonts[i];
+
+ /* create a charset containing our code point */
+ fccharset = FcCharSetCreate();
+ FcCharSetAddChar(fccharset, ucode);
+
+ /* create a pattern akin to the dc.pattern but containing our charset */
+ if (fccharset) {
+ fcpattern = FcPatternDuplicate(dc.pattern);
+ FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
+ }
+
+ /* find pattern matching fcpattern */
+ if (fcpattern) {
+ FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
+ FcDefaultSubstitute(fcpattern);
+ match = XftFontMatch(dpy, screen, fcpattern, &result);
+ }
+
+ /* if found a pattern, open its font */
+ if (match) {
+ retfont = XftFontOpenPattern(dpy, match);
+ if (retfont && XftCharExists(dpy, retfont, ucode) == FcTrue) {
+ if ((dc.fonts = realloc(dc.fonts, dc.nfonts+1)) == NULL)
+ err(1, "realloc");
+ dc.fonts[dc.nfonts] = retfont;
+ return dc.fonts[dc.nfonts++];
+ } else {
+ XftFontClose(dpy, retfont);
+ }
+ }
+
+ /* in case no fount was found, return the first one */
+ return dc.fonts[0];
+}
+
+/* draw text into XftDraw, return width of text glyphs */