/// ------------------------------------------------------------------------------------ /// <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 = TsPropsBldrClass.Create(); m_ttpFormattingProps = tsPropsBldr.GetTextProps(); // default properties } // Get an hvo for the new style int hvoStyle = m_FwStyleSheet.MakeNewStyle(); m_style = m_FwStyleSheet.Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvoStyle); // PutStyle() adds the style to the stylesheet. we'll give it the properties we // are aware of. m_FwStyleSheet.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_FwStyleSheet.FindStyle(ScrStyleNames.NormalParagraph); m_style.Context = m_style.BasedOnRA.Context; m_style.Structure = m_style.BasedOnRA.Structure; m_style.Function = m_style.BasedOnRA.Function; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the font size line height and space before after. /// </summary> /// <param name="stylesheet">The real stylesheet.</param> /// <param name="styleName">Name of the style to modify.</param> /// <param name="basedOnStyle">The name of the based-on style.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="lineHeight">Height of the line.</param> /// <param name="spaceBefore">The space before.</param> /// <param name="spaceAfter">The space after.</param> /// ------------------------------------------------------------------------------------ private static void SetFontSizeLineHeightAndSpaceBeforeAfter(FwStyleSheet stylesheet, string styleName, string basedOnStyle, int fontSize, int lineHeight, int spaceBefore, int spaceAfter) { IStStyle style = stylesheet.FindStyle(styleName); TsPropsBldr tpb = (TsPropsBldr)style.Rules.GetBldr(); if (fontSize != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, fontSize); } if (lineHeight != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, lineHeight); } if (spaceBefore != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvMilliPoint, spaceBefore); } if (spaceAfter != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvMilliPoint, spaceAfter); } int hvoBasedOn = 0; if (!string.IsNullOrEmpty(basedOnStyle)) { IStStyle basedOn = stylesheet.FindStyle(basedOnStyle); if (basedOn != null) { hvoBasedOn = basedOn.Hvo; } } stylesheet.PutStyle(styleName, string.Empty, style.Hvo, hvoBasedOn, 0, (int)StyleType.kstParagraph, true, false, tpb.GetTextProps()); }
/// ------------------------------------------------------------------------------------ /// <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, FwStyleSheet styleSheet) { m_FwStyleSheet = styleSheet; m_domain = domain; Debug.Assert(m_FwStyleSheet != 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_FwStyleSheet.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(); }
/// ------------------------------------------------------------------------------------ /// <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, FwStyleSheet 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, stylesheet.Cache.ProjectId.ServerName); } int ichStart = strBldr.Length; strBldr.Replace(ichStart, ichStart, sLinkText, StyleUtils.CharStyleTextProps(null, ws)); StringServices.MarkTextInBldrAsHyperlink(strBldr, ichStart, strBldr.Length, sUrl, hyperlinkStyle); return(true); }
public void ExportFootnote_Unicode() { CheckDisposed(); int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; ITsStrFactory stringFactory = TsStrFactoryClass.Create(); // Create a book with a section that has a paragraph with some text and a footnote! m_scrInMemoryCache.AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); StFootnote footnote = m_scrInMemoryCache.AddFootnote(m_book, m_para, 2); m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; m_scr.FootnoteMarkerSymbol = "¶"; m_scr.DisplaySymbolInFootnote = true; footnote.FootnoteMarker.UnderlyingTsString = stringFactory.MakeString(null, Cache.DefaultVernWs); StTxtPara footnotePara = new StTxtPara(); footnote.ParagraphsOS.Append(footnotePara); footnotePara.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); string footnoteText = "C\u00f2\u00f3\u013a footnot\u0113"; footnotePara.Contents.UnderlyingTsString = stringFactory.MakeString(footnoteText, Cache.DefaultVernWs); m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet); m_exporter.CallExportFootnote(new ScrFootnote(Cache, footnote.Hvo)); // Verify the contents of the temp file m_exporter.CloseOutputFile(); using (StreamReader file = new StreamReader(m_fileName, Encoding.ASCII)) { string line1 = file.ReadLine(); string line2 = file.ReadLine(); // the first line is the marker emitted into the text stream. // Footnote markers now have the footnote marker style applied Assert.AreEqual(@"\*\cs" + markerStyleNumber + @" \uc0\u182 }", line1); Assert.AreEqual(@"{\footnote \pard\plain \s" + footnoteStyleNumber + @"\f2\fs20{" + @"\*\cs" + markerStyleNumber + @" \uc0\u182 " + @"}{ }{C\uc0\u242 \uc0\u243 \uc0\u314 footnot\uc0\u275 }", line2); } }
/// ------------------------------------------------------------------------------------ /// <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) { // If m_ttpFormattingProps has not been set up, initialize it now if (m_ttpFormattingProps == null) { ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); m_ttpFormattingProps = tsPropsBldr.GetTextProps(); // default properties } // Get an hvo for the new style int hvoStyle = m_FwStyleSheet.MakeNewStyle(); m_style = new StStyle(m_FwStyleSheet.Cache, hvoStyle); // PutStyle() adds the style to the stylesheet. we'll give it the properties we // are aware of. m_FwStyleSheet.PutStyle(m_sStyleName, string.Empty, hvoStyle, 0, hvoStyle, (int)m_StyleType, false, false, m_ttpFormattingProps); // base the new style on "Paragraph" if (m_StyleType == StyleType.kstParagraph) { m_style.BasedOnRA = m_FwStyleSheet.FindStyle(ScrStyleNames.NormalParagraph); m_style.Context = m_style.BasedOnRA.Context; m_style.Structure = m_style.BasedOnRA.Structure; m_style.Function = m_style.BasedOnRA.Function; } } // Make sure this style is set to being used (UserLevel < 0) if (m_style != null && m_style.UserLevel > 0) { m_style.UserLevel = -m_style.UserLevel; } }
public void ExportFootnote_Unicode() { int markerStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.FootnoteMarker).IndexInOwner + 1; int footnoteStyleNumber = m_styleSheet.FindStyle(ScrStyleNames.NormalFootnoteParagraph).IndexInOwner + 1; ITsStrFactory stringFactory = TsStrFactoryClass.Create(); // Create a book with a section that has a paragraph with some text and a footnote! AddRunToMockedPara(m_para, "My text for footnotes", string.Empty); IScrFootnote footnote = AddFootnote(m_book, m_para, 2); m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; m_scr.FootnoteMarkerSymbol = "¶"; m_scr.DisplaySymbolInFootnote = true; footnote.FootnoteMarker = stringFactory.MakeString(null, Cache.DefaultVernWs); IScrTxtPara footnotePara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( footnote, ScrStyleNames.NormalFootnoteParagraph); string footnoteText = "C\u00f2\u00f3\u013a footnot\u0113"; footnotePara.Contents = stringFactory.MakeString(footnoteText, Cache.DefaultVernWs); m_exporter = new DummyExportRtf(m_fileName, Cache, m_styleSheet); m_exporter.CallExportFootnote(footnote); // Verify the contents of the temp file m_exporter.CloseOutputFile(); using (TextReader file = FileUtils.OpenFileForRead(m_fileName, Encoding.ASCII)) { string line1 = file.ReadLine(); string line2 = file.ReadLine(); // the first line is the marker emitted into the text stream. // Footnote markers now have the footnote marker style applied Assert.AreEqual(@"\*\cs" + markerStyleNumber + @" \uc0\u182 }", line1); Assert.AreEqual(@"{\footnote \pard\plain \s" + footnoteStyleNumber + @"\f1\fs20{" + @"\*\cs" + markerStyleNumber + @" \uc0\u182 " + @"}{ }{Co\uc0\u768 o\uc0\u769 l\uc0\u769 footnote\uc0\u772 }", line2); } }
/// ------------------------------------------------------------------------------------ /// <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, FwStyleSheet styleSheet) { m_FwStyleSheet = styleSheet; m_domain = domain; Debug.Assert(m_FwStyleSheet != 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_FwStyleSheet.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(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the font size line height and space before after. /// </summary> /// <param name="stylesheet">The real stylesheet.</param> /// <param name="styleName">Name of the style to modify.</param> /// <param name="basedOnStyle">The name of the based-on style.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="lineHeight">Height of the line.</param> /// <param name="spaceBefore">The space before.</param> /// <param name="spaceAfter">The space after.</param> /// ------------------------------------------------------------------------------------ private static void SetFontSizeLineHeightAndSpaceBeforeAfter(FwStyleSheet stylesheet, string styleName, string basedOnStyle, int fontSize, int lineHeight, int spaceBefore, int spaceAfter) { IStStyle style = stylesheet.FindStyle(styleName); TsPropsBldr tpb = (TsPropsBldr)style.Rules.GetBldr(); if (fontSize != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, fontSize); } if (lineHeight != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, lineHeight); } if (spaceBefore != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvMilliPoint, spaceBefore); } if (spaceAfter != -1) { tpb.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvMilliPoint, spaceAfter); } int hvoBasedOn = 0; if (!string.IsNullOrEmpty(basedOnStyle)) { IStStyle basedOn = stylesheet.FindStyle(basedOnStyle); if (basedOn != null) hvoBasedOn = basedOn.Hvo; } stylesheet.PutStyle(styleName, string.Empty, style.Hvo, hvoBasedOn, 0, (int)StyleType.kstParagraph, true, false, tpb.GetTextProps()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Applies the given URL as a hotlink to the currently selected text, if any, or /// inserts a link to the URL. /// </summary> /// <param name="clip">The URL.</param> /// <param name="stylesheet">The stylesheet.</param> /// ------------------------------------------------------------------------------------ public void ConvertSelToLink(string clip, FwStyleSheet stylesheet) { CheckDisposed(); var hyperlinkStyle = stylesheet.FindStyle(StyleServices.Hyperlink); if (m_callbacks == null || m_callbacks.EditedRootBox == null || hyperlinkStyle == null) return; IVwSelection sel = m_callbacks.EditedRootBox.Selection; ISilDataAccess sda = m_callbacks.EditedRootBox.DataAccess; var actionHandler = sda.GetActionHandler(); if(actionHandler == null) return; // no way we can do it. ITsString tssLink; bool fGotItAll; sel.GetFirstParaString(out tssLink, " ", out fGotItAll); ITsStrBldr tsb = tssLink.GetBldr(); if (sel.IsRange) { // Use the text of the selection as the text of the link int ich = tssLink.Text.IndexOf(Environment.NewLine); if (!fGotItAll || ich >= 0) { tsb.ReplaceTsString(ich, tsb.Length, null); int ichTop; if (sel.EndBeforeAnchor) ichTop = sel.get_ParagraphOffset(true); else ichTop = sel.get_ParagraphOffset(false); SelectionHelper helper = SelectionHelper.Create(sel, EditedRootBox.Site); helper.IchAnchor = ichTop; helper.IchEnd = ich; sel = helper.Selection; } //sel.GetSelectionString(out tssLink, " "); } if (!sel.IsRange) { ITsStrFactory tsf = TsStrFactoryClass.Create(); tssLink = tsf.MakeString(clip, sda.WritingSystemFactory.UserWs); tsb = tssLink.GetBldr(); } using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(actionHandler, EditedRootBox.Site, RootSiteStrings.ksUndoInsertLink, RootSiteStrings.ksRedoInsertLink)) { if (m_cache != null && m_cache.ProjectId != null) clip = FwLinkArgs.FixSilfwUrlForCurrentProject(clip, m_cache.ProjectId.Name, m_cache.ProjectId.ServerName); var filename = StringServices.MarkTextInBldrAsHyperlink(tsb, 0, tsb.Length, clip, hyperlinkStyle, m_cache.LanguageProject.LinkedFilesRootDir); if (FileUtils.IsFilePathValid(filename)) { Debug.Assert(m_cache.LangProject.FilePathsInTsStringsOA != null, "Somehow migration #30 did not add the FilePathsInTsStrings CmFolder. Fix by modifying FindOrCreateFolder()"); DomainObjectServices.FindOrCreateFile(m_cache.LangProject.FilePathsInTsStringsOA, filename); } tssLink = tsb.GetString(); sel.ReplaceWithTsString(tssLink); undoTaskHelper.RollBack = false; // Arrange that immediate further typing won't extend link. sel = Callbacks.EditedRootBox.Selection; // may have been changed. if (sel == null) return; ITsPropsBldr pb = tssLink.get_PropertiesAt(0).GetBldr(); pb.SetStrPropValue((int)FwTextPropType.ktptObjData, null); pb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null); sel.SetTypingProps(pb.GetTextProps()); } }
/// ------------------------------------------------------------------------------------ /// <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, FwStyleSheet 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, stylesheet.Cache.ProjectId.ServerName); int ichStart = strBldr.Length; strBldr.Replace(ichStart, ichStart, sLinkText, StyleUtils.CharStyleTextProps(null, ws)); StringServices.MarkTextInBldrAsHyperlink(strBldr, ichStart, strBldr.Length, sUrl, hyperlinkStyle); return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Marks the indicated text in the given string builder as a hyperlink. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ichStart">The index of the first character in the string builder which /// should be marked as hyperlink text.</param> /// <param name="ichLim">The "limit" index in the string builder indicating the end of /// the hyperlink text.</param> /// <param name="url">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)</returns> /// ------------------------------------------------------------------------------------ public static bool MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart, int ichLim, string url, FwStyleSheet stylesheet) { IStStyle hyperlinkStyle = stylesheet.FindStyle(StStyle.Hyperlink); if (hyperlinkStyle == null) return false; string propVal = Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName).ToString() + url; hyperlinkStyle.InUse = true; strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptNamedStyle, StStyle.Hyperlink); strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptObjData, propVal); return true; }
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 = TsPropsBldrClass.Create(); 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(proxy1.ParaProps); Assert.IsNotNull(proxy2.TsTextProps); Assert.IsNull(proxy2.ParaProps, "No para props for a char style"); // 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.IsNull(proxy4.ParaProps); // no 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.IsNull(proxy.ParaProps); //no props returned Assert.AreEqual(ContextValues.EndMarker, proxy.Context); Assert.IsTrue(proxy.IsUnknownMapping, "Xnote* should not exist"); Assert.AreEqual(cStylesX, m_styleSheet.CStyles); }