public void InterpretChrp() { var wsManager = new PalasoWritingSystemManager(); IWritingSystem ws = wsManager.Create("en-US"); var chrp = new LgCharRenderProps { ws = ws.Handle, szFaceName = new ushort[32], dympHeight = 10000, ssv = (int)FwSuperscriptVal.kssvSuper }; MarshalEx.StringToUShort("<default font>", chrp.szFaceName); ws.InterpretChrp(ref chrp); Assert.AreEqual(ws.DefaultFontName, MarshalEx.UShortToString(chrp.szFaceName)); Assert.AreEqual(10000 / 3, chrp.dympOffset); Assert.AreEqual((10000 * 2) / 3, chrp.dympHeight); Assert.AreEqual((int)FwSuperscriptVal.kssvOff, chrp.ssv); chrp.ssv = (int)FwSuperscriptVal.kssvSub; chrp.dympHeight = 10000; chrp.dympOffset = 0; ws.InterpretChrp(ref chrp); Assert.AreEqual(-(10000 / 5), chrp.dympOffset); Assert.AreEqual((10000 * 2) / 3, chrp.dympHeight); Assert.AreEqual((int)FwSuperscriptVal.kssvOff, chrp.ssv); wsManager.Save(); }
public void get_RendererFromChrp_Graphite() { using (GraphicsManager gm = new GraphicsManager(new Form())) { gm.Init(1.0f); try { var wsManager = new PalasoWritingSystemManager(); // by default Graphite is disabled IWritingSystem ws = wsManager.Set("en-US"); var chrp = new LgCharRenderProps { ws = ws.Handle, szFaceName = new ushort[32] }; MarshalEx.StringToUShort("Charis SIL", chrp.szFaceName); IRenderEngine engine = wsManager.get_RendererFromChrp(gm.VwGraphics, ref chrp); Assert.IsNotNull(engine); Assert.AreSame(wsManager, engine.WritingSystemFactory); Assert.IsInstanceOf(typeof(UniscribeEngine), engine); ws.IsGraphiteEnabled = true; engine = wsManager.get_RendererFromChrp(gm.VwGraphics, ref chrp); Assert.IsNotNull(engine); Assert.AreSame(wsManager, engine.WritingSystemFactory); Assert.IsInstanceOf(typeof(FwGrEngine), engine); wsManager.Save(); } finally { gm.Uninit(); } } }
public void get_Renderer_Uniscribe() { using (var control = new Form()) using (var gm = new GraphicsManager(control)) using (var reFactory = new RenderEngineFactory()) { gm.Init(1.0f); try { var wsManager = new WritingSystemManager(); CoreWritingSystemDefinition ws = wsManager.Set("en-US"); var chrp = new LgCharRenderProps { ws = ws.Handle, szFaceName = new ushort[32] }; MarshalEx.StringToUShort("Arial", chrp.szFaceName); gm.VwGraphics.SetupGraphics(ref chrp); IRenderEngine engine = reFactory.get_Renderer(ws, gm.VwGraphics); Assert.IsNotNull(engine); Assert.AreSame(wsManager, engine.WritingSystemFactory); Assert.IsInstanceOf(typeof(UniscribeEngine), engine); wsManager.Save(); } finally { gm.Uninit(); } } }
/// <summary> /// Apply any changes to the chrp before it is used for real: currently, /// interpret the magic font names. /// </summary> /// <param name="chrp"></param> public void InterpretChrp(ref LgCharRenderProps chrp) { string fontName = MarshalEx.UShortToString(chrp.szFaceName); string realFontName; if (TryGetRealFontName(fontName, out realFontName)) { MarshalEx.StringToUShort(realFontName, chrp.szFaceName); } if (chrp.ssv != (int)FwSuperscriptVal.kssvOff) { if (chrp.ssv == (int)FwSuperscriptVal.kssvSuper) { chrp.dympOffset += chrp.dympHeight / 3; } else { chrp.dympOffset -= chrp.dympHeight / 5; } chrp.dympHeight = (chrp.dympHeight * 2) / 3; // Make sure no way it can happen twice! chrp.ssv = (int)FwSuperscriptVal.kssvOff; } }
/// <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 '<default font>' which produces a renderer suitable for the default /// font. /// </summary> public IRenderEngine get_Renderer(ILgWritingSystem ws, IVwGraphics vg) { LgCharRenderProps chrp = vg.FontCharProperties; string fontName = MarshalEx.UShortToString(chrp.szFaceName); if (fontName == "<default font>") { fontName = ws.DefaultFontName; MarshalEx.StringToUShort(fontName, chrp.szFaceName); vg.SetupGraphics(ref chrp); } Dictionary <Tuple <string, bool, bool>, Tuple <bool, IRenderEngine> > wsFontEngines; if (!m_fontEngines.TryGetValue(ws, out wsFontEngines)) { wsFontEngines = new Dictionary <Tuple <string, bool, bool>, Tuple <bool, IRenderEngine> >(); m_fontEngines[ws] = wsFontEngines; } var key = Tuple.Create(fontName, chrp.ttvBold == (int)FwTextToggleVal.kttvForceOn, chrp.ttvItalic == (int)FwTextToggleVal.kttvForceOn); Tuple <bool, IRenderEngine> fontEngine; if (!wsFontEngines.TryGetValue(key, out fontEngine)) { // We don't have a font engine stored for this combination of font face with bold and italic // so we will create the engine for it here wsFontEngines[key] = GetRenderingEngine(fontName, vg, ws); } else if (fontEngine.Item1 == ws.IsGraphiteEnabled) { // We did have a font engine for this key and IsGraphiteEnabled hasn't changed so use it. return(fontEngine.Item2); } else { // We had a font engine for this key, but IsGraphiteEnabled has changed in the ws. // Destroy all the engines associated with this ws and create one for this key. ReleaseRenderEngines(wsFontEngines.Values); wsFontEngines.Clear(); var renderingEngine = GetRenderingEngine(fontName, vg, ws); wsFontEngines[key] = renderingEngine; } return(wsFontEngines[key].Item2); }
/// <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 '<default serif>' 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); } }