PrivateFontsTests.cs 1.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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>
    /// Test use the following embedded resources:
    ///   - 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";
        //private const string PrivateFontName = "Brush Script MT2";

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

26
27

        [TestMethod]
28
        [Ignore]
29
30
        public void TestPrivateFont()
        {
31
            // FIXME: Currently throws because of zero size 
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
            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.
            Marshal.FreeCoTaskMem(fontData); // Do not forget to frees the memory block.
        }
    }
}