 
 import AVFoundation
 import ImageIO
+import CoreText
 
 private func MyLog(text:String, level:Int = 0) {
     let s_verbosLevel = 0

    func addTextLayer(text:String, info:[String:AnyObject], dimension:CGSize, layer:CALayer) {
        var fTextBottom = false
        var fTextTop = false
        var rcText = layer.bounds
        let textLayer = CATextLayer()
        textLayer.wrapped = true
        textLayer.frame = rcText

        textLayer.alignmentMode = kCAAlignmentCenter
        func processAlignment(alignment:String) {

        attr[NSForegroundColorAttributeName] = UIColor(CGColor: SwipeParser.parseColor(self.info["textColor"], defaultColor: blackColor))
        processShadow(info, layer: layer)

        let attrString = NSAttributedString(string: text, attributes: attr)
        textLayer.string = attrString

        textLayer.frame = {
            var rcText = layer.bounds
            let setter = CTFramesetterCreateWithAttributedString(attrString)
            let suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(setter, CFRangeMake(0, attrString.length), nil, CGSizeMake(rcText.width, 99999), nil)
            if fTextBottom {
                rcText.origin.y = rcText.size.height - suggestedSize.height
            } else if !fTextTop {
                rcText.origin.y =  (rcText.size.height - suggestedSize.height) / 2
            }
            rcText.size.height = suggestedSize.height
            return rcText
        }()
        layer.addSublayer(textLayer)
    }
    
