示例#1
0
 private int getGlyphCode(Font font, int codePoint) {
   char[] chars = Character.toChars(codePoint);
   GlyphVector vector =
       font.layoutGlyphVector(
           GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
   return vector.getGlyphCode(0);
 }
 @Override
 public void drawGlyphVector(GlyphVector g, float x, float y) {
   for (int i = 0; i < g.getNumGlyphs(); i++) {
     drawChar((char) g.getGlyphCode(i), (int) x, (int) y);
     x += BitmapFont.CHAR_WIDTH;
   }
 }
示例#3
0
  @Override
  protected void createChars(final BufferedImage theCharImage, final Graphics2D theGraphics) {
    _myTesselator = new CCVectorFontTesselator();

    // six element array received from the Java2D path iterator
    float textPoints[] = new float[6];

    // array passed to createGylphVector
    char textArray[] = new char[1];

    final Graphics2D myGraphics = theGraphics;
    final FontRenderContext frc = myGraphics.getFontRenderContext();

    int index = 0;

    for (int i = 0; i < _myCharCount; i++) {
      char c = _myCharSet.chars()[i];

      if (!_myFont.canDisplay(c) || _myFontMetrics.charWidth(c) <= 0) {
        continue;
      }

      if (c < 128) {
        _myAsciiLookUpTable[c] = index;
      }

      _myCharCodes[index] = c;

      textArray[0] = c;
      final GlyphVector myGlyphVector = _myFont.createGlyphVector(frc, textArray);
      final Shape myShape = myGlyphVector.getOutline();
      final PathIterator myPathIterator = myShape.getPathIterator(null, 0.05);

      final CC3DChar my3DChar =
          new CC3DChar(c, myGlyphVector.getGlyphCode(0), charWidth(c), height(), _mySize, _myDepth);
      _myTesselator.beginPolygon(my3DChar);

      float lastX = 0;
      float lastY = 0;

      while (!myPathIterator.isDone()) {
        int type = myPathIterator.currentSegment(textPoints);
        switch (type) {
          case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints
            _myTesselator.beginContour();
            my3DChar.beginPath();
          case PathIterator.SEG_LINETO: // 1 point
            _myTesselator.vertex(textPoints[0], textPoints[1] + _myFontMetrics.getAscent(), 0);
            my3DChar.addOutlineVertex(textPoints[0], textPoints[1] + _myFontMetrics.getAscent());
            lastX = textPoints[0];
            lastY = textPoints[1];
            break;

          case PathIterator.SEG_QUADTO: // 2 points
            for (int j = 1; j < _myBezierDetail; j++) {
              float t = (float) j / _myBezierDetail;
              _myTesselator.vertex(
                  CCMath.bezierPoint(lastX, textPoints[0], textPoints[2], textPoints[2], t),
                  CCMath.bezierPoint(lastY, textPoints[1], textPoints[3], textPoints[3], t)
                      + _myFontMetrics.getAscent(),
                  0);
              my3DChar.addOutlineVertex(
                  CCMath.bezierPoint(lastX, textPoints[0], textPoints[2], textPoints[2], t),
                  CCMath.bezierPoint(lastY, textPoints[1], textPoints[3], textPoints[3], t)
                      + _myFontMetrics.getAscent());
            }

            lastX = textPoints[2];
            lastY = textPoints[3];
            break;

          case PathIterator.SEG_CUBICTO: // 3 points
            for (int j = 1; j < _myBezierDetail; j++) {
              float t = (float) j / _myBezierDetail;
              _myTesselator.vertex(
                  CCMath.bezierPoint(lastX, textPoints[0], textPoints[2], textPoints[4], t),
                  CCMath.bezierPoint(lastY, textPoints[1], textPoints[3], textPoints[5], t)
                      + _myFontMetrics.getAscent(),
                  0);
              my3DChar.addOutlineVertex(
                  CCMath.bezierPoint(lastX, textPoints[0], textPoints[2], textPoints[4], t),
                  CCMath.bezierPoint(lastY, textPoints[1], textPoints[3], textPoints[5], t)
                      + _myFontMetrics.getAscent());
            }

            lastX = textPoints[4];
            lastY = textPoints[5];
            break;

          case PathIterator.SEG_CLOSE:
            _myTesselator.endContour();
            my3DChar.endPath();
            break;
        }

        myPathIterator.next();
      }
      _myTesselator.endPolygon();
      _myChars[index] = my3DChar;

      index++;
    }
  }