| 147 | |
| 148 | export namespace ios { |
| 149 | export function registerFont(fontFile: string) { |
| 150 | let filePath = path.join(knownFolders.currentApp().path, FONTS_BASE_PATH, fontFile); |
| 151 | if (!File.exists(filePath)) { |
| 152 | filePath = path.join(knownFolders.currentApp().path, fontFile); |
| 153 | } |
| 154 | const fontData = NSFileManager.defaultManager.contentsAtPath(filePath); |
| 155 | if (!fontData) { |
| 156 | throw new Error('Could not load font from: ' + fontFile); |
| 157 | } |
| 158 | const provider = CGDataProviderCreateWithCFData(fontData); |
| 159 | const font = CGFontCreateWithDataProvider(provider); |
| 160 | |
| 161 | if (!font) { |
| 162 | throw new Error('Could not load font from: ' + fontFile); |
| 163 | } |
| 164 | |
| 165 | const error = new interop.Reference<NSError>(); |
| 166 | if (!CTFontManagerRegisterGraphicsFont(font, error)) { |
| 167 | if (Trace.isEnabled()) { |
| 168 | Trace.write('Error occur while registering font: ' + CFErrorCopyDescription(<NSError>error.value), Trace.categories.Error, Trace.messageType.error); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | function registerFontsInFolder(fontsFolderPath) { |