public void AdjustSectionReferences_DeleteCascadeChangeToNextsection()
        {
            // add section and paragraph
            IScrSection section1 = AddSectionToMockedBook(m_book);
            IScrTxtPara para1    = AddParaToMockedSectionContent(section1,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "This is verse one. ", null);
            AddRunToMockedPara(para1, "2", ScrStyleNames.VerseNumber);

            IScrSection section2 = AddSectionToMockedBook(m_book);
            IScrTxtPara para2    = AddParaToMockedSectionContent(section2,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para2, "This is more text. ", null);
            AddRunToMockedPara(para2, "3", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse three. ", null);

            // Test deleting the verse number at the end of para1
            ITsStrBldr strBuilder = para1.Contents.GetBldr();

            strBuilder.ReplaceRgch(21, 22, "", 0, para1.Contents.get_PropertiesAt(3));             // delete verse number 2
            para1.Contents = strBuilder.GetString();

            // verify the results
            Assert.AreEqual(40001001, section1.VerseRefMin);
            Assert.AreEqual(40001001, section1.VerseRefEnd);
            Assert.AreEqual(40001001, section1.VerseRefMax);
            Assert.AreEqual(40001001, section2.VerseRefMin);
            Assert.AreEqual(40001001, section2.VerseRefStart);
            Assert.AreEqual(40001003, section2.VerseRefMax);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public void ConvertChapterVerseNumbersTest_EmptyChapterNumber()
        {
            CheckDisposed();

            // Add paragraph with empty chapter number run.
            StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(m_exodus.SectionsOS[0].Hvo,
                                                                              ScrStyleNames.ChapterNumber);
            ITsPropsFactory propFact         = TsPropsFactoryClass.Create();
            ITsTextProps    ttpChapterNumber = propFact.MakeProps(ScrStyleNames.ChapterNumber,
                                                                  (int)InMemoryFdoCache.s_wsHvos.Fr, 0);
            ITsStrBldr bldr = para.Contents.UnderlyingTsString.GetBldr();

            bldr.SetProperties(0, 0, ttpChapterNumber);
            para.Contents.UnderlyingTsString = bldr.GetString();

            ScriptureProperties dlg = new ScriptureProperties(Cache, m_stylesheet, null, true);

            char bengaliZero = '\u09e6';
            char bengaliNine = (char)((int)bengaliZero + 9);

            // test arabic->bengali when there is a paragraph with an empty chapter number run.
            // It should complete without crashing.
            ScriptDigitConversionTest(bengaliZero, bengaliNine, dlg);
            // test bengali->arabic
            ScriptDigitConversionTest('0', '9', dlg);
        }
        public void TwoSegsPerVerse()
        {
            string pc1    = "Das Buch ist rot. ";
            string pc2    = "Das Maedchen ist schoen.";
            string verse1 = "9";
            string pc3    = "Der Herr ist gross.";
            string pc4    = "Ich spreche nicht viel Deutsch.";
            string verse2 = "10";
            string pc5    = "Was ist das?";
            string pc6    = "Wie gehts?";

            ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5 + pc6, m_wsVern).GetBldr();

            bldr.SetStrPropValue(pc1.Length + pc2.Length, pc1.Length + pc2.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            int ichEndV1 = pc1.Length + pc2.Length + verse1.Length + pc3.Length + pc4.Length;

            bldr.SetStrPropValue(ichEndV1, ichEndV1 + verse2.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            m_para.Contents = bldr.GetString();
            using (ParagraphParser pp = new ParagraphParser(m_para))
            {
                List <int> eosIndexes;
                var        segments = pp.CollectSegments(m_para.Contents, out eosIndexes);
                Assert.AreEqual(8, segments.Count);
                Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 0));
                Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 1));
                Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 3));
                Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 4));
                Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 6));
                Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 7));
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
 /// -------------------------------------------------------------------------------------
 /// <summary>
 /// For any footnote in the specified book whose first paragraph has a run marked with
 /// the Note Target Reference style, remove that run and set the property on the footnote
 /// to display the target reference in the footnote view.
 /// </summary>
 /// <param name="book">The ScrBook whose footnotes are to be searched</param>
 /// -------------------------------------------------------------------------------------
 private void RemoveDirectUsesOfFootnoteTargetRef(IScrBook book)
 {
     foreach (IStFootnote footnote in book.FootnotesOS)
     {
         // Probably only need to worry about first para
         if (footnote.ParagraphsOS.Count == 0)
         {
             continue;
         }
         IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0];
         ITsString  tss  = para.Contents;
         ITsStrBldr bldr = null;
         for (int iRun = 0; iRun < tss.RunCount; iRun++)
         {
             ITsTextProps props = tss.get_Properties(iRun);
             string       style = props.GetStrPropValue(
                 (int)FwTextPropType.ktptNamedStyle);
             if (style == ScrStyleNames.FootnoteTargetRef)
             {
                 if (bldr == null)
                 {
                     bldr = tss.GetBldr();
                 }
                 bldr.Replace(tss.get_MinOfRun(iRun), tss.get_LimOfRun(iRun), string.Empty, null);
             }
         }
         if (bldr != null)
         {
             para.Contents = bldr.GetString();
         }
     }
 }
        public void OneSegPerVerse()
        {
            string pc1    = "Das Buch ist rot. ";
            string verse1 = "9";
            string pc2    = "Der Herr ist gross.";
            string verse2 = "10";
            string pc3    = "Ich spreche nicht viel Deutsch.";

            ITsStrBldr bldr = m_tsf.MakeString(pc1 + verse1 + pc2 + verse2 + pc3, m_wsVern).GetBldr();

            bldr.SetStrPropValue(pc1.Length, pc1.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            int ichV2 = pc1.Length + verse1.Length + pc2.Length;

            bldr.SetStrPropValue(ichV2, ichV2 + verse2.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            m_para.Contents = bldr.GetString();
            using (ParagraphParser pp = new ParagraphParser(m_para))
            {
                List <int> eosIndexes;
                var        segments = pp.CollectSegments(m_para.Contents, out eosIndexes);
                Assert.AreEqual(5, segments.Count);
                Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 0));
                Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 2));
                Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 4));
            }
        }
        /// <summary>
        /// Glosses must be marked as proclitics or enclitics.  See LT-8288.
        /// </summary>
        private ITsString GetMarkedGloss(int hvo, int tag, int ws)
        {
            ITsString tss      = m_sda.get_MultiStringAlt(hvo, tag, ws);
            string    sPrefix  = null;
            string    sPostfix = null;

            if (m_guidMorphType == m_mmtEnclitic.Guid)
            {
                sPrefix  = m_mmtEnclitic.Prefix;
                sPostfix = m_mmtEnclitic.Postfix;
            }
            else if (m_guidMorphType == m_mmtProclitic.Guid)
            {
                sPrefix  = m_mmtProclitic.Prefix;
                sPostfix = m_mmtProclitic.Postfix;
            }
            if (sPrefix != null || sPostfix != null)
            {
                ITsStrBldr tsb = tss.GetBldr();
                if (!String.IsNullOrEmpty(sPrefix))
                {
                    tsb.Replace(0, 0, sPrefix, null);
                }
                if (!String.IsNullOrEmpty(sPostfix))
                {
                    tsb.Replace(tsb.Length, tsb.Length, sPostfix, null);
                }
                tss = tsb.GetString();
            }
            return(tss);
        }
예제 #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void DoIt()
        {
            m_rootb.DataAccess.BeginUndoTask(RootSiteStrings.ksUndoCorrectSpelling, RootSiteStrings.ksRedoSpellingChange);
            ITsString tssInput;

            if (m_wsAlt == 0)
            {
                tssInput = m_rootb.DataAccess.get_StringProp(m_hvoObj, m_tag);
            }
            else
            {
                tssInput = m_rootb.DataAccess.get_MultiStringAlt(m_hvoObj, m_tag, m_wsAlt);
            }
            ITsStrBldr bldr = tssInput.GetBldr();

            bldr.ReplaceTsString(m_ichMin, m_ichLim, m_tssReplacement);
            if (m_wsAlt == 0)
            {
                m_rootb.DataAccess.SetString(m_hvoObj, m_tag, bldr.GetString());
            }
            else
            {
                m_rootb.DataAccess.SetMultiStringAlt(m_hvoObj, m_tag, m_wsAlt, bldr.GetString());
            }
            m_rootb.PropChanged(m_hvoObj, m_tag, m_wsAlt, 1, 1);
            m_rootb.DataAccess.EndUndoTask();
        }
        public void AdjustSectionReferences_TrimFirstVerseToSingleDigit()
        {
            // add section and paragraph
            IScrSection section1 = AddSectionToMockedBook(m_book);
            IScrTxtPara para1    = AddParaToMockedSectionContent(section1,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para1, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para1, "23", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "This is verse one. ", null);

            IScrSection section2 = AddSectionToMockedBook(m_book);
            IScrTxtPara para2    = AddParaToMockedSectionContent(section2,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para2, "24", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is more text. ", null);
            AddRunToMockedPara(para2, "25", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse three.", null);

            // Test deleting the verse number at the start of para2
            ITsStrBldr strBuilder = para2.Contents.GetBldr();
            int        cch        = strBuilder.Length;

            strBuilder.ReplaceRgch(1, cch - 1, "", 0,
                                   para2.Contents.get_Properties(1));
            para2.Contents = strBuilder.GetString();

            // verify the results
            Assert.AreEqual(40001023, section1.VerseRefMin);
            Assert.AreEqual(40001023, section1.VerseRefMax);
            Assert.AreEqual(40001023, section2.VerseRefMin);
            Assert.AreEqual(40001023, section2.VerseRefMax);
        }
        public void AdjustSectionReferences_InsertedBadVerseNumAtBeginning()
        {
            // add section and paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IScrTxtPara para    = AddParaToMockedSectionContent(section,
                                                                ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para, "24", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "This is verse one. ", null);
            AddRunToMockedPara(para, "25", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para, "This is verse twentyfive. ", null);

            // Test inserting an extra digit into the first verse number making it 224
            ITsStrBldr strBuilder = para.Contents.GetBldr();

            // replace the current verse number with 224 to simulate editing
            strBuilder.ReplaceRgch(0, 2, "224", 3, para.Contents.get_PropertiesAt(0));
            para.Contents = strBuilder.GetString();

            // verify the results
            Assert.AreEqual(40001001, section.VerseRefMin);
            Assert.AreEqual(40001025, section.VerseRefMax);
            Assert.AreEqual(40001001, section.VerseRefStart);
            Assert.AreEqual(40001025, section.VerseRefEnd);
        }
        public void AdjustSectionReferences_InsertedVerseAtBeginning_MiddleOfBook()
        {
            // add section and paragraph
            IScrSection section1 = AddSectionToMockedBook(m_book);
            IScrTxtPara para1    = AddParaToMockedSectionContent(section1,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "This is verse one. ", null);

            IScrSection section2 = AddSectionToMockedBook(m_book);
            IScrTxtPara para2    = AddParaToMockedSectionContent(section2,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para2, "24", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse one. ", null);
            AddRunToMockedPara(para2, "25", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse twentyfive. ", null);

            // Test inserting an additional verse in the first paragraph of the second section
            ITsStrBldr strBuilder = para2.Contents.GetBldr();

            strBuilder.ReplaceRgch(0, 0, "14", 2, para2.Contents.get_Properties(0));
            string sVerseText = "This is a new verse. ";

            strBuilder.ReplaceRgch(2, 2, sVerseText, sVerseText.Length,
                                   para2.Contents.get_Properties(1));
            para2.Contents = strBuilder.GetString();

            // verify the results
            Assert.AreEqual(40001001, section1.VerseRefMin);
            Assert.AreEqual(40001001, section1.VerseRefMax);
            Assert.AreEqual(40001014, section2.VerseRefMin);
            Assert.AreEqual(40001025, section2.VerseRefMax);
        }
        public void LeadingPunctuation()
        {
            ITsStrFactory tsf   = TsStrFactoryClass.Create();
            string        test1 = "?This is a question with special punctuation?";
            ITsString     tss   = tsf.MakeString(test1, m_wsEn);

            m_para.Contents = tss;
            List <int> results;
            var        segments = m_pp.CollectSegments(tss, out results);

            VerifyBreaks(new int[] { test1.Length - 1 }, results, "leading QM");
            Assert.AreEqual(1, segments.Count);
            VerifySegment(segments[0], 0, test1.Length, m_para, "leading QM");

            // Now try leading punctuation following a verse number.
            ITsStrBldr bldr  = tss.GetBldr();
            string     verse = "5 ";

            bldr.Replace(0, 0, verse, null);
            bldr.SetStrPropValue(0, 1, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            ITsString tssMultiV = bldr.GetString();

            m_para.Contents = tssMultiV;
            segments        = m_pp.CollectSegments(tssMultiV, out results);
            VerifyBreaks(new int[] { verse.Length, tssMultiV.Length - 1 },
                         results, "leading verse and QM");
            Assert.AreEqual(2, segments.Count);
            VerifySegment(segments[0], 0, verse.Length, m_para, "first seg of leading verse and QM");
            VerifySegment(segments[1], verse.Length, tssMultiV.Length, m_para, "second seg of leading verse and QM");
        }
예제 #14
0
        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 &lt;brackets&gt;</RUN>" +
                                 @"<TRANS WS='de'><RUN WS='de'>German BT in &lt;brackets&gt;</RUN></TRANS>" +
                                 @"<TRANS WS='es'><RUN WS='es'>Spanish BT in &lt;brackets&gt;</RUN></TRANS></P></FN>";
            IStFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().CreateFromStringRep(m_book,
                                                                                                                footnoteRep, 0, "Note Marker");

            CompareFootnote(footnote);
        }
예제 #15
0
        GetHyperlinksInFolder_changeOfPlatform_helper(string origPathSetInDatabase,
                                                      string newPlatformStyleLookupPath, string newPlatformStyleResultToVerify)
        {
            // When running on Windows, call "foreign"="Linux" and "current"="Windows".
            // When running on Linux, call "foreign"="Windows" and "current"="Linux".

            var entry = MakeEntry("kick", "hit with foot");
            // Foreign-style path is set by a foreign-platform FieldWorks
            var        link      = origPathSetInDatabase;
            ITsString  tss       = TsStringUtils.MakeString("This here is a link", Cache.DefaultAnalWs);
            ITsStrBldr bldr      = tss.GetBldr();
            var        linkStyle = MakeStyle("testStyle");

            StringServices.MarkTextInBldrAsHyperlink(bldr, 5, 9, link, linkStyle);
            entry.LiteralMeaning.AnalysisDefaultWritingSystem = bldr.GetString();

            // Now current-platform FieldWorks opens and reads the database created by a
            // foreign-platform FieldWorks, and needs to respond to currentOS-style path lookups
            // that match foreign-style stored paths.
            var hyperlinkInfo = StringServices.GetHyperlinksInFolder(Cache, newPlatformStyleLookupPath);

            // There should be one hyperlink, and with the proper path.
            Assert.That(hyperlinkInfo, Has.Count.EqualTo(1),
                        "Should have found hyperlink despite different platform style path being used during lookup");
            var relPath = newPlatformStyleResultToVerify;

            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning, Cache.DefaultAnalWs, 5, 9, relPath);
            return(new Tuple <List <StringServices.LinkOccurrence>, ILexEntry>(hyperlinkInfo, entry));
        }
예제 #16
0
        public void FixOrcsWithoutProps_OrcForMissingObject()
        {
            CheckDisposed();

            IScrBook  exodus = CreateExodusData();
            StTxtPara para   = AddPara(exodus.SectionsOS[2]);

            AddVerse(para, 2, 3, "ORC is here, you see, my friend.");

            // Update the paragraph contents to include the picture
            ITsStrBldr    tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
            ITsStrFactory factory   = TsStrFactoryClass.Create();

            StringUtils.InsertOrcIntoPara(Guid.NewGuid(), FwObjDataTypes.kodtOwnNameGuidHot,
                                          tsStrBldr, 11, 11, 0);
            para.Contents.UnderlyingTsString = tsStrBldr.GetString();

            TeScrInitializer scrInit = new TestTeScrInitializer(Cache);
            List <string>    report  = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps");

            VerifyNoOrphanedFootnotes();
            VerifyResourceForFixedOrphans();

            Assert.AreEqual(1, report.Count);
            Assert.AreEqual("EXO 2:3 - Deleted corrupted footnote marker or picture anchor", report[0]);

            Assert.AreEqual(0, exodus.FootnotesOS.Count);
        }
        public void MarkBtAsUnfinishedOnVernacularEdit()
        {
            // add scripture section and paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IScrTxtPara para    = AddParaToMockedSectionContent(section,
                                                                ScrStyleNames.IntroParagraph);

            AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para, "This is the verse.", null);

            // Create a back translation paragraph.
            int            wsBT   = Cache.DefaultAnalWs;
            ICmTranslation btpara = AddBtToMockedParagraph(para, wsBT);

            AddRunToMockedTrans(btpara, wsBT, "My Back Translation", null);

            // set the state of the back translation to "finished".
            btpara.Status.SetAnalysisDefaultWritingSystem(BackTranslationStatus.Finished.ToString());

            // change the vernacular paragraph
            ITsStrBldr strBuilder = para.Contents.GetBldr();

            strBuilder.ReplaceRgch(0, 1, "5", 1, para.Contents.get_Properties(0));
            para.Contents = strBuilder.GetString();

            // make sure the back translation is changed to "unfinished".
            string checkState = BackTranslationStatus.Unfinished.ToString();

            Assert.AreEqual(checkState, btpara.Status.AnalysisDefaultWritingSystem.Text);
        }
예제 #18
0
        /// ------------------------------------------------------------------------------------
        /// <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());
        }
예제 #19
0
        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");
        }
예제 #20
0
        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");
        }
예제 #21
0
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs);

            ICmTranslation trans = contentPara.GetOrCreateBT();

            m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(2, helper.IchAnchor, "IP should be after chapter and verse number.");
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidContent,
                            m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
예제 #22
0
        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");
        }
예제 #23
0
        // Generate a suitable string representation of a WfiGloss.
        // Todo: finish implementing (add the gloss!)
        static internal ITsString MakeGlossStringRep(IWfiGloss wg, LcmCache fdoCache, bool fUseStyleSheet)
        {
            ITsStrBldr tsb = TsStringUtils.MakeStrBldr();
            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());
        }
        public void AdjustSectionReferences_DeletedChapterNumAtBeginning()
        {
            // add section and paragraph
            IScrSection section1 = AddSectionToMockedBook(m_book);
            IScrTxtPara para1    = AddParaToMockedSectionContent(section1,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para1, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para1, "This is verse one. ", null);

            IScrSection section2 = AddSectionToMockedBook(m_book);
            IScrTxtPara para2    = AddParaToMockedSectionContent(section2,
                                                                 ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(para2, "2", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(para2, "24", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse one. ", null);
            AddRunToMockedPara(para2, "25", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(para2, "This is verse twentyfive. ", null);

            // Test deleting the chapter number from the second para
            ITsStrBldr strBuilder = para2.Contents.GetBldr();

            strBuilder.ReplaceRgch(0, 1, "", 0,
                                   para2.Contents.get_Properties(1));
            para2.Contents = strBuilder.GetString();

            // verify the results
            Assert.AreEqual(40001001, section1.VerseRefMin);
            Assert.AreEqual(40001001, section1.VerseRefMax);
            Assert.AreEqual(40001024, section2.VerseRefMin);
            Assert.AreEqual(40001025, section2.VerseRefMax);
        }
예제 #25
0
        /// ------------------------------------------------------------------------------------
        /// <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());
        }
예제 #26
0
 /// <summary>
 /// Sets up the beginning of the tag with its (localizable) symbol.
 /// </summary>
 /// <param name="builder">A TsString builder.</param>
 private void StartTagSetup(ITsStrBldr builder)
 {
     // How this works depends on the directionality of both the vernacular and
     // analysis writing systems.  This does assume that nobody localizes [ and ]
     // to something like ] and [!  I'm not sure those strings should be localizable.
     // See LT-9551.
     if (RightToLeft)
     {
         if (m_fAnalRtl)
         {
             builder.Replace(0, 0, ITextStrings.ksEndTagSymbol, null);
         }
         else
         {
             builder.Replace(builder.Length, builder.Length, ITextStrings.ksEndTagSymbol, null);
         }
     }
     else
     {
         if (m_fAnalRtl)
         {
             builder.Replace(builder.Length, builder.Length, ITextStrings.ksStartTagSymbol, null);
         }
         else
         {
             builder.Replace(0, 0, ITextStrings.ksStartTagSymbol, null);
         }
     }
 }
예제 #27
0
        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);
            }
        }
예제 #28
0
        public void FixOrcsWithoutProps_OrphanedFootnoteAndValidPicture()
        {
            CheckDisposed();

            IScrBook  exodus = CreateExodusData();
            StTxtPara para   = AddPara(exodus.SectionsOS[2]);

            AddVerse(para, 2, 3, "ORC is here, you see, my friend.");

            // Update the paragraph contents to include the picture
            ITsStrBldr    tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
            ITsStrFactory factory   = TsStrFactoryClass.Create();
            CmPicture     pict      = new CmPicture(Cache, "c:\\junk.jpg",
                                                    factory.MakeString("Test picture", Cache.DefaultVernWs),
                                                    StringUtils.LocalPictures);

            Assert.IsNotNull(pict);
            pict.InsertOwningORCIntoPara(tsStrBldr, 11, 0);
            para.Contents.UnderlyingTsString = tsStrBldr.GetString();

            // Update the paragraph contents to include the (orphaned) footnote marker
            CreateFootnote(exodus, 1, 0, 1, 19, ScrStyleNames.CrossRefFootnoteParagraph, true);

            TeScrInitializer scrInit = new TestTeScrInitializer(Cache);
            List <string>    report  = (List <string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps");

            VerifyNoOrphanedFootnotes();
            VerifyResourceForFixedOrphans();

            Assert.AreEqual(1, report.Count);
            Assert.AreEqual("EXO 1:2 - Deleted corrupted footnote marker or picture anchor", report[0]);

            Assert.AreEqual(0, exodus.FootnotesOS.Count);
        }
예제 #29
0
        /// ------------------------------------------------------------------------------------
        /// <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 = TsStringUtils.MakeStrBldr();

            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);
        }
예제 #30
0
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToNowhere()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs);

            ICmTranslation trans = contentPara.GetOrCreateBT();
            ITsStrBldr     bldr  = trans.Translation.get_String(Cache.DefaultAnalWs).GetBldr();

            TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 2, 2, Cache.DefaultAnalWs);
            trans.Translation.set_String(Cache.DefaultAnalWs, bldr.GetString());

            m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
예제 #31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="StTxtParaBldr"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public StTxtParaBldr(FdoCache cache)
		{
			System.Diagnostics.Debug.Assert(cache != null);
			m_cache = cache;

			ITsStrFactory tsStringFactory = TsStrFactoryClass.Create();
			m_ParaStrBldr = tsStringFactory.GetBldr();
		}
예제 #32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Marks the indicated text in the given string builder as a hyperlink.
		/// </summary>
		/// <param name="strBldr">The string builder.</param>
		/// <param name="ichStart">The index of the first character in the string builder which
		/// should be marked as hyperlink text.</param>
		/// <param name="ichLim">The "limit" index in the string builder indicating the end of
		/// the hyperlink text.</param>
		/// <param name="url">The URL that is the target of the hyperlink.</param>
		/// <param name="linkStyle">The style to use to mark the hyperlink.</param>
		/// ------------------------------------------------------------------------------------
		public static void MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart,
			int ichLim, string url, IStStyle linkStyle)
		{
			var propVal = Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName) + url;
			if (!linkStyle.InUse && linkStyle is StStyle)
				((StStyle)linkStyle).InUse = true;
			strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptNamedStyle, linkStyle.Name);
			strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptObjData, propVal);
		}
예제 #33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="ws"></param>
		/// <param name="bldr"></param>
		/// <param name="styleId"></param>
		/// <param name="ichOffset"></param>
		/// <param name="reference"></param>
		/// ------------------------------------------------------------------------------------
		public BtFootnoteBldrInfo(int ws, ITsStrBldr bldr, string styleId, int ichOffset,
			BCVRef reference)
		{
			this.ws = ws;
			this.bldr = bldr;
			this.styleId = styleId;
			this.ichOffset = ichOffset;
			this.reference = new BCVRef(reference);
		}
예제 #34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="StTxtParaBldr"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public StTxtParaBldr(FdoCache cache)
		{
			System.Diagnostics.Debug.Assert(cache != null);
			m_cache = cache;

			ITsStrFactory tsStringFactory = cache.TsStrFactory;
			m_ParaStrBldr = tsStringFactory.GetBldr();

			// Give the builder a default WS so a created string will be legal. If any text
			// is added to the builder, it should replace this WS with the correct WS.
			m_ParaStrBldr.Replace(0, 0, null, StyleUtils.CharStyleTextProps(null, cache.DefaultVernWs));
		}
예제 #35
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert (or replace) an ORC run in a string builder.
		/// </summary>
		/// <param name="guid">The GUID representing the embedded object</param>
		/// <param name="objDataType">The type of embedding</param>
		/// <param name="tsStrBldr">The TS string builder</param>
		/// <param name="ichMin">The position at which the object is to be inserted</param>
		/// <param name="ichLim">If replacing an existing ORC (or other text), this is the Lim
		/// position (otherwise, should be set equal to ichMin)</param>
		/// <param name="ws">The ID of the writing system to use for the inserted run, or 0
		/// to leave unspecified</param>
		/// ------------------------------------------------------------------------------------
		public static void InsertOrcIntoPara(Guid guid, FwObjDataTypes objDataType,
			ITsStrBldr tsStrBldr, int ichMin, int ichLim, int ws)
		{
			byte[] objData = MiscUtils.GetObjData(guid, (byte)objDataType);
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
				objData, objData.Length);
			if (ws != 0)
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
			tsStrBldr.Replace(ichMin, ichLim, new string(kchObject, 1),
				propsBldr.GetTextProps());
		}
예제 #36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Marks the indicated text in the given string builder as a hyperlink.
		/// </summary>
		/// <param name="strBldr">The string builder.</param>
		/// <param name="ichStart">The index of the first character in the string builder which
		/// should be marked as hyperlink text.</param>
		/// <param name="ichLim">The "limit" index in the string builder indicating the end of
		/// the hyperlink text.</param>
		/// <param name="url">The URL that is the target of the hyperlink.</param>
		/// <param name="linkStyle">The style to use to mark the hyperlink.</param>
		/// <param name="linkedFilesRootDir">The project's LinkedFilesRootDir</param>
		/// <returns>The value returned is used to create a CmFile if it represents a file path.</returns>
		/// ------------------------------------------------------------------------------------
		public static string MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart,
			int ichLim, string url, IStStyle linkStyle, string linkedFilesRootDir)
		{
			var relativeUrl = LinkedFilesRelativePathHelper.GetRelativeLinkedFilesPath(url, linkedFilesRootDir);
			if (string.IsNullOrEmpty(relativeUrl))
			{
				MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, url, linkStyle);
				return url;
			}
			else
			{
				MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, relativeUrl, linkStyle);
				return relativeUrl;
			}
		}
예제 #37
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Append a picture to the end of the paragraph using the given writing system.
		/// </summary>
		/// <param name="ws">given writing system</param>
		/// <param name="strBldr">The string builder for the paragraph being composed</param>
		/// ------------------------------------------------------------------------------------
		public void AppendPicture(int ws, ITsStrBldr strBldr)
		{
			// Make a TsTextProps with the relevant object data and the same ws as its
			// context.
			byte[] objData = MiscUtils.GetObjData(m_cache.GetGuidFromId(this.Hvo),
				(byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
				objData, objData.Length);
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);

			// Insert the orc with the resulting properties.
			strBldr.Replace(strBldr.Length, strBldr.Length,
				new string(StringUtils.kchObject, 1), propsBldr.GetTextProps());
		}
예제 #38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert picture (ORC with the GUID in the properties) into the builder
		/// for the paragraph
		/// </summary>
		/// <param name="tsStrBldr">A string builder for the paragraph that is to contain the
		/// picture ORC</param>
		/// <param name="ich">The 0-based character offset into the paragraph</param>
		/// <param name="ws">The writing system id</param>
		/// ------------------------------------------------------------------------------------
		public void InsertOwningORCIntoPara(ITsStrBldr tsStrBldr, int ich, int ws)
		{
			StringUtils.InsertOrcIntoPara(Guid, FwObjDataTypes.kodtGuidMoveableObjDisp,
				tsStrBldr, ich, ich, ws);
		}
예제 #39
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			if (m_cpe != null && Marshal.IsComObject(m_cpe))
				Marshal.ReleaseComObject(m_cpe);
			m_cpe = null;
			m_settings = null;
			m_SOWrapper = null;
			m_sSegmentText = null;
			m_sMarker = null;
			m_styleProxy = null;
			m_vernParaStyleProxy = null;
			m_vernTextProps = null;
			m_analTextProps = null;
			m_styleProxies = null;
			m_notesStyleProxies = null;
			m_lastPara = null;
			m_BookTitleParaProxy = null;
			m_DefaultFootnoteParaProxy = null;
			m_TsStringFactory = null;
			m_BTFootnoteStrBldr = null;
			m_CurrParaPictures = null;
			m_CurrParaFootnotes = null;
			m_BTPendingPictures = null;
			m_CurrBTFootnote = null;
			m_sBtFootnoteParaStyle = null;
			m_BtFootnoteStrBldrs = null;
			m_PendingAnnotations = null;
			m_BTfootnoteIndex = null;
			m_sCharStyleEndMarker = null;
			m_sFootnoteEndMarker = null;
			m_sCharStyleBeginMarker = null;
			m_sFootnoteBeginMarker = null;
			m_scrTranslatorAnnotationDef = null;

			base.Dispose(disposing);
		}
예제 #40
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Helper function appends a run to the given string builder
		/// </summary>
		/// <param name="strBldr"></param>
		/// <param name="text"></param>
		/// <param name="ws"></param>
		/// <param name="charStyle"></param>
		/// ------------------------------------------------------------------------------------
		private void AddRunToStrBldr(ITsStrBldr strBldr, string text, int ws, string charStyle)
		{
			strBldr.Replace(strBldr.Length, strBldr.Length, text,
				StyleUtils.CharStyleTextProps(charStyle, ws));
		}
예제 #41
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts a footnote by inserting the footnote marker into the given string builder
		/// and creating a new <see cref="StFootnote"/> with the footnote marker set to the
		/// same marker. Note that this method does <em>not</em> insert any paragraphs into the
		/// footnote (the given style is only used to determine what kind of footnote it will
		/// be -- it is not actually applied.
		/// </summary>
		/// <param name="book">The book that the footnote is being added to</param>
		/// <param name="styleId">The styleId that tells us whether this is a general footnote
		/// or a cross-reference</param>
		/// <param name="iInsertAt">Zero-based index of the position in the sequence of
		/// footnotes where the new footnote is to be inserted</param>
		/// <param name="tsStrBldr">String builder for the paragraph being built</param>
		/// <param name="ich">Character index in paragraph where footnote is to be inserted
		/// </param>
		/// <returns>The newly created Footnote object</returns>
		/// ------------------------------------------------------------------------------------
		public static ScrFootnote InsertFootnoteAt(IScrBook book, string styleId, int iInsertAt,
			ITsStrBldr tsStrBldr, int ich)
		{
			// If the marker should be calculated, just insert an 'a' as a placeholder. It
			// will be changed in the RecalculateFootnoteMarkers() method.
			string sMarker = book.Cache.LangProject.TranslatedScriptureOA.GetFootnoteMarker(styleId);
			return InsertFootnoteAt(book, iInsertAt, tsStrBldr, ich, sMarker);
		}
예제 #42
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add any pending verse or chapter number as a run to the Back Translation for the
		/// given writing system.
		/// </summary>
		/// <param name="sVerseRef"></param>
		/// <param name="ws">Writing system ID</param>
		/// <param name="bldr">String builder for the BT</param>
		/// ------------------------------------------------------------------------------------
		private void AddPendingVerseAndChapterNumsToBackTrans(string sVerseRef, int ws,
			ITsStrBldr bldr)
		{
			if (BtChapterNumPending(m_wsCurrBtPara) &&
				m_vernParaStyleProxy != null &&
				((m_vernParaStyleProxy.Context == ContextValues.Text && m_vernParaStyleProxy.Structure == StructureValues.Body) ||
				m_vernParaStyleProxy.Context == ContextValues.EndMarker) &&
				!m_fInFootnote)
			{
				AddDropChapterNumToPara(bldr, ws);
			}

			if (BtVerseNumPending(ws))
			{
				// If previous marker is a verse number, add space between verse markers
				ITsStrBldr prevBldr = null;
				if (m_BTStrBldrs.ContainsKey(m_wsCurrBtPara))
					prevBldr = m_BTStrBldrs[m_wsCurrBtPara];
				if (PrevRunIsVerseNumber(prevBldr))
				{
					AddTextToPara(" ", StyleUtils.CharStyleTextProps(null, ws), bldr);
				}
				AddTextToPara(sVerseRef,
					StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, ws), bldr);
				m_btPendingVerseNumAdded.Add(ws);
			}
		}
예제 #43
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Remove all reference ORCs for the specified builder
		/// </summary>
		/// <param name="tssBldr">the builder</param>
		/// <param name="guidToRemove">guid of the ORC to remove</param>
		/// <returns>the ich location of the ORC that was deleted, or -1 if no ORC was
		/// deleted</returns>
		/// ------------------------------------------------------------------------------------
		public static int DeleteOrcFromBuilder(ITsStrBldr tssBldr, Guid guidToRemove)
		{
			Debug.Assert(guidToRemove != Guid.Empty);
			if (guidToRemove == Guid.Empty)
				return -1;

			int iRun = 0;
			Guid guid;
			while (iRun < tssBldr.RunCount)
			{
				guid = GetGuidFromRun(tssBldr.GetString(), iRun);

				if (guid == guidToRemove)
				{
					// ORC with same Guid found. Remove it.
					int ichMin, ichLim;
					TsRunInfo info;
					tssBldr.FetchRunInfo(iRun, out info);
					tssBldr.GetBoundsOfRun(iRun, out ichMin, out ichLim);
					ITsPropsBldr propsBldr = tssBldr.get_Properties(iRun).GetBldr();
					propsBldr.SetStrPropValue((int)FwTextPropType.ktptObjData, null);
					tssBldr.Replace(ichMin, ichLim, null, propsBldr.GetTextProps());
					return info.ichMin;
				}
				iRun++;
			}
			return -1;
		}
예제 #44
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add the given text and props as a new run to the end of the specified paragraph
		/// under construction.
		/// </summary>
		/// <param name="sText">Text to be appended to the paragraph being built</param>
		/// <param name="pttpProps">Properties (should contain only a named style) for the run
		/// of text to be added.</param>
		/// <param name="strbldr">String builder of paragraph being built</param>
		/// ------------------------------------------------------------------------------------
		protected void AddTextToPara(string sText, ITsTextProps pttpProps, ITsStrBldr strbldr)
		{
			// Don't bother trying to add empty runs. Also don't add runs consisting of a single
			// space if processing a marker that maps to a paragraph style.
			if (sText.Length > 0 &&
				(sText != " " || m_styleProxy.StyleType == StyleType.kstCharacter))
			{
				// send the text and props directly to the Builder, after first ensuring that
				// a ws is specified.
				int var;
				int ws = pttpProps.GetIntPropValues((int)FwTextPropType.ktptWs,
					out var);
				if (ws == -1)
				{
					ws = GetWsForContext(strbldr);
					ITsPropsBldr tpb = pttpProps.GetBldr();
					tpb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
					pttpProps = tpb.GetTextProps();
				}
				int cchLength = strbldr.Length;
				// Remove extra space.
				if (cchLength > 0 && UnicodeCharProps.get_IsSeparator(sText[0]))
				{
					string s = strbldr.GetChars(cchLength - 1, cchLength);
					if (UnicodeCharProps.get_IsSeparator(s[0]))
						sText = sText.Substring(1);
				}

				if (sText != string.Empty || cchLength == 0)
					strbldr.Replace(cchLength, cchLength, sText, pttpProps);
			}
		}
예제 #45
0
		/// <summary>
		/// Sets up the beginning of the tag with its (localizable) symbol.
		/// </summary>
		/// <param name="clen">The tag string length before.</param>
		/// <param name="builder">A TsString builder.</param>
		/// <returns>The tag string length after.</returns>
		private int StartTagSetup(int clen, ITsStrBldr builder)
		{
			// How this works depends on the directionality of both the vernacular and
			// analysis writing systems.  This does assume that nobody localizes [ and ]
			// to something like ] and [!  I'm not sure those strings should be localizable.
			// See LT-9551.
			if (RightToLeft)
			{
				if (m_fAnalRtl)
				{
					builder.Replace(0, 0, ITextStrings.ksEndTagSymbol, null);
					clen += ITextStrings.ksEndTagSymbol.Length;
				}
				else
				{
					builder.Replace(builder.Length, builder.Length, ITextStrings.ksEndTagSymbol, null);
					clen += ITextStrings.ksEndTagSymbol.Length;
				}
			}
			else
			{
				if (m_fAnalRtl)
				{
					builder.Replace(builder.Length, builder.Length, ITextStrings.ksStartTagSymbol, null);
					clen += ITextStrings.ksStartTagSymbol.Length;
				}
				else
				{
					builder.Replace(0, 0, ITextStrings.ksStartTagSymbol, null);
					clen += ITextStrings.ksStartTagSymbol.Length;
				}
			}
			return clen;
		}
예제 #46
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determine the writing system for the context. First use the WS of the para, if any
		/// (i.e., for BT paras); otherwise use the ws of the preceding segment, if any;
		/// otherwise use the default WS for the domain.
		/// </summary>
		/// <param name="strbldr">The string builder of the paragraph being built</param>
		/// <returns>HVO of writing system to be used</returns>
		/// ------------------------------------------------------------------------------------
		private int GetWsForContext(ITsStrBldr strbldr)
		{
			// Get the ws of the current paragraph.
			int ws = m_wsPara;
			if (ws <= 0)
			{
				// Get the ws from the preceding character(s).
				if (strbldr != null)
				{
					int cch = strbldr.Length;
					if (cch > 0)
					{
						ITsTextProps ttpCur = strbldr.get_PropertiesAt(cch - 1);
						int var;
						ws = ttpCur.GetIntPropValues((int)FwTextPropType.ktptWs,
							out var);
					}
				}
				if (ws <= 0)
				{
					// If all else fails, use the writing system appropriate for the
					// current IMPORT domain.
					ws = GetWsForImportDomain();
				}
			}
			return ws;
		}
예제 #47
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts the pending chapter number string into the beginning of a new paragraph,
		/// in proper location as a drop-cap.
		/// </summary>
		/// <param name="bldr">The string builder of the paragraph being built</param>
		/// <param name="ws">HVO of writing system to be used for chapter number (and
		/// preceding space if this is an intra-paragraph chapter number). Can be 0 to use
		/// vernacular or negative to get the correct WS for the context.</param>
		/// ------------------------------------------------------------------------------------
		protected void AddDropChapterNumToPara(ITsStrBldr bldr, int ws)
		{
			Debug.Assert(ScrStyleNames.ChapterNumber ==
				m_ttpChapterNumber.GetStrPropValue((int)FwTextPropType.ktptNamedStyle));

			// Compute the properties for the chapter number. If this is in BT, ws will be
			// non-zero; we use the specified ws.
			ITsTextProps chapterNumProps = m_ttpChapterNumber;
			bool fVernacular = (ws == 0);
			if (!fVernacular)
			{
				ITsPropsBldr propsBldr = chapterNumProps.GetBldr();
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
				chapterNumProps = propsBldr.GetTextProps();
			}

			// If inserting this chapter number in the middle of an existing paragraph, put in a
			// space if necessary.
			int cchBldr = bldr.Length;
			if (cchBldr > 0 && bldr.GetChars(cchBldr - 1, cchBldr) != " ")
			{
				ITsTextProps spaceProps = GetTextPropsWithWS(ws, bldr);
				AddTextToPara(" ", spaceProps, bldr);
			}

			// now insert the chapter number
			string sChapterNumber;
			if (fVernacular)
				sChapterNumber = m_scr.ConvertToString(m_nChapter);
			else
				sChapterNumber = m_nChapter.ToString();

			AddTextToPara(sChapterNumber, chapterNumProps, bldr);

			// clean up
			if (fVernacular)
				m_fChapterNumberPending = false;
			else
				m_btPendingChapterNumAdded.Add(ws);
		}
예제 #48
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add footnote callers to the string builder being built for the Back Translation and
		/// add BT to the footnotes themselves.
		/// </summary>
		/// <param name="ws">The writing system of the BT</param>
		/// <param name="bldr">The string builder for the back translation paragraph text
		/// </param>
		/// ------------------------------------------------------------------------------------
		private void AddPendingBTFootnotes(int ws, ITsStrBldr bldr)
		{
			int iFootnote = 0;
			foreach (BtFootnoteBldrInfo info in m_BtFootnoteStrBldrs)
			{
				if (info.ws == ws)
				{
					StFootnote footnote = FindCorrespondingFootnote(info.styleId, iFootnote);
					if (footnote == null)
					{
						throw new ScriptureUtilsException(
							SUE_ErrorCode.BackTransMissingVernFootnote,
							null, 0, info.bldr.Text,
							CurrentBook.BookId,
							info.reference.Chapter.ToString(),
							info.reference.Verse.ToString(),
							m_importDomain == ImportDomain.Main);
					}
					// Only allow one paragraph per footnote
					IStTxtPara footnotePara = (IStTxtPara)footnote.ParagraphsOS[0];
					ICmTranslation transl = footnotePara.GetOrCreateBT();
					transl.Translation.GetAlternative(ws).UnderlyingTsString =
						(info.bldr.Length == 0) ?
						m_TsStringFactory.MakeString(string.Empty, ws) :
						info.bldr.GetString();

					footnote.InsertRefORCIntoTrans(bldr, info.ichOffset + iFootnote, ws);
					iFootnote++;
				}
			}
		}
예제 #49
0
		private void ClearSquigglyLine(int hvo, ref ITsString tss, ref ITsStrBldr bldr)
		{
			bldr.SetIntPropValues(0, tss.Length,
				(int)FwTextPropType.ktptUnderline,
				(int)FwTextPropVar.ktpvEnum,
				(int)FwUnderlineType.kuntNone);
			m_vwCache.CacheUnicodeProp(hvo, kErrorMessage, "", 0);
		}
예제 #50
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Finalize the BT of the footnote, if any.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void EndBTFootnote()
		{
			Debug.Assert(m_fInFootnote);
			Debug.Assert(m_BTFootnoteStrBldr != null);
			ITsStrBldr strbldr = m_BTStrBldrs[m_wsCurrBtPara];
			// No need to assert, since the dictionary will
			// throw an exception if the key is not present.
			//Debug.Assert(strbldr != null);
			TrimTrailingSpace(m_BTFootnoteStrBldr);
			// If the last character in the paragraph is a separator, then insert the footnote
			// marker before it. (see TE-2431)
			int ichMarker = strbldr.Length;
			if (ichMarker > 0)
			{
				string s = strbldr.GetChars(ichMarker - 1, ichMarker);
				if (UnicodeCharProps.get_IsSeparator(s[0]))
					ichMarker--;
			}
			if (m_CurrBTFootnote != null)
			{
				// Don't support importing multi-para footnotes
				StTxtPara para = (StTxtPara)m_CurrBTFootnote.ParagraphsOS[0];

				ICmTranslation transl = para.GetOrCreateBT();
				transl.Translation.GetAlternative(m_wsCurrBtPara).UnderlyingTsString =
					(m_BTFootnoteStrBldr.Length == 0) ?
					m_TsStringFactory.MakeString(string.Empty, m_wsCurrBtPara) :
					m_BTFootnoteStrBldr.GetString();
				m_CurrBTFootnote.InsertRefORCIntoTrans(strbldr, ichMarker, m_wsCurrBtPara);
				m_CurrBTFootnote = null;
			}
			else
			{
				m_BtFootnoteStrBldrs.Add(new BtFootnoteBldrInfo(m_wsCurrBtPara, m_BTFootnoteStrBldr,
					m_sBtFootnoteParaStyle, ichMarker, m_currentRef));
			}
			m_fInFootnote = false;
			m_BTFootnoteStrBldr = null;
			//m_BtFootnoteStrBldrs.Clear();
			//m_currDomain = MarkerDomain.Default; // TODO: Do like EndFootnote
			if ((m_styleProxy.Domain & MarkerDomain.Footnote) == 0)
				m_currDomain &= ~MarkerDomain.Footnote;
		}
예제 #51
0
		/// <summary>
		/// Make red squiggly line, which starts at the point the validator
		/// determined it was wrong, ands at the end of the string.
		/// </summary>
		/// <remarks>
		/// We have it go to the end of the string,
		/// because the validator doesn't tell us where the problem ends.
		/// Since it didn't tell us, we don't try to guess.
		/// </remarks>
		/// <param name="hvo"></param>
		/// <param name="validatorMessage"></param>
		/// <param name="bldr"></param>
		private void MakeSquigglyLine(int hvo, string validatorMessage, ref ITsString tss,
			ref ITsStrBldr bldr)
		{

			//the validator message, unfortunately, maybe invalid XML if
			//	there were XML reserved characters in the environment.
			//until we get that fixed, at least don't crash, just draw squiggly under the entire word
			int pos = 0;
			try
			{
				XmlDocument xdoc = new XmlDocument();
				xdoc.LoadXml(validatorMessage);
				XmlAttribute posAttr = xdoc.DocumentElement.Attributes["pos"];
				pos = (posAttr != null) ? Convert.ToInt32(posAttr.Value) : 0;
			}
			catch (Exception)
			{
			}

			int len = tss.Length;
			if (pos >= len)
				pos = Math.Max(0, len - 1); // make sure something will show
			Color col = Color.Red;
			bldr.SetIntPropValues(pos, len, (int)FwTextPropType.ktptUnderline,
				(int)FwTextPropVar.ktpvEnum,
				(int)FwUnderlineType.kuntSquiggle);
			bldr.SetIntPropValues(pos, len, (int)FwTextPropType.ktptUnderColor,
				(int)FwTextPropVar.ktpvDefault,
				col.R + (col.B * 256 + col.G) * 256);

			//!!!NB: the code up to this point is, at least on the surface, identical to code in
			//PhEnvStrRepresentationSlice. so if you make a change here, go make it over there.
			//I assume this was done for lack of a commonplace to put the code?
			m_vwCache.CacheUnicodeProp(hvo, kErrorMessage, validatorMessage,
				validatorMessage.Length);
		}
예제 #52
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Process a back translation segment (duh)
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void ProcessBackTransSegment()
		{
			if (m_styleProxy.Function == FunctionValues.Chapter)
			{
				ProcessStartOfChapter();
				return;
			}

			if (!m_settings.ImportBackTranslation)
			{
				if (m_styleProxy.Function == FunctionValues.Verse)
					m_currentRef.Verse = SOWrapper.SegmentFirstRef.Verse;
				return;
			}

			if (CurrentBook == null)
			{
				// An interleaved BT paragraph is being imported for a book that
				// doesn't exist.
				throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernBook,
					null, null, ScrReference.NumberToBookCode(m_nBookNumber), null, null, true);
			}

			// Any non-end marker ends a character style
			if (m_context != ContextValues.EndMarker)
				EndCharStyle();

			ITsTextProps ttpBtSeg;
			bool fThisSegmentEndsAFootnote = false;
			if (m_importDomain == ImportDomain.Main)
			{
				int wsBT = BackTransWS;
				ttpBtSeg = GetBTProps(wsBT);
				if (wsBT != m_wsCurrBtPara &&
					(m_styleProxy.Domain != MarkerDomain.Default ||
					 m_styleProxy.StyleType == StyleType.kstParagraph))
				{
					// We're about to change which WS is being processed, so end any open character
					// style and/or footnote.
					EndCharStyle();
					if (m_fInFootnote)
					{
						EndFootnote();
						fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0;
					}
					m_wsCurrBtPara = wsBT;
				}
				else if (m_context == ContextValues.EndMarker)
					fThisSegmentEndsAFootnote = ProcessBTEndMarker();
				else if (m_fInFootnote && (m_currDomain & MarkerDomain.Footnote) != 0 &&
					m_styleProxy.StyleType == StyleType.kstParagraph)
				{
					EndFootnote();
					fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0;
				}
			}
			else
			{
				ttpBtSeg = GetBTProps(m_wsCurrBtPara);
				if (m_context == ContextValues.EndMarker)
					fThisSegmentEndsAFootnote = ProcessBTEndMarker();
			}

			if (m_importDomain == ImportDomain.BackTrans && ProcessingParagraphStart)
			{
				if (m_fInFootnote)
				{
					EndFootnote();
					fThisSegmentEndsAFootnote = (m_currDomain & MarkerDomain.Footnote) == 0;
				}

				AddBackTranslations();
			}

			if (!m_fInScriptureText && m_styleProxy.Context == ContextValues.Text &&
				m_styleProxy.Structure == StructureValues.Body)
			{
				// If this BT segment is a scripture body segment and we don't already have
				// a paragraph started, this file must have an implicit paragraph start,
				// so we initialize the member that holds the para style proxy for the
				// corresponding vernacular para so we'll have something reasonable to
				// look for when we go to find the corresponding para.
				if (m_BTStrBldrs.Count == 0 && m_importDomain == ImportDomain.BackTrans)
					m_vernParaStyleProxy = m_DefaultScrParaProxy;
				m_fInScriptureText = true;
				m_iNextBtPara = 0;
			}

			ITsStrBldr strbldr;

			if (m_BTStrBldrs.ContainsKey(m_wsCurrBtPara))
			{
				// We continue to use the existing BT para builder (for this WS) until the
				// vernacular paragraph -- and hence any BT paragraph(s) -- get written.
				// This means that if the BT contains spurious paragraph markers, their
				// segments will just be appended to the one-and-only BT paragraph (for this
				// WS) already being built.
				// TODO: Generate an error annotation.
				Debug.Assert(m_wsCurrBtPara != 0);
				strbldr = m_BTStrBldrs[m_wsCurrBtPara];
			}
			else
			{
				if (ProcessingParagraphStart)
				{
					if (m_importDomain == ImportDomain.Main)
					{
						if (m_vernParaStyleProxy == null || m_vernParaStyleProxy.StyleId == null)
						{
							// Got an unexpected BT paragraph segment. A BT paragraph came before
							// any vernacular paragraph in the import stream.
							int verse = SOWrapper.SegmentFirstRef.Verse;
							throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernPara,
								SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber,
								m_sMarker + " " + m_sSegmentText,
								m_fFoundABook ? CurrentBook.BookId : null,
								m_foundAChapter ? m_nChapter.ToString() : null,
								(verse > 0) ? verse.ToString() : null,
								true);
						}
						if (m_vernParaStyleProxy.StyleId != m_styleProxy.StyleId &&
							m_styleProxy.Style.Type != StyleType.kstCharacter)
						{
							// Got an unexpected BT paragraph segment. The paragraph style of the BT
							// paragraph doesn't match the style of the corresponding (i.e.,
							// preceding) vernacular paragraph.
							int verse = SOWrapper.SegmentFirstRef.Verse;
							throw new ScriptureUtilsException(SUE_ErrorCode.BackTransStyleMismatch,
								m_sMarker + " " + m_sSegmentText, string.Format(
								TeResourceHelper.GetResourceString("kstidBTStyleMismatchDetails"),
								m_styleProxy.StyleId, m_vernParaStyleProxy.StyleId),
								m_fFoundABook ? CurrentBook.BookId : null,
								m_foundAChapter ? m_nChapter.ToString() : null,
								(verse > 0) ? verse.ToString() : null, true);
						}
					}
					// Non-interleaved BT
					else
					{
						ProcessBtParaStart();
					}
				}
				strbldr  = TsStrBldrClass.Create();
				Debug.Assert(m_wsCurrBtPara != 0);
				m_BTStrBldrs[m_wsCurrBtPara] = strbldr;
			}

			if (m_context == ContextValues.Title)
			{
				SetBookName();
				if (m_fInBookTitle)
				{
					// We have another segment to add to the current title
					AddBookTitleSegment(strbldr, m_vernParaStyleProxy, ttpBtSeg);
					return;
				}
				m_fInBookTitle = true;
			}

			AddPendingVerseAndChapterNumsToBackTrans(GetVerseRefAsString(m_wsCurrBtPara), m_wsCurrBtPara, strbldr);

			if ((m_currDomain & MarkerDomain.Footnote) != 0 && !fThisSegmentEndsAFootnote)
			{
				if (m_BTFootnoteStrBldr == null)
				{
					if (m_fInFootnote)
					{
						// This BT footnote ends the vernacular footnote being built
						EndFootnote();
					}
					// remember that we are now processing a footnote
					SetInFootnote();
					CheckDataForFootnoteMarker();
					m_BTFootnoteStrBldr  = TsStrBldrClass.Create();
					m_sBtFootnoteParaStyle = (m_styleProxy.StyleType == StyleType.kstCharacter) ?
						m_DefaultFootnoteParaProxy.StyleId : m_styleProxy.StyleId;
					if (m_importDomain == ImportDomain.Main)
					{
						// If we aren't importing the vernacular... (TE-7445)
						if (!m_settings.ImportTranslation)
						{
							// attempt to find an existing vernacular paragraph that corresponds
							// to the back translation para.
							bool append;
							m_lastPara = FindCorrespondingVernParaForSegment(m_vernParaStyleProxy.Style,
								m_currentRef, out append);
							m_CurrParaFootnotes = (m_lastPara != null ?
								(m_lastPara as StTxtPara).GetFootnotes() : null);
						}

						m_CurrBTFootnote = FindCorrespondingFootnote(m_sBtFootnoteParaStyle);
						if (m_CurrBTFootnote == null)
						{
							int verse = SOWrapper.SegmentFirstRef.Verse;
							throw new ScriptureUtilsException(SUE_ErrorCode.BackTransMissingVernFootnote,
								SOWrapper.CurrentFileName, SOWrapper.CurrentLineNumber,
								m_sMarker + " " + m_sSegmentText,
								m_fFoundABook ? CurrentBook.BookId : null,
								m_foundAChapter ? m_nChapter.ToString(): null,
								(verse > 0) ? verse.ToString() : null,
								true);
						}
					}
					else
					{
						m_CurrBTFootnote = null;
					}
				}
				strbldr = m_BTFootnoteStrBldr;
				if (m_styleProxy.StyleType == StyleType.kstCharacter &&
					m_styleProxy.Context != ContextValues.EndMarker)
				{
					SetInCharacterStyle();
				}
			}
			else if (m_styleProxy.StyleType == StyleType.kstCharacter &&
				m_styleProxy.Function != FunctionValues.Verse)
			{
				SetInCharacterStyle();
			}

			// Add a line break between section head segments if we're processing
			// interleaved back translation section heading segments.
			if (m_fInSectionHeading && strbldr.Length > 0 &&
				ProcessingParagraphStart && m_importDomain == ImportDomain.Main)
			{
				AddTextToPara(kHardLineBreak, ttpBtSeg, strbldr);
			}

			AddTextToPara(m_sSegmentText, ttpBtSeg, strbldr);
		}
예제 #53
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Replaces the requested run of the given builder with an identical ORC but whose type
		/// is un-owned rather than owned. If the given run is not an ORC at all or is not
		/// owned, do nothing.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void TurnOwnedOrcIntoUnownedOrc(ITsStrBldr bldr, int irun)
		{
			string value = bldr.get_Properties(irun).ObjData();
			if (!string.IsNullOrEmpty(value) && value[0] == (char)FwObjDataTypes.kodtOwnNameGuidHot)
			{
				TsRunInfo runInfo;
				bldr.FetchRunInfo(irun, out runInfo);
				bldr.SetStrPropValue(runInfo.ichMin, runInfo.ichLim, (int)FwTextPropType.ktptObjData, (char)FwObjDataTypes.kodtNameGuidHot + value.Substring(1));
			}
		}
예제 #54
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Return text props that can be used for a run of "Default Paragraph Characters"
		/// having only a WS.
		/// </summary>
		/// <param name="ws">The explicit writing system to use, or 0 to use the default
		/// vernacular, or -1 to infer from the context</param>
		/// <param name="currBldr">The string builder, from which the WS might be inferred if
		/// not specified</param>
		/// ------------------------------------------------------------------------------------
		private ITsTextProps GetTextPropsWithWS(int ws, ITsStrBldr currBldr)
		{
			if (ws == m_wsVern || ws == 0)
				return m_vernTextProps;
			else if (ws == m_wsAnal)
				return m_analTextProps;
			if (ws < 0)
			{
				ws = GetWsForContext(currBldr);
			}
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
			return propsBldr.GetTextProps();
		}
예제 #55
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts a footnote by inserting the footnote marker into the given string builder
		/// and creating a new <see cref="StFootnote"/> with the footnote marker set to the
		/// same marker. This is the real workhorse, used mainly for internal implementation,
		/// but it's public so import can use it to create footnotes more efficiently.
		/// </summary>
		/// <param name="book">The book that the footnote is being added to</param>
		/// <param name="iInsertAt">Zero-based index of the position in the sequence of
		/// footnotes where the new footnote is to be inserted</param>
		/// <param name="tsStrBldr">String builder for the paragraph being built</param>
		/// <param name="ich">Character index in paragraph where footnote is to be inserted
		/// </param>
		/// <param name="sMarker">The marker to use (more or less)</param>
		/// <returns>The newly created Footnote object</returns>
		/// ------------------------------------------------------------------------------------
		public static ScrFootnote InsertFootnoteAt(IScrBook book, int iInsertAt,
			ITsStrBldr tsStrBldr, int ich, string sMarker)
		{
			FdoCache cache = book.Cache;
			// TODO (TimS): When we have a place in the DB to store the owning para of a footnote
			// we need to pass in the para and then store it in the footnote (TE-2885)
			System.Diagnostics.Debug.Assert(book != null);
			System.Diagnostics.Debug.Assert(tsStrBldr.Length >= ich);
			IScripture scr = cache.LangProject.TranslatedScriptureOA;

			// Determine the appropriate writing system for the marker
			int ws;
			if (tsStrBldr.Length > 0)
			{
				int nDummy;
				// Use the writing system of the run where the footnote marker
				// is being inserted.
				ws = (tsStrBldr.get_PropertiesAt(ich)).GetIntPropValues(
					(int)FwTextPropType.ktptWs, out nDummy);
			}
			else
			{
				// Otherwise, use the default vernacular writing system. This will only
				// happen when a footnote is being inserted at the beginning of an empty
				// string. It's unlikely, but we deal with it.
				ws = cache.LangProject.DefaultVernacularWritingSystem;
			}

			ScrFootnote footnote = CreateScrFootnote(book, iInsertAt, ref sMarker, cache, ws);

			// Insert the owning ORC into the paragraph
			footnote.InsertOwningORCIntoPara(tsStrBldr, ich, ws);

			return footnote;
		}
예제 #56
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determine whether the previous run is Verse Number.
		/// </summary>
		/// <param name="bldr">string builder</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public bool PrevRunIsVerseNumber(ITsStrBldr bldr)
		{
			CheckDisposed();

			if (bldr == null)
				return false;

			if (bldr.Length == 0) // Nothing has been added to builder yet
				return false;

			ITsTextProps propsOfLastRun = bldr.get_Properties(bldr.RunCount - 1);

			return (propsOfLastRun.GetStrPropValue((int)FwTextPropType.ktptNamedStyle)
				== ScrStyleNames.VerseNumber);
		}
			private void AddComboItems(ref int hvoEmptyGloss, ITsStrBldr tsb, IWfiAnalysis wa)
			{
				IList<int> wsids = m_sandbox.m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidWordGloss);
				foreach (IWfiGloss gloss in wa.MeaningsOC)
				{
					int glossCount = 0;

					foreach (int ws in wsids)
					{
						ITsString nextWsGloss = gloss.Form.get_String(ws);
						if (nextWsGloss.Length > 0)
						{
							// Append a comma if there are more glosses.
							if (glossCount > 0)
								tsb.Replace(tsb.Length, tsb.Length, ", ", null);

							// Append a Ws label if there are more than one Ws.
							if (wsids.Count > 1)
							{
								tsb.ReplaceTsString(tsb.Length, tsb.Length, WsListManager.WsLabel(m_caches.MainCache, ws));
								tsb.Replace(tsb.Length, tsb.Length, " ", null);
							}
							int oldLen = tsb.Length;
							tsb.ReplaceTsString(oldLen, oldLen, nextWsGloss);
							int color = (int)CmObjectUi.RGB(Color.Blue);
							tsb.SetIntPropValues(oldLen, tsb.Length, (int)FwTextPropType.ktptForeColor,
								(int)FwTextPropVar.ktpvDefault, color);
							glossCount++;
						}
					}
					// (LT-1428) If we find an empty gloss, use this hvo for "New word gloss" instead of 0.
					if (glossCount == 0 && wsids.Count > 0)
					{
						hvoEmptyGloss = gloss.Hvo;
						ITsPropsBldr tpbUserWs = TsPropsBldrClass.Create();
						tpbUserWs.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsUser);
						tsb.Replace(tsb.Length, tsb.Length, ITextStrings.ksEmpty, tpbUserWs.GetTextProps());
					}

					ComboList.Items.Add(new HvoTssComboItem(gloss.Hvo, tsb.GetString()));
					tsb.Clear();
				}
			}
예제 #58
0
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		protected virtual void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
			}
			if (m_cpe != null)
			{
				if (Marshal.IsComObject(m_cpe))
					Marshal.ReleaseComObject(m_cpe);
				m_cpe = null;
			}
			m_cache = null;
			m_ParaStyle = null;
			m_ParaStrBldr = null;
			m_ParaProps = null;

			m_isDisposed = true;
		}
예제 #59
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add a hard line break to separate this segment from the previous one. Then insert
		/// this segment as a new run.
		/// </summary>
		/// <param name="bldr">The STRING builder.</param>
		/// <param name="titleParaStyleProxy">The paragraph style proxy of the current title
		/// paragraph.</param>
		/// <param name="props">The text props to use for hard line break character and also
		/// paragraph text if current segment is a paragraph segment.</param>
		/// ------------------------------------------------------------------------------------
		private void AddBookTitleSegment(ITsStrBldr bldr,
			IParaStylePropsProxy titleParaStyleProxy, ITsTextProps props)
		{
			// Add a hard line break, if we have text
			if (bldr.Length > 0)
			{
				// First trim trailing space if necessary
				string s = bldr.Text;
				if (UnicodeCharProps.get_IsSeparator(s[s.Length - 1]))
					bldr.Replace(s.Length - 1, s.Length, null, null);

				AddTextToPara(kHardLineBreak, props, bldr);
			}
			if (m_styleProxy == titleParaStyleProxy)
				AddTextToPara(m_sSegmentText, props, bldr);
			else
				AddTextToPara(m_sSegmentText, m_styleProxy.TsTextProps, bldr);
		}
예제 #60
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Trims the last character from the given string builder if it's a separator
		/// </summary>
		/// <param name="bldr">The string builder</param>
		/// ------------------------------------------------------------------------------------
		private void TrimTrailingSpace(ITsStrBldr bldr)
		{
			int length = bldr.Length;
			if (length == 0)
				return;
			string s = bldr.GetChars(length - 1, length);
			if (UnicodeCharProps.get_IsSeparator(s[0]))
			{
				// remove the trailing space from the builder
				bldr.Replace(length - 1, length, null, null);
			}
		}