Updated to MonoGame 3.6 + Directory refactor
- Barotrauma's projects are in the Barotrauma directory - All libraries are in the Libraries directory - MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?) - NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred - Removed Content/effects.mgfx as it didn't seem to be used anywhere - Removed some references to Subsurface directory - Renamed Launcher2 to Launcher
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of constants used for the glyph-to-script-map property to specify the script submodule the auto-hinter
|
||||
/// should use for hinting a particular glyph.
|
||||
/// </summary>
|
||||
public enum AutoHinterScript
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't auto-hint this glyph.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Apply the latin auto-hinter. For the auto-hinter, ‘latin’ is a very broad term, including Cyrillic and
|
||||
/// Greek also since characters from those scripts share the same design constraints.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// By default, characters from the following Unicode ranges are assigned to this submodule.
|
||||
/// </para><para><code>
|
||||
/// U+0020 - U+007F // Basic Latin (no control characters)
|
||||
/// U+00A0 - U+00FF // Latin-1 Supplement (no control characters)
|
||||
/// U+0100 - U+017F // Latin Extended-A
|
||||
/// U+0180 - U+024F // Latin Extended-B
|
||||
/// U+0250 - U+02AF // IPA Extensions
|
||||
/// U+02B0 - U+02FF // Spacing Modifier Letters
|
||||
/// U+0300 - U+036F // Combining Diacritical Marks
|
||||
/// U+0370 - U+03FF // Greek and Coptic
|
||||
/// U+0400 - U+04FF // Cyrillic
|
||||
/// U+0500 - U+052F // Cyrillic Supplement
|
||||
/// U+1D00 - U+1D7F // Phonetic Extensions
|
||||
/// U+1D80 - U+1DBF // Phonetic Extensions Supplement
|
||||
/// U+1DC0 - U+1DFF // Combining Diacritical Marks Supplement
|
||||
/// U+1E00 - U+1EFF // Latin Extended Additional
|
||||
/// U+1F00 - U+1FFF // Greek Extended
|
||||
/// U+2000 - U+206F // General Punctuation
|
||||
/// U+2070 - U+209F // Superscripts and Subscripts
|
||||
/// U+20A0 - U+20CF // Currency Symbols
|
||||
/// U+2150 - U+218F // Number Forms
|
||||
/// U+2460 - U+24FF // Enclosed Alphanumerics
|
||||
/// U+2C60 - U+2C7F // Latin Extended-C
|
||||
/// U+2DE0 - U+2DFF // Cyrillic Extended-A
|
||||
/// U+2E00 - U+2E7F // Supplemental Punctuation
|
||||
/// U+A640 - U+A69F // Cyrillic Extended-B
|
||||
/// U+A720 - U+A7FF // Latin Extended-D
|
||||
/// U+FB00 - U+FB06 // Alphab. Present. Forms (Latin Ligatures)
|
||||
/// U+1D400 - U+1D7FF // Mathematical Alphanumeric Symbols
|
||||
/// U+1F100 - U+1F1FF // Enclosed Alphanumeric Supplement
|
||||
/// </code></para></remarks>
|
||||
Latin = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old Vietnamese, and some other scripts.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// By default, characters from the following Unicode ranges are assigned to this submodule.
|
||||
/// </para><para><code>
|
||||
/// U+1100 - U+11FF // Hangul Jamo
|
||||
/// U+2E80 - U+2EFF // CJK Radicals Supplement
|
||||
/// U+2F00 - U+2FDF // Kangxi Radicals
|
||||
/// U+2FF0 - U+2FFF // Ideographic Description Characters
|
||||
/// U+3000 - U+303F // CJK Symbols and Punctuation
|
||||
/// U+3040 - U+309F // Hiragana
|
||||
/// U+30A0 - U+30FF // Katakana
|
||||
/// U+3100 - U+312F // Bopomofo
|
||||
/// U+3130 - U+318F // Hangul Compatibility Jamo
|
||||
/// U+3190 - U+319F // Kanbun
|
||||
/// U+31A0 - U+31BF // Bopomofo Extended
|
||||
/// U+31C0 - U+31EF // CJK Strokes
|
||||
/// U+31F0 - U+31FF // Katakana Phonetic Extensions
|
||||
/// U+3200 - U+32FF // Enclosed CJK Letters and Months
|
||||
/// U+3300 - U+33FF // CJK Compatibility
|
||||
/// U+3400 - U+4DBF // CJK Unified Ideographs Extension A
|
||||
/// U+4DC0 - U+4DFF // Yijing Hexagram Symbols
|
||||
/// U+4E00 - U+9FFF // CJK Unified Ideographs
|
||||
/// U+A960 - U+A97F // Hangul Jamo Extended-A
|
||||
/// U+AC00 - U+D7AF // Hangul Syllables
|
||||
/// U+D7B0 - U+D7FF // Hangul Jamo Extended-B
|
||||
/// U+F900 - U+FAFF // CJK Compatibility Ideographs
|
||||
/// U+FE10 - U+FE1F // Vertical forms
|
||||
/// U+FE30 - U+FE4F // CJK Compatibility Forms
|
||||
/// U+FF00 - U+FFEF // Halfwidth and Fullwidth Forms
|
||||
/// U+1B000 - U+1B0FF // Kana Supplement
|
||||
/// U+1D300 - U+1D35F // Tai Xuan Hing Symbols
|
||||
/// U+1F200 - U+1F2FF // Enclosed Ideographic Supplement
|
||||
/// U+20000 - U+2A6DF // CJK Unified Ideographs Extension B
|
||||
/// U+2A700 - U+2B73F // CJK Unified Ideographs Extension C
|
||||
/// U+2B740 - U+2B81F // CJK Unified Ideographs Extension D
|
||||
/// U+2F800 - U+2FA1F // CJK Compatibility Ideographs Supplement
|
||||
/// </code></para></remarks>
|
||||
Cjk = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Apply the indic auto-hinter, covering all major scripts from the Indian sub-continent and some other
|
||||
/// related scripts like Thai, Lao, or Tibetan.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// By default, characters from the following Unicode ranges are assigned to this submodule.
|
||||
/// </para><para><code>
|
||||
/// U+0900 - U+0DFF // Indic Range
|
||||
/// U+0F00 - U+0FFF // Tibetan
|
||||
/// U+1900 - U+194F // Limbu
|
||||
/// U+1B80 - U+1BBF // Sundanese
|
||||
/// U+1C80 - U+1CDF // Meetei Mayak
|
||||
/// U+A800 - U+A82F // Syloti Nagri
|
||||
/// U+11800 - U+118DF // Sharada
|
||||
/// </code></para><para>
|
||||
/// Note that currently Indic support is rudimentary only, missing blue zone support.
|
||||
/// </para></remarks>
|
||||
Indic = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to hold an outline's bounding box, i.e., the
|
||||
/// coordinates of its extrema in the horizontal and vertical directions.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct BBox : IEquatable<BBox>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private FT_Long xMin, yMin;
|
||||
private FT_Long xMax, yMax;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BBox"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="left">The left bound.</param>
|
||||
/// <param name="bottom">The bottom bound.</param>
|
||||
/// <param name="right">The right bound.</param>
|
||||
/// <param name="top">The upper bound.</param>
|
||||
public BBox(int left, int bottom, int right, int top)
|
||||
{
|
||||
xMin = (IntPtr)left;
|
||||
yMin = (IntPtr)bottom;
|
||||
xMax = (IntPtr)right;
|
||||
yMax = (IntPtr)top;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal minimum (left-most).
|
||||
/// </summary>
|
||||
public int Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)xMin;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical minimum (bottom-most).
|
||||
/// </summary>
|
||||
public int Bottom
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)yMin;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal maximum (right-most).
|
||||
/// </summary>
|
||||
public int Right
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)xMax;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical maximum (top-most).
|
||||
/// </summary>
|
||||
public int Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)yMax;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="BBox"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="BBox"/>.</param>
|
||||
/// <param name="right">Another <see cref="BBox"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public static bool operator ==(BBox left, BBox right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="BBox"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="BBox"/>.</param>
|
||||
/// <param name="right">Another <see cref="BBox"/>.</param>
|
||||
/// <returns>A value indicating inequality.</returns>
|
||||
public static bool operator !=(BBox left, BBox right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="BBox"/> to another for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="BBox"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public bool Equals(BBox other)
|
||||
{
|
||||
return
|
||||
xMin == other.xMin &&
|
||||
yMin == other.yMin &&
|
||||
xMax == other.xMax &&
|
||||
yMax == other.yMax;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="BBox"/> to an object for equality.
|
||||
/// </summary>
|
||||
/// <param name="obj">An object.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is BBox)
|
||||
return this.Equals((BBox)obj);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//TODO better hash algo
|
||||
return xMin.GetHashCode() ^ yMin.GetHashCode() ^ xMax.GetHashCode() ^ yMax.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string that represents this instance.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of this instance.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "Min: (" + (int)xMin + ", " + (int)yMin + "), Max: (" + (int)xMax + ", " + (int)yMax + ")";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Bdf.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Pack = 0)]
|
||||
internal struct PropertyRec
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal PropertyType type;
|
||||
|
||||
[FieldOffset(4)]
|
||||
internal IntPtr atom;
|
||||
|
||||
[FieldOffset(4)]
|
||||
internal int integer;
|
||||
|
||||
[FieldOffset(4)]
|
||||
internal uint cardinal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Bdf.Internal;
|
||||
|
||||
namespace SharpFont.Bdf
|
||||
{
|
||||
/// <summary>
|
||||
/// This structure models a given BDF/PCF property.
|
||||
/// </summary>
|
||||
public class Property
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private PropertyRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Property(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property type.
|
||||
/// </summary>
|
||||
public PropertyType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the atom string, if type is <see cref="PropertyType.Atom"/>.
|
||||
/// </summary>
|
||||
public string Atom
|
||||
{
|
||||
get
|
||||
{
|
||||
// only this property throws an exception because the pointer could be to unmanaged memory not owned by
|
||||
// the process.
|
||||
if (rec.type != PropertyType.Atom)
|
||||
throw new InvalidOperationException("The property type is not Atom.");
|
||||
|
||||
return Marshal.PtrToStringAnsi(rec.atom);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a signed integer, if type is <see cref="PropertyType.Integer"/>.
|
||||
/// </summary>
|
||||
public int Integer
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.integer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an unsigned integer, if type is <see cref="PropertyType.Cardinal"/>.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Cardinal
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.cardinal;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<PropertyRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Bdf
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of BDF property types.
|
||||
/// </summary>
|
||||
public enum PropertyType
|
||||
{
|
||||
/// <summary>Value 0 is used to indicate a missing property.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Property is a string atom.</summary>
|
||||
Atom = 1,
|
||||
|
||||
/// <summary>Property is a 32-bit signed integer.</summary>
|
||||
Integer = 2,
|
||||
|
||||
/// <summary>Property is a 32-bit unsigned integer.</summary>
|
||||
Cardinal = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used for bitmap glyph images. This really is a ‘sub-class’ of <see cref="Glyph"/>.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// You can typecast an <see cref="Glyph"/> to <see cref="BitmapGlyph"/> if you have ‘<see cref="Glyph.Format"/> ==
|
||||
/// <see cref="GlyphFormat.Bitmap"/>’. This lets you access the bitmap's contents easily.
|
||||
/// </para><para>
|
||||
/// The corresponding pixel buffer is always owned by <see cref="BitmapGlyph"/> and is thus created and destroyed
|
||||
/// with it.
|
||||
/// </para></remarks>
|
||||
public sealed class BitmapGlyph : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private Glyph original;
|
||||
private BitmapGlyphRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal BitmapGlyph(Glyph original)
|
||||
{
|
||||
this.original = original;
|
||||
Reference = original.Reference; //generates the rec.
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="BitmapGlyph"/> class.
|
||||
/// </summary>
|
||||
~BitmapGlyph()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the object has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return original.IsDisposed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root <see cref="Glyph"/> fields.
|
||||
/// </summary>
|
||||
public Glyph Root
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Root", "Cannot access a disposed object.");
|
||||
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left-side bearing, i.e., the horizontal distance from the current pen position to the left border
|
||||
/// of the glyph bitmap.
|
||||
/// </summary>
|
||||
public int Left
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Left", "Cannot access a disposed object.");
|
||||
|
||||
return rec.left;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top-side bearing, i.e., the vertical distance from the current pen position to the top border of
|
||||
/// the glyph bitmap. This distance is positive for upwards y!
|
||||
/// </summary>
|
||||
public int Top
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Top", "Cannot access a disposed object.");
|
||||
|
||||
return rec.top;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a descriptor for the bitmap.
|
||||
/// </summary>
|
||||
public FTBitmap Bitmap
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Bitmap", "Cannot access a disposed object.");
|
||||
|
||||
return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf<BitmapGlyphRec>(Reference, "bitmap"), rec.bitmap, null);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return original.Reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot modify a disposed object.");
|
||||
|
||||
rec = PInvokeHelper.PtrToStructure<BitmapGlyphRec>(original.Reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="BitmapGlyph"/> back up to a <see cref="Glyph"/>. The eqivalent of
|
||||
/// <see cref="BitmapGlyph.Root"/>.
|
||||
/// </summary>
|
||||
/// <param name="g">A <see cref="BitmapGlyph"/>.</param>
|
||||
/// <returns>A <see cref="Glyph"/>.</returns>
|
||||
public static implicit operator Glyph(BitmapGlyph g)
|
||||
{
|
||||
return g.original;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// A CLS-compliant version of the implicit cast to <see cref="Glyph"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Glyph"/>.</returns>
|
||||
public Glyph ToGlyph()
|
||||
{
|
||||
return (Glyph)this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes an instance of the <see cref="BitmapGlyph"/> class.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
original.Dispose();
|
||||
original = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// This structure models the metrics of a bitmap strike (i.e., a set of
|
||||
/// glyphs for a given point size and resolution) in a bitmap font. It is
|
||||
/// used for the <see cref="Face.AvailableSizes"/> field of
|
||||
/// <see cref="Face"/>.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// Windows FNT: The nominal size given in a FNT font is not reliable. Thus
|
||||
/// when the driver finds it incorrect, it sets ‘size’ to some calculated
|
||||
/// values and sets ‘x_ppem’ and ‘y_ppem’ to the pixel width and height
|
||||
/// given in the font, respectively.
|
||||
/// </para><para>
|
||||
/// TrueType embedded bitmaps: ‘size’, ‘width’, and ‘height’ values are not
|
||||
/// contained in the bitmap strike itself. They are computed from the
|
||||
/// global font parameters.
|
||||
/// </para></remarks>
|
||||
public sealed class BitmapSize
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private BitmapSizeRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal BitmapSize(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
internal BitmapSize(BitmapSizeRec bmpSizeInt)
|
||||
{
|
||||
this.rec = bmpSizeInt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical distance, in pixels, between two consecutive
|
||||
/// baselines. It is always positive.
|
||||
/// </summary>
|
||||
public short Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the average width, in pixels, of all glyphs in the strike.
|
||||
/// </summary>
|
||||
public short Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the nominal size of the strike in 26.6 fractional points. This
|
||||
/// field is not very useful.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal ppem (nominal width) in 26.6 fractional pixels.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 NominalWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.x_ppem);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical ppem (nominal height) in 26.6 fractional pixels.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 NominalHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.y_ppem);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<BitmapSizeRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// An opaque handle used to model a charmap cache. This cache is to hold character codes -> glyph indices
|
||||
/// mappings.
|
||||
/// </summary>
|
||||
public class CMapCache
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CMapCache"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Like all other caches, this one will be destroyed with the cache manager.
|
||||
/// </remarks>
|
||||
/// <param name="manager">A handle to the cache manager.</param>
|
||||
public CMapCache(Manager manager)
|
||||
{
|
||||
IntPtr cacheRef;
|
||||
Error err = FT.FTC_CMapCache_New(manager.Reference, out cacheRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = cacheRef;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Translate a character code into a glyph index, using the charmap cache.
|
||||
/// </summary>
|
||||
/// <param name="faceId">The source face ID.</param>
|
||||
/// <param name="cmapIndex">
|
||||
/// The index of the charmap in the source face. Any negative value means to use the cache <see cref="Face"/>'s
|
||||
/// default charmap.
|
||||
/// </param>
|
||||
/// <param name="charCode">The character code (in the corresponding charmap).</param>
|
||||
/// <returns>Glyph index. 0 means ‘no glyph’.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public uint Lookup(IntPtr faceId, int cmapIndex, uint charCode)
|
||||
{
|
||||
return FT.FTC_CMapCache_Lookup(Reference, faceId, cmapIndex, charCode);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A callback function provided by client applications. It is used by the cache manager to translate a given
|
||||
/// FTC_FaceID into a new valid <see cref="Face"/> object, on demand.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The third parameter ‘req_data’ is the same as the one passed by the client when
|
||||
/// <see cref="Manager(Library, uint, uint, ulong, FaceRequester, IntPtr)"/> is called.
|
||||
/// </para><para>
|
||||
/// The face requester should not perform funny things on the returned face object, like creating a new
|
||||
/// <see cref="FTSize"/> for it, or setting a transformation through <see cref="Face.SetTransform()"/>!
|
||||
/// </para></remarks>
|
||||
/// <param name="faceId">The face ID to resolve.</param>
|
||||
/// <param name="library">A handle to a FreeType library object.</param>
|
||||
/// <param name="requestData">Application-provided request data (see note below).</param>
|
||||
/// <param name="aface">A new <see cref="Face"/> handle.</param>
|
||||
/// <returns>FreeType error code. 0 means success.</returns>
|
||||
public delegate Error FaceRequester(IntPtr faceId, IntPtr library, IntPtr requestData, out IntPtr aface);
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to an glyph image cache object. They are designed to hold many distinct glyph images while not
|
||||
/// exceeding a certain memory threshold.
|
||||
/// </summary>
|
||||
public class ImageCache
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private Manager parentManager;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ImageCache"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">The parent manager for the image cache.</param>
|
||||
public ImageCache(Manager manager)
|
||||
{
|
||||
if (manager == null)
|
||||
throw new ArgumentNullException("manager");
|
||||
|
||||
IntPtr cacheRef;
|
||||
Error err = FT.FTC_ImageCache_New(manager.Reference, out cacheRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
parentManager = manager;
|
||||
Reference = cacheRef;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a given glyph image from a glyph image cache.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it
|
||||
/// manually! You can however create a copy with <see cref="Glyph.Copy"/> and modify the new one.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is not NULL, it receives the address of the cache node containing the glyph image,
|
||||
/// after increasing its reference count. This ensures that the node (as well as the <see cref="Glyph"/>) will
|
||||
/// always be kept in the cache until you call <see cref="Node.Unref"/> to ‘release’ it.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is NULL, the cache node is left unchanged, which means that the <see cref="Glyph"/>
|
||||
/// could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that
|
||||
/// it is persistent!
|
||||
/// </para></remarks>
|
||||
/// <param name="type">A pointer to a glyph image type descriptor.</param>
|
||||
/// <param name="gIndex">The glyph index to retrieve.</param>
|
||||
/// <param name="node">
|
||||
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
|
||||
/// note below).
|
||||
/// </param>
|
||||
/// <returns>The corresponding <see cref="Glyph"/> object. 0 in case of failure.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public Glyph Lookup(ImageType type, uint gIndex, out Node node)
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr glyphRef, nodeRef;
|
||||
Error err = FT.FTC_ImageCache_Lookup(Reference, type.Reference, gIndex, out glyphRef, out nodeRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
node = new Node(nodeRef);
|
||||
return new Glyph(glyphRef, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A variant of <see cref="ImageCache.Lookup"/> that uses a <see cref="Scaler"/> to specify the face ID and its
|
||||
/// size.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The returned glyph is owned and managed by the glyph image cache. Never try to transform or discard it
|
||||
/// manually! You can however create a copy with <see cref="Glyph.Copy"/> and modify the new one.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is not NULL, it receives the address of the cache node containing the glyph image,
|
||||
/// after increasing its reference count. This ensures that the node (as well as the <see cref="Glyph"/>) will
|
||||
/// always be kept in the cache until you call <see cref="Node.Unref"/> to ‘release’ it.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is NULL, the cache node is left unchanged, which means that the <see cref="Glyph"/>
|
||||
/// could be flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that
|
||||
/// it is persistent!
|
||||
/// </para><para>
|
||||
/// Calls to <see cref="Face.SetCharSize"/> and friends have no effect on cached glyphs; you should always use
|
||||
/// the FreeType cache API instead.
|
||||
/// </para></remarks>
|
||||
/// <param name="scaler">A pointer to a scaler descriptor.</param>
|
||||
/// <param name="loadFlags">The corresponding load flags.</param>
|
||||
/// <param name="gIndex">The glyph index to retrieve.</param>
|
||||
/// <param name="node">
|
||||
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
|
||||
/// note below).
|
||||
/// </param>
|
||||
/// <returns>The corresponding <see cref="Glyph"/> object. 0 in case of failure.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public Glyph LookupScaler(Scaler scaler, LoadFlags loadFlags, uint gIndex, out Node node)
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr glyphRef, nodeRef;
|
||||
Error err = FT.FTC_ImageCache_LookupScaler(Reference, scaler.Reference, loadFlags, gIndex, out glyphRef, out nodeRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
node = new Node(nodeRef);
|
||||
return new Glyph(glyphRef, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Cache.Internal;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to model the type of images in a glyph cache.
|
||||
/// </summary>
|
||||
public class ImageType
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private ImageTypeRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal ImageType(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the face ID.
|
||||
/// </summary>
|
||||
public IntPtr FaceId
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.face_id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width in pixels.
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height in pixels.
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the load flags, as in <see cref="Face.LoadGlyph"/>
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public LoadFlags Flags
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.flags;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<ImageTypeRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct CMapCacheRec
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageCacheRec
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ImageTypeRec
|
||||
{
|
||||
internal IntPtr face_id;
|
||||
internal int width;
|
||||
internal int height;
|
||||
internal LoadFlags flags;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ManagerRec
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct NodeRec
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SBitCacheRec
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SBitRec
|
||||
{
|
||||
internal byte width;
|
||||
internal byte height;
|
||||
internal byte left;
|
||||
internal byte top;
|
||||
|
||||
internal byte format;
|
||||
internal byte max_grays;
|
||||
internal short pitch;
|
||||
internal byte xadvance;
|
||||
internal byte yadvance;
|
||||
|
||||
internal IntPtr buffer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ScalerRec
|
||||
{
|
||||
internal IntPtr face_id;
|
||||
internal uint width;
|
||||
internal uint height;
|
||||
internal int pixel;
|
||||
internal uint x_res;
|
||||
internal uint y_res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary><para>
|
||||
/// This object corresponds to one instance of the cache-subsystem. It is used to cache one or more
|
||||
/// <see cref="Face"/> objects, along with corresponding <see cref="FTSize"/> objects.
|
||||
/// </para><para>
|
||||
/// The manager intentionally limits the total number of opened <see cref="Face"/> and <see cref="FTSize"/> objects
|
||||
/// to control memory usage. See the ‘max_faces’ and ‘max_sizes’ parameters of
|
||||
/// <see cref="Manager(Library, uint, uint, ulong, FaceRequester, IntPtr)"/>.
|
||||
/// </para><para>
|
||||
/// The manager is also used to cache ‘nodes’ of various types while limiting their total memory usage.
|
||||
/// </para><para>
|
||||
/// All limitations are enforced by keeping lists of managed objects in most-recently-used order, and flushing old
|
||||
/// nodes to make room for new ones.
|
||||
/// </para></summary>
|
||||
public sealed class Manager : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private Library parentLibrary;
|
||||
|
||||
private bool disposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Manager class.
|
||||
/// </summary>
|
||||
/// <param name="library">The parent FreeType library handle to use.</param>
|
||||
/// <param name="maxFaces">
|
||||
/// Maximum number of opened <see cref="Face"/> objects managed by this cache instance. Use 0 for defaults.
|
||||
/// </param>
|
||||
/// <param name="maxSizes">
|
||||
/// Maximum number of opened <see cref="FTSize"/> objects managed by this cache instance. Use 0 for defaults.
|
||||
/// </param>
|
||||
/// <param name="maxBytes">
|
||||
/// Maximum number of bytes to use for cached data nodes. Use 0 for defaults. Note that this value does not
|
||||
/// account for managed <see cref="Face"/> and <see cref="FTSize"/> objects.
|
||||
/// </param>
|
||||
/// <param name="requester">
|
||||
/// An application-provided callback used to translate face IDs into real <see cref="Face"/> objects.
|
||||
/// </param>
|
||||
/// <param name="requestData">
|
||||
/// A generic pointer that is passed to the requester each time it is called (see <see cref="FaceRequester"/>).
|
||||
/// </param>
|
||||
[CLSCompliant(false)]
|
||||
public Manager(Library library, uint maxFaces, uint maxSizes, ulong maxBytes, FaceRequester requester, IntPtr requestData)
|
||||
{
|
||||
if (library == null)
|
||||
throw new ArgumentNullException("library");
|
||||
|
||||
IntPtr mgrRef;
|
||||
Error err = FT.FTC_Manager_New(library.Reference, maxFaces, maxSizes, maxBytes, requester, requestData, out mgrRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = mgrRef;
|
||||
|
||||
this.parentLibrary = library;
|
||||
library.AddChildManager(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the Manager class.
|
||||
/// </summary>
|
||||
~Manager()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the object has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return disposed;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Empty a given cache manager. This simply gets rid of all the currently cached <see cref="Face"/> and
|
||||
/// <see cref="FTSize"/> objects within the manager.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
|
||||
|
||||
FT.FTC_Manager_Reset(Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the <see cref="Face"/> object that corresponds to a given face ID through a cache manager.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The returned <see cref="Face"/> object is always owned by the manager. You should never try to discard it
|
||||
/// yourself.
|
||||
/// </para><para>
|
||||
/// The <see cref="Face"/> object doesn't necessarily have a current size object (i.e., <see cref="Face.Size"/>
|
||||
/// can be 0). If you need a specific ‘font size’, use <see cref="Manager.LookupSize"/> instead.
|
||||
/// </para><para>
|
||||
/// Never change the face's transformation matrix (i.e., never call the <see cref="Face.SetTransform()"/>
|
||||
/// function) on a returned face! If you need to transform glyphs, do it yourself after glyph loading.
|
||||
/// </para><para>
|
||||
/// When you perform a lookup, out-of-memory errors are detected within the lookup and force incremental
|
||||
/// flushes of the cache until enough memory is released for the lookup to succeed.
|
||||
/// </para><para>
|
||||
/// If a lookup fails with <see cref="Error.OutOfMemory"/> the cache has already been completely flushed, and
|
||||
/// still no memory was available for the operation.
|
||||
/// </para></remarks>
|
||||
/// <param name="faceId">The ID of the face object.</param>
|
||||
/// <returns>A handle to the face object.</returns>
|
||||
public Face LookupFace(IntPtr faceId)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr faceRef;
|
||||
Error err = FT.FTC_Manager_LookupFace(Reference, faceId, out faceRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
//HACK fix this later.
|
||||
return new Face(faceRef, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the <see cref="FTSize"/> object that corresponds to a given <see cref="Scaler"/> pointer through a
|
||||
/// cache manager.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The returned <see cref="FTSize"/> object is always owned by the/ manager. You should never try to discard
|
||||
/// it by yourself.
|
||||
/// </para><para>
|
||||
/// You can access the parent <see cref="Face"/> object simply as <see cref="FTSize.Face"/> if you need it.
|
||||
/// Note that this object is also owned by the manager.
|
||||
/// </para><para>
|
||||
/// When you perform a lookup, out-of-memory errors are detected within the lookup and force incremental
|
||||
/// flushes of the cache until enough memory is released for the lookup to succeed.
|
||||
/// </para><para>
|
||||
/// If a lookup fails with <see cref="Error.OutOfMemory"/> the cache has already been completely flushed, and
|
||||
/// still no memory is available for the operation.
|
||||
/// </para></remarks>
|
||||
/// <param name="scaler">A scaler handle.</param>
|
||||
/// <returns>A handle to the size object.</returns>
|
||||
public FTSize LookupSize(Scaler scaler)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr sizeRef;
|
||||
Error err = FT.FTC_Manager_LookupSize(Reference, scaler.Reference, out sizeRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
//HACK fix this later.
|
||||
return new FTSize(sizeRef, false, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A special function used to indicate to the cache manager that a given FTC_FaceID is no longer valid, either
|
||||
/// because its content changed, or because it was deallocated or uninstalled.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// This function flushes all nodes from the cache corresponding to this ‘faceID’, with the
|
||||
/// exception of nodes with a non-null reference count.
|
||||
/// </para><para>
|
||||
/// Such nodes are however modified internally so as to never appear in later lookups with the same
|
||||
/// ‘faceID’ value, and to be immediately destroyed when released by all their users.
|
||||
/// </para></remarks>
|
||||
/// <param name="faceId">The FTC_FaceID to be removed.</param>
|
||||
public void RemoveFaceId(IntPtr faceId)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Manager", "Cannot access a disposed object.");
|
||||
|
||||
FT.FTC_Manager_RemoveFaceID(Reference, faceId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the Manager.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
FT.FTC_Manager_Done(reference);
|
||||
reference = IntPtr.Zero;
|
||||
|
||||
// removes itself from the parent Library, with a check to prevent this from happening when Library is
|
||||
// being disposed (Library disposes all it's children with a foreach loop, this causes an
|
||||
// InvalidOperationException for modifying a collection during enumeration)
|
||||
if (!parentLibrary.IsDisposed)
|
||||
parentLibrary.RemoveChildManager(this);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary><para>
|
||||
/// An opaque handle to a cache node object. Each cache node is reference-counted. A node with a count of 0 might
|
||||
/// be flushed out of a full cache whenever a lookup request is performed.
|
||||
/// </para><para>
|
||||
/// If you look up nodes, you have the ability to ‘acquire’ them, i.e., to increment their reference count. This
|
||||
/// will prevent the node from being flushed out of the cache until you explicitly ‘release’ it.
|
||||
/// </para></summary>
|
||||
/// <see cref="Node.Unref"/>
|
||||
/// <seealso cref="SBitCache.Lookup"/>
|
||||
/// <seealso cref="ImageCache.Lookup"/>
|
||||
public class Node
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Node(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Decrement a cache node's internal reference count. When the count reaches 0, it is not destroyed but
|
||||
/// becomes eligible for subsequent cache flushes.
|
||||
/// </summary>
|
||||
/// <param name="manager">The cache manager handle.</param>
|
||||
public void Unref(Manager manager)
|
||||
{
|
||||
FT.FTC_Node_Unref(Reference, manager.Reference);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Cache.Internal;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to a small bitmap cache. These are special cache objects used to store small glyph bitmaps (and
|
||||
/// anti-aliased pixmaps) in a much more efficient way than the traditional glyph image cache implemented by
|
||||
/// <see cref="ImageCache"/>.
|
||||
/// </summary>
|
||||
public class SBit
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private SBitRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal SBit(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmap width in pixels.
|
||||
/// </summary>
|
||||
public byte Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmap height in pixels.
|
||||
/// </summary>
|
||||
public byte Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal distance from the pen position to the left bitmap border (a.k.a. ‘left side bearing’,
|
||||
/// or ‘lsb’).
|
||||
/// </summary>
|
||||
public byte Left
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.left;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical distance from the pen position (on the baseline) to the upper bitmap border (a.k.a. ‘top
|
||||
/// side bearing’). The distance is positive for upwards y coordinates.
|
||||
/// </summary>
|
||||
public byte Top
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.top;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format of the glyph bitmap (monochrome or gray).
|
||||
/// </summary>
|
||||
public byte Format
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.format;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum gray level value (in the range 1 to 255).
|
||||
/// </summary>
|
||||
public byte MaxGrays
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.max_grays;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes per bitmap line. May be positive or negative.
|
||||
/// </summary>
|
||||
public short Pitch
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal advance width in pixels.
|
||||
/// </summary>
|
||||
public byte AdvanceX
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.xadvance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical advance height in pixels.
|
||||
/// </summary>
|
||||
public byte AdvanceY
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.yadvance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a pointer to the bitmap pixels.
|
||||
/// </summary>
|
||||
public IntPtr Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<SBitRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to a small bitmap cache. These are special cache objects used to store small glyph bitmaps (and
|
||||
/// anti-aliased pixmaps) in a much more efficient way than the traditional glyph image cache implemented by
|
||||
/// <see cref="ImageCache"/>.
|
||||
/// </summary>
|
||||
public class SBitCache
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private Manager parentManager;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SBitCache"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">A handle to the source cache manager.</param>
|
||||
public SBitCache(Manager manager)
|
||||
{
|
||||
if (manager == null)
|
||||
throw new ArgumentNullException("manager");
|
||||
|
||||
IntPtr cacheRef;
|
||||
Error err = FT.FTC_SBitCache_New(manager.Reference, out cacheRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = cacheRef;
|
||||
parentManager = manager;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Look up a given small glyph bitmap in a given sbit cache and ‘lock’ it to prevent its flushing from the
|
||||
/// cache until needed.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the
|
||||
/// application. They might as well disappear from memory on the next cache lookup, so don't treat them as
|
||||
/// persistent data.
|
||||
/// </para><para>
|
||||
/// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is not NULL, it receives the address of the cache node containing the bitmap, after
|
||||
/// increasing its reference count. This ensures that the node (as well as the image) will always be kept in
|
||||
/// the cache until you call <see cref="Node.Unref"/> to ‘release’ it.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is NULL, the cache node is left unchanged, which means that the bitmap could be
|
||||
/// flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is
|
||||
/// persistent!
|
||||
/// </para></remarks>
|
||||
/// <param name="type">A pointer to the glyph image type descriptor.</param>
|
||||
/// <param name="gIndex">The glyph index.</param>
|
||||
/// <param name="node">
|
||||
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
|
||||
/// note below).
|
||||
/// </param>
|
||||
/// <returns>A handle to a small bitmap descriptor.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public SBit Lookup(ImageType type, uint gIndex, out Node node)
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr sbitRef, nodeRef;
|
||||
Error err = FT.FTC_SBitCache_Lookup(Reference, type.Reference, gIndex, out sbitRef, out nodeRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
node = new Node(nodeRef);
|
||||
return new SBit(sbitRef);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A variant of <see cref="SBitCache.Lookup"/> that uses a <see cref="Scaler"/> to specify the face ID and its
|
||||
/// size.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The small bitmap descriptor and its bit buffer are owned by the cache and should never be freed by the
|
||||
/// application. They might as well disappear from memory on the next cache lookup, so don't treat them as
|
||||
/// persistent data.
|
||||
/// </para><para>
|
||||
/// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is not NULL, it receives the address of the cache node containing the bitmap, after
|
||||
/// increasing its reference count. This ensures that the node (as well as the image) will always be kept in
|
||||
/// the cache until you call <see cref="Node.Unref"/> to ‘release’ it.
|
||||
/// </para><para>
|
||||
/// If ‘node’ is NULL, the cache node is left unchanged, which means that the bitmap could be
|
||||
/// flushed out of the cache on the next call to one of the caching sub-system APIs. Don't assume that it is
|
||||
/// persistent!
|
||||
/// </para></remarks>
|
||||
/// <param name="scaler">A pointer to the scaler descriptor.</param>
|
||||
/// <param name="loadFlags">The corresponding load flags.</param>
|
||||
/// <param name="gIndex">The glyph index.</param>
|
||||
/// <param name="node">
|
||||
/// Used to return the address of of the corresponding cache node after incrementing its reference count (see
|
||||
/// note below).
|
||||
/// </param>
|
||||
/// <returns>A handle to a small bitmap descriptor.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public SBit LookupScaler(Scaler scaler, LoadFlags loadFlags, uint gIndex, out Node node)
|
||||
{
|
||||
if (parentManager.IsDisposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr sbitRef, nodeRef;
|
||||
Error err = FT.FTC_SBitCache_LookupScaler(Reference, scaler.Reference, loadFlags, gIndex, out sbitRef, out nodeRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
node = new Node(nodeRef);
|
||||
return new SBit(sbitRef);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Cache.Internal;
|
||||
|
||||
namespace SharpFont.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to describe a given character size in either pixels or points to the cache manager.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This type is mainly used to retrieve <see cref="FTSize"/> objects through the cache manager.
|
||||
/// </remarks>
|
||||
/// <see cref="Manager.LookupSize"/>
|
||||
public class Scaler
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private ScalerRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Scaler(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source face ID.
|
||||
/// </summary>
|
||||
public IntPtr FaceId
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.face_id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character width.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character height.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the ‘width’ and ‘height’ fields are interpreted as integer pixel character
|
||||
/// sizes. Otherwise, they are expressed as 1/64th of points.
|
||||
/// </summary>
|
||||
public bool Pixel
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.pixel == 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the horizontal resolution in dpi; only used when ‘pixel’ is value 0.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint ResolutionX
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.x_res;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertical resolution in dpi; only used when ‘pixel’ is value 0.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint ResolutionY
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.y_res;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<ScalerRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Cff
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of constants used for the hinting-engine property to select the hinting engine for CFF fonts.
|
||||
/// </summary>
|
||||
public enum HintingEngine
|
||||
{
|
||||
/// <summary>Use the old FreeType hinting engine.</summary>
|
||||
FreeType = 0,
|
||||
|
||||
/// <summary>Use the hinting engine contributed by Adobe.</summary>
|
||||
Adobe = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
using SharpFont.TrueType;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// The base charmap structure.
|
||||
/// </summary>
|
||||
public sealed class CharMap
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private CharMapRec rec;
|
||||
|
||||
private Face parentFace;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal CharMap(IntPtr reference, Face parent)
|
||||
{
|
||||
Reference = reference;
|
||||
this.parentFace = parent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the parent face object.
|
||||
/// </summary>
|
||||
public Face Face
|
||||
{
|
||||
get
|
||||
{
|
||||
return parentFace;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="Encoding"/> tag identifying the charmap. Use this with
|
||||
/// <see cref="SharpFont.Face.SelectCharmap"/>.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public Encoding Encoding
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.encoding;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ID number describing the platform for the following encoding ID. This comes directly from the
|
||||
/// TrueType specification and should be emulated for other formats.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public PlatformId PlatformId
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.platform_id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a platform specific encoding number. This also comes from the TrueType specification and should be
|
||||
/// emulated similarly.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort EncodingId
|
||||
{
|
||||
get
|
||||
{
|
||||
//TODO find some way of getting a proper encoding ID enum...
|
||||
return rec.encoding_id;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<CharMapRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Base Interface
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve index of a given charmap.
|
||||
/// </summary>
|
||||
/// <returns>The index into the array of character maps within the face to which ‘charmap’ belongs.</returns>
|
||||
public int GetCharmapIndex()
|
||||
{
|
||||
return FT.FT_Get_Charmap_Index(Reference);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TrueType Tables
|
||||
|
||||
/// <summary>
|
||||
/// Return TrueType/sfnt specific cmap language ID. Definitions of language ID values are in
|
||||
/// ‘freetype/ttnameid.h’.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The language ID of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, just return 0 as the
|
||||
/// default value.
|
||||
/// </returns>
|
||||
[CLSCompliant(false)]
|
||||
public uint GetCMapLanguageId()
|
||||
{
|
||||
return FT.FT_Get_CMap_Language_ID(Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return TrueType/sfnt specific cmap format.
|
||||
/// </summary>
|
||||
/// <returns>The format of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, return -1.</returns>
|
||||
public int GetCMapFormat()
|
||||
{
|
||||
return FT.FT_Get_CMap_Format(Reference);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of bit-field constants used with <see cref="Face.ClassicKernValidate"/> to indicate the classic kern
|
||||
/// dialect or dialects. If the selected type doesn't fit, <see cref="Face.ClassicKernValidate"/> regards the table
|
||||
/// as invalid.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[CLSCompliant(false)]
|
||||
public enum ClassicKernValidationFlags : uint
|
||||
{
|
||||
/// <summary>Handle the ‘kern’ table as a classic Microsoft kern table.</summary>
|
||||
Microsoft = 0x4000 << 0,
|
||||
|
||||
/// <summary>Handle the ‘kern’ table as a classic Apple kern table.</summary>
|
||||
Apple = 0x4000 << 1,
|
||||
|
||||
/// <summary>Handle the ‘kern’ as either classic Apple or Microsoft kern table.</summary>
|
||||
All = Microsoft | Apple
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Read-only binary data represented as a pointer and a length.
|
||||
/// </summary>
|
||||
public sealed class Data
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Data(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data.
|
||||
/// </summary>
|
||||
public IntPtr Pointer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.ReadIntPtr(reference, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the data in bytes.
|
||||
/// </summary>
|
||||
public int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.ReadInt32(reference, IntPtr.Size);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of bit flags used in the ‘fsType’ field of the OS/2 table in a
|
||||
/// TrueType or OpenType font and the ‘FSType’ entry in a PostScript font.
|
||||
/// These bit flags are returned by FT_Get_FSType_Flags; they inform client
|
||||
/// applications of embedding and subsetting restrictions associated with a
|
||||
/// font.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// While the fsType flags can indicate that a font may be embedded, a
|
||||
/// license with the font vendor may be separately required to use the font
|
||||
/// in this way.
|
||||
/// </remarks>
|
||||
/// <see href="http://www.adobe.com/devnet/acrobat/pdfs/FontPolicies.pdf"/>
|
||||
[Flags]
|
||||
[CLSCompliant(false)]
|
||||
public enum EmbeddingTypes : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// Fonts with no fsType bit set may be embedded and permanently
|
||||
/// installed on the remote system by an application.
|
||||
/// </summary>
|
||||
Installable = 0x0000,
|
||||
|
||||
/// <summary>
|
||||
/// Fonts that have only this bit set must not be modified, embedded
|
||||
/// or exchanged in any manner without first obtaining permission of
|
||||
/// the font software copyright owner.
|
||||
/// </summary>
|
||||
RestrictedLicense = 0x0002,
|
||||
|
||||
/// <summary>
|
||||
/// If this bit is set, the font may be embedded and temporarily loaded
|
||||
/// on the remote system. Documents containing Preview & Print
|
||||
/// fonts must be opened ‘read-only’; no edits can be applied to the
|
||||
/// document.
|
||||
/// </summary>
|
||||
PreviewAndPrint = 0x0004,
|
||||
|
||||
/// <summary>
|
||||
/// If this bit is set, the font may be embedded but must only be
|
||||
/// installed temporarily on other systems. In contrast to Preview
|
||||
/// & Print fonts, documents containing editable fonts may be
|
||||
/// opened for reading, editing is permitted, and changes may be saved.
|
||||
/// </summary>
|
||||
Editable = 0x0008,
|
||||
|
||||
/// <summary>
|
||||
/// If this bit is set, the font may not be subsetted prior to
|
||||
/// embedding.
|
||||
/// </summary>
|
||||
NoSubsetting = 0x0100,
|
||||
|
||||
/// <summary>
|
||||
/// If this bit is set, only bitmaps contained in the font may be
|
||||
/// embedded; no outline data may be embedded. If there are no bitmaps
|
||||
/// available in the font, then the font is unembeddable.
|
||||
/// </summary>
|
||||
BitmapOnly = 0x0200
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumeration used to specify character sets supported by charmaps.
|
||||
/// Used in the FT_Select_Charmap API function.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// Despite the name, this enumeration lists specific character repertories
|
||||
/// (i.e., charsets), and not text encoding methods (e.g., UTF-8, UTF-16,
|
||||
/// etc.).
|
||||
/// </para><para>
|
||||
/// Other encodings might be defined in the future.
|
||||
/// </para></remarks>
|
||||
[CLSCompliant(false)]
|
||||
public enum Encoding : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// The encoding value 0 is reserved.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to the Microsoft Symbol encoding, used to encode
|
||||
/// mathematical symbols in the 32..255 character code range.
|
||||
/// </summary>
|
||||
/// <see href="http://www.ceviz.net/symbol.htm"/>
|
||||
MicrosoftSymbol = ('s' << 24 | 'y' << 16 | 'm' << 8 | 'b'),
|
||||
|
||||
/// <summary><para>
|
||||
/// Corresponds to the Unicode character set. This value covers all
|
||||
/// versions of the Unicode repertoire, including ASCII and Latin-1.
|
||||
/// Most fonts include a Unicode charmap, but not all of them.
|
||||
/// </para><para>
|
||||
/// For example, if you want to access Unicode value U+1F028 (and the
|
||||
/// font contains it), use value 0x1F028 as the input value for
|
||||
/// FT_Get_Char_Index.
|
||||
/// </para></summary>
|
||||
Unicode = ('u' << 24 | 'n' << 16 | 'i' << 8 | 'c'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to Japanese SJIS encoding.
|
||||
/// </summary>
|
||||
/// <see href="http://langsupport.japanreference.com/encoding.shtml"/>
|
||||
Sjis = ('s' << 24 | 'j' << 16 | 'i' << 8 | 's'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to an encoding system for Simplified Chinese as used
|
||||
/// used in mainland China.
|
||||
/// </summary>
|
||||
GB2312 = ('g' << 24 | 'b' << 16 | ' ' << 8 | ' '),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to an encoding system for Traditional Chinese as used
|
||||
/// in Taiwan and Hong Kong.
|
||||
/// </summary>
|
||||
Big5 = ('b' << 24 | 'i' << 16 | 'g' << 8 | '5'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to the Korean encoding system known as Wansung.
|
||||
/// </summary>
|
||||
/// <see href="http://www.microsoft.com/typography/unicode/949.txt"/>
|
||||
Wansung = ('w' << 24 | 'a' << 16 | 'n' << 8 | 's'),
|
||||
|
||||
/// <summary>
|
||||
/// The Korean standard character set (KS C 5601-1992), which
|
||||
/// corresponds to MS Windows code page 1361. This character set
|
||||
/// includes all possible Hangeul character combinations.
|
||||
/// </summary>
|
||||
Johab = ('j' << 24 | 'o' << 16 | 'h' << 8 | 'a'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to the Adobe Standard encoding, as found in Type 1,
|
||||
/// CFF, and OpenType/CFF fonts. It is limited to 256 character codes.
|
||||
/// </summary>
|
||||
AdobeStandard = ('A' << 24 | 'D' << 16 | 'O' << 8 | 'B'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to the Adobe Expert encoding, as found in Type 1, CFF,
|
||||
/// and OpenType/CFF fonts. It is limited to 256 character codes.
|
||||
/// </summary>
|
||||
AdobeExpert = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'E'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to a custom encoding, as found in Type 1, CFF, and
|
||||
/// OpenType/CFF fonts. It is limited to 256 character codes.
|
||||
/// </summary>
|
||||
AdobeCustom = ('A' << 24 | 'D' << 16 | 'B' << 8 | 'C'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to a Latin-1 encoding as defined in a Type 1 PostScript
|
||||
/// font. It is limited to 256 character codes.
|
||||
/// </summary>
|
||||
AdobeLatin1 = ('l' << 24 | 'a' << 16 | 't' << 8 | '1'),
|
||||
|
||||
/// <summary>
|
||||
/// This value is deprecated and was never used nor reported by
|
||||
/// FreeType. Don't use or test for it.
|
||||
/// </summary>
|
||||
[Obsolete("Never used nor reported by FreeType")]
|
||||
OldLatin2 = ('l' << 24 | 'a' << 16 | 't' << 8 | '2'),
|
||||
|
||||
/// <summary>
|
||||
/// Corresponds to the 8-bit Apple roman encoding. Many TrueType and
|
||||
/// OpenType fonts contain a charmap for this encoding, since older
|
||||
/// versions of Mac OS are able to use it.
|
||||
/// </summary>
|
||||
AppleRoman = ('a' << 24 | 'r' << 16 | 'm' << 8 | 'n'),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// FreeType error codes.
|
||||
/// </summary>
|
||||
public enum Error
|
||||
{
|
||||
/// <summary>No error.</summary>
|
||||
Ok = 0x00,
|
||||
|
||||
/// <summary>Cannot open resource.</summary>
|
||||
CannotOpenResource = 0x01,
|
||||
|
||||
/// <summary>Unknown file format.</summary>
|
||||
UnknownFileFormat = 0x02,
|
||||
|
||||
/// <summary>Broken file.</summary>
|
||||
InvalidFileFormat = 0x03,
|
||||
|
||||
/// <summary>Invalid FreeType version.</summary>
|
||||
InvalidVersion = 0x04,
|
||||
|
||||
/// <summary>Module version is too low.</summary>
|
||||
LowerModuleVersion = 0x05,
|
||||
|
||||
/// <summary>Invalid argument.</summary>
|
||||
InvalidArgument = 0x06,
|
||||
|
||||
/// <summary>Unimplemented feature.</summary>
|
||||
UnimplementedFeature = 0x07,
|
||||
|
||||
/// <summary>Broken table.</summary>
|
||||
InvalidTable = 0x08,
|
||||
|
||||
/// <summary>Broken offset within table.</summary>
|
||||
InvalidOffset = 0x09,
|
||||
|
||||
/// <summary>Array allocation size too large.</summary>
|
||||
ArrayTooLarge = 0x0A,
|
||||
|
||||
/// <summary>Invalid glyph index.</summary>
|
||||
InvalidGlyphIndex = 0x10,
|
||||
|
||||
/// <summary>Invalid character code.</summary>
|
||||
InvalidCharacterCode = 0x11,
|
||||
|
||||
/// <summary>Unsupported glyph image format.</summary>
|
||||
InvalidGlyphFormat = 0x12,
|
||||
|
||||
/// <summary>Cannot render this glyph format.</summary>
|
||||
CannotRenderGlyph = 0x13,
|
||||
|
||||
/// <summary>Invalid outline.</summary>
|
||||
InvalidOutline = 0x14,
|
||||
|
||||
/// <summary>Invalid composite glyph.</summary>
|
||||
InvalidComposite = 0x15,
|
||||
|
||||
/// <summary>Too many hints.</summary>
|
||||
TooManyHints = 0x16,
|
||||
|
||||
/// <summary>Invalid pixel size.</summary>
|
||||
InvalidPixelSize = 0x17,
|
||||
|
||||
/// <summary>Invalid object handle.</summary>
|
||||
InvalidHandle = 0x20,
|
||||
|
||||
/// <summary>Invalid library handle.</summary>
|
||||
InvalidLibraryHandle = 0x21,
|
||||
|
||||
/// <summary>Invalid module handle.</summary>
|
||||
InvalidDriverHandle = 0x22,
|
||||
|
||||
/// <summary>Invalid face handle.</summary>
|
||||
InvalidFaceHandle = 0x23,
|
||||
|
||||
/// <summary>Invalid size handle.</summary>
|
||||
InvalidSizeHandle = 0x24,
|
||||
|
||||
/// <summary>Invalid glyph slot handle.</summary>
|
||||
InvalidSlotHandle = 0x25,
|
||||
|
||||
/// <summary>Invalid charmap handle.</summary>
|
||||
InvalidCharMapHandle = 0x26,
|
||||
|
||||
/// <summary>Invalid cache manager handle.</summary>
|
||||
InvalidCacheHandle = 0x27,
|
||||
|
||||
/// <summary>Invalid stream handle.</summary>
|
||||
InvalidStreamHandle = 0x28,
|
||||
|
||||
/// <summary>Too many modules.</summary>
|
||||
TooManyDrivers = 0x30,
|
||||
|
||||
/// <summary>Too many extensions.</summary>
|
||||
TooManyExtensions = 0x31,
|
||||
|
||||
/// <summary>Out of memory.</summary>
|
||||
OutOfMemory = 0x40,
|
||||
|
||||
/// <summary>Unlisted object.</summary>
|
||||
UnlistedObject = 0x41,
|
||||
|
||||
/// <summary>Cannot open stream.</summary>
|
||||
CannotOpenStream = 0x51,
|
||||
|
||||
/// <summary>Invalid stream seek.</summary>
|
||||
InvalidStreamSeek = 0x52,
|
||||
|
||||
/// <summary>Invalid stream skip.</summary>
|
||||
InvalidStreamSkip = 0x53,
|
||||
|
||||
/// <summary>Invalid stream read.</summary>
|
||||
InvalidStreamRead = 0x54,
|
||||
|
||||
/// <summary>Invalid stream operation.</summary>
|
||||
InvalidStreamOperation = 0x55,
|
||||
|
||||
/// <summary>Invalid frame operation.</summary>
|
||||
InvalidFrameOperation = 0x56,
|
||||
|
||||
/// <summary>Nested frame access.</summary>
|
||||
NestedFrameAccess = 0x57,
|
||||
|
||||
/// <summary>Invalid frame read.</summary>
|
||||
InvalidFrameRead = 0x58,
|
||||
|
||||
/// <summary>Raster uninitialized.</summary>
|
||||
RasterUninitialized = 0x60,
|
||||
|
||||
/// <summary>Raster corrupted.</summary>
|
||||
RasterCorrupted = 0x61,
|
||||
|
||||
/// <summary>Raster overflow.</summary>
|
||||
RasterOverflow = 0x62,
|
||||
|
||||
/// <summary>Negative height while rastering.</summary>
|
||||
RasterNegativeHeight = 0x63,
|
||||
|
||||
/// <summary>Too many registered caches.</summary>
|
||||
TooManyCaches = 0x70,
|
||||
|
||||
/// <summary>Invalid opcode.</summary>
|
||||
InvalidOpCode = 0x80,
|
||||
|
||||
/// <summary>Too few arguments.</summary>
|
||||
TooFewArguments = 0x81,
|
||||
|
||||
/// <summary>Stack overflow.</summary>
|
||||
StackOverflow = 0x82,
|
||||
|
||||
/// <summary>Code overflow.</summary>
|
||||
CodeOverflow = 0x83,
|
||||
|
||||
/// <summary>Bad argument.</summary>
|
||||
BadArgument = 0x84,
|
||||
|
||||
/// <summary>Division by zero.</summary>
|
||||
DivideByZero = 0x85,
|
||||
|
||||
/// <summary>Invalid reference.</summary>
|
||||
InvalidReference = 0x86,
|
||||
|
||||
/// <summary>Found debug opcode.</summary>
|
||||
DebugOpCode = 0x87,
|
||||
|
||||
/// <summary>Found ENDF opcode in execution stream.</summary>
|
||||
EndfInExecStream = 0x88,
|
||||
|
||||
/// <summary>Nested DEFS.</summary>
|
||||
NestedDefs = 0x89,
|
||||
|
||||
/// <summary>Invalid code range.</summary>
|
||||
InvalidCodeRange = 0x8A,
|
||||
|
||||
/// <summary>Execution context too long.</summary>
|
||||
ExecutionTooLong = 0x8B,
|
||||
|
||||
/// <summary>Too many function definitions.</summary>
|
||||
TooManyFunctionDefs = 0x8C,
|
||||
|
||||
/// <summary>Too many instruction definitions.</summary>
|
||||
TooManyInstructionDefs = 0x8D,
|
||||
|
||||
/// <summary>SFNT font table missing.</summary>
|
||||
TableMissing = 0x8E,
|
||||
|
||||
/// <summary>Horizontal header (hhea) table missing.</summary>
|
||||
HorizHeaderMissing = 0x8F,
|
||||
|
||||
/// <summary>Locations (loca) table missing.</summary>
|
||||
LocationsMissing = 0x90,
|
||||
|
||||
/// <summary>Name table missing.</summary>
|
||||
NameTableMissing = 0x91,
|
||||
|
||||
/// <summary>Character map (cmap) table missing.</summary>
|
||||
CMapTableMissing = 0x92,
|
||||
|
||||
/// <summary>Horizontal metrics (hmtx) table missing.</summary>
|
||||
HmtxTableMissing = 0x93,
|
||||
|
||||
/// <summary>PostScript (post) table missing.</summary>
|
||||
PostTableMissing = 0x94,
|
||||
|
||||
/// <summary>Invalid horizontal metrics.</summary>
|
||||
InvalidHorizMetrics = 0x95,
|
||||
|
||||
/// <summary>Invalid character map (cmap) format.</summary>
|
||||
InvalidCharMapFormat = 0x96,
|
||||
|
||||
/// <summary>Invalid ppem value.</summary>
|
||||
InvalidPPem = 0x97,
|
||||
|
||||
/// <summary>Invalid vertical metrics.</summary>
|
||||
InvalidVertMetrics = 0x98,
|
||||
|
||||
/// <summary>Could not find context.</summary>
|
||||
CouldNotFindContext = 0x99,
|
||||
|
||||
/// <summary>Invalid PostScript (post) table format.</summary>
|
||||
InvalidPostTableFormat = 0x9A,
|
||||
|
||||
/// <summary>Invalid PostScript (post) table.</summary>
|
||||
InvalidPostTable = 0x9B,
|
||||
|
||||
/// <summary>Opcode syntax error.</summary>
|
||||
SyntaxError = 0xA0,
|
||||
|
||||
/// <summary>Argument stack underflow.</summary>
|
||||
StackUnderflow = 0xA1,
|
||||
|
||||
/// <summary>Ignore this error.</summary>
|
||||
Ignore = 0xA2,
|
||||
|
||||
/// <summary>No Unicode glyph name found.</summary>
|
||||
NoUnicodeGlyphName = 0xA3,
|
||||
|
||||
/// <summary>`STARTFONT' field missing.</summary>
|
||||
MissingStartfontField = 0xB0,
|
||||
|
||||
/// <summary>`FONT' field missing.</summary>
|
||||
MissingFontField = 0xB1,
|
||||
|
||||
/// <summary>`SIZE' field missing.</summary>
|
||||
MissingSizeField = 0xB2,
|
||||
|
||||
/// <summary>`FONTBOUNDINGBOX' field missing.</summary>
|
||||
MissingFontboudingboxField = 0xB3,
|
||||
|
||||
/// <summary>`CHARS' field missing.</summary>
|
||||
MissingCharsField = 0xB4,
|
||||
|
||||
/// <summary>`STARTCHAR' field missing.</summary>
|
||||
MissingStartcharField = 0xB5,
|
||||
|
||||
/// <summary>`ENCODING' field missing.</summary>
|
||||
MissingEncodingField = 0xB6,
|
||||
|
||||
/// <summary>`BBX' field missing.</summary>
|
||||
MissingBbxField = 0xB7,
|
||||
|
||||
/// <summary>`BBX' too big.</summary>
|
||||
BbxTooBig = 0xB8,
|
||||
|
||||
/// <summary>Font header corrupted or missing fields.</summary>
|
||||
CorruptedFontHeader = 0xB9,
|
||||
|
||||
/// <summary>Font glyphs corrupted or missing fields.</summary>
|
||||
CorruptedFontGlyphs = 0xBA
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,770 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Cache;
|
||||
using SharpFont.Internal;
|
||||
using SharpFont.PostScript;
|
||||
using SharpFont.TrueType;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <content>
|
||||
/// This file contains all the raw FreeType2 function signatures.
|
||||
/// </content>
|
||||
public static partial class FT
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the location of the FreeType DLL. Update SharpFont.dll.config if you change this!
|
||||
/// </summary>
|
||||
#if SHARPFONT_PLATFORM_IOS
|
||||
private const string FreetypeDll = "__Internal";
|
||||
#else
|
||||
private const string FreetypeDll = "freetype6";
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Defines the calling convention for P/Invoking the native freetype methods.
|
||||
/// </summary>
|
||||
private const CallingConvention CallConvention = CallingConvention.Cdecl;
|
||||
|
||||
#region Core API
|
||||
|
||||
#region FreeType Version
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Library_Version(IntPtr library, out int amajor, out int aminor, out int apatch);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
internal static extern bool FT_Face_CheckTrueTypePatents(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
internal static extern bool FT_Face_SetUnpatentedHinting(IntPtr face, [MarshalAs(UnmanagedType.U1)] bool value);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base Interface
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Init_FreeType(out IntPtr alibrary);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Done_FreeType(IntPtr library);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_New_Face(IntPtr library, string filepathname, int face_index, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Memory_Face(IntPtr library, IntPtr file_base, int file_size, int face_index, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Open_Face(IntPtr library, IntPtr args, int face_index, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Attach_File(IntPtr face, string filepathname);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Attach_Stream(IntPtr face, IntPtr parameters);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Reference_Face(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Done_Face(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Select_Size(IntPtr face, int strike_index);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Request_Size(IntPtr face, IntPtr req);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Char_Size(IntPtr face, IntPtr char_width, IntPtr char_height, uint horz_resolution, uint vert_resolution);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Pixel_Sizes(IntPtr face, uint pixel_width, uint pixel_height);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Load_Glyph(IntPtr face, uint glyph_index, int load_flags);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Load_Char(IntPtr face, uint char_code, int load_flags);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Set_Transform(IntPtr face, IntPtr matrix, IntPtr delta);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Render_Glyph(IntPtr slot, RenderMode render_mode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Kerning(IntPtr face, uint left_glyph, uint right_glyph, uint kern_mode, out FTVector26Dot6 akerning);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Track_Kerning(IntPtr face, IntPtr point_size, int degree, out IntPtr akerning);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Glyph_Name(IntPtr face, uint glyph_index, IntPtr buffer, uint buffer_max);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Get_Postscript_Name(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Select_Charmap(IntPtr face, Encoding encoding);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Charmap(IntPtr face, IntPtr charmap);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern int FT_Get_Charmap_Index(IntPtr charmap);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_Char_Index(IntPtr face, uint charcode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_First_Char(IntPtr face, out uint agindex);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_Next_Char(IntPtr face, uint char_code, out uint agindex);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_Name_Index(IntPtr face, IntPtr glyph_name);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_SubGlyph_Info(IntPtr glyph, uint sub_index, out int p_index, out SubGlyphFlags p_flags, out int p_arg1, out int p_arg2, out FTMatrix p_transform);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern EmbeddingTypes FT_Get_FSType_Flags(IntPtr face);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Glyph Variants
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Face_GetCharVariantIndex(IntPtr face, uint charcode, uint variantSelector);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern int FT_Face_GetCharVariantIsDefault(IntPtr face, uint charcode, uint variantSelector);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Face_GetVariantSelectors(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Face_GetVariantsOfChar(IntPtr face, uint charcode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Face_GetCharsOfVariant(IntPtr face, uint variantSelector);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Glyph Management
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Glyph(IntPtr slot, out IntPtr aglyph);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Glyph_Copy(IntPtr source, out IntPtr target);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Glyph_Transform(IntPtr glyph, ref FTMatrix matrix, ref FTVector delta);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Glyph_Get_CBox(IntPtr glyph, GlyphBBoxMode bbox_mode, out BBox acbox);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Glyph_To_Bitmap(ref IntPtr the_glyph, RenderMode render_mode, ref FTVector26Dot6 origin, [MarshalAs(UnmanagedType.U1)] bool destroy);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Done_Glyph(IntPtr glyph);
|
||||
|
||||
#endregion
|
||||
|
||||
#if !SHARPFONT_PLATFORM_IOS
|
||||
#region Mac Specific Interface
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Face_From_FOND(IntPtr library, IntPtr fond, int face_index, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_GetFile_From_Mac_Name(string fontName, out IntPtr pathSpec, out int face_index);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_GetFile_From_Mac_ATS_Name(string fontName, out IntPtr pathSpec, out int face_index);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_GetFilePath_From_Mac_ATS_Name(string fontName, IntPtr path, int maxPathSize, out int face_index);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Face_From_FSSpec(IntPtr library, IntPtr spec, int face_index, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Face_From_FSRef(IntPtr library, IntPtr @ref, int face_index, out IntPtr aface);
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
#region Size Management
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Size(IntPtr face, out IntPtr size);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Done_Size(IntPtr size);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Activate_Size(IntPtr size);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Format-Specific API
|
||||
|
||||
#region Multiple Masters
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Multi_Master(IntPtr face, out IntPtr amaster);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_MM_Var(IntPtr face, out IntPtr amaster);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_MM_Design_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Var_Design_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_MM_Blend_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Var_Blend_Coordinates(IntPtr face, uint num_coords, IntPtr coords);
|
||||
|
||||
#endregion
|
||||
|
||||
#region TrueType Tables
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Get_Sfnt_Table(IntPtr face, SfntTag tag);
|
||||
|
||||
//TODO find FT_TRUETYPE_TAGS_H and create an enum for "tag"
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Load_Sfnt_Table(IntPtr face, uint tag, int offset, IntPtr buffer, ref uint length);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static unsafe extern Error FT_Sfnt_Table_Info(IntPtr face, uint table_index, SfntTag* tag, out uint length);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_CMap_Language_ID(IntPtr charmap);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern int FT_Get_CMap_Format(IntPtr charmap);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Type 1 Tables
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
internal static extern bool FT_Has_PS_Glyph_Names(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_PS_Font_Info(IntPtr face, out PostScript.Internal.FontInfoRec afont_info);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_PS_Font_Private(IntPtr face, out PostScript.Internal.PrivateRec afont_private);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern int FT_Get_PS_Font_Value(IntPtr face, DictionaryKeys key, uint idx, ref IntPtr value, int value_len);
|
||||
|
||||
#endregion
|
||||
|
||||
#region SFNT Names
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FT_Get_Sfnt_Name_Count(IntPtr face);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Sfnt_Name(IntPtr face, uint idx, out TrueType.Internal.SfntNameRec aname);
|
||||
|
||||
#endregion
|
||||
|
||||
#region BDF and PCF Files
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Get_BDF_Charset_ID(IntPtr face, out string acharset_encoding, out string acharset_registry);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Get_BDF_Property(IntPtr face, string prop_name, out IntPtr aproperty);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CID Fonts
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Get_CID_Registry_Ordering_Supplement(IntPtr face, out string registry, out string ordering, out int aproperty);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_CID_Is_Internally_CID_Keyed(IntPtr face, out byte is_cid);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_CID_From_Glyph_Index(IntPtr face, uint glyph_index, out uint cid);
|
||||
|
||||
#endregion
|
||||
|
||||
#region PFR Fonts
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_PFR_Metrics(IntPtr face, out uint aoutline_resolution, out uint ametrics_resolution, out IntPtr ametrics_x_scale, out IntPtr ametrics_y_scale);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_PFR_Kerning(IntPtr face, uint left, uint right, out FTVector avector);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_PFR_Advance(IntPtr face, uint gindex, out int aadvance);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Window FNT Files
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_WinFNT_Header(IntPtr face, out IntPtr aheader);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Font Formats
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Get_X11_Font_Format(IntPtr face);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Gasp Table
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Gasp FT_Get_Gasp(IntPtr face, uint ppem);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Support API
|
||||
|
||||
#region Computations
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_MulDiv(IntPtr a, IntPtr b, IntPtr c);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_MulFix(IntPtr a, IntPtr b);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_DivFix(IntPtr a, IntPtr b);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_RoundFix(IntPtr a);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_CeilFix(IntPtr a);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_FloorFix(IntPtr a);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Vector_Transform(ref FTVector vec, ref FTMatrix matrix);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Matrix_Multiply(ref FTMatrix a, ref FTMatrix b);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Matrix_Invert(ref FTMatrix matrix);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Sin(IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Cos(IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Tan(IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Atan2(IntPtr x, IntPtr y);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Angle_Diff(IntPtr angle1, IntPtr angle2);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Vector_Unit(out FTVector vec, IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Vector_Rotate(ref FTVector vec, IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Vector_Length(ref FTVector vec);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Vector_Polarize(ref FTVector vec, out IntPtr length, out IntPtr angle);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Vector_From_Polar(out FTVector vec, IntPtr length, IntPtr angle);
|
||||
|
||||
#endregion
|
||||
|
||||
#region List Processing
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_List_Find(IntPtr list, IntPtr data);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_List_Add(IntPtr list, IntPtr node);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_List_Insert(IntPtr list, IntPtr node);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_List_Remove(IntPtr list, IntPtr node);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_List_Up(IntPtr list, IntPtr node);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_List_Iterate(IntPtr list, ListIterator iterator, IntPtr user);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_List_Finalize(IntPtr list, ListDestructor destroy, IntPtr memory, IntPtr user);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Outline Processing
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_New(IntPtr library, uint numPoints, int numContours, out IntPtr anoutline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_New_Internal(IntPtr memory, uint numPoints, int numContours, out IntPtr anoutline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Done(IntPtr library, IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Done_Internal(IntPtr memory, IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Copy(IntPtr source, ref IntPtr target);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Outline_Translate(IntPtr outline, int xOffset, int yOffset);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Outline_Transform(IntPtr outline, ref FTMatrix matrix);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Embolden(IntPtr outline, IntPtr strength);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_EmboldenXY(IntPtr outline, int xstrength, int ystrength);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Outline_Reverse(IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Check(IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Get_BBox(IntPtr outline, out BBox abbox);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Decompose(IntPtr outline, ref OutlineFuncsRec func_interface, IntPtr user);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Outline_Get_CBox(IntPtr outline, out BBox acbox);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Get_Bitmap(IntPtr library, IntPtr outline, IntPtr abitmap);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Outline_Render(IntPtr library, IntPtr outline, IntPtr @params);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Orientation FT_Outline_Get_Orientation(IntPtr outline);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quick retrieval of advance values
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Advance(IntPtr face, uint gIndex, LoadFlags load_flags, out IntPtr padvance);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Get_Advances(IntPtr face, uint start, uint count, LoadFlags load_flags, out IntPtr padvance);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bitmap Handling
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Bitmap_New(IntPtr abitmap);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Bitmap_Copy(IntPtr library, IntPtr source, IntPtr target);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Bitmap_Embolden(IntPtr library, IntPtr bitmap, IntPtr xStrength, IntPtr yStrength);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Bitmap_Convert(IntPtr library, IntPtr source, IntPtr target, int alignment);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_GlyphSlot_Own_Bitmap(IntPtr slot);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Bitmap_Done(IntPtr library, IntPtr bitmap);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Glyph Stroker
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern StrokerBorder FT_Outline_GetInsideBorder(IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern StrokerBorder FT_Outline_GetOutsideBorder(IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_New(IntPtr library, out IntPtr astroker);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Stroker_Set(IntPtr stroker, int radius, StrokerLineCap line_cap, StrokerLineJoin line_join, IntPtr miter_limit);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Stroker_Rewind(IntPtr stroker);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_ParseOutline(IntPtr stroker, IntPtr outline, [MarshalAs(UnmanagedType.U1)] bool opened);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_BeginSubPath(IntPtr stroker, ref FTVector to, [MarshalAs(UnmanagedType.U1)] bool open);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_EndSubPath(IntPtr stroker);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_LineTo(IntPtr stroker, ref FTVector to);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_ConicTo(IntPtr stroker, ref FTVector control, ref FTVector to);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_CubicTo(IntPtr stroker, ref FTVector control1, ref FTVector control2, ref FTVector to);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_GetBorderCounts(IntPtr stroker, StrokerBorder border, out uint anum_points, out uint anum_contours);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Stroker_ExportBorder(IntPtr stroker, StrokerBorder border, IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stroker_GetCounts(IntPtr stroker, out uint anum_points, out uint anum_contours);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Stroker_Export(IntPtr stroker, IntPtr outline);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Stroker_Done(IntPtr stroker);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Glyph_Stroke(ref IntPtr pglyph, IntPtr stoker, [MarshalAs(UnmanagedType.U1)] bool destroy);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Glyph_StrokeBorder(ref IntPtr pglyph, IntPtr stoker, [MarshalAs(UnmanagedType.U1)] bool inside, [MarshalAs(UnmanagedType.U1)] bool destroy);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Module Management
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Add_Module(IntPtr library, IntPtr clazz);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern IntPtr FT_Get_Module(IntPtr library, string module_name);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Remove_Module(IntPtr library, IntPtr module);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Property_Set(IntPtr library, string module_name, string property_name, IntPtr value);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
|
||||
internal static extern Error FT_Property_Get(IntPtr library, string module_name, string property_name, IntPtr value);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Reference_Library(IntPtr library);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_New_Library(IntPtr memory, out IntPtr alibrary);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Done_Library(IntPtr library);
|
||||
|
||||
//TODO figure out the method signature for debug_hook. (FT_DebugHook_Func)
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Set_Debug_Hook(IntPtr library, uint hook_index, IntPtr debug_hook);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_Add_Default_Modules(IntPtr library);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern IntPtr FT_Get_Renderer(IntPtr library, GlyphFormat format);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Set_Renderer(IntPtr library, IntPtr renderer, uint num_params, IntPtr parameters);
|
||||
|
||||
#endregion
|
||||
|
||||
#region GZIP Streams
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stream_OpenGzip(IntPtr stream, IntPtr source);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Gzip_Uncompress(IntPtr memory, IntPtr output, ref IntPtr output_len, IntPtr input, IntPtr input_len);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LZW Streams
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stream_OpenLZW(IntPtr stream, IntPtr source);
|
||||
|
||||
#endregion
|
||||
|
||||
#region BZIP2 Streams
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Stream_OpenBzip2(IntPtr stream, IntPtr source);
|
||||
|
||||
#endregion
|
||||
|
||||
#region LCD Filtering
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Library_SetLcdFilter(IntPtr library, LcdFilter filter);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_Library_SetLcdFilterWeights(IntPtr library, byte[] weights);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Caching Sub-system
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_Manager_New(IntPtr library, uint max_faces, uint max_sizes, ulong maxBytes, FaceRequester requester, IntPtr req_data, out IntPtr amanager);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FTC_Manager_Reset(IntPtr manager);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FTC_Manager_Done(IntPtr manager);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_Manager_LookupFace(IntPtr manager, IntPtr face_id, out IntPtr aface);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_Manager_LookupSize(IntPtr manager, IntPtr scaler, out IntPtr asize);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FTC_Node_Unref(IntPtr node, IntPtr manager);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FTC_Manager_RemoveFaceID(IntPtr manager, IntPtr face_id);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_CMapCache_New(IntPtr manager, out IntPtr acache);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern uint FTC_CMapCache_Lookup(IntPtr cache, IntPtr face_id, int cmap_index, uint char_code);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_ImageCache_New(IntPtr manager, out IntPtr acache);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_ImageCache_Lookup(IntPtr cache, IntPtr type, uint gindex, out IntPtr aglyph, out IntPtr anode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_ImageCache_LookupScaler(IntPtr cache, IntPtr scaler, LoadFlags load_flags, uint gindex, out IntPtr aglyph, out IntPtr anode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_SBitCache_New(IntPtr manager, out IntPtr acache);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_SBitCache_Lookup(IntPtr cache, IntPtr type, uint gindex, out IntPtr sbit, out IntPtr anode);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FTC_SBitCache_LookupScaler(IntPtr cache, IntPtr scaler, LoadFlags load_flags, uint gindex, out IntPtr sbit, out IntPtr anode);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Miscellaneous
|
||||
|
||||
#region OpenType Validation
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_OpenType_Validate(IntPtr face, OpenTypeValidationFlags validation_flags, out IntPtr base_table, out IntPtr gdef_table, out IntPtr gpos_table, out IntPtr gsub_table, out IntPtr jsft_table);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern void FT_OpenType_Free(IntPtr face, IntPtr table);
|
||||
|
||||
#endregion
|
||||
|
||||
#region The TrueType Engine
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern EngineType FT_Get_TrueType_Engine_Type(IntPtr library);
|
||||
|
||||
#endregion
|
||||
|
||||
#region TrueTypeGX/AAT Validation
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_TrueTypeGX_Validate(IntPtr face, TrueTypeValidationFlags validation_flags, byte[][] tables, uint tableLength);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_TrueTypeGX_Free(IntPtr face, IntPtr table);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_ClassicKern_Validate(IntPtr face, ClassicKernValidationFlags validation_flags, out IntPtr ckern_table);
|
||||
|
||||
[DllImport(FreetypeDll, CallingConvention = CallConvention)]
|
||||
internal static extern Error FT_ClassicKern_Free(IntPtr face, IntPtr table);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Miscellaneous FreeType2 functions that don't fit anywhere else.
|
||||
/// </summary>
|
||||
public static partial class FT
|
||||
{
|
||||
#region Computations
|
||||
|
||||
/// <summary><para>
|
||||
/// A very simple function used to perform the computation ‘(a*b)/c’ with maximal accuracy (it uses a 64-bit
|
||||
/// intermediate integer whenever necessary).
|
||||
/// </para><para>
|
||||
/// This function isn't necessarily as fast as some processor specific operations, but is at least completely
|
||||
/// portable.
|
||||
/// </para></summary>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier.</param>
|
||||
/// <param name="c">The divisor.</param>
|
||||
/// <returns>
|
||||
/// The result of ‘(a*b)/c’. This function never traps when trying to divide by zero; it simply returns
|
||||
/// ‘MaxInt’ or ‘MinInt’ depending on the signs of ‘a’ and ‘b’.
|
||||
/// </returns>
|
||||
[Obsolete("Use Fixed16Dot16.MultiplyDivide() instead.")]
|
||||
public static Fixed16Dot16 MulDiv(Fixed16Dot16 a, Fixed16Dot16 b, Fixed16Dot16 c)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_MulDiv((IntPtr)a.Value, (IntPtr)b.Value, (IntPtr)c.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to perform the computation ‘(a*b)/0x10000’ with maximal accuracy. Most of the
|
||||
/// time this is used to multiply a given value by a 16.16 fixed float factor.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// This function has been optimized for the case where the absolute value of ‘a’ is less than 2048, and ‘b’ is
|
||||
/// a 16.16 scaling factor. As this happens mainly when scaling from notional units to fractional pixels in
|
||||
/// FreeType, it resulted in noticeable speed improvements between versions 2.x and 1.x.
|
||||
/// </para><para>
|
||||
/// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make
|
||||
/// a great difference.
|
||||
/// </para></remarks>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
|
||||
/// <returns>The result of ‘(a*b)/0x10000’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.MultiplyFix() instead.")]
|
||||
public static Fixed16Dot16 MulFix(int a, Fixed16Dot16 b)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_MulFix((IntPtr)a, (IntPtr)b.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to perform the computation ‘(a*0x10000)/b’ with maximal accuracy. Most of the
|
||||
/// time, this is used to divide a given value by a 16.16 fixed float factor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The optimization for <see cref="DivFix"/> is simple: If (a << 16) fits in 32 bits, then the division
|
||||
/// is computed directly. Otherwise, we use a specialized version of <see cref="MulDiv"/>.
|
||||
/// </remarks>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
|
||||
/// <returns>The result of ‘(a*0x10000)/b’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.DivideFix() instead.")]
|
||||
public static Fixed16Dot16 DivFix(int a, Fixed16Dot16 b)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_DivFix((IntPtr)a, (IntPtr)b.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to round a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <param name="a">The number to be rounded.</param>
|
||||
/// <returns>The result of ‘(a + 0x8000) & -0x10000’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.RoundFix() instead.")]
|
||||
public static Fixed16Dot16 RoundFix(Fixed16Dot16 a)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_RoundFix((IntPtr)a.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to compute the ceiling function of a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <param name="a">The number for which the ceiling function is to be computed.</param>
|
||||
/// <returns>The result of ‘(a + 0x10000 - 1) & -0x10000’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.CeilingFix() instead.")]
|
||||
public static Fixed16Dot16 CeilFix(Fixed16Dot16 a)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_CeilFix((IntPtr)a.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to compute the floor function of a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <param name="a">The number for which the floor function is to be computed.</param>
|
||||
/// <returns>The result of ‘a & -0x10000’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.FloorFix() instead.")]
|
||||
public static Fixed16Dot16 FloorFix(Fixed16Dot16 a)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_FloorFix((IntPtr)a.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sinus of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
|
||||
/// </remarks>
|
||||
/// <param name="angle">The input angle.</param>
|
||||
/// <returns>The sinus value.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.Sin() instead.")]
|
||||
public static Fixed16Dot16 Sin(Fixed16Dot16 angle)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)angle.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the cosinus of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
|
||||
/// </remarks>
|
||||
/// <param name="angle">The input angle.</param>
|
||||
/// <returns>The cosinus value.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.Cos() instead.")]
|
||||
public static Fixed16Dot16 Cos(Fixed16Dot16 angle)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)angle.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the tangent of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <param name="angle">The input angle.</param>
|
||||
/// <returns>The tangent value.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.Tan() instead.")]
|
||||
public static Fixed16Dot16 Tan(Fixed16Dot16 angle)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)angle.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal vector coordinate.</param>
|
||||
/// <param name="y">The vertical vector coordinate.</param>
|
||||
/// <returns>The arc-tangent value (i.e. angle).</returns>
|
||||
[Obsolete("Use Fixed16Dot16.Atan2() instead.")]
|
||||
public static Fixed16Dot16 Atan2(Fixed16Dot16 x, Fixed16Dot16 y)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Atan2((IntPtr)x.Value, (IntPtr)y.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval.
|
||||
/// </summary>
|
||||
/// <param name="angle1">First angle.</param>
|
||||
/// <param name="angle2">Second angle.</param>
|
||||
/// <returns>Constrained value of ‘value2-value1’.</returns>
|
||||
[Obsolete("Use Fixed16Dot16.AngleDiff() instead.")]
|
||||
public static Fixed16Dot16 AngleDiff(Fixed16Dot16 angle1, Fixed16Dot16 angle2)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Angle_Diff((IntPtr)angle1.Value, (IntPtr)angle2.Value));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if !SHARPFONT_PLATFORM_IOS
|
||||
#region Mac Specific Interface
|
||||
|
||||
/// <summary>
|
||||
/// Return an FSSpec for the disk file containing the named font.
|
||||
/// </summary>
|
||||
/// <param name="fontName">Mac OS name of the font (e.g., Times New Roman Bold).</param>
|
||||
/// <param name="faceIndex">Index of the face. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</param>
|
||||
/// <returns>FSSpec to the file. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</returns>
|
||||
public static IntPtr GetFileFromMacName(string fontName, out int faceIndex)
|
||||
{
|
||||
IntPtr fsspec;
|
||||
|
||||
Error err = FT_GetFile_From_Mac_Name(fontName, out fsspec, out faceIndex);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return fsspec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return an FSSpec for the disk file containing the named font.
|
||||
/// </summary>
|
||||
/// <param name="fontName">Mac OS name of the font in ATS framework.</param>
|
||||
/// <param name="faceIndex">Index of the face. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</param>
|
||||
/// <returns>FSSpec to the file. For passing to <see cref="Library.NewFaceFromFSSpec"/>.</returns>
|
||||
public static IntPtr GetFileFromMacAtsName(string fontName, out int faceIndex)
|
||||
{
|
||||
IntPtr fsspec;
|
||||
|
||||
Error err = FT_GetFile_From_Mac_ATS_Name(fontName, out fsspec, out faceIndex);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return fsspec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a pathname of the disk file and face index for given font name which is handled by ATS framework.
|
||||
/// </summary>
|
||||
/// <param name="fontName">Mac OS name of the font in ATS framework.</param>
|
||||
/// <param name="path">
|
||||
/// Buffer to store pathname of the file. For passing to <see cref="Library.NewFace"/>. The client must
|
||||
/// allocate this buffer before calling this function.
|
||||
/// </param>
|
||||
/// <returns>Index of the face. For passing to <see cref="Library.NewFace"/>.</returns>
|
||||
public static unsafe int GetFilePathFromMacAtsName(string fontName, byte[] path)
|
||||
{
|
||||
int faceIndex;
|
||||
|
||||
fixed (void* ptr = path)
|
||||
{
|
||||
Error err = FT_GetFilePath_From_Mac_ATS_Name(fontName, (IntPtr)ptr, path.Length, out faceIndex);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
return faceIndex;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
#if !SHARPFONT_PORTABLE
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
#endif
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to describe a bitmap or pixmap to the raster. Note that we now manage pixmaps of various
|
||||
/// depths through the <see cref="PixelMode"/> field.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For now, the only pixel modes supported by FreeType are mono and grays. However, drivers might be added in the
|
||||
/// future to support more ‘colorful’ options.
|
||||
/// </remarks>
|
||||
public sealed class FTBitmap : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private BitmapRec rec;
|
||||
|
||||
private Library library;
|
||||
|
||||
private bool disposed;
|
||||
|
||||
//If the bitmap was generated with FT_Bitmap_New.
|
||||
private bool user;
|
||||
|
||||
//HACK these variables exist to reduce the cost of reflection at runtime.
|
||||
//Meant to be a temporary fix to https://github.com/Robmaister/SharpFont/issues/62
|
||||
//until libgdiplus gets patched.
|
||||
#if !SHARPFONT_PORTABLE
|
||||
private bool hasCheckedForMono;
|
||||
private bool isRunningOnMono;
|
||||
private System.Reflection.FieldInfo monoPaletteFlagsField;
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTBitmap"/> class.
|
||||
/// </summary>
|
||||
/// <param name="library">The parent <see cref="Library"/>.</param>
|
||||
public FTBitmap(Library library)
|
||||
{
|
||||
IntPtr bitmapRef = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BitmapRec)));
|
||||
FT.FT_Bitmap_New(bitmapRef);
|
||||
Reference = bitmapRef;
|
||||
|
||||
this.library = library;
|
||||
this.user = true;
|
||||
}
|
||||
|
||||
internal FTBitmap(IntPtr reference, Library library)
|
||||
{
|
||||
Reference = reference;
|
||||
this.library = library;
|
||||
}
|
||||
|
||||
internal FTBitmap(IntPtr reference, BitmapRec bmpInt, Library library)
|
||||
{
|
||||
this.reference = reference;
|
||||
this.rec = bmpInt;
|
||||
this.library = library;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="FTBitmap"/> class.
|
||||
/// </summary>
|
||||
~FTBitmap()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the <see cref="FTBitmap"/> has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return disposed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bitmap rows.
|
||||
/// </summary>
|
||||
public int Rows
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.rows;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of pixels in bitmap row.
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary><para>
|
||||
/// Gets the pitch's absolute value is the number of bytes taken by one bitmap row, including padding. However,
|
||||
/// the pitch is positive when the bitmap has a ‘down’ flow, and negative when it has an ‘up’ flow. In all
|
||||
/// cases, the pitch is an offset to add to a bitmap pointer in order to go down one row.
|
||||
/// </para><para>
|
||||
/// Note that ‘padding’ means the alignment of a bitmap to a byte border, and FreeType functions normally align
|
||||
/// to the smallest possible integer value.
|
||||
/// </para><para>
|
||||
/// For the B/W rasterizer, ‘pitch’ is always an even number.
|
||||
/// </para><para>
|
||||
/// To change the pitch of a bitmap (say, to make it a multiple of 4), use <see cref="FTBitmap.Convert"/>.
|
||||
/// Alternatively, you might use callback functions to directly render to the application's surface; see the
|
||||
/// file ‘example2.cpp’ in the tutorial for a demonstration.
|
||||
/// </para></summary>
|
||||
public int Pitch
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a typeless pointer to the bitmap buffer. This value should be aligned on 32-bit boundaries in most
|
||||
/// cases.
|
||||
/// </summary>
|
||||
public IntPtr Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of gray levels used in the bitmap. This field is only used with
|
||||
/// <see cref="SharpFont.PixelMode.Gray"/>.
|
||||
/// </summary>
|
||||
public short GrayLevels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.num_grays;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the pixel mode, i.e., how pixel bits are stored.
|
||||
/// </summary>
|
||||
public PixelMode PixelMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.pixel_mode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets how the palette is stored. This field is intended for paletted pixel modes.
|
||||
/// </summary>
|
||||
[Obsolete("Not used currently.")]
|
||||
public byte PaletteMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.palette_mode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a typeless pointer to the bitmap palette; this field is intended for paletted pixel modes.
|
||||
/// </summary>
|
||||
[Obsolete("Not used currently.")]
|
||||
public IntPtr Palette
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return rec.palette;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="FTBitmap"/>'s buffer as a byte array.
|
||||
/// </summary>
|
||||
public byte[] BufferData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
//TODO deal with negative pitch
|
||||
byte[] data = new byte[rec.rows * rec.pitch];
|
||||
Marshal.Copy(rec.buffer, data, 0, data.Length);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<BitmapRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Copy a bitmap into another one.
|
||||
/// </summary>
|
||||
/// <param name="library">A handle to a library object.</param>
|
||||
/// <returns>A handle to the target bitmap.</returns>
|
||||
public FTBitmap Copy(Library library)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
if (library == null)
|
||||
throw new ArgumentNullException("library");
|
||||
|
||||
FTBitmap newBitmap = new FTBitmap(library);
|
||||
IntPtr bmpRef = newBitmap.reference;
|
||||
Error err = FT.FT_Bitmap_Copy(library.Reference, Reference, bmpRef);
|
||||
newBitmap.Reference = bmpRef;
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return newBitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Embolden a bitmap. The new bitmap will be about ‘xStrength’ pixels wider and ‘yStrength’ pixels higher. The
|
||||
/// left and bottom borders are kept unchanged.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The current implementation restricts ‘xStrength’ to be less than or equal to 8 if bitmap is of pixel_mode
|
||||
/// <see cref="SharpFont.PixelMode.Mono"/>.
|
||||
/// </para><para>
|
||||
/// If you want to embolden the bitmap owned by a <see cref="GlyphSlot"/>, you should call
|
||||
/// <see cref="GlyphSlot.OwnBitmap"/> on the slot first.
|
||||
/// </para></remarks>
|
||||
/// <param name="library">A handle to a library object.</param>
|
||||
/// <param name="xStrength">
|
||||
/// How strong the glyph is emboldened horizontally. Expressed in 26.6 pixel format.
|
||||
/// </param>
|
||||
/// <param name="yStrength">
|
||||
/// How strong the glyph is emboldened vertically. Expressed in 26.6 pixel format.
|
||||
/// </param>
|
||||
public void Embolden(Library library, Fixed26Dot6 xStrength, Fixed26Dot6 yStrength)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
if (library == null)
|
||||
throw new ArgumentNullException("library");
|
||||
|
||||
Error err = FT.FT_Bitmap_Embolden(library.Reference, Reference, (IntPtr)xStrength.Value, (IntPtr)yStrength.Value);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a bitmap object with depth 1bpp, 2bpp, 4bpp, or 8bpp to a bitmap object with depth 8bpp, making the
|
||||
/// number of used bytes per line (a.k.a. the ‘pitch’) a multiple of ‘alignment’.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// It is possible to call <see cref="Convert"/> multiple times without calling
|
||||
/// <see cref="Dispose()"/> (the memory is simply reallocated).
|
||||
/// </para><para>
|
||||
/// Use <see cref="Dispose()"/> to finally remove the bitmap object.
|
||||
/// </para><para>
|
||||
/// The ‘library’ argument is taken to have access to FreeType's memory handling functions.
|
||||
/// </para></remarks>
|
||||
/// <param name="library">A handle to a library object.</param>
|
||||
/// <param name="alignment">
|
||||
/// The pitch of the bitmap is a multiple of this parameter. Common values are 1, 2, or 4.
|
||||
/// </param>
|
||||
/// <returns>The target bitmap.</returns>
|
||||
public FTBitmap Convert(Library library, int alignment)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
if (library == null)
|
||||
throw new ArgumentNullException("library");
|
||||
|
||||
FTBitmap newBitmap = new FTBitmap(library);
|
||||
IntPtr bmpRef = newBitmap.reference;
|
||||
Error err = FT.FT_Bitmap_Convert(library.Reference, Reference, bmpRef, alignment);
|
||||
newBitmap.Reference = bmpRef;
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return newBitmap;
|
||||
}
|
||||
|
||||
#if !SHARPFONT_PORTABLE
|
||||
/// <summary>
|
||||
/// Copies the contents of the <see cref="FTBitmap"/> to a GDI+ <see cref="Bitmap"/>.
|
||||
/// </summary>
|
||||
/// <returns>A GDI+ <see cref="Bitmap"/> containing this bitmap's data.</returns>
|
||||
public Bitmap ToGdipBitmap()
|
||||
{
|
||||
return ToGdipBitmap(Color.Black);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the contents of the <see cref="FTBitmap"/> to a GDI+ <see cref="Bitmap"/>.
|
||||
/// </summary>
|
||||
/// <param name="color">The color of the text.</param>
|
||||
/// <returns>A GDI+ <see cref="Bitmap"/> containing this bitmap's data with a transparent background.</returns>
|
||||
public Bitmap ToGdipBitmap(Color color)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("FTBitmap", "Cannot access a disposed object.");
|
||||
|
||||
if (rec.width == 0 || rec.rows == 0)
|
||||
throw new InvalidOperationException("Invalid image size - one or both dimensions are 0.");
|
||||
|
||||
//TODO deal with negative pitch
|
||||
switch (rec.pixel_mode)
|
||||
{
|
||||
case PixelMode.Mono:
|
||||
{
|
||||
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format1bppIndexed);
|
||||
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
|
||||
|
||||
for (int i = 0; i < rec.rows; i++)
|
||||
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
|
||||
|
||||
bmp.UnlockBits(locked);
|
||||
|
||||
ColorPalette palette = bmp.Palette;
|
||||
palette.Entries[0] = Color.FromArgb(0, color);
|
||||
palette.Entries[1] = Color.FromArgb(255, color);
|
||||
|
||||
bmp.Palette = palette;
|
||||
return bmp;
|
||||
}
|
||||
|
||||
case PixelMode.Gray4:
|
||||
{
|
||||
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format4bppIndexed);
|
||||
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format4bppIndexed);
|
||||
|
||||
for (int i = 0; i < rec.rows; i++)
|
||||
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
|
||||
|
||||
bmp.UnlockBits(locked);
|
||||
|
||||
ColorPalette palette = bmp.Palette;
|
||||
for (int i = 0; i < palette.Entries.Length; i++)
|
||||
{
|
||||
float a = (i * 17) / 255f;
|
||||
palette.Entries[i] = Color.FromArgb(i * 17, (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
|
||||
}
|
||||
|
||||
bmp.Palette = palette;
|
||||
return bmp;
|
||||
}
|
||||
|
||||
case PixelMode.Gray:
|
||||
{
|
||||
Bitmap bmp = new Bitmap(rec.width, rec.rows, PixelFormat.Format8bppIndexed);
|
||||
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
|
||||
|
||||
for (int i = 0; i < rec.rows; i++)
|
||||
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
|
||||
|
||||
bmp.UnlockBits(locked);
|
||||
|
||||
ColorPalette palette = bmp.Palette;
|
||||
for (int i = 0; i < palette.Entries.Length; i++)
|
||||
{
|
||||
float a = i / 255f;
|
||||
palette.Entries[i] = Color.FromArgb(i, (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
|
||||
}
|
||||
|
||||
//HACK There's a bug in Mono's libgdiplus requiring the "PaletteHasAlpha" flag to be set for transparency to work properly
|
||||
//See https://github.com/Robmaister/SharpFont/issues/62
|
||||
if (!hasCheckedForMono)
|
||||
{
|
||||
hasCheckedForMono = true;
|
||||
isRunningOnMono = Type.GetType("Mono.Runtime") != null;
|
||||
if (isRunningOnMono)
|
||||
{
|
||||
monoPaletteFlagsField = typeof(ColorPalette).GetField("flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
}
|
||||
}
|
||||
|
||||
if (isRunningOnMono)
|
||||
monoPaletteFlagsField.SetValue(palette, palette.Flags | 1);
|
||||
|
||||
bmp.Palette = palette;
|
||||
return bmp;
|
||||
}
|
||||
|
||||
case PixelMode.Lcd:
|
||||
{
|
||||
//TODO apply color
|
||||
int bmpWidth = rec.width / 3;
|
||||
Bitmap bmp = new Bitmap(bmpWidth, rec.rows, PixelFormat.Format24bppRgb);
|
||||
var locked = bmp.LockBits(new Rectangle(0, 0, bmpWidth, rec.rows), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
|
||||
|
||||
for (int i = 0; i < rec.rows; i++)
|
||||
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, locked.Stride);
|
||||
|
||||
bmp.UnlockBits(locked);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
/*case PixelMode.VerticalLcd:
|
||||
{
|
||||
int bmpHeight = rec.rows / 3;
|
||||
Bitmap bmp = new Bitmap(rec.width, bmpHeight, PixelFormat.Format24bppRgb);
|
||||
var locked = bmp.LockBits(new Rectangle(0, 0, rec.width, bmpHeight), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
|
||||
for (int i = 0; i < bmpHeight; i++)
|
||||
PInvokeHelper.Copy(Buffer, i * rec.pitch, locked.Scan0, i * locked.Stride, rec.width);
|
||||
bmp.UnlockBits(locked);
|
||||
|
||||
return bmp;
|
||||
}*/
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("System.Drawing.Bitmap does not support this pixel mode.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Disposes an instance of the <see cref="FTBitmap"/> class.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
if (user)
|
||||
{
|
||||
FT.FT_Bitmap_Done(library.Reference, reference);
|
||||
Marshal.FreeHGlobal(reference);
|
||||
}
|
||||
|
||||
reference = IntPtr.Zero;
|
||||
library = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="FTList"/> iterator function which is called during a list parse by <see cref="FTList.Iterate"/>.
|
||||
/// </summary>
|
||||
/// <param name="node">The current iteration list node.</param>
|
||||
/// <param name="user">
|
||||
/// A typeless pointer passed to <see cref="ListIterator"/>. Can be used to point to the iteration's state.
|
||||
/// </param>
|
||||
/// <returns>Error code.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate Error ListIterator(NativeReference<ListNode> node, IntPtr user);
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="FTList"/> iterator function which is called during a list finalization by
|
||||
/// <see cref="FTList.Finalize"/> to destroy all elements in a given list.
|
||||
/// </summary>
|
||||
/// <param name="memory">The current system object.</param>
|
||||
/// <param name="data">The current object to destroy.</param>
|
||||
/// <param name="user">
|
||||
/// A typeless pointer passed to <see cref="FTList.Iterate"/>. It can be used to point to the iteration's state.
|
||||
/// </param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ListDestructor(NativeReference<Memory> memory, IntPtr data, IntPtr user);
|
||||
|
||||
/// <summary>
|
||||
/// A structure used to hold a simple doubly-linked list. These are used in many parts of FreeType.
|
||||
/// </summary>
|
||||
public sealed class FTList
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private ListRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal FTList(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the head (first element) of doubly-linked list.
|
||||
/// </summary>
|
||||
public ListNode Head
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ListNode(rec.head);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tail (last element) of doubly-linked list.
|
||||
/// </summary>
|
||||
public ListNode Tail
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ListNode(rec.tail);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<ListRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Find the list node for a given listed object.
|
||||
/// </summary>
|
||||
/// <param name="data">The address of the listed object.</param>
|
||||
/// <returns>List node. NULL if it wasn't found.</returns>
|
||||
public ListNode Find(IntPtr data)
|
||||
{
|
||||
return new ListNode(FT.FT_List_Find(Reference, data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append an element to the end of a list.
|
||||
/// </summary>
|
||||
/// <param name="node">The node to append.</param>
|
||||
public void Add(ListNode node)
|
||||
{
|
||||
FT.FT_List_Add(Reference, node.Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert an element at the head of a list.
|
||||
/// </summary>
|
||||
/// <param name="node">The node to insert.</param>
|
||||
public void Insert(ListNode node)
|
||||
{
|
||||
FT.FT_List_Insert(Reference, node.Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a node from a list. This function doesn't check whether the node is in the list!
|
||||
/// </summary>
|
||||
/// <param name="node">The node to remove.</param>
|
||||
public void Remove(ListNode node)
|
||||
{
|
||||
FT.FT_List_Remove(Reference, node.Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move a node to the head/top of a list. Used to maintain LRU lists.
|
||||
/// </summary>
|
||||
/// <param name="node">The node to move.</param>
|
||||
public void Up(ListNode node)
|
||||
{
|
||||
FT.FT_List_Up(Reference, node.Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a list and calls a given iterator function on each element. Note that parsing is stopped as soon as
|
||||
/// one of the iterator calls returns a non-zero value.
|
||||
/// </summary>
|
||||
/// <param name="iterator">An iterator function, called on each node of the list.</param>
|
||||
/// <param name="user">A user-supplied field which is passed as the second argument to the iterator.</param>
|
||||
public void Iterate(ListIterator iterator, IntPtr user)
|
||||
{
|
||||
Error err = FT.FT_List_Iterate(Reference, iterator, user);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy all elements in the list as well as the list itself.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function expects that all nodes added by <see cref="Add"/> or <see cref="Insert"/> have been
|
||||
/// dynamically allocated.
|
||||
/// </remarks>
|
||||
/// <param name="destroy">A list destructor that will be applied to each element of the list.</param>
|
||||
/// <param name="memory">The current memory object which handles deallocation.</param>
|
||||
/// <param name="user">A user-supplied field which is passed as the last argument to the destructor.</param>
|
||||
public void Finalize(ListDestructor destroy, Memory memory, IntPtr user)
|
||||
{
|
||||
FT.FT_List_Finalize(Reference, destroy, memory.Reference, user);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple structure used to store a 2x2 matrix. Coefficients are in 16.16 fixed float format. The computation
|
||||
/// performed is:
|
||||
/// <code>
|
||||
/// x' = x*xx + y*xy
|
||||
/// y' = x*yx + y*yy
|
||||
/// </code>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct FTMatrix : IEquatable<FTMatrix>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr xx, xy;
|
||||
private IntPtr yx, yy;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTMatrix"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="xx">Matrix coefficient XX.</param>
|
||||
/// <param name="xy">Matrix coefficient XY.</param>
|
||||
/// <param name="yx">Matrix coefficient YX.</param>
|
||||
/// <param name="yy">Matrix coefficient YY.</param>
|
||||
public FTMatrix(int xx, int xy, int yx, int yy)
|
||||
: this()
|
||||
{
|
||||
this.xx = (IntPtr)xx;
|
||||
this.xy = (IntPtr)xy;
|
||||
this.yx = (IntPtr)yx;
|
||||
this.yy = (IntPtr)yy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTMatrix"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="row0">Matrix coefficients XX, XY.</param>
|
||||
/// <param name="row1">Matrix coefficients YX, YY.</param>
|
||||
public FTMatrix(FTVector row0, FTVector row1)
|
||||
: this(row0.X.Value, row0.Y.Value, row1.X.Value, row1.Y.Value)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matrix coefficient.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 XX
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)xx);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
xx = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matrix coefficient.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 XY
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)xy);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
xy = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matrix coefficient.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 YX
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)yx);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
yx = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matrix coefficient.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 YY
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)yy);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
yy = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTMatrix"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTMatrix"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTMatrix"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public static bool operator ==(FTMatrix left, FTMatrix right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTMatrix"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTMatrix"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTMatrix"/>.</param>
|
||||
/// <returns>A value indicating inequality.</returns>
|
||||
public static bool operator !=(FTMatrix left, FTMatrix right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Perform the matrix operation ‘b = a*b’.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The result is undefined if either ‘a’ or ‘b’ is zero.
|
||||
/// </remarks>
|
||||
/// <param name="a">A pointer to matrix ‘a’.</param>
|
||||
/// <param name="b">A pointer to matrix ‘b’.</param>
|
||||
public static void Multiply(FTMatrix a, FTMatrix b)
|
||||
{
|
||||
FT.FT_Matrix_Multiply(ref a, ref b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform the matrix operation ‘b = a*b’.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The result is undefined if either ‘a’ or ‘b’ is zero.
|
||||
/// </remarks>
|
||||
/// <param name="b">A pointer to matrix ‘b’.</param>
|
||||
public void Multiply(FTMatrix b)
|
||||
{
|
||||
FT.FT_Matrix_Multiply(ref this, ref b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invert a 2x2 matrix. Return an error if it can't be inverted.
|
||||
/// </summary>
|
||||
public void Invert()
|
||||
{
|
||||
Error err = FT.FT_Matrix_Invert(ref this);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTMatrix"/> to another for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="FTMatrix"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public bool Equals(FTMatrix other)
|
||||
{
|
||||
return
|
||||
xx == other.xx &&
|
||||
xy == other.xy &&
|
||||
yx == other.yx &&
|
||||
yy == other.yy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTMatrix"/> to an object for equality.
|
||||
/// </summary>
|
||||
/// <param name="obj">An object.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is FTMatrix)
|
||||
return this.Equals((FTMatrix)obj);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return xx.GetHashCode() ^ xy.GetHashCode() ^ yx.GetHashCode() ^ yy.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// FreeType root size class structure. A size object models a face object at a given size.
|
||||
/// </summary>
|
||||
public sealed class FTSize : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private bool userAlloc;
|
||||
private bool disposed;
|
||||
private bool duplicate;
|
||||
|
||||
private IntPtr reference;
|
||||
private SizeRec rec;
|
||||
|
||||
private Face parentFace;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTSize"/> class.
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent face.</param>
|
||||
public FTSize(Face parent)
|
||||
{
|
||||
IntPtr reference;
|
||||
Error err = FT.FT_New_Size(parent.Reference, out reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = reference;
|
||||
userAlloc = true;
|
||||
}
|
||||
|
||||
internal FTSize(IntPtr reference, bool userAlloc, Face parentFace)
|
||||
{
|
||||
Reference = reference;
|
||||
|
||||
this.userAlloc = userAlloc;
|
||||
|
||||
if (parentFace != null)
|
||||
{
|
||||
this.parentFace = parentFace;
|
||||
parentFace.AddChildSize(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
duplicate = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the FTSize class.
|
||||
/// </summary>
|
||||
~FTSize()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the size is disposed.
|
||||
/// </summary>
|
||||
public event EventHandler Disposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the object has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return disposed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the parent face object.
|
||||
/// </summary>
|
||||
public Face Face
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Face", "Cannot access a disposed object.");
|
||||
|
||||
return parentFace;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a typeless pointer, which is unused by the FreeType library or any of its drivers. It can be used by
|
||||
/// client applications to link their own data to each size object.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Tag property and Disposed event instead.")]
|
||||
public Generic Generic
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
|
||||
|
||||
return new Generic(rec.generic);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Generic", "Cannot access a disposed object.");
|
||||
|
||||
value.WriteToUnmanagedMemory(PInvokeHelper.AbsoluteOffsetOf<SizeRec>(Reference, "generic"));
|
||||
Reference = reference; //update rec.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets metrics for this size object. This field is read-only.
|
||||
/// </summary>
|
||||
public SizeMetrics Metrics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Metrics", "Cannot access a disposed object.");
|
||||
|
||||
return new SizeMetrics(rec.metrics);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an object used to identify this instance of <see cref="FTSize"/>. This object will not be
|
||||
/// modified or accessed internally.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a replacement for FT_Generic in FreeType. If you are retrieving the same object multiple times
|
||||
/// from functions, this object will not appear in new copies.
|
||||
/// </remarks>
|
||||
public object Tag { get; set; }
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
this.rec = PInvokeHelper.PtrToStructure<SizeRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary><para>
|
||||
/// Even though it is possible to create several size objects for a given face (see
|
||||
/// <see cref="SharpFont.Face.NewSize"/> for details), functions like <see cref="SharpFont.Face.LoadGlyph"/> or
|
||||
/// <see cref="SharpFont.Face.LoadChar"/> only use the one which has been activated last to determine the
|
||||
/// ‘current character pixel size’.
|
||||
/// </para><para>
|
||||
/// This function can be used to ‘activate’ a previously created size object.
|
||||
/// </para></summary>
|
||||
/// <remarks>
|
||||
/// If ‘face’ is the size's parent face object, this function changes the value of ‘face->size’ to the input
|
||||
/// size handle.
|
||||
/// </remarks>
|
||||
public void Activate()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Activate", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Activate_Size(Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diposes the FTSize.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
//only dispose the user allocated sizes that are not duplicates.
|
||||
if (userAlloc && !duplicate)
|
||||
{
|
||||
FT.FT_Done_Size(reference);
|
||||
}
|
||||
|
||||
// removes itself from the parent Face, with a check to prevent this from happening when Face is
|
||||
// being disposed (Face disposes all it's children with a foreach loop, this causes an
|
||||
// InvalidOperationException for modifying a collection during enumeration)
|
||||
if (parentFace != null && !parentFace.IsDisposed)
|
||||
parentFace.RemoveChildSize(this);
|
||||
|
||||
reference = IntPtr.Zero;
|
||||
rec = new SizeRec();
|
||||
|
||||
EventHandler handler = Disposed;
|
||||
if (handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A function used to seek and read data from a given input stream.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function might be called to perform a seek or skip operation with a ‘count’ of 0. A non-zero return value
|
||||
/// then indicates an error.
|
||||
/// </remarks>
|
||||
/// <param name="stream">A handle to the source stream.</param>
|
||||
/// <param name="offset">The offset of read in stream (always from start).</param>
|
||||
/// <param name="buffer">The address of the read buffer.</param>
|
||||
/// <param name="count">The number of bytes to read from the stream.</param>
|
||||
/// <returns>The number of bytes effectively read by the stream.</returns>
|
||||
[CLSCompliant(false)]
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate uint StreamIOFunc(NativeReference<FTStream> stream, uint offset, IntPtr buffer, uint count);
|
||||
|
||||
/// <summary>
|
||||
/// A function used to close a given input stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">A handle to the target stream.</param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void StreamCloseFunc(NativeReference<FTStream> stream);
|
||||
|
||||
/// <summary>
|
||||
/// A handle to an input stream.
|
||||
/// </summary>
|
||||
public sealed class FTStream : NativeObject
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private StreamRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal FTStream(IntPtr reference): base(reference)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets base. For memory-based streams, this is the address of the first stream byte in memory. This field
|
||||
/// should always be set to NULL for disk-based streams.
|
||||
/// </summary>
|
||||
public IntPtr Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.@base;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream size in bytes.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current position within the stream.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.pos;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the descriptor. This field is a union that can hold an integer or a pointer. It is used by stream
|
||||
/// implementations to store file descriptors or ‘FILE*’ pointers.
|
||||
/// </summary>
|
||||
public StreamDesc Descriptor
|
||||
{
|
||||
get
|
||||
{
|
||||
return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "descriptor"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path name. This field is completely ignored by FreeType. However, it is often useful during
|
||||
/// debugging to use it to store the stream's filename (where available).
|
||||
/// </summary>
|
||||
public StreamDesc PathName
|
||||
{
|
||||
get
|
||||
{
|
||||
return new StreamDesc(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "pathname"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream's input function.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public StreamIOFunc Read
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.read;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the stream's close function.
|
||||
/// </summary>
|
||||
public StreamCloseFunc Close
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.close;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the memory manager to use to preload frames. This is set internally by FreeType and shouldn't be
|
||||
/// touched by stream implementations.
|
||||
/// </summary>
|
||||
public Memory Memory
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Memory(PInvokeHelper.AbsoluteOffsetOf<StreamRec>(Reference, "memory"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cursor. This field is set and used internally by FreeType when parsing frames.
|
||||
/// </summary>
|
||||
public IntPtr Cursor
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the limit. This field is set and used internally by FreeType when parsing frames.
|
||||
/// </summary>
|
||||
public IntPtr Limit
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.limit;
|
||||
}
|
||||
}
|
||||
|
||||
internal override IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.Reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<StreamRec>(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region GZIP Streams
|
||||
|
||||
/// <summary>
|
||||
/// Open a new stream to parse gzip-compressed font files. This is mainly used to support the compressed
|
||||
/// ‘*.pcf.gz’ fonts that come with XFree86.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The source stream must be opened before calling this function.
|
||||
/// </para><para>
|
||||
/// Calling the internal function ‘FT_Stream_Close’ on the new stream will not call ‘FT_Stream_Close’ on the
|
||||
/// source stream. None of the stream objects will be released to the heap.
|
||||
/// </para><para>
|
||||
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
|
||||
/// needed within the stream.
|
||||
/// </para><para>
|
||||
/// In certain builds of the library, gzip compression recognition is automatically handled when calling
|
||||
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
|
||||
/// capable of handling the raw compressed file, the library will try to open a gzipped stream from it and
|
||||
/// re-open the face with it.
|
||||
/// </para><para>
|
||||
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
|
||||
/// compiled with zlib support.
|
||||
/// </para></remarks>
|
||||
/// <param name="source">The source stream.</param>
|
||||
public void OpenGzip(FTStream source)
|
||||
{
|
||||
Error err = FT.FT_Stream_OpenGzip(Reference, source.Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region LZW Streams
|
||||
|
||||
/// <summary>
|
||||
/// Open a new stream to parse LZW-compressed font files. This is mainly used to support the compressed
|
||||
/// ‘*.pcf.Z’ fonts that come with XFree86.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The source stream must be opened before calling this function.
|
||||
/// </para><para>
|
||||
/// Calling the internal function ‘FT_Stream_Close’ on the new stream will not call ‘FT_Stream_Close’ on the
|
||||
/// source stream. None of the stream objects will be released to the heap.
|
||||
/// </para><para>
|
||||
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
|
||||
/// needed within the stream.
|
||||
/// </para><para>
|
||||
/// In certain builds of the library, LZW compression recognition is automatically handled when calling
|
||||
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
|
||||
/// capable of handling the raw compressed file, the library will try to open a LZW stream from it and re-open
|
||||
/// the face with it.
|
||||
/// </para><para>
|
||||
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
|
||||
/// compiled with LZW support.
|
||||
/// </para></remarks>
|
||||
/// <param name="source">The source stream.</param>
|
||||
public void OpenLzw(FTStream source)
|
||||
{
|
||||
Error err = FT.FT_Stream_OpenLZW(Reference, source.Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BZIP2 Streams
|
||||
|
||||
/// <summary>
|
||||
/// Open a new stream to parse bzip2-compressed font files. This is mainly used to support the compressed
|
||||
/// ‘*.pcf.bz2’ fonts that come with XFree86.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The source stream must be opened before calling this function.
|
||||
/// </para><para>
|
||||
/// Calling the internal function ‘FT_Stream_Close’ on the new stream will not call ‘FT_Stream_Close’ on the
|
||||
/// source stream. None of the stream objects will be released to the heap.
|
||||
/// </para><para>
|
||||
/// The stream implementation is very basic and resets the decompression process each time seeking backwards is
|
||||
/// needed within the stream.
|
||||
/// </para><para>
|
||||
/// In certain builds of the library, bzip2 compression recognition is automatically handled when calling
|
||||
/// <see cref="Library.NewFace"/> or <see cref="Library.OpenFace"/>. This means that if no font driver is
|
||||
/// capable of handling the raw compressed file, the library will try to open a bzip2 stream from it and
|
||||
/// re-open the face with it.
|
||||
/// </para><para>
|
||||
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
|
||||
/// compiled with bzip2 support.
|
||||
/// </para></remarks>
|
||||
/// <param name="source">The source stream.</param>
|
||||
public void StreamOpenBzip2(FTStream source)
|
||||
{
|
||||
Error err = FT.FT_Stream_OpenBzip2(Reference, source.Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple structure used to store a 2D vector unit vector. Uses <see cref="Fixed2Dot14"/> types.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct FTUnitVector
|
||||
{
|
||||
/// <summary>
|
||||
/// Horizontal coordinate.
|
||||
/// </summary>
|
||||
public Fixed2Dot14 X;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical coordinate.
|
||||
/// </summary>
|
||||
public Fixed2Dot14 Y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple structure used to store a 2D vector.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct FTVector : IEquatable<FTVector>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr x;
|
||||
private IntPtr y;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTVector"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal coordinate.</param>
|
||||
/// <param name="y">The vertical coordinate.</param>
|
||||
public FTVector(Fixed16Dot16 x, Fixed16Dot16 y)
|
||||
: this()
|
||||
{
|
||||
this.x = (IntPtr)x.Value;
|
||||
this.y = (IntPtr)y.Value;
|
||||
}
|
||||
|
||||
internal FTVector(IntPtr reference)
|
||||
: this()
|
||||
{
|
||||
this.x = Marshal.ReadIntPtr(reference);
|
||||
this.y = Marshal.ReadIntPtr(reference, IntPtr.Size);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the horizontal coordinate.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 X
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)x);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
x = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vertical coordinate.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)y);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
y = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTVector"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTVector"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTVector"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public static bool operator ==(FTVector left, FTVector right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTVector"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTVector"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTVector"/>.</param>
|
||||
/// <returns>A value indicating inequality.</returns>
|
||||
public static bool operator !=(FTVector left, FTVector right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary><para>
|
||||
/// Return the unit vector corresponding to a given angle. After the call, the value of ‘vec.x’ will be
|
||||
/// ‘sin(angle)’, and the value of ‘vec.y’ will be ‘cos(angle)’.
|
||||
/// </para><para>
|
||||
/// This function is useful to retrieve both the sinus and cosinus of a given angle quickly.
|
||||
/// </para></summary>
|
||||
/// <param name="angle">The address of angle.</param>
|
||||
/// <returns>The address of target vector.</returns>
|
||||
public static FTVector Unit(Fixed16Dot16 angle)
|
||||
{
|
||||
FTVector vec;
|
||||
FT.FT_Vector_Unit(out vec, (IntPtr)angle.Value);
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute vector coordinates from a length and angle.
|
||||
/// </summary>
|
||||
/// <param name="length">The vector length.</param>
|
||||
/// <param name="angle">The vector angle.</param>
|
||||
/// <returns>The address of source vector.</returns>
|
||||
public static FTVector FromPolar(Fixed16Dot16 length, Fixed16Dot16 angle)
|
||||
{
|
||||
FTVector vec;
|
||||
FT.FT_Vector_From_Polar(out vec, (IntPtr)length.Value, (IntPtr)angle.Value);
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform a single vector through a 2x2 matrix.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The result is undefined if either ‘vector’ or ‘matrix’ is invalid.
|
||||
/// </remarks>
|
||||
/// <param name="matrix">A pointer to the source 2x2 matrix.</param>
|
||||
public void Transform(FTMatrix matrix)
|
||||
{
|
||||
FT.FT_Vector_Transform(ref this, ref matrix);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rotate a vector by a given angle.
|
||||
/// </summary>
|
||||
/// <param name="angle">The address of angle.</param>
|
||||
public void Rotate(Fixed16Dot16 angle)
|
||||
{
|
||||
FT.FT_Vector_Rotate(ref this, (IntPtr)angle.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the length of a given vector.
|
||||
/// </summary>
|
||||
/// <returns>The vector length, expressed in the same units that the original vector coordinates.</returns>
|
||||
public Fixed16Dot16 Length()
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Vector_Length(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute both the length and angle of a given vector.
|
||||
/// </summary>
|
||||
/// <param name="length">The vector length.</param>
|
||||
/// <param name="angle">The vector angle.</param>
|
||||
public void Polarize(out Fixed16Dot16 length, out Fixed16Dot16 angle)
|
||||
{
|
||||
IntPtr tmpLength, tmpAngle;
|
||||
FT.FT_Vector_Polarize(ref this, out tmpLength, out tmpAngle);
|
||||
|
||||
length = Fixed16Dot16.FromRawValue((int)tmpLength);
|
||||
angle = Fixed16Dot16.FromRawValue((int)tmpAngle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTVector"/> to another for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="FTVector"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public bool Equals(FTVector other)
|
||||
{
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTVector"/> to an object for equality.
|
||||
/// </summary>
|
||||
/// <param name="obj">An object.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is FTVector)
|
||||
return this.Equals((FTVector)obj);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() ^ y.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple structure used to store a 2D vector.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct FTVector26Dot6 : IEquatable<FTVector26Dot6>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr x;
|
||||
private IntPtr y;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FTVector26Dot6"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal coordinate.</param>
|
||||
/// <param name="y">The vertical coordinate.</param>
|
||||
public FTVector26Dot6(Fixed26Dot6 x, Fixed26Dot6 y)
|
||||
: this()
|
||||
{
|
||||
this.x = (IntPtr)x.Value;
|
||||
this.y = (IntPtr)y.Value;
|
||||
}
|
||||
|
||||
internal FTVector26Dot6(IntPtr reference)
|
||||
: this()
|
||||
{
|
||||
this.x = Marshal.ReadIntPtr(reference);
|
||||
this.y = Marshal.ReadIntPtr(reference, IntPtr.Size);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the horizontal coordinate.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 X
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)x);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
x = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vertical coordinate.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)y);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
y = (IntPtr)value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTVector26Dot6"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTVector26Dot6"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTVector26Dot6"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public static bool operator ==(FTVector26Dot6 left, FTVector26Dot6 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="FTVector26Dot6"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">A <see cref="FTVector26Dot6"/>.</param>
|
||||
/// <param name="right">Another <see cref="FTVector26Dot6"/>.</param>
|
||||
/// <returns>A value indicating inequality.</returns>
|
||||
public static bool operator !=(FTVector26Dot6 left, FTVector26Dot6 right)
|
||||
{
|
||||
return !left.Equals(right);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTVector26Dot6"/> to another for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="FTVector26Dot6"/>.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public bool Equals(FTVector26Dot6 other)
|
||||
{
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance of <see cref="FTVector26Dot6"/> to an object for equality.
|
||||
/// </summary>
|
||||
/// <param name="obj">An object.</param>
|
||||
/// <returns>A value indicating equality.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is FTVector26Dot6)
|
||||
return this.Equals((FTVector26Dot6)obj);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a unique hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return x.GetHashCode() ^ y.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of bit flags used in the ‘face_flags’ field of the <see cref="Face"/> structure. They inform client
|
||||
/// applications of properties of the corresponding face.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum FaceFlags : long
|
||||
{
|
||||
/// <summary>
|
||||
/// No style flags.
|
||||
/// </summary>
|
||||
None = 0x0000,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains outline glyphs. This doesn't prevent bitmap strikes, i.e., a face can have
|
||||
/// both this and and <see cref="FaceFlags.FixedSizes"/> set.
|
||||
/// </summary>
|
||||
Scalable = 0x0001,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains bitmap strikes. See also <see cref="Face.FixedSizesCount"/> and
|
||||
/// <see cref="Face.AvailableSizes"/>.
|
||||
/// </summary>
|
||||
FixedSizes = 0x0002,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains fixed-width characters (like Courier, Lucido, MonoType, etc.).
|
||||
/// </summary>
|
||||
FixedWidth = 0x0004,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face uses the ‘sfnt’ storage scheme. For now, this means TrueType and OpenType.
|
||||
/// </summary>
|
||||
Sfnt = 0x0008,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains horizontal glyph metrics. This should be set for all common formats.
|
||||
/// </summary>
|
||||
Horizontal = 0x0010,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains vertical glyph metrics. This is only available in some formats, not all of
|
||||
/// them.
|
||||
/// </summary>
|
||||
Vertical = 0x0020,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the face contains kerning information. If set, the kerning distance can be retrieved through
|
||||
/// the function <see cref="Face.GetKerning"/>. Otherwise the function always return the vector (0,0). Note
|
||||
/// that FreeType doesn't handle kerning data from the ‘GPOS’ table (as present in some OpenType fonts).
|
||||
/// </summary>
|
||||
Kerning = 0x0040,
|
||||
|
||||
/// <summary>
|
||||
/// THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT.
|
||||
/// </summary>
|
||||
[Obsolete("THIS FLAG IS DEPRECATED. DO NOT USE OR TEST IT.")]
|
||||
FastGlyphs = 0x0080,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the font contains multiple masters and is capable of interpolating between them. See the
|
||||
/// multiple-masters specific API for details.
|
||||
/// </summary>
|
||||
MultipleMasters = 0x0100,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the font contains glyph names that can be retrieved through
|
||||
/// <see cref="Face.GetGlyphName(uint, int)"/>. Note that some TrueType fonts contain broken glyph name
|
||||
/// tables. Use the function <see cref="Face.HasPSGlyphNames"/> when needed.
|
||||
/// </summary>
|
||||
GlyphNames = 0x0200,
|
||||
|
||||
/// <summary>
|
||||
/// Used internally by FreeType to indicate that a face's stream was provided by the client application and
|
||||
/// should not be destroyed when <see cref="Face.Dispose()"/> is called. Don't read or test this flag.
|
||||
/// </summary>
|
||||
ExternalStream = 0x0400,
|
||||
|
||||
/// <summary>
|
||||
/// Set if the font driver has a hinting machine of its own. For example, with TrueType fonts, it makes sense
|
||||
/// to use data from the SFNT ‘gasp’ table only if the native TrueType hinting engine (with the bytecode
|
||||
/// interpreter) is available and active.
|
||||
/// </summary>
|
||||
Hinter = 0x0800,
|
||||
|
||||
/// <summary><para>
|
||||
/// Set if the font is CID-keyed. In that case, the font is not accessed by glyph indices but by CID values.
|
||||
/// For subsetted CID-keyed fonts this has the consequence that not all index values are a valid argument to
|
||||
/// <see cref="Face.LoadGlyph"/>. Only the CID values for which corresponding glyphs in the subsetted font
|
||||
/// exist make <see cref="Face.LoadGlyph"/> return successfully; in all other cases you get an
|
||||
/// <see cref="Error.InvalidArgument"/> error.
|
||||
/// </para><para>
|
||||
/// Note that CID-keyed fonts which are in an SFNT wrapper don't have this flag set since the glyphs are
|
||||
/// accessed in the normal way (using contiguous indices); the ‘CID-ness’ isn't visible to the application.
|
||||
/// </para></summary>
|
||||
CidKeyed = 0x1000,
|
||||
|
||||
/// <summary><para>
|
||||
/// Set if the font is ‘tricky’, this is, it always needs the font format's native hinting engine to get a
|
||||
/// reasonable result. A typical example is the Chinese font ‘mingli.ttf’ which uses TrueType bytecode
|
||||
/// instructions to move and scale all of its subglyphs.
|
||||
/// </para><para>
|
||||
/// It is not possible to autohint such fonts using <see cref="LoadFlags.ForceAutohint"/>; it will also ignore
|
||||
/// <see cref="LoadFlags.NoHinting"/>. You have to set both <see cref="LoadFlags.NoHinting"/> and
|
||||
/// <see cref="LoadFlags.ForceAutohint"/> to really disable hinting; however, you probably never want this
|
||||
/// except for demonstration purposes.
|
||||
/// </para><para>
|
||||
/// Currently, there are about a dozen TrueType fonts in the list of tricky fonts; they are hard-coded in file
|
||||
/// ‘ttobjs.c’.
|
||||
/// </para></summary>
|
||||
Tricky = 0x2000,
|
||||
|
||||
/// <summary>
|
||||
/// Set if the font has color glyph tables. To access color glyphs use <see cref="LoadFlags.Color"/>.
|
||||
/// </summary>
|
||||
Color = 0x4000,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,752 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a fixed-point decimal value with 16 bits of decimal precision.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct Fixed16Dot16 : IEquatable<Fixed16Dot16>, IComparable<Fixed16Dot16>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// The angle pi expressed in FT_Angle units.
|
||||
/// </summary>
|
||||
public static readonly Fixed16Dot16 AnglePI = new Fixed16Dot16(180);
|
||||
|
||||
/// <summary>
|
||||
/// The angle 2*pi expressed in FT_Angle units.
|
||||
/// </summary>
|
||||
public static readonly Fixed16Dot16 Angle2PI = new Fixed16Dot16(360);
|
||||
|
||||
/// <summary>
|
||||
/// The angle pi/2 expressed in FT_Angle units.
|
||||
/// </summary>
|
||||
public static readonly Fixed16Dot16 AnglePI2 = new Fixed16Dot16(90);
|
||||
|
||||
/// <summary>
|
||||
/// The angle pi/4 expressed in FT_Angle units.
|
||||
/// </summary>
|
||||
public static readonly Fixed16Dot16 AnglePI4 = new Fixed16Dot16(45);
|
||||
|
||||
/// <summary>
|
||||
/// The raw 16.16 integer.
|
||||
/// </summary>
|
||||
private int value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">An integer value.</param>
|
||||
public Fixed16Dot16(int value)
|
||||
{
|
||||
this.value = value << 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed16Dot16(float value)
|
||||
{
|
||||
this.value = (int)(value * 65536);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed16Dot16(double value)
|
||||
{
|
||||
this.value = (int)(value * 65536);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed16Dot16"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed16Dot16(decimal value)
|
||||
{
|
||||
this.value = (int)(value * 65536);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw 16.16 integer.
|
||||
/// </summary>
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Static
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Fixed16Dot16"/> from an int containing a 16.16 value.
|
||||
/// </summary>
|
||||
/// <param name="value">A 16.16 value.</param>
|
||||
/// <returns>An instance of <see cref="Fixed16Dot16"/>.</returns>
|
||||
public static Fixed16Dot16 FromRawValue(int value)
|
||||
{
|
||||
Fixed16Dot16 f = new Fixed16Dot16();
|
||||
f.value = value;
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Int32"/>
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int32"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static Fixed16Dot16 FromInt32(int value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed16Dot16"/> from <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 16.16 value.</returns>
|
||||
public static Fixed16Dot16 FromSingle(float value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 16.16 value.</returns>
|
||||
public static Fixed16Dot16 FromDouble(double value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed16Dot16"/> from a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 16.16 value.</returns>
|
||||
public static Fixed16Dot16 FromDecimal(decimal value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 16.16 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed16Dot16 Add(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue(left.value + right.value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 16.16 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed16Dot16 Subtract(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue(left.value - right.value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 16.16 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed16Dot16 Multiply(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
long mul = (long)left.value * (long)right.value;
|
||||
Fixed16Dot16 ans = new Fixed16Dot16();
|
||||
ans.value = (int)(mul >> 16);
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to perform the computation ‘(a*b)/0x10000’ with maximal accuracy. Most of the
|
||||
/// time this is used to multiply a given value by a 16.16 fixed float factor.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// NOTE: This is a native FreeType function.
|
||||
/// </para><para>
|
||||
/// This function has been optimized for the case where the absolute value of ‘a’ is less than 2048, and ‘b’ is
|
||||
/// a 16.16 scaling factor. As this happens mainly when scaling from notional units to fractional pixels in
|
||||
/// FreeType, it resulted in noticeable speed improvements between versions 2.x and 1.x.
|
||||
/// </para><para>
|
||||
/// As a conclusion, always try to place a 16.16 factor as the second argument of this function; this can make
|
||||
/// a great difference.
|
||||
/// </para></remarks>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
|
||||
/// <returns>The result of ‘(a*b)/0x10000’.</returns>
|
||||
public static Fixed16Dot16 MultiplyFix(int a, Fixed16Dot16 b)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_MulFix((IntPtr)a, (IntPtr)b.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 16.16 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed16Dot16 Divide(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
long div = ((long)left.Value << 16) / right.value;
|
||||
Fixed16Dot16 ans = new Fixed16Dot16();
|
||||
ans.value = (int)div;
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to perform the computation ‘(a*0x10000)/b’ with maximal accuracy. Most of the
|
||||
/// time, this is used to divide a given value by a 16.16 fixed float factor.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// NOTE: This is a native FreeType function.
|
||||
/// </para><para>
|
||||
/// The optimization for <see cref="DivideFix"/> is simple: If (a << 16) fits in 32 bits, then the division
|
||||
/// is computed directly. Otherwise, we use a specialized version of <see cref="MultiplyDivide"/>.
|
||||
/// </para></remarks>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier. Use a 16.16 factor here whenever possible (see note below).</param>
|
||||
/// <returns>The result of ‘(a*0x10000)/b’.</returns>
|
||||
public static Fixed16Dot16 DivideFix(int a, Fixed16Dot16 b)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_DivFix((IntPtr)a, (IntPtr)b.Value));
|
||||
}
|
||||
|
||||
/// <summary><para>
|
||||
/// A very simple function used to perform the computation ‘(a*b)/c’ with maximal accuracy (it uses a 64-bit
|
||||
/// intermediate integer whenever necessary).
|
||||
/// </para><para>
|
||||
/// This function isn't necessarily as fast as some processor specific operations, but is at least completely
|
||||
/// portable.
|
||||
/// </para></summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <param name="a">The first multiplier.</param>
|
||||
/// <param name="b">The second multiplier.</param>
|
||||
/// <param name="c">The divisor.</param>
|
||||
/// <returns>
|
||||
/// The result of ‘(a*b)/c’. This function never traps when trying to divide by zero; it simply returns
|
||||
/// ‘MaxInt’ or ‘MinInt’ depending on the signs of ‘a’ and ‘b’.
|
||||
/// </returns>
|
||||
public static Fixed16Dot16 MultiplyDivide(Fixed16Dot16 a, Fixed16Dot16 b, Fixed16Dot16 c)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_MulDiv((IntPtr)a.Value, (IntPtr)b.Value, (IntPtr)c.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the arc-tangent corresponding to a given vector (x,y) in the 2d plane.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <param name="x">The horizontal vector coordinate.</param>
|
||||
/// <param name="y">The vertical vector coordinate.</param>
|
||||
/// <returns>The arc-tangent value (i.e. angle).</returns>
|
||||
public static Fixed16Dot16 Atan2(Fixed16Dot16 x, Fixed16Dot16 y)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Atan2((IntPtr)x.Value, (IntPtr)y.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the difference between two angles. The result is always constrained to the [-PI..PI] interval.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <param name="angle1">First angle.</param>
|
||||
/// <param name="angle2">Second angle.</param>
|
||||
/// <returns>Constrained value of ‘value2-value1’.</returns>
|
||||
public static Fixed16Dot16 AngleDiff(Fixed16Dot16 angle1, Fixed16Dot16 angle2)
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Angle_Diff((IntPtr)angle1.Value, (IntPtr)angle2.Value));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Int16"/> to a <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static implicit operator Fixed16Dot16(short value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Int32"/> to a <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int32"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static explicit operator Fixed16Dot16(int value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Single"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static explicit operator Fixed16Dot16(float value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Double"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static explicit operator Fixed16Dot16(double value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed16Dot16"/> value.</returns>
|
||||
public static explicit operator Fixed16Dot16(decimal value)
|
||||
{
|
||||
return new Fixed16Dot16(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Int32"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation can result in a loss of data.
|
||||
/// </remarks>
|
||||
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Int32"/> value.</returns>
|
||||
public static explicit operator int(Fixed16Dot16 value)
|
||||
{
|
||||
return value.ToInt32();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation can result in a loss of data.
|
||||
/// </remarks>
|
||||
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static explicit operator float(Fixed16Dot16 value)
|
||||
{
|
||||
return value.ToSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
|
||||
public static implicit operator double(Fixed16Dot16 value)
|
||||
{
|
||||
return value.ToDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed16Dot16"/> to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed16Dot16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static implicit operator decimal(Fixed16Dot16 value)
|
||||
{
|
||||
return value.ToDecimal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 16.16 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed16Dot16 operator +(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 16.16 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed16Dot16 operator -(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 16.16 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed16Dot16 operator *(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Multiply(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 16.16 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed16Dot16 operator /(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return Divide(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed16Dot16"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public static bool operator ==(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed16Dot16"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are not equal.</returns>
|
||||
public static bool operator !=(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than right.</returns>
|
||||
public static bool operator <(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return left.CompareTo(right) < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than or equal to right.</returns>
|
||||
public static bool operator <=(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return left.CompareTo(right) <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than right.</returns>
|
||||
public static bool operator >(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return left.CompareTo(right) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
|
||||
public static bool operator >=(Fixed16Dot16 left, Fixed16Dot16 right)
|
||||
{
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
/// <summary>
|
||||
/// Removes the decimal part of the value.
|
||||
/// </summary>
|
||||
/// <returns>The truncated number.</returns>
|
||||
public int Floor()
|
||||
{
|
||||
return value >> 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to compute the floor function of a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <returns>The result of ‘a & -0x10000’.</returns>
|
||||
public Fixed16Dot16 FloorFix()
|
||||
{
|
||||
//TODO does the P/Invoke overhead make this slower than re-implementing in C#? Test it
|
||||
return FromRawValue((int)FT.FT_FloorFix((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds to the nearest whole number.
|
||||
/// </summary>
|
||||
/// <returns>The nearest whole number.</returns>
|
||||
public int Round()
|
||||
{
|
||||
//add 2^15, rounds the integer part up if the decimal value is >= 0.5
|
||||
return (value + 32768) >> 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to round a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <returns>The result of ‘(a + 0x8000) & -0x10000’.</returns>
|
||||
public Fixed16Dot16 RoundFix()
|
||||
{
|
||||
return FromRawValue((int)FT.FT_RoundFix((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds up to the next whole number.
|
||||
/// </summary>
|
||||
/// <returns>The next whole number.</returns>
|
||||
public int Ceiling()
|
||||
{
|
||||
//add 2^16 - 1, rounds the integer part up if there's any decimal value
|
||||
return (value + 65535) >> 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A very simple function used to compute the ceiling function of a 16.16 fixed number.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <returns>The result of ‘(a + 0x10000 - 1) & -0x10000’.</returns>
|
||||
public Fixed16Dot16 CeilingFix()
|
||||
{
|
||||
return FromRawValue((int)FT.FT_CeilFix((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sinus of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// NOTE: This is a native FreeType function.
|
||||
/// </para><para>
|
||||
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
|
||||
/// </para></remarks>
|
||||
/// <returns>The sinus value.</returns>
|
||||
public Fixed16Dot16 Sin()
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Sin((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the cosinus of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// NOTE: This is a native FreeType function.
|
||||
/// </para><para>
|
||||
/// If you need both the sinus and cosinus for a given angle, use the function <see cref="FTVector.Unit"/>.
|
||||
/// </para></remarks>
|
||||
/// <returns>The cosinus value.</returns>
|
||||
public Fixed16Dot16 Cos()
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Cos((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the tangent of a given angle in fixed point format.
|
||||
/// </summary>
|
||||
/// <remarks>This is a native FreeType function.</remarks>
|
||||
/// <returns>The tangent value.</returns>
|
||||
public Fixed16Dot16 Tan()
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)FT.FT_Tan((IntPtr)this.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Int32"/>. The value is floored.
|
||||
/// </summary>
|
||||
/// <returns>An integer value.</returns>
|
||||
public int ToInt32()
|
||||
{
|
||||
return Floor();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public float ToSingle()
|
||||
{
|
||||
return value / 65536f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public double ToDouble()
|
||||
{
|
||||
return value / 65536d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <returns>A decimal value.</returns>
|
||||
public decimal ToDecimal()
|
||||
{
|
||||
return value / 65536m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another <see cref="Fixed16Dot16"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed16Dot16"/>.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public bool Equals(Fixed16Dot16 other)
|
||||
{
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instnace with another <see cref="Fixed16Dot16"/> and returns an integer that indicates
|
||||
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
|
||||
/// other <see cref="Fixed16Dot16"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed16Dot16"/>.</param>
|
||||
/// <returns>A value indicating the relative order of the instances.</returns>
|
||||
public int CompareTo(Fixed16Dot16 other)
|
||||
{
|
||||
return value.CompareTo(other.value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format)
|
||||
{
|
||||
return ToDecimal().ToString(format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format, IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(format, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return ToDecimal().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a hash code for the current object.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the current object.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return value.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified object isequal to the current object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to compare with the current object.</param>
|
||||
/// <returns>A value indicating equality between the two objects.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Fixed16Dot16)
|
||||
return this.Equals((Fixed16Dot16)obj);
|
||||
else if (obj is int)
|
||||
return value == ((Fixed16Dot16)obj).value;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,579 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a fixed-point decimal value with 6 bits of decimal precision.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Fixed26Dot6 : IEquatable<Fixed26Dot6>, IComparable<Fixed26Dot6>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// The raw 26.6 integer.
|
||||
/// </summary>
|
||||
private int value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">An integer value.</param>
|
||||
public Fixed26Dot6(int value)
|
||||
{
|
||||
this.value = value << 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed26Dot6(float value)
|
||||
{
|
||||
this.value = (int)(value * 64);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed26Dot6(double value)
|
||||
{
|
||||
this.value = (int)(value * 64);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed26Dot6"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed26Dot6(decimal value)
|
||||
{
|
||||
this.value = (int)(value * 64);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw 26.6 integer.
|
||||
/// </summary>
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Static
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Fixed26Dot6"/> from an int containing a 26.6 value.
|
||||
/// </summary>
|
||||
/// <param name="value">A 26.6 value.</param>
|
||||
/// <returns>An instance of <see cref="Fixed26Dot6"/>.</returns>
|
||||
public static Fixed26Dot6 FromRawValue(int value)
|
||||
{
|
||||
Fixed26Dot6 f = new Fixed26Dot6();
|
||||
f.value = value;
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Int32"/>
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int32"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static Fixed26Dot6 FromInt32(int value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed26Dot6"/> from <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 26.6 value.</returns>
|
||||
public static Fixed26Dot6 FromSingle(float value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 26.6 value.</returns>
|
||||
public static Fixed26Dot6 FromDouble(double value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed26Dot6"/> from a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 26.6 value.</returns>
|
||||
public static Fixed26Dot6 FromDecimal(decimal value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 26.6 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed26Dot6 Add(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue(left.value + right.value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 26.6 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed26Dot6 Subtract(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue(left.value - right.value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 26.6 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed26Dot6 Multiply(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
long mul = (long)left.value * (long)right.value;
|
||||
Fixed26Dot6 ans = new Fixed26Dot6();
|
||||
ans.value = (int)(mul >> 6);
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 26.6 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed26Dot6 Divide(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
long div = ((long)left.Value << 6) / right.value;
|
||||
Fixed26Dot6 ans = new Fixed26Dot6();
|
||||
ans.value = (int)div;
|
||||
return ans;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Int16"/> to a <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static implicit operator Fixed26Dot6(short value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Int32"/> to a <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int32"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static implicit operator Fixed26Dot6(int value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Single"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static implicit operator Fixed26Dot6(float value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Double"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static implicit operator Fixed26Dot6(double value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed26Dot6"/> value.</returns>
|
||||
public static implicit operator Fixed26Dot6(decimal value)
|
||||
{
|
||||
return new Fixed26Dot6(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Int32"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation can result in a loss of data.
|
||||
/// </remarks>
|
||||
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Int32"/> value.</returns>
|
||||
public static explicit operator int(Fixed26Dot6 value)
|
||||
{
|
||||
return value.ToInt32();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation can result in a loss of data.
|
||||
/// </remarks>
|
||||
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static explicit operator float(Fixed26Dot6 value)
|
||||
{
|
||||
return value.ToSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
|
||||
public static implicit operator double(Fixed26Dot6 value)
|
||||
{
|
||||
return value.ToDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed26Dot6"/> to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed26Dot6"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static implicit operator decimal(Fixed26Dot6 value)
|
||||
{
|
||||
return value.ToDecimal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 26.6 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed26Dot6 operator +(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 26.6 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed26Dot6 operator -(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 26.6 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed26Dot6 operator *(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Multiply(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 26.6 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed26Dot6 operator /(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return Divide(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed26Dot6"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public static bool operator ==(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed26Dot6"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are not equal.</returns>
|
||||
public static bool operator !=(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than right.</returns>
|
||||
public static bool operator <(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return left.CompareTo(right) < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than or equal to right.</returns>
|
||||
public static bool operator <=(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return left.CompareTo(right) <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than right.</returns>
|
||||
public static bool operator >(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return left.CompareTo(right) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
|
||||
public static bool operator >=(Fixed26Dot6 left, Fixed26Dot6 right)
|
||||
{
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
/// <summary>
|
||||
/// Removes the decimal part of the value.
|
||||
/// </summary>
|
||||
/// <returns>The truncated number.</returns>
|
||||
public int Floor()
|
||||
{
|
||||
return value >> 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds to the nearest whole number.
|
||||
/// </summary>
|
||||
/// <returns>The nearest whole number.</returns>
|
||||
public int Round()
|
||||
{
|
||||
//add 2^5, rounds the integer part up if the decimal value is >= 0.5
|
||||
return (value + 32) >> 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds up to the next whole number.
|
||||
/// </summary>
|
||||
/// <returns>The next whole number.</returns>
|
||||
public int Ceiling()
|
||||
{
|
||||
//add 2^6 - 1, rounds the integer part up if there's any decimal value
|
||||
return (value + 63) >> 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Int32"/>. The value is floored.
|
||||
/// </summary>
|
||||
/// <returns>An integer value.</returns>
|
||||
public int ToInt32()
|
||||
{
|
||||
return Floor();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public float ToSingle()
|
||||
{
|
||||
return value / 64f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public double ToDouble()
|
||||
{
|
||||
return value / 64d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <returns>A decimal value.</returns>
|
||||
public decimal ToDecimal()
|
||||
{
|
||||
return value / 64m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another <see cref="Fixed26Dot6"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed26Dot6"/>.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public bool Equals(Fixed26Dot6 other)
|
||||
{
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instnace with another <see cref="Fixed26Dot6"/> and returns an integer that indicates
|
||||
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
|
||||
/// other <see cref="Fixed26Dot6"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed26Dot6"/>.</param>
|
||||
/// <returns>A value indicating the relative order of the instances.</returns>
|
||||
public int CompareTo(Fixed26Dot6 other)
|
||||
{
|
||||
return value.CompareTo(other.value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format)
|
||||
{
|
||||
return ToDecimal().ToString(format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format, IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(format, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return ToDecimal().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a hash code for the current object.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the current object.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return value.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified object isequal to the current object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to compare with the current object.</param>
|
||||
/// <returns>A value indicating equality between the two objects.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Fixed26Dot6)
|
||||
return this.Equals((Fixed26Dot6)obj);
|
||||
else if (obj is int)
|
||||
return value == ((Fixed26Dot6)obj).value;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a fixed-point decimal value with 14 bits of decimal precision.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct Fixed2Dot14 : IEquatable<Fixed2Dot14>, IComparable<Fixed2Dot14>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// The raw 2.14 short.
|
||||
/// </summary>
|
||||
private short value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">An integer value.</param>
|
||||
public Fixed2Dot14(short value)
|
||||
{
|
||||
this.value = (short)(value << 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed2Dot14(float value)
|
||||
{
|
||||
this.value = (short)(value * 16384);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed2Dot14(double value)
|
||||
{
|
||||
this.value = (short)(value * 16384);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fixed2Dot14"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating point value.</param>
|
||||
public Fixed2Dot14(decimal value)
|
||||
{
|
||||
this.value = (short)(value * 16384);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw 2.14 integer.
|
||||
/// </summary>
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Static
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Fixed2Dot14"/> from an int containing a 2.14 value.
|
||||
/// </summary>
|
||||
/// <param name="value">A 2.14 value.</param>
|
||||
/// <returns>An instance of <see cref="Fixed2Dot14"/>.</returns>
|
||||
public static Fixed2Dot14 FromRawValue(short value)
|
||||
{
|
||||
Fixed2Dot14 f = new Fixed2Dot14();
|
||||
f.value = value;
|
||||
return f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed2Dot14"/> from a <see cref="System.Int16"/>
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Int16"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
|
||||
public static Fixed2Dot14 FromInt16(short value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 2.14 value.</returns>
|
||||
public static Fixed2Dot14 FromSingle(float value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 2.14 value.</returns>
|
||||
public static Fixed2Dot14 FromDouble(double value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Fixed2Dot14"/> from <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A floating-point value.</param>
|
||||
/// <returns>A fixed 2.14 value.</returns>
|
||||
public static Fixed2Dot14 FromDecimal(decimal value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 2.14 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed2Dot14 Add(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Fixed2Dot14.FromRawValue((short)(left.value + right.value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 2.14 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed2Dot14 Subtract(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Fixed2Dot14.FromRawValue((short)(left.value - right.value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 2.14 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed2Dot14 Multiply(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
int mul = (int)left.value * (int)right.value;
|
||||
Fixed2Dot14 ans;
|
||||
ans.value = (short)(mul >> 14);
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 2.14 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed2Dot14 Divide(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
int div = ((int)left.Value << 6) / right.value;
|
||||
Fixed2Dot14 ans;
|
||||
ans.value = (short)div;
|
||||
return ans;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed2Dot14"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Single"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
|
||||
public static explicit operator Fixed2Dot14(float value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Double"/> to a <see cref="Fixed2Dot14"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Double"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
|
||||
public static explicit operator Fixed2Dot14(double value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="System.Single"/> to a <see cref="Fixed2Dot14"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="System.Decimal"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="Fixed2Dot14"/> value.</returns>
|
||||
public static explicit operator Fixed2Dot14(decimal value)
|
||||
{
|
||||
return new Fixed2Dot14(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation can result in a loss of data.
|
||||
/// </remarks>
|
||||
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static explicit operator float(Fixed2Dot14 value)
|
||||
{
|
||||
return value.ToSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Double"/> value.</returns>
|
||||
public static implicit operator double(Fixed2Dot14 value)
|
||||
{
|
||||
return value.ToDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Casts a <see cref="Fixed2Dot14"/> to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">A <see cref="Fixed2Dot14"/> value.</param>
|
||||
/// <returns>The equivalent <see cref="System.Single"/> value.</returns>
|
||||
public static implicit operator decimal(Fixed2Dot14 value)
|
||||
{
|
||||
return value.ToDecimal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds two 2.14 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the addition.</returns>
|
||||
public static Fixed2Dot14 operator +(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Add(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtacts one 2.14 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the subtraction.</returns>
|
||||
public static Fixed2Dot14 operator -(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Subtract(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two 2.14 values together.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the multiplication.</returns>
|
||||
public static Fixed2Dot14 operator *(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Multiply(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Divides one 2.14 values from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>The result of the division.</returns>
|
||||
public static Fixed2Dot14 operator /(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return Divide(left, right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed2Dot14"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public static bool operator ==(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two instances of <see cref="Fixed2Dot14"/> for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether the two instances are not equal.</returns>
|
||||
public static bool operator !=(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than right.</returns>
|
||||
public static bool operator <(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return left.CompareTo(right) < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is less than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is less than or equal to right.</returns>
|
||||
public static bool operator <=(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return left.CompareTo(right) <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than right.</returns>
|
||||
public static bool operator >(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return left.CompareTo(right) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the left operand is greater than or equal to the right operand.
|
||||
/// </summary>
|
||||
/// <param name="left">The left operand.</param>
|
||||
/// <param name="right">The right operand.</param>
|
||||
/// <returns>A value indicating whether left is greater than or equal to right.</returns>
|
||||
public static bool operator >=(Fixed2Dot14 left, Fixed2Dot14 right)
|
||||
{
|
||||
return left.CompareTo(right) >= 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Instance
|
||||
|
||||
/// <summary>
|
||||
/// Removes the decimal part of the value.
|
||||
/// </summary>
|
||||
/// <returns>The truncated number.</returns>
|
||||
public short Floor()
|
||||
{
|
||||
return (short)(value >> 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds to the nearest whole number.
|
||||
/// </summary>
|
||||
/// <returns>The nearest whole number.</returns>
|
||||
public short Round()
|
||||
{
|
||||
//add 2^13, rounds the integer part up if the decimal value is >= 0.5
|
||||
return (short)((value + 8192) >> 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds up to the next whole number.
|
||||
/// </summary>
|
||||
/// <returns>The next whole number.</returns>
|
||||
public short Ceiling()
|
||||
{
|
||||
//add 2^14 - 1, rounds the integer part up if there's any decimal value
|
||||
return (short)((value + 16383) >> 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Int16"/>. The value is floored.
|
||||
/// </summary>
|
||||
/// <returns>An integer value.</returns>
|
||||
public short ToInt16()
|
||||
{
|
||||
return Floor();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Single"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public float ToSingle()
|
||||
{
|
||||
return value / 16384f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Double"/>.
|
||||
/// </summary>
|
||||
/// <returns>A floating-point value.</returns>
|
||||
public double ToDouble()
|
||||
{
|
||||
return value / 16384d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the value to a <see cref="System.Decimal"/>.
|
||||
/// </summary>
|
||||
/// <returns>A decimal value.</returns>
|
||||
public decimal ToDecimal()
|
||||
{
|
||||
return value / 16384m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instance to another <see cref="Fixed2Dot14"/> for equality.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed2Dot14"/>.</param>
|
||||
/// <returns>A value indicating whether the two instances are equal.</returns>
|
||||
public bool Equals(Fixed2Dot14 other)
|
||||
{
|
||||
return value == other.value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares this instnace with another <see cref="Fixed2Dot14"/> and returns an integer that indicates
|
||||
/// whether the current instance precedes, follows, or occurs in the same position in the sort order as the
|
||||
/// other <see cref="Fixed2Dot14"/>.
|
||||
/// </summary>
|
||||
/// <param name="other">A <see cref="Fixed2Dot14"/>.</param>
|
||||
/// <returns>A value indicating the relative order of the instances.</returns>
|
||||
public int CompareTo(Fixed2Dot14 other)
|
||||
{
|
||||
return value.CompareTo(other.value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format)
|
||||
{
|
||||
return ToDecimal().ToString(format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <param name="format">A numeric format string.</param>
|
||||
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public string ToString(string format, IFormatProvider provider)
|
||||
{
|
||||
return ToDecimal().ToString(format, provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string that represents the current object.
|
||||
/// </summary>
|
||||
/// <returns>A string that represents the current object.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return ToDecimal().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a hash code for the current object.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the current object.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return value.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified object isequal to the current object.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to compare with the current object.</param>
|
||||
/// <returns>A value indicating equality between the two objects.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Fixed2Dot14)
|
||||
return this.Equals((Fixed2Dot14)obj);
|
||||
else if (obj is int)
|
||||
return value == ((Fixed2Dot14)obj).value;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using SharpFont.Fnt.Internal;
|
||||
|
||||
namespace SharpFont.Fnt
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the general appearance of the font.
|
||||
/// </summary>
|
||||
public enum Family
|
||||
{
|
||||
/// <summary>
|
||||
/// Don't care or don't know which family.
|
||||
/// </summary>
|
||||
DontCare = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The font has a Roman appearance.
|
||||
/// </summary>
|
||||
Roman = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The font has a Swiss appearance.
|
||||
/// </summary>
|
||||
Swiss = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The font has a Modern appearance.
|
||||
/// </summary>
|
||||
Modern = 3,
|
||||
|
||||
/// <summary>
|
||||
/// The font has a script-like appearance.
|
||||
/// </summary>
|
||||
Script = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The font is decorative.
|
||||
/// </summary>
|
||||
Decorative = 5
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides flags for font proportions and color.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[CLSCompliant(false)]
|
||||
public enum Flags : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// Font is fixed.
|
||||
/// </summary>
|
||||
Fixed = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// Font is proportional.
|
||||
/// </summary>
|
||||
Proportional = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// Font is ABC fixed.
|
||||
/// </summary>
|
||||
AbcFixed = 1 << 2,
|
||||
|
||||
/// <summary>
|
||||
/// Font is ABC proportional.
|
||||
/// </summary>
|
||||
AbcProportional = 1 << 3,
|
||||
|
||||
/// <summary>
|
||||
/// Font is 2-bit color.
|
||||
/// </summary>
|
||||
Color1 = 1 << 4,
|
||||
|
||||
/// <summary>
|
||||
/// Font is 4-bit color.
|
||||
/// </summary>
|
||||
Color16 = 1 << 5,
|
||||
|
||||
/// <summary>
|
||||
/// Font is 8-bit color.
|
||||
/// </summary>
|
||||
Color256 = 1 << 6,
|
||||
|
||||
/// <summary>
|
||||
/// Font is RGB color.
|
||||
/// </summary>
|
||||
RgbColor = 1 << 7
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Windows FNT Header info.
|
||||
/// </summary>
|
||||
public class Header
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private HeaderRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Header(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version format of the file (e.g. 0x0200).
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.version;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the file in bytes.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint FileSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.file_size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the copyright text.
|
||||
/// Limited to 60 bytes.
|
||||
/// </summary>
|
||||
public byte[] Copyright
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.copyright;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the filetype (vector or bitmap). This is exclusively for GDI use.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort FileType
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.file_type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the nominal point size determined by the designer at which the font looks
|
||||
/// best.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort NominalPointSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.nominal_point_size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the nominal vertical resolution in dots per inch.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort VerticalResolution
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.vertical_resolution;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the nominal horizontal resolution in dots per inch.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort HorizontalResolution
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.horizontal_resolution;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the font's ascent from the baseline.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort Ascent
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.ascent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of leading inside the bounds of <see cref="PixelHeight"/>.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort InternalLeading
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.internal_leading;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of leading the designer recommends to be added between
|
||||
/// rows.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort ExternalLeading
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.external_leading;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the font is italic.
|
||||
/// </summary>
|
||||
public bool Italic
|
||||
{
|
||||
get
|
||||
{
|
||||
return (0x01 & rec.italic) == 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ges whether the font includes underlining.
|
||||
/// </summary>
|
||||
public bool Underline
|
||||
{
|
||||
get
|
||||
{
|
||||
return (0x01 & rec.underline) == 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ges whether the font includes strikeout.
|
||||
/// </summary>
|
||||
public bool Strikeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return (0x01 & rec.strike_out) == 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the weight of characters on a scale of 1 to 1000, with
|
||||
/// 400 being regular weight.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort Weight
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.weight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character set specified by the font.
|
||||
/// </summary>
|
||||
public byte Charset
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.charset;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of the vector grid (vector fonts). For raster fonts,
|
||||
/// a zero value indicates that characters have variables widths,
|
||||
/// otherwise, the value is the width of the bitmap for all characters.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort PixelWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.pixel_width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the vector grid (vector fonts) or the height
|
||||
/// of the bitmap for all characters (raster fonts).
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort PixelHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.pixel_height;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the font is variable pitch.
|
||||
/// </summary>
|
||||
public byte PitchAndFamily
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.pitch_and_family;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the width of characters in the font, based on the width of 'X'.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort AverageWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.avg_width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum width of all characters in the font.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort MaximumWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.max_width;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first character code specified in the font.
|
||||
/// </summary>
|
||||
public byte FirstChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.first_char;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last character code specified in the font.
|
||||
/// </summary>
|
||||
public byte LastChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.last_char;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character to substitute when a character is needed that
|
||||
/// isn't defined in the font.
|
||||
/// </summary>
|
||||
public byte DefaultChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.default_char;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character that defines word breaks, for purposes of word
|
||||
/// wrapping and word spacing justification. This value is relative to
|
||||
/// the <see cref="FirstChar"/>, so the character code is this value
|
||||
/// minus <see cref="FirstChar"/>.
|
||||
/// </summary>
|
||||
public byte BreakChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.break_char;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes in each row of the bitmap (raster fonts).
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort BytesPerRow
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.bytes_per_row;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the offset in the file, in bytes, to the string that gives the device name.
|
||||
/// The value is 0 for generic fonts.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint DeviceOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.device_offset;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the offset in the file, in bytes, to the string that gives the face name
|
||||
/// (null-terminated).
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint FaceNameOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.face_name_offset;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute machine address of the bitmap,
|
||||
/// which is set by GDI at load time.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint BitsPointer
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.bits_pointer;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the offset in the file, in bytes, to the beginning of the character data
|
||||
/// (raster or vector).
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint BitsOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)rec.bits_offset;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reservied.
|
||||
/// </summary>
|
||||
public byte Reserved
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.reserved;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets <see cref="Flags"/> that describe font proportion and color.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public Flags Flags
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Flags)rec.flags;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ASpace has not been used since before Windows 3.0.
|
||||
/// Set it to 0 for compatibility.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort ASpace
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.A_space;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BSpace has not been used since before Windows 3.0.
|
||||
/// Set it to 0 for compatibility.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort BSpace
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.B_space;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CSpace has not been used since before Windows 3.0.
|
||||
/// Set it to 0 for compatibility.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort CSpace
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.C_space;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the offset of the color table.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public ushort ColorTableOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.color_table_offset;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This field is reserved.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint[] Reserved1
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.reserved1.Select(x => (uint) x).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<HeaderRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Fnt.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct HeaderRec
|
||||
{
|
||||
internal ushort version;
|
||||
internal FT_ULong file_size;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
|
||||
internal byte[] copyright;
|
||||
internal ushort file_type;
|
||||
internal ushort nominal_point_size;
|
||||
internal ushort vertical_resolution;
|
||||
internal ushort horizontal_resolution;
|
||||
internal ushort ascent;
|
||||
internal ushort internal_leading;
|
||||
internal ushort external_leading;
|
||||
internal byte italic;
|
||||
internal byte underline;
|
||||
internal byte strike_out;
|
||||
internal ushort weight;
|
||||
internal byte charset;
|
||||
internal ushort pixel_width;
|
||||
internal ushort pixel_height;
|
||||
internal byte pitch_and_family;
|
||||
internal ushort avg_width;
|
||||
internal ushort max_width;
|
||||
internal byte first_char;
|
||||
internal byte last_char;
|
||||
internal byte default_char;
|
||||
internal byte break_char;
|
||||
internal ushort bytes_per_row;
|
||||
internal FT_ULong device_offset;
|
||||
internal FT_ULong face_name_offset;
|
||||
internal FT_ULong bits_pointer;
|
||||
internal FT_ULong bits_offset;
|
||||
internal byte reserved;
|
||||
internal FT_ULong flags;
|
||||
internal ushort A_space;
|
||||
internal ushort B_space;
|
||||
internal ushort C_space;
|
||||
internal ushort color_table_offset;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
||||
internal FT_ULong[] reserved1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont.Fnt
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of valid values for the ‘charset’ byte in <see cref="Header"/>. Exact mapping tables for the various
|
||||
/// cpXXXX encodings (except for cp1361) can be found at <see href="ftp://ftp.unicode.org" /> in the
|
||||
/// MAPPINGS/VENDORS/MICSFT/WINDOWS subdirectory. cp1361 is roughly a superset of
|
||||
/// MAPPINGS/OBSOLETE/EASTASIA/KSC/JOHAB.TXT.
|
||||
/// </summary>
|
||||
public enum WinFntId : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// ANSI encoding. A superset of ISO 8859-1.
|
||||
/// </summary>
|
||||
CP1252 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// This is used for font enumeration and font creation as a ‘don't care’ value. Valid font files don't contain
|
||||
/// this value. When querying for information about the character set of the font that is currently selected
|
||||
/// into a specified device context, this return value (of the related Windows API) simply denotes failure.
|
||||
/// </summary>
|
||||
Default = 1,
|
||||
|
||||
/// <summary>
|
||||
/// There is no known mapping table available.
|
||||
/// </summary>
|
||||
Symbol = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Mac Roman encoding.
|
||||
/// </summary>
|
||||
Mac = 77,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Japanese Shift-JIS (with minor deviations).
|
||||
/// </summary>
|
||||
CP932 = 128,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Korean Hangul KS C 5601-1987 (with different ordering and minor deviations).
|
||||
/// </summary>
|
||||
CP949 = 129,
|
||||
|
||||
/// <summary>
|
||||
/// Korean (Johab).
|
||||
/// </summary>
|
||||
CP1361 = 130,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of simplified Chinese GB 2312-1980 (with different ordering and minor deviations).
|
||||
/// </summary>
|
||||
CP936 = 134,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of traditional Chinese Big 5 ETen (with different ordering and minor deviations).
|
||||
/// </summary>
|
||||
CP950 = 136,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Greek ISO 8859-7 (with minor modifications).
|
||||
/// </summary>
|
||||
CP1253 = 161,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Turkish ISO 8859-9.
|
||||
/// </summary>
|
||||
CP1254 = 162,
|
||||
|
||||
/// <summary>
|
||||
/// For Vietnamese. This encoding doesn't cover all necessary characters.
|
||||
/// </summary>
|
||||
CP1258 = 163,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Hebrew ISO 8859-8 (with some modifications).
|
||||
/// </summary>
|
||||
CP1255 = 177,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Arabic ISO 8859-6 (with different ordering).
|
||||
/// </summary>
|
||||
CP1256 = 178,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Baltic ISO 8859-13 (with some deviations).
|
||||
/// </summary>
|
||||
CP1257 = 186,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Russian ISO 8859-5 (with different ordering).
|
||||
/// </summary>
|
||||
CP1251 = 204,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of Thai TIS 620 and ISO 8859-11.
|
||||
/// </summary>
|
||||
CP874 = 222,
|
||||
|
||||
/// <summary>
|
||||
/// A superset of East European ISO 8859-2 (with slightly different ordering).
|
||||
/// </summary>
|
||||
CP1250 = 238,
|
||||
|
||||
/// <summary><para>
|
||||
/// From Michael Pöttgen <michael@poettgen.de>:
|
||||
/// The ‘Windows Font Mapping’ article says that <see cref="WinFntId.Oem"/> is used for the charset of vector
|
||||
/// fonts, like ‘modern.fon’, ‘roman.fon’, and ‘script.fon’ on Windows.
|
||||
/// </para><para>
|
||||
/// The ‘CreateFont’ documentation says: The <see cref="WinFntId.Oem"/> value specifies a character set that is
|
||||
/// operating-system dependent.
|
||||
/// </para><para>
|
||||
/// The ‘IFIMETRICS’ documentation from the ‘Windows Driver Development Kit’ says: This font supports an
|
||||
/// OEM-specific character set. The OEM character set is system dependent.
|
||||
/// </para><para>
|
||||
/// In general OEM, as opposed to ANSI (i.e., cp1252), denotes the second default codepage that most
|
||||
/// international versions of Windows have. It is one of the OEM codepages from
|
||||
/// <see href="http://www.microsoft.com/globaldev/reference/cphome.mspx"/>, and is used for the ‘DOS boxes’, to
|
||||
/// support legacy applications. A German Windows version for example usually uses ANSI codepage 1252 and OEM
|
||||
/// codepage 850.
|
||||
/// </para></summary>
|
||||
Oem = 255
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// An exception that gets thrown when FreeType returns an error code.
|
||||
/// </summary>
|
||||
public class FreeTypeException : Exception
|
||||
{
|
||||
private Error error;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FreeTypeException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="error">The error returned by FreeType.</param>
|
||||
public FreeTypeException(Error error)
|
||||
: base("FreeType error: " + GetErrorMessage(error))
|
||||
{
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the FreeType error code that caused the exception.
|
||||
/// </summary>
|
||||
public Error Error
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.error;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetErrorMessage(Error err)
|
||||
{
|
||||
switch (err)
|
||||
{
|
||||
case Error.Ok: return "No error.";
|
||||
case Error.CannotOpenResource: return "Cannot open resource.";
|
||||
case Error.UnknownFileFormat: return "Unknown file format.";
|
||||
case Error.InvalidFileFormat: return "Broken file.";
|
||||
case Error.InvalidVersion: return "Invalid FreeType version.";
|
||||
case Error.LowerModuleVersion: return "Module version is too low.";
|
||||
case Error.InvalidArgument: return "Invalid argument.";
|
||||
case Error.UnimplementedFeature: return "Unimplemented feature.";
|
||||
case Error.InvalidTable: return "Broken table.";
|
||||
case Error.InvalidOffset: return "Broken offset within table.";
|
||||
case Error.ArrayTooLarge: return "Array allocation size too large.";
|
||||
case Error.InvalidGlyphIndex: return "Invalid glyph index.";
|
||||
case Error.InvalidCharacterCode: return "Invalid character code.";
|
||||
case Error.InvalidGlyphFormat: return "Unsupported glyph image format.";
|
||||
case Error.CannotRenderGlyph: return "Cannot render this glyph format.";
|
||||
case Error.InvalidOutline: return "Invalid outline.";
|
||||
case Error.InvalidComposite: return "Invalid composite glyph.";
|
||||
case Error.TooManyHints: return "Too many hints.";
|
||||
case Error.InvalidPixelSize: return "Invalid pixel size.";
|
||||
case Error.InvalidHandle: return "Invalid object handle.";
|
||||
case Error.InvalidLibraryHandle: return "Invalid library handle.";
|
||||
case Error.InvalidDriverHandle: return "Invalid module handle.";
|
||||
case Error.InvalidFaceHandle: return "Invalid face handle.";
|
||||
case Error.InvalidSizeHandle: return "Invalid size handle.";
|
||||
case Error.InvalidSlotHandle: return "Invalid glyph slot handle.";
|
||||
case Error.InvalidCharMapHandle: return "Invalid charmap handle.";
|
||||
case Error.InvalidCacheHandle: return "Invalid cache manager handle.";
|
||||
case Error.InvalidStreamHandle: return "Invalid stream handle.";
|
||||
case Error.TooManyDrivers: return "Too many modules.";
|
||||
case Error.TooManyExtensions: return "Too many extensions.";
|
||||
case Error.OutOfMemory: return "Out of memory.";
|
||||
case Error.UnlistedObject: return "Unlisted object.";
|
||||
case Error.CannotOpenStream: return "Cannot open stream.";
|
||||
case Error.InvalidStreamSeek: return "Invalid stream seek.";
|
||||
case Error.InvalidStreamSkip: return "Invalid stream skip.";
|
||||
case Error.InvalidStreamRead: return "Invalid stream read.";
|
||||
case Error.InvalidStreamOperation: return "Invalid stream operation.";
|
||||
case Error.InvalidFrameOperation: return "Invalid frame operation.";
|
||||
case Error.NestedFrameAccess: return "Nested frame access.";
|
||||
case Error.InvalidFrameRead: return "Invalid frame read.";
|
||||
case Error.RasterUninitialized: return "Raster uninitialized.";
|
||||
case Error.RasterCorrupted: return "Raster corrupted.";
|
||||
case Error.RasterOverflow: return "Raster overflow.";
|
||||
case Error.RasterNegativeHeight: return "Negative height while rastering.";
|
||||
case Error.TooManyCaches: return "Too many registered caches.";
|
||||
case Error.InvalidOpCode: return "Invalid opcode.";
|
||||
case Error.TooFewArguments: return "Too few arguments.";
|
||||
case Error.StackOverflow: return "Stack overflow.";
|
||||
case Error.CodeOverflow: return "Code overflow.";
|
||||
case Error.BadArgument: return "Bad argument.";
|
||||
case Error.DivideByZero: return "Division by zero.";
|
||||
case Error.InvalidReference: return "Invalid reference.";
|
||||
case Error.DebugOpCode: return "Found debug opcode.";
|
||||
case Error.EndfInExecStream: return "Found ENDF opcode in execution stream.";
|
||||
case Error.NestedDefs: return "Nested DEFS.";
|
||||
case Error.InvalidCodeRange: return "Invalid code range.";
|
||||
case Error.ExecutionTooLong: return "Execution context too long.";
|
||||
case Error.TooManyFunctionDefs: return "Too many function definitions.";
|
||||
case Error.TooManyInstructionDefs: return "Too many instruction definitions.";
|
||||
case Error.TableMissing: return "SFNT font table missing.";
|
||||
case Error.HorizHeaderMissing: return "Horizontal header (hhea) table missing.";
|
||||
case Error.LocationsMissing: return "Locations (loca) table missing.";
|
||||
case Error.NameTableMissing: return "Name table missing.";
|
||||
case Error.CMapTableMissing: return "Character map (cmap) table missing.";
|
||||
case Error.HmtxTableMissing: return "Horizontal metrics (hmtx) table missing.";
|
||||
case Error.PostTableMissing: return "PostScript (post) table missing.";
|
||||
case Error.InvalidHorizMetrics: return "Invalid horizontal metrics.";
|
||||
case Error.InvalidCharMapFormat: return "Invalid character map (cmap) format.";
|
||||
case Error.InvalidPPem: return "Invalid ppem value.";
|
||||
case Error.InvalidVertMetrics: return "Invalid vertical metrics.";
|
||||
case Error.CouldNotFindContext: return "Could not find context.";
|
||||
case Error.InvalidPostTableFormat: return "Invalid PostScript (post) table format.";
|
||||
case Error.InvalidPostTable: return "Invalid PostScript (post) table.";
|
||||
case Error.SyntaxError: return "Opcode syntax error.";
|
||||
case Error.StackUnderflow: return "Argument stack underflow.";
|
||||
case Error.Ignore: return "Ignore this error.";
|
||||
case Error.NoUnicodeGlyphName: return "No Unicode glyph name found.";
|
||||
case Error.MissingStartfontField: return "`STARTFONT' field missing.";
|
||||
case Error.MissingFontField: return "`FONT' field missing.";
|
||||
case Error.MissingSizeField: return "`SIZE' field missing.";
|
||||
case Error.MissingFontboudingboxField: return "`FONTBOUNDINGBOX' field missing.";
|
||||
case Error.MissingCharsField: return "`CHARS' field missing.";
|
||||
case Error.MissingStartcharField: return "`STARTCHAR' field missing.";
|
||||
case Error.MissingEncodingField: return "`ENCODING' field missing.";
|
||||
case Error.MissingBbxField: return "`BBX' field missing.";
|
||||
case Error.BbxTooBig: return "`BBX' too big.";
|
||||
case Error.CorruptedFontHeader: return "Font header corrupted or missing fields.";
|
||||
case Error.CorruptedFontGlyphs: return "Font glyphs corrupted or missing fields.";
|
||||
default: return "Encountered an unknown error. Most likely this is a new error that hasn't been included in SharpFont yet. Error:" + (int)err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of values and/or bit-flags returned by the FT_Get_Gasp function.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// The bit-flags <see cref="Gasp.DoGridfit"/> and <see cref="Gasp.DoGray"/> are to be used for standard font
|
||||
/// rasterization only. Independently of that, <see cref="Gasp.SymmetricSmoothing"/> and
|
||||
/// <see cref="Gasp.SymmetricGridfit"/> are to be used if ClearType is enabled (and <see cref="Gasp.DoGridfit"/>
|
||||
/// and <see cref="Gasp.DoGray"/> are consequently ignored).
|
||||
/// </para><para>
|
||||
/// ‘ClearType’ is Microsoft's implementation of LCD rendering, partly protected by patents.
|
||||
/// </para></remarks>
|
||||
[Flags]
|
||||
public enum Gasp
|
||||
{
|
||||
/// <summary>
|
||||
/// This special value means that there is no GASP table in this face. It is up to the client to decide what to
|
||||
/// do.
|
||||
/// </summary>
|
||||
NoTable = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Grid-fitting and hinting should be performed at the specified ppem. This really means TrueType bytecode
|
||||
/// interpretation. If this bit is not set, no hinting gets applied.
|
||||
/// </summary>
|
||||
DoGridfit = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// Anti-aliased rendering should be performed at the specified ppem. If not set, do monochrome rendering.
|
||||
/// </summary>
|
||||
DoGray = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// If set, smoothing along multiple axes must be used with ClearType.
|
||||
/// </summary>
|
||||
SymmetricSmoothing = 0x08,
|
||||
|
||||
/// <summary>
|
||||
/// Grid-fitting must be used with ClearType's symmetric smoothing.
|
||||
/// </summary>
|
||||
SymmetricGridfit = 0x10
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Describe a function used to destroy the ‘client’ data of any FreeType object. See the description of the
|
||||
/// <see cref="Generic"/> type for details of usage.
|
||||
/// </summary>
|
||||
/// <param name="object">
|
||||
/// The address of the FreeType object which is under finalization. Its client data is accessed through its
|
||||
/// ‘generic’ field.
|
||||
/// </param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void GenericFinalizer(IntPtr @object);
|
||||
|
||||
/// <summary><para>
|
||||
/// Client applications often need to associate their own data to a variety of FreeType core objects. For example,
|
||||
/// a text layout API might want to associate a glyph cache to a given size object.
|
||||
/// </para><para>
|
||||
/// Most FreeType object contains a ‘generic’ field, of type <see cref="Generic"/>, which usage is left to client
|
||||
/// applications and font servers.
|
||||
/// </para><para>
|
||||
/// It can be used to store a pointer to client-specific data, as well as the address of a ‘finalizer’ function,
|
||||
/// which will be called by FreeType when the object is destroyed (for example, the previous client example would
|
||||
/// put the address of the glyph cache destructor in the ‘finalizer’ field).
|
||||
/// </para></summary>
|
||||
[Obsolete("Use the Tag property and Disposed event.")]
|
||||
public class Generic
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private GenericRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Generic"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">
|
||||
/// A typeless pointer to some client data. The data it cointains must stay fixed until finalizer is called.
|
||||
/// </param>
|
||||
/// <param name="finalizer">A delegate that gets called when the contained object gets finalized.</param>
|
||||
public Generic(IntPtr data, GenericFinalizer finalizer)
|
||||
{
|
||||
rec.data = data;
|
||||
//rec.finalizer = finalizer;
|
||||
}
|
||||
|
||||
internal Generic(GenericRec genInternal)
|
||||
{
|
||||
rec = genInternal;
|
||||
}
|
||||
|
||||
internal Generic(IntPtr reference)
|
||||
{
|
||||
rec = PInvokeHelper.PtrToStructure<GenericRec>(reference);
|
||||
}
|
||||
|
||||
internal Generic(IntPtr reference, int offset)
|
||||
: this(new IntPtr(reference.ToInt64() + offset))
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of a <see cref="Generic"/>, in bytes.
|
||||
/// </summary>
|
||||
public static int SizeInBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.SizeOf(typeof(GenericRec));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a typeless pointer to any client-specified data. This field is completely ignored by the
|
||||
/// FreeType library.
|
||||
/// </summary>
|
||||
public IntPtr Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.data;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
rec.data = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a pointer to a <see cref="GenericFinalizer"/> function, which will be called when the object
|
||||
/// is destroyed. If this field is set to NULL, no code will be called.
|
||||
/// </summary>
|
||||
/*public GenericFinalizer Finalizer
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.finalizer;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
rec.finalizer = value;
|
||||
}
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
//TODO make this private and build it into the setters if the reference isn't IntPtr.Zero.
|
||||
internal void WriteToUnmanagedMemory(IntPtr location)
|
||||
{
|
||||
Marshal.WriteIntPtr(location, rec.data);
|
||||
//Marshal.WriteIntPtr(location, IntPtr.Size, Marshal.GetFunctionPointerForDelegate(rec.finalizer));
|
||||
Marshal.WriteIntPtr(location, IntPtr.Size, rec.finalizer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,444 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// The root glyph structure contains a given glyph image plus its advance width in 16.16 fixed float format.
|
||||
/// </summary>
|
||||
public sealed class Glyph : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private bool disposed;
|
||||
|
||||
private IntPtr reference;
|
||||
private GlyphRec rec;
|
||||
|
||||
private Library parentLibrary;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Glyph(IntPtr reference, Library parentLibrary)
|
||||
{
|
||||
Reference = reference;
|
||||
|
||||
this.parentLibrary = parentLibrary;
|
||||
parentLibrary.AddChildGlyph(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the Glyph class.
|
||||
/// </summary>
|
||||
~Glyph()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the object has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return disposed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the FreeType library object.
|
||||
/// </summary>
|
||||
public Library Library
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return parentLibrary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format of the glyph's image.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public GlyphFormat Format
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Format", "Cannot access a disposed object.");
|
||||
|
||||
return rec.format;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a 16.16 vector that gives the glyph's advance width.
|
||||
/// </summary>
|
||||
public FTVector Advance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Advance", "Cannot access a disposed object.");
|
||||
|
||||
return rec.advance;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<GlyphRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
/// Downcasts a <see cref="Glyph"/> to a <see cref="BitmapGlyph"/>
|
||||
/// </summary>
|
||||
/// <param name="g">A <see cref="Glyph"/>.</param>
|
||||
/// <returns>A <see cref="BitmapGlyph"/>.</returns>
|
||||
/// <exception cref="InvalidCastException">
|
||||
/// If the <see cref="Glyph"/>'s format is not <see cref="GlyphFormat.Bitmap"/>.
|
||||
/// </exception>
|
||||
public static explicit operator BitmapGlyph(Glyph g)
|
||||
{
|
||||
if (g.Format == GlyphFormat.Bitmap)
|
||||
return new BitmapGlyph(g);
|
||||
else
|
||||
throw new InvalidCastException("The glyph's format is not GlyphFormat.Bitmap.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downcasts a <see cref="Glyph"/> to a <see cref="OutlineGlyph"/>
|
||||
/// </summary>
|
||||
/// <param name="g">A <see cref="Glyph"/>.</param>
|
||||
/// <returns>A <see cref="OutlineGlyph"/>.</returns>
|
||||
/// <exception cref="InvalidCastException">
|
||||
/// If the <see cref="Glyph"/>'s format is not <see cref="GlyphFormat.Outline"/>.
|
||||
/// </exception>
|
||||
public static explicit operator OutlineGlyph(Glyph g)
|
||||
{
|
||||
if (g.Format == GlyphFormat.Outline)
|
||||
return new OutlineGlyph(g);
|
||||
else
|
||||
throw new InvalidCastException("The glyph's format is not GlyphFormat.Outline.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// CLS-compliant equivalent of an explicit cast to <see cref="BitmapGlyph"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="BitmapGlyph"/>.</returns>
|
||||
public BitmapGlyph ToBitmapGlyph()
|
||||
{
|
||||
return (BitmapGlyph)this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CLS-compliant equivalent of an explicit cast to <see cref="OutlineGlyph"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="OutlineGlyph"/>.</returns>
|
||||
public OutlineGlyph ToOutlineGlyph()
|
||||
{
|
||||
return (OutlineGlyph)this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A function used to copy a glyph image. Note that the created <see cref="Glyph"/> object must be released
|
||||
/// with <see cref="Glyph.Dispose()"/>.
|
||||
/// </summary>
|
||||
/// <returns>A handle to the target glyph object. 0 in case of error.</returns>
|
||||
public Glyph Copy()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr glyphRef;
|
||||
|
||||
Error err = FT.FT_Glyph_Copy(Reference, out glyphRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Glyph(glyphRef, Library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform a glyph image if its format is scalable.
|
||||
/// </summary>
|
||||
/// <param name="matrix">A pointer to a 2x2 matrix to apply.</param>
|
||||
/// <param name="delta">
|
||||
/// A pointer to a 2d vector to apply. Coordinates are expressed in 1/64th of a pixel.
|
||||
/// </param>
|
||||
public void Transform(FTMatrix matrix, FTVector delta)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Glyph_Transform(Reference, ref matrix, ref delta);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary><para>
|
||||
/// Return a glyph's ‘control box’. The control box encloses all the outline's points, including Bézier control
|
||||
/// points. Though it coincides with the exact bounding box for most glyphs, it can be slightly larger in some
|
||||
/// situations (like when rotating an outline which contains Bézier outside arcs).
|
||||
/// </para><para>
|
||||
/// Computing the control box is very fast, while getting the bounding box can take much more time as it needs
|
||||
/// to walk over all segments and arcs in the outline. To get the latter, you can use the ‘ftbbox’ component
|
||||
/// which is dedicated to this single task.
|
||||
/// </para></summary>
|
||||
/// <remarks><para>
|
||||
/// Coordinates are relative to the glyph origin, using the y upwards convention.
|
||||
/// </para><para>
|
||||
/// If the glyph has been loaded with <see cref="LoadFlags.NoScale"/>, ‘bbox_mode’ must be set to
|
||||
/// <see cref="GlyphBBoxMode.Unscaled"/> to get unscaled font units in 26.6 pixel format. The value
|
||||
/// <see cref="GlyphBBoxMode.Subpixels"/> is another name for this constant.
|
||||
/// </para><para>
|
||||
/// If the font is tricky and the glyph has been loaded with <see cref="LoadFlags.NoScale"/>, the resulting
|
||||
/// CBox is meaningless. To get reasonable values for the CBox it is necessary to load the glyph at a large
|
||||
/// ppem value (so that the hinting instructions can properly shift and scale the subglyphs), then extracting
|
||||
/// the CBox which can be eventually converted back to font units.
|
||||
/// </para><para>
|
||||
/// Note that the maximum coordinates are exclusive, which means that one can compute the width and height of
|
||||
/// the glyph image (be it in integer or 26.6 pixels) as:
|
||||
/// </para><para>
|
||||
/// <code>
|
||||
/// width = bbox.xMax - bbox.xMin;
|
||||
/// height = bbox.yMax - bbox.yMin;
|
||||
/// </code>
|
||||
/// </para><para>
|
||||
/// Note also that for 26.6 coordinates, if ‘bbox_mode’ is set to <see cref="GlyphBBoxMode.Gridfit"/>, the
|
||||
/// coordinates will also be grid-fitted, which corresponds to:
|
||||
/// </para><para>
|
||||
/// <code>
|
||||
/// bbox.xMin = FLOOR(bbox.xMin);
|
||||
/// bbox.yMin = FLOOR(bbox.yMin);
|
||||
/// bbox.xMax = CEILING(bbox.xMax);
|
||||
/// bbox.yMax = CEILING(bbox.yMax);
|
||||
/// </code>
|
||||
/// </para><para>
|
||||
/// To get the bbox in pixel coordinates, set ‘bbox_mode’ to <see cref="GlyphBBoxMode.Truncate"/>.
|
||||
/// </para><para>
|
||||
/// To get the bbox in grid-fitted pixel coordinates, set ‘bbox_mode’ to <see cref="GlyphBBoxMode.Pixels"/>.
|
||||
/// </para></remarks>
|
||||
/// <param name="mode">The mode which indicates how to interpret the returned bounding box values.</param>
|
||||
/// <returns>
|
||||
/// The glyph coordinate bounding box. Coordinates are expressed in 1/64th of pixels if it is grid-fitted.
|
||||
/// </returns>
|
||||
[CLSCompliant(false)]
|
||||
public BBox GetCBox(GlyphBBoxMode mode)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
BBox box;
|
||||
FT.FT_Glyph_Get_CBox(Reference, mode, out box);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given glyph object to a bitmap glyph object.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// This function does nothing if the glyph format isn't scalable.
|
||||
/// </para><para>
|
||||
/// The glyph image is translated with the ‘origin’ vector before rendering.
|
||||
/// </para><para>
|
||||
/// The first parameter is a pointer to an <see cref="Glyph"/> handle, that will be replaced by this function
|
||||
/// (with newly allocated data). Typically, you would use (omitting error handling):
|
||||
/// </para><para>
|
||||
/// --sample code ommitted--
|
||||
/// </para></remarks>
|
||||
/// <param name="renderMode">An enumeration that describes how the data is rendered.</param>
|
||||
/// <param name="origin">
|
||||
/// A pointer to a vector used to translate the glyph image before rendering. Can be 0 (if no translation). The
|
||||
/// origin is expressed in 26.6 pixels.
|
||||
/// </param>
|
||||
/// <param name="destroy">
|
||||
/// A boolean that indicates that the original glyph image should be destroyed by this function. It is never
|
||||
/// destroyed in case of error.
|
||||
/// </param>
|
||||
public void ToBitmap(RenderMode renderMode, FTVector26Dot6 origin, bool destroy)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr glyphRef = Reference;
|
||||
Error err = FT.FT_Glyph_To_Bitmap(ref glyphRef, renderMode, ref origin, destroy);
|
||||
|
||||
Reference = glyphRef;
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#region Glyph Stroker
|
||||
|
||||
/// <summary>
|
||||
/// Stroke a given outline glyph object with a given stroker.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The source glyph is untouched in case of error.
|
||||
/// </remarks>
|
||||
/// <param name="stroker">A stroker handle.</param>
|
||||
/// <param name="destroy">A Boolean. If 1, the source glyph object is destroyed on success.</param>
|
||||
/// <returns>New glyph handle.</returns>
|
||||
public Glyph Stroke(Stroker stroker, bool destroy)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
if (stroker == null)
|
||||
throw new ArgumentNullException("stroker");
|
||||
|
||||
IntPtr sourceRef = Reference;
|
||||
Error err = FT.FT_Glyph_Stroke(ref sourceRef, stroker.Reference, destroy);
|
||||
|
||||
if (destroy && err == Error.Ok)
|
||||
{
|
||||
//if FT_Glyph_Stroke destroys the glyph, keep the C# side synchronized.
|
||||
disposed = true;
|
||||
reference = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
//check if the pointer didn't change.
|
||||
if (sourceRef == Reference)
|
||||
return this;
|
||||
else
|
||||
return new Glyph(sourceRef, Library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stroke a given outline glyph object with a given stroker, but only return either its inside or outside
|
||||
/// border.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The source glyph is untouched in case of error.
|
||||
/// </remarks>
|
||||
/// <param name="stroker">A stroker handle.</param>
|
||||
/// <param name="inside">A Boolean. If 1, return the inside border, otherwise the outside border.</param>
|
||||
/// <param name="destroy">A Boolean. If 1, the source glyph object is destroyed on success.</param>
|
||||
/// <returns>New glyph handle.</returns>
|
||||
public Glyph StrokeBorder(Stroker stroker, bool inside, bool destroy)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Glyph", "Cannot access a disposed object.");
|
||||
|
||||
if (stroker == null)
|
||||
throw new ArgumentNullException("stroker");
|
||||
|
||||
IntPtr sourceRef = Reference;
|
||||
Error err = FT.FT_Glyph_StrokeBorder(ref sourceRef, stroker.Reference, inside, destroy);
|
||||
|
||||
if (destroy && err == Error.Ok)
|
||||
{
|
||||
//if FT_Glyph_Stroke destroys the glyph, keep the C# side synchronized.
|
||||
disposed = true;
|
||||
reference = IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
//check if the pointer didn't change.
|
||||
if (sourceRef == Reference)
|
||||
return this;
|
||||
else
|
||||
return new Glyph(sourceRef, Library);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the Glyph.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
FT.FT_Done_Glyph(reference);
|
||||
|
||||
// removes itself from the parent Library, with a check to prevent this from happening when Library is
|
||||
// being disposed (Library disposes all it's children with a foreach loop, this causes an
|
||||
// InvalidOperationException for modifying a collection during enumeration)
|
||||
if (!parentLibrary.IsDisposed)
|
||||
parentLibrary.RemoveChildGlyph(this);
|
||||
|
||||
reference = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// The mode how the values of <see cref="Glyph.GetCBox"/> are returned.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public enum GlyphBBoxMode : uint
|
||||
{
|
||||
/// <summary>Return unscaled font units.</summary>
|
||||
Unscaled = 0,
|
||||
|
||||
/// <summary>Return unfitted 26.6 coordinates.</summary>
|
||||
Subpixels = 0,
|
||||
|
||||
/// <summary>Return grid-fitted 26.6 coordinates.</summary>
|
||||
Gridfit = 1,
|
||||
|
||||
/// <summary>Return coordinates in integer pixels.</summary>
|
||||
Truncate = 2,
|
||||
|
||||
/// <summary>Return grid-fitted pixel coordinates.</summary>
|
||||
Pixels = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumeration type used to describe the format of a given glyph image. Note that this version of FreeType only
|
||||
/// supports two image formats, even though future font drivers will be able to register their own format.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public enum GlyphFormat : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// The value 0 is reserved.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The glyph image is a composite of several other images. This format is only used with
|
||||
/// <see cref="LoadFlags.NoRecurse"/>, and is used to report compound glyphs (like accented characters).
|
||||
/// </summary>
|
||||
Composite = ('c' << 24 | 'o' << 16 | 'm' << 8 | 'p'),
|
||||
|
||||
/// <summary>
|
||||
/// The glyph image is a bitmap, and can be described as an <see cref="FTBitmap"/>. You generally need to
|
||||
/// access the ‘bitmap’ field of the <see cref="GlyphSlot"/> structure to read it.
|
||||
/// </summary>
|
||||
Bitmap = ('b' << 24 | 'i' << 16 | 't' << 8 | 's'),
|
||||
|
||||
/// <summary>
|
||||
/// The glyph image is a vectorial outline made of line segments and Bézier arcs; it can be described as an
|
||||
/// <see cref="Outline"/>; you generally want to access the ‘outline’ field of the <see cref="GlyphSlot"/>
|
||||
/// structure to read it.
|
||||
/// </summary>
|
||||
Outline = ('o' << 24 | 'u' << 16 | 't' << 8 | 'l'),
|
||||
|
||||
/// <summary>
|
||||
/// The glyph image is a vectorial path with no inside and outside contours. Some Type 1 fonts, like those in
|
||||
/// the Hershey family, contain glyphs in this format. These are described as <see cref="Outline"/>, but
|
||||
/// FreeType isn't currently capable of rendering them correctly.
|
||||
/// </summary>
|
||||
Plotter = ('p' << 24 | 'l' << 16 | 'o' << 8 | 't')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to model the metrics of a single glyph. The values are expressed in 26.6 fractional pixel
|
||||
/// format; if the flag <see cref="LoadFlags.NoScale"/> has been used while loading the glyph, values are expressed
|
||||
/// in font units instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If not disabled with <see cref="LoadFlags.NoHinting"/>, the values represent dimensions of the hinted glyph (in
|
||||
/// case hinting is applicable).
|
||||
/// </remarks>
|
||||
public sealed class GlyphMetrics
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private GlyphMetricsRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal GlyphMetrics(IntPtr reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
internal GlyphMetrics(GlyphMetricsRec glyphMetInt)
|
||||
{
|
||||
this.rec = glyphMetInt;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the glyph's width. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
|
||||
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.width);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the glyph's height. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
|
||||
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left side bearing for horizontal layout. If getting metrics from a face loaded with
|
||||
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 HorizontalBearingX
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.horiBearingX);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top side bearing for horizontal layout. If getting metrics from a face loaded with
|
||||
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 HorizontalBearingY
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.horiBearingY);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the advance width for horizontal layout. If getting metrics from a face loaded with
|
||||
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 HorizontalAdvance
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.horiAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left side bearing for vertical layout. If getting metrics from a face loaded with
|
||||
/// <see cref="LoadFlags.NoScale"/>, call <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 VerticalBearingX
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.vertBearingX);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the top side bearing for vertical layout. Larger positive values mean further below the vertical glyph
|
||||
/// origin. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
|
||||
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 VerticalBearingY
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.vertBearingY);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the advance height for vertical layout. Positive values mean the glyph has a positive advance
|
||||
/// downward. If getting metrics from a face loaded with <see cref="LoadFlags.NoScale"/>, call
|
||||
/// <see cref="Fixed26Dot6.Value"/> to get the unscaled value.
|
||||
/// </summary>
|
||||
public Fixed26Dot6 VerticalAdvance
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed26Dot6.FromRawValue((int)rec.vertAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<GlyphMetricsRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// FreeType root glyph slot class structure. A glyph slot is a container where individual glyphs can be loaded, be
|
||||
/// they in outline or bitmap format.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// If <see cref="SharpFont.Face.LoadGlyph"/> is called with default flags (see <see cref="LoadFlags.Default"/>)
|
||||
/// the glyph image is loaded in the glyph slot in its native format (e.g., an outline glyph for TrueType and Type
|
||||
/// 1 formats).
|
||||
/// </para><para>
|
||||
/// This image can later be converted into a bitmap by calling <see cref="RenderGlyph"/>. This function finds the
|
||||
/// current renderer for the native image's format, then invokes it.
|
||||
/// </para><para>
|
||||
/// The renderer is in charge of transforming the native image through the slot's face transformation fields, then
|
||||
/// converting it into a bitmap that is returned in ‘slot->bitmap’.
|
||||
/// </para><para>
|
||||
/// Note that ‘slot->bitmap_left’ and ‘slot->bitmap_top’ are also used to specify the position of the bitmap
|
||||
/// relative to the current pen position (e.g., coordinates (0,0) on the baseline). Of course, ‘slot->format’ is
|
||||
/// also changed to <see cref="GlyphFormat.Bitmap"/>.
|
||||
/// </para></remarks>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// FT_Pos origin_x = 0;
|
||||
/// FT_Pos prev_rsb_delta = 0;
|
||||
///
|
||||
///
|
||||
/// for all glyphs do
|
||||
/// <compute kern between current and previous glyph and add it to
|
||||
/// `origin_x'>
|
||||
///
|
||||
/// <load glyph with `FT_Load_Glyph'>
|
||||
///
|
||||
/// if ( prev_rsb_delta - face->glyph->lsb_delta >= 32 )
|
||||
/// origin_x -= 64;
|
||||
/// else if ( prev_rsb_delta - face->glyph->lsb_delta < -32 )
|
||||
/// origin_x += 64;
|
||||
///
|
||||
/// prev_rsb_delta = face->glyph->rsb_delta;
|
||||
///
|
||||
/// <save glyph image, or render glyph, or ...>
|
||||
///
|
||||
/// origin_x += face->glyph->advance.x;
|
||||
/// endfor
|
||||
/// </code>
|
||||
/// </example>
|
||||
public sealed class GlyphSlot
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
private GlyphSlotRec rec;
|
||||
|
||||
private Face parentFace;
|
||||
private Library parentLibrary;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal GlyphSlot(IntPtr reference, Face parentFace, Library parentLibrary)
|
||||
{
|
||||
Reference = reference;
|
||||
this.parentFace = parentFace;
|
||||
this.parentLibrary = parentLibrary;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the FreeType library instance this slot belongs to.
|
||||
/// </summary>
|
||||
public Library Library
|
||||
{
|
||||
get
|
||||
{
|
||||
return parentLibrary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the parent face object.
|
||||
/// </summary>
|
||||
public Face Face
|
||||
{
|
||||
get
|
||||
{
|
||||
return parentFace;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next <see cref="GlyphSlot"/>. In some cases (like some font tools), several glyph slots per face
|
||||
/// object can be a good thing. As this is rare, the glyph slots are listed through a direct, single-linked
|
||||
/// list using its ‘next’ field.
|
||||
/// </summary>
|
||||
public GlyphSlot Next
|
||||
{
|
||||
get
|
||||
{
|
||||
return new GlyphSlot(rec.next, parentFace, parentLibrary);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a typeless pointer which is unused by the FreeType library or any of its drivers. It can be used by
|
||||
/// client applications to link their own data to each glyph slot object.
|
||||
/// </summary>
|
||||
[Obsolete("Use the Tag property, Dispose callback not handled currently.")]
|
||||
public Generic Generic
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Generic(rec.generic);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary><para>
|
||||
/// Gets the metrics of the last loaded glyph in the slot. The returned values depend on the last load flags
|
||||
/// (see the <see cref="SharpFont.Face.LoadGlyph"/> API function) and can be expressed either in 26.6
|
||||
/// fractional pixels or font units.
|
||||
/// </para><para>
|
||||
/// Note that even when the glyph image is transformed, the metrics are not.
|
||||
/// </para></summary>
|
||||
public GlyphMetrics Metrics
|
||||
{
|
||||
get
|
||||
{
|
||||
return new GlyphMetrics(rec.metrics);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the advance width of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless
|
||||
/// <see cref="LoadFlags.LinearDesign"/> is set when loading the glyph. This field can be important to perform
|
||||
/// correct WYSIWYG layout. Only relevant for outline glyphs.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 LinearHorizontalAdvance
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)rec.linearHoriAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the advance height of the unhinted glyph. Its value is expressed in 16.16 fractional pixels, unless
|
||||
/// <see cref="LoadFlags.LinearDesign"/> is set when loading the glyph. This field can be important to perform
|
||||
/// correct WYSIWYG layout. Only relevant for outline glyphs.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 LinearVerticalAdvance
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)rec.linearVertAdvance);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the advance. This shorthand is, depending on <see cref="LoadFlags.IgnoreTransform"/>, the transformed
|
||||
/// advance width for the glyph (in 26.6 fractional pixel format). As specified with
|
||||
/// <see cref="LoadFlags.VerticalLayout"/>, it uses either the ‘horiAdvance’ or the ‘vertAdvance’ value of
|
||||
/// ‘metrics’ field.
|
||||
/// </summary>
|
||||
public FTVector26Dot6 Advance
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.advance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the glyph format. This field indicates the format of the image contained in the glyph slot. Typically
|
||||
/// <see cref="GlyphFormat.Bitmap"/>, <see cref="GlyphFormat.Outline"/>, or
|
||||
/// <see cref="GlyphFormat.Composite"/>, but others are possible.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public GlyphFormat Format
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.format;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmap. This field is used as a bitmap descriptor when the slot format is
|
||||
/// <see cref="GlyphFormat.Bitmap"/>. Note that the address and content of the bitmap buffer can change between
|
||||
/// calls of <see cref="SharpFont.Face.LoadGlyph"/> and a few other functions.
|
||||
/// </summary>
|
||||
public FTBitmap Bitmap
|
||||
{
|
||||
get
|
||||
{
|
||||
return new FTBitmap(PInvokeHelper.AbsoluteOffsetOf<GlyphSlotRec>(Reference, "bitmap"), rec.bitmap, parentLibrary);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmap's left bearing expressed in integer pixels. Of course, this is only valid if the format is
|
||||
/// <see cref="GlyphFormat.Bitmap"/>.
|
||||
/// </summary>
|
||||
public int BitmapLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.bitmap_left;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmap's top bearing expressed in integer pixels. Remember that this is the distance from the
|
||||
/// baseline to the top-most glyph scanline, upwards y coordinates being positive.
|
||||
/// </summary>
|
||||
public int BitmapTop
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.bitmap_top;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the outline descriptor for the current glyph image if its format is <see cref="GlyphFormat.Outline"/>.
|
||||
/// Once a glyph is loaded, ‘outline’ can be transformed, distorted, embolded, etc. However, it must not be
|
||||
/// freed.
|
||||
/// </summary>
|
||||
public Outline Outline
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Outline(PInvokeHelper.AbsoluteOffsetOf<GlyphSlotRec>(Reference, "outline"), rec.outline);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of subglyphs in a composite glyph. This field is only valid for the composite glyph format
|
||||
/// that should normally only be loaded with the <see cref="LoadFlags.NoRecurse"/> flag. For now this is
|
||||
/// internal to FreeType.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint SubglyphsCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.num_subglyphs;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an array of subglyph descriptors for composite glyphs. There are ‘num_subglyphs’ elements in there.
|
||||
/// Currently internal to FreeType.
|
||||
/// </summary>
|
||||
public SubGlyph[] Subglyphs
|
||||
{
|
||||
get
|
||||
{
|
||||
int count = (int)SubglyphsCount;
|
||||
|
||||
if (count == 0)
|
||||
return null;
|
||||
|
||||
SubGlyph[] subglyphs = new SubGlyph[count];
|
||||
IntPtr array = rec.subglyphs;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
subglyphs[i] = new SubGlyph((IntPtr)(array.ToInt64() + IntPtr.Size * i));
|
||||
}
|
||||
|
||||
return subglyphs;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the control data. Certain font drivers can also return the control data for a given glyph image (e.g.
|
||||
/// TrueType bytecode, Type 1 charstrings, etc.). This field is a pointer to such data.
|
||||
/// </summary>
|
||||
public IntPtr ControlData
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.control_data;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length in bytes of the control data.
|
||||
/// </summary>
|
||||
public int ControlLength
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)rec.control_len;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the difference between hinted and unhinted left side bearing while autohinting is active. Zero
|
||||
/// otherwise.
|
||||
/// </summary>
|
||||
public int DeltaLsb
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)rec.lsb_delta;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the difference between hinted and unhinted right side bearing while autohinting is active. Zero
|
||||
/// otherwise.
|
||||
/// </summary>
|
||||
public int DeltaRsb
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)rec.rsb_delta;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an object used to identify this instance of <see cref="GlyphSlot"/>. This object will not be
|
||||
/// modified or accessed internally.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a replacement for FT_Generic in FreeType. If you are retrieving the same object multiple times
|
||||
/// from functions, this object will not appear in new copies.
|
||||
/// </remarks>
|
||||
public object Tag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets other data. Really wicked formats can use this pointer to present their own glyph image to client
|
||||
/// applications. Note that the application needs to know about the image format.
|
||||
/// </summary>
|
||||
public IntPtr Other
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.other;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<GlyphSlotRec>(reference);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#region Base Interface
|
||||
|
||||
/// <summary>
|
||||
/// Convert a given glyph image to a bitmap. It does so by inspecting the glyph image format, finding the
|
||||
/// relevant renderer, and invoking it.
|
||||
/// </summary>
|
||||
/// <param name="mode">This is the render mode used to render the glyph image into a bitmap.</param>
|
||||
public void RenderGlyph(RenderMode mode)
|
||||
{
|
||||
Error err = FT.FT_Render_Glyph(Reference, mode);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a description of a given subglyph. Only use it if <see cref="GlyphSlot.Format"/> is
|
||||
/// <see cref="GlyphFormat.Composite"/>; an error is returned otherwise.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The values of ‘*p_arg1’, ‘*p_arg2’, and ‘*p_transform’ must be interpreted depending on the flags returned
|
||||
/// in ‘*p_flags’. See the TrueType specification for details.
|
||||
/// </remarks>
|
||||
/// <param name="subIndex">
|
||||
/// The index of the subglyph. Must be less than <see cref="GlyphSlot.SubglyphsCount"/>.
|
||||
/// </param>
|
||||
/// <param name="index">The glyph index of the subglyph.</param>
|
||||
/// <param name="flags">The subglyph flags, see <see cref="SubGlyphFlags"/>.</param>
|
||||
/// <param name="arg1">The subglyph's first argument (if any).</param>
|
||||
/// <param name="arg2">The subglyph's second argument (if any).</param>
|
||||
/// <param name="transform">The subglyph transformation (if any).</param>
|
||||
[CLSCompliant(false)]
|
||||
public void GetSubGlyphInfo(uint subIndex, out int index, out SubGlyphFlags flags, out int arg1, out int arg2, out FTMatrix transform)
|
||||
{
|
||||
Error err = FT.FT_Get_SubGlyph_Info(Reference, subIndex, out index, out flags, out arg1, out arg2, out transform);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Glyph Management
|
||||
|
||||
/// <summary>
|
||||
/// A function used to extract a glyph image from a slot. Note that the created <see cref="Glyph"/> object must
|
||||
/// be released with <see cref="Glyph.Dispose()"/>.
|
||||
/// </summary>
|
||||
/// <returns>A handle to the glyph object.</returns>
|
||||
public Glyph GetGlyph()
|
||||
{
|
||||
IntPtr glyphRef;
|
||||
Error err = FT.FT_Get_Glyph(Reference, out glyphRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Glyph(glyphRef, Library);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bitmap Handling
|
||||
|
||||
/// <summary>
|
||||
/// Make sure that a glyph slot owns ‘slot->bitmap’.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function is to be used in combination with <see cref="FTBitmap.Embolden"/>.
|
||||
/// </remarks>
|
||||
public void OwnBitmap()
|
||||
{
|
||||
Error err = FT.FT_GlyphSlot_Own_Bitmap(Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// The data exchange structure for the glyph-to-script-map property.
|
||||
/// </summary>
|
||||
public class GlyphToScriptMapProperty
|
||||
{
|
||||
private GlyphToScriptMapPropertyRec rec;
|
||||
private Face face;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GlyphToScriptMapProperty"/> class.
|
||||
/// </summary>
|
||||
/// <param name="face">The face to apply the property to.</param>
|
||||
public GlyphToScriptMapProperty(Face face)
|
||||
{
|
||||
Face = face;
|
||||
}
|
||||
|
||||
internal GlyphToScriptMapProperty(GlyphToScriptMapPropertyRec rec, Face face)
|
||||
{
|
||||
this.rec = rec;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the associated face.
|
||||
/// </summary>
|
||||
public Face Face
|
||||
{
|
||||
get
|
||||
{
|
||||
return face;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
face = value;
|
||||
rec.face = face.Reference;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the associated map.
|
||||
/// </summary>
|
||||
public IntPtr Map
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.map;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
rec.map = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal GlyphToScriptMapPropertyRec Rec
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// The data exchange structure for the increase-x-height property.
|
||||
/// </summary>
|
||||
public class IncreaseXHeightProperty
|
||||
{
|
||||
private IncreaseXHeightPropertyRec rec;
|
||||
private Face face;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IncreaseXHeightProperty"/> class.
|
||||
/// </summary>
|
||||
/// <param name="face">The face to increase the X height of.</param>
|
||||
public IncreaseXHeightProperty(Face face)
|
||||
{
|
||||
this.rec.face = face.Reference;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
internal IncreaseXHeightProperty(IncreaseXHeightPropertyRec rec, Face face)
|
||||
{
|
||||
this.rec = rec;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the associated face.
|
||||
/// </summary>
|
||||
public Face Face
|
||||
{
|
||||
get
|
||||
{
|
||||
return face;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
face = value;
|
||||
rec.face = face.Reference;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the limit property.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Limit
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.limit;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
rec.limit = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal IncreaseXHeightPropertyRec Rec
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct BitmapGlyphRec
|
||||
{
|
||||
internal GlyphRec root;
|
||||
internal int left;
|
||||
internal int top;
|
||||
internal BitmapRec bitmap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a Bitmap.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="FTBitmap"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct BitmapRec
|
||||
{
|
||||
internal int rows;
|
||||
internal int width;
|
||||
internal int pitch;
|
||||
internal IntPtr buffer;
|
||||
internal short num_grays;
|
||||
internal PixelMode pixel_mode;
|
||||
internal byte palette_mode;
|
||||
internal IntPtr palette;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a BitmapSize.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="BitmapSize"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct BitmapSizeRec
|
||||
{
|
||||
internal short height;
|
||||
internal short width;
|
||||
|
||||
internal FT_Long size;
|
||||
|
||||
internal FT_Long x_ppem;
|
||||
internal FT_Long y_ppem;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(BitmapSizeRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.TrueType;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a CharMap.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="CharMap"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct CharMapRec
|
||||
{
|
||||
internal IntPtr face;
|
||||
internal Encoding encoding;
|
||||
internal PlatformId platform_id;
|
||||
internal ushort encoding_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a Face.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="Face"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct FaceRec
|
||||
{
|
||||
internal FT_Long num_faces;
|
||||
internal FT_Long face_index;
|
||||
|
||||
internal FT_Long face_flags;
|
||||
internal FT_Long style_flags;
|
||||
|
||||
internal FT_Long num_glyphs;
|
||||
|
||||
internal IntPtr family_name;
|
||||
internal IntPtr style_name;
|
||||
|
||||
internal int num_fixed_sizes;
|
||||
internal IntPtr available_sizes;
|
||||
|
||||
internal int num_charmaps;
|
||||
internal IntPtr charmaps;
|
||||
|
||||
internal GenericRec generic;
|
||||
|
||||
internal BBox bbox;
|
||||
|
||||
internal ushort units_per_EM;
|
||||
internal short ascender;
|
||||
internal short descender;
|
||||
internal short height;
|
||||
|
||||
internal short max_advance_width;
|
||||
internal short max_advance_height;
|
||||
|
||||
internal short underline_position;
|
||||
internal short underline_thickness;
|
||||
|
||||
internal IntPtr glyph;
|
||||
internal IntPtr size;
|
||||
internal IntPtr charmap;
|
||||
|
||||
private IntPtr driver;
|
||||
private IntPtr memory;
|
||||
private IntPtr stream;
|
||||
|
||||
private IntPtr sizes_list;
|
||||
private GenericRec autohint;
|
||||
private IntPtr extensions;
|
||||
|
||||
private IntPtr @internal;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(FaceRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GenericRec
|
||||
{
|
||||
internal IntPtr data;
|
||||
internal IntPtr finalizer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a GlyphMetrics.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="GlyphMetrics"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GlyphMetricsRec
|
||||
{
|
||||
internal FT_Long width;
|
||||
internal FT_Long height;
|
||||
|
||||
internal FT_Long horiBearingX;
|
||||
internal FT_Long horiBearingY;
|
||||
internal FT_Long horiAdvance;
|
||||
|
||||
internal FT_Long vertBearingX;
|
||||
internal FT_Long vertBearingY;
|
||||
internal FT_Long vertAdvance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GlyphRec
|
||||
{
|
||||
internal IntPtr library;
|
||||
private IntPtr clazz;
|
||||
internal GlyphFormat format;
|
||||
internal FTVector advance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a GlyphSlot.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="GlyphSlot"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GlyphSlotRec
|
||||
{
|
||||
internal IntPtr library;
|
||||
internal IntPtr face;
|
||||
internal IntPtr next;
|
||||
internal uint reserved;
|
||||
internal GenericRec generic;
|
||||
|
||||
internal GlyphMetricsRec metrics;
|
||||
internal FT_Long linearHoriAdvance;
|
||||
internal FT_Long linearVertAdvance;
|
||||
internal FTVector26Dot6 advance;
|
||||
|
||||
internal GlyphFormat format;
|
||||
|
||||
internal BitmapRec bitmap;
|
||||
internal int bitmap_left;
|
||||
internal int bitmap_top;
|
||||
|
||||
internal OutlineRec outline;
|
||||
|
||||
internal uint num_subglyphs;
|
||||
internal IntPtr subglyphs;
|
||||
|
||||
internal IntPtr control_data;
|
||||
internal FT_Long control_len;
|
||||
|
||||
internal FT_Long lsb_delta;
|
||||
internal FT_Long rsb_delta;
|
||||
|
||||
internal IntPtr other;
|
||||
|
||||
private IntPtr @internal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct GlyphToScriptMapPropertyRec
|
||||
{
|
||||
internal IntPtr face;
|
||||
internal IntPtr map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct IncreaseXHeightPropertyRec
|
||||
{
|
||||
internal IntPtr face;
|
||||
internal uint limit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ListNodeRec
|
||||
{
|
||||
internal IntPtr prev;
|
||||
internal IntPtr next;
|
||||
internal IntPtr data;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(ListNodeRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ListRec
|
||||
{
|
||||
internal IntPtr head;
|
||||
internal IntPtr tail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MemoryRec
|
||||
{
|
||||
internal IntPtr user;
|
||||
internal AllocFunc alloc;
|
||||
internal FreeFunc free;
|
||||
internal ReallocFunc realloc;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(MemoryRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ModuleClassRec
|
||||
{
|
||||
internal uint module_flags;
|
||||
internal FT_Long module_size;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
internal string module_name;
|
||||
internal FT_Long module_version;
|
||||
internal FT_Long module_requires;
|
||||
|
||||
internal IntPtr module_interface;
|
||||
|
||||
internal ModuleConstructor module_init;
|
||||
internal ModuleDestructor module_done;
|
||||
internal ModuleRequester get_interface;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// Provide a consistent means for using pointers as references.
|
||||
/// </summary>
|
||||
public abstract class NativeObject
|
||||
{
|
||||
private IntPtr reference;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new NativeObject and assign the reference.
|
||||
/// </summary>
|
||||
/// <param name="reference"></param>
|
||||
protected NativeObject(IntPtr reference)
|
||||
{
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
internal virtual IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return reference;
|
||||
}
|
||||
set
|
||||
{
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Struct NativeReference
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct NativeReference<T> where T : NativeObject
|
||||
{
|
||||
private readonly IntPtr memoryPtr;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NativeReference{T}"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="memoryPtr">The memory PTR.</param>
|
||||
public NativeReference(IntPtr memoryPtr)
|
||||
{
|
||||
this.memoryPtr = memoryPtr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an implicit conversion from <see cref="Memory"/> to <see cref="NativeReference{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="memory">The memory.</param>
|
||||
/// <returns>The result of the conversion.</returns>
|
||||
public static implicit operator NativeReference<T>(T memory)
|
||||
{
|
||||
return new NativeReference<T>(memory.Reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct OpenArgsRec
|
||||
{
|
||||
internal OpenFlags flags;
|
||||
internal IntPtr memory_base;
|
||||
internal FT_Long memory_size;
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
internal string pathname;
|
||||
|
||||
internal IntPtr stream;
|
||||
internal IntPtr driver;
|
||||
internal int num_params;
|
||||
internal IntPtr @params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct OutlineFuncsRec
|
||||
{
|
||||
internal IntPtr moveTo;
|
||||
internal IntPtr lineTo;
|
||||
internal IntPtr conicTo;
|
||||
internal IntPtr cubicTo;
|
||||
internal int shift;
|
||||
internal FT_Long delta;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct OutlineGlyphRec
|
||||
{
|
||||
internal GlyphRec root;
|
||||
internal OutlineRec outline;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct OutlineRec
|
||||
{
|
||||
internal short n_contours;
|
||||
internal short n_points;
|
||||
|
||||
internal IntPtr points;
|
||||
internal IntPtr tags;
|
||||
internal IntPtr contours;
|
||||
|
||||
internal OutlineFlags flags;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct ParameterRec
|
||||
{
|
||||
internal FT_ULong tag;
|
||||
internal IntPtr data;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(ParameterRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct RasterFuncsRec
|
||||
{
|
||||
internal GlyphFormat glyph_format;
|
||||
internal RasterNewFunc raster_new;
|
||||
internal RasterResetFunc raster_reset;
|
||||
internal RasterSetModeFunc raster_set_mode;
|
||||
internal RasterRenderFunc raster_render;
|
||||
internal RasterDoneFunc raster_done;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct RasterParamsRec
|
||||
{
|
||||
internal IntPtr target;
|
||||
internal IntPtr source;
|
||||
internal RasterFlags flags;
|
||||
internal RasterSpanFunc gray_spans;
|
||||
internal RasterSpanFunc black_spans;
|
||||
|
||||
[Obsolete("Unused")]
|
||||
internal RasterBitTestFunc bit_test;
|
||||
|
||||
[Obsolete("Unused")]
|
||||
internal RasterBitSetFunc bit_set;
|
||||
|
||||
internal IntPtr user;
|
||||
internal BBox clip_box;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(RasterParamsRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct RendererClassRec
|
||||
{
|
||||
internal ModuleClassRec root;
|
||||
|
||||
internal GlyphFormat glyph_format;
|
||||
|
||||
internal IntPtr render_glyph;
|
||||
internal IntPtr transform_glyph;
|
||||
internal IntPtr get_glyph_cbox;
|
||||
internal IntPtr set_mode;
|
||||
|
||||
internal IntPtr raster_class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SizeMetricsRec
|
||||
{
|
||||
internal ushort x_ppem;
|
||||
internal ushort y_ppem;
|
||||
|
||||
internal FT_Long x_scale;
|
||||
internal FT_Long y_scale;
|
||||
internal FT_Long ascender;
|
||||
internal FT_Long descender;
|
||||
internal FT_Long height;
|
||||
internal FT_Long max_advance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SizeRec
|
||||
{
|
||||
internal IntPtr face;
|
||||
internal GenericRec generic;
|
||||
internal SizeMetricsRec metrics;
|
||||
private IntPtr @internal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Internally represents a <see cref="SizeRequest"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Refer to <see cref="SizeRequest"/> for FreeType documentation.
|
||||
/// </remarks>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SizeRequestRec
|
||||
{
|
||||
internal SizeRequestType type;
|
||||
internal FT_Long width;
|
||||
internal FT_Long height;
|
||||
internal uint horiResolution;
|
||||
internal uint vertResolution;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct SpanRec
|
||||
{
|
||||
internal short x;
|
||||
internal ushort len;
|
||||
internal byte coverage;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(SpanRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct StreamDescRec
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal FT_Long value;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal IntPtr pointer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct StreamRec
|
||||
{
|
||||
internal IntPtr @base;
|
||||
internal FT_ULong size;
|
||||
internal FT_ULong pos;
|
||||
|
||||
internal StreamDescRec descriptor;
|
||||
internal StreamDescRec pathname;
|
||||
internal StreamIOFunc read;
|
||||
internal StreamCloseFunc close;
|
||||
|
||||
internal IntPtr memory;
|
||||
internal IntPtr cursor;
|
||||
internal IntPtr limit;
|
||||
|
||||
internal static int SizeInBytes { get { return Marshal.SizeOf(typeof(StreamRec)); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumeration used to specify which kerning values to return in <see cref="Face.GetKerning"/>.
|
||||
/// </summary>
|
||||
public enum KerningMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Return scaled and grid-fitted kerning distances.
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Return scaled but un-grid-fitted kerning distances.
|
||||
/// </summary>
|
||||
Unfitted,
|
||||
|
||||
/// <summary>
|
||||
/// Return the kerning vector in original font units.
|
||||
/// </summary>
|
||||
Unscaled
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of values to identify various types of LCD filters.
|
||||
/// </summary>
|
||||
public enum LcdFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Do not perform filtering. When used with subpixel rendering, this results in sometimes severe color
|
||||
/// fringes.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The default filter reduces color fringes considerably, at the cost of a slight blurriness in the output.
|
||||
/// </summary>
|
||||
Default = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The light filter is a variant that produces less blurriness at the cost of slightly more color fringes than
|
||||
/// the default one. It might be better, depending on taste, your monitor, or your personal vision.
|
||||
/// </summary>
|
||||
Light = 2,
|
||||
|
||||
/// <summary><para>
|
||||
/// This filter corresponds to the original libXft color filter. It provides high contrast output but can
|
||||
/// exhibit really bad color fringes if glyphs are not extremely well hinted to the pixel grid. In other words,
|
||||
/// it only works well if the TrueType bytecode interpreter is enabled and high-quality hinted fonts are used.
|
||||
/// </para><para>
|
||||
/// This filter is only provided for comparison purposes, and might be disabled or stay unsupported in the
|
||||
/// future.
|
||||
/// </para></summary>
|
||||
Legacy = 16
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,897 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014, 2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Cache;
|
||||
using SharpFont.Internal;
|
||||
using SharpFont.TrueType;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary><para>
|
||||
/// A handle to a FreeType library instance. Each ‘library’ is completely independent from the others; it is the
|
||||
/// ‘root’ of a set of objects like fonts, faces, sizes, etc.
|
||||
/// </para><para>
|
||||
/// It also embeds a memory manager (see <see cref="Memory"/>), as well as a scan-line converter object (see
|
||||
/// <see cref="Raster"/>).
|
||||
/// </para><para>
|
||||
/// For multi-threading applications each thread should have its own <see cref="Library"/> object.
|
||||
/// </para></summary>
|
||||
public sealed class Library : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private IntPtr reference;
|
||||
|
||||
private bool customMemory;
|
||||
private bool disposed;
|
||||
|
||||
private List<Face> childFaces;
|
||||
private List<Glyph> childGlyphs;
|
||||
private List<Outline> childOutlines;
|
||||
private List<Stroker> childStrokers;
|
||||
private List<Manager> childManagers;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Library"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// SharpFont assumes that you have the correct version of FreeType for your operating system and processor
|
||||
/// architecture. If you get a <see cref="BadImageFormatException"/> here on Windows, there's a good chance
|
||||
/// that you're trying to run your program as a 64-bit process and have a 32-bit version of FreeType or vice
|
||||
/// versa. See the SharpFont.Examples project for how to handle this situation.
|
||||
/// </remarks>
|
||||
public Library()
|
||||
: this(false)
|
||||
{
|
||||
IntPtr libraryRef;
|
||||
Error err = FT.FT_Init_FreeType(out libraryRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = libraryRef;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Library"/> class.
|
||||
/// </summary>
|
||||
/// <param name="memory">A custom FreeType memory manager.</param>
|
||||
public Library(Memory memory)
|
||||
: this(false)
|
||||
{
|
||||
IntPtr libraryRef;
|
||||
Error err = FT.FT_New_Library(memory.Reference, out libraryRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
Reference = libraryRef;
|
||||
customMemory = true;
|
||||
}
|
||||
|
||||
private Library(bool duplicate)
|
||||
{
|
||||
childFaces = new List<Face>();
|
||||
childGlyphs = new List<Glyph>();
|
||||
childOutlines = new List<Outline>();
|
||||
childStrokers = new List<Stroker>();
|
||||
childManagers = new List<Manager>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes an instance of the <see cref="Library"/> class.
|
||||
/// </summary>
|
||||
~Library()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the object has been disposed.
|
||||
/// </summary>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return disposed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of the FreeType library being used.
|
||||
/// </summary>
|
||||
public Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Version", "Cannot access a disposed object.");
|
||||
|
||||
int major, minor, patch;
|
||||
FT.FT_Library_Version(Reference, out major, out minor, out patch);
|
||||
return new Version(major, minor, patch);
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Reference", "Cannot access a disposed object.");
|
||||
|
||||
reference = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Base Interface
|
||||
|
||||
/// <summary>
|
||||
/// This function calls <see cref="OpenFace"/> to open a font by its pathname.
|
||||
/// </summary>
|
||||
/// <param name="path">A path to the font file.</param>
|
||||
/// <param name="faceIndex">The index of the face within the font. The first face has index 0.</param>
|
||||
/// <returns>
|
||||
/// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL.
|
||||
/// </returns>
|
||||
/// <see cref="OpenFace"/>
|
||||
public Face NewFace(string path, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return new Face(this, path, faceIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function calls <see cref="OpenFace"/> to open a font which has been loaded into memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// You must not deallocate the memory before calling <see cref="Face.Dispose()"/>.
|
||||
/// </remarks>
|
||||
/// <param name="file">A pointer to the beginning of the font data.</param>
|
||||
/// <param name="faceIndex">The index of the face within the font. The first face has index 0.</param>
|
||||
/// <returns>
|
||||
/// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL.
|
||||
/// </returns>
|
||||
/// <see cref="OpenFace"/>
|
||||
public Face NewMemoryFace(byte[] file, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return new Face(this, file, faceIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function calls <see cref="OpenFace"/> to open a font which has been loaded into memory.
|
||||
/// </summary>
|
||||
/// <param name="bufferPtr">A pointer to the beginning of the font data.</param>
|
||||
/// <param name="length">Length of the buffer</param>
|
||||
/// <param name="faceIndex">The index of the face within the font. The first face has index 0.</param>
|
||||
/// <returns>
|
||||
/// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL.
|
||||
/// </returns>
|
||||
public Face NewMemoryFace(IntPtr bufferPtr, int length, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return new Face(this, bufferPtr, length, faceIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="Face"/> object from a given resource described by <see cref="OpenArgs"/>.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// Unlike FreeType 1.x, this function automatically creates a glyph slot for the face object which can be
|
||||
/// accessed directly through <see cref="Face.Glyph"/>.
|
||||
/// </para><para>
|
||||
/// OpenFace can be used to quickly check whether the font format of a given font resource is supported by
|
||||
/// FreeType. If the ‘faceIndex’ field is negative, the function's return value is 0 if the font format is
|
||||
/// recognized, or non-zero otherwise; the function returns a more or less empty face handle in ‘*aface’ (if
|
||||
/// ‘aface’ isn't NULL). The only useful field in this special case is <see cref="Face.FaceCount"/> which gives
|
||||
/// the number of faces within the font file. After examination, the returned <see cref="Face"/> structure
|
||||
/// should be deallocated with a call to <see cref="Face.Dispose()"/>.
|
||||
/// </para><para>
|
||||
/// Each new face object created with this function also owns a default <see cref="FTSize"/> object, accessible
|
||||
/// as <see cref="Face.Size"/>.
|
||||
/// </para><para>
|
||||
/// See the discussion of reference counters in the description of FT_Reference_Face.
|
||||
/// </para></remarks>
|
||||
/// <param name="args">
|
||||
/// A pointer to an <see cref="OpenArgs"/> structure which must be filled by the caller.
|
||||
/// </param>
|
||||
/// <param name="faceIndex">The index of the face within the font. The first face has index 0.</param>
|
||||
/// <returns>
|
||||
/// A handle to a new face object. If ‘faceIndex’ is greater than or equal to zero, it must be non-NULL.
|
||||
/// </returns>
|
||||
public Face OpenFace(OpenArgs args, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr faceRef;
|
||||
|
||||
Error err = FT.FT_Open_Face(Reference, args.Reference, faceIndex, out faceRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Face(faceRef, this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#if !SHARPFONT_PLATFORM_IOS
|
||||
#region Mac Specific Interface
|
||||
|
||||
/// <summary>
|
||||
/// Create a new face object from a FOND resource.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function can be used to create <see cref="Face"/> objects from fonts that are installed in the system
|
||||
/// as follows.
|
||||
/// <code>
|
||||
/// fond = GetResource( 'FOND', fontName );
|
||||
/// error = FT_New_Face_From_FOND( library, fond, 0, &face );
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
/// <param name="fond">A FOND resource.</param>
|
||||
/// <param name="faceIndex">Only supported for the -1 ‘sanity check’ special case.</param>
|
||||
/// <returns>A handle to a new face object.</returns>
|
||||
public Face NewFaceFromFond(IntPtr fond, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr faceRef;
|
||||
|
||||
Error err = FT.FT_New_Face_From_FOND(Reference, fond, faceIndex, out faceRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Face(faceRef, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new face object from a given resource and typeface index using an FSSpec to the font file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="NewFaceFromFSSpec"/> is identical to <see cref="NewFace"/> except it accepts an FSSpec instead
|
||||
/// of a path.
|
||||
/// </remarks>
|
||||
/// <param name="spec">FSSpec to the font file.</param>
|
||||
/// <param name="faceIndex">The index of the face within the resource. The first face has index 0.</param>
|
||||
/// <returns>A handle to a new face object.</returns>
|
||||
public Face NewFaceFromFSSpec(IntPtr spec, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr faceRef;
|
||||
|
||||
Error err = FT.FT_New_Face_From_FSSpec(Reference, spec, faceIndex, out faceRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Face(faceRef, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new face object from a given resource and typeface index using an FSRef to the font file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="NewFaceFromFSRef"/> is identical to <see cref="NewFace"/> except it accepts an FSRef instead of
|
||||
/// a path.
|
||||
/// </remarks>
|
||||
/// <param name="ref">FSRef to the font file.</param>
|
||||
/// <param name="faceIndex">The index of the face within the resource. The first face has index 0.</param>
|
||||
/// <returns>A handle to a new face object.</returns>
|
||||
public Face NewFaceFromFSRef(IntPtr @ref, int faceIndex)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
IntPtr faceRef;
|
||||
|
||||
Error err = FT.FT_New_Face_From_FSRef(Reference, @ref, faceIndex, out faceRef);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
|
||||
return new Face(faceRef, this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
#region Module Management
|
||||
|
||||
/// <summary>
|
||||
/// Add a new module to a given library instance.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An error will be returned if a module already exists by that name, or if the module requires a version of
|
||||
/// FreeType that is too great.
|
||||
/// </remarks>
|
||||
/// <param name="clazz">A pointer to class descriptor for the module.</param>
|
||||
public void AddModule(ModuleClass clazz)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Add_Module(Reference, clazz.Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a module by its name.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// FreeType's internal modules aren't documented very well, and you should look up the source code for
|
||||
/// details.
|
||||
/// </remarks>
|
||||
/// <param name="moduleName">The module's name (as an ASCII string).</param>
|
||||
/// <returns>A module handle. 0 if none was found.</returns>
|
||||
public Module GetModule(string moduleName)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return new Module(FT.FT_Get_Module(Reference, moduleName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a given module from a library instance.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The module object is destroyed by the function in case of success.
|
||||
/// </remarks>
|
||||
/// <param name="module">A handle to a module object.</param>
|
||||
public void RemoveModule(Module module)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
if (module == null)
|
||||
throw new ArgumentNullException("module");
|
||||
|
||||
Error err = FT.FT_Remove_Module(Reference, module.Reference);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a property for a given module.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName"><para>The property name. Properties are described in the ‘Synopsis’ subsection
|
||||
/// of the module's documentation.
|
||||
/// </para><para>
|
||||
/// Note that only a few modules have properties.</para></param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the new value of the property.
|
||||
/// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertySet(string moduleName, string propertyName, IntPtr value)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Property_Set(Reference, moduleName, propertyName, value);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a property for a given module.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of property to set.</typeparam>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName"><para>The property name. Properties are described in the ‘Synopsis’ subsection
|
||||
/// of the module's documentation.
|
||||
/// </para><para>
|
||||
/// Note that only a few modules have properties.</para></param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the new value of the property.
|
||||
/// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertySet<T>(string moduleName, string propertyName, ref T value)
|
||||
where T : struct
|
||||
{
|
||||
GCHandle gch = GCHandle.Alloc(value, GCHandleType.Pinned);
|
||||
PropertySet(moduleName, propertyName, gch.AddrOfPinnedObject());
|
||||
gch.Free();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a property for a given module.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of property to set.</typeparam>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName"><para>The property name. Properties are described in the ‘Synopsis’ subsection
|
||||
/// of the module's documentation.
|
||||
/// </para><para>
|
||||
/// Note that only a few modules have properties.</para></param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the new value of the property.
|
||||
/// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertySet<T>(string moduleName, string propertyName, T value)
|
||||
where T : struct
|
||||
{
|
||||
PropertySet(moduleName, propertyName, ref value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a property for a given module.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName"><para>The property name. Properties are described in the ‘Synopsis’ subsection
|
||||
/// of the module's documentation.
|
||||
/// </para><para>
|
||||
/// Note that only a few modules have properties.</para></param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the new value of the property.
|
||||
/// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertySet(string moduleName, string propertyName, GlyphToScriptMapProperty value)
|
||||
{
|
||||
var rec = value.Rec;
|
||||
PropertySet(moduleName, propertyName, ref rec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a property for a given module.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName"><para>The property name. Properties are described in the ‘Synopsis’ subsection
|
||||
/// of the module's documentation.
|
||||
/// </para><para>
|
||||
/// Note that only a few modules have properties.</para></param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the new value of the property.
|
||||
/// The exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertySet(string moduleName, string propertyName, IncreaseXHeightProperty value)
|
||||
{
|
||||
var rec = value.Rec;
|
||||
PropertySet(moduleName, propertyName, ref rec);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a module's property value.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <param name="value">A generic pointer to a variable or structure which gives the value of the property. The
|
||||
/// exact definition of ‘value’ is dependent on the property; see the ‘Synopsis’ subsection of the module's
|
||||
/// documentation.</param>
|
||||
public void PropertyGet(string moduleName, string propertyName, IntPtr value)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Property_Get(Reference, moduleName, propertyName, value);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a module's property value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of property to get.</typeparam>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <param name="value">The value read from the module.</param>
|
||||
public void PropertyGet<T>(string moduleName, string propertyName, out T value)
|
||||
where T : struct
|
||||
{
|
||||
value = default(T);
|
||||
|
||||
GCHandle gch = GCHandle.Alloc(value, GCHandleType.Pinned);
|
||||
PropertyGet(moduleName, propertyName, gch.AddrOfPinnedObject());
|
||||
value = PInvokeHelper.PtrToStructure<T>(gch.AddrOfPinnedObject());
|
||||
gch.Free();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a module's property value.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <param name="value">The value read from the module.</param>
|
||||
[Obsolete("Use PropertyGetGlyphToScriptMap instead")]
|
||||
public void PropertyGet(string moduleName, string propertyName, out GlyphToScriptMapProperty value)
|
||||
{
|
||||
value = PropertyGetGlyphToScriptMap(moduleName, propertyName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a module's property value.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <param name="value">The value read from the module.</param>
|
||||
[Obsolete("Use PropertyGetIncreaseXHeight instead")]
|
||||
public void PropertyGet(string moduleName, string propertyName, out IncreaseXHeightProperty value)
|
||||
{
|
||||
value = PropertyGetIncreaseXHeight(moduleName, propertyName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a module's property value of the type <see cref="GlyphToScriptMapProperty"/>.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <returns>The value read from the module.</returns>
|
||||
public GlyphToScriptMapProperty PropertyGetGlyphToScriptMap(string moduleName, string propertyName)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
GlyphToScriptMapPropertyRec rec;
|
||||
PropertyGet(moduleName, propertyName, out rec);
|
||||
|
||||
Face face = childFaces.Find(f => f.Reference == rec.face);
|
||||
return new GlyphToScriptMapProperty(rec, face);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a module's property value of the type <see cref="IncreaseXHeightProperty"/>.
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
/// <param name="propertyName">The property name. Properties are described in the ‘Synopsis’ subsection of the
|
||||
/// module's documentation.</param>
|
||||
/// <returns>The value read from the module.</returns>
|
||||
public IncreaseXHeightProperty PropertyGetIncreaseXHeight(string moduleName, string propertyName)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
IncreaseXHeightPropertyRec rec;
|
||||
PropertyGet(moduleName, propertyName, out rec);
|
||||
|
||||
Face face = childFaces.Find(f => f.Reference == rec.face);
|
||||
return new IncreaseXHeightProperty(rec, face);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a debug hook function for debugging the interpreter of a font format.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// Currently, four debug hook slots are available, but only two (for the TrueType and the Type 1 interpreter)
|
||||
/// are defined.
|
||||
/// </para><para>
|
||||
/// Since the internal headers of FreeType are no longer installed, the symbol ‘FT_DEBUG_HOOK_TRUETYPE’ isn't
|
||||
/// available publicly. This is a bug and will be fixed in a forthcoming release.
|
||||
/// </para></remarks>
|
||||
/// <param name="hookIndex">The index of the debug hook. You should use the values defined in ‘ftobjs.h’, e.g.,
|
||||
/// ‘FT_DEBUG_HOOK_TRUETYPE’.</param>
|
||||
/// <param name="debugHook">The function used to debug the interpreter.</param>
|
||||
[CLSCompliant(false)]
|
||||
public void SetDebugHook(uint hookIndex, IntPtr debugHook)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
FT.FT_Set_Debug_Hook(Reference, hookIndex, debugHook);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the set of default drivers to a given library object. This is only useful when you create a library
|
||||
/// object with <see cref="Library(Memory)"/> (usually to plug a custom memory manager).
|
||||
/// </summary>
|
||||
public void AddDefaultModules()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
FT.FT_Add_Default_Modules(Reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the current renderer for a given glyph format.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// An error will be returned if a module already exists by that name, or if the module requires a version of
|
||||
/// FreeType that is too great.
|
||||
/// </para><para>
|
||||
/// To add a new renderer, simply use <see cref="AddModule"/>. To retrieve a renderer by its name, use
|
||||
/// <see cref="GetModule"/>.
|
||||
/// </para></remarks>
|
||||
/// <param name="format">The glyph format.</param>
|
||||
/// <returns>A renderer handle. 0 if none found.</returns>
|
||||
[CLSCompliant(false)]
|
||||
public Renderer GetRenderer(GlyphFormat format)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return new Renderer(FT.FT_Get_Renderer(Reference, format));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the current renderer to use, and set additional mode.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// In case of success, the renderer will be used to convert glyph images in the renderer's known format into
|
||||
/// bitmaps.
|
||||
/// </para><para>
|
||||
/// This doesn't change the current renderer for other formats.
|
||||
/// </para><para>
|
||||
/// Currently, only the B/W renderer, if compiled with FT_RASTER_OPTION_ANTI_ALIASING (providing a 5-levels
|
||||
/// anti-aliasing mode; this option must be set directly in ‘ftraster.c’ and is undefined by default) accepts a
|
||||
/// single tag ‘pal5’ to set its gray palette as a character string with 5 elements. Consequently, the third
|
||||
/// and fourth argument are zero normally.
|
||||
/// </para></remarks>
|
||||
/// <param name="renderer">A handle to the renderer object.</param>
|
||||
/// <param name="numParams">The number of additional parameters.</param>
|
||||
/// <param name="parameters">Additional parameters.</param>
|
||||
[CLSCompliant(false)]
|
||||
public unsafe void SetRenderer(Renderer renderer, uint numParams, Parameter[] parameters)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
if (renderer == null)
|
||||
throw new ArgumentNullException("renderer");
|
||||
|
||||
if (parameters == null)
|
||||
throw new ArgumentNullException("parameters");
|
||||
|
||||
ParameterRec[] paramRecs = parameters.Select(x => x.Record).ToArray();
|
||||
fixed (void* ptr = paramRecs)
|
||||
{
|
||||
Error err = FT.FT_Set_Renderer(Reference, renderer.Reference, numParams, (IntPtr)ptr);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region LCD Filtering
|
||||
|
||||
/// <summary>
|
||||
/// This function is used to apply color filtering to LCD decimated bitmaps, like the ones used when calling
|
||||
/// <see cref="GlyphSlot.RenderGlyph"/> with <see cref="RenderMode.Lcd"/> or
|
||||
/// <see cref="RenderMode.VerticalLcd"/>.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// This feature is always disabled by default. Clients must make an explicit call to this function with a
|
||||
/// ‘filter’ value other than <see cref="LcdFilter.None"/> in order to enable it.
|
||||
/// </para><para>
|
||||
/// Due to <b>PATENTS</b> covering subpixel rendering, this function doesn't do anything except returning
|
||||
/// <see cref="Error.UnimplementedFeature"/> if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is
|
||||
/// not defined in your build of the library, which should correspond to all default builds of FreeType.
|
||||
/// </para><para>
|
||||
/// The filter affects glyph bitmaps rendered through <see cref="GlyphSlot.RenderGlyph"/>,
|
||||
/// <see cref="Outline.GetBitmap(FTBitmap)"/>, <see cref="Face.LoadGlyph"/>, and <see cref="Face.LoadChar"/>.
|
||||
/// </para><para>
|
||||
/// It does not affect the output of <see cref="Outline.Render(RasterParams)"/> and
|
||||
/// <see cref="Outline.GetBitmap(FTBitmap)"/>.
|
||||
/// </para><para>
|
||||
/// If this feature is activated, the dimensions of LCD glyph bitmaps are either larger or taller than the
|
||||
/// dimensions of the corresponding outline with regards to the pixel grid. For example, for
|
||||
/// <see cref="RenderMode.Lcd"/>, the filter adds up to 3 pixels to the left, and up to 3 pixels to the right.
|
||||
/// </para><para>
|
||||
/// The bitmap offset values are adjusted correctly, so clients shouldn't need to modify their layout and glyph
|
||||
/// positioning code when enabling the filter.
|
||||
/// </para></remarks>
|
||||
/// <param name="filter"><para>
|
||||
/// The filter type.
|
||||
/// </para><para>
|
||||
/// You can use <see cref="LcdFilter.None"/> here to disable this feature, or <see cref="LcdFilter.Default"/>
|
||||
/// to use a default filter that should work well on most LCD screens.
|
||||
/// </para></param>
|
||||
public void SetLcdFilter(LcdFilter filter)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
Error err = FT.FT_Library_SetLcdFilter(Reference, filter);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this function to override the filter weights selected by <see cref="SetLcdFilter"/>. By default,
|
||||
/// FreeType uses the quintuple (0x00, 0x55, 0x56, 0x55, 0x00) for <see cref="LcdFilter.Light"/>, and (0x10,
|
||||
/// 0x40, 0x70, 0x40, 0x10) for <see cref="LcdFilter.Default"/> and <see cref="LcdFilter.Legacy"/>.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// Due to <b>PATENTS</b> covering subpixel rendering, this function doesn't do anything except returning
|
||||
/// <see cref="Error.UnimplementedFeature"/> if the configuration macro FT_CONFIG_OPTION_SUBPIXEL_RENDERING is
|
||||
/// not defined in your build of the library, which should correspond to all default builds of FreeType.
|
||||
/// </para><para>
|
||||
/// This function must be called after <see cref="SetLcdFilter"/> to have any effect.
|
||||
/// </para></remarks>
|
||||
/// <param name="weights">
|
||||
/// A pointer to an array; the function copies the first five bytes and uses them to specify the filter
|
||||
/// weights.
|
||||
/// </param>
|
||||
public void SetLcdFilterWeights(byte[] weights)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
if (weights == null)
|
||||
throw new ArgumentNullException("weights");
|
||||
|
||||
Error err = FT.FT_Library_SetLcdFilterWeights(Reference, weights);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region The TrueType Engine
|
||||
|
||||
/// <summary>
|
||||
/// Return an <see cref="EngineType"/> value to indicate which level of the TrueType virtual machine a given
|
||||
/// library instance supports.
|
||||
/// </summary>
|
||||
/// <returns>A value indicating which level is supported.</returns>
|
||||
public EngineType GetTrueTypeEngineType()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException("Library", "Cannot access a disposed object.");
|
||||
|
||||
return FT.FT_Get_TrueType_Engine_Type(Reference);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the Library.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal void AddChildFace(Face child)
|
||||
{
|
||||
childFaces.Add(child);
|
||||
}
|
||||
|
||||
internal void RemoveChildFace(Face child)
|
||||
{
|
||||
childFaces.Remove(child);
|
||||
}
|
||||
|
||||
internal void AddChildGlyph(Glyph child)
|
||||
{
|
||||
childGlyphs.Add(child);
|
||||
}
|
||||
|
||||
internal void RemoveChildGlyph(Glyph child)
|
||||
{
|
||||
childGlyphs.Remove(child);
|
||||
}
|
||||
|
||||
internal void AddChildOutline(Outline child)
|
||||
{
|
||||
childOutlines.Add(child);
|
||||
}
|
||||
|
||||
internal void RemoveChildOutline(Outline child)
|
||||
{
|
||||
childOutlines.Remove(child);
|
||||
}
|
||||
|
||||
internal void AddChildStroker(Stroker child)
|
||||
{
|
||||
childStrokers.Add(child);
|
||||
}
|
||||
|
||||
internal void RemoveChildStroker(Stroker child)
|
||||
{
|
||||
childStrokers.Remove(child);
|
||||
}
|
||||
|
||||
internal void AddChildManager(Manager child)
|
||||
{
|
||||
childManagers.Add(child);
|
||||
}
|
||||
|
||||
internal void RemoveChildManager(Manager child)
|
||||
{
|
||||
childManagers.Remove(child);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
//dipose all the children before disposing the library.
|
||||
foreach (Face f in childFaces)
|
||||
f.Dispose();
|
||||
|
||||
foreach (Glyph g in childGlyphs)
|
||||
g.Dispose();
|
||||
|
||||
foreach (Outline o in childOutlines)
|
||||
o.Dispose();
|
||||
|
||||
foreach (Stroker s in childStrokers)
|
||||
s.Dispose();
|
||||
|
||||
foreach (Manager m in childManagers)
|
||||
m.Dispose();
|
||||
|
||||
childFaces.Clear();
|
||||
childGlyphs.Clear();
|
||||
childOutlines.Clear();
|
||||
childStrokers.Clear();
|
||||
childManagers.Clear();
|
||||
|
||||
Error err = customMemory ? FT.FT_Done_Library(reference) : FT.FT_Done_FreeType(reference);
|
||||
reference = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure used to hold a single list element.
|
||||
/// </summary>
|
||||
public class ListNode: NativeObject
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private ListNodeRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal ListNode(IntPtr reference): base(reference)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the previous element in the list. NULL if first.
|
||||
/// </summary>
|
||||
public ListNode Previous
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rec.prev == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new ListNode(rec.prev);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next element in the list. NULL if last.
|
||||
/// </summary>
|
||||
public ListNode Next
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rec.next == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return new ListNode(rec.next);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a typeless pointer to the listed object.
|
||||
/// </summary>
|
||||
public IntPtr Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.data;
|
||||
}
|
||||
}
|
||||
|
||||
internal override IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.Reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<ListNodeRec>(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2016 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A list of bit-field constants used with <see cref="Face.LoadGlyph"/> to indicate what kind of operations to
|
||||
/// perform during glyph loading.
|
||||
/// </summary>
|
||||
/// <remarks><para>
|
||||
/// By default, hinting is enabled and the font's native hinter (see <see cref="FaceFlags.Hinter"/>) is preferred
|
||||
/// over the auto-hinter. You can disable hinting by setting <see cref="LoadFlags.NoHinting"/> or change the
|
||||
/// precedence by setting <see cref="LoadFlags.ForceAutohint"/>. You can also set
|
||||
/// <see cref="LoadFlags.NoAutohint"/> in case you don't want the auto-hinter to be used at all.
|
||||
/// </para><para>
|
||||
/// See the description of <see cref="FaceFlags.Tricky"/> for a special exception (affecting only a handful of
|
||||
/// Asian fonts).
|
||||
/// </para><para>
|
||||
/// Besides deciding which hinter to use, you can also decide which hinting algorithm to use. See
|
||||
/// <see cref="LoadTarget"/> for details.
|
||||
/// </para></remarks>
|
||||
[Flags]
|
||||
[CLSCompliant(false)]
|
||||
public enum LoadFlags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Corresponding to 0, this value is used as the default glyph load operation. In this case, the following
|
||||
/// happens:
|
||||
/// <list type="number">
|
||||
/// <item><description>
|
||||
/// FreeType looks for a bitmap for the glyph corresponding to the face's current size. If one is found, the
|
||||
/// function returns. The bitmap data can be accessed from the glyph slot (see note below).
|
||||
/// </description></item>
|
||||
/// <item><description>
|
||||
/// If no embedded bitmap is searched or found, FreeType looks for a scalable outline. If one is found, it is
|
||||
/// loaded from the font file, scaled to device pixels, then ‘hinted’ to the pixel grid in order to optimize
|
||||
/// it. The outline data can be accessed from the glyph slot (see note below).
|
||||
/// </description></item>
|
||||
/// </list>
|
||||
/// Note that by default, the glyph loader doesn't render outlines into bitmaps. The following flags are used
|
||||
/// to modify this default behaviour to more specific and useful cases.
|
||||
/// </summary>
|
||||
Default = 0x000000,
|
||||
|
||||
/// <summary><para>
|
||||
/// Don't scale the outline glyph loaded, but keep it in font units.
|
||||
/// </para><para>
|
||||
/// This flag implies <see cref="LoadFlags.NoHinting"/> and <see cref="LoadFlags.NoBitmap"/>, and unsets
|
||||
/// <see cref="LoadFlags.Render"/>.
|
||||
/// </para></summary>
|
||||
NoScale = 0x000001,
|
||||
|
||||
/// <summary><para>
|
||||
/// Disable hinting. This generally generates ‘blurrier’ bitmap glyph when the glyph is rendered in any of the
|
||||
/// anti-aliased modes. See also the note below.
|
||||
/// </para><para>
|
||||
/// This flag is implied by <see cref="LoadFlags.NoScale"/>.
|
||||
/// </para></summary>
|
||||
NoHinting = 0x000002,
|
||||
|
||||
/// <summary><para>
|
||||
/// Call <see cref="GlyphSlot.RenderGlyph"/> after the glyph is loaded. By default, the glyph is rendered in
|
||||
/// <see cref="RenderMode.Normal"/> mode. This can be overridden by <see cref="LoadTarget"/> or
|
||||
/// <see cref="LoadFlags.Monochrome"/>.
|
||||
/// </para><para>
|
||||
/// This flag is unset by <see cref="LoadFlags.NoScale"/>.
|
||||
/// </para></summary>
|
||||
Render = 0x000004,
|
||||
|
||||
/// <summary><para>
|
||||
/// Ignore bitmap strikes when loading. Bitmap-only fonts ignore this flag.
|
||||
/// </para><para>
|
||||
/// <see cref="LoadFlags.NoScale"/> always sets this flag.
|
||||
/// </para></summary>
|
||||
NoBitmap = 0x000008,
|
||||
|
||||
/// <summary>
|
||||
/// Load the glyph for vertical text layout. Don't use it as it is problematic currently.
|
||||
/// </summary>
|
||||
VerticalLayout = 0x000010,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the auto-hinter is preferred over the font's native hinter. See also the note below.
|
||||
/// </summary>
|
||||
ForceAutohint = 0x000020,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the font driver should crop the loaded bitmap glyph (i.e., remove all space around its black
|
||||
/// bits). Not all drivers implement this.
|
||||
/// </summary>
|
||||
CropBitmap = 0x000040,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the font driver should perform pedantic verifications during glyph loading. This is mostly
|
||||
/// used to detect broken glyphs in fonts. By default, FreeType tries to handle broken fonts also.
|
||||
/// </summary>
|
||||
Pedantic = 0x000080,
|
||||
|
||||
/// <summary>
|
||||
/// Ignored. Deprecated.
|
||||
/// </summary>
|
||||
[Obsolete("Ignored. Deprecated.")]
|
||||
IgnoreGlobalAdvanceWidth = 0x000200,
|
||||
|
||||
/// <summary><para>
|
||||
/// This flag is only used internally. It merely indicates that the font driver should not load composite
|
||||
/// glyphs recursively. Instead, it should set the ‘num_subglyph’ and ‘subglyphs’ values of the glyph slot
|
||||
/// accordingly, and set ‘glyph->format’ to <see cref="GlyphFormat.Composite"/>.
|
||||
/// </para><para>
|
||||
/// The description of sub-glyphs is not available to client applications for now.
|
||||
/// </para><para>
|
||||
/// This flag implies <see cref="LoadFlags.NoScale"/> and <see cref="LoadFlags.IgnoreTransform"/>.
|
||||
/// </para></summary>
|
||||
NoRecurse = 0x000400,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the transform matrix set by <see cref="Face.SetTransform()"/> should be ignored.
|
||||
/// </summary>
|
||||
IgnoreTransform = 0x000800,
|
||||
|
||||
/// <summary><para>
|
||||
/// This flag is used with <see cref="LoadFlags.Render"/> to indicate that you want to render an outline glyph
|
||||
/// to a 1-bit monochrome bitmap glyph, with 8 pixels packed into each byte of the bitmap data.
|
||||
/// </para><para>
|
||||
/// Note that this has no effect on the hinting algorithm used. You should rather use
|
||||
/// <see cref="LoadTarget.Mono"/> so that the monochrome-optimized hinting algorithm is used.
|
||||
/// </para></summary>
|
||||
Monochrome = 0x001000,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the ‘linearHoriAdvance’ and ‘linearVertAdvance’ fields of <see cref="GlyphSlot"/> should be
|
||||
/// kept in font units. See <see cref="GlyphSlot"/> for details.
|
||||
/// </summary>
|
||||
LinearDesign = 0x002000,
|
||||
|
||||
/// <summary>
|
||||
/// Disable auto-hinter. See also the note below.
|
||||
/// </summary>
|
||||
NoAutohint = 0x008000,
|
||||
|
||||
/// <summary>
|
||||
/// This flag is used to request loading of color embedded-bitmap images. The resulting color bitmaps, if
|
||||
/// available, will have the <see cref="PixelMode.Bgra"/> format. When the flag is not used and color bitmaps
|
||||
/// are found, they will be converted to 256-level gray bitmaps transparently. Those bitmaps will be in the
|
||||
/// <see cref="PixelMode.Gray"/> format.
|
||||
/// </summary>
|
||||
Color = 0x100000,
|
||||
|
||||
/// <summary>
|
||||
/// This flag sets computing glyph metrics without the use of bundled
|
||||
/// metrics tables. Well-behaving fonts have optimized bundled metrics
|
||||
/// and these should be used. This flag is mainly used by font
|
||||
/// validating or font editing applications which need to ignore, verify
|
||||
/// or edit those tables.
|
||||
/// </summary>
|
||||
ComputeMetrics = 0x200000,
|
||||
|
||||
/// <summary><para>
|
||||
/// A bit-flag to be OR-ed with the ‘flags’ parameter of the <see cref="Face.GetAdvance"/> and
|
||||
/// <see cref="Face.GetAdvances"/> functions.
|
||||
/// </para><para>
|
||||
/// If set, it indicates that you want these functions to fail if the corresponding hinting mode or font driver
|
||||
/// doesn't allow for very quick advance computation.
|
||||
/// </para><para>
|
||||
/// Typically, glyphs which are either unscaled, unhinted, bitmapped, or light-hinted can have their advance
|
||||
/// width computed very quickly.
|
||||
/// </para><para>
|
||||
/// Normal and bytecode hinted modes, which require loading, scaling, and hinting of the glyph outline, are
|
||||
/// extremely slow by comparison.
|
||||
/// </para></summary>
|
||||
AdvanceFlagFastOnly = 0x20000000
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary><para>
|
||||
/// A list of values that are used to select a specific hinting algorithm to use by the hinter. You should OR one
|
||||
/// of these values to your ‘load_flags’ when calling <see cref="Face.LoadGlyph"/>.
|
||||
/// </para><para>
|
||||
/// Note that font's native hinters may ignore the hinting algorithm you have specified (e.g., the TrueType
|
||||
/// bytecode interpreter). You can set <see cref="LoadFlags.ForceAutohint"/> to ensure that the auto-hinter is
|
||||
/// used.
|
||||
/// </para><para>
|
||||
/// Also note that <see cref="LoadTarget.Light"/> is an exception, in that it always implies
|
||||
/// <see cref="LoadFlags.ForceAutohint"/>.
|
||||
/// </para></summary>
|
||||
/// <remarks><para>
|
||||
/// You should use only one of the <see cref="LoadTarget"/> values in your ‘load_flags’. They can't be ORed.
|
||||
/// </para><para>
|
||||
/// If <see cref="LoadFlags.Render"/> is also set, the glyph is rendered in the corresponding mode (i.e., the mode
|
||||
/// which matches the used algorithm best) unless <see cref="LoadFlags.Monochrome"/> is set.
|
||||
/// </para><para>
|
||||
/// You can use a hinting algorithm that doesn't correspond to the same rendering mode. As an example, it is
|
||||
/// possible to use the ‘light’ hinting algorithm and have the results rendered in horizontal LCD pixel mode, with
|
||||
/// code like:
|
||||
/// <code>
|
||||
/// FT_Load_Glyph( face, glyph_index,
|
||||
/// load_flags | FT_LOAD_TARGET_LIGHT );
|
||||
///
|
||||
/// FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD );
|
||||
/// </code>
|
||||
/// </para></remarks>
|
||||
public enum LoadTarget
|
||||
{
|
||||
/// <summary>
|
||||
/// This corresponds to the default hinting algorithm, optimized for standard gray-level rendering. For
|
||||
/// monochrome output, use <see cref="LoadTarget.Mono"/> instead.
|
||||
/// </summary>
|
||||
Normal = (RenderMode.Normal & 15) << 16,
|
||||
|
||||
/// <summary><para>
|
||||
/// A lighter hinting algorithm for non-monochrome modes. Many generated glyphs are more fuzzy but better
|
||||
/// resemble its original shape. A bit like rendering on Mac OS X.
|
||||
/// </para><para>
|
||||
/// As a special exception, this target implies <see cref="LoadFlags.ForceAutohint"/>.
|
||||
/// </para></summary>
|
||||
Light = (RenderMode.Light & 15) << 16,
|
||||
|
||||
/// <summary>
|
||||
/// Strong hinting algorithm that should only be used for monochrome output. The result is probably unpleasant
|
||||
/// if the glyph is rendered in non-monochrome modes.
|
||||
/// </summary>
|
||||
Mono = (RenderMode.Mono & 15) << 16,
|
||||
|
||||
/// <summary>
|
||||
/// A variant of <see cref="LoadTarget.Normal"/> optimized for horizontally decimated LCD displays.
|
||||
/// </summary>
|
||||
Lcd = (RenderMode.Lcd & 15) << 16,
|
||||
|
||||
/// <summary>
|
||||
/// A variant of <see cref="LoadTarget.Normal"/> optimized for vertically decimated LCD displays.
|
||||
/// </summary>
|
||||
VerticalLcd = (RenderMode.VerticalLcd & 15) << 16
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2014 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A function used to allocate ‘size’ bytes from ‘memory’.
|
||||
/// </summary>
|
||||
/// <param name="memory">A handle to the source memory manager.</param>
|
||||
/// <param name="size">The size in bytes to allocate.</param>
|
||||
/// <returns>Address of new memory block. 0 in case of failure.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate IntPtr AllocFunc(NativeReference<Memory> memory, IntPtr size);
|
||||
|
||||
/// <summary>
|
||||
/// A function used to release a given block of memory.
|
||||
/// </summary>
|
||||
/// <param name="memory">A handle to the source memory manager.</param>
|
||||
/// <param name="block">The address of the target memory block.</param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void FreeFunc(NativeReference<Memory> memory, IntPtr block);
|
||||
|
||||
/// <summary>
|
||||
/// A function used to re-allocate a given block of memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In case of error, the old block must still be available.
|
||||
/// </remarks>
|
||||
/// <param name="memory">A handle to the source memory manager.</param>
|
||||
/// <param name="currentSize">The block's current size in bytes.</param>
|
||||
/// <param name="newSize">The block's requested new size.</param>
|
||||
/// <param name="block">The block's current address.</param>
|
||||
/// <returns>New block address. 0 in case of memory shortage.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate IntPtr ReallocFunc(NativeReference<Memory> memory, IntPtr currentSize, IntPtr newSize, IntPtr block);
|
||||
|
||||
/// <summary>
|
||||
/// A structure used to describe a given memory manager to FreeType 2.
|
||||
/// </summary>
|
||||
public class Memory: NativeObject
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private MemoryRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal Memory(IntPtr reference): base(reference)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets a generic typeless pointer for user data.
|
||||
/// </summary>
|
||||
public IntPtr User
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.user;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a pointer type to an allocation function.
|
||||
/// </summary>
|
||||
public AllocFunc Allocate
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.alloc;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a pointer type to an memory freeing function.
|
||||
/// </summary>
|
||||
public FreeFunc Free
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.free;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a pointer type to a reallocation function.
|
||||
/// </summary>
|
||||
public ReallocFunc Reallocate
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.realloc;
|
||||
}
|
||||
}
|
||||
|
||||
internal override IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.Reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<MemoryRec>(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Decompress a zipped input buffer into an output buffer. This function is modeled after zlib's ‘uncompress’
|
||||
/// function.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This function may return <see cref="Error.UnimplementedFeature"/> if your build of FreeType was not
|
||||
/// compiled with zlib support.
|
||||
/// </remarks>
|
||||
/// <param name="input">The input buffer.</param>
|
||||
/// <param name="output">The output buffer.</param>
|
||||
/// <returns>The length of the used data in output.</returns>
|
||||
public unsafe int GzipUncompress(byte[] input, byte[] output)
|
||||
{
|
||||
IntPtr len = (IntPtr)output.Length;
|
||||
|
||||
fixed (byte* inPtr = input, outPtr = output)
|
||||
{
|
||||
Error err = FT.FT_Gzip_Uncompress(Reference, (IntPtr)outPtr, ref len, (IntPtr)inPtr, (IntPtr)input.Length);
|
||||
|
||||
if (err != Error.Ok)
|
||||
throw new FreeTypeException(err);
|
||||
}
|
||||
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A handle to a given FreeType module object. Each module can be a font driver, a renderer, or anything else that
|
||||
/// provides services to the formers.
|
||||
/// </summary>
|
||||
public sealed class Module : NativeObject
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
internal Module(IntPtr reference): base(reference)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2013, 2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using SharpFont.Internal;
|
||||
|
||||
namespace SharpFont
|
||||
{
|
||||
/// <summary>
|
||||
/// A function used to initialize (not create) a new module object.
|
||||
/// </summary>
|
||||
/// <param name="module">The module to initialize.</param>
|
||||
/// <returns>FreeType error code.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate Error ModuleConstructor(NativeReference<Module> module);
|
||||
|
||||
/// <summary>
|
||||
/// A function used to finalize (not destroy) a given module object.
|
||||
/// </summary>
|
||||
/// <param name="module">The module to finalize.</param>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ModuleDestructor(NativeReference<Module> module);
|
||||
|
||||
/// <summary>
|
||||
/// A function used to query a given module for a specific interface.
|
||||
/// </summary>
|
||||
/// <param name="module">The module that contains the interface.</param>
|
||||
/// <param name="name">The name of the interface in the module.</param>
|
||||
/// <returns>The interface.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate IntPtr ModuleRequester(NativeReference<Module> module, [MarshalAs(UnmanagedType.LPStr)] string name);
|
||||
|
||||
/// <summary>
|
||||
/// The module class descriptor.
|
||||
/// </summary>
|
||||
public class ModuleClass : NativeObject
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private ModuleClassRec rec;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal ModuleClass(IntPtr reference) : base(reference)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets bit flags describing the module.
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint Flags
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.module_flags;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of one module object/instance in bytes.
|
||||
/// </summary>
|
||||
public int Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)rec.module_size;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the module.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.module_name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version, as a 16.16 fixed number (major.minor).
|
||||
/// </summary>
|
||||
public Fixed16Dot16 Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)rec.module_version);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of FreeType this module requires, as a 16.16 fixed number (major.minor). Starts at version
|
||||
/// 2.0, i.e., 0x20000.
|
||||
/// </summary>
|
||||
public Fixed16Dot16 Requires
|
||||
{
|
||||
get
|
||||
{
|
||||
return Fixed16Dot16.FromRawValue((int)rec.module_requires);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the module interface.
|
||||
/// </summary>
|
||||
public IntPtr Interface
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.module_interface;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the initializing function.
|
||||
/// </summary>
|
||||
public ModuleConstructor Init
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.module_init;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the finalizing function.
|
||||
/// </summary>
|
||||
public ModuleDestructor Done
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.module_done;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interface requesting function.
|
||||
/// </summary>
|
||||
public ModuleRequester GetInterface
|
||||
{
|
||||
get
|
||||
{
|
||||
return rec.get_interface;
|
||||
}
|
||||
}
|
||||
|
||||
internal override IntPtr Reference
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Reference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.Reference = value;
|
||||
rec = PInvokeHelper.PtrToStructure<ModuleClassRec>(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#region MIT License
|
||||
/*Copyright (c) 2012-2015 Robert Rouhani <robert.rouhani@gmail.com>
|
||||
|
||||
SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using FT_Long = System.IntPtr;
|
||||
using FT_ULong = System.UIntPtr;
|
||||
|
||||
namespace SharpFont.MultipleMasters.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MMAxisRec
|
||||
{
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
internal string name;
|
||||
|
||||
internal FT_Long minimum;
|
||||
internal FT_Long maximum;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user