static Decoration getDecoration(Map<? extends Attribute, ?> attributes) {
        if (attributes == null) {
            return null; // It is for plain text
        }

        Object underline = attributes.get(TextAttribute.UNDERLINE);
        boolean hasStandardUnderline = underline == TextAttribute.UNDERLINE_ON;

        Object imUnderline = attributes.get(TextAttribute.INPUT_METHOD_UNDERLINE);
        Integer imUl = (Integer) imUnderline;

        boolean swapBgFg =
                TextAttribute.SWAP_COLORS_ON.equals(
                        attributes.get(TextAttribute.SWAP_COLORS)
                );

        boolean strikeThrough =
                TextAttribute.STRIKETHROUGH_ON.equals(
                        attributes.get(TextAttribute.STRIKETHROUGH)
                );

        Paint fg = (Paint) attributes.get(TextAttribute.FOREGROUND);
        Paint bg = (Paint) attributes.get(TextAttribute.BACKGROUND);

        if (
                !hasStandardUnderline &&
                imUnderline == null &&
                fg == null &&
                bg == null &&
                !swapBgFg &&
                !strikeThrough
        ) {
            return null;
        }
        return new Decoration(imUl, swapBgFg, strikeThrough, bg, fg, hasStandardUnderline);
    }