/// <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; } }
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> /// Derive the LgCharRenderProps from the DataGridViewCellStyle and FwTextBoxColumn. /// </summary> /// <remarks>Only used with Mono</remarks> private LgCharRenderProps GetRenderProps(DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { Debug.Assert(Platform.IsMono, "This method is only needed on Mono"); var renderProps = new LgCharRenderProps(); renderProps.szFaceName = new ushort[32]; // arrays should be created in constructor, but struct doesn't have one. renderProps.szFontVar = new ushort[64]; var foreColor = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; renderProps.clrFore = (uint)foreColor.ToArgb(); // The background behind the characters must be transparent for the correct // background color to show (at least for Selected). const uint transparent = 0xC0000000; // FwTextColor.kclrTransparent won't convert to uint renderProps.clrBack = transparent; renderProps.ws = col.TextBoxControl.WritingSystemCode; renderProps.fWsRtl = (byte)(col.TextBoxControl.RightToLeft == RightToLeft.Yes ? 1 : 0); var font = cellStyle.Font; renderProps.dympHeight = (int)(font.SizeInPoints * 1000.0); // size in millipoints int lim = Math.Min(renderProps.szFaceName.Length, font.Name.Length); for (var i = 0; i < lim; ++i) { renderProps.szFaceName[i] = (ushort)font.Name[i]; } // The rest of these values are set to default values. renderProps.clrUnder = 0xFFFFFF; renderProps.nDirDepth = 0; renderProps.ssv = 0; renderProps.unt = 0; renderProps.ttvBold = 0; renderProps.ttvItalic = 0; return(renderProps); }
/// ----------------------------------------------------------------------------------- /// <summary>Member FwSetupGraphics</summary> /// <param name='_chrp'>_chrp</param> /// ----------------------------------------------------------------------------------- public void FwSetupGraphics(ref LgCharRenderProps _chrp) { //LgCharRenderProps _chrp = __chrp; if (m_font == null || m_charProps.ttvBold != _chrp.ttvBold || m_charProps.ttvItalic != _chrp.ttvItalic || !m_charProps.szFaceName.Equals(_chrp.szFaceName) || m_charProps.dympHeight != _chrp.dympHeight) { // Remember the font we switch to. m_charProps = _chrp; int style = 0; if (_chrp.ttvBold != (int)FwKernelLib.FwTextToggleVal.kttvOff) { style |= (int)FontStyle.Bold; } if (_chrp.ttvItalic != (int)FwKernelLib.FwTextToggleVal.kttvOff) { style |= (int)FontStyle.Italic; } float size = _chrp.dympHeight / 1000; char[] fontFace = new char[_chrp.szFaceName.Length]; _chrp.szFaceName.CopyTo(fontFace, 0); m_font = new Font(new string(fontFace), size, (FontStyle)style, GraphicsUnit.Point); } set_FwForeColor(ChangeFromBGRtoRGB(_chrp.clrFore)); set_FwBackColor(ChangeFromBGRtoRGB(_chrp.clrBack)); }
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(); }
/// -------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="T:HoldDummyGraphics"/> class. /// </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> /// <param name="ctrl">The parent control</param> /// -------------------------------------------------------------------------------- public HoldDummyGraphics(string fontName, bool fBold, bool fItalic, Control ctrl) { // Make a VwGraphics and initialize it. IVwGraphicsWin32 vwGraphics32 = VwGraphicsWin32Class.Create(); m_vwGraphics = vwGraphics32; m_graphics = ctrl.CreateGraphics(); m_hdc = m_graphics.GetHdc(); ((IVwGraphicsWin32)m_vwGraphics).Initialize(m_hdc); // Select our font into it. var chrp = new LgCharRenderProps(); chrp.szFaceName = new ushort[32]; for (int ich = 0; ich < fontName.Length; ++ich) { if (ich < 32) { chrp.szFaceName[ich] = fontName[ich]; } } if (fontName.Length < 32) { chrp.szFaceName[fontName.Length] = 0; } else { chrp.szFaceName[31] = 0; } chrp.ttvBold = (int)(fBold ? FwTextToggleVal.kttvForceOn : FwTextToggleVal.kttvOff); chrp.ttvItalic = (int)(fItalic ? FwTextToggleVal.kttvForceOn : FwTextToggleVal.kttvOff); m_vwGraphics.SetupGraphics(ref chrp); }
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 InterpretChrp(ref LgCharRenderProps chrp) { if (AssembledStyles.FaceNameFromChrp(chrp) == AssembledStyles.DefaultFontName) { AssembledStyles.SetFaceName(ref chrp, "MockFont"); } }
/// <summary> /// Gets the character render properties for the given style name and writing system. /// </summary> /// <param name="styleName">The style name.</param> /// <param name="styleSheet">The stylesheet.</param> /// <param name="hvoWs">The HVO of the WS.</param> /// <param name="writingSystemFactory">The writing system factory.</param> /// <returns>The character render properties.</returns> public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet, int hvoWs, ILgWritingSystemFactory writingSystemFactory) { if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs))) { try { throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent. Call an expert (JohnT)"); } catch (ArgumentException e) { Logger.WriteError(e); Debug.Fail("This is a hard-to-reproduce scenario (TE-6891) where writing system and factory are inconsistent. Call an expert (JohnT) while you have this Assert active!"); hvoWs = writingSystemFactory.UserWs; } } IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = styleSheet; vwps.WritingSystemFactory = writingSystemFactory; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs); ITsTextProps ttp = ttpBldr.GetTextProps(); LgCharRenderProps chrps = vwps.get_ChrpFor(ttp); IWritingSystem ws = writingSystemFactory.get_EngineOrNull(hvoWs); ws.InterpretChrp(ref chrps); return(chrps); }
public void GetCharProps(int ich, out LgCharRenderProps chrp, out int ichMin, out int ichLim) { int runIndex = RunContaining(ich); MapRun run = Runs[runIndex]; ichMin = run.RenderStart; ichLim = ichMin + run.RenderLength; chrp = run.Chrp; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find the height of the font used for the given style name and writing system /// </summary> /// <param name="styleName">Style name</param> /// <param name="styleSheet">The stylesheet where the style is defined</param> /// <param name="hvoWs">Id of the writing system</param> /// <param name="writingSystemFactory"></param> /// <returns>Height of the font (not counting the descender) for the given style in /// the given writing system</returns> /// ------------------------------------------------------------------------------------ public static int GetFontHeightForStyle(string styleName, IVwStylesheet styleSheet, int hvoWs, ILgWritingSystemFactory writingSystemFactory) { // For testing, if there is no writing system set, just return 0 for the height. if (hvoWs == -1) { return(0); } LgCharRenderProps chrps = GetChrpForStyle(styleName, styleSheet, hvoWs, writingSystemFactory); return(chrps.dympHeight); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up a Chrp consistent with the current style sheet /// </summary> /// ------------------------------------------------------------------------------------ protected void MakeCharProps() { LangProject lp = m_Parent.LangProj; // Make a text property with the named style. ITsPropsBldr tsPropsBuilder = TsPropsBldrClass.Create(); tsPropsBuilder.SetStrPropValue((int)VwStyleProperty.kspNamedStyle, m_FieldSpec.Style); tsPropsBuilder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_ws); ITsTextProps tsTextProps = tsPropsBuilder.GetTextProps(); // Fill out the LgCharRenderProps. ILgWritingSystemFactory lgEncFactory; IVwPropertyStore vwPropertyStore = VwPropertyStoreClass.Create(); IVwStylesheet vwStylesheet = DeStyleSheet; if (vwStylesheet != null) { vwPropertyStore.Stylesheet = vwStylesheet; } if (lp != null) { lgEncFactory = lp.Cache.LanguageWritingSystemFactoryAccessor; } else { // Get default registry-based factory. lgEncFactory = LgWritingSystemFactoryClass.Create(); } Debug.Assert(lgEncFactory != null); vwPropertyStore.WritingSystemFactory = lgEncFactory; m_CharacterRenderingProps = vwPropertyStore.get_ChrpFor(tsTextProps); IWritingSystem writingSystem = lgEncFactory.get_EngineOrNull(m_CharacterRenderingProps.ws); Debug.Assert(writingSystem != null); writingSystem.InterpretChrp(ref m_CharacterRenderingProps); // For our purposes here, we don't want transparent backgrounds. if ((int)m_CharacterRenderingProps.clrBack == (int)FwTextColor.kclrTransparent) { m_CharacterRenderingProps.clrBack = (uint)SystemColors.Window.ToArgb(); } // Make a brush for the background. m_BackgroundBrush = new SolidBrush(Color.FromArgb((int)m_CharacterRenderingProps.clrBack)); }
/// <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); }
public void TestOverrideFontForWritingSystem_ForStyleWithNullProps() { TestFwStylesheet stylesheet = new TestFwStylesheet(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, null); ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create(); try { wsf.BypassInstall = true; IWritingSystem ws = wsf.get_Engine("de"); int hvoGermanWs = ws.WritingSystem; Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an hvo for the German WS"); // Array of 1 struct, contains writing system and font size to override List <FontOverride> fontOverrides = new List <FontOverride>(1); FontOverride aFontOverride; aFontOverride.writingSystem = hvoGermanWs; aFontOverride.fontSize = 48; fontOverrides.Add(aFontOverride); stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides); //check results IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = stylesheet; vwps.WritingSystemFactory = wsf; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs); ITsTextProps ttp = ttpBldr.GetTextProps(); LgCharRenderProps chrps = vwps.get_ChrpFor(ttp); ws.InterpretChrp(ref chrps); Assert.AreEqual(48, chrps.dympHeight / 1000); } finally { wsf.Shutdown(); } }
/// <summary> /// Find the font that is used for the given style name and writing system. /// </summary> /// <param name="styleName">The style name.</param> /// <param name="styleSheet">The stylesheet.</param> /// <param name="hvoWs">The HVO of the WS.</param> /// <param name="writingSystemFactory">The writing system factory.</param> /// <returns>The font.</returns> public static Font GetFontForStyle(string styleName, IVwStylesheet styleSheet, int hvoWs, ILgWritingSystemFactory writingSystemFactory) { LgCharRenderProps chrps = GetChrpForStyle(styleName, styleSheet, hvoWs, writingSystemFactory); int dympHeight = chrps.dympHeight; StringBuilder bldr = new StringBuilder(chrps.szFaceName.Length); for (int i = 0; i < chrps.szFaceName.Length; i++) { ushort ch = chrps.szFaceName[i]; if (ch == 0) { break; // null termination } bldr.Append(Convert.ToChar(ch)); } return(new Font(bldr.ToString(), (float)(dympHeight / 1000.0f))); }
/// <summary> /// Gets the character render properties for the given style name and writing system. /// </summary> /// <param name="styleName">The style name.</param> /// <param name="styleSheet">The stylesheet.</param> /// <param name="hvoWs">The HVO of the WS.</param> /// <param name="writingSystemFactory">The writing system factory.</param> /// <returns>The character render properties.</returns> public static LgCharRenderProps GetChrpForStyle(string styleName, IVwStylesheet styleSheet, int hvoWs, ILgWritingSystemFactory writingSystemFactory) { if (string.IsNullOrEmpty(writingSystemFactory.GetStrFromWs(hvoWs))) { try { //You may have forgotten to set the WritingSystemFactory in a recently added custom control? throw new ArgumentException("This is a hard-to-reproduce scenario (TE-6891) where writing system (" + hvoWs + ") and factory are inconsistent."); } catch (ArgumentException e) { Logger.WriteError(e); var msg = e.Message + " If we aren't called from a Widget, " + "call an expert (JohnT) while you have this Assert active!"; Debug.Fail(msg); hvoWs = writingSystemFactory.UserWs; } } IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = styleSheet; vwps.WritingSystemFactory = writingSystemFactory; ITsPropsBldr ttpBldr = TsStringUtils.MakePropsBldr(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoWs); ITsTextProps ttp = ttpBldr.GetTextProps(); LgCharRenderProps chrps = vwps.get_ChrpFor(ttp); ILgWritingSystem ws = writingSystemFactory.get_EngineOrNull(hvoWs); ws.InterpretChrp(ref chrps); return(chrps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up a Chrp consistent with the current style sheet /// </summary> /// ------------------------------------------------------------------------------------ protected void MakeCharProps() { LangProject lp = m_Parent.LangProj; // Make a text property with the named style. ITsPropsBldr tsPropsBuilder = TsPropsBldrClass.Create(); tsPropsBuilder.SetStrPropValue((int)VwStyleProperty.kspNamedStyle, m_FieldSpec.Style); tsPropsBuilder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_ws); ITsTextProps tsTextProps = tsPropsBuilder.GetTextProps(); // Fill out the LgCharRenderProps. ILgWritingSystemFactory lgEncFactory; IVwPropertyStore vwPropertyStore = VwPropertyStoreClass.Create(); IVwStylesheet vwStylesheet = DeStyleSheet; if (vwStylesheet != null) { vwPropertyStore.Stylesheet = vwStylesheet; } if (lp != null) { lgEncFactory = lp.Cache.LanguageWritingSystemFactoryAccessor; } else { // Get default registry-based factory. lgEncFactory = LgWritingSystemFactoryClass.Create(); } Debug.Assert(lgEncFactory != null); vwPropertyStore.WritingSystemFactory = lgEncFactory; m_CharacterRenderingProps = vwPropertyStore.get_ChrpFor(tsTextProps); IWritingSystem writingSystem = lgEncFactory.get_EngineOrNull(m_CharacterRenderingProps.ws); Debug.Assert(writingSystem != null); writingSystem.InterpretChrp(ref m_CharacterRenderingProps); // For our purposes here, we don't want transparent backgrounds. if ((int)m_CharacterRenderingProps.clrBack == (int)FwTextColor.kclrTransparent) m_CharacterRenderingProps.clrBack = (uint)SystemColors.Window.ToArgb(); // Make a brush for the background. m_BackgroundBrush = new SolidBrush(Color.FromArgb((int)m_CharacterRenderingProps.clrBack)); }
public void SetupGraphics(ref LgCharRenderProps _chrp) { }
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(GraphiteEngine), engine); wsManager.Save(); } finally { gm.Uninit(); } } }
public void TestOverrideFontsForWritingSystems_ForStyleWithProps() { var stylesheet = new TestFwStylesheet(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 23000); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, propsBldr.GetTextProps()); var wsf = new PalasoWritingSystemManager(); ILgWritingSystem wsIngles = wsf.get_Engine("en"); int hvoInglesWs = wsIngles.Handle; Assert.IsTrue(hvoInglesWs > 0, "Should have gotten an HVO for the English WS"); ILgWritingSystem wsFrench = wsf.get_Engine("fr"); int hvoFrenchWs = wsFrench.Handle; Assert.IsTrue(hvoFrenchWs > 0, "Should have gotten an HVO for the French WS"); ILgWritingSystem wsGerman = wsf.get_Engine("de"); int hvoGermanWs = wsGerman.Handle; Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an HVO for the German WS"); Assert.IsTrue(hvoFrenchWs != hvoGermanWs, "Should have gotten different HVOs for each WS"); Assert.IsTrue(hvoInglesWs != hvoGermanWs, "Should have gotten different HVOs for each WS"); Assert.IsTrue(hvoFrenchWs != hvoInglesWs, "Should have gotten different HVOs for each WS"); // Array of structs, containing writing systems and font sizes to override. var fontOverrides = new List <FontOverride>(2); FontOverride aFontOverride; aFontOverride.writingSystem = hvoInglesWs; aFontOverride.fontSize = 34; fontOverrides.Add(aFontOverride); aFontOverride.writingSystem = hvoGermanWs; aFontOverride.fontSize = 48; fontOverrides.Add(aFontOverride); stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides); //check results IVwPropertyStore vwps = VwPropertyStoreClass.Create(); vwps.Stylesheet = stylesheet; vwps.WritingSystemFactory = wsf; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoFrenchWs); ITsTextProps ttpFrench = ttpBldr.GetTextProps(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs); ITsTextProps ttpGerman = ttpBldr.GetTextProps(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoInglesWs); ITsTextProps ttpIngles = ttpBldr.GetTextProps(); LgCharRenderProps chrpsFrench = vwps.get_ChrpFor(ttpFrench); LgCharRenderProps chrpsGerman = vwps.get_ChrpFor(ttpGerman); LgCharRenderProps chrpsIngles = vwps.get_ChrpFor(ttpIngles); wsFrench.InterpretChrp(ref chrpsFrench); wsGerman.InterpretChrp(ref chrpsGerman); wsIngles.InterpretChrp(ref chrpsIngles); Assert.AreEqual(23, chrpsFrench.dympHeight / 1000); Assert.AreEqual(34, chrpsIngles.dympHeight / 1000); Assert.AreEqual(48, chrpsGerman.dympHeight / 1000); }
protected void ProcessSetupGraphics(IEnumerable<string> arguments) { Debug.Assert(arguments.Count() == 14); LgCharRenderProps props = new LgCharRenderProps(); props.clrFore = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.clrBack = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.clrUnder = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.dympOffset = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ws = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.fWsRtl = byte.Parse(arguments.First()); arguments = arguments.Skip(1); props.nDirDepth = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ssv = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.unt = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ttvBold = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ttvItalic = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.dympHeight = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.szFaceName = new ushort[32]; for (int ich = 0; ich < arguments.First().Length; ++ich) { props.szFaceName[ich] = (ushort)arguments.First()[ich]; } if (arguments.First().Length < 32) props.szFaceName[arguments.First().Length] = 0; else props.szFaceName[31] = 0; arguments = arguments.Skip(1); props.szFontVar = new ushort[64]; for (int ich = 0; ich < arguments.First().Length; ++ich) { props.szFontVar[ich] = (ushort)arguments.First()[ich]; } if (arguments.First().Length < 64) props.szFontVar[arguments.First().Length] = 0; else props.szFontVar[63] = 0; arguments = arguments.Skip(1); m_vwGraphics32.SetupGraphics(ref props); // all argument should be used up. Debug.Assert(arguments.Count() == 0); }
public void InterpretChrp(ref LgCharRenderProps chrp) { if (AssembledStyles.FaceNameFromChrp(chrp) == AssembledStyles.DefaultFontName) AssembledStyles.SetFaceName(ref chrp, "MockFont"); }
public IRenderEngine get_RendererFromChrp(ref LgCharRenderProps _chrp) { throw new NotImplementedException(); }
/// <summary> /// Intended for use only by AssembledStylesCache to make derived styles. /// If inheritedOnly is true, only those properties are copied which should be inherited by /// nested boxes. /// </summary> internal AssembledStyles(AssembledStyles basedOn, bool inheritedOnly) { m_styleCache = basedOn.m_styleCache; // all derived styles share it m_chrp = basedOn.m_chrp; m_lineHeight = basedOn.m_lineHeight; m_firstLineIndent = basedOn.m_firstLineIndent; m_styleName = basedOn.m_styleName; RightToLeft = basedOn.RightToLeft; if (inheritedOnly) { SetNonInheritedDefaults(); } else { // copy everything else, too. m_paraAlignment = basedOn.m_paraAlignment; m_borderColor = basedOn.m_borderColor; m_borders = basedOn.m_borders; m_margins = basedOn.m_margins; m_pads = basedOn.m_pads; m_weight = basedOn.m_weight; } }
/// <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); } }
/// <summary> /// Get the renderer for a particular Chrp /// </summary> public IRenderEngine get_RendererFromChrp(IVwGraphics vg, ref LgCharRenderProps chrp) { vg.SetupGraphics(ref chrp); return(get_Renderer(chrp.ws, vg)); }
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(); }
/// ----------------------------------------------------------------------------------- /// <summary>Member FwSetupGraphics</summary> /// <param name='_chrp'>_chrp</param> /// ----------------------------------------------------------------------------------- public void FwSetupGraphics(ref LgCharRenderProps _chrp) { //LgCharRenderProps _chrp = __chrp; if (m_font == null || m_charProps.ttvBold != _chrp.ttvBold || m_charProps.ttvItalic != _chrp.ttvItalic || !m_charProps.szFaceName.Equals(_chrp.szFaceName) || m_charProps.dympHeight != _chrp.dympHeight) { // Remember the font we switch to. m_charProps = _chrp; int style = 0; if (_chrp.ttvBold != (int)FwKernelLib.FwTextToggleVal.kttvOff) style |= (int)FontStyle.Bold; if (_chrp.ttvItalic != (int)FwKernelLib.FwTextToggleVal.kttvOff) style |= (int)FontStyle.Italic; float size = _chrp.dympHeight / 1000; char[] fontFace = new char[_chrp.szFaceName.Length]; _chrp.szFaceName.CopyTo(fontFace, 0); m_font = new Font(new string(fontFace), size, (FontStyle)style, GraphicsUnit.Point); } set_FwForeColor(ChangeFromBGRtoRGB(_chrp.clrFore)); set_FwBackColor(ChangeFromBGRtoRGB(_chrp.clrBack)); }
/// <summary> /// Get the renderer for a particular Chrp /// </summary> public IRenderEngine get_RendererFromChrp(IVwGraphics vg, ref LgCharRenderProps chrp) { vg.SetupGraphics(ref chrp); return get_Renderer(chrp.ws, vg); }
public static string FaceNameFromChrp(LgCharRenderProps chrp) { return MarshalEx.UShortToString(chrp.szFaceName).Trim(); }
/// -------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="T:HoldDummyGraphics"/> class. /// </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> /// <param name="ctrl">The parent control</param> /// -------------------------------------------------------------------------------- public HoldDummyGraphics(string fontName, bool fBold, bool fItalic, Control ctrl) { // Make a VwGraphics and initialize it. IVwGraphicsWin32 vwGraphics32 = VwGraphicsWin32Class.Create(); m_vwGraphics = vwGraphics32; m_graphics = ctrl.CreateGraphics(); m_hdc = m_graphics.GetHdc(); ((IVwGraphicsWin32)m_vwGraphics).Initialize(m_hdc); // Select our font into it. var chrp = new LgCharRenderProps(); chrp.szFaceName = new ushort[32]; for (int ich = 0; ich < fontName.Length; ++ich) { if (ich < 32) chrp.szFaceName[ich] = fontName[ich]; } if (fontName.Length < 32) chrp.szFaceName[fontName.Length] = 0; else chrp.szFaceName[31] = 0; chrp.ttvBold = (int)(fBold ? FwTextToggleVal.kttvForceOn : FwTextToggleVal.kttvOff); chrp.ttvItalic = (int)(fItalic ? FwTextToggleVal.kttvForceOn : FwTextToggleVal.kttvOff); m_vwGraphics.SetupGraphics(ref chrp); }
public void InterpretChrp(ref LgCharRenderProps chrp) { throw new NotImplementedException(); }
private LgCharRenderProps GetRenderProps(DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { var renderProps = new LgCharRenderProps(); renderProps.szFaceName = new ushort[32]; // arrays should be created in constructor, but struct doesn't have one. renderProps.szFontVar = new ushort[64]; var foreColor = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; renderProps.clrFore = (uint)foreColor.ToArgb(); // The background behind the characters must be transparent for the correct // background color to show (at least for Selected). const uint transparent = 0xC0000000; // FwTextColor.kclrTransparent won't convert to uint renderProps.clrBack = transparent; renderProps.ws = col.TextBoxControl.WritingSystemCode; renderProps.fWsRtl = (byte)(col.TextBoxControl.RightToLeft == RightToLeft.Yes ? 1 : 0); var font = cellStyle.Font; renderProps.dympHeight = (int)(font.SizeInPoints * 1000.0); // size in millipoints int lim = Math.Min(renderProps.szFaceName.Length, font.Name.Length); for (var i = 0; i < lim; ++i) renderProps.szFaceName[i] = (ushort)font.Name[i]; // The rest of these values are set to default values. renderProps.clrUnder = 0xFFFFFF; renderProps.nDirDepth = 0; renderProps.ssv = 0; renderProps.unt = 0; renderProps.ttvBold = 0; renderProps.ttvItalic = 0; return renderProps; }
public void InterpretChrp(ref LgCharRenderProps _chrp) { }
/// <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> /// /// </summary> /// <param name="_chrp"></param> /// -------------------------------------------------------------------------------- public void SetupGraphics(ref LgCharRenderProps _chrp) { CheckDisposed(); // TODO: Add DummyGraphics.SetupGraphics implementation }
protected void ProcessSetupGraphics(IEnumerable <string> arguments) { Debug.Assert(arguments.Count() == 14); LgCharRenderProps props = new LgCharRenderProps(); props.clrFore = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.clrBack = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.clrUnder = uint.Parse(arguments.First()); arguments = arguments.Skip(1); props.dympOffset = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ws = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.fWsRtl = byte.Parse(arguments.First()); arguments = arguments.Skip(1); props.nDirDepth = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ssv = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.unt = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ttvBold = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.ttvItalic = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.dympHeight = int.Parse(arguments.First()); arguments = arguments.Skip(1); props.szFaceName = new ushort[32]; for (int ich = 0; ich < arguments.First().Length; ++ich) { props.szFaceName[ich] = (ushort)arguments.First()[ich]; } if (arguments.First().Length < 32) { props.szFaceName[arguments.First().Length] = 0; } else { props.szFaceName[31] = 0; } arguments = arguments.Skip(1); props.szFontVar = new ushort[64]; for (int ich = 0; ich < arguments.First().Length; ++ich) { props.szFontVar[ich] = (ushort)arguments.First()[ich]; } if (arguments.First().Length < 64) { props.szFontVar[arguments.First().Length] = 0; } else { props.szFontVar[63] = 0; } arguments = arguments.Skip(1); m_vwGraphics32.SetupGraphics(ref props); // all argument should be used up. Debug.Assert(arguments.Count() == 0); }
internal static void SetFaceName(ref LgCharRenderProps chrp, string fontName) { chrp.szFaceName = new ushort[32]; MarshalEx.StringToUShort(fontName, chrp.szFaceName); }