#region MIT License /*Copyright (c) 2012 Robert Rouhani 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 { /// /// A function used to create a new raster object. /// /// /// The ‘memory’ parameter is a typeless pointer in order to avoid un-wanted dependencies on the rest of the /// FreeType code. In practice, it is an object, i.e., a handle to the standard FreeType /// memory allocator. However, this field can be completely ignored by a given raster implementation. /// /// A handle to the memory allocator. /// A handle to the new raster object. /// Error code. 0 means success. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Error RasterNewFunc(IntPtr memory, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterMarshaler))] Raster raster); /// /// A function used to destroy a given raster object. /// /// A handle to the raster object. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void RasterDoneFunc([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterMarshaler))] Raster raster); /// /// FreeType provides an area of memory called the ‘render pool’, available to all registered rasters. This pool /// can be freely used during a given scan-conversion but is shared by all rasters. Its content is thus transient. /// /// This function is called each time the render pool changes, or just after a new raster object is created. /// /// /// Rasters can ignore the render pool and rely on dynamic memory allocation if they want to (a handle to the /// memory allocator is passed to the raster constructor). However, this is not recommended for efficiency /// purposes. /// /// A handle to the new raster object. /// The address in memory of the render pool. /// The size in bytes of the render pool. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void RasterResetFunc([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterMarshaler))] Raster raster, IntPtr pool_base, int pool_size); /// /// This function is a generic facility to change modes or attributes in a given raster. This can be used for /// debugging purposes, or simply to allow implementation-specific ‘features’ in a given raster module. /// /// A handle to the new raster object. /// A 4-byte tag used to name the mode or property. /// A pointer to the new mode/property to use. [CLSCompliant(false)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void RasterSetModeFunc([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterMarshaler))] Raster raster, uint mode, IntPtr args); /// /// Invoke a given raster to scan-convert a given glyph image into a target /// bitmap. /// /// /// The exact format of the source image depends on the raster's glyph format defined in its /// structure. It can be an or anything else in order to support a /// large array of glyph formats. /// /// Note also that the render function can fail and return a error code if /// the raster used does not support direct composition. /// /// XXX: For now, the standard raster doesn't support direct composition but this should change for the final /// release (see the files ‘demos/src/ftgrays.c’ and ‘demos/src/ftgrays2.c’ for examples of distinct /// implementations which support direct composition). /// /// A handle to the raster object. /// /// A pointer to an structure used to store the rendering parameters. /// /// Error code. 0 means success. [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Error RasterRenderFunc([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterMarshaler))] Raster raster, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(RasterParamsMarshaler))] RasterParams @params); /// /// A structure used to describe a given raster class to the library. /// public class RasterFuncs { #region Fields private IntPtr reference; private RasterFuncsRec rec; #endregion #region Constructors internal RasterFuncs(IntPtr reference) { Reference = reference; } internal RasterFuncs(IntPtr reference, IntPtr offset) : this(new IntPtr(reference.ToInt64() + offset.ToInt64())) { } #endregion #region Properties /// /// Gets the supported glyph format for this raster. /// [CLSCompliant(false)] public GlyphFormat Format { get { return rec.glyph_format; } } /// /// Gets the raster constructor. /// public RasterNewFunc New { get { return rec.raster_new; } } /// /// Gets a function used to reset the render pool within the raster. /// public RasterResetFunc Reset { get { return rec.raster_reset; } } /// /// Gets a function to set or change modes. /// [CLSCompliant(false)] public RasterSetModeFunc SetMode { get { return rec.raster_set_mode; } } /// /// Gets a function to render a glyph into a given bitmap. /// public RasterRenderFunc Render { get { return rec.raster_render; } } /// /// Gets the raster destructor. /// public RasterDoneFunc Done { get { return rec.raster_done; } } internal IntPtr Reference { get { return reference; } set { reference = value; rec = PInvokeHelper.PtrToStructure(reference); } } #endregion } }