void (Graphics2D g, float x, float y, int startColumn, int endColumn) { updateStats(endColumn - startColumn, myCharPositions.length); if (startColumn == 0 && endColumn == myCharPositions.length) { g.drawGlyphVector(myGlyphVector, x, y); } else { Shape savedClip = g.getClip(); float startX = x - getX(startColumn); // We define clip region here assuming that glyphs do not extend further than CLIP_MARGIN pixels from baseline // vertically (both up and down) and horizontally (from the region defined by glyph vector's total advance) double xMin = x - (startColumn == 0 ? CLIP_MARGIN : 0); double xMax = startX + getX(endColumn) + (endColumn == myCharPositions.length ? CLIP_MARGIN : 0); double yMin = y - CLIP_MARGIN; double yMax = y + CLIP_MARGIN; g.clip(new Rectangle2D.Double(xMin, yMin, xMax - xMin, yMax - yMin)); g.drawGlyphVector(myGlyphVector, startX, y); g.setClip(savedClip); } }