-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathTextLineSimpleTests.cs
More file actions
117 lines (93 loc) · 3.96 KB
/
Copy pathTextLineSimpleTests.cs
File metadata and controls
117 lines (93 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using EPPlus.Fonts.OpenType.Integration;
using EPPlus.Fonts.OpenType.TextShaping;
using EPPlus.Fonts.OpenType.Utils;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EPPlus.Fonts.OpenType.Tests.DataHolders
{
[TestClass]
public class TextLineSimpleTests
{
[TestMethod]
public void TestLineFragmentAbstraction()
{
var maxSizePoints = Math.Round(300d, 0, MidpointRounding.AwayFromZero).PixelToPoint();
var fragments = GetTextFragments();
var layout = OpenTypeFonts.GetTextLayoutEngineForFont(fragments[0].Font);
var wrappedLines = layout.WrapRichTextLines(fragments, maxSizePoints);
var wrappedCollection = layout.WrapRichTextLineCollection(fragments, maxSizePoints);
}
[TestMethod]
public void TestLineFragmentSeeWhatLinesUseWhatRichText()
{
var maxSizePoints = Math.Round(300d, 0, MidpointRounding.AwayFromZero).PixelToPoint();
var fragments = GetTextFragments();
fragments[4].RichTextOptions.FontColor = Color.DarkRed;
var layout = OpenTypeFonts.GetTextLayoutEngineForFont(fragments[0].Font);
var wrappedLines = layout.WrapRichTextLines(fragments, maxSizePoints);
var wrappedCollection = layout.WrapRichTextLineCollection(fragments, maxSizePoints);
var lines = wrappedCollection.GetTextLinesThatUse(fragments[4]);
var specificFragments = wrappedCollection.GetLineFragmentsThatUse(fragments[4]);
var lineIndicies = wrappedCollection.GetLineNumbersThatUse(fragments[4]);
Assert.AreEqual(lines[0].LineFragments[1], specificFragments[0]);
Assert.AreEqual(fragments[4], wrappedCollection.LineFragments[6].OriginalTextFragment);
Assert.AreEqual(Color.DarkRed, wrappedCollection.LineFragments[6].OriginalTextFragment.RichTextOptions.FontColor);
var expectedArr = new int[] { 3, 4 };
expectedArr.SequenceCompareTo(lineIndicies);
}
List<TextFragment> GetTextFragments()
{
List<string> lstOfRichText = new() { "TextBox\r\na\r\n", "TextBox2", "ra underline", "La Strike", "Goudy size 16", "SvgSize 24" };
var font1 = new MeasurementFont()
{
FontFamily = "Aptos Narrow",
Size = 11,
Style = MeasurementFontStyles.Regular
};
var font2 = new MeasurementFont()
{
FontFamily = "Aptos Narrow",
Size = 11,
Style = MeasurementFontStyles.Bold
};
var font3 = new MeasurementFont()
{
FontFamily = "Aptos Narrow",
Size = 11,
Style = MeasurementFontStyles.Underline
};
var font4 = new MeasurementFont()
{
FontFamily = "Aptos Narrow",
Size = 11,
Style = MeasurementFontStyles.Strikeout
};
var font5 = new MeasurementFont()
{
FontFamily = "Goudy Stout",
Size = 16,
Style = MeasurementFontStyles.Regular
};
var font6 = new MeasurementFont()
{
FontFamily = "Aptos Narrow",
Size = 24,
Style = MeasurementFontStyles.Regular
};
List<MeasurementFont> fonts = new() { font1, font2, font3, font4, font5, font6 };
var fragments = new List<TextFragment>();
for (int i = 0; i < lstOfRichText.Count(); i++)
{
var currentFrag = new TextFragment() { Text = lstOfRichText[i], Font = fonts[i] };
fragments.Add(currentFrag);
}
return fragments;
}
}
}