static Rectangle2D extendVisualBounds(
            TextRunSegment trs,
            Rectangle2D segmentBounds,
            Decoration d
    ) {
        if (d == null) {
            return segmentBounds;
        }
        double minx = segmentBounds.getMinX();
        double miny = segmentBounds.getMinY();
        double maxx = segmentBounds.getMaxX();
        double maxy = segmentBounds.getMaxY();

        Rectangle2D lb = trs.getLogicalBounds();

        if (d.swapBfFg || d.bg != null) {
            minx = Math.min(lb.getMinX() - trs.x, minx);
            miny = Math.min(lb.getMinY() - trs.y, miny);
            maxx = Math.max(lb.getMaxX() - trs.x, maxx);
            maxy = Math.max(lb.getMaxY() - trs.y, maxy);
        }

        if (d.ulOn || d.imUlStroke != null || d.strikeThrough) {
            minx = Math.min(lb.getMinX() - trs.x, minx);
            maxx = Math.max(lb.getMaxX() - trs.x, maxx);

            d.getStrokes(trs.metrics);

            if (d.ulStroke != null) {
                maxy = Math.max(
                        maxy,
                        trs.metrics.underlineOffset +
                        d.ulStroke.getLineWidth()
                );
            }

            if (d.imUlStroke != null) {
                maxy = Math.max(
                        maxy,
                        trs.metrics.underlineOffset +
                        d.imUlStroke.getLineWidth() +
                        (d.imUlStroke2 == null ? 0 : d.imUlStroke2.getLineWidth())
                );
            }
        }

        return new Rectangle2D.Double(minx, miny, maxx-minx, maxy-miny);
    }