#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; namespace SharpFont.Cache { /// /// 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 /// . /// public class SBitCache { #region Fields private IntPtr reference; private Manager parentManager; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// A handle to the source cache manager. 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 /// /// Look up a given small glyph bitmap in a given sbit cache and ‘lock’ it to prevent its flushing from the /// cache until needed. /// /// /// 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. /// /// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap. /// /// 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 to ‘release’ it. /// /// 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! /// /// A pointer to the glyph image type descriptor. /// The glyph index. /// /// Used to return the address of of the corresponding cache node after incrementing its reference count (see /// note below). /// /// A handle to a small bitmap descriptor. [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); } /// /// A variant of that uses a to specify the face ID and its /// size. /// /// /// 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. /// /// The descriptor's ‘buffer’ field is set to 0 to indicate a missing glyph bitmap. /// /// 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 to ‘release’ it. /// /// 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! /// /// A pointer to the scaler descriptor. /// The corresponding load flags. /// The glyph index. /// /// Used to return the address of of the corresponding cache node after incrementing its reference count (see /// note below). /// /// A handle to a small bitmap descriptor. [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 } }