public void LogicalRuns() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_HEBREW_MIXED, BiDi.DEFAULT_LTR, null); Assert.AreEqual(3, bidi.CountRuns()); var logicalMap = bidi.GetLogicalMap(); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, logicalMap.Length); Assert.AreEqual(HEBREW_SHORT.Length, logicalMap.Select((m, i) => (m, i)).Count(mi => mi.Item1 != mi.Item2)); Assert.That(Enumerable.Range(0, ENGLISH_PART_1.Length).All(i => bidi.GetLogicalIndex(i) == i)); Assert.That(Enumerable.Range(ENGLISH_PART_1.Length, HEBREW_SHORT.Length).All(i => bidi.GetLogicalIndex(i) == ENGLISH_PART_1.Length + HEBREW_SHORT.Length - i + ENGLISH_PART_1.Length - 1)); Assert.That(Enumerable.Range(ENGLISH_PART_1.Length + HEBREW_SHORT.Length, ENGLISH_PART_2.Length).All(i => bidi.GetLogicalIndex(i) == i)); var limit = bidi.GetLogicalRun(3, out byte runlevel); Assert.AreEqual(ENGLISH_PART_1.Length, limit); Assert.AreEqual(0, runlevel); limit = bidi.GetLogicalRun(ENGLISH_PART_1.Length + 3, out runlevel); Assert.AreEqual(ENGLISH_PART_1.Length + HEBREW_SHORT.Length, limit); Assert.AreEqual(1, runlevel); limit = bidi.GetLogicalRun(ENGLISH_PART_1.Length + HEBREW_SHORT.Length + 3, out runlevel); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, limit); Assert.AreEqual(0, runlevel); bidi.SetPara(ENGLISH_LONG, BiDi.DEFAULT_LTR, null); Assert.AreEqual(1, bidi.CountRuns()); bidi.SetPara(HEBREW_LONG, BiDi.DEFAULT_LTR, null); Assert.AreEqual(1, bidi.CountRuns()); } }
public void VisualRuns() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_HEBREW_MIXED, BiDi.DEFAULT_LTR, null); Assert.AreEqual(3, bidi.CountRuns()); var visualMap = bidi.GetVisualMap(); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, visualMap.Length); Assert.AreEqual(HEBREW_SHORT.Length, visualMap.Select((m, i) => (m, i)).Count(mi => mi.Item1 != mi.Item2)); Assert.That(Enumerable.Range(0, ENGLISH_PART_1.Length).All(i => bidi.GetVisualIndex(i) == i)); Assert.That(Enumerable.Range(ENGLISH_PART_1.Length, HEBREW_SHORT.Length).All(i => bidi.GetVisualIndex(i) == ENGLISH_PART_1.Length + HEBREW_SHORT.Length - i + ENGLISH_PART_1.Length - 1)); Assert.That(Enumerable.Range(ENGLISH_PART_1.Length + HEBREW_SHORT.Length, ENGLISH_PART_2.Length).All(i => bidi.GetVisualIndex(i) == i)); var direction = bidi.GetVisualRun(0, out int start, out int len); Assert.AreEqual(0, start); Assert.AreEqual(ENGLISH_PART_1.Length, len); Assert.AreEqual(direction, BiDi.BiDiDirection.LTR); direction = bidi.GetVisualRun(1, out start, out len); Assert.AreEqual(ENGLISH_PART_1.Length, start); Assert.AreEqual(HEBREW_SHORT.Length, len); Assert.AreEqual(direction, BiDi.BiDiDirection.RTL); direction = bidi.GetVisualRun(2, out start, out len); Assert.AreEqual(ENGLISH_PART_1.Length + HEBREW_SHORT.Length, start); Assert.AreEqual(ENGLISH_PART_2.Length, len); Assert.AreEqual(direction, BiDi.BiDiDirection.LTR); } }
public void ReorderingBaseCombining() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_HEBREW_MIXED, BiDi.DEFAULT_LTR, null); var reordered = bidi.GetReordered(BiDi.CallReorderingOptions.KEEP_BASE_COMBINING); Assert.AreEqual(ENGLISH_PART_1, reordered.Substring(0, ENGLISH_PART_1.Length)); Assert.AreNotEqual(string.Join("", HEBREW_SHORT.Reverse()), reordered.Substring(ENGLISH_PART_1.Length, HEBREW_SHORT.Length)); Assert.AreEqual(ENGLISH_PART_2, reordered.Substring(ENGLISH_PART_1.Length + HEBREW_SHORT.Length)); } }
public void BasicPropertiesEmpty() { using (var bidi = new BiDi()) { bidi.SetPara(string.Empty, 0, null); Assert.AreEqual(string.Empty, bidi.Text); Assert.AreEqual(string.Empty.Length, bidi.Length); Assert.AreEqual(string.Empty.Length, bidi.ProcessedLength); Assert.AreEqual(string.Empty.Length, bidi.ResultLength); Assert.AreEqual(BiDi.BiDiDirection.LTR, bidi.Direction); } }
public void BasicProperties() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_HEBREW_MIXED, 0, null); Assert.AreEqual(ENGLISH_HEBREW_MIXED, bidi.Text); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, bidi.Length); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, bidi.ProcessedLength); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, bidi.ResultLength); Assert.AreEqual(BiDi.BiDiDirection.MIXED, bidi.Direction); } }
public void ReorderingInverse() { using (var bidi = new BiDi()) { bidi.SetPara(HEBREW_LONG, BiDi.DEFAULT_RTL, null); var reorderedHebrew = bidi.GetReordered(BiDi.CallReorderingOptions.DEFAULT); Assert.AreEqual(string.Join("", HEBREW_LONG.Reverse()), reorderedHebrew); bidi.IsInverse = true; bidi.SetPara(reorderedHebrew, BiDi.DEFAULT_LTR, null); Assert.AreEqual(HEBREW_LONG, bidi.GetReordered(BiDi.CallReorderingOptions.DEFAULT)); } }
public void LevelsHebrew() { using (var bidi = new BiDi()) { bidi.SetPara(HEBREW_LONG, BiDi.DEFAULT_LTR, null); Assert.AreEqual(BiDi.BiDiDirection.RTL, bidi.Direction); Assert.AreEqual(1, bidi.GetParaLevel()); Assert.AreEqual(1, bidi.GetLevelAt(HEBREW_LONG.Length / 2)); var levels = bidi.GetLevels().ToArray(); Assert.AreEqual(HEBREW_LONG.Length, levels.Length); Assert.That(levels.Where(ll => ll != 1).Count() == 0); } }
public void LevelsEnglish() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_LONG, BiDi.DEFAULT_LTR, null); Assert.AreEqual(BiDi.BiDiDirection.LTR, bidi.Direction); Assert.AreEqual(0, bidi.GetParaLevel()); Assert.AreEqual(0, bidi.GetLevelAt(ENGLISH_LONG.Length / 2)); var levels = bidi.GetLevels().ToArray(); Assert.AreEqual(ENGLISH_LONG.Length, levels.Length); Assert.That(levels.Where(ll => ll != 0).Count() == 0); } }
public void LevelsHebrewEnglish() { using (var bidi = new BiDi()) { bidi.SetPara(HEBREW_ENGLISH_MIXED, BiDi.DEFAULT_LTR, null); Assert.AreEqual(BiDi.BiDiDirection.MIXED, bidi.Direction); Assert.AreEqual(1, bidi.GetParaLevel()); Assert.AreEqual(1, bidi.GetLevelAt(HEBREW_ENGLISH_MIXED.Length - 1)); var levels = bidi.GetLevels().ToArray(); Assert.AreEqual(HEBREW_ENGLISH_MIXED.Length, levels.Length); Assert.That(levels.Where(ll => ll == 2).Count() > 0); } }
public void LevelsEnglishHebrew() { using (var bidi = new BiDi()) { bidi.SetPara(ENGLISH_HEBREW_MIXED, BiDi.DEFAULT_LTR, null); Assert.AreEqual(BiDi.BiDiDirection.MIXED, bidi.Direction); Assert.AreEqual(0, bidi.GetParaLevel()); Assert.AreEqual(0, bidi.GetLevelAt(ENGLISH_HEBREW_MIXED.Length - 1)); var levels = bidi.GetLevels().ToArray(); Assert.AreEqual(ENGLISH_HEBREW_MIXED.Length, levels.Length); Assert.AreEqual(HEBREW_SHORT.Length, levels.Where(ll => ll != 0).Count()); } }
public void Paragraphs() { using (var bidi = new BiDi()) { bidi.SetPara(PARAGRAPHS, BiDi.DEFAULT_LTR, null); Assert.AreEqual(BiDi.BiDiDirection.MIXED, bidi.Direction); Assert.AreEqual(5, bidi.CountParagraphs()); var index = bidi.GetParagraph(0, out int paraStart, out int paraLimit, out byte paraLevel); Assert.AreEqual(0, index); Assert.AreEqual(0, paraStart); Assert.AreEqual(ENGLISH_LONG.Length + 2, paraLimit); // +2 for crlf Assert.AreEqual(0, paraLevel); index = bidi.GetParagraph(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + 2 + 14, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(2, index); Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + 2, paraStart); // +2 for crlf Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + 2 + HEBREW_LONG.Length + 2, paraLimit); // +2 for crlf Assert.AreEqual(1, paraLevel); index = bidi.GetParagraph(PARAGRAPHS.Length - 2, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(4, index); Assert.AreEqual(PARAGRAPHS.Length - ENGLISH_HEBREW_MIXED.Length, paraStart); Assert.AreEqual(PARAGRAPHS.Length, paraLimit); Assert.AreEqual(0, paraLevel); bidi.GetParagraphByIndex(0, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(0, paraStart); Assert.AreEqual(ENGLISH_LONG.Length + 2, paraLimit); // +2 for crlf Assert.AreEqual(0, paraLevel); bidi.GetParagraphByIndex(2, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + 2, paraStart); // +2 for crlf Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + 2 + HEBREW_LONG.Length + 2, paraLimit); // +2 for crlf Assert.AreEqual(1, paraLevel); bidi.GetParagraphByIndex(3, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + HEBREW_LONG.Length + 2 + 2, paraStart); // +2 for crlf Assert.AreEqual(ENGLISH_LONG.Length + 2 + HEBREW_ENGLISH_MIXED.Length + HEBREW_LONG.Length + 2 + 2 + 2, paraLimit); // +2 for crlf Assert.AreEqual(0, paraLevel); bidi.GetParagraphByIndex(4, out paraStart, out paraLimit, out paraLevel); Assert.AreEqual(PARAGRAPHS.Length - ENGLISH_HEBREW_MIXED.Length, paraStart); Assert.AreEqual(PARAGRAPHS.Length, paraLimit); Assert.AreEqual(0, paraLevel); } }
// Creates an Paragraph instance and adds its children. public Paragraph CreateCellParagraph() { Paragraph paragraph = new Paragraph(); ParagraphProperties paragraphProperties = new ParagraphProperties(); KeepNext keepNext = new KeepNext() { Val = false }; KeepLines keepLines = new KeepLines() { Val = false }; PageBreakBefore pageBreakBefore = new PageBreakBefore() { Val = false }; WidowControl widowControl = new WidowControl() { Val = false }; Kinsoku kinsoku = new Kinsoku(); WordWrap wordWrap = new WordWrap(); OverflowPunctuation overflowPunctuation = new OverflowPunctuation(); TopLinePunctuation topLinePunctuation = new TopLinePunctuation() { Val = false }; AutoSpaceDE autoSpaceDE = new AutoSpaceDE(); AutoSpaceDN autoSpaceDN = new AutoSpaceDN(); BiDi biDi = new BiDi() { Val = false }; AdjustRightIndent adjustRightIndent = new AdjustRightIndent(); SnapToGrid snapToGrid = new SnapToGrid(); SpacingBetweenLines spacingBetweenLines = new SpacingBetweenLines() { Line = "113", LineRule = LineSpacingRuleValues.Exact }; TextAlignment textAlignment = new TextAlignment() { Val = VerticalTextAlignmentValues.Auto }; paragraphProperties.Append(keepNext); paragraphProperties.Append(keepLines); paragraphProperties.Append(pageBreakBefore); paragraphProperties.Append(widowControl); paragraphProperties.Append(kinsoku); paragraphProperties.Append(wordWrap); paragraphProperties.Append(overflowPunctuation); paragraphProperties.Append(topLinePunctuation); paragraphProperties.Append(autoSpaceDE); paragraphProperties.Append(autoSpaceDN); paragraphProperties.Append(biDi); paragraphProperties.Append(adjustRightIndent); paragraphProperties.Append(snapToGrid); paragraphProperties.Append(spacingBetweenLines); paragraphProperties.Append(textAlignment); paragraph.Append(paragraphProperties); return(paragraph); }
public BiDi.BiDiDirection StaticBaseDirection(string str) { return(BiDi.GetBaseDirection(str)); }
public string StaticReverseString(string str, BiDi.CallReorderingOptions options) { return(BiDi.ReverseString(str, options)); }
// Generates content of styleDefinitionsPart1. private void GenerateStyleDefinitionsPart1Content(StyleDefinitionsPart styleDefinitionsPart1) { Styles styles1 = new Styles() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14" } }; styles1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); styles1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); styles1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); DocDefaults docDefaults1 = new DocDefaults(); RunPropertiesDefault runPropertiesDefault1 = new RunPropertiesDefault(); RunPropertiesBaseStyle runPropertiesBaseStyle1 = new RunPropertiesBaseStyle(); RunFonts runFonts24 = new RunFonts() { Ascii = "Liberation Serif", HighAnsi = "Liberation Serif", EastAsia = "SimSun", ComplexScript = "Lucida Sans" }; FontSizeComplexScript fontSizeComplexScript541 = new FontSizeComplexScript() { Val = "24" }; Languages languages8 = new Languages() { Val = "ru-RU", EastAsia = "zh-CN", Bidi = "hi-IN" }; runPropertiesBaseStyle1.Append(runFonts24); runPropertiesBaseStyle1.Append(fontSizeComplexScript541); runPropertiesBaseStyle1.Append(languages8); runPropertiesDefault1.Append(runPropertiesBaseStyle1); ParagraphPropertiesDefault paragraphPropertiesDefault1 = new ParagraphPropertiesDefault(); ParagraphPropertiesBaseStyle paragraphPropertiesBaseStyle1 = new ParagraphPropertiesBaseStyle(); paragraphPropertiesDefault1.Append(paragraphPropertiesBaseStyle1); docDefaults1.Append(runPropertiesDefault1); docDefaults1.Append(paragraphPropertiesDefault1); Style style1 = new Style() { Type = StyleValues.Paragraph, StyleId = "Normal" }; StyleName styleName1 = new StyleName() { Val = "Normal" }; PrimaryStyle primaryStyle1 = new PrimaryStyle(); StyleParagraphProperties styleParagraphProperties1 = new StyleParagraphProperties(); WidowControl widowControl1 = new WidowControl() { Val = false }; BiDi biDi1 = new BiDi() { Val = false }; Justification justification319 = new Justification() { Val = JustificationValues.Start }; styleParagraphProperties1.Append(widowControl1); styleParagraphProperties1.Append(biDi1); styleParagraphProperties1.Append(justification319); StyleRunProperties styleRunProperties1 = new StyleRunProperties(); RunFonts runFonts25 = new RunFonts() { Ascii = "Liberation Serif", HighAnsi = "Liberation Serif", EastAsia = "SimSun", ComplexScript = "Lucida Sans" }; Color color13 = new Color() { Val = "00000A" }; FontSize fontSize541 = new FontSize() { Val = "24" }; FontSizeComplexScript fontSizeComplexScript542 = new FontSizeComplexScript() { Val = "24" }; Languages languages9 = new Languages() { Val = "ru-RU", EastAsia = "zh-CN", Bidi = "hi-IN" }; styleRunProperties1.Append(runFonts25); styleRunProperties1.Append(color13); styleRunProperties1.Append(fontSize541); styleRunProperties1.Append(fontSizeComplexScript542); styleRunProperties1.Append(languages9); style1.Append(styleName1); style1.Append(primaryStyle1); style1.Append(styleParagraphProperties1); style1.Append(styleRunProperties1); Style style2 = new Style() { Type = StyleValues.Paragraph, StyleId = "1" }; StyleName styleName2 = new StyleName() { Val = "Заголовок 1" }; BasedOn basedOn1 = new BasedOn() { Val = "Style11" }; StyleParagraphProperties styleParagraphProperties2 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines() { Before = "240", After = "120" }; OutlineLevel outlineLevel1 = new OutlineLevel() { Val = 0 }; styleParagraphProperties2.Append(spacingBetweenLines1); styleParagraphProperties2.Append(outlineLevel1); StyleRunProperties styleRunProperties2 = new StyleRunProperties(); Bold bold40 = new Bold(); BoldComplexScript boldComplexScript1 = new BoldComplexScript(); FontSize fontSize542 = new FontSize() { Val = "36" }; FontSizeComplexScript fontSizeComplexScript543 = new FontSizeComplexScript() { Val = "36" }; styleRunProperties2.Append(bold40); styleRunProperties2.Append(boldComplexScript1); styleRunProperties2.Append(fontSize542); styleRunProperties2.Append(fontSizeComplexScript543); style2.Append(styleName2); style2.Append(basedOn1); style2.Append(styleParagraphProperties2); style2.Append(styleRunProperties2); Style style3 = new Style() { Type = StyleValues.Paragraph, StyleId = "2" }; StyleName styleName3 = new StyleName() { Val = "Заголовок 2" }; BasedOn basedOn2 = new BasedOn() { Val = "Style11" }; StyleParagraphProperties styleParagraphProperties3 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines2 = new SpacingBetweenLines() { Before = "200", After = "120" }; OutlineLevel outlineLevel2 = new OutlineLevel() { Val = 1 }; styleParagraphProperties3.Append(spacingBetweenLines2); styleParagraphProperties3.Append(outlineLevel2); StyleRunProperties styleRunProperties3 = new StyleRunProperties(); Bold bold41 = new Bold(); BoldComplexScript boldComplexScript2 = new BoldComplexScript(); FontSize fontSize543 = new FontSize() { Val = "32" }; FontSizeComplexScript fontSizeComplexScript544 = new FontSizeComplexScript() { Val = "32" }; styleRunProperties3.Append(bold41); styleRunProperties3.Append(boldComplexScript2); styleRunProperties3.Append(fontSize543); styleRunProperties3.Append(fontSizeComplexScript544); style3.Append(styleName3); style3.Append(basedOn2); style3.Append(styleParagraphProperties3); style3.Append(styleRunProperties3); Style style4 = new Style() { Type = StyleValues.Paragraph, StyleId = "3" }; StyleName styleName4 = new StyleName() { Val = "Заголовок 3" }; BasedOn basedOn3 = new BasedOn() { Val = "Style11" }; StyleParagraphProperties styleParagraphProperties4 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines3 = new SpacingBetweenLines() { Before = "140", After = "120" }; OutlineLevel outlineLevel3 = new OutlineLevel() { Val = 2 }; styleParagraphProperties4.Append(spacingBetweenLines3); styleParagraphProperties4.Append(outlineLevel3); StyleRunProperties styleRunProperties4 = new StyleRunProperties(); Bold bold42 = new Bold(); BoldComplexScript boldComplexScript3 = new BoldComplexScript(); FontSize fontSize544 = new FontSize() { Val = "28" }; FontSizeComplexScript fontSizeComplexScript545 = new FontSizeComplexScript() { Val = "28" }; styleRunProperties4.Append(bold42); styleRunProperties4.Append(boldComplexScript3); styleRunProperties4.Append(fontSize544); styleRunProperties4.Append(fontSizeComplexScript545); style4.Append(styleName4); style4.Append(basedOn3); style4.Append(styleParagraphProperties4); style4.Append(styleRunProperties4); Style style5 = new Style() { Type = StyleValues.Character, StyleId = "DefaultParagraphFont" }; StyleName styleName5 = new StyleName() { Val = "Default Paragraph Font" }; PrimaryStyle primaryStyle2 = new PrimaryStyle(); StyleRunProperties styleRunProperties5 = new StyleRunProperties(); style5.Append(styleName5); style5.Append(primaryStyle2); style5.Append(styleRunProperties5); Style style6 = new Style() { Type = StyleValues.Character, StyleId = "FontStyle48" }; StyleName styleName6 = new StyleName() { Val = "Font Style48" }; BasedOn basedOn4 = new BasedOn() { Val = "DefaultParagraphFont" }; PrimaryStyle primaryStyle3 = new PrimaryStyle(); StyleRunProperties styleRunProperties6 = new StyleRunProperties(); RunFonts runFonts26 = new RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Spacing spacing5 = new Spacing() { Val = 0 }; FontSize fontSize545 = new FontSize() { Val = "26" }; FontSizeComplexScript fontSizeComplexScript546 = new FontSizeComplexScript() { Val = "26" }; styleRunProperties6.Append(runFonts26); styleRunProperties6.Append(spacing5); styleRunProperties6.Append(fontSize545); styleRunProperties6.Append(fontSizeComplexScript546); style6.Append(styleName6); style6.Append(basedOn4); style6.Append(primaryStyle3); style6.Append(styleRunProperties6); Style style7 = new Style() { Type = StyleValues.Character, StyleId = "FontStyle62" }; StyleName styleName7 = new StyleName() { Val = "Font Style62" }; BasedOn basedOn5 = new BasedOn() { Val = "DefaultParagraphFont" }; PrimaryStyle primaryStyle4 = new PrimaryStyle(); StyleRunProperties styleRunProperties7 = new StyleRunProperties(); RunFonts runFonts27 = new RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" }; Bold bold43 = new Bold(); BoldComplexScript boldComplexScript4 = new BoldComplexScript(); FontSize fontSize546 = new FontSize() { Val = "22" }; FontSizeComplexScript fontSizeComplexScript547 = new FontSizeComplexScript() { Val = "22" }; styleRunProperties7.Append(runFonts27); styleRunProperties7.Append(bold43); styleRunProperties7.Append(boldComplexScript4); styleRunProperties7.Append(fontSize546); styleRunProperties7.Append(fontSizeComplexScript547); style7.Append(styleName7); style7.Append(basedOn5); style7.Append(primaryStyle4); style7.Append(styleRunProperties7); Style style8 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style11" }; StyleName styleName8 = new StyleName() { Val = "Заголовок" }; BasedOn basedOn6 = new BasedOn() { Val = "Normal" }; NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle() { Val = "Style12" }; PrimaryStyle primaryStyle5 = new PrimaryStyle(); StyleParagraphProperties styleParagraphProperties5 = new StyleParagraphProperties(); KeepNext keepNext1 = new KeepNext(); SpacingBetweenLines spacingBetweenLines4 = new SpacingBetweenLines() { Before = "240", After = "120" }; styleParagraphProperties5.Append(keepNext1); styleParagraphProperties5.Append(spacingBetweenLines4); StyleRunProperties styleRunProperties8 = new StyleRunProperties(); RunFonts runFonts28 = new RunFonts() { Ascii = "Liberation Sans", HighAnsi = "Liberation Sans", EastAsia = "Microsoft YaHei", ComplexScript = "Lucida Sans" }; FontSize fontSize547 = new FontSize() { Val = "28" }; FontSizeComplexScript fontSizeComplexScript548 = new FontSizeComplexScript() { Val = "28" }; styleRunProperties8.Append(runFonts28); styleRunProperties8.Append(fontSize547); styleRunProperties8.Append(fontSizeComplexScript548); style8.Append(styleName8); style8.Append(basedOn6); style8.Append(nextParagraphStyle1); style8.Append(primaryStyle5); style8.Append(styleParagraphProperties5); style8.Append(styleRunProperties8); Style style9 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style12" }; StyleName styleName9 = new StyleName() { Val = "Основной текст" }; BasedOn basedOn7 = new BasedOn() { Val = "Normal" }; StyleParagraphProperties styleParagraphProperties6 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines5 = new SpacingBetweenLines() { Before = "0", After = "140", Line = "288", LineRule = LineSpacingRuleValues.Auto }; styleParagraphProperties6.Append(spacingBetweenLines5); StyleRunProperties styleRunProperties9 = new StyleRunProperties(); style9.Append(styleName9); style9.Append(basedOn7); style9.Append(styleParagraphProperties6); style9.Append(styleRunProperties9); Style style10 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style13" }; StyleName styleName10 = new StyleName() { Val = "Список" }; BasedOn basedOn8 = new BasedOn() { Val = "Style12" }; StyleParagraphProperties styleParagraphProperties7 = new StyleParagraphProperties(); StyleRunProperties styleRunProperties10 = new StyleRunProperties(); RunFonts runFonts29 = new RunFonts() { ComplexScript = "Lucida Sans" }; styleRunProperties10.Append(runFonts29); style10.Append(styleName10); style10.Append(basedOn8); style10.Append(styleParagraphProperties7); style10.Append(styleRunProperties10); Style style11 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style14" }; StyleName styleName11 = new StyleName() { Val = "Название" }; BasedOn basedOn9 = new BasedOn() { Val = "Normal" }; StyleParagraphProperties styleParagraphProperties8 = new StyleParagraphProperties(); SuppressLineNumbers suppressLineNumbers1 = new SuppressLineNumbers(); SpacingBetweenLines spacingBetweenLines6 = new SpacingBetweenLines() { Before = "120", After = "120" }; styleParagraphProperties8.Append(suppressLineNumbers1); styleParagraphProperties8.Append(spacingBetweenLines6); StyleRunProperties styleRunProperties11 = new StyleRunProperties(); RunFonts runFonts30 = new RunFonts() { ComplexScript = "Lucida Sans" }; Italic italic1 = new Italic(); ItalicComplexScript italicComplexScript1 = new ItalicComplexScript(); FontSize fontSize548 = new FontSize() { Val = "24" }; FontSizeComplexScript fontSizeComplexScript549 = new FontSizeComplexScript() { Val = "24" }; styleRunProperties11.Append(runFonts30); styleRunProperties11.Append(italic1); styleRunProperties11.Append(italicComplexScript1); styleRunProperties11.Append(fontSize548); styleRunProperties11.Append(fontSizeComplexScript549); style11.Append(styleName11); style11.Append(basedOn9); style11.Append(styleParagraphProperties8); style11.Append(styleRunProperties11); Style style12 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style15" }; StyleName styleName12 = new StyleName() { Val = "Указатель" }; BasedOn basedOn10 = new BasedOn() { Val = "Normal" }; PrimaryStyle primaryStyle6 = new PrimaryStyle(); StyleParagraphProperties styleParagraphProperties9 = new StyleParagraphProperties(); SuppressLineNumbers suppressLineNumbers2 = new SuppressLineNumbers(); styleParagraphProperties9.Append(suppressLineNumbers2); StyleRunProperties styleRunProperties12 = new StyleRunProperties(); RunFonts runFonts31 = new RunFonts() { ComplexScript = "Lucida Sans" }; styleRunProperties12.Append(runFonts31); style12.Append(styleName12); style12.Append(basedOn10); style12.Append(primaryStyle6); style12.Append(styleParagraphProperties9); style12.Append(styleRunProperties12); Style style13 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style16" }; StyleName styleName13 = new StyleName() { Val = "Блочная цитата" }; BasedOn basedOn11 = new BasedOn() { Val = "Normal" }; PrimaryStyle primaryStyle7 = new PrimaryStyle(); StyleParagraphProperties styleParagraphProperties10 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines7 = new SpacingBetweenLines() { Before = "0", After = "283" }; Indentation indentation47 = new Indentation() { Start = "567", End = "567", Hanging = "0" }; styleParagraphProperties10.Append(spacingBetweenLines7); styleParagraphProperties10.Append(indentation47); StyleRunProperties styleRunProperties13 = new StyleRunProperties(); style13.Append(styleName13); style13.Append(basedOn11); style13.Append(primaryStyle7); style13.Append(styleParagraphProperties10); style13.Append(styleRunProperties13); Style style14 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style17" }; StyleName styleName14 = new StyleName() { Val = "Заглавие" }; BasedOn basedOn12 = new BasedOn() { Val = "Style11" }; StyleParagraphProperties styleParagraphProperties11 = new StyleParagraphProperties(); Justification justification320 = new Justification() { Val = JustificationValues.Center }; styleParagraphProperties11.Append(justification320); StyleRunProperties styleRunProperties14 = new StyleRunProperties(); Bold bold44 = new Bold(); BoldComplexScript boldComplexScript5 = new BoldComplexScript(); FontSize fontSize549 = new FontSize() { Val = "56" }; FontSizeComplexScript fontSizeComplexScript550 = new FontSizeComplexScript() { Val = "56" }; styleRunProperties14.Append(bold44); styleRunProperties14.Append(boldComplexScript5); styleRunProperties14.Append(fontSize549); styleRunProperties14.Append(fontSizeComplexScript550); style14.Append(styleName14); style14.Append(basedOn12); style14.Append(styleParagraphProperties11); style14.Append(styleRunProperties14); Style style15 = new Style() { Type = StyleValues.Paragraph, StyleId = "Style18" }; StyleName styleName15 = new StyleName() { Val = "Подзаголовок" }; BasedOn basedOn13 = new BasedOn() { Val = "Style11" }; StyleParagraphProperties styleParagraphProperties12 = new StyleParagraphProperties(); SpacingBetweenLines spacingBetweenLines8 = new SpacingBetweenLines() { Before = "60", After = "120" }; Justification justification321 = new Justification() { Val = JustificationValues.Center }; styleParagraphProperties12.Append(spacingBetweenLines8); styleParagraphProperties12.Append(justification321); StyleRunProperties styleRunProperties15 = new StyleRunProperties(); FontSize fontSize550 = new FontSize() { Val = "36" }; FontSizeComplexScript fontSizeComplexScript551 = new FontSizeComplexScript() { Val = "36" }; styleRunProperties15.Append(fontSize550); styleRunProperties15.Append(fontSizeComplexScript551); style15.Append(styleName15); style15.Append(basedOn13); style15.Append(styleParagraphProperties12); style15.Append(styleRunProperties15); styles1.Append(docDefaults1); styles1.Append(style1); styles1.Append(style2); styles1.Append(style3); styles1.Append(style4); styles1.Append(style5); styles1.Append(style6); styles1.Append(style7); styles1.Append(style8); styles1.Append(style9); styles1.Append(style10); styles1.Append(style11); styles1.Append(style12); styles1.Append(style13); styles1.Append(style14); styles1.Append(style15); styleDefinitionsPart1.Styles = styles1; }
public void HelloWorld(Int32 SurahNr) { var basmala = @"بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ"; string docName = @"C:\Data\surah-" + SurahNr + ".docx"; // Create a Wordprocessing document. using (WordprocessingDocument mydoc = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document)) { // Add a new main document part. MainDocumentPart mainPart = mydoc.AddMainDocumentPart(); //Create DOM tree for simple document. mainPart.Document = new Document(); Body body = new Body(); Paragraph p = new Paragraph(); ParagraphProperties pp = p.ChildElements.First <ParagraphProperties>(); if (pp == null) { pp = new ParagraphProperties(); p.Append(pp); //p.InsertBefore(pp, p.First()); } BiDi bidi = new BiDi(); pp.Append(bidi); Run r = new Run(); Text t; // = new Text(ayah.AyahText); Table table = new Table(); //Quran ayah; using (var context = new DBEntities()) { TableProperties props = new TableProperties( new TableBorders( new TopBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 12 }, new BottomBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 11 }, new LeftBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 11 }, new RightBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 11 }, new InsideHorizontalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 11 }, new InsideVerticalBorder { Val = new EnumValue <BorderValues>(BorderValues.Single), Size = 11 })); table.AppendChild <TableProperties>(props); //var ayah = context.Qurans.Where(q => q.SuraID == 112 && q.VerseID == 2).FirstOrDefault<Quran>(); var ayah = from a in context.Qurans where a.SuraID.Equals(SurahNr) select a; foreach (var a in ayah) { var tr = new TableRow(); var ayahT = a.AyahText; if (a.VerseID == 1) { ayahT = ayahT.Remove(0, basmala.Length); } var tc = new TableCell(); tc.Append(new Paragraph(new Run(new Text(ayahT)))); //var p2 = new Paragraph(); //pp = p2.ChildElements.First<ParagraphProperties>(); //if (pp == null) //{ // pp = new ParagraphProperties(); // p.Append(pp); // //p.InsertBefore(pp, p.First()); //} //bidi = new BiDi(); //pp.Append(bidi); //r = new Run(); //t = new Text(a.AyahText); //tc.Append(p2); //tc.Append(new Paragraph(new Run(new Text(a.VerseID.ToString())))); tr.Append(tc); tc = new TableCell(); //tc.Append(new Paragraph(new Run(new Text(a.AyahText)))); tc.Append(new Paragraph(new Run(new Text(a.VerseID.ToString())))); //p2 = new Paragraph(); //pp = p2.ChildElements.First<ParagraphProperties>(); //if (pp == null) //{ // pp = new ParagraphProperties(); // p.Append(pp); // //p.InsertBefore(pp, p.First()); //} //bidi = new BiDi(); //pp.Append(bidi); //r = new Run(); //t = new Text(a.VerseID.ToString()); //tc.Append(p2); tr.Append(tc); table.Append(tr); //t = new Text(a.VerseID + ": " + a.AyahText); //r.Append(t); //r.AppendChild(new Break()); } } //Append elements appropriately. //r.Append(t); p.Append(r); body.Append(table); body.Append(p); mainPart.Document.Append(body); // Save changes to the main document part. mainPart.Document.Save(); // Save changes to the main document part. mydoc.MainDocumentPart.Document.Save(); } }