double iwd = block.background_image.getWidth(null); double ihd = block.background_image.getHeight(null);
    public static void paint(Context c, Box block) {        // don't draw if the backgrounds are turned off        if (!Configuration.isTrue("xr.renderer.draw.backgrounds", true)) {            return;        }        Border border = c.getCurrentStyle().getBorderWidth();        if (border == null) return;        Border margin = c.getCurrentStyle().getMarginWidth();        Rectangle box = new Rectangle(block.x + margin.left + border.left,                block.y + margin.top + border.top,                block.width - margin.left - margin.right - border.left - border.right,                block.height - margin.top - border.top - border.bottom - margin.bottom);                         // paint the background        Color background_color = BoxRendering.getBackgroundColor(c, block);        if (background_color != null) {            // skip transparent background            if (!background_color.equals(transparent)) {                //TODO. make conf controlled Uu.p("filling a background");                c.getGraphics().setColor(background_color);                c.getGraphics().fillRect(box.x, box.y, box.width, box.height);            }        }        int xoff = 0;        int yoff = 0;        if (block.attachment != null && block.attachment.equals("fixed")) {            yoff = c.getCanvas().getLocation().y;            //TODO. make conf controlled Uu.p("setting the clip rect for fixed background");            c.getGraphics().setClip(c.getCanvas().getVisibleRect());        }        if (block.background_image != null) {            int left_insets = box.x;            int top_insets = box.y;            int back_width = box.width;            int back_height = box.height;            Rectangle2D oldclip = (Rectangle2D) c.getGraphics().getClip();            Rectangle new_clip = new Rectangle(left_insets, top_insets, back_width, back_height);            c.getGraphics().setClip(oldclip.createIntersection(new_clip));            // calculate repeat indecies            int repeatx = 1;            int repeaty = 1;            if (block.repeat == null) {                repeatx = 1;                repeaty = 1;            } else if (block.repeat.equals("repeat-Xx")) {                repeatx = back_width;            } else if (block.repeat.equals("repeat-y")) {                repeaty = back_height;            } else if (block.repeat.equals("repeat")) {                repeatx = back_width;                repeaty = back_height;            }            double iwd = block.background_image.getWidth(null);            double ihd = block.background_image.getHeight(null);            int iw = block.background_image.getWidth(null);            int ih = block.background_image.getHeight(null);            // handle image position offsets            /* KEEP JMM (11/16)             * xoff = block width - image width * pos             * pos = 0             * block width = 300             * image width = 100             * if pos = 0 then             * xoff = 0             * if pos = 1 then             * xoff = 200             */            xoff += (int) ((double) (back_width - iw) * (double) ((double) block.background_position_horizontal / (double) 100));            yoff -= (int) ((double) (back_height - ih) * (double) ((double) block.background_position_vertical / (double) 100));            // calculations for fixed tile images            int starty = (int) Math.ceil((double) (top_insets + yoff) / ih);            int endy = (int) Math.ceil((double) (back_height + top_insets + yoff) / ih);            int startx = (int) Math.ceil((double) (left_insets) / iw);            int endx = (int) Math.ceil((double) (back_width + left_insets) / iw);            // tile the image as appropriate            // do fixed tile image            boolean horiz = false;            boolean vert = false;            if (block.repeat.equals("repeat-Xx")) {                horiz = true;                vert = false;            }            if (block.repeat.equals("repeat-y")) {                horiz = false;                vert = true;            }            if (block.repeat.equals("repeat")) {                horiz = true;                vert = true;            }            //TODO. make conf controlled Uu.p("filling background with an image");            // fixed tiled image            if (block.attachment != null && block.attachment.equals("fixed")) {                tileFill(c.getGraphics(), block.background_image,                        new Rectangle(left_insets, top_insets, back_width, back_height),                        xoff, -yoff, horiz, vert);            } else {                // do normal tile image                tileFill(c.getGraphics(), block.background_image,                        new Rectangle(left_insets, top_insets, back_width, back_height),                        xoff, -yoff, horiz, vert);            }            //TODO. make conf controlled Uu.p("setting the clip rect");            c.getGraphics().setClip(oldclip);        }    }