Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a new real style in the stylesheet for this proxy, if needed.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void AddStyleToStylesheet()
        {
            if (m_style != null || m_Context == ContextValues.EndMarker || m_sStyleName == null)
            {
                return;
            }
            // If m_ttpFormattingProps has not been set up, initialize it now
            if (m_ttpFormattingProps == null)
            {
                ITsPropsBldr tsPropsBldr = TsStringUtils.MakePropsBldr();
                m_ttpFormattingProps = tsPropsBldr.GetTextProps();                 // default properties
            }

            // Get an hvo for the new style
            int hvoStyle = m_LcmStyleSheet.MakeNewStyle();

            m_style = m_LcmStyleSheet.Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvoStyle);

            // PutStyle() adds the style to the stylesheet. we'll give it the properties we
            // are aware of.
            m_LcmStyleSheet.PutStyle(m_sStyleName, string.Empty, hvoStyle, 0,
                                     m_StyleType == StyleType.kstParagraph ? hvoStyle : 0, (int)m_StyleType, false, false, m_ttpFormattingProps);

            // base the new style on "Paragraph"
            if (m_StyleType == StyleType.kstParagraph)
            {
                m_style.BasedOnRA = m_LcmStyleSheet.FindStyle(ScrStyleNames.NormalParagraph);
                m_style.Context   = m_style.BasedOnRA.Context;
                m_style.Structure = m_style.BasedOnRA.Structure;
                m_style.Function  = m_style.BasedOnRA.Function;
            }
        }
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Constructor with ContextValues and MarkerDomain as a parameters.
        /// </summary>
        /// <param name="sStyleName">Name of the style.</param>
        /// <param name="styleType">kstCharacter or kstParagraph</param>
        /// <param name="ws">character or paragraph writing system</param>
        /// <param name="context">Context that will be used if this is a new style (otherwise existing
        /// context in DB will be used), see ContextValues for possible types</param>
        /// <param name="domain">The marker domain to use</param>
        /// <param name="styleSheet">The style sheet</param>
        /// ------------------------------------------------------------------------------------
        public ImportStyleProxy(string sStyleName, StyleType styleType, int ws,
                                ContextValues context, MarkerDomain domain, LcmStyleSheet styleSheet)
        {
            m_LcmStyleSheet = styleSheet;
            m_domain        = domain;
            Debug.Assert(m_LcmStyleSheet != null);

            m_ttpFormattingProps = null;
            m_fIsScriptureStyle  = true;     //default
            m_sEndMarker         = null;     //default

            if (context == ContextValues.EndMarker)
            {                       // this proxy represents an end marker - not a style; set bogus info
                sStyleName = "End"; //name does not matter
                styleType  = StyleType.kstCharacter;
            }
            else if (sStyleName != null)
            {
                // Determine whether style exists in the StyleSheet
                Debug.Assert(ws != 0);
                m_style = m_LcmStyleSheet.FindStyle(sStyleName);
                if (m_style != null)
                {
                    // If this is an existing style, the actual type, context, structure, and
                    // function always override the requested values.
                    styleType   = m_style.Type;
                    context     = (ContextValues)m_style.Context;
                    m_structure = (StructureValues)m_style.Structure;
                    m_function  = (FunctionValues)m_style.Function;
                }
            }

            m_sStyleName = sStyleName;
            m_StyleType  = styleType;
            m_ws         = ws;
            m_Context    = context;

//			//force StartOfFootnote marker to be processed as a para style proxy having para props
//			if (context == StyleRole.StartOfFootnote)
//				m_StyleType = StyleType.kstParagraph;

            //set the text property vars for this proxy
            SetTextProps();
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Appends the given text as a hyperlink to the given URL.
        /// </summary>
        /// <param name="strBldr">The string builder.</param>
        /// <param name="ws">The HVO of the writing system to use for the added text.</param>
        /// <param name="sLinkText">The text which should appear as the hyperlink text</param>
        /// <param name="sUrl">The URL that is the target of the hyperlink.</param>
        /// <param name="stylesheet">The stylesheet.</param>
        /// <returns><c>true</c> if the hyperlink was successfully inserted; <c>false</c>
        /// otherwise (indicating that the hyperlink style could not be found in the given
        /// stylesheet). In either case, the link text will be appended to the string builder.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public static bool AddHyperlink(ITsStrBldr strBldr, int ws, string sLinkText, string sUrl,
                                        LcmStyleSheet stylesheet)
        {
            var hyperlinkStyle = stylesheet.FindStyle(StyleServices.Hyperlink);

            if (hyperlinkStyle == null)
            {
                return(false);
            }

            if (stylesheet != null && stylesheet.Cache != null && stylesheet.Cache.ProjectId != null)
            {
                sUrl = FwLinkArgs.FixSilfwUrlForCurrentProject(sUrl, stylesheet.Cache.ProjectId.Name);
            }
            int ichStart = strBldr.Length;

            strBldr.Replace(ichStart, ichStart, sLinkText, StyleUtils.CharStyleTextProps(null, ws));
            StringServices.MarkTextInBldrAsHyperlink(strBldr, ichStart, strBldr.Length,
                                                     sUrl, hyperlinkStyle);
            return(true);
        }
Exemple #4
0
        public void BasicTest()
        {
            int cStylesOrig = m_styleSheet.CStyles;

            Assert.IsTrue(cStylesOrig > 10);
            Assert.IsNotNull(m_styleSheet.GetStyleRgch(0, "Section Head"));
            Assert.IsNotNull(m_styleSheet.GetStyleRgch(0, "Verse Number"));

            // create four new proxies;  verify that they properly determine if they are
            //  mapped to the TE default stylesheet
            int wsVern = Cache.DefaultVernWs;
            int wsAnal = Cache.DefaultAnalWs;
            ImportStyleProxy proxy1 = new ImportStyleProxy("Section Head",
                                                           StyleType.kstParagraph, wsVern, ContextValues.Text, m_styleSheet);

            Assert.IsFalse(proxy1.IsUnknownMapping, "Section Head style should exist in DB");

            ImportStyleProxy proxy2 = new ImportStyleProxy("Verse Number",
                                                           StyleType.kstCharacter, wsVern, ContextValues.Text, m_styleSheet);

            Assert.IsFalse(proxy2.IsUnknownMapping, "Verse Number style should exist in DB");

            string           proxy3Name = "Tom Bogle";
            ImportStyleProxy proxy3     = new ImportStyleProxy(proxy3Name,
                                                               StyleType.kstParagraph, wsVern, m_styleSheet); //defaults to Text context

            Assert.IsTrue(proxy3.IsUnknownMapping, "Tom Bogle style shouldn't exist in DB");

            string           proxy4Name = "Todd Jones";
            ImportStyleProxy proxy4     = new ImportStyleProxy(proxy4Name,
                                                               StyleType.kstCharacter, wsVern, m_styleSheet); //defaults to Text context

            Assert.IsTrue(proxy4.IsUnknownMapping, "Todd Jones style shouldn't exist in DB");

            // verify basic proxy info - name, context, structure, function, styletype, endmarker
            Assert.AreEqual("Section Head", proxy1.StyleId);
            Assert.AreEqual(ContextValues.Text, proxy1.Context);
            Assert.AreEqual(StructureValues.Heading, proxy1.Structure);
            Assert.AreEqual(StyleType.kstParagraph, proxy1.StyleType);
            Assert.IsNull(proxy1.EndMarker);

            Assert.AreEqual(ContextValues.Text, proxy2.Context);
            Assert.AreEqual(StructureValues.Body, proxy2.Structure);
            Assert.AreEqual(FunctionValues.Verse, proxy2.Function);
            Assert.AreEqual(StyleType.kstCharacter, proxy2.StyleType);
            Assert.IsNull(proxy2.EndMarker);

            Assert.AreEqual(ContextValues.Text, proxy3.Context);
            // getting the text props will cause the style to be created in the database
            ITsTextProps props   = proxy3.TsTextProps;
            IStStyle     dbStyle = m_styleSheet.FindStyle(proxy3Name);

            Assert.AreEqual(ScrStyleNames.NormalParagraph, dbStyle.BasedOnRA.Name);
            Assert.AreEqual(StyleType.kstParagraph, proxy3.StyleType);
            Assert.IsNull(proxy3.EndMarker);

            Assert.AreEqual(ContextValues.Text, proxy4.Context);
            props   = proxy4.TsTextProps;
            dbStyle = m_styleSheet.FindStyle(proxy4Name);
            Assert.IsNull(dbStyle.BasedOnRA);
            Assert.AreEqual(StyleType.kstCharacter, proxy4.StyleType);
            Assert.IsNull(proxy4.EndMarker);

            // use SetFormat to add formatting props to unmapped proxy3
            ITsPropsBldr tsPropertiesBldr = TsStringUtils.MakePropsBldr();

            tsPropertiesBldr.SetIntPropValues((int)FwTextPropType.ktptItalic,
                                              (int)FwTextPropVar.ktpvEnum,
                                              (int)FwTextToggleVal.kttvForceOn);
            ITsTextProps formatProps3 = tsPropertiesBldr.GetTextProps();

            proxy3.SetFormat(formatProps3, false);

            // Test retrieval of ParaProps and TsTextProps
            Assert.IsNotNull(proxy1.TsTextProps);
            Assert.IsNotNull(proxy2.TsTextProps);
            // Besides returning the props, retrieving ParaProps or TsTextProps adds a
            // previously unmapped style to the stylesheet, so that proxy becomes mapped
            // Next two calls force creation of new styles
            Assert.IsNotNull(proxy3.TsTextProps);             // has benefit of SetFormat
            Assert.IsFalse(proxy3.IsUnknownMapping,
                           "Tom Bogle style should be created when getting TsTextProps");
            Assert.IsFalse(proxy4.IsUnknownMapping,
                           "Todd Jones style should be created when getting ParaProps");
            // verify that two new styles were added to the style sheet
            Assert.AreEqual(cStylesOrig + 2, m_styleSheet.CStyles);

            // verify that the added styles have the appropriate context, etc
            IStStyle style = m_styleSheet.FindStyle("Tom Bogle");

            Assert.AreEqual(ContextValues.Text, (ContextValues)style.Context);
            Assert.AreEqual(StructureValues.Body, (StructureValues)style.Structure);
            Assert.AreEqual(FunctionValues.Prose, (FunctionValues)style.Function);

            // Test the styletype override from stylesheet
            // We will attempt to construct a paragraph style proxy,
            //  but since in the stylesheet Chapter Number is a character style,
            //  character will override
            ImportStyleProxy proxy = new ImportStyleProxy("Chapter Number",
                                                          StyleType.kstParagraph, wsVern, m_styleSheet); //override as char style

            Assert.AreEqual(StyleType.kstCharacter, proxy.StyleType,
                            "Should override as character style");

            // verify TagType, EndMarker info
            proxy = new ImportStyleProxy("Xnote",             // This style doesn't exist in DB
                                         StyleType.kstParagraph, wsVern, ContextValues.Note, m_styleSheet);
            proxy.EndMarker = "Xnote*";
            Assert.AreEqual(ContextValues.Note, proxy.Context);
            Assert.AreEqual("Xnote*", proxy.EndMarker);

            // Verify that proxy doesn't attempt to create style when context is EndMarker
            proxy = new ImportStyleProxy("Xnote*",
                                         0, 0, ContextValues.EndMarker, m_styleSheet);
            int cStylesX = m_styleSheet.CStyles;

            // These calls should not add new style
            Assert.IsNull(proxy.TsTextProps);             //no props returned
            Assert.AreEqual(ContextValues.EndMarker, proxy.Context);
            Assert.IsTrue(proxy.IsUnknownMapping, "Xnote* should not exist");
            Assert.AreEqual(cStylesX, m_styleSheet.CStyles);
        }