<commit_before>//
//  Icomoon.swift
//  Icomoon
//
//  Created by <NAME> on 25/12/2015.
//  Copyright © 2015 Optonaut. All rights reserved.
//

import UIKit

private class FontLoader {
    class func loadFont() {
        let bundle = Bundle(for: FontLoader.self)
        let fontURL = bundle.url(forResource: "font", withExtension: "ttf")!
        let data = try! Data(contentsOf: fontURL)
        
        if let provider = CGDataProvider(data: data as CFData) {
            let font = CGFont(provider)
            
            var error: Unmanaged<CFError>?
            if !CTFontManagerRegisterGraphicsFont(font, &error) {
                let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
                let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
                NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
            }
        }
    }
}

public extension UIFont {
    public static func iconOfSize(_ fontSize: CGFloat) -> UIFont {
        struct Static {
            static var onceToken : Int = {
                if UIFont.fontNames(forFamilyName: Font.FontName).count == 0 {
                    FontLoader.loadFont()
                }
                return 0
            }()
        }
        
        return UIFont(name: Font.FontName, size: fontSize)!
    }
}

public extension UIImage {
    public static func iconWithName(_ name: Icon, textColor: UIColor, fontSize: CGFloat, offset: CGSize = CGSize.zero) -> UIImage {
        let paragraph = NSMutableParagraphStyle()
        paragraph.lineBreakMode = .byWordWrapping
        paragraph.alignment = .center
        let attributes = [<commit_msg>Fix dispatch once<commit_after>//
//  Icomoon.swift
//  Icomoon
//
//  Created by <NAME> on 25/12/2015.
//  Copyright © 2015 Optonaut. All rights reserved.
//

import UIKit

private class FontLoader {
    class func loadFont() {
        let bundle = Bundle(for: FontLoader.self)
        let fontURL = bundle.url(forResource: "font", withExtension: "ttf")!
        let data = try! Data(contentsOf: fontURL)
        
        if let provider = CGDataProvider(data: data as CFData) {
            let font = CGFont(provider)
            
            var error: Unmanaged<CFError>?
            if !CTFontManagerRegisterGraphicsFont(font, &error) {
                let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue())
                let nsError = error!.takeUnretainedValue() as AnyObject as! NSError
                NSException(name: NSExceptionName.internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise()
            }
        }
    }
}

public extension UIFont {
    private static var _loaded = false
    
    public static func iconOfSize(_ fontSize: CGFloat) -> UIFont {
        if !_loaded {
            if UIFont.fontNames(forFamilyName: Font.FontName).count == 0 {
                FontLoader.loadFont()
            }
            _loaded = true
        }
        
        return UIFont(name: Font.FontName, size: fontSize)!
    }
}

public extension UIImage {
    public static func iconWithName(_ name: Icon, textColor: UIColor, fontSize: CGFloat, offset: CGSize = CGSize.zero) -> UIImage {
        let paragraph = NSMutableParagraphStyle()
        paragraph.lineBreakMode = .byWordWrapping
        paragraph.alignment = .center
        let attributes = [
{'fraction_non_alphanumeric': 0.09260832625318606, 'fraction_numerical': 0.0076465590484282074, 'mean_word_length': 2.2855813953488373, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4783832', 'n_tokens_mistral': 1035, 'n_tokens_neox': 976, 'n_words': 259}