SharpFont + ScalableFont implementation

https://github.com/Robmaister/SharpFont

TODO: replace Code Bold.otf with the full version, fix any bugs, build on Linux, possibly move ToolBox string wrapping and limiting logic to ScalableFont class for better results.
This commit is contained in:
juanjp600
2017-03-07 13:44:42 -03:00
parent 88a76f0c9f
commit d6c292a2cc
231 changed files with 28528 additions and 94 deletions

View File

@@ -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
}
}

View File

@@ -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);
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
{
}
}

View File

@@ -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
{
}
}

View File

@@ -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;
}
}

View File

@@ -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
{
}
}

View File

@@ -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
{
}
}

View File

@@ -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
{
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}