<commit_before>//
//  TextStyle.swift
//  SwiftStylable
//
//  Created by <NAME> on 20/09/2018.
//

import Foundation

public class TextStyle : StyleSetBase {
    
    public private(set) var font:UIFont?
    public private(set) var fullUppercaseText:Bool?
    
    private let _parent:TextStyle?
    
    private (set) var fontName:String?
    private (set) var fontSize:CGFloat?
    private var _fullUppercaseText:Bool?
    
    
    // -----------------------------------------------------------------------------------------------------------------------
    //
    // MARK: - Initializers
    //
    // -----------------------------------------------------------------------------------------------------------------------
    
    internal init(name:String, parent:TextStyle? = nil, data:[String:Any], colorCollection:ColorCollection) {
        self._parent = parent
        super.init(name: name, parent: parent, colorCollection: colorCollection)
        self.applyData(data)
    }
    
    
    // -----------------------------------------------------------------------------------------------------------------------
    //
    // MARK: - Internal methods
    //
    // -----------------------------------------------------------------------------------------------------------------------
    
    override internal func _applyData(_ data:[String:Any]) {
        super._applyData(data)
        
        if let font = data["font"] as? [String:Any] {
            if let name = font["name"] as? String {
                self.fontName = name
            }
            if let sizeAny = font["size"] {
                if let size = sizeAny as? CGFloat {
                    self.fontSize = size
                } else {
                    print("WARNING: Style definition for '\(self.name)' has a font size of type String, change to a Number in the styles.plist")
                }
            }
        }
        if let fullUppercaseText = data["fullUppercaseText"] as? Bool {
            self._fullUppercaseText = fullUppercaseText
        }
    }
    
    override internal func update() {
        super.update()
        
        self.font = self.createFont(name: self.fontName, size: self.fontSize, defaultName: self._parent?.fontName, defaultSize: self._parent?.fontSize)
        self.fullUppercaseText = self._fullUppercaseText ?? self._parent?.fullUppercaseText
    }
}<commit_msg>Fixed an issue causing the font to not be inherited from parents more than a generation away.<commit_after>//
//  TextStyle.swift
//  SwiftStylable
//
//  Created by <NAME> on 20/09/2018.
//

import Foundation

public class TextStyle : StyleSetBase {
    
    public private(set) var font:UIFont?
    public private(set) var fullUppercaseText:Bool?
    
    private let _parent:TextStyle?
    
    private var _fontName:String?
    private var _fontSize:CGFloat?
    private var _fullUppercaseText:Bool?
    
    
    // -----------------------------------------------------------------------------------------------------------------------
    //
    // MARK: - Initializers
    //
    // -----------------------------------------------------------------------------------------------------------------------
    
    internal init(name:String, parent:TextStyle? = nil, data:[String:Any], colorCollection:ColorCollection) {
        self._parent = parent
        super.init(name: name, parent: parent, colorCollection: colorCollection)
        self.applyData(data)
    }
    
    
    // -----------------------------------------------------------------------------------------------------------------------
    //
    // MARK: - Computed properties
    //
    // -----------------------------------------------------------------------------------------------------------------------
    
    var fontName:String? {
        get {
            return self._fontName ?? self._parent?.fontName
        }
    }
    
    var fontSize:CGFloat? {
        get {
            return self._fontSize ?? self._parent?.fontSize
        }
    }
    
    
    // -----------------------------------------------------------------------------------------------------------------------
    //
    // MARK: - Internal methods
    //
    // -----------------------------------------------------------------------------------------------------------------------
    
    override internal func _applyData(_ data:[String:Any]) {
        super._applyData(data)
        
        if let font = data["font"] as? [String:Any] {
            if let name = font["name"] as? String {
                self._fontName = name
            }
            if let sizeAny = font["size"] {
                if let size = sizeAny as? CGFloat {
                    self._fontSize = size
                } else {
                    print("WARNING: Style definition for '\(self.name)' has a font size of type String, change to a Number in the styles.plist")
                }
            }
        }
        if let fullUppercaseText = data["fullUppercaseText"] as? Bool {
            self._fullUppercaseText = fullUppercaseText
        }
    }
    
    override internal func update() {
        super.update()
        
        self.font = self.createFont(name: self.fontName, size: self.fontSize)
        self.fullUppercaseText = self._fullUppercaseText ?? self._parent?.fullUppercaseText
    }
}
{'fraction_non_alphanumeric': 0.3026956196181206, 'fraction_numerical': 0.002995132909022838, 'mean_word_length': 0.9921700223713646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5102815', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1202, 'n_words': 291}