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); }
private static TsTextProps EditStrProperty(TsTextProps textProps, int tpt, string strVal) { ITsPropsBldr tpb = textProps.GetBldr(); tpb.SetStrPropValue(tpt, strVal); return((TsTextProps)tpb.GetTextProps()); }
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); }
/// ----------------------------------------------------------------------------------- /// <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); }
/// <summary> /// We only use this to generate our empty text prompt. /// </summary> /// <param name="vwenv"></param> /// <param name="tag"></param> /// <param name="v"></param> /// <param name="frag"></param> /// <returns></returns> public override ITsString DisplayVariant(IVwEnv vwenv, int tag, object v, int frag) { CheckDisposed(); string userPrompt = ITextStrings.ksEnterOrPasteHere; ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, Color.LightGray.ToArgb()); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.DefaultUserWs); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, userPrompt, ttpBldr.GetTextProps()); // Begin the prompt with a zero-width space in the vernacular writing system (with // no funny colors). This ensures anything the user types (or pastes from a non-FW // clipboard) is put in that WS. // 200B == zero-width space. ITsPropsBldr ttpBldr2 = TsPropsBldrClass.Create(); ttpBldr2.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.DefaultVernWs); bldr.Replace(0, 0, "\u200B", ttpBldr2.GetTextProps()); return(bldr.GetString()); }
public TitleContentsVc(FdoCache cache) { int wsUser = cache.DefaultUserWs; ITsStrFactory tsf = TsStrFactoryClass.Create(); m_tssTitle = tsf.MakeString(ITextStrings.ksTitle, wsUser); ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); m_ttpBold = tpb.GetTextProps(); tpb = TsPropsBldrClass.Create(); // Set some padding all around. tpb.SetIntPropValues((int)FwTextPropType.ktptPadTop, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, 3000); tpb.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint, 3000); tpb.SetIntPropValues((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, 11000); // 10000 clips right border. m_ttpDataCellProps = tpb.GetTextProps(); m_vtagStTextTitle = cache.MetaDataCacheAccessor.GetFieldId("StText", "Title", false); // Set up the array of writing systems we will display for title. SetupWritingSystemsForTitle(cache); }
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 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 GetFootnoteMarkerFromGuid() { StFootnote footnote = new StFootnote(); m_scr.ScriptureBooksOS[0].FootnotesOS.Append(footnote); footnote.FootnoteMarker.Text = "a"; Guid guid = m_fdoCache.GetGuidFromId(footnote.Hvo); // Add the guid property so we can get it out as a string. ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); byte[] objData = MiscUtils.GetObjData(guid, 1); propsBldr.SetStrPropValueRgch(1, objData, objData.Length); // Get the guid property as a string. string sObjData; propsBldr.GetStrPropValue(1, out sObjData); using (StVc vc = new StVc()) { vc.Cache = m_fdoCache; vc.DefaultWs = m_fdoCache.LanguageWritingSystemFactoryAccessor.UserWs; ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1)); Assert.AreEqual("2", footnoteMarker.Text); } }
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 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 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 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 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); }
private static void ApplyStyleToTsPropertyBuilder(ITsPropsBldr tpb, string style) { if (String.IsNullOrEmpty(style)) { return; } style = style.ToLowerInvariant(); // N.B.: Was tempted to refactor with IndexOf("-"), but realized // that style could be "italic -bold" or "-italic bold" or "-italic -bold". if (style.IndexOf("-bold") >= 0) { tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvOff); } else if (style.IndexOf("bold") >= 0) { tpb.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); } if (style.IndexOf("-italic") >= 0) { tpb.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvOff); } else if (style.IndexOf("italic") >= 0) { tpb.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); } }
/// <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 TsStringsTwoEmpty_ExpectedIntProp() { CheckDisposed(); ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 45); ITsTextProps propsS1 = propsBldr.GetTextProps(); // Create TsString #1 strBldr.Replace(0, 0, "", propsS1); ITsString tssExpected = strBldr.GetString(); // Create TsString #2 strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "", null); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( "TsStrings differ in format of run 1.\n\t" + "Props differ in ktptWs property. Expected <45>, but was <-1>.", s, "Got incorrect explanation of difference"); }
/// ------------------------------------------------------------------------------------ /// <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()); }
private static TsTextProps EditIntProperty(TsTextProps textProps, int tpt, int nVar, int nVal) { ITsPropsBldr tpb = textProps.GetBldr(); tpb.SetIntPropValues(tpt, nVar, nVal); return((TsTextProps)tpb.GetTextProps()); }
public void TsStringsTwoEmpty_WritingSystemsDiffer() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 45); ITsTextProps propsS1 = propsBldr.GetTextProps(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 15); ITsTextProps propsS2 = propsBldr.GetTextProps(); // Create TsString #1 strBldr.Replace(0, 0, "", propsS1); ITsString tssExpected = strBldr.GetString(); // Create TsString #2 strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "", propsS2); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( "TsStrings differ in format of run 1." + Environment.NewLine + "\tProps differ in ktptWs property. Expected ws <45> and var <0>, but was ws <15> and var <0>.", s, "Got incorrect explanation of difference"); }
// /// ------------------------------------------------------------------------------------ // /// <summary> // /// Builds a number string for the preview window based on the settings in the // /// Number group and the selected numbering scheme // /// </summary> // /// <param name="line">The line.</param> // /// ------------------------------------------------------------------------------------ // private string GetNumberString(int line) // { // return GetNumberString(line, m_nudStartAt.Value, m_cboNumberScheme.SelectedIndex, // m_tbTextBefore.Text, m_tbTextAfter.Text); // } // /// ------------------------------------------------------------------------------------ // /// <summary> // /// Builds a number string for the preview window based on the given values // /// </summary> // /// <param name="line">The line.</param> // /// <param name="nStartAt">The number to start at.</param> // /// <param name="iScheme">The i scheme.</param> // /// <param name="textBefore">The text before.</param> // /// <param name="textAfter">The text after.</param> // /// <returns></returns> // /// ------------------------------------------------------------------------------------ // private string GetNumberString(int line, int nStartAt, int iScheme, string textBefore, // string textAfter) // { // int number = nStartAt + line; // string numberString = string.Empty; // switch (iScheme) // { // case 0: // 1, 2, 3' // numberString = number.ToString(); // break; // case 1: // I, II, III (Roman numerals) // numberString = RomanNumerals.IntToRoman(number); // break; // case 2: // i, ii, iii (lower case Roman numerals) // numberString = RomanNumerals.IntToRoman(number).ToLowerInvariant(); // break; // case 3: // A, B, C // numberString = AlphaOutline.NumToAlphaOutline(number); // break; // case 4: // a, b, c // numberString = AlphaOutline.NumToAlphaOutline(number).ToLowerInvariant(); // break; // case 5: // 01, 02, 03 // numberString = number.ToString("d2"); // break; // } // return textBefore + numberString + textAfter; // } /// ------------------------------------------------------------------------------------ /// <summary> /// When any data field changes, refresh the preview panel /// </summary> /// ------------------------------------------------------------------------------------ private void DataChange(object sender, EventArgs e) { // If the value in the "start at" spinner control is other than 1, then check // the start at check box if (m_nudStartAt.Value != 1) { m_chkStartAt.Checked = true; } UpdateBulletInfo(ref m_currentStyleBulletInfo); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); m_currentStyleBulletInfo.ConvertAsTextProps(propsBldr); propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvMilliPoint, 6000); ITsTextProps propsFirst = propsBldr.GetTextProps(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, -1, -1); m_preview.SetProps(propsFirst, propsBldr.GetTextProps()); m_preview.Refresh(); if (StyleDataChanged != null) { StyleDataChanged(this, null); } }
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 TsStringsTwoEmpty_ExpectedIntProp() { ITsStrBldr strBldr = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 45); ITsTextProps propsS2 = propsBldr.GetTextProps(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, 1); ITsTextProps propsS1 = propsBldr.GetTextProps(); // Create TsString #1 strBldr.Replace(0, 0, "", propsS1); ITsString tssExpected = strBldr.GetString(); // Create TsString #2 strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "", propsS2); string s; Assert.IsFalse(TsStringHelper.TsStringsAreEqual(tssExpected, strBldr.GetString(), out s)); Assert.AreEqual( "TsStrings differ in format of run 1." + Environment.NewLine + "\tProps differ in intProp type " + (int)FwTextPropType.ktptSuperscript + ". Expected <1,3>, but was <-1,-1>.", s, "Got incorrect explanation of difference"); }
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 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)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the expected user prompt string /// </summary> /// <param name="text">text for the prompt</param> /// <param name="ws">writing system to use for the ZWS character</param> /// ------------------------------------------------------------------------------------ private ITsString ExpectedUserPrompt(string text, int ws) { // Set up the text we expect to be added to the paragraph ITsPropsBldr ttpBldr = TsPropsBldrClass.Create(); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.LightGray)); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.WritingSystemFactory.UserWs); ttpBldr.SetIntPropValues(SimpleRootSite.ktptUserPrompt, (int)FwTextPropVar.ktpvDefault, 1); ttpBldr.SetIntPropValues((int)FwTextPropType.ktptSpellCheck, (int)FwTextPropVar.ktpvEnum, (int)SpellingModes.ksmDoNotCheck); ITsStrBldr strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, text, ttpBldr.GetTextProps()); ITsPropsBldr ttpBldr2 = TsPropsBldrClass.Create(); ttpBldr2.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, ws); ttpBldr2.SetIntPropValues(SimpleRootSite.ktptUserPrompt, (int)FwTextPropVar.ktpvDefault, 1); strBldr.Replace(0, 0, "\u200B", ttpBldr2.GetTextProps()); return(strBldr.GetString()); }
/// <summary> /// /// </summary> /// <param name="fdoCache"></param> /// <returns></returns> public static ITsTextProps PartOfSpeechTextProperties(LcmCache fdoCache, bool inAnalysisLine, bool fUseStyleSheet) { int color = (int)CmObjectUi.RGB(Color.Green); ITsPropsBldr bldr = TsStringUtils.MakePropsBldr(); if (!fUseStyleSheet) { bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, (int)(s_baseFontSize * 1000 * .8)); } bldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, fdoCache.DefaultAnalWs); // bldr.SetIntPropValues((int)FwTextPropType.ktptItalic, // (int)FwTextPropVar.ktpvEnum, // (int)FwTextToggleVal.kttvInvert); if (inAnalysisLine) { bldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSub); } bldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, color); return(bldr.GetTextProps()); }
int GetIterCtxtWidth(IPhIterationContext ctxt, IVwEnv vwenv) { if (ctxt.MemberRAHvo != 0) { int len = GetSimpleCtxtWidth(ctxt.MemberRA as IPhSimpleContext, vwenv); int numLines = GetNumLines(ctxt.MemberRA); if (numLines > 1) { len += GetMinMaxWidth(ctxt, null, vwenv); } else { if (ctxt.MemberRA.ClassID != PhSimpleContextNC.kclsidPhSimpleContextNC) { len += GetStrWidth(m_leftParen, null, vwenv); len += GetStrWidth(m_rightParen, null, vwenv); } int fontHeight = GetFontHeight(m_cache.DefaultUserWs); int superSubHeight = (fontHeight * 2) / 3; ITsPropsBldr tpb = TsPropsBldrClass.Create(); tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, superSubHeight); len += GetMinMaxWidth(ctxt, tpb.GetTextProps(), vwenv); } return(len); } else { return(GetStrWidth(m_questions, null, vwenv)); } }
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 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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a new real style in the stylesheet for this proxy, if needed. /// </summary> /// ------------------------------------------------------------------------------------ private void AddStyleToStylesheet() { if (m_style != null || m_Context == ContextValues.EndMarker || m_sStyleName == null) { return; } // If m_ttpFormattingProps has not been set up, initialize it now if (m_ttpFormattingProps == null) { ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); m_ttpFormattingProps = tsPropsBldr.GetTextProps(); // default properties } // Get an hvo for the new style int hvoStyle = m_FwStyleSheet.MakeNewStyle(); m_style = m_FwStyleSheet.Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvoStyle); // PutStyle() adds the style to the stylesheet. we'll give it the properties we // are aware of. m_FwStyleSheet.PutStyle(m_sStyleName, string.Empty, hvoStyle, 0, m_StyleType == StyleType.kstParagraph ? hvoStyle : 0, (int)m_StyleType, false, false, m_ttpFormattingProps); // base the new style on "Paragraph" if (m_StyleType == StyleType.kstParagraph) { m_style.BasedOnRA = m_FwStyleSheet.FindStyle(ScrStyleNames.NormalParagraph); m_style.Context = m_style.BasedOnRA.Context; m_style.Structure = m_style.BasedOnRA.Structure; m_style.Function = m_style.BasedOnRA.Function; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a size property to the specified props builder with the specified prop type. /// This default does not allow negative sizes. /// </summary> /// <param name="propsBldr">The props builder.</param> /// <param name="value">The string representation of the size value.</param> /// <param name="proptype">The property type.</param> /// <param name="unitAttr">The attribute containing the size unit (can be null).</param> /// <param name="typeAttr">The attribute containing the size type (can be null).</param> /// ------------------------------------------------------------------------------------ private static void AddSizePropertyToBldr(ITsPropsBldr propsBldr, string value, int proptype, XAttribute unitAttr, XAttribute typeAttr) { AddSizePropertyToBldr(propsBldr, value, proptype, unitAttr, typeAttr, false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds object link data to the specified text property builder /// </summary> /// <param name="propsBldr">The props builder.</param> /// <param name="attr">The attribute to process.</param> /// <param name="type">The type of object data to be added to the text properties.</param> /// ------------------------------------------------------------------------------------ private static void AddObjDataToBldr(ITsPropsBldr propsBldr, XAttribute attr, FwObjDataTypes type) { byte[] objData = TsStringUtils.GetObjData(new Guid(attr.Value), (byte)type); propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length); }
/// ------------------------------------------------------------------------------------ /// <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> /// 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> /// 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 a size property to the specified props builder with the specified prop type. /// </summary> /// <param name="propsBldr">The props builder.</param> /// <param name="value">The string representation of the size value.</param> /// <param name="proptype">The property type.</param> /// <param name="unitAttr">The attribute containing the size unit (can be null).</param> /// <param name="typeAttr">The attribute containing the size type (can be null).</param> /// <param name="allowNegative">true if negative size is allowed (e.g., baseline offset)</param> /// ------------------------------------------------------------------------------------ private static void AddSizePropertyToBldr(ITsPropsBldr propsBldr, string value, int proptype, XAttribute unitAttr, XAttribute typeAttr, bool allowNegative) { int var; int intValue = GetSizeValue(value, unitAttr, typeAttr, allowNegative, out var); propsBldr.SetIntPropValues(proptype, var, intValue); }
/// ------------------------------------------------------------------------------------ /// <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; } } }
private static void ApplyStyleToTsPropertyBuilder(ITsPropsBldr tpb, string style) { if (String.IsNullOrEmpty(style)) return; style = style.ToLowerInvariant(); // N.B.: Was tempted to refactor with IndexOf("-"), but realized // that style could be "italic -bold" or "-italic bold" or "-italic -bold". if (style.IndexOf("-bold") >= 0) { tpb.SetIntPropValues((int) FwTextPropType.ktptBold, (int) FwTextPropVar.ktpvEnum, (int) FwTextToggleVal.kttvOff); } else if (style.IndexOf("bold") >= 0) { tpb.SetIntPropValues((int) FwTextPropType.ktptBold, (int) FwTextPropVar.ktpvEnum, (int) FwTextToggleVal.kttvForceOn); } if (style.IndexOf("-italic") >= 0) { tpb.SetIntPropValues((int) FwTextPropType.ktptItalic, (int) FwTextPropVar.ktpvEnum, (int) FwTextToggleVal.kttvOff); } else if (style.IndexOf("italic") >= 0) { tpb.SetIntPropValues((int) FwTextPropType.ktptItalic, (int) FwTextPropVar.ktpvEnum, (int) FwTextToggleVal.kttvForceOn); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the paragraph 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 paragraph properties</param> /// <param name="propsBldr">the props builder to store the props</param> /// ------------------------------------------------------------------------------------ protected void SetParagraphProperties(string styleName, XmlNode styleTag, ITsPropsBldr propsBldr) { XmlNode node = styleTag.SelectSingleNode("paragraph"); if (node == null) { ReportInvalidInstallation(String.Format( FrameworkStrings.ksMissingParagraphNode, styleName, ResourceFileName)); } XmlAttributeCollection paraAttributes = node.Attributes; // Set alignment node = paraAttributes.GetNamedItem("alignment"); if (node != null) { string sAlign = node.Value; int nAlign = (int)FwTextAlign.ktalLeading; switch (sAlign) { case "left": break; case "center": nAlign = (int)FwTextAlign.ktalCenter; break; case "right": nAlign = (int)FwTextAlign.ktalTrailing; break; case "full": nAlign = (int)FwTextAlign.ktalJustify; break; default: ReportInvalidInstallation(String.Format( FrameworkStrings.ksUnknownAlignmentValue, styleName, ResourceFileName)); break; } propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, nAlign); } node = paraAttributes.GetNamedItem("background"); if (node != null && node.Value != "white") ReportInvalidInstallation(String.Format( FrameworkStrings.ksUnknownBackgroundValue, styleName, ResourceFileName)); // set leading indentation node = paraAttributes.GetNamedItem("indentLeft"); if (node != null) { int nLeftIndent = InterpretMeasurementAttribute(node.Value, "indentLeft", styleName, ResourceFileName); propsBldr.SetIntPropValues( (int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvMilliPoint, nLeftIndent); } // Set trailing indentation node = paraAttributes.GetNamedItem("indentRight"); if (node != null) { int nRightIndent = InterpretMeasurementAttribute(node.Value, "indentRight", styleName, ResourceFileName); propsBldr.SetIntPropValues( (int)FwTextPropType.ktptTrailingIndent, (int)FwTextPropVar.ktpvMilliPoint, nRightIndent); } // Set first-line/hanging indentation int nFirstIndent = 0; bool fFirstLineOrHangingIndentSpecified = false; node = paraAttributes.GetNamedItem("firstLine"); if (node != null) { nFirstIndent = InterpretMeasurementAttribute(node.Value, "firstLine", styleName, ResourceFileName); fFirstLineOrHangingIndentSpecified = true; } int nHangingIndent = 0; node = paraAttributes.GetNamedItem("hanging"); if (node != null) { nHangingIndent = InterpretMeasurementAttribute(node.Value, "hanging", styleName, ResourceFileName); fFirstLineOrHangingIndentSpecified = true; } if (nFirstIndent != 0 && nHangingIndent != 0) ReportInvalidInstallation(String.Format( FrameworkStrings.ksInvalidFirstLineHanging, styleName, ResourceFileName)); nFirstIndent -= nHangingIndent; if (fFirstLineOrHangingIndentSpecified) { propsBldr.SetIntPropValues( (int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvMilliPoint, nFirstIndent); } // Set space before node = paraAttributes.GetNamedItem("spaceBefore"); if (node != null) { int nSpaceBefore = InterpretMeasurementAttribute(node.Value, "spaceBefore", styleName, ResourceFileName); propsBldr.SetIntPropValues( (int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvMilliPoint, nSpaceBefore); } // Set space after node = paraAttributes.GetNamedItem("spaceAfter"); if (node != null) { int nSpaceAfter = InterpretMeasurementAttribute(node.Value, "spaceAfter", styleName, ResourceFileName); propsBldr.SetIntPropValues( (int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvMilliPoint, nSpaceAfter); } // Set lineSpacing node = paraAttributes.GetNamedItem("lineSpacingType"); string sLineSpacingType = ""; if (node != null) { sLineSpacingType = node.Value; switch (sLineSpacingType) { //verify valid line spacing types case "atleast": break; case "exact": break; default: ReportInvalidInstallation(String.Format( FrameworkStrings.ksUnknownLineSpacingValue, styleName, ResourceFileName)); break; } } node = paraAttributes.GetNamedItem("lineSpacing"); if (node != null) { int lineSpacing = InterpretMeasurementAttribute(node.Value, "lineSpacing", styleName, ResourceFileName); if (lineSpacing < 0) { ReportInvalidInstallation(String.Format( FrameworkStrings.ksNegativeLineSpacing, styleName, ResourceFileName)); } if(sLineSpacingType == "exact") { lineSpacing *= -1; // negative lineSpacing indicates exact line spacing } propsBldr.SetIntPropValues( (int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, lineSpacing); } // Set borders node = paraAttributes.GetNamedItem("border"); if (node != null) { int nBorder = 0; switch (node.Value) { case "top": nBorder = (int)FwTextPropType.ktptBorderTop; break; case "bottom": nBorder = (int)FwTextPropType.ktptBorderBottom; break; case "leading": nBorder = (int)FwTextPropType.ktptBorderLeading; break; case "trailing": nBorder = (int)FwTextPropType.ktptBorderTrailing; break; default: ReportInvalidInstallation(String.Format( FrameworkStrings.ksUnknownBorderValue, styleName, ResourceFileName)); break; } propsBldr.SetIntPropValues(nBorder, (int)FwTextPropVar.ktpvDefault, 500); } node = paraAttributes.GetNamedItem("keepWithNext"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptKeepWithNext, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(paraAttributes, "keepWithNext", styleName, ResourceFileName) ? (int)FwTextToggleVal.kttvForceOn : (int)FwTextToggleVal.kttvOff); } node = paraAttributes.GetNamedItem("keepTogether"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptKeepTogether, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(paraAttributes, "keepTogether", styleName, ResourceFileName) ? (int)FwTextToggleVal.kttvForceOn : (int)FwTextToggleVal.kttvOff); } node = paraAttributes.GetNamedItem("widowOrphan"); if (node != null) { propsBldr.SetIntPropValues((int)FwTextPropType.ktptWidowOrphanControl, (int)FwTextPropVar.ktpvEnum, GetBoolAttribute(paraAttributes, "widowOrphan", styleName, ResourceFileName) ? (int)FwTextToggleVal.kttvForceOn : (int)FwTextToggleVal.kttvOff); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Saves a boolean property value to a props builder that will go to the database. /// </summary> /// <param name="props">props builder</param> /// <param name="boolProp">The boolean property to write</param> /// <param name="propTag">The property tag</param> /// ------------------------------------------------------------------------------------ private void SaveBoolProp(ITsPropsBldr props, InheritableStyleProp<bool> boolProp, int propTag) { if (!boolProp.IsInherited) props.SetIntPropValues(propTag, 0, boolProp.Value ? 1 : 0); }