/ CoreText / include / CoreText / CTFont.h
CTFont.h
  1  /* Copyright (c) 2007 Christopher J. W. Lloyd
  2  
  3  Permission is hereby granted, free of charge, to any person obtaining a copy of
  4  this software and associated documentation files(the "Software"), to deal in the
  5  Software without restriction, including without limitation the rights to use,
  6  copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
  7  Software, and to permit persons to whom the Software is furnished to do so,
  8  subject to the following conditions:
  9  
 10  The above copyright notice and this permission notice shall be included in all
 11  copies or substantial portions of the Software.
 12  
 13  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 14  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 15  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 16  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 17  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 18  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
 19  
 20  #import <CoreGraphics/CGContext.h>
 21  #import <CoreText/CTFontDescriptor.h>
 22  #import <CoreText/CTParagraphStyle.h>
 23  #import <CoreText/CoreTextExport.h>
 24  #import <ATS/ATS.h>
 25  
 26  typedef struct CF_BRIDGED_TYPE(id) KTFont *CTFontRef;
 27  
 28  CORETEXT_EXPORT const CFStringRef kCTFontCopyrightNameKey;
 29  CORETEXT_EXPORT const CFStringRef kCTFontFamilyNameKey;
 30  CORETEXT_EXPORT const CFStringRef kCTFontSubFamilyNameKey;
 31  CORETEXT_EXPORT const CFStringRef kCTFontStyleNameKey;
 32  CORETEXT_EXPORT const CFStringRef kCTFontUniqueNameKey;
 33  CORETEXT_EXPORT const CFStringRef kCTFontFullNameKey;
 34  CORETEXT_EXPORT const CFStringRef kCTFontVersionNameKey;
 35  CORETEXT_EXPORT const CFStringRef kCTFontPostScriptNameKey;
 36  CORETEXT_EXPORT const CFStringRef kCTFontTrademarkNameKey;
 37  CORETEXT_EXPORT const CFStringRef kCTFontManufacturerNameKey;
 38  CORETEXT_EXPORT const CFStringRef kCTFontDesignerNameKey;
 39  CORETEXT_EXPORT const CFStringRef kCTFontDescriptionNameKey;
 40  CORETEXT_EXPORT const CFStringRef kCTFontVendorURLNameKey;
 41  CORETEXT_EXPORT const CFStringRef kCTFontDesignerURLNameKey;
 42  CORETEXT_EXPORT const CFStringRef kCTFontLicenseNameKey;
 43  CORETEXT_EXPORT const CFStringRef kCTFontLicenseURLNameKey;
 44  CORETEXT_EXPORT const CFStringRef kCTFontSampleTextNameKey;
 45  CORETEXT_EXPORT const CFStringRef kCTFontPostScriptCIDNameKey;
 46  
 47  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisIdentifierKey;
 48  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisMinimumValueKey;
 49  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisMaximumValueKey;
 50  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisDefaultValueKey;
 51  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisNameKey;
 52  CORETEXT_EXPORT const CFStringRef kCTFontVariationAxisHiddenKey;
 53  
 54  CORETEXT_EXPORT const CFStringRef kCTFontFeatureTypeIdentifierKey;
 55  CORETEXT_EXPORT const CFStringRef kCTFontFeatureTypeNameKey;
 56  CORETEXT_EXPORT const CFStringRef kCTFontFeatureTypeExclusiveKey;
 57  CORETEXT_EXPORT const CFStringRef kCTFontFeatureTypeSelectorsKey;
 58  CORETEXT_EXPORT const CFStringRef kCTFontFeatureSelectorIdentifierKey;
 59  CORETEXT_EXPORT const CFStringRef kCTFontFeatureSelectorNameKey;
 60  CORETEXT_EXPORT const CFStringRef kCTFontFeatureSelectorDefaultKey;
 61  CORETEXT_EXPORT const CFStringRef kCTFontFeatureSelectorSettingKey;
 62  CORETEXT_EXPORT const CFStringRef kCTFontFeatureSampleTextKey;
 63  CORETEXT_EXPORT const CFStringRef kCTFontFeatureTooltipTextKey;
 64  
 65  typedef enum CTFontUIFontType : uint32_t {
 66      kCTFontUIFontNone = (uint32_t)-1,
 67      kCTFontUIFontUser = 0,
 68      kCTFontUserFontType = 0, // Deprecated
 69      kCTFontUIFontUserFixedPitch = 1,
 70      kCTFontUserFixedPitchFontType = 1,
 71      kCTFontUIFontSystem = 2,
 72      kCTFontSystemFontType = 2, // Deprecated
 73      kCTFontUIFontEmphasizedSystem = 3,
 74      kCTFontEmphasizedSystemFontType = 3, // Deprecated
 75      kCTFontUIFontSmallSystem = 4,
 76      kCTFontSmallSystemFontType = 4, // Deprecated
 77      kCTFontUIFontSmallEmphasizedSystem = 5,
 78      kCTFontSmallEmphasizedSystemFontType = 5, // Deprecated
 79      kCTFontUIFontMiniSystem = 6,
 80      kCTFontMiniSystemFontType = 6, // Deprecated
 81      kCTFontUIFontMiniEmphasizedSystem = 7,
 82      kCTFontMiniEmphasizedSystemFontType = 7, // Deprecated
 83      kCTFontUIFontViews = 8,
 84      kCTFontViewsFontType = 8, // Deprecated
 85      kCTFontUIFontApplication = 9,
 86      kCTFontApplicationFontType = 9, // Deprecated
 87      kCTFontUIFontLabel = 10,
 88      kCTFontLabelFontType = 10, // Deprecated
 89      kCTFontUIFontMenuTitle = 11,
 90      kCTFontMenuTitleFontType = 11, // Deprecated
 91      kCTFontUIFontMenuItem = 12,
 92      kCTFontMenuItemFontType = 12, // Deprecated
 93      kCTFontUIFontMenuItemMark = 13,
 94      kCTFontMenuItemMarkFontType = 13, // Deprecated
 95      kCTFontUIFontMenuItemCmdKey = 14,
 96      kCTFontMenuItemCmdKeyFontType = 14, // Deprecated
 97      kCTFontUIFontWindowTitle = 15,
 98      kCTFontWindowTitleFontType = 15, // Deprecated
 99      kCTFontUIFontPushButton = 16,
100      kCTFontPushButtonFontType = 16, // Deprecated
101      kCTFontUIFontUtilityWindowTitle = 17,
102      kCTFontUtilityWindowTitleFontType = 17, // Deprecated
103      kCTFontUIFontAlertHeader = 18,
104      kCTFontAlertHeaderFontType = 18, // Deprecated
105      kCTFontUIFontSystemDetail = 19,
106      kCTFontSystemDetailFontType = 19, // Deprecated
107      kCTFontUIFontEmphasizedSystemDetail = 20,
108      kCTFontEmphasizedSystemDetailFontType = 20, // Deprecated
109      kCTFontUIFontToolbar = 21,
110      kCTFontToolbarFontType = 21, // Deprecated
111      kCTFontUIFontSmallToolbar = 22,
112      kCTFontSmallToolbarFontType = 22, // Deprecated
113      kCTFontUIFontMessage = 23,
114      kCTFontMessageFontType = 23, // Deprecated
115      kCTFontUIFontPalette = 24,
116      kCTFontPaletteFontType = 24, // Deprecated
117      kCTFontUIFontToolTip = 25,
118      kCTFontToolTipFontType = 25, // Deprecated
119      kCTFontUIFontControlContent = 26,
120      kCTFontControlContentFontType = 26 // Deprecated
121  } CTFontUIFontType;
122  
123  typedef CF_OPTIONS(uint32_t, CTFontTableOptions) {
124      kCTFontTableOptionNoOptions        = 0,
125      kCTFontTableOptionExcludeSynthetic = 1, // Deprecated
126  };
127  
128  enum : unsigned int {
129      kCTFontTableBASE = 'BASE',
130      kCTFontTableCFF  = 'CFF ',
131      kCTFontTableDSIG = 'DSIG',
132      kCTFontTableEBDT = 'EBDT',
133      kCTFontTableEBLC = 'EBLC',
134      kCTFontTableEBSC = 'EBSC',
135      kCTFontTableGDEF = 'GDEF',
136      kCTFontTableGPOS = 'GPOS',
137      kCTFontTableGSUB = 'GSUB',
138      kCTFontTableJSTF = 'JSTF',
139      kCTFontTableLTSH = 'LTSH',
140      kCTFontTableOS2  = 'OS/2',
141      kCTFontTablePCLT = 'PCLT',
142      kCTFontTableVDMX = 'VDMX',
143      kCTFontTableVORG = 'VORG',
144      kCTFontTableZapf = 'Zapf',
145      kCTFontTableAcnt = 'acnt',
146      kCTFontTableAvar = 'avar',
147      kCTFontTableBdat = 'bdat',
148      kCTFontTableBhed = 'bhed',
149      kCTFontTableBloc = 'bloc',
150      kCTFontTableBsln = 'bsln',
151      kCTFontTableCmap = 'cmap',
152      kCTFontTableCvar = 'cvar',
153      kCTFontTableCvt  = 'cvt ',
154      kCTFontTableFdsc = 'fdsc',
155      kCTFontTableFeat = 'feat',
156      kCTFontTableFmtx = 'fmtx',
157      kCTFontTableFpgm = 'fpgm',
158      kCTFontTableFvar = 'fvar',
159      kCTFontTableGasp = 'gasp',
160      kCTFontTableGlyf = 'glyf',
161      kCTFontTableGvar = 'gvar',
162      kCTFontTableHdmx = 'hdmx',
163      kCTFontTableHead = 'head',
164      kCTFontTableHhea = 'hhea',
165      kCTFontTableHmtx = 'hmtx',
166      kCTFontTableHsty = 'hsty',
167      kCTFontTableJust = 'just',
168      kCTFontTableKern = 'kern',
169      kCTFontTableKerx = 'kerx',
170      kCTFontTableLcar = 'lcar',
171      kCTFontTableLoca = 'loca',
172      kCTFontTableMaxp = 'maxp',
173      kCTFontTableMort = 'mort',
174      kCTFontTableMorx = 'morx',
175      kCTFontTableName = 'name',
176      kCTFontTableOpbd = 'opbd',
177      kCTFontTablePost = 'post',
178      kCTFontTablePrep = 'prep',
179      kCTFontTableProp = 'prop',
180      kCTFontTableSbit = 'sbit',
181      kCTFontTableSbix = 'sbix',
182      kCTFontTableTrak = 'trak',
183      kCTFontTableVhea = 'vhea',
184      kCTFontTableVmtx = 'vmtx'
185  };
186  typedef FourCharCode CTFontTableTag;
187  
188  typedef enum CTFontOptions : CFOptionFlags {
189      kCTFontOptionsDefault = 0,
190      kCTFontOptionsPreventAutoActivation = 1 << 0,
191      kCTFontOptionsPreventAutoDownload = 1 << 1,
192      kCTFontOptionsPreferSystemFont = 1 << 2,
193  } CTFontOptions;
194  
195  CF_IMPLICIT_BRIDGING_ENABLED
196  
197  CORETEXT_EXPORT CTFontRef CTFontCreateWithName(CFStringRef name, CGFloat size,
198                                                 const CGAffineTransform *matrix);
199  CORETEXT_EXPORT CTFontRef CTFontCreateWithNameAndOptions(
200          CFStringRef name, CGFloat size, const CGAffineTransform *matrix,
201          CTFontOptions options);
202  CORETEXT_EXPORT CTFontRef CTFontCreateWithFontDescriptor(
203          CTFontDescriptorRef descriptor, CGFloat size,
204          const CGAffineTransform *matrix);
205  CORETEXT_EXPORT CTFontRef CTFontCreateWithFontDescriptorAndOptions(
206          CTFontDescriptorRef descriptor, CGFloat size,
207          const CGAffineTransform *matrix, CTFontOptions options);
208  CORETEXT_EXPORT CTFontRef CTFontCreateUIFontForLanguage(
209          CTFontUIFontType uiFontType, CGFloat size, CFStringRef language);
210  CORETEXT_EXPORT CTFontRef CTFontCreateCopyWithAttributes(
211          CTFontRef font, CGFloat size, const CGAffineTransform *matrix,
212          CTFontDescriptorRef attributes);
213  CORETEXT_EXPORT CTFontRef CTFontCreateCopyWithSymbolicTraits(CTFontRef font, CGFloat size, const CGAffineTransform *matrix, CTFontSymbolicTraits symTraitValue, CTFontSymbolicTraits symTraitMask);
214  CORETEXT_EXPORT CTFontRef CTFontCreateCopyWithFamily(CTFontRef font, CGFloat size, const CGAffineTransform *matrix, CFStringRef family);
215  CORETEXT_EXPORT CTFontRef CTFontCreateForString(CTFontRef currentFont, CFStringRef string, CFRange range);
216  CORETEXT_EXPORT CTFontRef CTFontCreateForStringWithLanguage(CTFontRef currentFont, CFStringRef string, CFRange range, CFStringRef language);
217  
218  CORETEXT_EXPORT CTFontDescriptorRef CTFontCopyFontDescriptor(CTFontRef font);
219  CORETEXT_EXPORT CFTypeRef CTFontCopyAttribute(CTFontRef font, CFStringRef attribute);
220  CORETEXT_EXPORT CGFloat CTFontGetSize(CTFontRef self);
221  CORETEXT_EXPORT CGAffineTransform CTFontGetMatrix(CTFontRef font);
222  CORETEXT_EXPORT CTFontSymbolicTraits CTFontGetSymbolicTraits(CTFontRef font);
223  
224  CORETEXT_EXPORT CFDictionaryRef CTFontCopyTraits(CTFontRef font);
225  CORETEXT_EXPORT CFArrayRef CTFontCopyDefaultCascadeListForLanguages(CTFontRef font, CFArrayRef languagePrefList);
226  
227  CORETEXT_EXPORT CFStringRef CTFontCopyPostScriptName(CTFontRef font);
228  CORETEXT_EXPORT CFStringRef CTFontCopyFamilyName(CTFontRef font);
229  CORETEXT_EXPORT CFStringRef CTFontCopyFullName(CTFontRef self);
230  CORETEXT_EXPORT CFStringRef CTFontCopyDisplayName(CTFontRef font);
231  CORETEXT_EXPORT CFStringRef CTFontCopyName(CTFontRef font, CFStringRef nameKey);
232  CORETEXT_EXPORT CFStringRef CTFontCopyLocalizedName(CTFontRef font, CFStringRef nameKey, CFStringRef  _Nullable *actualLanguage);
233  
234  CORETEXT_EXPORT CFCharacterSetRef CTFontCopyCharacterSet(CTFontRef font);
235  CORETEXT_EXPORT CFStringEncoding CTFontGetStringEncoding(CTFontRef font);
236  CORETEXT_EXPORT CFArrayRef CTFontCopySupportedLanguages(CTFontRef font);
237  
238  CORETEXT_EXPORT CGFloat CTFontGetAscent(CTFontRef self);
239  CORETEXT_EXPORT CGFloat CTFontGetDescent(CTFontRef self);
240  CORETEXT_EXPORT CGFloat CTFontGetLeading(CTFontRef self);
241  CORETEXT_EXPORT unsigned int CTFontGetUnitsPerEm(CTFontRef font);
242  CORETEXT_EXPORT CFIndex CTFontGetGlyphCount(CTFontRef font);
243  CORETEXT_EXPORT CGRect CTFontGetBoundingBox(CTFontRef self);
244  CORETEXT_EXPORT CGFloat CTFontGetUnderlinePosition(CTFontRef self);
245  CORETEXT_EXPORT CGFloat CTFontGetUnderlineThickness(CTFontRef self);
246  CORETEXT_EXPORT CGFloat CTFontGetSlantAngle(CTFontRef self);
247  CORETEXT_EXPORT CGFloat CTFontGetCapHeight(CTFontRef self);
248  CORETEXT_EXPORT CGFloat CTFontGetXHeight(CTFontRef self);
249  
250  CORETEXT_EXPORT CGPathRef CTFontCreatePathForGlyph(CTFontRef self,
251                                                     CGGlyph glyph,
252                                                     CGAffineTransform *xform);
253  CORETEXT_EXPORT CGGlyph CTFontGetGlyphWithName(CTFontRef font, CFStringRef glyphName);
254  CORETEXT_EXPORT CGRect CTFontGetBoundingRectsForGlyphs(CTFontRef font, CTFontOrientation orientation, const CGGlyph *glyphs, CGRect *boundingRects, CFIndex count);
255  CORETEXT_EXPORT double CTFontGetAdvancesForGlyphs(CTFontRef font, CTFontOrientation orientation,
256                                                  const CGGlyph *glyphs,
257                                                  CGSize *advances, CFIndex count);
258  CORETEXT_EXPORT CGRect CTFontGetOpticalBoundsForGlyphs(CTFontRef font, const CGGlyph *glyphs, CGRect *boundingRects, CFIndex count, CFOptionFlags options);
259  CORETEXT_EXPORT void CTFontGetVerticalTranslationsForGlyphs(CTFontRef font, const CGGlyph *glyphs, CGSize *translations, CFIndex count);
260  
261  CORETEXT_EXPORT CFArrayRef CTFontCopyVariationAxes(CTFontRef font);
262  CORETEXT_EXPORT CFDictionaryRef CTFontCopyVariation(CTFontRef font);
263  
264  CORETEXT_EXPORT CFArrayRef CTFontCopyFeatures(CTFontRef font);
265  CORETEXT_EXPORT CFArrayRef CTFontCopyFeatureSettings(CTFontRef font);
266  
267  CORETEXT_EXPORT bool CTFontGetGlyphsForCharacters(CTFontRef font, const UniChar *characters, CGGlyph *glyphs, CFIndex count);
268  CORETEXT_EXPORT void CTFontDrawGlyphs(CTFontRef font, const CGGlyph *glyphs, const CGPoint *positions, size_t count, CGContextRef context);
269  CORETEXT_EXPORT CFIndex CTFontGetLigatureCaretPositions(CTFontRef font, CGGlyph glyph, CGFloat *positions, CFIndex maxPositions);
270  
271  CORETEXT_EXPORT CGFontRef CTFontCopyGraphicsFont(
272          CTFontRef font, CTFontDescriptorRef _Nullable *attributes);
273  CORETEXT_EXPORT CTFontRef CTFontCreateWithGraphicsFont(
274          CGFontRef cgFont, CGFloat size, CGAffineTransform *xform,
275          CTFontDescriptorRef attributes);
276  
277  CORETEXT_EXPORT ATSFontRef CTFontGetPlatformFont(CTFontRef font, CTFontDescriptorRef  _Nullable *attributes); // Deprecated
278  CORETEXT_EXPORT CTFontRef CTFontCreateWithPlatformFont(ATSFontRef platformFont, CGFloat size, const CGAffineTransform *matrix, CTFontDescriptorRef attributes); // Deprecated
279  CORETEXT_EXPORT CTFontRef CTFontCreateWithQuickdrawInstance(ConstStr255Param name, int16_t identifier, uint8_t style, CGFloat size); // Deprecated
280  
281  CORETEXT_EXPORT CFArrayRef CTFontCopyAvailableTables(CTFontRef font, CTFontTableOptions options);
282  CORETEXT_EXPORT CFDataRef CTFontCopyTable(CTFontRef font, CTFontTableTag table, CTFontTableOptions options);
283  
284  CORETEXT_EXPORT CFTypeID CTFontGetTypeID(void);
285  
286  CF_IMPLICIT_BRIDGING_DISABLED