Search in sources :

Example 1 with SVGTextElement

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

the class SVGGrid method produceSVGGridYWestLabelsTexts.

private final void produceSVGGridYWestLabelsTexts(final SVGDocument document, final SVGElement texts, final double xorigin, final double tly, final double gridWidth, final Text fooText, final double minY, final double maxY, final double labelHeight, final double absStep) {
    final double width = gridWidth / 2d;
    final int gridLabelsSize = shape.getLabelsSize();
    for (double i = tly + (shape.isXLabelSouth() ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
        final String label = String.valueOf((int) j);
        final SVGElement 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);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) Point(net.sf.latexdraw.model.api.shape.Point)

Example 2 with SVGTextElement

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

the class SVGGrid method produceSVGGridXLabelsTexts.

private final void produceSVGGridXLabelsTexts(final SVGDocument document, final SVGElement texts, final double yorigin, final double minX, final double maxX, final double tlx, final double labelWidth, final double gridWidth, final double absStep) {
    final int gridLabelsSize = shape.getLabelsSize();
    final double width = gridWidth / 2d;
    final double tmp = shape.isXLabelSouth() ? width : -width;
    for (double i = tlx + (shape.isYLabelWest() ? width + gridLabelsSize / 4d : -width - labelWidth - gridLabelsSize / 4d), j = minX; j <= maxX; i += absStep, j++) {
        final SVGElement 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);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) Point(net.sf.latexdraw.model.api.shape.Point)

Example 3 with SVGTextElement

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

the class SVGGrid method produceSVGGridYEastLabelsTexts.

private final void produceSVGGridYEastLabelsTexts(final SVGDocument document, final SVGElement texts, final double xorigin, final double tly, final double gridWidth, final double minY, final double maxY, final double labelHeight, final double absStep) {
    final double width = gridWidth / 2d;
    final int gridLabelsSize = shape.getLabelsSize();
    for (double i = tly + (shape.isXLabelSouth() ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
        final String label = String.valueOf((int) j);
        final SVGElement 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);
    }
}
Also used : SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) Point(net.sf.latexdraw.model.api.shape.Point)

Example 4 with SVGTextElement

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

the class SVGText method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    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, 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.parser.svg.SVGGElement) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) SVGTextElement(net.sf.latexdraw.parser.svg.SVGTextElement) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) Element(org.w3c.dom.Element) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Aggregations

SVGElement (net.sf.latexdraw.parser.svg.SVGElement)4 SVGTextElement (net.sf.latexdraw.parser.svg.SVGTextElement)4 Point (net.sf.latexdraw.model.api.shape.Point)3 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)1 Element (org.w3c.dom.Element)1