Ejemplo n.º 1
0
		public void TestReplaceFormerStyles()
		{
			DummyTeStylesXmlAccessor acc = new DummyTeStylesXmlAccessor(m_scr, null);

			string headingStyleNameToDelete = null;
			string bodyStyleNameToDelete = null;
			foreach (IStStyle style in m_scr.StylesOC)
			{
				if (style.Context == ContextValues.Text)
				{
					if (style.Structure == StructureValues.Heading &&
						style.Type == StyleType.kstParagraph &&
						style.Name != ScrStyleNames.SectionHead)
						headingStyleNameToDelete = style.Name;
					else if (style.Structure == StructureValues.Body &&
						style.Type == StyleType.kstParagraph &&
						style.Name != ScrStyleNames.NormalParagraph)
						bodyStyleNameToDelete = style.Name;
				}
				if (headingStyleNameToDelete != null && bodyStyleNameToDelete != null)
					break;
			}
			Assert.IsNotNull(headingStyleNameToDelete, "Couldn't find a real style for test -- need to create a bogus heading para style");
			Assert.IsNotNull(bodyStyleNameToDelete, "Couldn't find a real style for test -- need to create a bogus body para style");
			IStStyle styDeleteThisTitleStyle = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create();
			m_scr.StylesOC.Add(styDeleteThisTitleStyle);
			styDeleteThisTitleStyle.Name = "Auf wiedersehen";
			styDeleteThisTitleStyle.Context = ContextValues.Title;
			styDeleteThisTitleStyle.Type = StyleType.kstParagraph;

			// Create a few paragraphs using some fake styles
			IScrBook book = m_scr.ScriptureBooksOS[0];
			IScrSection sect = book.SectionsOS[0];
			IStTxtPara hPara0 = (IStTxtPara)sect.HeadingOA.ParagraphsOS[0];
			IStTxtPara cPara0 = (IStTxtPara)sect.ContentOA.ParagraphsOS[0];
			IStTxtPara tPara0 = (IStTxtPara)book.TitleOA.ParagraphsOS[0];
			book = m_scr.ScriptureBooksOS[1];
			IFdoOwningSequence<IScrSection> sections = book.SectionsOS;
			sect = sections[sections.Count - 1];
			IStTxtPara hPara1 = (IStTxtPara)sect.HeadingOA.ParagraphsOS[0];
			IFdoOwningSequence<IStPara> paras = sect.ContentOA.ParagraphsOS;
			IStTxtPara cPara1 = (IStTxtPara)paras[paras.Count - 1];
			IStTxtPara tPara1 = (IStTxtPara)book.TitleOA.ParagraphsOS[0];

			// Change the paragraph style to something bogus
			ITsPropsBldr bldr = TsPropsBldrClass.Create();
			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "To Be Replaced");
			ITsTextProps props = bldr.GetTextProps();
			hPara0.StyleRules = props;
			cPara0.StyleRules = props;
			tPara0.StyleRules = props;
			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, headingStyleNameToDelete);
			hPara1.StyleRules = bldr.GetTextProps();
			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, bodyStyleNameToDelete);
			cPara1.StyleRules = bldr.GetTextProps();
			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, styDeleteThisTitleStyle.Name);
			tPara1.StyleRules = bldr.GetTextProps();

			// Add some runs using a bogus character style
			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Wacky Char Style");
			props = bldr.GetTextProps();

			ITsStrBldr strBldr = hPara0.Contents.GetBldr();
			strBldr.Replace(0, 0, "glub", props);
			hPara0.Contents = strBldr.GetString();

			strBldr = cPara0.Contents.GetBldr();
			strBldr.Replace(3, 3, "glub", props);
			cPara0.Contents = strBldr.GetString();

			strBldr = tPara0.Contents.GetBldr();
			strBldr.Replace(3, 3, "glub", props);
			tPara0.Contents = strBldr.GetString();

			bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Be Gone");
			props = bldr.GetTextProps();

			strBldr = hPara1.Contents.GetBldr();
			strBldr.Replace(3, 3, "glub", props);
			hPara1.Contents = strBldr.GetString();

			strBldr = cPara1.Contents.GetBldr();
			strBldr.Replace(3, 3, "glub", props);
			cPara1.Contents = strBldr.GetString();

			// Simulate a paragraph style replacement
			acc.StyleReplacements["To Be Replaced"] = "With This";
			acc.StyleReplacements["Wacky Char Style"] = "Sane Char Style";
			//acc.DeletedStyles.Add(headingStyleNameToDelete);
			//acc.DeletedStyles.Add(bodyStyleNameToDelete);
			//acc.DeletedStyles.Add(styDeleteThisTitleStyle.Name);
			//acc.DeletedStyles.Add("Be Gone");
			acc.CallReplaceFormerStyles();

			// Check replaced paragraph style
			string styleName = hPara0.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("With This", styleName);
			styleName = cPara0.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("With This", styleName);
			styleName = tPara0.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("With This", styleName);
			// Check deleted paragraph styles
			styleName = hPara1.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(ScrStyleNames.SectionHead, styleName);
			styleName = cPara1.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(ScrStyleNames.NormalParagraph, styleName);
			styleName = tPara1.StyleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(ScrStyleNames.MainBookTitle, styleName);

			//Check replaced character style
			props = hPara0.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("Sane Char Style", styleName);
			props = cPara0.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("Sane Char Style", styleName);
			props = tPara0.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual("Sane Char Style", styleName);
			// Check deleted character styles
			props = hPara1.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(null, styleName);
			props = cPara1.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(null, styleName);
			props = tPara1.Contents.get_PropertiesAt(4);
			styleName = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle);
			Assert.AreEqual(null, styleName);
		}