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 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_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"); }
public void SetUp() { CheckDisposed(); if (m_emptyTsString != null) { Marshal.ReleaseComObject(m_emptyTsString); } // Create an empty TsString ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, string.Empty, null); m_emptyTsString = bldr.GetString(); // Set up the FDO mock and populate it with some values m_inMemoryCache = ScrInMemoryFdoCache.Create(); m_inMemoryCache.InitializeLangProject(); m_inMemoryCache.InitializeScripture(); m_book = m_inMemoryCache.AddBookToMockedScripture(57, "Philemon"); // Set up IVwEnv object m_vwenvMock = new DynamicMock(typeof(IVwEnv)); m_vwenvMock.SetupResult("DataAccess", m_inMemoryCache.CacheAccessor); // save settings m_oldPromptSetting = Options.ShowEmptyParagraphPromptsSetting; }
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); } }
// Generate a suitable string representation of a WfiGloss. // Todo: finish implementing (add the gloss!) static internal ITsString MakeGlossStringRep(IWfiGloss wg, FdoCache fdoCache, bool fUseStyleSheet) { ITsStrBldr tsb = TsStrBldrClass.Create(); var wa = wg.Owner as IWfiAnalysis; var category = wa.CategoryRA; if (category != null) { ITsString tssPos = category.Abbreviation.get_String(fdoCache.DefaultAnalWs); tsb.Replace(0, 0, tssPos.Text, PartOfSpeechTextProperties(fdoCache, false, fUseStyleSheet)); } else { tsb.Replace(0, 0, ksMissingString, PartOfSpeechTextProperties(fdoCache, false, fUseStyleSheet)); } tsb.Replace(tsb.Length, tsb.Length, " ", null); tsb.Replace(tsb.Length, tsb.Length, wg.Form.get_String(fdoCache.DefaultAnalWs).Text, GlossTextProperties(fdoCache, false, fUseStyleSheet)); //indent tsb.Replace(0, 0, " ", null); return(tsb.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(ICmObject topObj, ICmObject bottomObj, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; ICmAnnotationDefn transNoteAnnDefn = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; // Get information from the selection about the location of the annotation. ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn, ann.AnnotationTypeRA, "Wrong type of note created"); Assert.AreEqual(topObj, ann.BeginObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(bottomObj, ann.EndObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent, ann.SourceRA, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((IStTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
/// <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 void CreateFromStringRep_twoCharStylePara() { 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 = 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); }
/// <summary> /// Initialize the combo contents. /// </summary> public void SetupCombo() { CheckDisposed(); ITsStrBldr builder = TsStrBldrClass.Create(); m_fInitializing = true; int wordformHvo = m_owner.GetWordformHvoOfAnalysis(); // Add the analyses, and recursively the other items. foreach (int hvoAnalysis in m_cache.GetVectorProperty(wordformHvo, (int)WfiWordform.WfiWordformTags.kflidAnalyses, false)) { IWfiAnalysis wa = (IWfiAnalysis)CmObject.CreateFromDBObject(m_cache, hvoAnalysis, CmObject.GetTypeFromFullClassName(m_cache, "SIL.FieldWorks.FDO.Ling.WfiAnalysis"), false, false); Opinions o = wa.GetAgentOpinion( m_cache.LangProject.DefaultUserAgent); // skip any analysis the user has disapproved. if (o != Opinions.disapproves) { AddAnalysisItems(hvoAnalysis); AddSeparatorLine(); } } // Add option to clear the analysis altogeter. AddItem(wordformHvo, MakeSimpleString(ITextStrings.ksNewAnalysis), false, WfiWordform.kclsidWfiWordform); // Add option to reset to the default AddItem(0, MakeSimpleString(ITextStrings.ksUseDefaultAnalysis), false); m_fInitializing = false; }
// Generate a suitable string representation of a WfiGloss. // Todo: finish implementing (add the gloss!) static internal ITsString MakeGlossStringRep(int hvoGloss, FdoCache fdoCache, bool fUseStyleSheet) { ITsStrBldr tsb = TsStrBldrClass.Create(); int hvoWa = fdoCache.GetOwnerOfObject(hvoGloss); int hvoCategory = fdoCache.GetObjProperty(hvoWa, (int)WfiAnalysis.WfiAnalysisTags.kflidCategory); if (hvoCategory > 0) { ITsString tssPos = fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoCategory, (int)CmPossibility.CmPossibilityTags.kflidAbbreviation, fdoCache.DefaultAnalWs); tsb.Replace(0, 0, tssPos.Text, PartOfSpeechTextProperties(fdoCache, false, fUseStyleSheet)); } else { tsb.Replace(0, 0, ksMissingString, PartOfSpeechTextProperties(fdoCache, false, fUseStyleSheet)); } tsb.Replace(tsb.Length, tsb.Length, " ", null); tsb.Replace(tsb.Length, tsb.Length, fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoGloss, (int)WfiGloss.WfiGlossTags.kflidForm, fdoCache.DefaultAnalWs).Text, GlossTextProperties(fdoCache, false, fUseStyleSheet)); //indent tsb.Replace(0, 0, " ", null); return(tsb.GetString()); }
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); } }
public void CreateFromStringRep_twoParas() { CheckDisposed(); ITsStrBldr bldr = m_footnotePara.Contents.UnderlyingTsString.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents.UnderlyingTsString = bldr.GetString(); // create second para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps("Note Exegesis Paragraph"); bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents.UnderlyingTsString = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>"; StFootnote footnote = StFootnote.CreateFromStringRep(m_book, (int)ScrBook.ScrBookTags.kflidFootnotes, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets up a TsString to be returned from the selection helper so that it will appear /// to the editing helper as though we're editing a string consisting of only a hyperlink. /// </summary> /// ------------------------------------------------------------------------------------ private void SimulateHyperlinkOnly(SelectionHelper selHelper, IchPosition start, IchPosition end) { ITsStrBldr bldr = (ITsStrBldr)TsStrBldrClass.Create(); bldr.Replace(0, 0, "Google", m_ttpHyperlink); selHelper.Stub(selH => selH.GetTss(Arg <SelectionHelper.SelLimitType> .Is.Anything)) .Return(bldr.GetString()); selHelper.Stub(selH => selH.GetSelProps(Arg <SelectionHelper.SelLimitType> .Is.Anything)) .Return(m_ttpHyperlink); int ichStart = 0; int ichEnd = 0; switch (start) { case IchPosition.EarlyInHyperlink: ichStart = 2; break; case IchPosition.EndOfString: case IchPosition.EndOfHyperlink: ichStart = bldr.Length; break; } switch (end) { case IchPosition.LateInHyperlink: ichEnd = 4; break; case IchPosition.EndOfString: case IchPosition.EndOfHyperlink: ichEnd = bldr.Length; break; } selHelper.Stub(selH => selH.GetIch(SelectionHelper.SelLimitType.Top)).Return(ichStart); selHelper.Stub(selH => selH.GetIch(SelectionHelper.SelLimitType.Bottom)).Return(ichEnd); selHelper.Stub(selH => selH.IsRange).Return(ichStart != ichEnd); }
public void CreateFromStringRep_twoParas() { ITsStrBldr bldr = m_footnotePara.Contents.GetBldr(); bldr.Replace(0, 0, "Paragraph One", null); m_footnotePara.Contents = bldr.GetString(); ReflectionHelper.SetField(typeof(SIL.FieldWorks.FDO.DomainImpl.ScrFootnote), "s_maxAllowedParagraphs", 2); // create second para IStTxtPara para = m_footnote.AddNewTextPara("Note Exegesis Paragraph"); bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps("Foreign", m_wsUr)); para.Contents = bldr.GetString(); string footnoteRep = @"<FN><M>o</M><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>"; IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book, footnoteRep, 0, "Note Marker"); CompareFootnote(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Save the object match criteria in this cell's Contents field as an ITsString. /// </summary> /// <param name="matchVal">The match value.</param> /// ------------------------------------------------------------------------------------ private void SaveObjectMatchCriteria(ICmPossibility matchVal) { ITsStrBldr bldr = TsStrBldrClass.Create(); string sCriteria = string.Empty; if (m_comparisonType == ComparisonTypes.kMatches) { sCriteria = (m_matchEmpty ? "Empty or Matches " : "Matches "); } else if (m_matchEmpty) { sCriteria = "Empty"; } ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs); bldr.Replace(0, 0, sCriteria, ttp); if (matchVal != null) { bldr.AppendOrc(matchVal.Guid, FwObjDataTypes.kodtNameGuidHot, m_cache.DefaultUserWs); } if (m_matchSubitems) { sCriteria = (matchVal != null ? " " : string.Empty) + "+subitems"; bldr.Replace(bldr.Length, bldr.Length, sCriteria, ttp); } Contents = bldr.GetString(); InitializeMatchValuesArray(); }
public void CreateFromStringRep_BT_withBrackets() { 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 = 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 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> /// Save the object match criteria in this cell's Contents field as an ITsString. /// </summary> /// ------------------------------------------------------------------------------------ private void SaveObjectMatchCriteria() { ITsStrBldr bldr = TsStrBldrClass.Create(); string sCriteria = string.Empty; if (m_comparisonType == ComparisionTypes.kMatches) { sCriteria = (m_matchEmpty ? "Empty or Matches " : "Matches "); } else if (m_matchEmpty) { sCriteria = "Empty"; } ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, m_cache.DefaultUserWs); bldr.Replace(0, 0, sCriteria, ttp); if (m_matchValue > 0) { StringUtils.InsertOrcIntoPara(m_cache.GetGuidFromId(m_matchValue), FwObjDataTypes.kodtNameGuidHot, bldr, bldr.Length, bldr.Length, m_cache.DefaultUserWs); } if (m_matchSubitems) { sCriteria = (m_matchValue > 0) ? " +subitems" : "+subitems"; bldr.Replace(bldr.Length, bldr.Length, sCriteria, ttp); } Contents.UnderlyingTsString = bldr.GetString(); }
public void ReplaceAllWithMultipleRuns() { ITsStrBldr stringBuilder = TsStrBldrClass.Create(); stringBuilder.Replace(0, 0, "blaBLA", null); stringBuilder.SetIntPropValues(0, 6, (int)FwTextPropType.ktptWs, 0, Cache.DefaultVernWs); stringBuilder.SetStrPropValue(0, 3, (int)FwTextPropType.ktptNamedStyle, "CStyle3"); m_pattern.ReplaceWith = stringBuilder.GetString(); ReplaceAllCollectorEnv collectorEnv = new ReplaceAllCollectorEnv(m_vc, Cache.MainCacheAccessor, m_para1.Owner.Hvo, (int)StTextFrags.kfrText, m_pattern, null); int nReplaces = collectorEnv.ReplaceAll(); Assert.AreEqual(8, nReplaces); Assert.AreEqual("This is some text so thblaBLAt we cblaBLAn test the find functionblaBLAlity.", m_para1.Contents.Text); Assert.AreEqual("Some more text so thblaBLAt we cblaBLAn test the find blaBLAnd replblaBLAce functionblaBLAlity.", m_para2.Contents.Text); Assert.AreEqual("This purugruph doesn't contuin the first letter of the ulphubet.", m_para3.Contents.Text); ITsString para1Contents = m_para1.Contents; Assert.AreEqual(7, para1Contents.RunCount); Assert.AreEqual("bla", para1Contents.get_RunText(1)); Assert.AreEqual("CStyle3", para1Contents.get_Properties(1).GetStrPropValue( (int)FwTextPropType.ktptNamedStyle)); }
public void CustomFields() { CheckDisposed(); uint flid = GetCustomFlid("LexEntry", "foo"); Assert.IsTrue(m_fdoCache.GetIsCustomField(flid)); int hvo = m_fdoCache.LangProject.LexDbOA.EntriesOC.HvoArray[0]; // LexMajorEntry entry = new LexMajorEntry (); // m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(entry); // m_fdoCache.MainCacheAccessor.get_StringProp(entry.Hvo,flid); ITsString x = m_fdoCache.GetTsStringProperty(hvo, (int)flid); if (x != null) { int l = x.Length; Assert.IsTrue(l == 0); } //m_fdoCache.MainCacheAccessor.RemoveObjRefs ITsStrBldr strBldr = TsStrBldrClass.Create(); strBldr.Replace(0, 0, "Test", null); // string s; // Assert.IsTrue(TsStringHelper.TsStringsAreEqual(strBldr.GetString(), // strBldr.GetString(), out s)); m_fdoCache.SetTsStringProperty(hvo, (int)flid, strBldr.GetString()); m_fdoCache.Save(); }
/// ------------------------------------------------------------------------------------ /// <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()); }
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> /// /// </summary> /// <param name="text"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private ITsString CreateTss(string text) { ITsStrBldr strBuilder = TsStrBldrClass.Create(); strBuilder.Replace(0, 0, text, null); return(strBuilder.GetString()); }
public void MultiStringAlt() { ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(1117, 2227, 7); Assert.IsNotNull(tsStringNew); Assert.AreEqual(0, tsStringNew.Length); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); ITsStrBldr strBldr = TsStrBldrClass.Create(); 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 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"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(int hvoObjStart, int hvoObjEnd, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; CmAnnotationDefn transNoteAnnDefn = new CmAnnotationDefn(Cache, LangProject.kguidAnnTranslatorNote); // Get information from the selection about the location of the annotation. CmObject topObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjStart); CmObject bottomObj = (CmObject)CmObject.CreateFromDBObject(m_inMemoryCache.Cache, hvoObjEnd); int wsSelector = -1; ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, wsSelector, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn.Hvo, ann.AnnotationTypeRAHvo, "Wrong type of note created"); Assert.AreEqual(hvoObjStart, ann.BeginObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(hvoObjEnd, ann.EndObjectRAHvo, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent.Hvo, ann.SourceRAHvo, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((StTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
public void BackTranslation_ReportBTTextNotPartOfPara() { CheckDisposed(); m_importer.Settings.ImportBackTranslation = true; m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(2, 0, 0); m_importer.ProcessSegment("", @"\id"); ReflectionHelper.SetField(m_importer, "m_importDomain", ImportDomain.BackTrans); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.ReplaceRgch(0, 0, "Exodus", 6, null); Dictionary <int, ITsStrBldr> bldrs = ReflectionHelper.GetField(m_importer, "m_BTStrBldrs") as Dictionary <int, ITsStrBldr>; bldrs[1] = bldr; try { ReflectionHelper.CallMethod(m_importer, "ReportBTTextNotPartOfPara"); } catch (Exception e) { ScriptureUtilsException sue = e.InnerException as ScriptureUtilsException; Assert.IsFalse(sue.InterleavedImport); } }
public void GetTextRepresentation_twoParas() { CheckDisposed(); m_footnotePara.Contents.UnderlyingTsString = m_strFact.MakeString("Paragraph One", m_vernWs); // create second para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); // Set the paragraph style para.StyleRules = StyleUtils.ParaStyleTextProps("Note Exegesis Paragraph"); ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Paragraph Two", StyleUtils.CharStyleTextProps( "Foreign", m_wsUr)); para.Contents.UnderlyingTsString = bldr.GetString(); string result = m_footnote.GetTextRepresentation(); Assert.AreEqual(@"<FN><M>o</M><ShowMarker/><P><PS>Note General Paragraph</PS>" + @"<RUN WS='fr'>Paragraph One</RUN></P><P><PS>Note Exegesis Paragraph</PS>" + @"<RUN WS='ur' CS='Foreign'>Paragraph Two</RUN></P></FN>", result); }