/**
  * Paint the glyphs for the given view. This is implemented to only render if the Graphics is of
  * type Graphics2D which is required by TextLayout (and this should be the case if running on the
  * JDK).
  */
 public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
   if (g instanceof Graphics2D) {
     Rectangle2D alloc = a.getBounds2D();
     Graphics2D g2d = (Graphics2D) g;
     float y = (float) alloc.getY() + layout.getAscent() + layout.getLeading();
     float x = (float) alloc.getX();
     if (p0 > v.getStartOffset() || p1 < v.getEndOffset()) {
       try {
         // TextLayout can't render only part of it's range, so if a
         // partial range is required, add a clip region.
         Shape s = v.modelToView(p0, Position.Bias.Forward, p1, Position.Bias.Backward, a);
         Shape savedClip = g.getClip();
         g2d.clip(s);
         layout.draw(g2d, x, y);
         g.setClip(savedClip);
       } catch (BadLocationException e) {
       }
     } else {
       layout.draw(g2d, x, y);
     }
   }
 }