Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Append a new section to the given book, having the specified text as the section
        /// head. The new section will have an empty content text created also.
        /// </summary>
        /// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
        /// <param name="book">The book to which the section is to be appended</param>
        /// <param name="sSectionHead">The text of the new section head. Can be a simple string
        /// or a format string. (See CreateText for the definition of the format string)</param>
        /// <param name="paraStyleName">paragraph style to apply to the section head</param>
        /// <returns>The newly created section</returns>
        /// ------------------------------------------------------------------------------------
        internal static ScrSection CreateSection(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book,
                                                 string sSectionHead, string paraStyleName)
        {
            // Create a section
            ScrSection section = new ScrSection();

            book.SectionsOS.Append(section);

            // Create a section head for this section
            section.HeadingOA = new StText();

            if (sSectionHead.Length == 0 || sSectionHead[0] != '\\')
            {
                // create a simple section head with no character style
                StTxtParaBldr paraBldr = new StTxtParaBldr(scrInMemoryCache.Cache);
                paraBldr.ParaProps = StyleUtils.ParaStyleTextProps(paraStyleName);
                paraBldr.AppendRun(sSectionHead,
                                   StyleUtils.CharStyleTextProps(null, scrInMemoryCache.Cache.DefaultVernWs));
                paraBldr.CreateParagraph(section.HeadingOAHvo);
            }
            else
            {
                // Create a more complex section head from the given format string
                // insert a new para in the title
                StTxtPara para = new StTxtPara();
                section.HeadingOA.ParagraphsOS.Append(para);
                // set the para's fields
                scrInMemoryCache.AddFormatTextToMockedPara(book, para, sSectionHead, scrInMemoryCache.Cache.DefaultVernWs);
                para.StyleRules = StyleUtils.ParaStyleTextProps(paraStyleName);
            }

            section.ContentOA = new StText();
            section.AdjustReferences();
            return(section);
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a paragraph from a format string, and append it to the given section's
        /// heading.
        /// </summary>
        /// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
        /// <param name="book">book to use</param>
        /// <param name="section">section to append to</param>
        /// <param name="format">(See CreateText for the definition of the format string)</param>
        /// <param name="ws">writing system to use</param>
        /// <param name="paraStyle">paragraph style name</param>
        /// <returns>the new paragraph</returns>
        /// ------------------------------------------------------------------------------------
        internal static StTxtPara AppendParagraphToSectionHead(ScrInMemoryFdoCache scrInMemoryCache,
                                                               IScrBook book, IScrSection section, string format, int ws, string paraStyle)
        {
            // insert a new para in the section content
            StTxtPara para = new StTxtPara();

            section.HeadingOA.ParagraphsOS.Append(para);

            // set the para's fields
            scrInMemoryCache.AddFormatTextToMockedPara(book as ScrBook, para, format, ws);
            para.StyleRules = StyleUtils.ParaStyleTextProps(paraStyle);

            return(para);
        }
Пример #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a title paragrpaph for the given book.
        /// </summary>
        /// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
        /// <param name="book">The book</param>param>
        /// <param name="sTitle">The text of the title. Can be a simple string or a format
        /// string. (See InMemoryFdoCache.CreateFormatText for the definition of the
        /// format string)</param>
        /// ------------------------------------------------------------------------------------
        internal static void SetTitle(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book, string sTitle)
        {
            book.TitleOA = new StText();

            if (sTitle[0] != '\\')
            {
                scrInMemoryCache.AddTitleToMockedBook(book.Hvo, sTitle);
            }
            else
            {
                // Create a more complex title from the given format string
                // insert a new para in the title
                StTxtPara para = new StTxtPara();
                book.TitleOA.ParagraphsOS.Append(para);
                // set the para's fields
                scrInMemoryCache.AddFormatTextToMockedPara(book, para, sTitle, scrInMemoryCache.Cache.DefaultVernWs);
                para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.MainBookTitle);
            }
        }