Пример #1
0
    public void paint(Graphics2D graphics){
        Rectangle2D anchor = _shape.GetLogicalAnchor2D();
        TextElement[] elem = GetTextElements((float)anchor.Width, graphics.GetFontRenderContext());
        if(elem == null) return;

        float textHeight = 0;
        for (int i = 0; i < elem.Length; i++) {
            textHeight += elem[i].ascent + elem[i].descent;
        }

        int valign = _shape.GetVerticalAlignment();
        double y0 = anchor.GetY();
        switch (valign){
            case TextShape.AnchorTopBaseline:
            case TextShape.AnchorTop:
                y0 += _shape.GetMarginTop();
                break;
            case TextShape.AnchorBottom:
                y0 += anchor.Height - textHeight - _shape.GetMarginBottom();
                break;
            default:
            case TextShape.AnchorMiddle:
                float delta =  (float)anchor.Height - textHeight - _shape.GetMarginTop() - _shape.GetMarginBottom();
                y0 += _shape.GetMarginTop()  + delta/2;
                break;
        }

        //finally Draw the text fragments
        for (int i = 0; i < elem.Length; i++) {
            y0 += elem[i].ascent;

            Point2D.Double pen = new Point2D.Double();
            pen.y = y0;
            switch (elem[i]._align) {
                default:
                case TextShape.AlignLeft:
                    pen.x = anchor.GetX() + _shape.GetMarginLeft();
                    break;
                case TextShape.AlignCenter:
                    pen.x = anchor.GetX() + _shape.GetMarginLeft() +
                            (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight()) / 2;
                    break;
                case TextShape.AlignRight:
                    pen.x = anchor.GetX() + _shape.GetMarginLeft() +
                            (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight());
                    break;
            }
            if(elem[i]._bullet != null){
                graphics.DrawString(elem[i]._bullet.GetIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y);
            }
            AttributedCharacterIterator chIt = elem[i]._text.GetIterator();
            if(chIt.GetEndIndex() > chIt.GetBeginIndex()) {
                graphics.DrawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y);
            }
            y0 += elem[i].descent;
        }
    }