CMapCache.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #region MIT License
  2. /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
  3. SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.*/
  19. #endregion
  20. using System;
  21. namespace SharpFont.Cache
  22. {
  23. /// <summary>
  24. /// An opaque handle used to model a charmap cache. This cache is to hold character codes -> glyph indices
  25. /// mappings.
  26. /// </summary>
  27. public class CMapCache
  28. {
  29. #region Fields
  30. private IntPtr reference;
  31. #endregion
  32. #region Constructors
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="CMapCache"/> class.
  35. /// </summary>
  36. /// <remarks>
  37. /// Like all other caches, this one will be destroyed with the cache manager.
  38. /// </remarks>
  39. /// <param name="manager">A handle to the cache manager.</param>
  40. public CMapCache(Manager manager)
  41. {
  42. IntPtr cacheRef;
  43. Error err = FT.FTC_CMapCache_New(manager.Reference, out cacheRef);
  44. if (err != Error.Ok)
  45. throw new FreeTypeException(err);
  46. Reference = cacheRef;
  47. }
  48. #endregion
  49. #region Properties
  50. internal IntPtr Reference
  51. {
  52. get
  53. {
  54. return reference;
  55. }
  56. set
  57. {
  58. reference = value;
  59. }
  60. }
  61. #endregion
  62. #region Methods
  63. /// <summary>
  64. /// Translate a character code into a glyph index, using the charmap cache.
  65. /// </summary>
  66. /// <param name="faceId">The source face ID.</param>
  67. /// <param name="cmapIndex">
  68. /// The index of the charmap in the source face. Any negative value means to use the cache <see cref="Face"/>'s
  69. /// default charmap.
  70. /// </param>
  71. /// <param name="charCode">The character code (in the corresponding charmap).</param>
  72. /// <returns>Glyph index. 0 means ‘no glyph’.</returns>
  73. [CLSCompliant(false)]
  74. public uint Lookup(IntPtr faceId, int cmapIndex, uint charCode)
  75. {
  76. return FT.FTC_CMapCache_Lookup(Reference, faceId, cmapIndex, charCode);
  77. }
  78. #endregion
  79. }
  80. }