private void align() {
        if (block.getTextBox() == null) {
            // Without a text block, there is no alignment.
            return;

            // For unbounded left-to-right texts the letters will simply be shown starting from
            // x0 = 0 and advance toward right as line length is considered to be infinite.
            // For unbounded right-to-left texts the letters will be shown starting from x0 = 0
            // (at the same position as left-to-right texts) but move toward the left from there.
        }

        final Align alignment = block.getAlignment();
        final VAlign valignment = block.getVerticalAlignment();
        final float width = block.getTextBox().width;
        final float height = block.getTextBox().height;
        float lineWidth = 0;
        float gapX = 0;
        float gapY = 0;

        validateSize();
        if (totalHeight < height) { // align vertically only for no overflow
            switch (valignment) {
                case Top:
                    gapY = 0;
                    break;
                case Center:
                    gapY = (height - totalHeight) * 0.5f;
                    break;
                case Bottom:
                    gapY = height - totalHeight;
                    break;
            }
        }

        if (font.isRightToLeft()) {
            if ((alignment == Align.Right && valignment == VAlign.Top)) {
                return;
            }
            LetterQuad cursor = tail.getPrevious();
            // Temporary set the flag, it will be reset when invalidated.
            cursor.setEndOfLine();
            while (!cursor.isHead()) {
                if (cursor.isEndOfLine()) {
                    if (alignment == Align.Left) {
                        gapX = block.getTextBox().x - cursor.getX0();
                    } else if (alignment == Align.Center) {
                        gapX = (block.getTextBox().x - cursor.getX0()) / 2;
                    } else {
                        gapX = 0;
                    }
                }
                cursor.setAlignment(gapX, gapY);
                cursor = cursor.getPrevious();
            }
        } else { // left-to-right
            if (alignment == Align.Left && valignment == VAlign.Top) {
                return;
            }
            LetterQuad cursor = tail.getPrevious();
            // Temporary set the flag, it will be reset when invalidated.
            cursor.setEndOfLine();
            while (!cursor.isHead()) {
                if (cursor.isEndOfLine()) {
                    lineWidth = cursor.getX1() - block.getTextBox().x;
                    if (alignment == Align.Center) {
                        gapX = (width - lineWidth) / 2;
                    } else if (alignment == Align.Right) {
                        gapX = width - lineWidth;
                    } else {
                        gapX = 0;
                    }
                }
                cursor.setAlignment(gapX, gapY);
                cursor = cursor.getPrevious();
            }
        }
    }
Manage and align LetterQuads
@author YongHoon
jme3-core/src/main/java/com/jme3/font/Letters.java