/// <summary> /// Get the name of the default font for the given language tag. /// </summary> /// <param name="lang">ISO 3066 tag for the language (e.g., "en", "es", "zh-CN", etc.)</param> /// <returns>Name of the font, or <c>null</c> if not found.</returns> public static string GetFontNameForLanguage(string lang) { if (MiscUtils.IsWindows) { throw new PlatformNotSupportedException(); } string fontName; if (m_mapLangToFont.TryGetValue(lang, out fontName)) { return(fontName); } IntPtr pattern = FcPatternCreate(); int isOk = FcPatternAddString(pattern, FC_LANG, lang); if (isOk == 0) { FcPatternDestroy(pattern); return(null); } isOk = FcConfigSubstitute(IntPtr.Zero, pattern, FcMatchKind.FcMatchPattern); if (isOk == 0) { FcPatternDestroy(pattern); return(null); } FcDefaultSubstitute(pattern); FcResult result; IntPtr fullPattern = FcFontMatch(IntPtr.Zero, pattern, out result); if (result != FcResult.FcResultMatch) { FcPatternDestroy(pattern); FcPatternDestroy(fullPattern); return(null); } FcPatternDestroy(pattern); IntPtr res; FcResult fcRes = FcPatternGetString(fullPattern, FC_FAMILY, 0, out res); if (fcRes == FcResult.FcResultMatch) { fontName = Marshal.PtrToStringAuto(res); m_mapLangToFont.Add(lang, fontName); } FcPatternDestroy(fullPattern); return(fontName); }
public FcPattern Match(FcConfig config, out FcResult result) { return(new FcPattern(Native.FcFontMatch(config.Handle, Handle, out result))); }
public static extern System.IntPtr FcFontMatch(System.IntPtr config, System.IntPtr p, out FcResult result);
static extern IntPtr FcFontMatch(IntPtr config, IntPtr pattern, out FcResult result);
private static extern IntPtr FcFontMatch_Base(IntPtr config, IntPtr pattern, out FcResult result);