Ejemplo n.º 1
0
  /**
   * Creates a master shape of the letter.
   *
   * @param shape
   * @return the master shape
   */
  private final Master createMaster(RenderContext ctx, Shape shape, double ascent) {
    final Area area = new Area(shape);
    final double scale = MASTER_HEIGHT / ascent;

    area.transform(AffineTransform.getScaleInstance(scale, scale));
    final Rectangle bounds = area.getBounds();
    // System.out.println("createMaster bounds " + bounds);
    // area.transform(AffineTransform.getTranslateInstance(-bounds.getMinX(),
    // -bounds.getMinY()));
    // bounds = area.getBounds();

    final int minX = (int) (bounds.getMinX() - 0.5);
    final int maxX = (int) (bounds.getMaxX() + 0.5);
    final int minY = (int) (bounds.getMinY() - 0.5);
    final int maxY = (int) (bounds.getMaxY() + 0.5);
    final int width = maxX - minX;
    final int height = maxY - minY;

    BitSet bits = (BitSet) ctx.getObject(BITS_NAME);
    if (bits == null) {
      bits = new BitSet(width * height);
      ctx.setObject(BITS_NAME, bits);
    } else {
      bits.clear();
    }
    int ofs = 0;
    for (int y = maxY; y > minY; y--) {
      for (int x = minX; x < maxX; x++) {
        if (area.contains(x, y)) {
          bits.set(ofs);
        }
        ofs++;
      }
    }

    return new Master(bits, width, height, minX, minY);
  }