/**
   * @param pWidth the width to draw, it can be 0
   * @param pHeight the height to draw, it can be 0
   */
  public static void createTextBitmap(
      String pString,
      final String pFontName,
      final int pFontSize,
      final int pAlignment,
      final int pWidth,
      final int pHeight) {
    final int horizontalAlignment = pAlignment & 0x0F;
    final int verticalAlignment = (pAlignment >> 4) & 0x0F;

    pString = Cocos2dxBitmap.refactorString(pString);
    final Paint paint = Cocos2dxBitmap.newPaint(pFontName, pFontSize, horizontalAlignment);

    final TextProperty textProperty =
        Cocos2dxBitmap.computeTextProperty(pString, pWidth, pHeight, paint);

    final int bitmapTotalHeight = (pHeight == 0 ? textProperty.mTotalHeight : pHeight);

    final Bitmap bitmap =
        Bitmap.createBitmap(textProperty.mMaxWidth, bitmapTotalHeight, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);

    /* Draw string. */
    final FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
    int x = 0;
    int y =
        Cocos2dxBitmap.computeY(
            fontMetricsInt, pHeight, textProperty.mTotalHeight, verticalAlignment);
    final String[] lines = textProperty.mLines;
    for (final String line : lines) {
      x = Cocos2dxBitmap.computeX(line, textProperty.mMaxWidth, horizontalAlignment);
      canvas.drawText(line, x, y, paint);
      y += textProperty.mHeightPerLine;
    }

    Cocos2dxBitmap.initNativeObject(bitmap);
  }
  public static boolean createTextBitmapShadowStroke(
      byte[] bytes,
      final String fontName,
      int fontSize,
      int fontTintR,
      int fontTintG,
      int fontTintB,
      int fontTintA,
      int alignment,
      int width,
      int height,
      boolean shadow,
      float shadowDX,
      float shadowDY,
      float shadowBlur,
      float shadowOpacity,
      boolean stroke,
      int strokeR,
      int strokeG,
      int strokeB,
      int strokeA,
      float strokeSize) {

    String string;
    if (bytes == null || bytes.length == 0) {
      string = "";
    } else {
      string = new String(bytes);
    }

    final int horizontalAlignment = alignment & 0x0F;
    final int verticalAlignment = (alignment >> 4) & 0x0F;

    string = Cocos2dxBitmap.refactorString(string);
    final Paint paint = Cocos2dxBitmap.newPaint(fontName, fontSize, horizontalAlignment);

    // if the first word width less than designed width, it means no words to show
    if (0 != width) {
      final int firstWordWidth = (int) Math.ceil(paint.measureText(string, 0, 1));
      if (firstWordWidth > width) {
        Log.w(
            "createTextBitmapShadowStroke warning:",
            "the input width is less than the width of the pString's first word\n");
        return false;
      }
    }

    // set the paint color
    paint.setARGB(fontTintA, fontTintR, fontTintG, fontTintB);

    final TextProperty textProperty =
        Cocos2dxBitmap.computeTextProperty(string, width, height, paint);
    final int bitmapTotalHeight = (height == 0 ? textProperty.mTotalHeight : height);

    // padding needed when using shadows (not used otherwise)
    float bitmapPaddingX = 0.0f;
    float bitmapPaddingY = 0.0f;
    float renderTextDeltaX = 0.0f;
    float renderTextDeltaY = 0.0f;

    if (0 == textProperty.mMaxWidth || 0 == bitmapTotalHeight) {
      Log.w(
          "createTextBitmapShadowStroke warning:",
          "textProperty MaxWidth is 0 or bitMapTotalHeight is 0\n");
      return false;
    }

    final Bitmap bitmap =
        Bitmap.createBitmap(
            textProperty.mMaxWidth + (int) bitmapPaddingX,
            bitmapTotalHeight + (int) bitmapPaddingY,
            Bitmap.Config.ARGB_8888);

    final Canvas canvas = new Canvas(bitmap);

    // Draw string.
    final FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();

    // draw again with stroke on if needed
    if (stroke) {
      final Paint paintStroke = Cocos2dxBitmap.newPaint(fontName, fontSize, horizontalAlignment);
      paintStroke.setStyle(Paint.Style.STROKE);
      paintStroke.setStrokeWidth(strokeSize);
      paintStroke.setARGB(strokeA, strokeR, strokeG, strokeB);

      int x = 0;
      int y =
          Cocos2dxBitmap.computeY(
              fontMetricsInt, height, textProperty.mTotalHeight, verticalAlignment);
      final String[] lines2 = textProperty.mLines;

      for (final String line : lines2) {

        x = Cocos2dxBitmap.computeX(line, textProperty.mMaxWidth, horizontalAlignment);
        canvas.drawText(line, x + renderTextDeltaX, y + renderTextDeltaY, paintStroke);
        canvas.drawText(line, x + renderTextDeltaX, y + renderTextDeltaY, paint);
        y += textProperty.mHeightPerLine;
      }

    } else {
      int x = 0;
      int y =
          Cocos2dxBitmap.computeY(
              fontMetricsInt, height, textProperty.mTotalHeight, verticalAlignment);

      final String[] lines = textProperty.mLines;

      for (final String line : lines) {

        x = Cocos2dxBitmap.computeX(line, textProperty.mMaxWidth, horizontalAlignment);
        canvas.drawText(line, x + renderTextDeltaX, y + renderTextDeltaY, paint);
        y += textProperty.mHeightPerLine;
      }
    }

    Cocos2dxBitmap.initNativeObject(bitmap);

    return true;
  }