/// <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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets an array of property stores, one for each paragraph in the given selection. /// </summary> /// <param name="vwsel">The selection.</param> /// <param name="vqvps">The property stores.</param> /// ------------------------------------------------------------------------------------ protected override void GetParaPropStores(IVwSelection vwsel, out IVwPropertyStore[] vqvps) { if (m_fOverrideGetParaPropStores) vqvps = new IVwPropertyStore[1]; else base.GetParaPropStores(vwsel, out vqvps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets an array of property stores, one for each paragraph in the given selection. /// </summary> /// <param name="vwsel">The selection.</param> /// <param name="vqvps">The property stores.</param> /// ------------------------------------------------------------------------------------ protected override void GetParaPropStores(IVwSelection vwsel, out IVwPropertyStore[] vqvps) { if (m_fOverrideGetParaPropStores) { vqvps = new IVwPropertyStore[1]; } else { base.GetParaPropStores(vwsel, out vqvps); } }
/// ------------------------------------------------------------------------------------ /// <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 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> /// 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); }
public void PropInfo(bool fEndPoint, int ilev, out int _hvoObj, out int _tag, out int _ihvo, out int _cpropPrevious, out IVwPropertyStore _pvps) { throw new NotImplementedException(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine if text that belongs to ttp and vps is editable. /// </summary> /// <param name="ttp"></param> /// <param name="vps"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static bool IsEditable(ITsTextProps ttp, IVwPropertyStore vps) { int nVar; int nVal = -1; if (ttp != null) nVal = ttp.GetIntPropValues((int)FwTextPropType.ktptEditable, out nVar); if (nVal == -1 && vps != null) nVal = vps.get_IntProperty((int)FwTextPropType.ktptEditable); if (nVal == (int)TptEditable.ktptNotEditable || nVal == (int)TptEditable.ktptSemiEditable) return false; return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the paragraph properties for the specified IVwSelection /// </summary> /// <param name="vwSel">The view Selection</param> /// <param name="vvps">Returned array of IVwPropertyStores in the selection</param> /// <param name="cvps">Returned count of IVwPropertyStores</param> /// ------------------------------------------------------------------------------------ public static void GetParaProps(IVwSelection vwSel, out IVwPropertyStore[] vvps, out int cvps) { vvps = null; vwSel.GetParaProps(0, ArrayPtr.Null, out cvps); using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<IVwPropertyStore>(cvps)) { vwSel.GetParaProps(cvps, arrayPtr, out cvps); vvps = MarshalEx.NativeToArray<IVwPropertyStore>(arrayPtr, cvps); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is like GetSelectionProps, except that the vvpsSoft items include all /// formatting MINUS the hard formatting in the text properties (ie, those derived by /// the view constructor and styles). /// </summary> /// <param name="vwSel">The view Selection</param> /// <param name="vttp">Returned array of ITsTextProps in the selection</param> /// <param name="vvpsSoft">Returned array of IVwPropertyStores in the selection</param> /// <param name="cttp">Returned count of properties</param> /// ------------------------------------------------------------------------------------ public static void GetHardAndSoftCharProps(IVwSelection vwSel, out ITsTextProps[] vttp, out IVwPropertyStore[] vvpsSoft, out int cttp) { vttp = null; vvpsSoft = null; GetSelectionProps(vwSel, out vttp, out vvpsSoft, out cttp); if (cttp == 0) return; using (ArrayPtr pvTtp = MarshalEx.ArrayToNative<ITsTextProps>(cttp)) { using (ArrayPtr pvVps = MarshalEx.ArrayToNative<IVwPropertyStore>(cttp)) { vwSel.GetHardAndSoftCharProps(cttp, pvTtp, pvVps, out cttp); vttp = MarshalEx.NativeToArray<ITsTextProps>(pvTtp, cttp); vvpsSoft = MarshalEx.NativeToArray<IVwPropertyStore>(pvVps, cttp); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the selection props for the specified IVwSelection /// </summary> /// <param name="vwSel">The view Selection</param> /// <param name="vttp">Returned array of ITsTextProps in the selection</param> /// <param name="vvps">Returned array of IVwPropertyStores in the selection</param> /// <param name="cttp">Returned count of TsTxtProps (this is basically just the number /// of runs in the selection)</param> /// ------------------------------------------------------------------------------------ public static void GetSelectionProps(IVwSelection vwSel, out ITsTextProps[] vttp, out IVwPropertyStore[] vvps, out int cttp) { Debug.Assert(vwSel != null); vttp = null; vvps = null; cttp = 0; if (!vwSel.IsValid) return; // The first call to GetSelectionProps gets the count of properties vwSel.GetSelectionProps(0, ArrayPtr.Null, ArrayPtr.Null, out cttp); if (cttp == 0) return; using (ArrayPtr pvTtp = MarshalEx.ArrayToNative<ITsTextProps>(cttp)) { using (ArrayPtr pvVps = MarshalEx.ArrayToNative<IVwPropertyStore>(cttp)) { vwSel.GetSelectionProps(cttp, pvTtp, pvVps, out cttp); vttp = MarshalEx.NativeToArray<ITsTextProps>(pvTtp, cttp); vvps = MarshalEx.NativeToArray< IVwPropertyStore>(pvVps, cttp); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the view selection and paragraph properties. /// </summary> /// <param name="vwsel">[out] The selection</param> /// <param name="hvoText">[out] The HVO</param> /// <param name="tagText">[out] The tag</param> /// <param name="vqvps">[out] The paragraph properties</param> /// <param name="ihvoFirst">[out] Start index of selection</param> /// <param name="ihvoLast">[out] End index of selection</param> /// <param name="vqttp">[out] The style rules</param> /// <returns>Return false if there is neither a selection nor a paragraph property. /// Otherwise return true.</returns> /// ------------------------------------------------------------------------------------ public bool GetParagraphProps(out IVwSelection vwsel, out int hvoText, out int tagText, out IVwPropertyStore[] vqvps, out int ihvoFirst, out int ihvoLast, out ITsTextProps[] vqttp) { CheckDisposed(); vwsel = null; hvoText = 0; tagText = 0; vqvps = null; ihvoFirst = 0; ihvoLast = 0; vqttp = null; return EditingHelper.GetParagraphProps(out vwsel, out hvoText, out tagText, out vqvps, out ihvoFirst, out ihvoLast, out vqttp); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Check for presence of proper paragraph properties. /// </summary> /// <param name="vwsel">[out] The selection</param> /// <param name="hvoText">[out] The HVO</param> /// <param name="tagText">[out] The tag</param> /// <param name="vqvps">[out] The paragraph properties</param> /// <param name="ihvoAnchor">[out] Start index of selection</param> /// <param name="ihvoEnd">[out] End index of selection</param> /// <returns>Return <c>false</c> if neither selection nor paragraph property. Otherwise /// return <c>true</c>.</returns> /// ------------------------------------------------------------------------------------ public bool IsParagraphProps(out IVwSelection vwsel, out int hvoText, out int tagText, out IVwPropertyStore[] vqvps, out int ihvoAnchor, out int ihvoEnd) { CheckDisposed(); vwsel = null; hvoText = 0; tagText = 0; vqvps = null; ihvoAnchor = 0; ihvoEnd = 0; return EditingHelper.IsParagraphProps(out vwsel, out hvoText, out tagText, out vqvps, out ihvoAnchor, out ihvoEnd); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets an array of property stores, one for each paragraph in the given selection. /// </summary> /// <param name="vwsel">The selection.</param> /// <param name="vqvps">The property stores.</param> /// ------------------------------------------------------------------------------------ protected override void GetParaPropStores(IVwSelection vwsel, out IVwPropertyStore[] vqvps) { if (m_fOverrideGetParaPropStores) vqvps = new IVwPropertyStore[1]; else { int cvps; SelectionHelper.GetParaProps(vwsel, out vqvps, out cvps); } }
public void PropInfo(bool fEndPoint, int ilev, out int _hvoObj, out int _tag, out int _ihvo, out int _cpropPrevious, out IVwPropertyStore _pvps) { throw new NotImplementedException(); }
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); }
public void PropInfo(bool fEndPoint, int ilev, out int _hvoObj, out int _tag, out int _ihvo, out int _cpropPrevious, out IVwPropertyStore _pvps) { _hvoObj = 0; _tag = 0; _ihvo = 0; _cpropPrevious = 0; _pvps = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the selection props for the current selection /// </summary> /// <param name="vttp">Returned array of ITsTextProps in the selection</param> /// <param name="vvps">Returned array of IVwPropertyStores in the selection</param> /// ------------------------------------------------------------------------------------ public void GetCurrSelectionProps(out ITsTextProps[] vttp, out IVwPropertyStore[] vvps) { int cttp; GetSelectionProps(Selection, out vttp, out vvps, out cttp); }