public float getAttributeSize ( ScoreAttribute sa ) throws AttributeNotDefinedException , RuntimeException { if ( ! ( sa . getDefaultValue ( ) instanceof ScoreAttribute . Size ) ) throw new RuntimeException ( sa . toString ( ) + " is not a size attribute" ) ; ScoreAttribute . Size s = ( ScoreAttribute . Size ) getAttributeObject ( sa ) ; if ( s == null ) throw new AttributeNotDefinedException ( sa ) ; SizeUnit u = s . getUnit ( ) ; float size = s . getSize ( ) ; if ( ( u . equals ( SizeUnit . PX ) ) || ( u . equals ( SizeUnit . PT ) ) ) { return size ; } else if ( u . equals ( SizeUnit . NOTE_HEIGHT ) ) { return ( float ) ( size * getMetrics ( ) . getNoteHeight ( ) ) ; } else if ( u . equals ( SizeUnit . NOTE_WIDTH ) ) { return ( float ) ( size * getMetrics ( ) . getNoteWidth ( ) ) ; } else if ( u . equals ( SizeUnit . GRACENOTE_HEIGHT ) ) { return ( float ) ( size * getMetrics ( ) . getGraceNoteHeight ( ) ) ; } else if ( u . equals ( SizeUnit . GRACENOTE_WIDTH ) ) { return ( float ) ( size * getMetrics ( ) . getGraceNoteWidth ( ) ) ; } else if ( u . equals ( SizeUnit . STAFF_HEIGHT ) ) { return ( float ) ( size * getMetrics ( ) . getStaffCharBounds ( ) . getHeight ( ) ) ; } else if ( u . equals ( SizeUnit . STAFF_WIDTH ) ) { return ( float ) ( size * getMetrics ( ) . getStaffCharBounds ( ) . getWidth ( ) ) ; } else if ( u . equals ( SizeUnit . PERCENT ) ) { return size / 100 * getAttributeSize ( ScoreAttribute . NOTATION_SIZE ) ; } else throw new RuntimeException ( "unknown size unit for attribute: " + sa . toString ( ) ) ; }
Gets the size of an attribute calculated from score metrics if needed .