/// ------------------------------------------------------------------------------------ /// <summary> /// Setups the font features. /// </summary> /// ------------------------------------------------------------------------------------ private void SetupFontFeatures() { if (m_fontName == null || m_fontName == "") { Enabled = false; return; } IRenderEngine renderer; if (FontHasGraphiteTables(m_fontName, false, false)) { renderer = FwGrEngineClass.Create(); } else { renderer = UniscribeEngineClass.Create(); } renderer.WritingSystemFactory = m_wsf; HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, CreateGraphics()); renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures); m_featureEngine = renderer as IRenderingFeatures; if (m_featureEngine == null) { Enabled = false; hdg.Close(); return; } int cfid; m_featureEngine.GetFeatureIDs(0, null, out cfid); if (cfid == 0) { Enabled = false; hdg.Close(); return; } if (cfid == 1) { // What if it's the dummy built-in graphite feature that we ignore? // Get the list of features (only 1). using (ArrayPtr idsM = MarshalEx.ArrayToNative(cfid, typeof(int))) { m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid); int [] ids = (int[])MarshalEx.NativeToArray(idsM, cfid, typeof(int)); if (ids[0] == kGrLangFeature) { Enabled = false; hdg.Close(); return; } } } Enabled = true; hdg.Close(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fonts the has graphite tables. /// </summary> /// <param name="fontName">Name of the font.</param> /// <param name="fBold">if set to <c>true</c> [f bold].</param> /// <param name="fItalic">if set to <c>true</c> [f italic].</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool FontHasGraphiteTables(string fontName, bool fBold, bool fItalic) { try { HoldDummyGraphics hdg = new HoldDummyGraphics(fontName, fBold, fItalic, CreateGraphics()); // Ask it whether that font has the main Graphite data table. If it does, // we assume it is a Graphite font. int tblSize; const int tag_Silf = 0x666c6953; hdg.m_vwGraphics.GetFontData(tag_Silf, out tblSize); hdg.Close(); if (tblSize > 0) { return(true); } } catch { return(false); } // This has not yet been fully tested, should be equivalent to the following C++. // StrApp str("Software\\SIL\\GraphiteFonts"); // bool f; // RegKey hkey; // f = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, 0, katRead, &hkey); // if (f != ERROR_SUCCESS) // return false; // // DWORD dwIndex = 0; // for ( ; ; ) // { // achar rgch[256]; // DWORD cb = isizeof(rgch); // LONG l = ::RegEnumKeyEx(hkey, dwIndex, rgch, &cb, NULL, NULL, NULL, NULL); // if (_tcscmp(pszFontKey, rgch) == 0) // return true; // else if (l == ERROR_NO_MORE_ITEMS) // return false; // else if (l != ERROR_SUCCESS) // return false; // dwIndex++; // } RegistryKey regKey = Registry.LocalMachine.OpenSubKey("Software\\SIL\\GraphiteFonts"); if (regKey == null) { return(false); } string [] subkeys = regKey.GetSubKeyNames(); foreach (string key in subkeys) { if (key == fontName) { return(true); } } return(false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Setups the font features. /// </summary> /// ------------------------------------------------------------------------------------ private void SetupFontFeatures() { if (m_fontName == null || m_fontName == "") { Enabled = false; return; } IRenderEngine renderer; if (FontHasGraphiteTables(m_fontName, false, false)) renderer = FwGrEngineClass.Create(); else renderer = UniscribeEngineClass.Create(); renderer.WritingSystemFactory = m_wsf; HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, CreateGraphics()); renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures); m_featureEngine = renderer as IRenderingFeatures; if (m_featureEngine == null) { Enabled = false; hdg.Close(); return; } int cfid; m_featureEngine.GetFeatureIDs(0, null, out cfid); if (cfid == 0) { Enabled = false; hdg.Close(); return; } if (cfid == 1) { // What if it's the dummy built-in graphite feature that we ignore? // Get the list of features (only 1). using (ArrayPtr idsM = MarshalEx.ArrayToNative(cfid, typeof(int))) { m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid); int [] ids = (int[])MarshalEx.NativeToArray(idsM, cfid, typeof(int)); if (ids[0] == kGrLangFeature) { Enabled = false; hdg.Close(); return; } } } Enabled = true; hdg.Close(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fonts the has graphite tables. /// </summary> /// <param name="fontName">Name of the font.</param> /// <param name="fBold">if set to <c>true</c> [f bold].</param> /// <param name="fItalic">if set to <c>true</c> [f italic].</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool FontHasGraphiteTables(string fontName, bool fBold, bool fItalic) { try { HoldDummyGraphics hdg = new HoldDummyGraphics(fontName, fBold, fItalic, CreateGraphics()); // Ask it whether that font has the main Graphite data table. If it does, // we assume it is a Graphite font. int tblSize; const int tag_Silf = 0x666c6953; hdg.m_vwGraphics.GetFontData(tag_Silf, out tblSize); hdg.Close(); if (tblSize > 0) return true; } catch { return false; } // This has not yet been fully tested, should be equivalent to the following C++. // StrApp str("Software\\SIL\\GraphiteFonts"); // bool f; // RegKey hkey; // f = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, str, 0, katRead, &hkey); // if (f != ERROR_SUCCESS) // return false; // // DWORD dwIndex = 0; // for ( ; ; ) // { // achar rgch[256]; // DWORD cb = isizeof(rgch); // LONG l = ::RegEnumKeyEx(hkey, dwIndex, rgch, &cb, NULL, NULL, NULL, NULL); // if (_tcscmp(pszFontKey, rgch) == 0) // return true; // else if (l == ERROR_NO_MORE_ITEMS) // return false; // else if (l != ERROR_SUCCESS) // return false; // dwIndex++; // } RegistryKey regKey = Registry.LocalMachine.OpenSubKey("Software\\SIL\\GraphiteFonts"); if (regKey == null) return false; string [] subkeys = regKey.GetSubKeyNames(); foreach (string key in subkeys) if (key == fontName) return true; return false; }