コード例 #1
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        /// <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();
        }
コード例 #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SetupFontFeatures()
        {
            CheckDisposed();

            if (string.IsNullOrEmpty(m_fontName))
            {
                Enabled          = false;
                m_isGraphiteFont = false;
                return;
            }

            using (var hdg = new HoldDummyGraphics(m_fontName, false, false, this))
            {
                IRenderEngine renderer = GraphiteEngineClass.Create();
                renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
                // check if the font is a valid Graphite font
                if (!renderer.FontIsValid)
                {
                    m_isGraphiteFont = false;
                    Enabled          = false;
                    return;
                }
                renderer.WritingSystemFactory = m_wsf;
                m_isGraphiteFont = true;
                m_featureEngine  = renderer as IRenderingFeatures;
                if (m_featureEngine == null)
                {
                    Enabled = false;
                    return;
                }
                int cfid;
                m_featureEngine.GetFeatureIDs(0, null, out cfid);
                if (cfid == 0)
                {
                    Enabled = false;
                    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 <int>(cfid))
                    {
                        m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                        int [] ids = MarshalEx.NativeToArray <int>(idsM, cfid);
                        if (ids[0] == kGrLangFeature)
                        {
                            Enabled = false;
                            return;
                        }
                    }
                }
                Enabled = true;
            }
        }
コード例 #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setups the font features.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void SetupFontFeatures()
		{
			CheckDisposed();

			if (string.IsNullOrEmpty(m_fontName))
			{
				Enabled = false;
				m_isGraphiteFont = false;
				return;
			}

			using (var hdg = new HoldDummyGraphics(m_fontName, false, false, this))
			{
				IRenderEngine renderer = GraphiteEngineClass.Create();
				renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
				// check if the font is a valid Graphite font
				if (!renderer.FontIsValid)
				{
					m_isGraphiteFont = false;
					Enabled = false;
					return;
				}
				renderer.WritingSystemFactory = m_wsf;
				m_isGraphiteFont = true;
				m_featureEngine = renderer as IRenderingFeatures;
				if (m_featureEngine == null)
				{
					Enabled = false;
					return;
				}
				int cfid;
				m_featureEngine.GetFeatureIDs(0, null, out cfid);
				if (cfid == 0)
				{
					Enabled = false;
					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<int>(cfid))
					{
						m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
						int [] ids = MarshalEx.NativeToArray<int>(idsM, cfid);
						if (ids[0] == kGrLangFeature)
						{
							Enabled = false;
							return;
						}
					}
				}
				Enabled = true;
			}
		}
コード例 #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SetupFontFeatures()
        {
            CheckDisposed();

#if __MonoCS__
            // TODO-Linux: Neither Graphite or UniscribeEngine Avaliable
            m_featureEngine = null;
            return;
#else
            if (m_fontName == null || m_fontName == "")
            {
                Enabled          = false;
                m_isGraphiteFont = false;
                return;
            }
            IRenderEngine renderer;
            if (FontHasGraphiteTables(m_fontName, false, false))
            {
                renderer         = FwGrEngineClass.Create();
                m_isGraphiteFont = true;
            }
            else
            {
                renderer         = UniscribeEngineClass.Create();
                m_isGraphiteFont = false;
            }
            renderer.WritingSystemFactory = m_wsf;
            using (HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, this))
            {
                renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
                m_featureEngine = renderer as IRenderingFeatures;
                if (m_featureEngine == null)
                {
                    Enabled = false;
                    return;
                }
                int cfid;
                m_featureEngine.GetFeatureIDs(0, null, out cfid);
                if (cfid == 0)
                {
                    Enabled = false;
                    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 <int>(cfid))
                    {
                        m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                        int [] ids = MarshalEx.NativeToArray <int>(idsM, cfid);
                        if (ids[0] == kGrLangFeature)
                        {
                            Enabled = false;
                            return;
                        }
                    }
                }
                Enabled = true;
            }
#endif
        }
コード例 #6
0
		/// ------------------------------------------------------------------------------------
		/// <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();
		}
コード例 #7
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
コード例 #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Setups the font features.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void SetupFontFeatures()
		{
			CheckDisposed();

#if __MonoCS__
			// TODO-Linux: Neither Graphite or UniscribeEngine Avaliable
			m_featureEngine = null;
			return;
#else
			if (m_fontName == null || m_fontName == "")
			{
				Enabled = false;
				m_isGraphiteFont = false;
				return;
			}
			IRenderEngine renderer;
			if (FontHasGraphiteTables(m_fontName, false, false))
			{
				renderer = FwGrEngineClass.Create();
				m_isGraphiteFont = true;
			}
			else
			{
				renderer = UniscribeEngineClass.Create();
				m_isGraphiteFont = false;
			}
			renderer.WritingSystemFactory = m_wsf;
			using (HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, this))
			{
			renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
			m_featureEngine = renderer as IRenderingFeatures;
			if (m_featureEngine == null)
			{
				Enabled = false;
				return;
			}
			int cfid;
			m_featureEngine.GetFeatureIDs(0, null, out cfid);
			if (cfid == 0)
			{
				Enabled = false;
				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<int>(cfid))
				{
					m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
					int [] ids = MarshalEx.NativeToArray<int>(idsM, cfid);
					if (ids[0] == kGrLangFeature)
					{
						Enabled = false;
						return;
					}
				}
			}
			Enabled = true;
			}
#endif
		}
コード例 #9
0
		/// ------------------------------------------------------------------------------------
		/// <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
			{
				using (HoldDummyGraphics hdg = new HoldDummyGraphics(fontName, fBold, fItalic, this))
				{
					// 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);
					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++;
			//			}

			// This code is a fallback for finding old Graphite fonts installed using the
			// deprecated GrFontInst program.
			// On a few broken Windows machines, normal registry access to HKLM returns null (LT-15158).
			if (RegistryHelper.CompanyKeyLocalMachine == null)
				return false;

			using (RegistryKey regKey = RegistryHelper.CompanyKeyLocalMachine.OpenSubKey("GraphiteFonts"))
			{
				if (regKey == null)
					return false;
				string[] subkeys = regKey.GetSubKeyNames();
				foreach (string key in subkeys)
					if (key == fontName)
						return true;
				return false;
			}
		}