GSFont.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. GSFont.h ... Graphics Service Font
  3. Copyright (c) 2009, KennyTM~
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7. * Redistributions of source code must retain the above copyright notice, this
  8. list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. * Neither the name of the KennyTM~ nor the names of its contributors may be
  13. used to endorse or promote products derived from this software without
  14. specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef GSFONT_H
  27. #define GSFONT_H
  28. #include <CoreGraphics/CoreGraphics.h>
  29. #include <CoreFoundation/CoreFoundation.h>
  30. #include <Availability2.h>
  31. #if __cplusplus
  32. extern "C" {
  33. #endif
  34. /*!
  35. @file GSFont.h
  36. @brief Mid-level wrapper of font stuff.
  37. @author Kenny TM~
  38. @date 2009 Aug 5
  39. GSFont is a "mid-level" wrapper of many CGFont operations. It includes functions that
  40. - Caching common fonts, and
  41. - Creating common fonts by a font family, traits and size.
  42. */
  43. typedef struct __GSFont* GSFontRef;
  44. typedef enum __GSFontTraitMask {
  45. // Why not kGS...? Ask Apple. http://www.opensource.apple.com/source/WebCore/WebCore-351.9/platform/graphics/mac/FontCacheMac.mm
  46. GSItalicFontMask = 1,
  47. GSBoldFontMask = 2,
  48. // Backward compatibility with WinterBoard.
  49. kGSFontTraitNone = 0,
  50. kGSFontTraitBold = 1,
  51. kGSFontTraitItalic = 2,
  52. kGSFontTraitBoldItalic = 3
  53. } GSFontTraitMask;
  54. // Backward compatibility with WinterBoard.
  55. typedef GSFontTraitMask GSFontTrait;
  56. /*
  57. struct __GSFont {
  58. __CFRuntimeBase _base; // 0
  59. CGFontRef _cgFont; // 8
  60. CGFloat _size; // c
  61. struct GSFontTraits _traits; // 10
  62. struct GSFontTraits _xorTraits; // 14
  63. CGFloat _ascent; // 18
  64. CGFloat _descent; // 1c
  65. CGFloat _lineSpacing; // 20
  66. CGFloat _lineGap; // 24
  67. CGFloat _maximumAdvanceWidth // 28 (since 3.2)
  68. }
  69. */
  70. CFHashCode GSFontHash(GSFontRef font); ///< Compute the font's hash value.
  71. Boolean GSFontEqual(GSFontRef a, GSFontRef b); ///< Determine if two fonts are equal.
  72. CFTypeID GSFontGetTypeID(); ///< Get the CoreFoundation type identifier of GSFont.
  73. /*!
  74. @brief Set to use legacy font metrics or not.
  75. The setting will apply when you create a GSFont. The difference between using legacy metrics or not is that, with
  76. the modern metrics, most floating point operations are single precision, and float-to-int operations are rounded up
  77. (ceiling), while for legacy metrics there are more double precision operations and floating points are rounded to the
  78. nearest integers (floor(0.5+x)). There may be some other differences in the algorithm.
  79. */
  80. void GSFontSetUseLegacyFontMetrics(Boolean useLegacyFontMetrics);
  81. Boolean GSFontGetUseLegacyFontMetrics(); ///< Get whether legacy font metrics is used.
  82. CGFontRef GSFontGetCGFont(GSFontRef font); ///< Get CGFont from a GSFont.
  83. Boolean GSFontIsBold(GSFontRef font); ///< Check whether a font is bold.
  84. GSFontTraitMask GSFontGetTraits(GSFontRef font); ///< Get the traits mask of the font.
  85. GSFontTraitMask GSFontGetSynthesizedTraits(GSFontRef font); ///< Get the synthesized traits mask of the font.
  86. CGFloat GSFontGetSize(GSFontRef font); ///< Get the font's point size
  87. CGFloat GSFontGetAscent(GSFontRef font); ///< Get the font's ascent.
  88. CGFloat GSFontGetDescent(GSFontRef font); ///< Get the font's descent.
  89. CGFloat GSFontGetLineSpacing(GSFontRef font); ///< Get the font's line spacing.
  90. CGFloat GSFontGetLineGap(GSFontRef font); ///< Get the font's line gap.
  91. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
  92. CGFloat GSFontGetMaximumAdvanceWidth(GSFontRef font); ///< Get the font's maximum advance width.
  93. #endif
  94. typedef enum CGFontRenderingMode {
  95. kCGFontRenderingModeAntialiased = 3
  96. } CGFontRenderingMode;
  97. /// Compute the transformed advances (occupied size?) of glyphs in the font.
  98. Boolean GSFontGetGlyphTransformedAdvances(GSFontRef font, const CGAffineTransform transforms[], CGFontRenderingMode mode, const CGGlyph glyph[], unsigned count, CGSize transformedAdvances[]);
  99. /// Find the glyphs of the corresponding Unicode characters.
  100. void GSFontGetGlyphsForUnichars(GSFontRef font, const UniChar unichars[], CGGlyph glyphs[], size_t count);
  101. size_t GSFontGetNumberOfGlyphs(GSFontRef font); ///< Get the number of glyphs in the font.
  102. int GSFontGetUnitsPerEm(GSFontRef font);
  103. CGFloat GSFontGetCapHeight(GSFontRef font);
  104. CGFloat GSFontGetXHeight(GSFontRef font);
  105. GSFontTraitMask GSFontGetTraitsForName(const char* fontName);
  106. Boolean GSFontIsFixedPitch(GSFontRef font);
  107. const char* GSFontGetFamilyName(GSFontRef font);
  108. const char* GSFontGetFullName(GSFontRef font);
  109. CFArrayRef GSFontCopyFontNamesForFamilyName(const char* familyName); // an array of CFString, not const char*
  110. CFArrayRef GSFontCopyFamilyNames();
  111. #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2
  112. void GSFontPurgeFontCache();
  113. #endif
  114. void GSFontInitialize();
  115. /// Use the specified font in the context.
  116. void GSFontSetFont(CGContextRef context, GSFontRef font);
  117. /// Add a CGFont for search.
  118. Boolean GSFontAddCGFont(CGFontRef cgFont);
  119. /// Add a font from a file to search.
  120. Boolean GSFontAddFromFile(const char* filename);
  121. GSFontRef GSFontCreateWithName(const char* fontName, GSFontTraitMask traits, CGFloat fontSize);
  122. const char* GSFontGetPostScriptName(GSFontRef font);
  123. #if __cplusplus
  124. }
  125. #endif
  126. #endif