PrivateFontsTests.cs 1.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing.Text;
using System.Runtime.InteropServices;

namespace Svg.UnitTests
{

    /// <summary>
    /// Test Class of the feature to use Private Fonts in SVGs.
    /// Based on Issue 204.
    /// </summary>
    /// <remarks>
13
    /// Test uses the following embedded resources:
14
15
16
17
18
19
20
21
22
    ///   - Issue204_PrivateFont\Text.svg
    ///   - Issue204_PrivateFont\BrushScriptMT2.ttf
    /// </remarks>
    [TestClass]
    public class PrivateFontsTests : SvgTestHelper
    {
        private const string PrivateFontSvg = "Issue204_PrivateFont.Text.svg";
        private const string PrivateFont = "Issue204_PrivateFont.BrushScriptMT2.ttf";

23
24
        protected override int ExpectedSize { get { return 3200; } } //3512

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

        [TestMethod]
        public void TestPrivateFont()
        {
            AddFontFromResource(SvgElement.PrivateFonts, GetFullResourceString(PrivateFont));
            LoadSvg(GetXMLDocFromResource(GetFullResourceString(PrivateFontSvg)));
        }


        private void AddFontFromResource(PrivateFontCollection privateFontCollection, string fullFontResourceString)
        {
            var fontBytes = GetResourceBytes(fullFontResourceString);
            var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);
            Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);
            privateFontCollection.AddMemoryFont(fontData, fontBytes.Length); // Add font to collection.
40
            Marshal.FreeCoTaskMem(fontData); // Do not forget to free the memory block.
41
42
43
        }
    }
}