/// ------------------------------------------------------------------------------------
        /// <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;
                }
            }
        }
示例#2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines if paragraph has chapter or verse numbers in it.
        /// </summary>
        /// <returns><code>true</code> if either a chapter number or verse number is found
        /// in the paragraph</returns>
        /// ------------------------------------------------------------------------------------
        public bool HasChapterOrVerseNumbers()
        {
            ITsString    tss  = Contents.UnderlyingTsString;
            int          cRun = tss.RunCount;
            ITsTextProps ttpRun;

            for (int i = 0; i < cRun; i++)
            {
                ttpRun = tss.get_Properties(i);

                if (StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber) ||
                    StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        public void ChangeParagraphToSectionHead_EndOfSection()
        {
            CheckDisposed();

            IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_matthew.Hvo);

            m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "This is the heading",
                                                           ScrStyleNames.SectionHead);
            m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
            m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
            StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
                                                                              ScrStyleNames.NormalParagraph);

            m_scrInMemoryCache.AddRunToMockedPara(para, "6", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedPara(para, "Content of paragraph 2", null);
            section.AdjustReferences();

            ScrSection  secHelp    = new ScrSection(Cache, section.Hvo);
            IScrSection newSecHelp = secHelp.ChangeParagraphToSectionHead(2, 1);

            // verify that the new section has one content paragraph and one heading paragraph.
            Assert.AreEqual(1, newSecHelp.ContentOA.ParagraphsOS.Count);
            Assert.AreEqual(1, newSecHelp.HeadingOA.ParagraphsOS.Count);

            // verify that the text of the old paragraph is now in the new section head
            // and that the new section content paragraph is empty and has normal paragraph
            // style.
            StTxtPara newSecPara = (StTxtPara)newSecHelp.ContentOA.ParagraphsOS[0];

            Assert.IsTrue(StStyle.IsStyle(newSecPara.StyleRules, ScrStyleNames.NormalParagraph));
            Assert.IsFalse(StStyle.IsStyle(newSecPara.Contents.UnderlyingTsString.get_Properties(0),
                                           ScrStyleNames.NormalParagraph));

            Assert.IsNull(newSecPara.Contents.Text);
            StTxtPara newSecHeadPara = (StTxtPara)newSecHelp.HeadingOA.ParagraphsOS[0];

            Assert.AreEqual(para.Contents.Text, newSecHeadPara.Contents.Text);
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Check to see if section can be used as the starting section of the export. Must either
        /// be an intro section or a section that begins with a chapter number run.
        /// </summary>
        /// <param name="sect">section to be checked</param>
        /// <param name="prevSect">section previous to current section</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private bool ValidStartingSection(ScrSection sect, ScrSection prevSect)
        {
            if (sect.IsIntro || prevSect == null || prevSect.IsIntro)
            {
                return(true);
            }

            if (sect.ContentOA.ParagraphsOS.Count > 0)
            {
                StTxtPara para = (StTxtPara)sect.ContentOA.ParagraphsOS[0];
                ITsString tss  = para.Contents.UnderlyingTsString;
                if (tss.RunCount > 0)
                {
                    ITsTextProps ttpRun;
                    ttpRun = tss.get_Properties(0);
                    if (StStyle.IsStyle(ttpRun, ScrStyleNames.ChapterNumber))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find the start and end reference, by searching backwards in the given ITsString
        /// from the given position.
        /// </summary>
        /// <param name="tss">the given ITsString</param>
        /// <param name="ichPos">Index of character in paragraph whose reference we want</param>
        /// <param name="fAssocPrev">Consider this position to be associated with any preceding
        /// text in the paragraph (in the case where ichPos is at a chapter boundary).</param>
        /// <param name="refStart">[out] Start reference for the paragraph.</param>
        /// <param name="refEnd">[out] End reference for the paragraph.</param>
        /// <returns>A value of <see cref="ChapterVerseFound"/> that tells if a chapter and/or
        /// verse number was found in this paragraph.</returns>
        /// <remarks>If ichPos LT zero, we will not search this para, and simply return.
        /// Be careful not to use this method to search the contents of paragraph using
        /// character offsets from the BT!
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        static public ChapterVerseFound GetBCVRefAtPosWithinTss(ITsString tss, int ichPos,
                                                                bool fAssocPrev, out BCVRef refStart, out BCVRef refEnd)
        {
            refStart = new BCVRef();
            refEnd   = new BCVRef();
            ChapterVerseFound retVal = ChapterVerseFound.None;

            if (tss.Length <= 0)
            {
                return(retVal);
            }

            TsRunInfo    tsi;
            ITsTextProps ttpRun;
            bool         fGotVerse = false;

            int ich = ichPos;

            if (ich > tss.Length)
            {
                ich = tss.Length;
            }
            while (ich >= 0)
            {
                // Get props of current run.
                ttpRun = tss.FetchRunInfoAt(ich, out tsi);

                // If we're at (the front edge of) a C/V number boundary and the
                // caller said to associate the position with the previous material, then
                // ignore this run unless we're at the beginning of the para.
                // The run is actually the *following*  run, which we don't care about.
                if (!fAssocPrev || ichPos <= 0 || ichPos != tsi.ichMin)
                {
                    // See if it is our verse number style.
                    if (!fGotVerse && StStyle.IsStyle(ttpRun, ScrStyleNames.VerseNumber))
                    {
                        // The whole run is the verse number. Extract it.
                        string sVerseNum = tss.get_RunText(tsi.irun);
                        //					string sVerseNum = tss.Text.Substring(tsi.ichMin,
                        //						tsi.ichLim - tsi.ichMin);
                        int startVerse, endVerse;
                        ScrReference.VerseToInt(sVerseNum, out startVerse, out endVerse);
                        refStart.Verse = startVerse;
                        refEnd.Verse   = endVerse;
                        fGotVerse      = true;
                        retVal         = ChapterVerseFound.Verse;
                    }
                    // 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 = tss.get_RunText(tsi.irun);
                            int    nChapter    = ScrReference.ChapterToInt(sChapterNum);
                            refStart.Chapter = refEnd.Chapter = nChapter;

                            if (fGotVerse)
                            {
                                // Found a chapter number to go with the verse number we
                                // already found, so build the full reference using this
                                // chapter with the previously found verse (already set).
                                retVal |= ChapterVerseFound.Chapter;
                            }
                            else
                            {
                                // Found a chapter number but no verse number, so assume the
                                // edited text is in verse 1 of the chapter.
                                refStart.Verse = refEnd.Verse = 1;
                                fGotVerse      = true;
                                retVal         = ChapterVerseFound.Chapter | ChapterVerseFound.Verse;
                            }
                            break;
                        }
                        catch (ArgumentException)
                        {
                            // ignore runs with invalid Chapter numbers
                        }
                    }
                }

                // move index (going backwards) to the character just before the Min of the run
                // we just looked at
                ich = tsi.ichMin - 1;
            }
            return(retVal);
        }
示例#6
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;
            }
        }
示例#7
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.
        }