Beispiel #1
0
        private Tuple <bool, IRenderEngine> GetRenderingEngine(string fontName, IVwGraphics vg, ILgWritingSystem ws)
        {
            // NB: Even if the ws claims graphite is enabled, this might not be a graphite font
            if (ws.IsGraphiteEnabled)
            {
                var graphiteEngine = GraphiteEngineClass.Create();

                string fontFeatures = null;
                if (fontName == ws.DefaultFontName)
                {
                    fontFeatures = GraphiteFontFeatures.ConvertFontFeatureCodesToIds(ws.DefaultFontFeatures);
                }
                graphiteEngine.InitRenderer(vg, fontFeatures);
                // check if the font is a valid Graphite font
                if (graphiteEngine.FontIsValid)
                {
                    graphiteEngine.RenderEngineFactory  = this;
                    graphiteEngine.WritingSystemFactory = ws.WritingSystemFactory;
                    return(new Tuple <bool, IRenderEngine>(ws.IsGraphiteEnabled, graphiteEngine));
                }
                // It wasn't really a graphite font - release the graphite one and create a Uniscribe below
                Marshal.ReleaseComObject(graphiteEngine);
            }
            return(new Tuple <bool, IRenderEngine>(ws.IsGraphiteEnabled, GetUniscribeEngine(vg, ws)));
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get the engine used to render text with the specified properties. At present only
        /// font, bold, and italic properties are significant.
        /// Font name may be '&lt;default serif&gt;' which produces a renderer suitable for the default
        /// serif font.
        /// </summary>
        /// <param name="vg"></param>
        /// <returns></returns>
        public IRenderEngine get_Renderer(IVwGraphics vg)
        {
            lock (m_syncRoot)
            {
                LgCharRenderProps          chrp     = vg.FontCharProperties;
                string                     fontName = MarshalEx.UShortToString(chrp.szFaceName);
                Tuple <string, bool, bool> key      = Tuple.Create(fontName, chrp.ttvBold == (int)FwTextToggleVal.kttvForceOn,
                                                                   chrp.ttvItalic == (int)FwTextToggleVal.kttvForceOn);
                IRenderEngine renderEngine;
                if (m_renderEngines.TryGetValue(key, out renderEngine))
                {
                    return(renderEngine);
                }
                Tuple <string, bool, bool> key2 = null;
                string realFontName;
                if (TryGetRealFontName(fontName, out realFontName))
                {
                    MarshalEx.StringToUShort(realFontName, chrp.szFaceName);
                    vg.SetupGraphics(ref chrp);
                    key2 = Tuple.Create(realFontName, key.Item2, key.Item3);
                    if (m_renderEngines.TryGetValue(key2, out renderEngine))
                    {
                        m_renderEngines[key] = renderEngine;
                        return(renderEngine);
                    }
                }
                else
                {
                    realFontName = fontName;
                }

                bool graphiteFont = false;
                if (m_isGraphiteEnabled)
                {
                    renderEngine = GraphiteEngineClass.Create();

                    string fontFeatures = null;
                    if (realFontName == DefaultFontName)
                    {
                        fontFeatures = DefaultFontFeatures;
                    }
                    renderEngine.InitRenderer(vg, fontFeatures);
                    // check if the font is a valid Graphite font
                    if (renderEngine.FontIsValid)
                    {
                        SetupRenderEngine(renderEngine);
                        graphiteFont = true;
                    }
                }

                if (!graphiteFont)
                {
                    if (!MiscUtils.IsUnix)
                    {
                        if (m_uniscribeEngine == null)
                        {
                            m_uniscribeEngine = UniscribeEngineClass.Create();
                            m_uniscribeEngine.InitRenderer(vg, null);
                            SetupRenderEngine(m_uniscribeEngine);
                        }
                        renderEngine = m_uniscribeEngine;
                    }
                    else
                    {
                        // default to the UniscribeEngine unless ROMAN environment variable is set.
                        if (Environment.GetEnvironmentVariable("ROMAN") == null)
                        {
                            renderEngine = UniscribeEngineClass.Create();
                        }
                        else
                        {
                            renderEngine = RomRenderEngineClass.Create();
                        }
                        renderEngine.InitRenderer(vg, null);
                        SetupRenderEngine(renderEngine);
                    }
                }

                m_renderEngines[key] = renderEngine;
                if (key2 != null)
                {
                    m_renderEngines[key2] = renderEngine;
                }
                return(renderEngine);
            }
        }