Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sanity check to ensure the scripture texts are valid.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void EnsureScriptureTextsValid()
        {
            foreach (ScrBook book in m_scr.ScriptureBooksOS)
            {
                int[] sectionHvos = book.SectionsOS.HvoArray;
                // Don't crash if we don't have any sections (TE-5380)
                if (sectionHvos.Length == 0)
                {
                    continue;
                }

                ContextValues sectionContext;
                foreach (ScrSection section in book.SectionsOS)
                {
                    // Check the heading paragraphs.
                    if (section.HeadingOA == null)
                    {
                        m_cache.CreateObject(StText.kClassId, section.Hvo,
                                             (int)ScrSection.ScrSectionTags.kflidHeading, 0);
                    }
                    if (section.HeadingOA.ParagraphsOS.Count == 0)
                    {
                        StTxtPara para = new StTxtPara();
                        section.HeadingOA.ParagraphsOS.Append(para);
                        para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead);
                        sectionContext  = ContextValues.Text;
                    }
                    else
                    {
                        IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules);
                        // style could be null. set default context if possible
                        sectionContext = style == null ? ContextValues.Text : style.Context;
                    }

                    // Check the content paragraphs.
                    if (section.ContentOA == null)
                    {
                        m_cache.CreateObject(StText.kClassId, section.Hvo,
                                             (int)ScrSection.ScrSectionTags.kflidContent, 0);
                    }
                    if (section.ContentOA.ParagraphsOS.Count == 0)
                    {
                        StTxtPara para = new StTxtPara();
                        section.ContentOA.ParagraphsOS.Append(para);
                        para.StyleRules = StyleUtils.ParaStyleTextProps(
                            TeEditingHelper.GetDefaultStyleForContext(sectionContext, false));
                        section.AdjustReferences();
                    }
                }
            }
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sanity check to ensure the scripture texts are valid.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void EnsureScriptureTextsValid()
        {
            foreach (IScrBook book in m_scr.ScriptureBooksOS)
            {
                if (book.SectionsOS.Count == 0)
                {
                    continue;
                }

                ContextValues sectionContext;
                foreach (IScrSection section in book.SectionsOS)
                {
                    // Check the heading paragraphs.
                    if (section.HeadingOA == null)
                    {
                        section.HeadingOA = m_cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
                    }

                    if (section.HeadingOA.ParagraphsOS.Count == 0)
                    {
                        IStTxtPara para = m_cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                            section.HeadingOA, ScrStyleNames.SectionHead);
                        sectionContext = ContextValues.Text;
                    }
                    else
                    {
                        IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules);
                        // style could be null. set default context if possible
                        sectionContext = style == null ? ContextValues.Text : style.Context;
                    }

                    // Check the content paragraphs.
                    if (section.ContentOA == null)
                    {
                        section.ContentOA = m_cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
                    }

                    if (section.ContentOA.ParagraphsOS.Count == 0)
                    {
                        IStTxtPara para = m_cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                            section.ContentOA, TeStylesXmlAccessor.GetDefaultStyleForContext(sectionContext, false));
                    }
                }
            }
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Converts chapter and verse numbers in the given paragraph.
        /// </summary>
        /// <param name="para">Paragraph to be converted</param>
        /// <param name="zeroDigit">Character representing zero for chapter/verse numbers</param>
        /// <param name="charEngine">Unicode character properties engine</param>
        /// <returns>true if chapter or verse numbers were changed in paragraph</returns>
        /// <remarks>Return value is only used for testing.  Also, method is made virtual so
        /// test class can override it.  Allows testing to limit amount of processing for sake of
        /// time.</remarks>
        /// ------------------------------------------------------------------------------------
        protected virtual bool ConvertChapterVerseNumbers(IScrTxtPara para, char zeroDigit,
                                                          ILgCharacterPropertyEngine charEngine)
        {
            ITsString  tss          = para.Contents;
            ITsStrBldr tssBldr      = tss.GetBldr();
            int        cRun         = tss.RunCount;
            bool       numbersFound = false;

            for (int i = 0; i < cRun; i++)
            {
                TsRunInfo    tri;
                ITsTextProps ttp   = tss.FetchRunInfo(i, out tri);
                IStStyle     style = m_scr.FindStyle(ttp);
                if (style != null &&
                    (style.Function == FunctionValues.Verse ||
                     style.Function == FunctionValues.Chapter) && tri.ichMin < tri.ichLim)
                {
                    numbersFound = true;
                    string        runChars = tss.GetChars(tri.ichMin, tri.ichLim);
                    StringBuilder strBldr  = new StringBuilder(runChars.Length);
                    foreach (char c in runChars)
                    {
                        if (charEngine.get_IsNumber(c))
                        {
                            strBldr.Append((char)(zeroDigit + charEngine.get_NumericValue(c)));
                        }
                        else
                        {
                            strBldr.Append(c);
                        }
                    }
                    tssBldr.Replace(tri.ichMin, tri.ichLim, strBldr.ToString(), ttp);
                }
            }
            if (numbersFound)
            {
                para.Contents = tssBldr.GetString();
            }
            return(numbersFound);
        }
Esempio n. 4
0
        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");
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Ensures that all styles that are used in the specified paragraph are marked as InUse
		/// </summary>
		/// <param name="para">The paragraph to scan for used styles.</param>
		/// <param name="scr">Scripture.</param>
		/// ------------------------------------------------------------------------------------
		private static void EnsureStylesInUseSetForPara(IScrTxtPara para, IScripture scr)
		{
			IStStyle paraStyle = scr.FindStyle(para.StyleName);
			if (paraStyle == null)
			{
				para.StyleName = para.DefaultStyleName;
				paraStyle = scr.FindStyle(para.StyleName);
			}
			((StStyle)paraStyle).InUse = true;

			ITsString paraContents = para.Contents;
			for (int iRun = 0; iRun < paraContents.RunCount; iRun++)
			{
				string charStyleName = paraContents.get_StringProperty(iRun, (int)FwTextPropType.ktptNamedStyle);
				if (!string.IsNullOrEmpty(charStyleName))
				{
					IStStyle charStyle = scr.FindStyle(charStyleName);
					if (charStyle == null)
					{
						// FWR-2594: Converted FW 6.0 project can contain runs with styles that were deleted
						// cleanest fix was to recreate the missing style and allow the user to clean up the text
						// later.
						Logger.WriteEvent("EnsureStylesInUseSetForPara: Deleted style (" + charStyleName + ") still in use, recreated it.");
						charStyle = para.Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(scr.StylesOC, charStyleName,
							ContextValues.General, StructureValues.Undefined, FunctionValues.Prose, true, 0, false);
					}
					((StStyle)charStyle).InUse = true;
				}
			}
		}