Initial commit

Based on version 1.0.5 from http://www.zer7.com/software/truetypesharp
This commit is contained in:
Gered 2013-08-11 09:54:26 -04:00
commit 72061260e1
21 changed files with 4856 additions and 0 deletions

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
.DS_Store
*.suo
*.user
*.userprefs
*.sln.docstates
[Dd]ebug/
[Rr]elease/
[Bb]in/
[Oo]bj/

5
CHANGES Normal file
View file

@ -0,0 +1,5 @@
1.0.5 May 14, 2012:
Ported over stb_truetype 0.5, adding kerning and subpixel functions.
1.0.2 August 25, 2010:
Initial public release.

18
LICENSE Normal file
View file

@ -0,0 +1,18 @@
TrueTypeSharp
Copyright (c) 2010, 2012 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View file

@ -0,0 +1,102 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace TrueTypeSharp.Demo
{
class Program
{
static void SaveBitmap(byte[] data, int x0, int y0, int x1, int y1,
int stride, string filename)
{
var bitmap = new Bitmap(x1 - x0, y1 - y0);
for (int y = y0; y < y1; y++)
{
for (int x = x0; x < x1; x++)
{
byte opacity = data[y * stride + x];
bitmap.SetPixel(x - x0, y - y0, Color.FromArgb(opacity, 0x00, 0x7f, 0xff));
}
}
bitmap.Save(filename);
}
static void Main(string[] args)
{
var font = new TrueTypeFont(@"Anonymous/Anonymous Pro.ttf");
// Render some characters...
for (char ch = 'A'; ch <= 'Z'; ch++)
{
int width, height, xOffset, yOffset;
float scale = font.GetScaleForPixelHeight(80);
byte[] data = font.GetCodepointBitmap(ch, scale, scale,
out width, out height, out xOffset, out yOffset);
SaveBitmap(data, 0, 0, width, height, width, "Char-" + ch.ToString() + ".png");
}
// Let's try baking. Tasty tasty.
BakedCharCollection characters; float pixelHeight = 18;
var bitmap = font.BakeFontBitmap(pixelHeight, out characters, true);
SaveBitmap(bitmap.Buffer, 0, 0, bitmap.Width, bitmap.Height, bitmap.Width, "BakeResult1.png");
// Now, let's give serialization a go.
using (var file = File.OpenWrite("BakeResult2.temp"))
{
var bitmapSaver = new BinaryFormatter();
bitmapSaver.Serialize(file, bitmap);
bitmapSaver.Serialize(file, characters);
int ascent, descent, lineGap;
float scale = font.GetScaleForPixelHeight(pixelHeight);
font.GetFontVMetrics(out ascent, out descent, out lineGap);
bitmapSaver.Serialize(file, (float)ascent * scale);
bitmapSaver.Serialize(file, (float)descent * scale);
bitmapSaver.Serialize(file, (float)lineGap * scale);
}
using (var file = File.OpenRead("BakeResult2.temp"))
{
var bitmapLoader = new BinaryFormatter();
var bitmapAgain = (FontBitmap)bitmapLoader.Deserialize(file);
var charactersAgain = (BakedCharCollection)bitmapLoader.Deserialize(file);
SaveBitmap(bitmapAgain.Buffer, 0, 0, bitmapAgain.Width, bitmapAgain.Height, bitmap.Width, "BakeResult2.png");
for (char ch = 'A'; ch <= 'Z'; ch++)
{
BakedChar bakedChar = charactersAgain[ch];
if (bakedChar.IsEmpty) { continue; }
SaveBitmap(bitmapAgain.Buffer,
bakedChar.X0, bakedChar.Y0, bakedChar.X1, bakedChar.Y1,
bitmapAgain.Stride, "SmallChar-" + ch.ToString() + ".png");
}
}
}
}
}

View file

@ -0,0 +1,8 @@
using System.Reflection;
[assembly: AssemblyTitle("TrueTypeSharp.Demo")]
[assembly: AssemblyDescription("TrueTypeSharp demo application")]
[assembly: AssemblyProduct("TrueTypeSharp")]
[assembly: AssemblyCopyright("TrueTypeSharp: Copyright © 2010 Illusory Studios LLC. stb_truetype: Public domain, Sean Barrett.")]
[assembly: AssemblyVersion("1.0.0.0")]

View file

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B067AB58-D823-4A46-97E1-43BC75F7FF35}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TrueTypeSharp.Demo</RootNamespace>
<AssemblyName>TrueTypeSharp.Demo</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TrueTypeSharp\TrueTypeSharp.csproj">
<Project>{B722113F-1252-4BE1-9D43-6BC82B3E37D1}</Project>
<Name>TrueTypeSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

26
TrueTypeSharp.sln Normal file
View file

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueTypeSharp", "TrueTypeSharp\TrueTypeSharp.csproj", "{B722113F-1252-4BE1-9D43-6BC82B3E37D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrueTypeSharp.Demo", "TrueTypeSharp.Demo\TrueTypeSharp.Demo.csproj", "{B067AB58-D823-4A46-97E1-43BC75F7FF35}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B722113F-1252-4BE1-9D43-6BC82B3E37D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B722113F-1252-4BE1-9D43-6BC82B3E37D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B722113F-1252-4BE1-9D43-6BC82B3E37D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B722113F-1252-4BE1-9D43-6BC82B3E37D1}.Release|Any CPU.Build.0 = Release|Any CPU
{B067AB58-D823-4A46-97E1-43BC75F7FF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B067AB58-D823-4A46-97E1-43BC75F7FF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B067AB58-D823-4A46-97E1-43BC75F7FF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B067AB58-D823-4A46-97E1-43BC75F7FF35}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,68 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
namespace TrueTypeSharp
{
[Serializable]
public struct BakedChar
{
public static BakedChar Empty
{
get { return default(BakedChar); }
}
public ushort X0, Y0, X1, Y1;
public float XOffset, YOffset, XAdvance;
public BakedQuad GetBakedQuad(int bakeWidth, int bakeHeight,
ref float xPosition, ref float yPosition)
{
return GetBakedQuad(bakeWidth, bakeHeight, ref xPosition, ref yPosition, false);
}
public BakedQuad GetBakedQuad(int bakeWidth, int bakeHeight,
ref float xPosition, ref float yPosition, bool putTexCoordsAtTexelCenters)
{
BakedQuad quad;
stb_truetype.stbtt_GetBakedQuad(ref this, bakeWidth, bakeHeight,
ref xPosition, ref yPosition, out quad, putTexCoordsAtTexelCenters ? 0 : 1);
return quad;
}
public bool IsEmpty
{
get { return Width == 0 && Height == 0 && XAdvance == 0; }
}
public int Width
{
get { return X1 - X0; }
}
public int Height
{
get { return Y1 - Y0; }
}
}
}

View file

@ -0,0 +1,224 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace TrueTypeSharp
{
[Serializable]
public class BakedCharCollection : ISerializable
{
Dictionary<char, BakedChar> _characters;
int _bakeWidth, _bakeHeight;
public BakedCharCollection(char firstCodepoint, BakedChar[] characters,
int bakeWidth, int bakeHeight)
{
if (characters == null) { throw new ArgumentNullException("characters"); }
Dictionary<char, BakedChar> dictionary = new Dictionary<char, BakedChar>();
for (int i = 0; i < characters.Length; i++)
{
char codepoint = (char)(firstCodepoint + i);
if (char.IsSurrogate(codepoint)) { continue; }
BakedChar character = characters[i];
if (character.IsEmpty) { continue; }
dictionary[codepoint] = character;
}
Create(dictionary, bakeWidth, bakeHeight);
}
protected BakedCharCollection(SerializationInfo info, StreamingContext context)
{
Create((Dictionary<char, BakedChar>)
info.GetValue("Characters", typeof(Dictionary<char, BakedChar>)),
info.GetInt32("BakeWidth"), info.GetInt32("BakeHeight"));
}
void Create(Dictionary<char, BakedChar> characters, int bakeWidth, int bakeHeight)
{
if (characters == null) { throw new ArgumentNullException("characters"); }
if (bakeWidth < 0 || bakeHeight < 0) { throw new ArgumentOutOfRangeException(); }
BakeWidth = bakeWidth; BakeHeight = bakeHeight;
_characters = characters;
}
public IEnumerable<BakedQuad> GetTextQuads(string str,
float lineAscender, float lineDescender, float lineGap,
int hAlign, int vAlign)
{
return GetTextQuads(new string[] { str },
lineAscender, lineDescender, lineGap, hAlign, vAlign);
}
public IEnumerable<BakedQuad> GetTextQuads(IEnumerable<string> strs,
float lineAscender, float lineDescender, float lineGap,
int hAlign, int vAlign)
{
if (strs == null) { throw new ArgumentNullException("strs"); }
float y0 = 0, y1, yPosition = 0;
y1 = BakedCharCollection.GetVerticalTextHeight(strs, lineAscender, lineDescender, lineGap);
BakedCharCollection.OffsetTextPositionForAlignment(y0, y1, ref yPosition, vAlign);
foreach (var str in strs)
{
yPosition += lineAscender;
float sx0, sy0, sx1, sy1, sxPosition = 0, syPosition = yPosition;
if (GetTextBounds(str, out sx0, out sy0, out sx1, out sy1))
{
BakedCharCollection.OffsetTextPositionForAlignment
(sx0, sx1, ref sxPosition, hAlign);
foreach (var ch in str)
{
var quad = GetBakedQuad(ch, ref sxPosition, ref syPosition);
if (quad.IsEmpty) { continue; }
yield return quad;
}
}
yPosition += lineGap - lineDescender;
}
}
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)
{
return GetBakedQuad(character, ref xPosition, ref yPosition, false);
}
public BakedQuad GetBakedQuad(char character,
ref float xPosition, ref float yPosition, bool putTexCoordsAtTexelCenters)
{
var bakedChar = this[character]; if (bakedChar.IsEmpty) { return BakedQuad.Empty; }
return bakedChar.GetBakedQuad(BakeWidth, BakeHeight,
ref xPosition, ref yPosition, putTexCoordsAtTexelCenters);
}
static int ElementCount(IEnumerable<string> strs)
{
var list = strs as ICollection<string>; if (list != null) { return list.Count; }
var e = strs.GetEnumerator(); int count = 0; while (e.MoveNext()) { count++; }
return count;
}
public static float GetVerticalTextHeight(IEnumerable<string> strs,
float lineAscender, float lineDescender, float lineGap)
{
if (strs == null) { throw new ArgumentNullException("strs"); }
return GetVerticalTextHeight(ElementCount(strs),
lineAscender, lineDescender, lineGap);
}
public static float GetVerticalTextHeight(int lineCount,
float lineAscender, float lineDescender, float lineGap)
{
return Math.Max(0, lineGap * (lineCount - 1)
+ (lineAscender - lineDescender) * lineCount);
}
public bool GetTextBounds(string str, out float x0, out float y0, out float x1, out float y1)
{
if (str == null) { throw new ArgumentNullException("str"); }
x0 = y0 = x1 = y1 = 0; bool isSet = false; float xPosition = 0, yPosition = 0;
foreach (var ch in str)
{
var quad = GetBakedQuad(ch, ref xPosition, ref yPosition);
if (quad.IsEmpty) { continue; }
if (isSet)
{
if (quad.X0 < x0) { x0 = quad.X0; } if (quad.Y0 < y0) { y0 = quad.Y0; }
if (quad.X1 > x1) { x1 = quad.X1; } if (quad.Y1 > y1) { y1 = quad.Y1; }
}
else
{
x0 = quad.X0; y0 = quad.Y0; x1 = quad.X1; y1 = quad.Y1;
isSet = true;
}
}
return isSet;
}
public void OffsetTextPositionForAlignment(string str,
ref float xPosition, ref float yPosition, int hAlign, int vAlign)
{
float x0, y0, x1, y1;
GetTextBounds(str, out x0, out y0, out x1, out y1);
OffsetTextPositionForAlignment(x0, x1, ref xPosition, hAlign);
OffsetTextPositionForAlignment(y0, y1, ref yPosition, vAlign);
}
public static void OffsetTextPositionForAlignment(float xOrY0, float xOrY1,
ref float position, int align)
{
if (align < 0) { position -= xOrY0; }
else if (align == 0) { position -= (xOrY0 + xOrY1) * 0.5f; }
else { position -= xOrY1; }
}
public int BakeWidth
{
get { return _bakeWidth; }
set { if (value < 0) { throw new ArgumentOutOfRangeException(); } _bakeWidth = value; }
}
public int BakeHeight
{
get { return _bakeHeight; }
set { if (value < 0) { throw new ArgumentOutOfRangeException(); } _bakeHeight = value; }
}
public IDictionary<char, BakedChar> Characters
{
get { return _characters; }
}
public BakedChar this[char character]
{
get
{
BakedChar bakedChar;
_characters.TryGetValue(character, out bakedChar);
return bakedChar;
}
}
}
}

View file

@ -0,0 +1,43 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
namespace TrueTypeSharp
{
[Serializable]
public struct BakedQuad
{
public static BakedQuad Empty
{
get { return default(BakedQuad); }
}
public float X0, Y0, S0, T0;
public float X1, Y1, S1, T1;
public bool IsEmpty
{
get { return X0 == X1 && Y0 == Y1; }
}
}
}

View file

@ -0,0 +1,32 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
namespace TrueTypeSharp
{
[Serializable]
public struct ContourPoint
{
public float X, Y;
}
}

98
TrueTypeSharp/FakePtr.cs Normal file
View file

@ -0,0 +1,98 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
namespace TrueTypeSharp
{
#pragma warning disable 0660, 0661 // This never goes into a collection...
struct FakePtr<T>
{
public T[] Array; public int Offset;
public T[] GetData(int length)
{
var t = new T[length];
if (Array != null) { global::System.Array.Copy(Array, Offset, t, 0, length); }
return t;
}
public void MakeNull()
{
Array = null; Offset = 0;
}
public T this[int index]
{
get
{
try { return Array[Offset + index]; }
catch (IndexOutOfRangeException) { return default(T); } // Sometimes accesses are made out of range, it appears.
// In particular, to get all the way to char.MaxValue, this was needed.
// Probably bad data in the font. Also, is bounds checking done?
// I don't see it... Either way, it's not a problem for us here.
}
set { Array[Offset + index] = value; }
}
public T Value
{
get { return this[0]; }
set { this[0] = value; }
}
public bool IsNull
{
get { return Array == null; }
}
public static FakePtr<T> operator +(FakePtr<T> p, int offset)
{
return new FakePtr<T>() { Array = p.Array, Offset = p.Offset + offset };
}
public static FakePtr<T> operator -(FakePtr<T> p, int offset)
{
return p + -offset;
}
public static FakePtr<T> operator +(FakePtr<T> p, uint offset)
{
return p + (int)offset;
}
public static FakePtr<T> operator ++(FakePtr<T> p)
{
return p + 1;
}
public static bool operator ==(FakePtr<T> p1, FakePtr<T> p2)
{
return p1.Array == p2.Array && p1.Offset == p2.Offset;
}
public static bool operator !=(FakePtr<T> p1, FakePtr<T> p2)
{
return !(p1 == p2);
}
}
}

182
TrueTypeSharp/FontBitmap.cs Normal file
View file

@ -0,0 +1,182 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
using System.Runtime.Serialization;
namespace TrueTypeSharp
{
[Serializable]
public struct FontBitmap : ISerializable
{
public delegate T PixelConversionFunc<T>(byte opacity);
public byte[] Buffer; public int BufferOffset;
public int XOffset, YOffset, Width, Height, Stride;
public FontBitmap(int width, int height) : this()
{
if (width < 0 || height < 0 || width * height < 0)
{ throw new ArgumentOutOfRangeException(); }
Buffer = new byte[width * height];
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);
int w = Math.Min(width, Width), h = Math.Min(height, Height);
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++) { bitmap[x, y] = this[x, y]; }
}
return bitmap;
}
public FontBitmap GetResizedBitmap(int width, int height, BakedCharCollection bakedChars)
{
var bitmap = GetResizedBitmap(width, height);
if (bakedChars != null) { bakedChars.BakeWidth = bitmap.Width; bakedChars.BakeHeight = bitmap.Height; }
return bitmap;
}
static int RoundUpToPow2(int value)
{
int rounded = 1;
while (rounded < value) { rounded <<= 1; }
return rounded;
}
public FontBitmap GetResizedBitmapPow2()
{
return GetResizedBitmap(RoundUpToPow2(Width), RoundUpToPow2(Height));
}
public FontBitmap GetResizedBitmapPow2(BakedCharCollection bakedChars)
{
return GetResizedBitmap(RoundUpToPow2(Width), RoundUpToPow2(Height), bakedChars);
}
public FontBitmap GetTrimmedBitmap()
{
return GetResizedBitmap(Width, Height);
}
public byte[,] To2DBitmap()
{
return To2DBitmap(false);
}
public byte[,] To2DBitmap(bool yMajor)
{
return To2DBitmap(yMajor, x => x);
}
public T[,] To2DBitmap<T>(bool yMajor, PixelConversionFunc<T> pixelConversionFunc)
{
if (pixelConversionFunc == null) { throw new ArgumentNullException("pixelConversionFunc"); }
if (yMajor)
{
var bitmap = new T[Height, Width];
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
bitmap[y, x] = pixelConversionFunc(this[x, y]);
}
}
return bitmap;
}
else
{
var bitmap = new T[Width, Height];
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
bitmap[x, y] = pixelConversionFunc(this[x, y]);
}
}
return bitmap;
}
}
public int StartOffset
{
get { return YOffset * Stride + XOffset + BufferOffset; }
}
public bool IsValid
{
get
{
return Buffer != null && Width >= 0 && Height >= 0 && StartOffset >= 0
&& Width * Height >= 0 && Width * Height <= Buffer.Length
&& StartOffset + Height * Stride >= 0
&& StartOffset + Height * Stride <= Buffer.Length;
}
}
internal FakePtr<byte> StartPointer
{
get { return new FakePtr<byte>() { Array = Buffer, Offset = StartOffset }; }
}
public byte this[int x, int y]
{
get
{
try { return Buffer[StartOffset + y * Stride + x]; }
catch (NullReferenceException) { throw new InvalidOperationException(); }
}
set
{
try { Buffer[StartOffset + y * Stride + x] = value; }
catch (NullReferenceException) { throw new InvalidOperationException(); }
}
}
}
}

View file

@ -0,0 +1,33 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
namespace TrueTypeSharp
{
[Serializable]
public struct GlyphVertex
{
public short X, Y, CX, CY;
public GlyphVertexType Type;
}
}

View file

@ -0,0 +1,31 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
namespace TrueTypeSharp
{
public enum GlyphVertexType : ushort
{
Move = 1,
Line,
Curve
}
}

View file

@ -0,0 +1,8 @@
using System.Reflection;
[assembly: AssemblyTitle("TrueTypeSharp")]
[assembly: AssemblyDescription("C# TrueType font renderer")]
[assembly: AssemblyProduct("TrueTypeSharp")]
[assembly: AssemblyCopyright("TrueTypeSharp: Copyright © 2010, 2012 Illusory Studios LLC. stb_truetype: Public domain, Sean Barrett.")]
[assembly: AssemblyVersion("1.0.5.0")]

View file

@ -0,0 +1,85 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010, 2012 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
namespace TrueTypeSharp
{
public partial class TrueTypeFont
{
public byte[] GetCodepointBitmapSubpixel(char codepoint,
float xScale, float yScale, float xShift, float yShift,
out int width, out int height, out int xOffset, out int yOffset)
{
return GetGlyphBitmapSubpixel(FindGlyphIndex(codepoint),
xScale, yScale, xShift, yShift,
out width, out height, out xOffset, out yOffset);
}
public byte[] GetCodepointBitmap(char codepoint, float xScale, float yScale,
out int width, out int height, out int xOffset, out int yOffset)
{
return GetCodepointBitmapSubpixel(codepoint, xScale, yScale, 0, 0,
out width, out height, out xOffset, out yOffset);
}
public void GetCodepointBitmapBoxSubpixel(char codepoint,
float xScale, float yScale, float xShift, float yShift,
out int x0, out int y0, out int x1, out int y1)
{
GetGlyphBitmapBoxSubpixel(FindGlyphIndex(codepoint),
xScale, yScale, xShift, yShift,
out x0, out y0, out x1, out y1);
}
public void GetCodepointBitmapBox(char codepoint, float xScale, float yScale,
out int x0, out int y0, out int x1, out int y1)
{
GetCodepointBitmapBoxSubpixel(codepoint, xScale, yScale, 0, 0, out x0, out y0, out x1, out y1);
}
public void GetCodepointBox(char codepoint,
out int x0, out int y0, out int x1, out int y1)
{
GetGlyphBox(FindGlyphIndex(codepoint), out x0, out y0, out x1, out y1);
}
public int GetCodepointKernAdvance(char codepoint1, char codepoint2)
{
return GetGlyphKernAdvance(FindGlyphIndex(codepoint1), FindGlyphIndex(codepoint2));
}
public void GetCodepointHMetrics(char codepoint, out int advanceWidth, out int leftSideBearing)
{
GetGlyphHMetrics(FindGlyphIndex(codepoint), out advanceWidth, out leftSideBearing);
}
public GlyphVertex[] GetCodepointShape(char codepoint)
{
return GetGlyphShape(FindGlyphIndex(codepoint));
}
public void MakeCodepointBitmap(char codepoint, float xScale, float yScale,
FontBitmap bitmap)
{
MakeGlyphBitmap(FindGlyphIndex(codepoint), xScale, yScale, bitmap);
}
}
}

View file

@ -0,0 +1,256 @@
#region License
/* TrueTypeSharp
Copyright (c) 2010, 2012 Illusory Studios LLC
TrueTypeSharp is available at zer7.com. It is a C# port of Sean Barrett's
C library stb_truetype, which was placed in the public domain and is
available at nothings.org.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endregion
using System;
using System.Diagnostics;
using System.IO;
namespace TrueTypeSharp
{
public partial class TrueTypeFont
{
stb_truetype.stbtt_fontinfo _info;
public TrueTypeFont(byte[] data, int offset)
{
CheckFontData(data, offset);
if (0 == stb_truetype.stbtt_InitFont(ref _info,
new FakePtr<byte>() { Array = data }, offset))
{
throw new BadImageFormatException("Couldn't load TrueType file.");
}
}
public TrueTypeFont(string filename)
: this(File.ReadAllBytes(filename), 0)
{
}
static void CheckFontData(byte[] data, int offset)
{
if (data == null) { throw new ArgumentNullException("data"); }
if (offset < 0 || offset > data.Length) { throw new ArgumentOutOfRangeException("offset"); }
}
public static bool TryGetFontOffsetForIndex(byte[] data, int index, out int offset)
{
offset = stb_truetype.stbtt_GetFontOffsetForIndex(new FakePtr<byte>() { Array = data }, index);
if (offset < 0) { offset = 0; return false; } else { return true; }
}
public int BakeFontBitmap(float pixelHeight, char firstCodepoint,
BakedChar[] characters, FontBitmap bitmap)
{
float scale = GetScaleForPixelHeight(pixelHeight);
return BakeFontBitmap(scale, scale, firstCodepoint, characters, bitmap);
}
public int BakeFontBitmap(float xScale, float yScale, char firstCodepoint,
BakedChar[] characters, FontBitmap bitmap)
{
if (!bitmap.IsValid) { throw new ArgumentException("bitmap"); }
if (characters == null) { throw new ArgumentNullException("characters"); }
return stb_truetype.stbtt_BakeFontBitmap(ref _info, xScale, yScale,
bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
(int)firstCodepoint, characters.Length,
new FakePtr<BakedChar>() { Array = characters });
}
// generates square textures ... minimalHeight can be used to crop if desired
public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
BakedChar[] characters, out int minimalHeight)
{
int size = 16;
if (characters.Length == 0) { minimalHeight = 0; return new FontBitmap(0, 0); }
while (true)
{
var bitmap = new FontBitmap(size, size);
int result = BakeFontBitmap(pixelHeight, firstCodepoint, characters, bitmap);
if (result > 0) { minimalHeight = result; return bitmap; }
size *= 2;
}
}
public FontBitmap BakeFontBitmap(float pixelHeight, out BakedCharCollection characters)
{
return BakeFontBitmap(pixelHeight, out characters, false);
}
public FontBitmap BakeFontBitmap(float pixelHeight, out BakedCharCollection characters,
bool shrinkToMinimalHeight)
{
return BakeFontBitmap(pixelHeight, char.MinValue, char.MaxValue, out characters,
shrinkToMinimalHeight);
}
public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
char lastCodepoint, out BakedCharCollection characters)
{
if (lastCodepoint < firstCodepoint)
{
var tmp = lastCodepoint;
lastCodepoint = firstCodepoint;
firstCodepoint = tmp;
}
return BakeFontBitmap(pixelHeight, firstCodepoint,
lastCodepoint - firstCodepoint + 1, out characters);
}
public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
int characterCount, out BakedCharCollection characters)
{
return BakeFontBitmap(pixelHeight, firstCodepoint, characterCount,
out characters, false);
}
public FontBitmap BakeFontBitmap(float pixelHeight, char firstCodepoint,
int characterCount, out BakedCharCollection characters, bool shrinkToMinimalHeight)
{
if (characterCount < 0) { throw new ArgumentOutOfRangeException("characterCount"); }
var charArray = new BakedChar[characterCount]; int minimalHeight;
var bitmap = BakeFontBitmap(pixelHeight, firstCodepoint, charArray, out minimalHeight);
if (shrinkToMinimalHeight) { bitmap.Height = minimalHeight; bitmap = bitmap.GetTrimmedBitmap(); }
characters = new BakedCharCollection(firstCodepoint, charArray, bitmap.Width, bitmap.Height);
return bitmap;
}
public uint FindGlyphIndex(char codepoint)
{
return stb_truetype.stbtt_FindGlyphIndex(ref _info, (uint)codepoint);
}
public void FlattenCurves(GlyphVertex[] vertices, float flatness,
out ContourPoint[] points, out int[] contourLengths)
{
if (vertices == null) { throw new ArgumentNullException("vertices"); }
FakePtr<int> contourLengthsFP; int contourCount;
var contours = stb_truetype.stbtt_FlattenCurves
(new FakePtr<GlyphVertex>() { Array = vertices }, vertices.Length,
flatness, out contourLengthsFP, out contourCount);
contourLengths = contourLengthsFP.GetData(contourCount);
int pointCount = 0;
foreach (var length in contourLengths) { pointCount += length; }
points = contours.GetData(pointCount);
}
public byte[] GetGlyphBitmapSubpixel(uint glyphIndex, float xScale, float yScale, float xShift, float yShift,
out int width, out int height, out int xOffset, out int yOffset)
{
var data = stb_truetype.stbtt_GetGlyphBitmapSubpixel(ref _info, xScale, yScale, xShift, yShift, glyphIndex,
out width, out height, out xOffset, out yOffset);
if (data.IsNull) { width = 0; height = 0; xOffset = 0; yOffset = 0; return data.GetData(0); }
return data.GetData(width * height);
}
public byte[] GetGlyphBitmap(uint glyphIndex, float xScale, float yScale,
out int width, out int height, out int xOffset, out int yOffset)
{
return GetGlyphBitmapSubpixel(glyphIndex, xScale, yScale, 0, 0,
out width, out height, out xOffset, out yOffset);
}
public void MakeGlyphBitmapSubpixel(uint glyphIndex,
float xScale, float yScale, float xShift, float yShift,
FontBitmap bitmap)
{
if (bitmap.Buffer == null) { throw new ArgumentNullException("bitmap.Buffer"); }
stb_truetype.stbtt_MakeGlyphBitmapSubpixel(ref _info,
bitmap.StartPointer, bitmap.Width, bitmap.Height, bitmap.Stride,
xScale, yScale, xShift, yShift, glyphIndex);
}
public void MakeGlyphBitmap(uint glyphIndex, float xScale, float yScale, FontBitmap bitmap)
{
MakeGlyphBitmapSubpixel(glyphIndex, xScale, yScale, 0, 0, bitmap);
}
public void GetGlyphBitmapBoxSubpixel(uint glyphIndex,
float xScale, float yScale, float xShift, float yShift,
out int x0, out int y0, out int x1, out int y1)
{
stb_truetype.stbtt_GetGlyphBitmapBoxSubpixel(ref _info, glyphIndex,
xScale, yScale, xShift, yShift, out x0, out y0, out x1, out y1);
}
public void GetGlyphBitmapBox(uint glyphIndex, float xScale, float yScale,
out int x0, out int y0, out int x1, out int y1)
{
GetGlyphBitmapBoxSubpixel(glyphIndex, xScale, yScale, 0, 0, out x0, out y0, out x1, out y1);
}
public void GetGlyphBox(uint glyphIndex,
out int x0, out int y0, out int x1, out int y1)
{
stb_truetype.stbtt_GetGlyphBox(ref _info, glyphIndex,
out x0, out y0, out x1, out y1);
}
public void GetGlyphHMetrics(uint glyphIndex, out int advanceWidth, out int leftSideBearing)
{
stb_truetype.stbtt_GetGlyphHMetrics(ref _info, glyphIndex,
out advanceWidth, out leftSideBearing);
}
public GlyphVertex[] GetGlyphShape(uint glyphIndex)
{
FakePtr<GlyphVertex> vertices;
int n = stb_truetype.stbtt_GetGlyphShape(ref _info, glyphIndex, out vertices);
return vertices.GetData(n);
}
public int GetGlyphKernAdvance(uint glyph1Index, uint glyph2Index)
{
return stb_truetype.stbtt_GetGlyphKernAdvance(ref _info, glyph1Index, glyph2Index);
}
public void GetFontVMetrics(out int lineAscender, out int lineDescender, out int lineGap)
{
stb_truetype.stbtt_GetFontVMetrics(ref _info, out lineAscender, out lineDescender, out lineGap);
}
public void GetFontVMetricsAtScale(float pixelHeight, out float lineAscender, out float lineDescender, out float lineGap)
{
int lineAscenderI, lineDescenderI, lineGapI;
GetFontVMetrics(out lineAscenderI, out lineDescenderI, out lineGapI);
float scale = GetScaleForPixelHeight(pixelHeight);
lineAscender = (float)lineAscenderI * scale;
lineDescender = (float)lineDescenderI * scale;
lineGap = (float)lineGapI * scale;
}
public float GetScaleForPixelHeight(float pixelHeight)
{
return stb_truetype.stbtt_ScaleForPixelHeight(ref _info, pixelHeight);
}
}
}

View file

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B722113F-1252-4BE1-9D43-6BC82B3E37D1}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TrueTypeSharp</RootNamespace>
<AssemblyName>TrueTypeSharp</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<None Include="stb_truetype.h" />
<Compile Include="BakedChar.cs" />
<Compile Include="BakedCharCollection.cs" />
<Compile Include="BakedQuad.cs" />
<Compile Include="FakePtr.cs" />
<Compile Include="FontBitmap.cs" />
<Compile Include="GlyphVertex.cs" />
<Compile Include="GlyphVertexType.cs" />
<Compile Include="ContourPoint.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="stb_truetype.cs" />
<Compile Include="TrueTypeFont.Codepoints.cs" />
<Compile Include="TrueTypeFont.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

File diff suppressed because it is too large Load diff

1958
TrueTypeSharp/stb_truetype.h Normal file

File diff suppressed because it is too large Load diff