final boolean isXLabelSouth = shape.isXLabelSouth();
final boolean isYLabelWest = shape.isYLabelWest();
final double originX = shape.getOriginX();
final double originY = shape.getOriginY();
final Color gridLabelsColor = shape.getGridLabelsColour();
final FontMetrics fontMetrics = FontDesignMetrics.getMetrics(new Font(null, Font.PLAIN, shape.getLabelsSize()));
final float labelHeight = fontMetrics.getAscent();
final float labelWidth = fontMetrics.stringWidth(String.valueOf((int)maxX));
final double xorigin = xStep*originX;
final double yorigin = isXLabelSouth ? yStep*originY+labelHeight : yStep*originY-2;
final double width=gridWidth/2.;
final double tmp = isXLabelSouth ? width : -width;
final SVGElement texts = new SVGGElement(document);
SVGElement text;
String label;
double i;
double j;
texts.setAttribute(SVGAttributes.SVG_FONT_SIZE, String.valueOf(shape.getLabelsSize()));
texts.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(gridLabelsColor, true));
texts.setAttribute(prefix+LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
for(i=tlx + (isYLabelWest ? width+gridLabelsSize/4. : -width-labelWidth-gridLabelsSize/4.), j=minX; j<=maxX; i+=absStep, j++) {
text = new SVGTextElement(document);
text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int)i));
text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int)(yorigin+tmp)));
text.setTextContent(String.valueOf((int)j));
texts.appendChild(text);
}
if(isYLabelWest)
for(i=tly + (isXLabelSouth ? -width-gridLabelsSize/4. : width+labelHeight), j=maxY ; j>=minY; i+=absStep, j--) {
label = String.valueOf((int)j);
text = new SVGTextElement(document);
text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int)(xorigin-fontMetrics.stringWidth(label)-gridLabelsSize/4.-width)));
text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int)i));
text.setTextContent(label);
texts.appendChild(text);
}
else