private CharSequence css ( final String id , final Element svg ) { Throwing . Function < String , Tuple < Tuple < Number , String > , Tuple < Number , String > > > viewBox = Throwing . < String , Tuple < Tuple < Number , String > , Tuple < Number , String > > > throwingFunction ( name -> { String vbox = svg . attr ( name ) ; String [ ] dimension = vbox . split ( "\\s+" ) ; return new Tuple ( parse ( dimension [ 2 ] ) , parse ( dimension [ _3 ] ) ) ; } ) . memoized ( ) ; Tuple < Number , String > w = Optional . ofNullable ( Strings . emptyToNull ( svg . attr ( "width" ) ) ) . map ( this :: parse ) . orElseGet ( ( ) -> viewBox . apply ( "viewBox" ) . _1 ) ; Tuple < Number , String > h = Optional . ofNullable ( Strings . emptyToNull ( svg . attr ( "height" ) ) ) . map ( this :: parse ) . orElseGet ( ( ) -> viewBox . apply ( "viewBox" ) . _2 ) ; StringBuilder css = new StringBuilder ( ) ; css . append ( get ( "css.prefix" ) . toString ( ) ) . append ( "." ) . append ( id ) . append ( " {\n width: " ) . append ( w . _1 ) . append ( w . _2 ) . append ( ";\n" ) . append ( " height: " ) . append ( h . _1 ) . append ( h . _2 ) . append ( ";\n}" ) ; return css ; }
Generate a CSS rule it reads the width and height attributes of the svg element or fallback to viewBox attribute .