From 8babb253991e448561920e4f906eeaf5a7c858c9 Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 11 Aug 2013 10:28:48 -0400 Subject: [PATCH] change TrueTypeSharp to a .NET 4.0 PCL Ripped out serialization support for now since the "Serializable" attribute is not supported in PCLs currently. --- TrueTypeSharp/BakedChar.cs | 1 - TrueTypeSharp/BakedCharCollection.cs | 18 +------ TrueTypeSharp/BakedQuad.cs | 1 - TrueTypeSharp/ContourPoint.cs | 1 - TrueTypeSharp/FontBitmap.cs | 26 +-------- TrueTypeSharp/GlyphVertex.cs | 1 - TrueTypeSharp/TrueTypeFont.cs | 30 +++++++---- TrueTypeSharp/TrueTypeSharp.csproj | 81 +++++++--------------------- 8 files changed, 41 insertions(+), 118 deletions(-) diff --git a/TrueTypeSharp/BakedChar.cs b/TrueTypeSharp/BakedChar.cs index 0d45dd4..eac50bd 100644 --- a/TrueTypeSharp/BakedChar.cs +++ b/TrueTypeSharp/BakedChar.cs @@ -24,7 +24,6 @@ using System; namespace TrueTypeSharp { - [Serializable] public struct BakedChar { public static BakedChar Empty diff --git a/TrueTypeSharp/BakedCharCollection.cs b/TrueTypeSharp/BakedCharCollection.cs index 1b07186..aa25992 100644 --- a/TrueTypeSharp/BakedCharCollection.cs +++ b/TrueTypeSharp/BakedCharCollection.cs @@ -22,12 +22,10 @@ using System; using System.Collections.Generic; -using System.Runtime.Serialization; namespace TrueTypeSharp { - [Serializable] - public class BakedCharCollection : ISerializable + public class BakedCharCollection { Dictionary _characters; int _bakeWidth, _bakeHeight; @@ -51,13 +49,6 @@ namespace TrueTypeSharp Create(dictionary, bakeWidth, bakeHeight); } - protected BakedCharCollection(SerializationInfo info, StreamingContext context) - { - Create((Dictionary) - info.GetValue("Characters", typeof(Dictionary)), - info.GetInt32("BakeWidth"), info.GetInt32("BakeHeight")); - } - void Create(Dictionary characters, int bakeWidth, int bakeHeight) { if (characters == null) { throw new ArgumentNullException("characters"); } @@ -109,13 +100,6 @@ namespace TrueTypeSharp } } - public virtual void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("Characters", Characters); - info.AddValue("BakeWidth", BakeWidth); - info.AddValue("BakeHeight", BakeHeight); - } - public BakedQuad GetBakedQuad(char character, ref float xPosition, ref float yPosition) { diff --git a/TrueTypeSharp/BakedQuad.cs b/TrueTypeSharp/BakedQuad.cs index 982a23d..d175388 100644 --- a/TrueTypeSharp/BakedQuad.cs +++ b/TrueTypeSharp/BakedQuad.cs @@ -24,7 +24,6 @@ using System; namespace TrueTypeSharp { - [Serializable] public struct BakedQuad { public static BakedQuad Empty diff --git a/TrueTypeSharp/ContourPoint.cs b/TrueTypeSharp/ContourPoint.cs index 9f06b78..cc29ebe 100644 --- a/TrueTypeSharp/ContourPoint.cs +++ b/TrueTypeSharp/ContourPoint.cs @@ -24,7 +24,6 @@ using System; namespace TrueTypeSharp { - [Serializable] public struct ContourPoint { public float X, Y; diff --git a/TrueTypeSharp/FontBitmap.cs b/TrueTypeSharp/FontBitmap.cs index 3f901d7..1d3dd02 100644 --- a/TrueTypeSharp/FontBitmap.cs +++ b/TrueTypeSharp/FontBitmap.cs @@ -21,12 +21,10 @@ #endregion using System; -using System.Runtime.Serialization; namespace TrueTypeSharp { - [Serializable] - public struct FontBitmap : ISerializable + public struct FontBitmap { public delegate T PixelConversionFunc(byte opacity); @@ -42,28 +40,6 @@ namespace TrueTypeSharp Stride = Width = width; Height = height; } - FontBitmap(SerializationInfo info, StreamingContext context) : this() - { - Buffer = (byte[])info.GetValue("Buffer", typeof(byte[])); - BufferOffset = info.GetInt32("BufferOffset"); - XOffset = info.GetInt32("XOffset"); - YOffset = info.GetInt32("YOffset"); - Width = info.GetInt32("Width"); - Height = info.GetInt32("Height"); - Stride = info.GetInt32("Stride"); - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("Buffer", Buffer); - info.AddValue("BufferOffset", BufferOffset); - info.AddValue("XOffset", XOffset); - info.AddValue("YOffset", YOffset); - info.AddValue("Width", Width); - info.AddValue("Height", Height); - info.AddValue("Stride", Stride); - } - public FontBitmap GetResizedBitmap(int width, int height) { var bitmap = new FontBitmap(width, height); diff --git a/TrueTypeSharp/GlyphVertex.cs b/TrueTypeSharp/GlyphVertex.cs index 49d2287..46fc796 100644 --- a/TrueTypeSharp/GlyphVertex.cs +++ b/TrueTypeSharp/GlyphVertex.cs @@ -24,7 +24,6 @@ using System; namespace TrueTypeSharp { - [Serializable] public struct GlyphVertex { public short X, Y, CX, CY; diff --git a/TrueTypeSharp/TrueTypeFont.cs b/TrueTypeSharp/TrueTypeFont.cs index d089cfa..18bfe71 100644 --- a/TrueTypeSharp/TrueTypeFont.cs +++ b/TrueTypeSharp/TrueTypeFont.cs @@ -32,20 +32,28 @@ namespace TrueTypeSharp public TrueTypeFont(byte[] data, int offset) { - CheckFontData(data, offset); - - if (0 == stb_truetype.stbtt_InitFont(ref _info, - new FakePtr() { Array = data }, offset)) - { - throw new BadImageFormatException("Couldn't load TrueType file."); - } + InitFontData(data, offset); } - public TrueTypeFont(string filename) - : this(File.ReadAllBytes(filename), 0) - { + public TrueTypeFont(Stream stream) + { + using (var memoryStream = new MemoryStream()) + { + stream.CopyTo(memoryStream); + InitFontData(memoryStream.ToArray(), 0); + } + } - } + private void InitFontData(byte[] data, int offset) + { + CheckFontData(data, offset); + + if (0 == stb_truetype.stbtt_InitFont(ref _info, + new FakePtr() { Array = data }, offset)) + { + throw new BadImageFormatException("Couldn't load TrueType file."); + } + } static void CheckFontData(byte[] data, int offset) { diff --git a/TrueTypeSharp/TrueTypeSharp.csproj b/TrueTypeSharp/TrueTypeSharp.csproj index 61c2d42..fd28d09 100644 --- a/TrueTypeSharp/TrueTypeSharp.csproj +++ b/TrueTypeSharp/TrueTypeSharp.csproj @@ -1,98 +1,57 @@ - - + + Debug AnyCPU - 9.0.30729 + 10.0.0 2.0 - {B722113F-1252-4BE1-9D43-6BC82B3E37D1} + {1651CC69-D1D5-4770-9C93-45CB91579130} + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library - Properties TrueTypeSharp TrueTypeSharp - v2.0 - 512 - - - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true + Profile14 + v4.0 true full false - ..\bin\ - DEBUG;TRACE + ..\bin + DEBUG; prompt 4 + false - pdbonly + full true - ..\bin\ - TRACE + ..\bin prompt 4 + false + + - + + - - - + + - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - + - - \ No newline at end of file