public void WriteParatextLdsFile()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			DummyFileWriter actualLds = new DummyFileWriter();
			ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
				Cache.DefaultVernWs, normalEntry, actualLds);

			// Verify the .lds file
			string[] expectedLds =
			{
				"[General]",
				"codepage=65001",
				"RTL=F",
				"font=Wingdings",
				"name=French",
				"size=14",
				string.Empty,
				"[Checking]",
				string.Empty,
				"[Characters]",
				string.Empty,
				"[Punctuation]"
			};

			actualLds.VerifyOutput(expectedLds);
		}
Esempio n. 2
0
		public void WriteUsfmStyFile()
		{
			CheckDisposed();

			DummyUsfmStyEntry entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("id", entry);
			entry.P6Name = "(id) File - Identification";
			entry.Description = "File identification information (BOOKID, FILENAME, EDITOR, MODIFICATION DATE)";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Book;
			entry.Structure = StructureValues.Undefined;
			entry.TextPropertiesFromStyFile = "paragraph nonpublishable nonvernacular book";
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("c", entry);
			entry.Name = "Chapter Number";
			entry.P6Name = "(c) Chapter Number";
			entry.Description = "Chapter number (necessary for normal Paratext operation)";
			entry.IsParagraphStyle = false;
			entry.OccursUnder = "id";
			entry.Rank = 8;
			entry.Context = ContextValues.Text;
			entry.Structure = StructureValues.Body;
			entry.Function = FunctionValues.Chapter;
			entry.DefaultFontInfo.m_bold.ExplicitValue = true;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 18000;
			entry.SpaceBefore = 8000;
			entry.SpaceAfter = 4000;

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("v", entry);
			entry.Name = "Verse Number";
			entry.P6Name = "(v) Verse Number";
			entry.Description = "A verse number (Necessary for normal paratext operation)";
			entry.IsParagraphStyle = false;
			entry.OccursUnder = "li li1 li2 li3 li4 m mi mis nb p pc ph phi pi pr ps psi q q1 q2 q3 qc qr tc1 tc2 tc3 tc4 s3 d";
			entry.Context = ContextValues.Text;
			entry.Structure = StructureValues.Body;
			entry.Function = FunctionValues.Verse;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;
			entry.DefaultFontInfo.m_superSub.ExplicitValue = FwSuperscriptVal.kssvSuper;

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("p", entry);
			entry.Name = "Paragraph";
			entry.P6Name = "(p) Paragraph - Normal, First Line Indent";
			entry.Description = "Paragraph text, with first line indent";
			entry.IsParagraphStyle = true;
			entry.OccursUnder = "c";
			entry.Rank = 4;
			entry.Context = ContextValues.Text;
			entry.Structure = StructureValues.Body;
			entry.Function = FunctionValues.Prose;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;
			entry.FirstLineIndent = (int)(0.125 * 72000);

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("rem", entry);
			entry.Name = "Remark";
			entry.P6Name = "(rem) File - Remark";
			entry.Description = "Comments and remarks";
			entry.OccursUnder = "id ide";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Annotation;
			entry.Structure = StructureValues.Undefined;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;
			entry.DefaultFontInfo.m_fontColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)16711680);

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("Custom_User-defined_Style", entry);
			entry.Name = "Custom User-defined Style";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Text;
			entry.Structure = StructureValues.Body;
			entry.Function = FunctionValues.Prose;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 10000;
			entry.DefaultFontInfo.m_fontName.ExplicitValue = "Courier New";
			entry.SpaceAfter = 6000;

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("is2", entry);
			entry.Name = "Intro Section Head Minor";
			entry.P6Name = "(is2) Introduction - Section Heading Level 2";
			entry.Description = "Introduction section heading, level 2 ";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Intro;
			entry.Structure = StructureValues.Heading;
			entry.Function = FunctionValues.Prose;
			entry.OccursUnder = "id";
			entry.Rank = 6;
			entry.Level = 2;
			entry.NotRepeatable = true;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;
			entry.DefaultFontInfo.m_bold.ExplicitValue = true;
			entry.Alignment = FwTextAlign.ktalCenter;
			entry.SpaceBefore = 8000;
			entry.SpaceAfter = 4000;

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("f", entry);
			entry.P6Name = "(f...f*) Footnote ";
			entry.Endmarker = "f*";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Note;
			entry.OccursUnder = "c li li1 li2 li3 li4 m mi mis nb p pc ph phi pi pr ps psi q q1 q2 q3 qc qr sp tc1 tc2 tc3 tc4 ms ms1 ms2 s s1 s2 s3 spd d ip";
			entry.TextPropertiesFromStyFile = "publishable vernacular note";
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 12000;
			entry.XmlTag = "<usfm:f>";

			entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("b", entry);
			entry.P6Name = "(b) Poetry - Stanza Break (Blank Line)";
			entry.IsParagraphStyle = true;
			entry.Context = ContextValues.Text;
			entry.Structure = StructureValues.Body;
			entry.Function = FunctionValues.Prose;
			entry.TextPropertiesFromStyFile = "paragraph publishable vernacular poetic";
			entry.Poetic = true;
			entry.DefaultFontInfo.m_fontSize.ExplicitValue = 5000;
			entry.DefaultFontInfo.m_italic.ExplicitValue = true;
			entry.DefaultFontInfo.m_underline.ExplicitValue = FwUnderlineType.kuntSingle;
			entry.LeadingIndent = (int)(.25 * 72000);
			entry.TrailingIndent = (int)(.25 * 72000);

			DummyFileWriter writer = new DummyFileWriter();
			m_exporter.UsfmStyFileAccessor.SaveStyFile("Test project", writer, -1);

			// Verify the .sty file
			string[] expectedSty = new string[]
			{
				"## Stylesheet for exported TE project Test project ##",
				"",
				@"\Marker b",
				@"\Name (b) Poetry - Stanza Break (Blank Line)",
				@"\TextType VerseText",
				@"\TextProperties paragraph publishable vernacular poetic",
				@"\StyleType Paragraph",
				@"\Italic",
				@"\Underline",
				@"\FontSize 5",
				@"\LeftMargin .250",
				@"\RightMargin .250",
				"",
				@"\Marker c",
				@"\TEStyleName Chapter Number",
				@"\Name (c) Chapter Number",
				@"\Description Chapter number (necessary for normal Paratext operation)",
				@"\OccursUnder id",
				@"\Rank 8",
				@"\TextType ChapterNumber",
				@"\TextProperties chapter",
				@"\StyleType Paragraph",
				@"\Bold",
				@"\FontSize 18",
				@"\SpaceBefore 8",
				@"\SpaceAfter 4",
				"",
				@"\Marker Custom_User-defined_Style",
				@"\TEStyleName Custom User-defined Style",
				@"\Name Custom User-defined Style",
				@"\TextType VerseText",
				@"\TextProperties paragraph publishable vernacular",
				@"\StyleType Paragraph",
				@"\FontName Courier New",
				@"\FontSize 10",
				@"\SpaceAfter 6",
				"",
				@"\Marker f",
				@"\Endmarker f*",
				@"\Name (f...f*) Footnote",
				@"\OccursUnder c li li1 li2 li3 li4 m mi mis nb p pc ph phi pi pr ps psi q q1 q2 q3 qc qr sp tc1 tc2 tc3 tc4 ms ms1 ms2 s s1 s2 s3 spd d ip",
				@"\TextType NoteText",
				@"\TextProperties publishable vernacular note",
				@"\StyleType Note",
				@"\FontSize 12",
				@"\XMLTag <usfm:f>",
				"",
				@"\Marker id",
				@"\Name (id) File - Identification",
				@"\Description File identification information (BOOKID, FILENAME, EDITOR, MODIFICATION DATE)",
				@"\TextType Other",
				@"\TextProperties paragraph nonpublishable nonvernacular book",
				@"\StyleType Paragraph",
				@"\FontSize 12",
				"",
				@"\Marker is2",
				@"\TEStyleName Intro Section Head Minor",
				@"\Name (is2) Introduction - Section Heading Level 2",
				@"\Description Introduction section heading, level 2",
				@"\OccursUnder id",
				@"\Rank 6",
				@"\NotRepeatable",
				@"\TextType Section",
				@"\TextProperties paragraph publishable vernacular level_2",
				@"\StyleType Paragraph",
				@"\Bold",
				@"\FontSize 12",
				@"\Justification Center",
				@"\SpaceBefore 8",
				@"\SpaceAfter 4",
				"",
				@"\Marker p",
				@"\TEStyleName Paragraph",
				@"\Name (p) Paragraph - Normal, First Line Indent",
				@"\Description Paragraph text, with first line indent",
				@"\OccursUnder c",
				@"\Rank 4",
				@"\TextType VerseText",
				@"\TextProperties paragraph publishable vernacular",
				@"\StyleType Paragraph",
				@"\FontSize 12",
				@"\FirstLineIndent .125",
				"",
				@"\Marker rem",
				@"\TEStyleName Remark",
				@"\Name (rem) File - Remark",
				@"\Description Comments and remarks",
				@"\OccursUnder id ide",
				@"\TextType Other",
				@"\TextProperties paragraph nonpublishable nonvernacular",
				@"\StyleType Paragraph",
				@"\FontSize 12",
				@"\Color 16711680",
				"",
				@"\Marker v",
				@"\TEStyleName Verse Number",
				@"\Name (v) Verse Number",
				@"\Description A verse number (Necessary for normal paratext operation)",
				@"\OccursUnder li li1 li2 li3 li4 m mi mis nb p pc ph phi pi pr ps psi q q1 q2 q3 qc qr tc1 tc2 tc3 tc4 s3 d",
				@"\TextType VerseNumber",
				@"\TextProperties verse",
				@"\StyleType Character",
				@"\Superscript",
				@"\FontSize 12",
				""
			};

			writer.VerifyOutput(expectedSty);
		}
Esempio n. 3
0
		public void SetStyleMapping_Update()
		{
			CheckDisposed();

			DummyUsfmStyEntry entry = new DummyUsfmStyEntry();
			m_exporter.UsfmStyFileAccessor.Add("mt", entry);
			entry.SetUsfmStyProperty(@"\TEStyleName", "Book Title");
			entry.SetUsfmStyProperty(@"\Name", "(mt) Title - Major Title Level 1");
			entry.SetUsfmStyProperty(@"\Description", "The main title of the book (if single level)");
			entry.SetUsfmStyProperty(@"\OccursUnder", "id");
			entry.SetUsfmStyProperty(@"\Rank", "3");
			entry.SetUsfmStyProperty(@"\TextProperties", "paragraph publishable vernacular level_1");
			entry.SetUsfmStyProperty(@"\TextType", "Title");
			entry.SetUsfmStyProperty(@"\StyleType", "Paragraph");
			entry.SetUsfmStyProperty(@"\FontSize", "20");
			entry.SetUsfmStyProperty(@"\Bold", "");
			entry.SetUsfmStyProperty(@"\Justification", "Center");
			entry.SetUsfmStyProperty(@"\SpaceBefore", "8");
			entry.SetUsfmStyProperty(@"\SpaceAfter", "4");

			// The test base already creates all of the standard scripture styles. We just modify
			// one of them here for our test.
			ITsPropsBldr props;
			IStStyle mainTitleStyle = m_scr.FindStyle(ScrStyleNames.MainBookTitle);
			Assert.IsNotNull(mainTitleStyle, "Problem in test setup - Main Title should exist");
			props = mainTitleStyle.Rules.GetBldr();
			props.SetIntPropValues((int)FwTextPropType.ktptBold,
				(int)FwTextPropVar.ktpvEnum,
				(int)FwTextToggleVal.kttvOff);
			props.SetIntPropValues((int)FwTextPropType.ktptAlign,
				(int)FwTextPropVar.ktpvDefault, (int)FwTextAlign.ktalLeading);
			props.SetIntPropValues((int)FwTextPropType.ktptFontSize,
				(int)FwTextPropVar.ktpvMilliPoint, 22000);
			props.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore,
				(int)FwTextPropVar.ktpvMilliPoint, 2000);
			mainTitleStyle.Rules = props.GetTextProps();

			m_exporter.SetStyleMapping(ScrStyleNames.MainBookTitle, @"\mt");
			entry = (DummyUsfmStyEntry)m_exporter.UsfmEntries[ScrStyleNames.MainBookTitle];
			Assert.IsNotNull(entry);
			Assert.AreEqual(ScrStyleNames.MainBookTitle, entry.Name);
			Assert.AreEqual("(mt) Title - Major Title Level 1", entry.P6Name);
			Assert.AreEqual("The main title of the book (if single level)", entry.Description);
			Assert.AreEqual("id", entry.OccursUnder);
			Assert.AreEqual(3, entry.Rank);
			Assert.AreEqual("Title", entry.TextType);
			Assert.AreEqual("Paragraph", entry.StyleType);
			Assert.AreEqual(FwTextAlign.ktalLeading, entry.Alignment);
			Assert.IsFalse(entry.FontInfoForWs(-1).m_bold.Value);
			Assert.AreEqual(22000, entry.FontInfoForWs(-1).m_fontSize.Value);
			Assert.AreEqual("Title", entry.TextType);
			Assert.AreEqual("Paragraph", entry.StyleType);
			Assert.AreEqual("paragraph publishable vernacular level_1 ", entry.TextProperties);
			Assert.AreEqual(4000, entry.SpaceAfter);
			Assert.AreEqual(2000, entry.SpaceBefore);
		}
		public void UpdateParatextLdsFile_GeneralSectionMissing()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[OtherStuff]";

			DummyFileWriter writer = new DummyFileWriter();
			writer.Open("test.lds");
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
				ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

			// Verify the .lds file
			string[] expectedLdsContents =
			{
				"[OtherStuff]",
				//Environment.NewLine +
				"[General]",
				"codepage=65001",
				"font=Wingdings",
				"size=14",
				"name=French",
				"RTL=F"
			};

			writer.VerifyOutput(expectedLdsContents);
		}
		public void UpdateParatextLdsFile_UpdateFontAndSizeAndAddRTL()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[General]" + Environment.NewLine +
				"codepage=65001" + Environment.NewLine +
				"DialogFontsize=0" + Environment.NewLine +
				"LowerCaseLetters=" + Environment.NewLine +
				"NoCaseLetters=" + Environment.NewLine +
				"UpperCaseLetters=" + Environment.NewLine +
				"errors=" + Environment.NewLine +
				"font=Arial" + Environment.NewLine +
				"name=French" + Environment.NewLine +
				"separator=" + Environment.NewLine +
				"size=32" + Environment.NewLine +
				Environment.NewLine +
				"[Checking]" + Environment.NewLine +
				Environment.NewLine +
				"[Characters]" + Environment.NewLine +
				Environment.NewLine +
				"[Punctuation]" + Environment.NewLine +
				"diacritics=" + Environment.NewLine +
				"medial=";

			DummyFileWriter writer = new DummyFileWriter();
			writer.Open("test.lds");
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
				ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

			// Verify the .lds file
			string[] expectedLdsContents =
			{
				"[General]",
				"codepage=65001",
				"DialogFontsize=0",
				"LowerCaseLetters=",
				"NoCaseLetters=",
				"UpperCaseLetters=",
				"errors=",
				"font=Wingdings",
				"name=French",
				"separator=",
				"size=14",
				"RTL=F",
				//Environment.NewLine, string.Empty
				"[Checking]",
				//Environment.NewLine, string.Empty
				"[Characters]",
				//Environment.NewLine, string.Empty
				"[Punctuation]",
				"diacritics=",
				"medial="
			};
		   ((DummyFileWriter)writer).VerifyOutput(expectedLdsContents);
		}
		public void WriteParatextLdsFile_BT()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsUrduBT = InMemoryFdoCache.s_wsHvos.Ur;
			IWritingSystem btWs = Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsUrduBT);
			string btWsName = btWs.get_UiName(Cache.DefaultUserWs);

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			DummyFileWriter fileWriterLDS = new DummyFileWriter();
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
				wsUrduBT, normalEntry, fileWriterLDS);

			// Verify the .lds file
			string[] expectedLds =
			{
				"[General]",
				"codepage=65001",
				"RTL=T",
				"font=Wingdings",
				"name=" + btWs.get_UiName(Cache.DefaultUserWs),
				"size=14",
				string.Empty,
				"[Checking]",
				string.Empty,
				"[Characters]",
				string.Empty,
				"[Punctuation]"
			};

			fileWriterLDS.VerifyOutput(expectedLds);
		}