import dealParagraph from './dealParagraph' ; import dealColor from './dealColor' ; import dealFont from './dealFont' ; import dealLetterSpacing from './dealLetterSpacing' ; import dealTextDecorate from './dealTextDecorate' ; import { SKLayer , TextStyle , SKParagraphStyle } from '../../types' ; export default ( layer ) : any [ ] => { if ( layer . attributedString && layer . attributedString . string && layer . attributedString . attributes ) { let size = 1 ; let attrList = layer . attributedString . attributes ; let strStyleList = [ ] ; let minFontSize = 0 ; for ( let attrItem of attrList ) { if ( attrItem . _class == 'stringAttribute' ) { let attributes = attrItem . attributes ; let fontStyle = attributes [ 'MSAttributedStringFontAttribute' ] ; let colorStyle = attributes [ 'MSAttributedStringColorAttribute' ] || { red : 0 , green : 0 , blue : 0 , alpha : 1 , _class : 'color' } ; let paragraphStyleObj = attributes [ 'paragraphStyle' ] ; let kerning = attributes [ 'kerning' ] ; const textStyle = { ... dealParagraph ( paragraphStyleObj , fontStyle , size ) , ... dealColor ( colorStyle , layer ) , ... dealFont ( fontStyle , size ) , ... dealLetterSpacing ( kerning ) , ... dealTextDecorate ( attributes ) , } ; if ( minFontSize > textStyle . fontSize ) { minFontSize = textStyle . fontSize ; } } } let isTextBreak = false ; if ( minFontSize && minFontSize > 0.5 * layer . frame . height ) { isTextBreak = true ; } for ( let attrItem of attrList ) { if ( attrItem . _class == 'stringAttribute' ) { let attributes = attrItem . attributes ; let fontStyle = attributes [ 'MSAttributedStringFontAttribute' ] ; let colorStyle = attributes [ 'MSAttributedStringColorAttribute' ] || { red : 0 , green : 0 , blue : 0 , alpha : 1 , _class : 'color' } ; let paragraphStyleObj = attributes [ 'paragraphStyle' ] ; let kerning = attributes [ 'kerning' ] ; const style = { pos : [ attrItem . location , attrItem . length ] , ... dealParagraph ( paragraphStyleObj , fontStyle , size ) , ... dealColor ( colorStyle , layer ) , ... dealFont ( fontStyle , size ) , ... dealLetterSpacing ( kerning ) , ... dealTextDecorate ( attributes ) , } ; strStyleList . push ( style ) ; } } return strStyleList ; } return [ ] ; } ;