Exemple #1
0
        public void ExportNotationParagraphs_WritingSystems()
        {
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                                   ScrStyleNames.NormalParagraph);
            IScrScriptureNote note = m_scrInMemoryCache.AddAnnotation(para, new BCVRef(01001001),
                                                                      NoteType.Translator, "This is some text with espa\u00F1ol.");
            TsStringAccessor tssaDisc = ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents;
            ITsStrBldr       bldr     = tssaDisc.UnderlyingTsString.GetBldr();

            bldr.SetProperties(bldr.Length - 8, bldr.Length - 1,
                               StyleUtils.CharStyleTextProps(null, InMemoryFdoCache.s_wsHvos.Es));
            tssaDisc.UnderlyingTsString = bldr.GetString();

            StringWriter  stream = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(stream);

            m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0,
                                       "ExportNotationParagraphs_WritingSystems");

            ReflectionHelper.SetField(m_exporter, "m_writer", writer);
            ReflectionHelper.CallMethod(m_exporter, "ExportNotationParagraphs", note.DiscussionOA,
                                        "notationDiscussion");
            Assert.AreEqual("<notationDiscussion><para xml:lang=\"en\">" +
                            "<span>This is some text with </span>" +
                            "<span xml:lang=\"es\">espa\u00F1ol</span>" +
                            "<span>.</span>" +
                            "</para></notationDiscussion>", stream.ToString());
        }
Exemple #2
0
        public void ExportNotationParagraphs_Hyperlink()
        {
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                                   ScrStyleNames.NormalParagraph);
            IScrScriptureNote note = m_scrInMemoryCache.AddAnnotation(para, new BCVRef(01001001),
                                                                      NoteType.Translator, "This is some text with a hyperlink!");
            TsStringAccessor tssaDisc = ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents;

            tssaDisc.MarkTextAsHyperlink(tssaDisc.Length - 10, tssaDisc.Length - 1,
                                         "http://www.myspace.com", m_stylesheet);

            StringWriter  stream = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(stream);

            m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0,
                                       "ExportNotationParagraphs_Hyperlink");

            ReflectionHelper.SetField(m_exporter, "m_writer", writer);
            ReflectionHelper.CallMethod(m_exporter, "ExportNotationParagraphs", note.DiscussionOA,
                                        "notationDiscussion");
            Assert.AreEqual("<notationDiscussion><para xml:lang=\"en\">" +
                            "<span>This is some text with a </span>" +
                            "<a href=\"http://www.myspace.com\">hyperlink</a>" +
                            "<span>!</span>" +
                            "</para></notationDiscussion>", stream.ToString());
        }
Exemple #3
0
        public void MoveNext_ImplicitChapter1AndVerse1()
        {
            CheckDisposed();

            IScrSection      sectionCur = ScrSection.CreateSectionWithEmptyParas(m_genesis, 0, false);
            TsStringAccessor heading    = ((StTxtPara)sectionCur.HeadingOA.ParagraphsOS[0]).Contents;
            ITsStrBldr       strBldr    = heading.UnderlyingTsString.GetBldr();

            strBldr.Replace(0, strBldr.Length, "My aching head!", null);
            heading.UnderlyingTsString = strBldr.GetString();

            TsStringAccessor content = ((StTxtPara)sectionCur.ContentOA.ParagraphsOS[0]).Contents;

            strBldr = content.UnderlyingTsString.GetBldr();
            strBldr.Replace(0, strBldr.Length, "Verse One. ", null);
            content.UnderlyingTsString = strBldr.GetString();

            sectionCur.AdjustReferences();

            ScrTxtPara  stPara   = new ScrTxtPara(Cache, sectionCur.ContentOA.ParagraphsOS.HvoArray[0]);
            ScrVerseSet verseSet = new ScrVerseSet(stPara);

            // Iterate through the verses in the paragraph
            ScrVerse verse;

            Assert.IsTrue(verseSet.MoveNext());
            verse = (ScrVerse)verseSet.Current;
            Assert.AreEqual("Verse One. ", verse.Text.Text);
            Assert.AreEqual(01001001, verse.StartRef);
            Assert.AreEqual(01001001, verse.EndRef);

            Assert.IsFalse(verseSet.MoveNext());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given a Scripture section, this method returns the index of the paragraph containing
        /// the requested verse and the position of the character immediately following the
        /// verse number in that paragraph. If an exact match isn't found, the closest
        /// approximate place is found.
        /// </summary>
        /// <param name="section">The section whose paragraphs will be searched</param>
        /// <param name="targetRef">The reference being sought</param>
        /// <param name="ihvoPara"></param>
        /// <param name="ichPosition"></param>
        /// <remarks>Currently, this does NOT attempt to find a close match, but some day it
        /// should</remarks>
        /// ------------------------------------------------------------------------------------
        protected void FindVerseNumber(ScrSection section, ScrReference targetRef,
                                       out int ihvoPara, out int ichPosition)
        {
            ihvoPara    = 0;
            ichPosition = 0;

            bool fChapterFound = ((ScrReference)section.VerseRefStart).Chapter == targetRef.Chapter;

            foreach (StTxtPara para in section.ContentOA.ParagraphsOS)
            {
                TsStringAccessor contents = para.Contents;
                TsRunInfo        tsi;
                ITsTextProps     ttpRun;
                int ich = 0;
                while (ich < contents.Text.Length)
                {
                    // Get props of current run.
                    ttpRun = contents.UnderlyingTsString.FetchRunInfoAt(ich, out tsi);
                    // See if it is our verse number style.
                    if (fChapterFound)
                    {
                        if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
                        {
                            // The whole run is the verse number. Extract it.
                            string sVerseNum = contents.Text.Substring(tsi.ichMin,
                                                                       tsi.ichLim - tsi.ichMin);
                            int startVerse, endVerse;
                            ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
                            if (targetRef.Verse >= startVerse && targetRef.Verse <= endVerse)
                            {
                                ihvoPara    = para.OwnOrd - 1;
                                ichPosition = tsi.ichLim;
                                return;
                            }
                            // TODO: Currently, this does NOT attempt to detect when we have
                            // a close match
                        }
                    }
                    // See if it is our chapter number style.
                    else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                    {
                        // Assume the whole run is the chapter number. Extract it.
                        string sChapterNum = contents.Text.Substring(tsi.ichMin,
                                                                     tsi.ichLim - tsi.ichMin);
                        int nChapter = ScrReference.ChapterToInt(sChapterNum);
                        fChapterFound = (nChapter == targetRef.Chapter);
                    }
                    ich = tsi.ichLim;
                }
            }
        }
Exemple #5
0
        public void MoveNext_NonNumericChapter()
        {
            CheckDisposed();

            IScrSection      sectionCur = ScrSection.CreateSectionWithEmptyParas(m_genesis, 0, false);
            TsStringAccessor heading    = ((StTxtPara)sectionCur.HeadingOA.ParagraphsOS[0]).Contents;
            ITsStrBldr       strBldr    = heading.UnderlyingTsString.GetBldr();

            strBldr.Replace(0, strBldr.Length, "My aching head!", null);
            heading.UnderlyingTsString = strBldr.GetString();

            TsStringAccessor content = ((StTxtPara)sectionCur.ContentOA.ParagraphsOS[0]).Contents;

            strBldr = content.UnderlyingTsString.GetBldr();
            strBldr.Replace(0, strBldr.Length, "A",
                            StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, Cache.DefaultVernWs));
            strBldr.Replace(strBldr.Length, strBldr.Length, "Verse One. ",
                            StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            strBldr.Replace(strBldr.Length, strBldr.Length, "2",
                            StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber, Cache.DefaultVernWs));
            strBldr.Replace(strBldr.Length, strBldr.Length, " Verse Two. ",
                            StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            content.UnderlyingTsString = strBldr.GetString();

            sectionCur.AdjustReferences();

            ScrTxtPara stPara = new ScrTxtPara(Cache, sectionCur.ContentOA.ParagraphsOS.HvoArray[0]);

            ScrVerseSet verseSet = new ScrVerseSet(stPara);

            // Iterate through the verses in the paragraph
            ScrVerse verse;

            Assert.IsTrue(verseSet.MoveNext());
            verse = (ScrVerse)verseSet.Current;
            Assert.AreEqual("AVerse One. ", verse.Text.Text);
            Assert.AreEqual(01001001, verse.StartRef);
            Assert.AreEqual(01001001, verse.EndRef);

            Assert.IsTrue(verseSet.MoveNext());
            verse = (ScrVerse)verseSet.Current;
            Assert.AreEqual("2 Verse Two. ", verse.Text.Text);
            Assert.AreEqual(01001002, verse.StartRef);
            Assert.AreEqual(01001002, verse.EndRef);

            Assert.IsFalse(verseSet.MoveNext());
        }
Exemple #6
0
        public void ExportNotationParagraphs_Basic()
        {
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo);
            StTxtPara   para    = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                                   ScrStyleNames.NormalParagraph);
            IScrScriptureNote note = m_scrInMemoryCache.AddAnnotation(para, new BCVRef(01001001),
                                                                      NoteType.Translator, "This is some basic text.");
            TsStringAccessor tssaDisc = ((StTxtPara)note.DiscussionOA.ParagraphsOS[0]).Contents;

            StringWriter  stream = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(stream);

            m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0,
                                       "ExportNotationParagraphs_Basic");

            ReflectionHelper.SetField(m_exporter, "m_writer", writer);
            ReflectionHelper.CallMethod(m_exporter, "ExportNotationParagraphs", note.DiscussionOA,
                                        "notationDiscussion");
            Assert.AreEqual("<notationDiscussion><para xml:lang=\"en\">" +
                            "<span>This is some basic text.</span>" +
                            "</para></notationDiscussion>", stream.ToString());
        }
Exemple #7
0
        public void TwoBts()
        {
            CheckDisposed();

            m_importer.Settings.ImportBackTranslation = true;

            // initialize - process a \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Vernacular ID Text", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("verse text", @"\v");

            // verify state of NormalParaStrBldr
            Assert.AreEqual(3, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "1", ScrStyleNames.ChapterNumber);
            VerifyBldrRun(1, "1", ScrStyleNames.VerseNumber);
            VerifyBldrRun(2, "verse text", null);

            // ************** End of Scripture file *********************

            // ******* Back translation in default Analysis WS **********
            m_importer.CurrentImportDomain        = ImportDomain.BackTrans;
            m_importer.DummySoWrapper.m_CurrentWs = m_wsAnal;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Ignore this", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("back trans", @"\v");

            // ******* Back translation in Spanish WS **********
            int wsSpanish = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("es");

            m_importer.DummySoWrapper.m_CurrentWs = wsSpanish;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("EXO Ignora esto tambien", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("retrotraduccion", @"\v");

            // ************** finalize **************
            m_importer.FinalizeImport();

            IScrBook book = new ScrBook(Cache, m_importer.ScrBook.Hvo);

            Assert.AreEqual("Vernacular ID Text", book.IdText);
            Assert.AreEqual(1, book.SectionsOS.Count);
            IScrSection section = book.SectionsOS[0];

            Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count);
            Assert.AreEqual(02001001, section.VerseRefMin);
            Assert.AreEqual(02001001, section.VerseRefMax);
            StTxtPara para = (StTxtPara)section.ContentOA.ParagraphsOS[0];

            Assert.AreEqual("11verse text", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans = para.GetBT();
            // Check default analysis BT
            TsStringAccessor bt = trans.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual("11back trans", bt.Text);
            Assert.AreEqual(3, bt.UnderlyingTsString.RunCount);
            Assert.AreEqual("back trans", bt.UnderlyingTsString.get_RunText(2));
            ITsTextProps ttpRun3 = bt.UnderlyingTsString.get_Properties(2);

            Assert.AreEqual(null,
                            ttpRun3.GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            int nVar;

            Assert.AreEqual(m_wsAnal,
                            ttpRun3.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar));

            // Check Spanish BT
            bt = trans.Translation.GetAlternative(wsSpanish);
            Assert.AreEqual("11retrotraduccion", bt.Text);
            Assert.AreEqual(3, bt.UnderlyingTsString.RunCount);
            Assert.AreEqual("retrotraduccion", bt.UnderlyingTsString.get_RunText(2));
            ttpRun3 = bt.UnderlyingTsString.get_Properties(2);
            Assert.AreEqual(null,
                            ttpRun3.GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            Assert.AreEqual(wsSpanish,
                            ttpRun3.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar));
        }
Exemple #8
0
        public void VerseBeyondVersificationMax()
        {
            CheckDisposed();

            m_importer.Settings.ImportBackTranslation = true;

            // initialize - process a \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(45, 7, 25);
            m_importer.TextSegment.LastReference  = new BCVRef(45, 7, 25);
            m_importer.ProcessSegment("", @"\id");

            m_importer.ProcessSegment("", @"\c");

            // ************** process two new paragraphs *********************
            m_importer.ProcessSegment("", @"\p");
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("Front text for verse25", @"\vt");
            m_importer.TextSegment.FirstReference = new BCVRef(45, 7, 26);
            m_importer.TextSegment.LastReference  = new BCVRef(45, 7, 26);
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("Front text for verse26", @"\vt");

            //// verify state of NormalParaStrBldr
            Assert.AreEqual(5, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "7", ScrStyleNames.ChapterNumber);
            VerifyBldrRun(1, "25", ScrStyleNames.VerseNumber);
            VerifyBldrRun(2, "Front text for verse25", null);
            VerifyBldrRun(3, "26", ScrStyleNames.VerseNumber);
            VerifyBldrRun(4, "Front text for verse26", null);


            // ************** End of Scripture file *********************

            // ******* Back translation in default Analysis WS **********
            m_importer.CurrentImportDomain        = ImportDomain.BackTrans;
            m_importer.DummySoWrapper.m_CurrentWs = m_wsAnal;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(45, 7, 26);
            m_importer.TextSegment.LastReference  = new BCVRef(45, 7, 26);
            m_importer.ProcessSegment("", @"\id");
            m_importer.ProcessSegment("", @"\c");

            // ************** process two new paragraphs *********************
            m_importer.ProcessSegment("", @"\p");
            m_importer.ProcessSegment("", @"\v");
            m_importer.ProcessSegment("Back text for verse", @"\vt");

            // ************** finalize **************
            m_importer.FinalizeImport();

            IScrBook book = new ScrBook(Cache, m_importer.ScrBook.Hvo);
            // Check section 1
            StTxtPara para = (StTxtPara)book.SectionsOS[0].ContentOA.ParagraphsOS[0];

            Assert.AreEqual("725Front text for verse2526Front text for verse26", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans = para.GetBT();
            // Check default analysis BT
            TsStringAccessor bt = trans.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual("726Back text for verse", bt.Text);
            Assert.AreEqual(3, bt.UnderlyingTsString.RunCount);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 0,
                                  "7", ScrStyleNames.ChapterNumber, m_scr.Cache.DefaultAnalWs);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 1,
                                  "26", ScrStyleNames.VerseNumber, m_scr.Cache.DefaultAnalWs);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 2,
                                  "Back text for verse", null, m_scr.Cache.DefaultAnalWs);
        }
Exemple #9
0
        public void DoubleSectionHeadMarker()
        {
            CheckDisposed();

            m_importer.Settings.ImportBackTranslation = true;

            // initialize - process a \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            // ************** process the two-line section head ***************
            m_importer.ProcessSegment("Front Section head 1.1", @"\s");
            m_importer.ProcessSegment("Front Section head 1.2", @"\s");

            //// verify state of NormalParaStrBldr
            Assert.AreEqual(1, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "Front Section head 1.1\u2028Front Section head 1.2", null);

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("Some verse", @"\v");

            // ************** process another two-line section head **************
            m_importer.ProcessSegment("Front Section head 2.1", @"\s");
            m_importer.ProcessSegment("Front Section head 2.2", @"\s");

            //// verify state of NormalParaStrBldr
            Assert.AreEqual(1, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "Front Section head 2.1\u2028Front Section head 2.2", null);

            // ************** End of Scripture file *********************

            // ******* Back translation in default Analysis WS **********
            m_importer.CurrentImportDomain        = ImportDomain.BackTrans;
            m_importer.DummySoWrapper.m_CurrentWs = m_wsAnal;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            // ************** process the BT of section head 1 **************
            m_importer.ProcessSegment("Back Section head 1.1", @"\s");
            m_importer.ProcessSegment("Back Section head 1.2", @"\s");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("Algun versiculo", @"\v");

            // ************** process the BT of section head 2 **************
            m_importer.ProcessSegment("Back Section head 2.1", @"\s");
            m_importer.ProcessSegment("Back Section head 2.2", @"\s");

            // ************** finalize **************
            m_importer.FinalizeImport();

            IScrBook book = new ScrBook(Cache, m_importer.ScrBook.Hvo);
            // Check section 1
            StTxtPara para = (StTxtPara)book.SectionsOS[0].HeadingOA.ParagraphsOS[0];

            Assert.AreEqual("Front Section head 1.1\u2028Front Section head 1.2", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans = para.GetBT();
            // Check default analysis BT
            TsStringAccessor bt = trans.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual("Back Section head 1.1\u2028Back Section head 1.2", bt.Text);
            Assert.AreEqual(1, bt.UnderlyingTsString.RunCount);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 0,
                                  "Back Section head 1.1\u2028Back Section head 1.2", null, m_scr.Cache.DefaultAnalWs);

            // Check section 2
            para = (StTxtPara)book.SectionsOS[1].HeadingOA.ParagraphsOS[0];
            Assert.AreEqual("Front Section head 2.1\u2028Front Section head 2.2", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            trans = para.GetBT();
            // Check default analysis BT
            bt = trans.Translation.AnalysisDefaultWritingSystem;
            Assert.AreEqual("Back Section head 2.1\u2028Back Section head 2.2", bt.Text);
            Assert.AreEqual(1, bt.UnderlyingTsString.RunCount);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 0,
                                  "Back Section head 2.1\u2028Back Section head 2.2", null, m_scr.Cache.DefaultAnalWs);
        }
Exemple #10
0
        public void TitleSecondary()
        {
            CheckDisposed();

            m_importer.Settings.ImportBackTranslation = true;

            // initialize - process a \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            // ************** process the title secondary style *********************
            m_importer.ProcessSegment("Title secondary", @"\st");
            m_importer.ProcessSegment("main title", @"\mt");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("verse text", @"\v");

            // verify state of NormalParaStrBldr
            Assert.AreEqual(3, m_importer.NormalParaStrBldr.RunCount);
            VerifyBldrRun(0, "1", ScrStyleNames.ChapterNumber);
            VerifyBldrRun(1, "1", ScrStyleNames.VerseNumber);
            VerifyBldrRun(2, "verse text", null);

            // ************** End of Scripture file *********************

            // ******* Back translation in default Analysis WS **********
            m_importer.CurrentImportDomain        = ImportDomain.BackTrans;
            m_importer.DummySoWrapper.m_CurrentWs = m_wsAnal;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            // ************** process the title secondary style *********************
            m_importer.ProcessSegment("Title secondary BT", @"\st");
            m_importer.ProcessSegment("main title BT", @"\mt");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("back trans", @"\v");

            // ******* Back translation in Spanish WS **********
            int wsSpanish = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("es");

            m_importer.DummySoWrapper.m_CurrentWs = wsSpanish;

            // process an \id segment to establish a book
            m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 0, 0);
            m_importer.ProcessSegment("", @"\id");

            // ************** process a chapter *********************
            m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1);
            m_importer.TextSegment.LastReference  = new BCVRef(2, 1, 1);
            m_importer.ProcessSegment("", @"\c");
            Assert.AreEqual(1, m_importer.Chapter);

            // ************** process v1 verse 1 *********************
            m_importer.ProcessSegment("retrotraduccion", @"\v");


            // ************** finalize **************
            m_importer.FinalizeImport();

            IScrBook  book = new ScrBook(Cache, m_importer.ScrBook.Hvo);
            StTxtPara para = (StTxtPara)book.TitleOA.ParagraphsOS[0];

            Assert.AreEqual("Title secondary\u2028main title", para.Contents.Text);
            Assert.AreEqual(1, para.TranslationsOC.Count);
            ICmTranslation trans = para.GetBT();
            // Check default analysis BT
            TsStringAccessor bt = trans.Translation.AnalysisDefaultWritingSystem;

            Assert.AreEqual("Title secondary BT\u2028main title BT", bt.Text);
            Assert.AreEqual(2, bt.UnderlyingTsString.RunCount);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 0, "Title secondary BT",
                                  "Title Secondary", m_scr.Cache.DefaultAnalWs);
            AssertEx.RunIsCorrect(bt.UnderlyingTsString, 1, "\u2028main title BT",
                                  null, m_scr.Cache.DefaultAnalWs);
        }
Exemple #11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This is called by a view when the views code is about to delete a paragraph. We
        /// need to save the back translations by moving them to whatever paragraph the deleted
        /// one is merging with.
        /// </summary>
        /// <param name="selHelper">The selection helper</param>
        /// <param name="hvoObject">Paragraph to be deleted</param>
        /// <param name="hvoOwner">StText that owns the para</param>
        /// <param name="tag">flid in which para is owned</param>
        /// <param name="ihvo">index of paragraph in text</param>
        /// <param name="fMergeNext"><c>true</c> if this paragraph is merging with the
        /// following paragraph.</param>
        /// ------------------------------------------------------------------------------------
        public virtual void AboutToDelete(SelectionHelper selHelper, int hvoObject,
                                          int hvoOwner, int tag, int ihvo, bool fMergeNext)
        {
            CheckDisposed();

            if (tag != (int)StText.StTextTags.kflidParagraphs)
            {
                return;
            }

            StTxtPara paraToDelete = new StTxtPara(m_cache, hvoObject);

            // If the paragraph that is being deleted is empty, then do not attempt to save a back
            // translation for it.
            if (paraToDelete.Contents.Text == null)
            {
                return;
            }

            // ihvoTop is either the paragraph before the IP or the first paragraph in a range selection
            int ihvoTop           = ihvo - 1;
            int hvoOwnerSurviving = hvoOwner;

            // Figure out what is being deleted and what is staying.
            // NOTE: it is possible that the selection is no longer valid. This is ok for our purposes here,
            // since all information we access here is already retrieved and stored in member variables of
            // SelectionHelper.
            if (selHelper.IsRange)
            {
                int          paraLev      = selHelper.GetLevelForTag(tag, SelectionHelper.SelLimitType.Top);
                SelLevInfo[] rgSelLevInfo = selHelper.GetLevelInfo(SelectionHelper.SelLimitType.Top);
                ihvoTop = rgSelLevInfo[paraLev].ihvo;
                if (paraLev + 1 < rgSelLevInfo.Length)
                {
                    hvoOwnerSurviving = rgSelLevInfo[paraLev + 1].hvo;
                }
                int ihvoBottom = selHelper.GetLevelInfoForTag(tag, SelectionHelper.SelLimitType.Bottom).ihvo;

                // Pretty sure that if we get here top will NEVER equal bottom.
                Debug.Assert(ihvoTop != ihvoBottom || hvoOwnerSurviving != hvoOwner);
                if (hvoOwnerSurviving == hvoOwner)
                {
                    if (ihvoTop == ihvoBottom)
                    {
                        return;
                    }

                    int ichEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo == ihvoBottom && ichEnd == paraToDelete.Contents.Length)
                    {
                        return;
                    }
                    // No need to merge because entire paragraph (with its contents) is going away.
                    if (ihvo > ihvoTop && ihvo < ihvoBottom)
                    {
                        return;
                    }
                }
            }

            // Determine the surviving paragraph.
            StText    text = new StText(m_cache, hvoOwnerSurviving);
            StTxtPara paraSurviving;

            if (fMergeNext)
            {
                // when merging with next and there are no more paragraphs, then the BT can be discarded.
                if (text.ParagraphsOS.Count < ihvo + 1)
                {
                    return;
                }
                // The surviving paragraph will be the one following the one that is deleted
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvo + 1];
            }
            else
            {
                // If we are deleting the first paragraph in the surviving text, the BT should
                // also be deleted, so we're done.
                if (ihvo == 0 && hvoOwnerSurviving == hvoOwner)
                {
                    return;
                }
                // The surviving paragraph will be the top one in the selection
                paraSurviving = (StTxtPara)text.ParagraphsOS[ihvoTop];
            }

            ITsStrBldr bldr;
            ILgWritingSystemFactory wsf;
            List <int> writingSystems = GetWsList(out wsf);

            foreach (ICmTranslation transToDelete in paraToDelete.TranslationsOC)
            {
                // Find or create surviving translation of the same type.
                ICmTranslation transSurviving = paraSurviving.GetOrCreateTrans(transToDelete.TypeRA);

                // Merge back translations of the surviving and paragraph to be deleted for each writing system
                foreach (int ws in writingSystems)
                {
                    TsStringAccessor tssAccToDelete = transToDelete.Translation.GetAlternative(ws);
                    if (tssAccToDelete.Text != null)
                    {
                        TsStringAccessor tssAccSurviving = transSurviving.Translation.GetAlternative(ws);
                        bldr = tssAccSurviving.UnderlyingTsString.GetBldr();

                        // If the surviving paragraph ends with white space of the paragraph to delete
                        // begins with white space, add white space.
                        string textSurviving = bldr.Text;
                        ILgCharacterPropertyEngine charPropEng = m_cache.UnicodeCharProps;
                        if (textSurviving != null &&
                            !charPropEng.get_IsSeparator(textSurviving[textSurviving.Length - 1]) &&
                            !charPropEng.get_IsSeparator(tssAccToDelete.Text[0]))
                        {
                            bldr.ReplaceRgch(textSurviving.Length, textSurviving.Length, " ", 1, null);
                        }

                        int cch = bldr.Length;
                        bldr.ReplaceTsString(cch, cch, tssAccToDelete.UnderlyingTsString);
                        tssAccSurviving.UnderlyingTsString = bldr.GetString();
                    }
                }
            }
        }
Exemple #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given a Scripture section, this method returns the index of the paragraph containing
        /// the requested verse and the position of the character immediately following the
        /// verse number in that paragraph. If an exact match isn't found, the closest
        /// approximate place is found.
        /// </summary>
        /// <param name="section">The section whose paragraphs will be searched</param>
        /// <param name="targetRef">The reference being sought</param>
        /// <param name="iPara">The index of the paragraph where the verse was found</param>
        /// <param name="ichPosition">The index of the character immediately following the
        /// verse number in that paragraph</param>
        /// ------------------------------------------------------------------------------------
        protected void FindVerseNumber(ScrSection section, ScrReference targetRef, out int iPara,
                                       out int ichPosition)
        {
            iPara       = 0;
            ichPosition = 0;

            bool fChapterFound = (BCVRef.GetChapterFromBcv(section.VerseRefMin) == targetRef.Chapter);

            foreach (StTxtPara para in section.ContentOA.ParagraphsOS)
            {
                TsStringAccessor contents = para.Contents;
                if (para.Contents.Text == null)
                {
                    continue;
                }
                TsRunInfo    tsi;
                ITsTextProps ttpRun;
                int          ich = 0;
                while (ich < contents.UnderlyingTsString.Length)
                {
                    // Get props of current run.
                    ttpRun = contents.UnderlyingTsString.FetchRunInfoAt(ich, out tsi);
                    // See if it is our verse number style.
                    if (fChapterFound)
                    {
                        if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
                        {
                            // The whole run is the verse number. Extract it.
                            string sVerseNum = contents.Text.Substring(tsi.ichMin,
                                                                       tsi.ichLim - tsi.ichMin);
                            int startVerse, endVerse;
                            ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
                            if ((targetRef.Verse >= startVerse && targetRef.Verse <= endVerse) ||
                                targetRef.Verse < startVerse)
                            {
                                ichPosition = tsi.ichLim;
                                return;
                            }
                        }
                    }
                    // See if it is our chapter number style.
                    else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                    {
                        try
                        {
                            // Assume the whole run is the chapter number. Extract it.
                            string sChapterNum = contents.Text.Substring(tsi.ichMin,
                                                                         tsi.ichLim - tsi.ichMin);
                            fChapterFound = (ScrReference.ChapterToInt(sChapterNum) == targetRef.Chapter);
                        }
                        catch (ArgumentException)
                        {
                            // ignore runs with invalid Chapter numbers
                        }
                    }
                    ich = tsi.ichLim;
                }
                iPara++;
            }
            iPara = 0;             // Couldn't find it.
        }