Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Open the file. This is virtual so it can be replaced in testing with an
        /// in-memory file writer.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected override FileWriter OpenFile(string fileName)
        {
            DummyFileWriter writer = new DummyFileWriter();

            writer.Open(fileName);
            return(writer);
        }
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// constructor
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public DummyExportUsfm(FdoCache cache, FilteredScrBooks filter) :
			base(cache, filter, string.Empty, null)
		{
			if (m_file != null)
				m_file.Close();
			m_file = new DummyFileWriter();
			// Usually this is set by the main window and most tests need this.
			m_requestedAnalWS = new int[] { m_defaultAnalWS };
		}
Exemplo n.º 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// constructor
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public DummyExportUsfm(FdoCache cache, FilteredScrBooks filter) :
     base(cache, filter, string.Empty, null)
 {
     if (m_file != null)
     {
         m_file.Close();
     }
     m_file = new DummyFileWriter();
     // Usually this is set by the main window and most tests need this.
     m_requestedAnalWS = new int[] { m_defaultAnalWS };
 }
Exemplo n.º 4
0
		public void WriteParatextSsfFile_SeptuagintVersification()
		{
			m_scr.Versification = ScrVers.Septuagint;
			IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;

			using (DummyFileWriter writer = new DummyFileWriter())
			{
				FileNameFormat fileNameFormat = new FileNameFormat("pre",
					FileNameFormat.SchemeFormat.NNBBB, "suf", "ext");
				m_exporter.ParatextSsfFileAccessor.SaveSsfFile(fileNameFormat, "dummy", "styFile.sty",
					@"C:\My Paratext Projects\dummy", writer, Cache.DefaultVernWs);

				// Verify the .ssf file
				string[] expectedSsf = new string[]
				{
					@"<ScriptureText>",
					@"<BooksPresent>100000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000</BooksPresent>",
					@"<Copyright></Copyright>",
					@"<Directory>C:\My Paratext Projects\dummy</Directory>",
					@"<Editable>T</Editable>",
					@"<Encoding>" + ParatextSsfFileAccessor.kUnicodeEncoding + "</Encoding>",
					@"<FileNameForm>41MAT</FileNameForm>",
					@"<FileNamePostPart>suf.ext</FileNamePostPart>",
					@"<FileNamePrePart>pre</FileNamePrePart>",
					@"<FullName>" + Cache.ProjectId.Name + "</FullName>",
					@"<Language>French</Language>",
					@"<LeftToRight>" + (vernWs.RightToLeftScript ? "F" : "T") + "</LeftToRight>",
					@"<Name>dummy</Name>",
					@"<StyleSheet>styFile.sty</StyleSheet>",
					@"<Versification>2</Versification>", // Septuagint
					"<Naming PrePart=\"pre\" PostPart=\"suf.ext\" BookNameForm=\"41MAT\"></Naming>",
					@"</ScriptureText>"
				};

				writer.VerifyOutput(expectedSsf);
			}
		}
Exemplo n.º 5
0
		public void WriteUsfmStyFile_OtherCulture()
		{
			DummyUsfmStyEntry 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);

			using (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",
					""
				};

				writer.VerifyOutput(expectedSty);
			}
		}
Exemplo n.º 6
0
		public void WriteUsfmStyFile()
		{
			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);

			using (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);
			}
		}
Exemplo n.º 7
0
		public void UpdateParatextLdsFile_GeneralSectionMissing()
		{
			IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			m_exporter.UsfmEntries.Add(ScrStyleNames.Normal, normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[OtherStuff]";

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			using (TextWriter tw = FileUtils.OpenFileForWrite("test.lds", Encoding.ASCII))
				ldsAccessor.UpdateLdsContents(ldsContentsOrig, normalEntry, Cache.DefaultVernWs, tw);

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

			using (DummyFileWriter writer = new DummyFileWriter())
			{
				writer.Open("test.lds");
				writer.VerifyOutput(expectedLdsContents);
			}
		}
Exemplo n.º 8
0
		public void UpdateParatextLdsFile_UpdateFontAndSizeAndAddRTL()
		{
			IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			m_exporter.UsfmEntries.Add(ScrStyleNames.Normal, normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[General]" + Environment.NewLine +
				"codepage=" + ParatextSsfFileAccessor.kUnicodeEncoding + 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=";

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			using (TextWriter tw = FileUtils.OpenFileForWrite("test.lds", Encoding.ASCII))
				ldsAccessor.UpdateLdsContents(ldsContentsOrig, normalEntry, Cache.DefaultVernWs, tw);

			// Verify the .lds file
			string[] expectedLdsContents =
			{
				"[General]",
				"codepage=" + ParatextSsfFileAccessor.kUnicodeEncoding,
				"DialogFontsize=0",
				"LowerCaseLetters=",
				"NoCaseLetters=",
				"UpperCaseLetters=",
				"errors=",
				"font=Wingdings",
				"name=French",
				"separator=",
				"size=14",
				"RTL=F",
				"",
				"[Checking]",
				"",
				"[Characters]",
				"",
				"[Punctuation]",
				"diacritics=",
				"medial="
			};
			using (DummyFileWriter writer = new DummyFileWriter())
			{
				writer.Open("test.lds");
				writer.VerifyOutput(expectedLdsContents);
			}
		}
Exemplo n.º 9
0
		public void WriteParatextLdsFile_BT()
		{

			IWritingSystem wsUr = Cache.ServiceLocator.WritingSystemManager.Get("ur");
			wsUr.RightToLeftScript = true;
			string btWsName = wsUr.DisplayLabel;

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			m_exporter.UsfmEntries.Add(ScrStyleNames.Normal, normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ldsAccessor.WriteParatextLdsFile("test.lds", wsUr.Handle, normalEntry);

			// Verify the .lds file
			string[] expectedLds =
			{
				"[General]",
				"codepage=" + ParatextSsfFileAccessor.kUnicodeEncoding,
				"RTL=T",
				"font=Wingdings",
				"name=" + btWsName,
				"size=14",
				string.Empty,
				"[Checking]",
				string.Empty,
				"[Characters]",
				string.Empty,
				"[Punctuation]"
			};

			using (DummyFileWriter actualLds = new DummyFileWriter())
			{
				actualLds.Open("test.lds");
				actualLds.VerifyOutput(expectedLds);
			}
		}
Exemplo n.º 10
0
		public void WriteParatextLdsFile()
		{

			IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			m_exporter.UsfmEntries.Add(ScrStyleNames.Normal, normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

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

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

			using (DummyFileWriter actualLds = new DummyFileWriter())
			{
				actualLds.Open("test.lds");
				actualLds.VerifyOutput(expectedLds);
			}
		}
Exemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Open the file. This is virtual so it can be replaced in testing with an
		/// in-memory file writer.
		/// </summary>
		/// <param name="fileName"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected override FileWriter OpenFile(string fileName)
		{
			DummyFileWriter writer = new DummyFileWriter();
			writer.Open(fileName);
			return writer;
		}