Search in sources :

Example 1 with SVGTextElement

use of net.sf.latexdraw.parsers.svg.SVGTextElement in project latexdraw by arnobl.

the class SVGAxes method createTextLabel.

@Override
public SVGTextElement createTextLabel(final String text, final double x, final double y, final Font font) {
    if (currentTicks != null && currentDoc != null) {
        final SVGTextElement textElt = new SVGTextElement(currentDoc);
        textElt.setAttribute(SVGAttributes.SVG_X, MathUtils.INST.format.format(x));
        textElt.setAttribute(SVGAttributes.SVG_Y, MathUtils.INST.format.format(y));
        textElt.setTextContent(text);
        currentTicks.appendChild(textElt);
        return textElt;
    }
    return null;
}
Also used : SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement)

Example 2 with SVGTextElement

use of net.sf.latexdraw.parsers.svg.SVGTextElement in project latexdraw by arnobl.

the class SVGGrid method createSVGGridLabels.

/**
 * Creates the SVG element corresponding to the labels of the grid.
 */
private void createSVGGridLabels(final SVGDocument document, final SVGElement elt, final String prefix, final double minX, final double maxX, final double minY, final double maxY, final double tlx, final double tly, final double xStep, final double yStep, final double gridWidth, final double absStep) {
    final int gridLabelsSize = shape.getLabelsSize();
    final boolean isXLabelSouth = shape.isXLabelSouth();
    final boolean isYLabelWest = shape.isYLabelWest();
    final double originX = shape.getOriginX();
    final double originY = shape.getOriginY();
    final Color gridLabelsColor = shape.getGridLabelsColour();
    final Text fooText = new Text(String.valueOf((int) maxX));
    fooText.setFont(new Font(null, shape.getLabelsSize()));
    final double labelHeight = fooText.getBaselineOffset();
    final double labelWidth = fooText.getBoundsInLocal().getWidth();
    final double xorigin = xStep * originX;
    final double yorigin = isXLabelSouth ? yStep * originY + labelHeight : yStep * originY - 2d;
    final double width = gridWidth / 2d;
    final double tmp = isXLabelSouth ? width : -width;
    final SVGElement texts = new SVGGElement(document);
    SVGElement text;
    String label;
    double i;
    double j;
    texts.setAttribute(SVGAttributes.SVG_FONT_SIZE, String.valueOf(shape.getLabelsSize()));
    texts.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(gridLabelsColor, true));
    texts.setAttribute(prefix + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    if (gridLabelsColor.getO() < 1d) {
        texts.setAttribute(SVGAttributes.SVG_OPACITY, MathUtils.INST.format.format(gridLabelsColor.getO()));
    }
    for (i = tlx + (isYLabelWest ? width + gridLabelsSize / 4d : -width - labelWidth - gridLabelsSize / 4d), j = minX; j <= maxX; i += absStep, j++) {
        text = new SVGTextElement(document);
        text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) i));
        text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) (yorigin + tmp)));
        text.setTextContent(String.valueOf((int) j));
        texts.appendChild(text);
    }
    if (isYLabelWest) {
        for (i = tly + (isXLabelSouth ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
            label = String.valueOf((int) j);
            text = new SVGTextElement(document);
            fooText.setText(label);
            text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin - fooText.getLayoutBounds().getWidth() - gridLabelsSize / 4d - width)));
            text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
            text.setTextContent(label);
            texts.appendChild(text);
        }
    } else {
        for (i = tly + (isXLabelSouth ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
            label = String.valueOf((int) j);
            text = new SVGTextElement(document);
            text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin + gridLabelsSize / 4d + width)));
            text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
            text.setTextContent(label);
            texts.appendChild(text);
        }
    }
    elt.appendChild(texts);
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement) Color(net.sf.latexdraw.models.interfaces.shape.Color) Text(javafx.scene.text.Text) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Font(javafx.scene.text.Font)

Example 3 with SVGTextElement

use of net.sf.latexdraw.parsers.svg.SVGTextElement in project latexdraw by arnobl.

the class SVGText method toSVG.

@Override
public SVGElement toSVG(final SVGDocument doc) {
    if (doc == null) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    final String ltdPref = LNamespace.LATEXDRAW_NAMESPACE + ':';
    final Element txt = new SVGTextElement(doc);
    root.setAttribute(ltdPref + LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    root.setAttribute(SVGAttributes.SVG_FILL, CSSColors.INSTANCE.getColorName(shape.getLineColour(), true));
    root.setAttribute(ltdPref + LNamespace.XML_POSITION, String.valueOf(shape.getTextPosition().getLatexToken()));
    txt.setAttribute(SVGAttributes.SVG_X, String.valueOf(shape.getX()));
    txt.setAttribute(SVGAttributes.SVG_Y, String.valueOf(shape.getY()));
    txt.appendChild(doc.createTextNode(shape.getText()));
    root.appendChild(txt);
    setSVGRotationAttribute(root);
    return root;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement) SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) Element(org.w3c.dom.Element) SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) SVGTextElement(net.sf.latexdraw.parsers.svg.SVGTextElement)

Aggregations

SVGTextElement (net.sf.latexdraw.parsers.svg.SVGTextElement)3 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)2 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)2 Font (javafx.scene.text.Font)1 Text (javafx.scene.text.Text)1 Color (net.sf.latexdraw.models.interfaces.shape.Color)1 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)1 Element (org.w3c.dom.Element)1