public void TsStringsDifferByRunBreaks() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 1); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "S1"); ITsTextProps propsS1 = propsBldr.GetTextProps(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "S2"); ITsTextProps propsS2 = propsBldr.GetTextProps(); // Create TsString #1: "Weird/Test/Dude" strBldr.Replace(0, 0, "Dude", propsS1); strBldr.Replace(0, 0, "Test", propsS2); strBldr.Replace(0, 0, "Weird", propsS1); ITsString tssExpected = strBldr.GetString(); // Create TsString #2: "Weird/Tes/tDude" strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "tDude", propsS1); strBldr.Replace(0, 0, "Tes", propsS2); strBldr.Replace(0, 0, "Weird", propsS1); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( string.Format("TsStrings differ in length of run 2.{0}\tExpected length=4, but was length=3.{0}\t" + "expected run:<Test>{0}\t" + " but was:<Tes>", Environment.NewLine), s, "Got incorrect explanation of difference"); }
public void CreateFromStringRep_BT_withBrackets() { CheckDisposed(); SetupBackTrans(); // Setup expected results for the footnote ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Text in <brackets>", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); // ... and now set up the expected results for the back translations of the footnote. m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsEs, "Spanish BT in <brackets>", null); m_scrInMemoryCache.AddRunToMockedTrans(m_trans, m_wsDe, "German BT in <brackets>", null); // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Text in <brackets></RUN>" + @"<TRANS WS='es'><RUN WS='es'>Spanish BT in <brackets></RUN></TRANS>" + @"<TRANS WS='de'><RUN WS='de'>German BT in <brackets></RUN></TRANS></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void CreateFromStringRep_twoCharStylePara() { CheckDisposed(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis"); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Test Text", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); bldr.Replace(bldr.Length, bldr.Length, "No char style", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Quoted Text"); bldr.Replace(bldr.Length, bldr.Length, "Ahh!!!!!!", propsBldr.GetTextProps()); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" + "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void PropsDifferByStrProps() { // test of different str prop: named style ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "your style"); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in ktptNamedStyle property. " + "Expected <my style>, but was <your style>.", s); // test of different str prop: named style tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565754); // int prop, same for both tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "my font"); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "your font"); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in strProp type 1. " + "Expected <my font>, but was <your font>.", s); }
public void CreateFromStringRep_twoCharStylePara() { ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasis"); ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Test Text", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); bldr.Replace(bldr.Length, bldr.Length, "No char style", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Quoted Text"); bldr.Replace(bldr.Length, bldr.Length, "Ahh!!!!!!", propsBldr.GetTextProps()); m_footnotePara.Contents = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" + "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void CreateFromStringRep_BT_withBrackets() { SetupBackTrans(); // Setup expected results for the footnote ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_vernWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); bldr.Replace(0, 0, "Text in <brackets>", propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); m_footnotePara.Contents = bldr.GetString(); // ... and now set up the expected results for the back translations of the footnote. AddRunToMockedTrans(m_trans, m_wsEs, "Spanish BT in <brackets>", null); AddRunToMockedTrans(m_trans, m_wsDe, "German BT in <brackets>", null); // Define text representation and create a footnote from it. string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Text in <brackets></RUN>" + @"<TRANS WS='de'><RUN WS='de'>German BT in <brackets></RUN></TRANS>" + @"<TRANS WS='es'><RUN WS='es'>Spanish BT in <brackets></RUN></TRANS></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
public void PropsDifferByCount() { // test of different string property counts ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); //note: due to design in PropsAreEqual(), we will get the count message // only when all the str props in the first ttp match in the second ttp, and the // second ttp has additional str props tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "my font"); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in count of strProps. Expected <1>, but was <2>.", s); // test of different int property counts tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, 123); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvDefault, 10); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in count of intProps. Expected <1>, but was <2>.", s); }
public void TestTsStringWrapperRoundTrip(string str1, string namedStyle1, string str2, string namedStyle2) { var wsFact = new PalasoWritingSystemManager(); ITsStrBldr bldr = TsStrBldrClass.Create(); ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); try { wsFact.get_Engine("en"); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, wsFact.GetWsFromStr("en")); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, namedStyle1); bldr.Replace(bldr.Length, bldr.Length, str1, ttpBldr.GetTextProps()); if (namedStyle2 != null && str2 != null) { ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, namedStyle2); bldr.Replace(bldr.Length, bldr.Length, str2, ttpBldr.GetTextProps()); } var tsString1 = bldr.GetString(); var strWrapper = new TsStringWrapper(tsString1, wsFact); var tsString2 = strWrapper.GetTsString(wsFact); Assert.AreEqual(tsString1.Text, tsString2.Text); } finally { Marshal.ReleaseComObject(ttpBldr); Marshal.ReleaseComObject(bldr); } }
public AffixRuleFormulaVc(LcmCache cache, PropertyTable propertyTable) : base(cache, propertyTable) { ITsPropsBldr tpb = TsStringUtils.MakePropsBldr(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_headerProps = tpb.GetTextProps(); tpb = TsStringUtils.MakePropsBldr(); tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 24000); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Charis SIL"); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_arrowProps = tpb.GetTextProps(); tpb = TsStringUtils.MakePropsBldr(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); m_ctxtProps = tpb.GetTextProps(); tpb = TsStringUtils.MakePropsBldr(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); m_indexProps = tpb.GetTextProps(); tpb = TsStringUtils.MakePropsBldr(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); m_resultProps = tpb.GetTextProps(); var userWs = m_cache.DefaultUserWs; m_inputStr = TsStringUtils.MakeString(MEStrings.ksAffixRuleInput, userWs); m_indexStr = TsStringUtils.MakeString(MEStrings.ksAffixRuleIndex, userWs); m_resultStr = TsStringUtils.MakeString(MEStrings.ksAffixRuleResult, userWs); m_doubleArrow = TsStringUtils.MakeString("\u21d2", userWs); m_space = TsStringUtils.MakeString(" ", userWs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up some dummy styles for testing purposes /// </summary> /// ------------------------------------------------------------------------------------ public override void FixtureSetup() { base.FixtureSetup(); m_stylesheet = new TestFwStylesheet(); m_wsManager = new PalasoWritingSystemManager(); // English IWritingSystem enWs; m_wsManager.GetOrSet("en", out enWs); m_hvoEnglishWs = enWs.Handle; Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS"); // German IWritingSystem deWs; m_wsManager.GetOrSet("de", out deWs); m_hvoGermanWs = deWs.Handle; Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS"); Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs"); // Create a couple of styles int hvoStyle = m_stylesheet.MakeNewStyle(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial"); m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false, propsBldr.GetTextProps()); hvoStyle = m_stylesheet.MakeNewStyle(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman"); m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false, propsBldr.GetTextProps()); // Override the font size for each writing system and each style. List <FontOverride> fontOverrides = new List <FontOverride>(2); FontOverride fo; fo.writingSystem = m_hvoEnglishWs; fo.fontSize = 21; fontOverrides.Add(fo); fo.writingSystem = m_hvoGermanWs; fo.fontSize = 13; fontOverrides.Add(fo); m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides); fontOverrides.Clear(); fo.writingSystem = m_hvoEnglishWs; fo.fontSize = 20; fontOverrides.Add(fo); fo.writingSystem = m_hvoGermanWs; fo.fontSize = 56; fontOverrides.Add(fo); m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides); }
public void SetupStyles() { m_stylesheet = new TestFwStylesheet(); m_wsf = LgWritingSystemFactoryClass.Create(); m_wsf.BypassInstall = true; // German IWritingSystem wsGerman = m_wsf.get_Engine("de"); m_hvoGermanWs = wsGerman.WritingSystem; Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS"); // English IWritingSystem wsEnglish = m_wsf.get_Engine("en"); m_hvoEnglishWs = wsEnglish.WritingSystem; Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS"); Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs"); // Create a couple of styles int hvoStyle = m_stylesheet.MakeNewStyle(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial"); m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false, propsBldr.GetTextProps()); hvoStyle = m_stylesheet.MakeNewStyle(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman"); m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false, propsBldr.GetTextProps()); // Override the font size for each writing system and each style. List <FontOverride> fontOverrides = new List <FontOverride>(2); FontOverride fo; fo.writingSystem = m_hvoGermanWs; fo.fontSize = 13; fontOverrides.Add(fo); fo.writingSystem = m_hvoEnglishWs; fo.fontSize = 21; fontOverrides.Add(fo); m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides); fontOverrides.Clear(); fo.writingSystem = m_hvoGermanWs; fo.fontSize = 56; fontOverrides.Add(fo); fo.writingSystem = m_hvoEnglishWs; fo.fontSize = 20; fontOverrides.Add(fo); m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides); }
public MetaRuleFormulaVc(FdoCache cache, XCore.Mediator mediator) : base(cache, mediator) { ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); m_inputCtxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); m_resultCtxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_colHeaderProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalLeft); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_rowHeaderProps = tpb.GetTextProps(); var tsf = m_cache.TsStrFactory; var userWs = m_cache.DefaultUserWs; m_inputStr = tsf.MakeString(MEStrings.ksMetaRuleInput, userWs); m_resultStr = tsf.MakeString(MEStrings.ksMetaRuleResult, userWs); m_leftEnvStr = tsf.MakeString(MEStrings.ksMetaRuleLeftEnv, userWs); m_rightEnvStr = tsf.MakeString(MEStrings.ksMetaRuleRightEnv, userWs); m_switchStr = tsf.MakeString(MEStrings.ksMetaRuleSwitch, userWs); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Static method to create a new structured text. It creates an StText object owned by /// hvoOwner in property tag, then creates an StTxtPara owned by the new StText. It /// sets the contents of the paragraph to be an empty string in the specified writing system, /// and Normal paragraph style. /// </summary> /// ENHANCE JohnT: probably we will identify styles by something other than name. /// REVIEW JohnT(TomB): Are we supposed to be supplying a style name rather than just /// using "Normal"? /// /// <param name="cache">FieldWorks database access</param> /// <param name="hvoOwner">id of object to own the new StText</param> /// <param name="propTag">property (field) type of the new StText</param> /// <param name="ws">language writing system of empty paragraph</param> /// <returns>HVO of the newly created StText object</returns> /// ----------------------------------------------------------------------------------- public static int MakeEmptyStText(FdoCache cache, int hvoOwner, int propTag, int ws) { // REVIEW TomB: Lastparm should really be null if Randy changes CreateObject. // Response from RandyR: I changed CreateObject. Null should work for // everything now. // Most of this code could be moved into the FDO objects, if desired. int hvoStText = cache.CreateObject(StText.kclsidStText, hvoOwner, propTag, 0); int hvoPara = cache.CreateObject(StTxtPara.kclsidStTxtPara, hvoStText, (int)StText.StTextTags.kflidParagraphs, 0); // Set the style of the paragraph to Normal ITsTextProps ttpNormal; ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleNames.ksNormal); ttpNormal = tsPropsBldr.GetTextProps(); cache.MainCacheAccessor.SetUnknown(hvoPara, (int)StPara.StParaTags.kflidStyleRules, ttpNormal); // Set its contents to an empty string in the right writing system. ITsStrFactory tsFactory = TsStrFactoryClass.Create(); cache.SetTsStringProperty(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, tsFactory.MakeStringRgch("", 0, ws)); return(hvoStText); }
public RegRuleFormulaVc(FdoCache cache, XCore.Mediator mediator) : base(cache, mediator) { ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); m_ctxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20000); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, 2000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint, 2000); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Arial"); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_charProps = tpb.GetTextProps(); m_arrow = m_cache.MakeUserTss("\u2192"); m_slash = m_cache.MakeUserTss("/"); m_underscore = m_cache.MakeUserTss("__"); }
public void MultiStringAlt() { ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.IsNotNull(tsStringNew); Assert.AreEqual(0, tsStringNew.Length); ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); ITsStrBldr strBldr = TsStringUtils.MakeStrBldr(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse"); strBldr.Replace(0, 0, "Test", propsBldr.GetTextProps()); ITsString tsString = strBldr.GetString(); m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.AreEqual(tsString, tsStringNew); strBldr.Replace(0, 0, "SecondTest", propsBldr.GetTextProps()); tsString = strBldr.GetString(); m_IVwCacheDa.CacheStringAlt(1117, 2227, 7, tsString); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.AreEqual(tsString, tsStringNew); tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 8); Assert.IsNotNull(tsStringNew); Assert.AreEqual(0, tsStringNew.Length); }
public void StringProp() { CheckDisposed(); // Test StringProp ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228); Assert.AreEqual(0, tsStringNew.Length); Assert.IsFalse(m_ISilDataAccess.IsDirty()); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); ITsStrBldr strBldr = TsStrBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse"); strBldr.Replace(0, 0, "StringPropTest", propsBldr.GetTextProps()); ITsString tsString = strBldr.GetString(); m_ISilDataAccess.SetString(1118, 2228, tsString); tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228); Assert.AreEqual(tsString, tsStringNew); Assert.IsTrue(m_ISilDataAccess.IsDirty()); strBldr.Replace(0, 0, "Second", propsBldr.GetTextProps()); tsString = strBldr.GetString(); m_ISilDataAccess.SetString(1118, 2228, tsString); tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228); Assert.AreEqual(tsString, tsStringNew); Assert.IsTrue(m_ISilDataAccess.IsDirty()); CheckProp(1118, 2228, tsString, CellarModuleDefns.kcptString); }
public void StringPropWrongLengthFmtTest() { CheckDisposed(); // Set class first, or it will throw an exception. int hvo = 1; uint clid = SilDataAccess.MetaDataCache.GetClassId("PhEnvironment"); SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clid); int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("PhEnvironment", "StringRepresentation", false); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse"); ITsStrBldr strBldr = TsStrBldrClass.Create(); // Test StringFields (which are basically the same, except that the // format of the parameters is different) strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps()); ITsString tsString = strBldr.GetString(); int cbFmt; byte[] rgbFmt; using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte))) { cbFmt = tsString.SerializeFmtRgb(arrayPtr, 1000); rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte)); } VwCacheDa.CacheStringFields(hvo, tag, tsString.Text, tsString.Length, rgbFmt, cbFmt - 1); }
public void StringFields_Replace() { CheckDisposed(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse"); ITsStrBldr strBldr = TsStrBldrClass.Create(); // Test StringFields (which are basically the same, except that the // format of the parameters is different) strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps()); ITsString tsString = strBldr.GetString(); using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte))) { int cbFmt = tsString.SerializeFmtRgb(arrayPtr, 1000); byte[] rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte)); m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text, tsString.Length, rgbFmt, cbFmt); strBldr.Replace(0, 5, "Fourth", propsBldr.GetTextProps()); tsString = strBldr.GetString(); m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text, tsString.Length, rgbFmt, cbFmt); ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228); Assert.AreEqual(tsString.Text, tsStringNew.Text); } }
private static TsTextProps EditStrProperty(TsTextProps textProps, int tpt, string strVal) { ITsPropsBldr tpb = textProps.GetBldr(); tpb.SetStrPropValue(tpt, strVal); return((TsTextProps)tpb.GetTextProps()); }
/// <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 TestGetStyleRgch() { IVwStylesheet stylesheet = (IVwStylesheet) new TestFwStylesheet(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times"); ITsTextProps props1 = propsBldr.GetTextProps(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, 256); ITsTextProps props2 = propsBldr.GetTextProps(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, hvoNewStyle1, 0, false, false, props1); int hvoNewStyle2 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("SecondStyle", "bla", hvoNewStyle2, 0, hvoNewStyle1, 0, false, false, props2); string sHowDifferent; bool fEqual = TsTextPropsHelper.PropsAreEqual(props2, stylesheet.GetStyleRgch(0, "SecondStyle"), out sHowDifferent); Assert.IsTrue(fEqual, sHowDifferent); fEqual = TsTextPropsHelper.PropsAreEqual(props1, stylesheet.GetStyleRgch(0, "FirstStyle"), out sHowDifferent); Assert.IsTrue(fEqual, sHowDifferent); }
public RegRuleFormulaVc(FdoCache cache, Mediator mediator) : base(cache, mediator) { ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); m_ctxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20000); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, 2000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint, 2000); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_charProps = tpb.GetTextProps(); ITsStrFactory tsf = m_cache.TsStrFactory; int userWs = m_cache.DefaultUserWs; m_arrow = tsf.MakeString("\u2192", userWs); m_slash = tsf.MakeString("/", userWs); m_underscore = tsf.MakeString("__", userWs); }
public void TypingBeforeHyperlink_WithPrecedingItalicsText() { var selection = MakeMockSelection(false); var selHelper = SelectionHelper.s_mockedSelectionHelper = MockRepository.GenerateStub <SelectionHelper>(); selHelper.Stub(selH => selH.Selection).Return(selection); ITsPropsBldr bldr = m_ttpNormal.GetBldr(); bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Italics"); SimulateTextFollowedByHyperlink(selHelper, bldr.GetTextProps(), IchPosition.StartOfHyperlink, IchPosition.StartOfHyperlink); using (FwEditingHelper editingHelper = new FwEditingHelper(Cache, m_callbacks)) { editingHelper.OnKeyPress(new KeyPressEventArgs('b'), Keys.None); IList <object[]> argsSentToSetTypingProps = selection.GetArgumentsForCallsMadeOn(sel => sel.SetTypingProps(null)); Assert.AreEqual(1, argsSentToSetTypingProps.Count); ITsTextProps ttpSentToSetTypingProps = (ITsTextProps)argsSentToSetTypingProps[0][0]; Assert.AreEqual(1, ttpSentToSetTypingProps.StrPropCount); Assert.AreEqual(1, ttpSentToSetTypingProps.IntPropCount); int nVar; Assert.AreEqual("Italics", ttpSentToSetTypingProps.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); Assert.AreEqual(911, ttpSentToSetTypingProps.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); } }
public void PropsDifferByIntProps() { // test of different int prop: writing system ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565754); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565753); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in ktptWs property. Expected ws <4565754> and var <0>, but was ws <4565753> and var <0>.", s); // test of different int prop: background color tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); //string prop, same for both tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, 98); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, 99); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in intProp type 9. " + "Expected <98,0>, but was <99,0>.", s); }
public RuleFormulaVc(FdoCache cache, XCore.Mediator mediator) { m_cache = cache; m_mediator = mediator; // use Doulos SIL because it supports the special characters that are needed for // multiline brackets ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Charis SIL"); m_bracketProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptMarginLeading, (int)FwTextPropVar.ktpvMilliPoint, PILE_MARGIN); tpb.SetIntPropValues((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, PILE_MARGIN); m_pileProps = tpb.GetTextProps(); m_empty = m_cache.MakeUserTss(""); m_infinity = m_cache.MakeUserTss("\u221e"); m_leftBracketUpHook = m_cache.MakeUserTss("\u23a1"); m_leftBracketExt = m_cache.MakeUserTss("\u23a2"); m_leftBracketLowHook = m_cache.MakeUserTss("\u23a3"); m_rightBracketUpHook = m_cache.MakeUserTss("\u23a4"); m_rightBracketExt = m_cache.MakeUserTss("\u23a5"); m_rightBracketLowHook = m_cache.MakeUserTss("\u23a6"); m_leftBracket = m_cache.MakeUserTss("["); m_rightBracket = m_cache.MakeUserTss("]"); m_questions = m_cache.MakeUserTss("???"); m_leftParen = m_cache.MakeUserTss("("); m_rightParen = m_cache.MakeUserTss(")"); m_x = m_cache.MakeUserTss("X"); m_zwSpace = m_cache.MakeUserTss("\u200b"); }
public MetaRuleFormulaVc(FdoCache cache, XCore.Mediator mediator) : base(cache, mediator) { ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); m_inputCtxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); m_resultCtxtProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Arial"); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000); tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_colHeaderProps = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Arial"); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000); tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray)); tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalLeft); tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); m_rowHeaderProps = tpb.GetTextProps(); m_inputStr = m_cache.MakeUserTss(MEStrings.ksMetaRuleInput); m_resultStr = m_cache.MakeUserTss(MEStrings.ksMetaRuleResult); m_leftEnvStr = m_cache.MakeUserTss(MEStrings.ksMetaRuleLeftEnv); m_rightEnvStr = m_cache.MakeUserTss(MEStrings.ksMetaRuleRightEnv); m_switchStr = m_cache.MakeUserTss(MEStrings.ksMetaRuleSwitch); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set a font face name for a style. /// </summary> /// <param name="styleName"></param> /// <param name="fontName"></param> /// ------------------------------------------------------------------------------------ public void SetStyleFont(string styleName, string fontName) { IStStyle style = FindStyle(styleName); ITsPropsBldr ttpBldr = style.Rules.GetBldr(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, fontName); style.Rules = ttpBldr.GetTextProps(); ComputeDerivedStyles(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns paragraph textprops representing a paragraph style of the given name. /// </summary> /// <param name="styleName">The name of the paragraph style</param> /// <returns>A TsTextProps object wich will have exactly zero int props and one string /// prop: the named style, whose value will be the given styleName</returns> /// <remarks>This is useful for setting BaseStPara.StyleRules.</remarks> /// ------------------------------------------------------------------------------------ public static ITsTextProps ParaStyleTextProps(string styleName) { Debug.Assert(!string.IsNullOrEmpty(styleName)); // Build props for the given para style name ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styleName); return(tsPropsBldr.GetTextProps()); }
public void TestGetAdjustedTsString() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsStrBldr strBldrExpected = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs); strBldr.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps()); strBldrExpected.ReplaceRgch(0, 0, "Hello People", 12, propsBldr.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleA"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs); strBldr.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldr.GetTextProps()); var propsBldrExpected = propsBldr; propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20500); strBldrExpected.ReplaceRgch(0, 0, "Hello numero dos", 16, propsBldrExpected.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoGermanWs); strBldr.ReplaceRgch(0, 0, "3 Hello", 7, propsBldr.GetTextProps()); propsBldrExpected = propsBldr; propsBldrExpected.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, ExpectedFontHeightForArial); strBldrExpected.ReplaceRgch(0, 0, "3 Hello", 7, propsBldrExpected.GetTextProps()); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "StyleB"); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_hvoEnglishWs); strBldr.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps()); strBldrExpected.ReplaceRgch(0, 0, "This is 4", 9, propsBldr.GetTextProps()); var tss = FontHeightAdjuster.GetAdjustedTsString(strBldr.GetString(), 23000, m_stylesheet, m_wsManager); var propsWithWiggleRoom = new Dictionary <int, int>(); if (GetUbuntuVersion() == 14) { propsWithWiggleRoom[(int)FwTextPropType.ktptFontSize] = 1000; // millipoints. for some reason, the result is sometimes a point smaller on Trusty } AssertEx.AreTsStringsEqual(strBldrExpected.GetString(), tss, propsWithWiggleRoom); }
/// <summary> /// Make a TsString in the specified (typicaly UI) writing system, which is forced to be /// displayed in the default UIElement style. /// </summary> protected ITsString MakeUiElementString(string text, int uiWs, Action<ITsPropsBldr> SetAdditionalProps) { ITsStrBldr bldr = TsStringUtils.MakeStrBldr(); ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, uiWs); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleServices.UiElementStylename); if (SetAdditionalProps != null) SetAdditionalProps(propsBldr); bldr.Replace(0, 0, text, propsBldr.GetTextProps()); return bldr.GetString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the font properties from the XML node and set the properties in the given /// props builder. /// </summary> /// <param name="styleName">Name of style being created/updated (for error reporting) /// </param> /// <param name="styleTag">XML node that has the font properties</param> /// <param name="propsBldr">the props builder to store the props</param> /// ------------------------------------------------------------------------------------ protected void SetFontProperties(string styleName, XmlNode styleTag, ITsPropsBldr propsBldr) { // Get character properties XmlAttributeCollection fontAttributes = styleTag.SelectSingleNode("font").Attributes; XmlNode node = fontAttributes.GetNamedItem("italic"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(fontAttributes, "italic", styleName, ResourceFileName) ? (int)FwTextToggleVal.kttvInvert : (int)FwTextToggleVal.kttvOff); } node = fontAttributes.GetNamedItem("bold"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(fontAttributes, "bold", styleName, ResourceFileName) ? (int)FwTextToggleVal.kttvInvert : (int)FwTextToggleVal.kttvOff); } node = fontAttributes.GetNamedItem("superscript"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(fontAttributes, "superscript", styleName, ResourceFileName) ? (int)FwSuperscriptVal.kssvSuper : (int)FwSuperscriptVal.kssvOff); } node = fontAttributes.GetNamedItem("size"); if (node != null) { int nSize = InterpretMeasurementAttribute(node.Value, "size", styleName, ResourceFileName); propsBldr.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, nSize); } node = fontAttributes.GetNamedItem("color"); string sColor = (node == null ? "default" : node.Value); if (sColor != "default") { propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, ColorVal(sColor, styleName)); } node = fontAttributes.GetNamedItem("underlineColor"); sColor = (node == null ? "default" : node.Value); if (sColor != "default") { propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault, ColorVal(sColor, styleName)); } node = fontAttributes.GetNamedItem("underline"); string sUnderline = (node == null) ? null : node.Value; if (sUnderline != null) { int unt = InterpretUnderlineType(sUnderline); propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvEnum, unt); } node = fontAttributes.GetNamedItem("spellcheck"); bool fSpellcheck = (node == null ? true : (node.Value == "true")); if (!fSpellcheck) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpellCheck, (int)FwTextPropVar.ktpvEnum, (int)SpellingModes.ksmDoNotCheck); } // TODO: Handle dropcap attribute node = fontAttributes.GetNamedItem("type"); if (node != null && node.Value != string.Empty) { string sFontFamily = node.Value; switch (sFontFamily) { case "heading": propsBldr.SetStrPropValue( (int)FwTextPropType.ktptFontFamily, StStyle.DefaultHeadingFont); break; case "default": propsBldr.SetStrPropValue( (int)FwTextPropType.ktptFontFamily, StStyle.DefaultFont); break; case "publication": propsBldr.SetStrPropValue( (int)FwTextPropType.ktptFontFamily, StStyle.DefaultPubFont); break; default: ReportInvalidInstallation(String.Format( FrameworkStrings.ksUnknownFontType, styleName, ResourceFileName)); break; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Saves the font overrides to the database. /// </summary> /// <param name="styleProps">The style props to write to</param> /// ------------------------------------------------------------------------------------ private void SaveFontOverridesToDB(ITsPropsBldr styleProps) { StringBuilder overridesString = new StringBuilder(); // JohnT: we MUST add writing system info to this string IN ORDER, sorted by // (unsigned) ws. List<int> wss = new List<int>(m_fontInfoOverrides.Keys); wss.Sort(CompareIntsAsUnsigned); foreach (int ws in wss) { FontInfo info = m_fontInfoOverrides[ws]; string fontName = null; List<IntPropInfo> intProps = new List<IntPropInfo>(); if (info.m_fontName.IsExplicit) fontName = info.m_fontName.Value; if (info.m_bold.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptBold, info.m_bold.Value ? (int)FwTextToggleVal.kttvInvert : (int)FwTextToggleVal.kttvOff, (int)FwTextPropVar.ktpvEnum)); } if (info.m_italic.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptItalic, info.m_italic.Value ? (int)FwTextToggleVal.kttvInvert : (int)FwTextToggleVal.kttvOff, (int)FwTextPropVar.ktpvEnum)); } if (info.m_superSub.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptSuperscript, (int)info.m_superSub.Value, 0)); } if (info.m_fontSize.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptFontSize, info.m_fontSize.Value, 0)); } if (info.m_fontColor.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptForeColor, (int)ColorUtil.ConvertColorToBGR(info.m_fontColor.Value), 0)); } if (info.m_backColor.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptBackColor, (int)ColorUtil.ConvertColorToBGR(info.m_backColor.Value), 0)); } if (info.m_offset.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptOffset, info.m_offset.Value, (int)FwTextPropVar.ktpvMilliPoint)); } if (info.m_underline.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptUnderline, (int)info.m_underline.Value, 0)); } if (info.m_underlineColor.IsExplicit) { intProps.Add(new IntPropInfo((int)FwTextPropType.ktptUnderColor, (int)ColorUtil.ConvertColorToBGR(info.m_underlineColor.Value), 0)); } // If anything was explicitly defined in this override, then save it if (fontName != null || intProps.Count != 0 || info.m_features.IsExplicit) { overridesString.Append(IntToString(ws)); if (fontName == null) overridesString.Append(ShortToString((short)0)); else { overridesString.Append(ShortToString((short)fontName.Length)); overridesString.Append(fontName); } if (info.m_features.IsExplicit) { overridesString.Append(ShortToString((short)-1)); // negative number indicates string property count overridesString.Append(ShortToString((short)FwTextPropType.ktptFontVariations)); string features = info.m_features.ValueIsSet && info.m_features.Value != null ? info.m_features.Value : ""; overridesString.Append(ShortToString((short)features.Length)); overridesString.Append(features); } overridesString.Append(ShortToString((short)intProps.Count)); foreach (IntPropInfo prop in intProps) { overridesString.Append(ShortToString((short)prop.m_textPropType)); overridesString.Append(ShortToString((short)prop.m_variant)); overridesString.Append(IntToString(prop.m_value)); } } } if (overridesString.Length != 0) { styleProps.SetStrPropValue((int)FwTextPropType.ktptWsStyle, overridesString.ToString()); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Converts this bullet info to a text props object /// </summary> /// <param name="styleProps">The style props</param> /// ------------------------------------------------------------------------------------ public void ConvertAsTextProps(ITsPropsBldr styleProps) { if (styleProps == null) return; styleProps.SetIntPropValues((int)FwTextPropType.ktptBulNumScheme, (int)FwTextPropVar.ktpvEnum, (int)m_numberScheme); if (m_numberScheme == VwBulNum.kvbnNone) { // no bullets styleProps.SetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, -1, -1); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef, null); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtAft, null); } else if ((int)m_numberScheme >= (int)VwBulNum.kvbnBulletBase) { // bullets styleProps.SetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, -1, -1); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef, null); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtAft, null); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumFontInfo, EncodedFontInfo); } else { // numbered styleProps.SetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, (int)FwTextPropVar.ktpvDefault, m_start); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef, m_textBefore); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtAft, m_textAfter); styleProps.SetStrPropValue((int)FwTextPropType.ktptBulNumFontInfo, EncodedFontInfo); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the ws style info to BLDR. /// </summary> /// <param name="bldr">The BLDR.</param> /// <param name="wsStyleInfo">The ws style info.</param> /// <param name="lgwsf">The LGWSF.</param> /// ------------------------------------------------------------------------------------ private static void AddWsStyleInfoToBldr(ITsPropsBldr bldr, XElement wsStyleInfo, ILgWritingSystemFactory lgwsf) { StringBuilder wsStyleProps = new StringBuilder(); foreach (XElement wsPropInfo in wsStyleInfo.Elements()) { if (wsPropInfo.Name.LocalName != "WsProp") throw new XmlSchemaException("Invalid nested element in <WsStyle9999> element: " + wsPropInfo.Name.LocalName); // Get the writing system that the prop override is for XAttribute wsAttrib = wsPropInfo.Attribute("ws"); if (wsAttrib == null) throw new XmlSchemaException("WsProp must contain a 'ws' attribute"); wsAttrib.Remove(); // Make sure we don't count it twice WriteIntToStrBuilder(wsStyleProps, TsStringSerializer.GetWsForId(wsAttrib.Value, lgwsf)); // Get the font family for the prop override XAttribute fontFamilyAttrib = wsPropInfo.Attribute("fontFamily"); wsStyleProps.Append((char)((fontFamilyAttrib != null) ? fontFamilyAttrib.Value.Length : 0)); if (fontFamilyAttrib != null) { fontFamilyAttrib.Remove(); // Make sure we don't count it twice wsStyleProps.Append(fontFamilyAttrib.Value); } // Get the rest of the props that are available ITsPropsBldr wsProps = GetPropAttributesForElement(wsPropInfo, lgwsf); // A negative value is specified for string properties, positive value // if only integer properties are added. wsStyleProps.Append((char)((wsProps.StrPropCount > 0) ? -wsProps.StrPropCount : wsProps.IntPropCount)); int intValue, type, var; string strValue; // Add the string properties to the ws props string) if (wsProps.StrPropCount > 0) { for (int i = 0; i < wsProps.StrPropCount; i++) { wsProps.GetStrProp(i, out type, out strValue); wsStyleProps.Append((char)type); wsStyleProps.Append((char)strValue.Length); wsStyleProps.Append(strValue); } // Need to add the count of integer properties wsStyleProps.Append((char)wsProps.IntPropCount); } // Add the integer properties to the ws props string for (int i = 0; i < wsProps.IntPropCount; i++) { wsProps.GetIntProp(i, out type, out var, out intValue); wsStyleProps.Append((char)type); wsStyleProps.Append((char)var); WriteIntToStrBuilder(wsStyleProps, intValue); } } bldr.SetStrPropValue((int)FwTextPropType.ktptWsStyle, wsStyleProps.ToString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the bullet font information to the specified props builder. /// </summary> /// <param name="bldr">The props builder.</param> /// <param name="bulFontInfo">The bullet font information XML.</param> /// <param name="lgwsf">The writing system factory.</param> /// ------------------------------------------------------------------------------------ private static void AddBulletFontInfoToBldr(ITsPropsBldr bldr, XElement bulFontInfo, ILgWritingSystemFactory lgwsf) { int intValue, type, var; string strValue; ITsPropsBldr fontProps = GetPropAttributesForElement(bulFontInfo, lgwsf); // Add the integer properties to the bullet props string StringBuilder bulletProps = new StringBuilder(fontProps.IntPropCount * 3 + fontProps.StrPropCount * 20); for (int i = 0; i < fontProps.IntPropCount; i++) { fontProps.GetIntProp(i, out type, out var, out intValue); bulletProps.Append((char)type); WriteIntToStrBuilder(bulletProps, intValue); } // Add the string properties to the bullet props string for (int i = 0; i < fontProps.StrPropCount; i++) { fontProps.GetStrProp(i, out type, out strValue); bulletProps.Append((char)type); bulletProps.Append(strValue); bulletProps.Append('\u0000'); } bldr.SetStrPropValue((int)FwTextPropType.ktptBulNumFontInfo, bulletProps.ToString()); }