static void prepareGraphics(
            TextRunSegment trs, Graphics2D g2d,
            float xOffset, float yOffset
    ) {
        Decoration d = trs.decoration;

        if (d.fg == null && d.bg == null && d.swapBfFg == false) {
            return; // Nothing to do
        }

        d.graphicsPaint = g2d.getPaint();

        if (d.fg == null) {
            d.fg = d.graphicsPaint;
        }

        if (d.swapBfFg) {
            // Fill background area
            g2d.setPaint(d.fg);
            Rectangle2D bgArea = trs.getLogicalBounds();
            Rectangle2D toFill =
                    new Rectangle2D.Double(
                            bgArea.getX() + xOffset,
                            bgArea.getY() + yOffset,
                            bgArea.getWidth(),
                            bgArea.getHeight()
                    );
            g2d.fill(toFill);

            // Set foreground color
            g2d.setPaint(d.bg == null ? Color.WHITE : d.bg);
        } else {
            if (d.bg != null) { // Fill background area
                g2d.setPaint(d.bg);
                Rectangle2D bgArea = trs.getLogicalBounds();
                Rectangle2D toFill =
                        new Rectangle2D.Double(
                                bgArea.getX() + xOffset,
                                bgArea.getY() + yOffset,
                                bgArea.getWidth(),
                                bgArea.getHeight()
                        );
                g2d.fill(toFill);
            }

            // Set foreground color
            g2d.setPaint(d.fg);
        }
    }