Exemple #1
0
        public void BeginAndEndUndoTask()
        {
            CheckDisposed();

            ShowForm();
            // we need a selection
            m_basicView.RootBox.MakeSimpleSel(true, true, false, true);

            // this should begin an outer undo task, so we will have only one undoable task!
            using (new UndoTaskHelper(m_basicView, "kstidUndoStyleChanges"))
            {
                m_fdoCache.BeginUndoTask("", "");
                StStyle style = new StStyle();
                m_fdoCache.LangProject.StylesOC.Add(style);
                m_fdoCache.EndUndoTask();

                m_fdoCache.BeginUndoTask("", "");
                style = new StStyle();
                m_fdoCache.LangProject.StylesOC.Add(style);
                m_fdoCache.EndUndoTask();
            }
            int nUndoTasks = 0;

            while (m_fdoCache.Undo())
            {
                nUndoTasks++;
            }
            Assert.AreEqual(1, nUndoTasks);
        }
Exemple #2
0
        //[Ignore("Has problems with new restore database approach")]
        public void Transactions()
        {
            CheckDisposed();

            if (!m_fdoCache.DatabaseAccessor.IsTransactionOpen())
            {
                m_fdoCache.DatabaseAccessor.BeginTrans();
            }

            StStyle newStyle = new StStyle();

            m_fdoCache.LangProject.StylesOC.Add(newStyle);

            int newStyleHvo = newStyle.Hvo;

            m_fdoCache.DatabaseAccessor.RollbackTrans();

            // A simple rollback will not clear the object from the cache,
            // so do it here.
            m_fdoCache.VwCacheDaAccessor.ClearInfoAbout(newStyleHvo, VwClearInfoAction.kciaRemoveAllObjectInfo);

            if (newStyle.IsValidObject())
            {
                // Should not get here, as the create call should throw the exception.
                // Just in case, however, delete the new object.
                newStyle.DeleteUnderlyingObject();
                Assert.Fail("Object is still valid.");
            }
        }
Exemple #3
0
        public void SaveToDB_NewInfo()
        {
            IStStyle realStyle = new StStyle();

            Cache.LangProject.StylesOC.Add(realStyle);
            realStyle.Context   = ContextValues.Intro;
            realStyle.Function  = FunctionValues.Table;
            realStyle.Structure = StructureValues.Heading;
            StyleInfo basedOn = new StyleInfo(realStyle);

            StyleInfo testInfo = new StyleInfo("New Style", basedOn,
                                               StyleType.kstParagraph, Cache);

            // simulate a save to the DB for the test style.
            IStStyle style = new StStyle();

            Cache.LangProject.StylesOC.Add(style);
            testInfo.SaveToDB(style, false);

            Assert.AreEqual(ContextValues.Intro, testInfo.Context);
            Assert.AreEqual(StructureValues.Heading, testInfo.Structure);
            Assert.AreEqual(FunctionValues.Table, testInfo.Function);
            Assert.AreEqual(ContextValues.Intro, style.Context);
            Assert.AreEqual(StructureValues.Heading, style.Structure);
            Assert.AreEqual(FunctionValues.Table, style.Function);
        }
Exemple #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 ///
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected override void CreateTestData()
 {
     m_style = new StStyle();
     Cache.LangProject.StylesOC.Add(m_style);
     m_style.Name      = "Section Head Major";
     m_style.UserLevel = -1;
 }
Exemple #5
0
        public void CreateAndLoadOwnedObject()
        {
            CheckDisposed();

            StStyle style = new StStyle();

            Cache.LangProject.StylesOC.Add(style);

            Guid guid = Cache.GetGuidFromId(style.Hvo);

            Assert.IsTrue(guid != Guid.Empty);
        }
        public void SetGetSingleUnicode()
        {
            CheckDisposed();

            StStyle st = new StStyle();

            Cache.LangProject.StylesOC.Add(st);
            string s = "NewName" + m_rand.Next().ToString();

            st.Name = s;

            Assert.AreEqual(s, st.Name);
        }
        /// ------------------------------------------------------------------------------------
        /// <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;
                }
            }
        }
        public void StyleCollectionWorksWithUpperAscii()
        {
            string  styleName = "\u00e1bc";
            StStyle style     = new StStyle();

            Cache.LangProject.StylesOC.Add(style);
            style.Name = styleName;

            FwStyleSheet.StyleInfoCollection styleCollection = new FwStyleSheet.StyleInfoCollection();
            styleCollection.Add(new BaseStyleInfo(style));

            Assert.IsTrue(styleCollection.Contains(styleName.Normalize(NormalizationForm.FormC)));
            Assert.IsTrue(styleCollection.Contains(styleName.Normalize(NormalizationForm.FormD)));
            Assert.IsTrue(styleCollection.Contains(styleName.Normalize(NormalizationForm.FormKC)));
            Assert.IsTrue(styleCollection.Contains(styleName.Normalize(NormalizationForm.FormKD)));
        }
Exemple #9
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);
        }
Exemple #10
0
        public void SaveToDB_CopyOfStyleBasedOnNormal()
        {
            StyleInfoTable styleTable  = new StyleInfoTable("Normal", Cache.LanguageWritingSystemFactoryAccessor);
            IStStyle       normalStyle = new StStyle();

            Cache.LangProject.StylesOC.Add(normalStyle);
            normalStyle.Name      = "Normal";
            normalStyle.Context   = ContextValues.Internal;
            normalStyle.Function  = FunctionValues.Prose;
            normalStyle.Structure = StructureValues.Undefined;
            StyleInfo normal = new StyleInfo(normalStyle);

            styleTable.Add("Normal", normal);

            IStStyle realStyle = new StStyle();

            Cache.LangProject.StylesOC.Add(realStyle);
            realStyle.Name      = "Paragraph";
            realStyle.Context   = ContextValues.Text;
            realStyle.Function  = FunctionValues.Prose;
            realStyle.Structure = StructureValues.Body;
            realStyle.BasedOnRA = normalStyle;
            StyleInfo styleToCopyFrom = new StyleInfo(realStyle);

            styleTable.Add("Paragraph", styleToCopyFrom);

            StyleInfo testInfo = new StyleInfo(styleToCopyFrom, "Copy of Paragraph");

            styleTable.Add("Copy of Paragraph", testInfo);
            styleTable.ConnectStyles();

            // simulate a save to the DB for the test style.
            IStStyle style = new StStyle();

            Cache.LangProject.StylesOC.Add(style);
            testInfo.SaveToDB(style, false);

            Assert.AreEqual(ContextValues.Text, testInfo.Context);
            Assert.AreEqual(StructureValues.Body, testInfo.Structure);
            Assert.AreEqual(FunctionValues.Prose, testInfo.Function);
            Assert.AreEqual(ContextValues.Text, style.Context);
            Assert.AreEqual(StructureValues.Body, style.Structure);
            Assert.AreEqual(FunctionValues.Prose, style.Function);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a new style and add it to the Language Project stylesheet.
        /// </summary>
        /// <param name="name">style name</param>
        /// <param name="context">style context</param>
        /// <param name="structure">style structure</param>
        /// <param name="function">style function</param>
        /// <param name="isCharStyle">true if character style, otherwise false</param>
        /// <param name="userLevel">The user level.</param>
        /// <param name="styleCollection">The style collection.</param>
        /// <returns>The style</returns>
        /// ------------------------------------------------------------------------------------
        public IStStyle AddTestStyle(string name, ContextValues context, StructureValues structure,
                                     FunctionValues function, bool isCharStyle, int userLevel,
                                     FdoOwningCollection <IStStyle> styleCollection)
        {
            CheckDisposed();
            ITsPropsBldr bldr  = TsPropsBldrClass.Create();
            StStyle      style = new StStyle();

            styleCollection.Add(style);
            style.Name      = name;
            style.Context   = context;
            style.Structure = structure;
            style.Function  = function;
            style.Rules     = bldr.GetTextProps();
            style.Type      = (isCharStyle ? StyleType.kstCharacter : StyleType.kstParagraph);
            style.UserLevel = userLevel;

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

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

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_style = null;

            base.Dispose(disposing);
        }
Exemple #13
0
        public void SaveToDB_NewInfoAndBasedOnNewInfo()
        {
            IStStyle realStyle = new StStyle();

            Cache.LangProject.StylesOC.Add(realStyle);
            realStyle.Context   = ContextValues.Intro;
            realStyle.Function  = FunctionValues.Table;
            realStyle.Structure = StructureValues.Heading;
            StyleInfo basedOn = new StyleInfo(realStyle);

            StyleInfo testInfo1 = new StyleInfo("New Style 1", basedOn,
                                                StyleType.kstParagraph, Cache);
            StyleInfo testInfo2 = new StyleInfo("New Style 2", testInfo1,
                                                StyleType.kstParagraph, Cache);

            // simulate a save to the DB for the test styles. Save the second one first for
            // a better test.
            IStStyle style2 = new StStyle();

            Cache.LangProject.StylesOC.Add(style2);
            testInfo2.SaveToDB(style2, false);
            IStStyle style = new StStyle();

            Cache.LangProject.StylesOC.Add(style);
            testInfo1.SaveToDB(style, false);

            Assert.AreEqual(ContextValues.Intro, testInfo1.Context);
            Assert.AreEqual(StructureValues.Heading, testInfo1.Structure);
            Assert.AreEqual(FunctionValues.Table, testInfo1.Function);
            Assert.AreEqual(ContextValues.Intro, style.Context);
            Assert.AreEqual(StructureValues.Heading, style.Structure);
            Assert.AreEqual(FunctionValues.Table, style.Function);

            Assert.AreEqual(ContextValues.Intro, testInfo2.Context);
            Assert.AreEqual(StructureValues.Heading, testInfo2.Structure);
            Assert.AreEqual(FunctionValues.Table, testInfo2.Function);
            Assert.AreEqual(ContextValues.Intro, style2.Context);
            Assert.AreEqual(StructureValues.Heading, style2.Structure);
            Assert.AreEqual(FunctionValues.Table, style2.Function);
        }
Exemple #14
0
        public void UserDefinedCharacterStyle_ExplicitFontName()
        {
            // Create a style with an unspecified font name.
            IStStyle charStyle = new StStyle();

            Cache.LangProject.StylesOC.Add(charStyle);
            charStyle.Context   = ContextValues.Text;
            charStyle.Function  = FunctionValues.Prose;
            charStyle.Structure = StructureValues.Body;
            charStyle.Type      = StyleType.kstCharacter;
            StyleInfo basedOn = new StyleInfo(charStyle);

            // Create a user-defined character style inherited from the previously-created character
            // style, but this style has a font name specified.
            StyleInfo charStyleInfo = new StyleInfo("New Char Style", basedOn,
                                                    StyleType.kstCharacter, Cache);
            FontInfo charFontInfo = charStyleInfo.FontInfoForWs(Cache.DefaultVernWs);

            m_fontTab.UpdateForStyle(charStyleInfo);

            // Select a font name for the style (which will call the event handler
            // m_cboFontNames_SelectedIndexChanged).
            FwInheritablePropComboBox cboFontNames =
                ReflectionHelper.GetField(m_fontTab, "m_cboFontNames") as FwInheritablePropComboBox;

            Assert.IsNotNull(cboFontNames);
            cboFontNames.AdjustedSelectedIndex = 2;
            // Make sure we successfully set the font for this user-defined character style.
            Assert.IsTrue(charStyleInfo.FontInfoForWs(-1).m_fontName.IsExplicit);
            Assert.AreEqual("<default pub font>", charStyleInfo.FontInfoForWs(-1).m_fontName.Value,
                            "The font should have been set to the default publication font.");

            cboFontNames.AdjustedSelectedIndex = 3;
            // Make sure we successfully set the font for this user-defined character style.
            Assert.IsTrue(charStyleInfo.FontInfoForWs(-1).m_fontName.IsExplicit);
            Assert.AreEqual("<default sans serif>", charStyleInfo.FontInfoForWs(-1).m_fontName.Value,
                            "The font should have been set to the default heading font (i.e., sans-serif).");
        }
Exemple #15
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);
        }
        public void AddDeleteStyle()
        {
            CheckDisposed();

            ITsPropsBldr tsPropsBldr        = TsPropsBldrClass.Create();
            ITsTextProps ttpFormattingProps = tsPropsBldr.GetTextProps();             // default properties

            int nStylesOrig = m_styleSheet.CStyles;

            // get an hvo for the new style
            int     hvoStyle = m_styleSheet.MakeNewStyle();
            StStyle style    = new StStyle(m_styleSheet.Cache, hvoStyle);

            // PutStyle() adds the style to the stylesheet
            m_styleSheet.PutStyle("MyNewStyle", "bla", hvoStyle, 0,
                                  hvoStyle, 0, false, false, ttpFormattingProps);

            Assert.AreEqual(nStylesOrig + 1, m_styleSheet.CStyles);
            Assert.AreEqual(ttpFormattingProps, m_styleSheet.GetStyleRgch(0, "MyNewStyle"),
                            "Should get correct format props for the style added");

            // Make style be based on section head and check context
            IStStyle baseOnStyle = m_scr.FindStyle(ScrStyleNames.SectionHead);

            m_styleSheet.PutStyle("MyNewStyle", "bla", hvoStyle, baseOnStyle.Hvo,
                                  hvoStyle, 0, false, false, ttpFormattingProps);
            Assert.AreEqual(baseOnStyle.Context, style.Context);

            // Now delete the new style
            m_styleSheet.Delete(hvoStyle);

            // Verfiy the deletion
            Assert.AreEqual(nStylesOrig, m_styleSheet.CStyles);
            Assert.IsNull(m_styleSheet.GetStyleRgch(0, "MyNewStyle"),
                          "Should get null because style is not there");
        }
Exemple #17
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);
        }
Exemple #18
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);
        }
Exemple #19
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.
        }
		/// <summary>
		/// Create a new style with a fixed guid.
		/// </summary>
		/// <param name="cache">project cache</param>
		/// <param name="guid">the factory set guid</param>
		/// <returns>A style interface</returns>
		public IStStyle Create(FdoCache cache, Guid guid)
		{
			int hvo = ((IDataReader)cache.ServiceLocator.DataSetup).GetNextRealHvo();
			var retval = new StStyle(cache, hvo, guid);
			return retval;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a new style on the specified style list.
		/// </summary>
		/// <param name="styleList">The style list to add the style to</param>
		/// <param name="name">style name</param>
		/// <param name="context">style context</param>
		/// <param name="structure">style structure</param>
		/// <param name="function">style function</param>
		/// <param name="isCharStyle">true if character style, otherwise false</param>
		/// <param name="userLevel">User level</param>
		/// <param name="isBuiltin">True for a builtin style, otherwise, false.</param>
		/// <returns>The new created (and properly owned style.</returns>
		/// ------------------------------------------------------------------------------------
		public IStStyle Create(IFdoOwningCollection<IStStyle> styleList, string name,
			ContextValues context, StructureValues structure, FunctionValues function,
			bool isCharStyle, int userLevel, bool isBuiltin)
		{
			var retval = new StStyle();
			styleList.Add(retval);
			retval.Name = name;
			retval.Context = context;
			retval.Structure = structure;
			retval.Function = function;
			retval.Type = (isCharStyle ? StyleType.kstCharacter : StyleType.kstParagraph);
			retval.UserLevel = userLevel;
			retval.IsBuiltIn = isBuiltin;

			return retval;
		}
Exemple #22
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;
            }
        }