示例#1
0
        public void FindNextBackTrans_SectionContentToTitle()
        {
            CheckDisposed();

            // add new book
            IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText   text = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");
            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);

            // add BT for title para of the last book
            para = new ScrTxtPara(Cache, text.ParagraphsOS.HvoArray[0]);
            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            int iLastSectionInExodus = m_book.SectionsOS.Count - 1;

            m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                            0, iLastSectionInExodus,
                                            m_book.SectionsOS[iLastSectionInExodus].ContentOA.ParagraphsOS.Count - 1);

            m_btDraftView.CallNextUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(1, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(-1, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.IsTrue(m_btDraftView.TeEditingHelper.InBookTitle);
        }
示例#2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 ///
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public ScrVerseList(ScrTxtPara para)
 {
     foreach (ScrVerse verse in new ScrVerseSet(para))
     {
         this.Add(verse);
     }
 }
示例#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());
        }
示例#4
0
        public void FindPrevBackTrans_SecondBookTitleToFirstBook()
        {
            CheckDisposed();

            // add new book with a BT
            IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText   text = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");

            m_scrInMemoryCache.AddBtToMockedParagraph((StTxtPara)text.ParagraphsOS[0],
                                                      Cache.DefaultAnalWs);

            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            m_btDraftView.SetInsertionPoint((int)ScrBook.ScrBookTags.kflidTitle, 1, 0);

            m_btDraftView.CallPrevUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(2, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent,
                            m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle);
        }
示例#5
0
        private List <int> GetSegments(ITsStrBldr bldr, ScrTxtPara para)
        {
            para.Contents.UnderlyingTsString = bldr.GetString();
            ParagraphParser pp = new ParagraphParser(para);
            List <int>      eosIndexes;
            List <int>      segments = pp.CollectSegmentAnnotations(para.Contents.UnderlyingTsString, out eosIndexes);

            Cache.VwCacheDaAccessor.CacheVecProp(para.Hvo, ktagParaSegments, segments.ToArray(), segments.Count);
            return(segments);
        }
示例#6
0
            /// --------------------------------------------------------------------------------
            /// <summary>
            /// Initializes the variables related to the current paragraph.
            /// </summary>
            /// --------------------------------------------------------------------------------
            private void InitPara()
            {
                m_iRun = -1;
                ScrTxtPara para =
                    new ScrTxtPara(m_text.Cache, m_text.ParagraphsOS.HvoArray[m_iPara]);

                m_obj           = para;
                m_paraTss       = para.Contents.UnderlyingTsString;
                m_paraStyleName = para.StyleName;
            }
示例#7
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ScrVerseSet"/> class, for the given
        /// paragraph.
        /// </summary>
        /// <param name="para">given paragraph</param>
        /// -----------------------------------------------------------------------------------
        public ScrVerseSet(ScrTxtPara para)
        {
            if (para == null)
            {
                throw new ArgumentNullException("para");
            }

            m_para    = para;
            m_address = new ParaNodeMap(para);
            m_para.GetBCVRefAtPosition(0, out m_startRef, out m_endRef);
        }
示例#8
0
 /// <summary>
 /// It's safer to save the paragraph here...the segment might get deleted by one of the edits
 /// we're monitoring.
 /// </summary>
 /// <param name="newMonitorObject"></param>
 protected override void SetMonitorObject(CmObject newMonitorObject)
 {
     base.SetMonitorObject(newMonitorObject);
     if (m_objectToMonitor != null)
     {
         CmBaseAnnotation seg = (m_objectToMonitor as CmIndirectAnnotation).AppliesToRS[0] as CmBaseAnnotation;
         m_para = new ScrTxtPara(m_cache, seg.BeginObjectRAHvo);
     }
     else
     {
         m_para = null;
     }
 }
示例#9
0
        public void MoveNext_EmptyPara()
        {
            CheckDisposed();
            IScrSection section   = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo);
            StTxtPara   emptyPara = AddEmptyPara(section, ScrStyleNames.SpeechLine1);

            section.AdjustReferences();

            // Create and iterate through the verses in the StText.
            ScrTxtPara  emptyScrPara = new ScrTxtPara(m_inMemoryCache.Cache, emptyPara.Hvo);
            ScrVerseSet verseSet     = new ScrVerseSet(emptyScrPara);

            Assert.IsFalse(verseSet.MoveNext(),
                           "The iterator provided a ScrVerse for an empty para that wasn't a Stanza Break.");
        }
示例#10
0
 public override void Initialize()
 {
     CheckDisposed();
     base.Initialize();
     m_inMemoryCache.InitializeAnnotationDefs();
     InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml",
                     new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" });
     m_text = new Text();
     Cache.LangProject.TextsOC.Add(m_text);
     m_para            = new ScrTxtPara();
     m_stText          = new StText();
     m_text.ContentsOA = m_stText;
     m_stText.ParagraphsOS.Append(m_para);
     ktagParaSegments = InterlinVc.ParaSegmentTag(Cache);
     m_wsVern         = Cache.DefaultVernWs;
 }
示例#11
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());
        }
示例#12
0
        /// -----------------------------------------------------------------------------------
        ///<summary>
        /// Verify the specified ScrVerse
        ///</summary>
        ///<param name="verse">specified ScrVerse</param>
        ///<param name="cache">database</param>
        ///<param name="verseText">expected text within the ScrVerse</param>
        ///<param name="styleName">expected stylename for the ScrVerse paragraph</param>
        ///<param name="startRef">expected starting reference</param>
        ///<param name="endRef">expected ending reference</param>
        /// -----------------------------------------------------------------------------------
        public static void VerifyScrVerse(ScrVerse verse, FdoCache cache, string verseText,
                                          string styleName, BCVRef startRef, BCVRef endRef)
        {
            ScrTxtPara versePara = new ScrTxtPara(cache, verse.HvoPara);

            if (string.IsNullOrEmpty(verseText))
            {
                Assert.IsTrue(verse.Text == null || string.IsNullOrEmpty(verse.Text.Text));
            }
            else
            {
                Assert.AreEqual(verseText, verse.Text.Text);
            }
            Assert.AreEqual(styleName, ScrStyleNames.GetStyleName(versePara.Hvo, cache));
            Assert.AreEqual(startRef, verse.StartRef);
            Assert.AreEqual(endRef, verse.EndRef);
        }
示例#13
0
        public void MoveNext_StanzaBreak()
        {
            CheckDisposed();
            IScrSection section   = m_scrInMemoryCache.AddSectionToMockedBook(m_genesis.Hvo);
            StTxtPara   emptyPara = AddEmptyPara(section, ScrStyleNames.StanzaBreak);

            section.AdjustReferences();

            // Create and iterate through the verses in the StText.
            ScrTxtPara  emptyScrPara = new ScrTxtPara(m_inMemoryCache.Cache, emptyPara.Hvo);
            ScrVerseSet verseSet     = new ScrVerseSet(emptyScrPara);

            Assert.IsTrue(verseSet.MoveNext());
            VerifyScrVerse((ScrVerse)verseSet.Current, m_inMemoryCache.Cache, null,
                           ScrStyleNames.StanzaBreak, 01001001, 01001001);
            Assert.IsFalse(verseSet.MoveNext());
        }
示例#14
0
        public void FindNextBackTrans_SectionContentToNextBook_TitleFinished()
        {
            CheckDisposed();

            // add new book
            IScrBook    book    = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
            StText      text    = m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Title for Leviticus");
            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Heading",
                                                           ScrStyleNames.SectionHead);
            // add BT for last para of first book
            ScrTxtPara para = new ScrTxtPara(Cache, m_book.SectionsOS[2].ContentOA.ParagraphsOS.HvoArray[0]);

            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);

            // add BT for title para of the last book
            para = new ScrTxtPara(Cache, text.ParagraphsOS.HvoArray[0]);
            ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(para,
                                                                          Cache.DefaultAnalWs);

            m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Finished);

            // add BT for the first section head of the last book
            para = new ScrTxtPara(Cache, book.SectionsOS[0].HeadingOA.ParagraphsOS.HvoArray[0]);
            m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs);
            m_btDraftView.RefreshDisplay();

            int iLastSectionInExodus = m_book.SectionsOS.Count - 1;

            m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent,
                                            0, iLastSectionInExodus,
                                            m_book.SectionsOS[iLastSectionInExodus].ContentOA.ParagraphsOS.Count - 1);

            m_btDraftView.CallNextUnfinishedBackTrans();
            SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(0, helper.IchAnchor);
            Assert.AreEqual(1, m_btDraftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(0, m_btDraftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(0, m_btDraftView.ParagraphIndex);
            Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidHeading,
                            m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle);
        }
示例#15
0
        protected override CmObject GetObjectToMonitor(int hvo)
        {
            if (m_cache.GetClassOfObject(hvo) != CmTranslation.kclsidCmTranslation)
            {
                return(null);
            }
            // Return result unless it is disqualified somehow.
            CmTranslation result = CmObject.CreateFromDBObject(m_cache, hvo) as CmTranslation;
            StTxtPara     para   = result.Owner as StTxtPara;

            if (para == null)
            {
                return(null);                // not a translation of Scripture...unlikely unless this is hooked up to some unexpected view.
            }
            // Make sure the paragraph belongs to Scripture.
            if (!ScrTxtPara.IsScripturePara(para.Hvo, m_cache))
            {
                return(null);          // not Scripture
            }
            return(result);            // finally!
        }
示例#16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Calls ParseStTxtPara to carry out the desired side effects: re-parsing the paragraph
        /// for wordforms, ???.
        /// </summary>
        /// <param name="hvoPara">The Paragraph that was changed</param>
        /// <param name="ivMin">the starting character index where the change occurred</param>
        /// <param name="cvIns">the number of characters inserted</param>
        /// <param name="cvDel">the number of characters deleted</param>
        /// ------------------------------------------------------------------------------------
        protected override void DoEffectsOfPropChange(int hvoPara, int ivMin, int cvIns, int cvDel)
        {
            // If nothing really changed, don't do anything.
            if (cvIns == 0 && cvDel == 0)
            {
                return;
            }

            // Check that the paragraph is truly Scripture, and not a footnote or some other kind
            // of non-Scripture paragraph
            int hvoOfStTextThatOwnsPara = m_cache.GetOwnerOfObject(hvoPara);

            switch (m_cache.GetOwningFlidOfObject(hvoOfStTextThatOwnsPara))
            {
            case (int)ScrSection.ScrSectionTags.kflidContent:
            {
                ScrTxtPara para = new ScrTxtPara(m_cache, hvoPara, false, false);
                // get para props to determine para style - Intro?
                para.ProcessChapterVerseNums(ivMin, cvIns, cvDel);

                // Mark any back translations as unfinished
                para.MarkBackTranslationsAsUnfinished();
                break;
            }

            case (int)ScrBook.ScrBookTags.kflidFootnotes:
            case (int)ScrSection.ScrSectionTags.kflidHeading:
            {
                ScrTxtPara para = new ScrTxtPara(m_cache, hvoPara, false, false);
                // Mark any back translations as stale
                para.MarkBackTranslationsAsUnfinished();
                break;
            }

            default:
                // REVIEW TETeam(TomB): Is any checking needed for anything else?
                break;
            }
        }
示例#17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adjusts the references of the section and creates any needed BT's
        /// </summary>
        /// <param name="hvoText">The StText that was changed</param>
        /// <param name="ivMin">the starting index where the change occurred</param>
        /// <param name="cvIns">the number of paragraphs inserted</param>
        /// <param name="cvDel">the number of paragraphs deleted</param>
        /// ------------------------------------------------------------------------------------
        protected override void DoEffectsOfPropChange(int hvoText, int ivMin, int cvIns, int cvDel)
        {
            if (cvIns == 0 && cvDel == 0)
            {
                return;                 // Nothing actually changed
            }
            int    flid = m_cache.GetOwningFlidOfObject(hvoText);
            StText text = new StText(m_cache, hvoText, false, false);
            FdoOwningSequence <IStPara> paras = text.ParagraphsOS;

            // Create back translations for any new paragraphs
            if (flid == (int)ScrSection.ScrSectionTags.kflidContent ||
                flid == (int)ScrSection.ScrSectionTags.kflidHeading ||
                flid == (int)ScrBook.ScrBookTags.kflidTitle)
            {
                for (int iPara = ivMin; iPara < ivMin + cvIns; iPara++)
                {
                    ScrTxtPara para = new ScrTxtPara(m_cache, paras.HvoArray[iPara]);
                    para.GetOrCreateBT();
                }
            }

            // Adjust section references for section contents if we have some paragraphs left
            if (flid == (int)ScrSection.ScrSectionTags.kflidContent && paras.Count > 0)
            {
                ScrTxtPara.AdjustSectionRefsForStTextParaChg(text, ivMin);
            }

            // If we show boundary markers and we insert or delete a paragraph, we have to
            // update the marker of the previous paragraph as well, as that might
            // now be no longer the last paragraph (and thus needs to show the paragraph
            // marker instead of the section marker).
            if (((cvIns > 0 && cvDel == 0) || (cvIns == 0 && cvDel > 0)) && ivMin > 0 &&
                Options.ShowFormatMarksSetting)
            {
                text.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoText,
                                       (int)StText.StTextTags.kflidParagraphs, ivMin - 1, 1, 1);
            }
        }
示例#18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Subclasses should override this, if they need to have side effects.
        /// </summary>
        /// <param name="multiAltFlid"></param>
        /// <param name="alternativeWs"></param>
        /// <param name="originalValue"></param>
        /// <param name="newValue"></param>
        /// ------------------------------------------------------------------------------------
        protected override void ITsStringAltChangedSideEffectsInternal(int multiAltFlid,
                                                                       CoreWritingSystemDefinition alternativeWs, ITsString originalValue, ITsString newValue)
        {
            base.ITsStringAltChangedSideEffectsInternal(multiAltFlid, alternativeWs, originalValue, newValue);

            // Make sure the translation belongs to Scripture.
            ScrTxtPara para = Owner as ScrTxtPara;

            if (para == null || TypeRA == null)
            {
                return;
            }

            if (multiAltFlid == CmTranslationTags.kflidTranslation &&
                TypeRA.Guid == CmPossibilityTags.kguidTranBackTranslation &&
                ((originalValue == null && newValue != null) ||
                 (originalValue != null && newValue == null) ||
                 (originalValue != null && originalValue.Text != newValue.Text)))
            {
                BtConverter.ConvertCmTransToInterlin(para, alternativeWs.Handle);
                MarkAsUnfinished(alternativeWs.Handle);
            }
        }
示例#19
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a Back Translation for the stuff in Exodus with the following layout:
        ///
        ///			()
        ///		   BT Heading 1
        ///	BT Intro text
        ///		   BT Heading 2
        ///	(1)1BT Verse one.
        ///
        ///	(1) = chapter number 1
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreatePartialExodusBT(int wsAnal)
        {
            IScrBook      book    = ScrBook.FindBookByID(m_scr, 2);
            IScrSection   section = book.SectionsOS[0];
            ScrTxtPara    para    = new ScrTxtPara(Cache, section.HeadingOA.ParagraphsOS.HvoArray[0]);
            CmTranslation trans   = (CmTranslation)para.GetOrCreateBT();

            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "BT Heading 1", null);

            para  = new ScrTxtPara(Cache, section.ContentOA.ParagraphsOS.HvoArray[0]);
            trans = (CmTranslation)para.GetOrCreateBT();
            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "BT Intro text", null);

            section = book.SectionsOS[1];
            para    = new ScrTxtPara(Cache, section.HeadingOA.ParagraphsOS.HvoArray[0]);
            trans   = (CmTranslation)para.GetOrCreateBT();
            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "BT Heading 2", null);

            para  = new ScrTxtPara(Cache, section.ContentOA.ParagraphsOS.HvoArray[0]);
            trans = (CmTranslation)para.GetOrCreateBT();
            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "1", ScrStyleNames.ChapterNumber);
            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "1", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedTrans(trans, wsAnal, "BT Verse one", null);
        }
示例#20
0
        // If hvo is an CmIndirectAnnotation that is the free translation of a segment of Scripture, return the
        // annotation; otherwise return null.
        CmIndirectAnnotation GetAnnotation(int hvo)
        {
            if (m_cache.GetClassOfObject(hvo) != CmIndirectAnnotation.kclsidCmIndirectAnnotation)
            {
                return(null);
            }
            // Return result unless it is disqualified somehow.
            CmIndirectAnnotation result = CmObject.CreateFromDBObject(m_cache, hvo) as CmIndirectAnnotation;

            if (result.AnnotationTypeRAHvo != m_hvoFtDefn)
            {
                return(null);                // not a free translation
            }
            if (result.AppliesToRS.Count == 0)
            {
                return(null);                // huh? all FTs should applyTo their segment.
            }
            CmBaseAnnotation cbaSeg = result.AppliesToRS[0] as CmBaseAnnotation;

            if (cbaSeg == null)
            {
                return(null);                // huh? again for same reason
            }
            StTxtPara para = cbaSeg.BeginObjectRA as StTxtPara;

            if (para == null)
            {
                return(null);                // also unlikely, a  segment should link to a paragraph
            }
            // Make sure the paragraph belongs to Scripture.
            if (!ScrTxtPara.IsScripturePara(para.Hvo, m_cache))
            {
                return(null);          // not Scripture
            }
            return(result);            // finally!
        }
示例#21
0
        public void MultipleParas()
        {
            ScrTxtPara paraPrev = new ScrTxtPara();

            m_stText.ParagraphsOS.InsertAt(paraPrev, 0);
            ScrTxtPara paraFirst = new ScrTxtPara();

            m_stText.ParagraphsOS.InsertAt(paraFirst, 0);
            ScrTxtPara paraNext = new ScrTxtPara();

            m_stText.ParagraphsOS.Append(paraNext);
            ScrTxtPara paraLast = new ScrTxtPara();

            m_stText.ParagraphsOS.Append(paraLast);

            string pc1    = "Das buch ist rot. ";
            string pc2    = "Das Madchen ist shon.";
            string verse1 = "9";
            string pc3    = "Der Herr ist gross.";
            string pc4    = "Ich spreche nicht viel Deutsch.";
            string verse2 = "10";
            string pc5    = "Was is das?";
            string pc6    = "Wie gehts?";

            ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5, 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);
            List <int> segments = GetSegments(bldr, m_para);

            string verse8 = "8";

            bldr = m_tsf.MakeString(verse8 + pc3 + pc4, m_wsVern).GetBldr();
            bldr.SetStrPropValue(0, verse8.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraFirst);

            bldr = m_tsf.MakeString(pc1 + pc2, m_wsVern).GetBldr();
            GetSegments(bldr, paraPrev);

            string verse11 = "11";

            bldr = m_tsf.MakeString(pc3 + verse11 + pc4, m_wsVern).GetBldr();
            bldr.SetStrPropValue(pc3.Length, pc3.Length + verse11.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraNext);

            string verse12 = "12";

            bldr = m_tsf.MakeString(verse12 + pc5 + pc6, m_wsVern).GetBldr();
            bldr.SetStrPropValue(0, verse12.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraLast);
            Assert.AreEqual(7, segments.Count);
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(paraFirst, 1, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(paraFirst, 2, ktagParaSegments));
            Assert.AreEqual("c", AnnotationRefHandler.VerseSegLabel(paraPrev, 0, ktagParaSegments));
            Assert.AreEqual("d", AnnotationRefHandler.VerseSegLabel(paraPrev, 1, ktagParaSegments));
            Assert.AreEqual("e", AnnotationRefHandler.VerseSegLabel(m_para, 0, ktagParaSegments));
            Assert.AreEqual("f", AnnotationRefHandler.VerseSegLabel(m_para, 1, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 3, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(m_para, 4, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 6, ktagParaSegments), "should have label because seg in following para");
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(paraNext, 0, ktagParaSegments), "should have label due to previous para");
            Assert.AreEqual("", AnnotationRefHandler.VerseSegLabel(paraNext, 2, ktagParaSegments),
                            "should have no label because next para starts with verse");
        }
示例#22
0
        public void MoveNext_SpacesInVerses()
        {
            CheckDisposed();

            ScrSection sectionCur = new ScrSection();

            m_genesis.SectionsOS.Append(sectionCur);
            // Create a section head for this section
            sectionCur.HeadingOA = new StText();
            StTxtParaBldr paraBldr = new StTxtParaBldr(Cache);

            paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead);
            paraBldr.AppendRun("My aching head!",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.CreateParagraph(sectionCur.HeadingOAHvo);
            sectionCur.ContentOA = new StText();

            paraBldr           = new StTxtParaBldr(Cache);
            paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalParagraph);
            paraBldr.AppendRun("1", StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse One. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("2", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun(" Verse Two. ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("3", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("Verse Three.",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            paraBldr.AppendRun("4", StyleUtils.CharStyleTextProps(ScrStyleNames.VerseNumber,
                                                                  Cache.DefaultVernWs));
            paraBldr.AppendRun("     ",
                               StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs));
            StTxtPara para = paraBldr.CreateParagraph(sectionCur.ContentOA.Hvo);

            sectionCur.AdjustReferences();

            ScrTxtPara  stPara   = new ScrTxtPara(Cache, para.Hvo);
            ScrVerseSet verseSet = new ScrVerseSet(stPara);

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

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

            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.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.IsTrue(verseSet.MoveNext());
            verse = (ScrVerse)verseSet.Current;
            Assert.AreEqual("3Verse Three.", verse.Text.Text);
            Assert.AreEqual(01001003, verse.StartRef);
            Assert.AreEqual(01001003, verse.EndRef);

            Assert.IsTrue(verseSet.MoveNext());
            verse = (ScrVerse)verseSet.Current;
            Assert.AreEqual("4     ", verse.Text.Text);
            Assert.AreEqual(01001004, verse.StartRef);
            Assert.AreEqual(01001004, verse.EndRef);

            Assert.IsFalse(verseSet.MoveNext());
        }
示例#23
0
        ///  ------------------------------------------------------------------------------------
        /// <summary>
        /// Advances the enumerator to the next verse in the paragraph.
        /// </summary>
        /// <returns>True if we successfully moved to the next ScrVerse; False if we reached
        /// the end of the paragraph.</returns>
        /// ------------------------------------------------------------------------------------
        public bool MoveNext()
        {
            InitializeParaContents();

            if (m_ich > m_paraLength)
            {
                return(false);
            }

            m_ichVerseStart = m_ichTextStart = m_ich;
            TsRunInfo    tsi;
            ITsTextProps ttpRun;
            string       sPara    = m_tssParaContents.Text;
            int          nChapter = -1;     // This is used to see if we found a chapter later.

            m_inVerseNum   = false;
            m_inChapterNum = false;
            while (m_ich < m_paraLength)
            {
                ttpRun = m_tssParaContents.FetchRunInfoAt(m_ich, out tsi);

                // If this run is our verse number style
                if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
                {
                    // If there is already a verse in process, a new verse number run will terminate it.
                    if (m_ichVerseStart != m_ich)
                    {
                        break;
                    }

                    // Assume the whole run is the verse number
                    string sVerseNum = sPara.Substring(m_ich, tsi.ichLim - tsi.ichMin);
                    int    nVerseStart, nVerseEnd;
                    ScrReference.VerseToInt(sVerseNum, out nVerseStart, out nVerseEnd);
                    m_startRef.Verse = nVerseStart;
                    m_endRef.Verse   = nVerseEnd;
                    m_ichVerseStart  = m_ich;                    //set VerseStart at beg of verse number
                    m_ich           += sVerseNum.Length;
                    m_ichTextStart   = m_ich;
                    m_inVerseNum     = true;
                }
                // If this run is our chapter number style
                else if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                {
                    // If there is already a verse being processed, then the chapter number
                    // run will end it
                    if (m_ichVerseStart != m_ich)
                    {
                        break;
                    }

                    try
                    {
                        // Assume the whole run is the chapter number
                        string sChapterNum = sPara.Substring(m_ich, tsi.ichLim - tsi.ichMin);
                        nChapter           = ScrReference.ChapterToInt(sChapterNum);
                        m_startRef.Chapter = m_endRef.Chapter = nChapter;
                        // Set the verse number to 1, since the first verse number after a
                        // chapter is optional. If we happen to get a verse number in the
                        // next run, this '1' will be overridden (though it will probably
                        // still be a 1).
                        m_startRef.Verse = m_endRef.Verse = 1;
                        m_ichVerseStart  = m_ich;                        //set VerseStart at beg of chapter number
                        m_ich           += sChapterNum.Length;
                        m_ichTextStart   = m_ich;
                        m_inChapterNum   = true;
                    }
                    catch (ArgumentException)
                    {
                        // ignore runs with invalid Chapter numbers
                        m_ich += tsi.ichLim - tsi.ichMin;
                    }
                }

                else                 // Process a text run.
                {
                    // If it comes after a chapter number, then just return the
                    // chapter number without adding the text.
                    if (nChapter > 0)
                    {
                        break;
                    }

                    // skip to the next run
                    m_ich += tsi.ichLim - tsi.ichMin;
                }
            }

            // determine if this verse is a complete paragraph, an empty para and/or a stanza break.
            m_isCompletePara = (m_ichVerseStart == 0 && m_ich == m_paraLength);
            if (string.IsNullOrEmpty(sPara))
            {
                //m_isEmptyPara = true;
                m_isStanzaBreak = string.Equals(ScrStyleNames.StanzaBreak,
                                                ScrStyleNames.GetStyleName(m_para.Hvo, m_para.Cache));
            }

            try
            {
                return((m_ich > m_ichVerseStart) || FirstTimeAtStanzaBreak);
            }
            finally
            {
                // Update the previous paragraph for the next time (but we do the update
                // in a 'finally' so that we can compare the current to the previous for
                // the return value).
                m_prevPara = m_para;
            }
        }
示例#24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets Scripture reference for a selection
        /// </summary>
        /// <param name="helper">The selection helper that represents the selection</param>
        /// <param name="fInclusive"><c>true</c> if the reference returned should include the
        /// reference of the text of the verse where the selection is, even if that selection
        /// is not at the start of the verse; <c>false</c> if the reference should be that of
        /// the first full verse at or following the selection</param>
        /// <param name="scriptureRef">returns the scripture reference found</param>
        /// <returns>A TsString representing the reference of the selection, or null if the
        /// selection represents a book title or something weird.</returns>
        /// ------------------------------------------------------------------------------------
        private ITsString GetSelectionReference(SelectionHelper helper, bool fInclusive,
                                                out BCVRef scriptureRef)
        {
            scriptureRef = new BCVRef();
            if (helper != null && m_page.Publication != null && m_page.Publication is ScripturePublication)
            {
                ScripturePublication scrPub = m_page.Publication as ScripturePublication;
                int iParaLevel = helper.GetLevelForTag((int)StText.StTextTags.kflidParagraphs);
                if (iParaLevel >= 0)
                {
                    ScrTxtPara para = new ScrTxtPara(m_cache, helper.LevelInfo[iParaLevel].hvo);
                    // Look through the verses of the paragraph until we pass the location
                    // where the page break occurs. This verse reference will then be the
                    // first one on the page.
                    ScrVerse firstVerseOnPage = null;
                    int      ichPageBreak     = helper.IchAnchor;
                    foreach (ScrVerse verse in para)
                    {
                        if (!fInclusive)
                        {
                            firstVerseOnPage = verse;
                        }
                        if (verse.VerseStartIndex > ichPageBreak ||
                            (verse.VerseStartIndex == ichPageBreak && !fInclusive))
                        {
                            break;
                        }
                        if (fInclusive)
                        {
                            firstVerseOnPage = verse;
                        }
                    }

                    ITsString tssBookName = GetBookName(helper);
                    if (tssBookName != null)
                    {
                        ITsStrBldr bldr = tssBookName.GetBldr();
                        int        cch  = bldr.Length;
                        if (firstVerseOnPage != null)
                        {
                            if (firstVerseOnPage.StartRef.Verse != 0)
                            {
                                bldr.Replace(cch, cch, " " +
                                             ((Scripture)m_scr).ChapterVerseRefAsString(firstVerseOnPage.StartRef, m_wsDefault), null);
                            }
                            scriptureRef = firstVerseOnPage.StartRef;
                        }
                        return(bldr.GetString());
                    }
                    //else
                    //{
                    //    // Probably no verses were found in the paragraph
                    //    IVwSelection sel = FindNextPara(helper);
                    //    helper = SelectionHelper.Create(sel, helper.RootSite);

                    //    return GetSelectionReference(helper, fInclusive, out scriptureRef);
                    //}
                }
            }
            return(null);
        }
示例#25
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a Verse iterator from the back translation paragraph
 /// </summary>
 /// <param name="para">The paragraph with the back translation</param>
 /// <param name="BTWritingSystem">The writing system of the back translation</param>
 /// ------------------------------------------------------------------------------------
 public ScrVerseSetBT(ScrTxtPara para, int BTWritingSystem) : base(para)
 {
     m_BackTranslationWS = BTWritingSystem;
 }