public void drawVerticalString(String string, int x, int y) { // x and y here are the center of the string FontMetrics fm = cp.getFontMetrics(); int ascent = fm.getAscent(); int descent = fm.getDescent(); int height = ascent + descent; int width = cp.getStringWidth(string); int[] mask = new int[width * height]; for (int i = 0; i < width * height; i++) { mask[i] = 0xffffffff; } ColorProcessor cp2 = new ColorProcessor(width, height, mask); cp2.setAntialiasedText(antialias); cp2.setFont(cp.getFont()); cp2.drawString(string, 0, ascent); ColorProcessor cp3 = (ColorProcessor) cp2.rotateLeft(); mask = (int[]) cp3.getPixels(); int newx = x - height / 2; int newy = y - width / 2; int[] pixels = (int[]) cp.getPixels(); int owidth = cp.getWidth(); int oheight = cp.getHeight(); for (int i = 0; i < width; i++) { int b = newy + i; if (b >= 0 && b < oheight) { for (int j = 0; j < height; j++) { int a = newx + j; if (a >= 0 && a < owidth) { if (mask[j + i * height] != 0xffffffff) { pixels[a + owidth * b] = mask[j + i * height]; } } } } } }
public Font getFont() { return cp.getFont(); }