Search in sources :

Example 6 with Color

use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.

the class PSTShapeView method getDoubleBorderCode.

/**
 * @param ppc The number of pixels per centimetre.
 * @return The PSTricks code of the double border of the shape.
 * @since 3.0
 */
protected StringBuilder getDoubleBorderCode(final float ppc) {
    final StringBuilder code;
    if (shape.hasDbleBord()) {
        final Color doubleColor = shape.getDbleBordCol();
        code = new StringBuilder();
        // $NON-NLS-1$
        code.append("doubleline=true, doublesep=");
        code.append(MathUtils.INST.getCutNumberFloat(shape.getDbleBordSep() / ppc));
        if (!doubleColor.equals(PSTricksConstants.DEFAULT_DOUBLE_COLOR))
            // $NON-NLS-1$
            code.append(", doublecolor=").append(getColourName(doubleColor));
    } else
        code = null;
    return code;
}
Also used : Color(net.sf.latexdraw.models.interfaces.shape.Color)

Example 7 with Color

use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.

the class PSTTextView method getCode.

@Override
public String getCode(final IPoint origin, final float ppc) {
    if (!MathUtils.INST.isValidPt(origin) || ppc < 1)
        return "";
    final StringBuilder rot = getRotationHeaderCode(ppc, origin);
    final StringBuilder code = new StringBuilder();
    if (rot != null)
        code.append(rot);
    final String colorName;
    final Color lineCol = shape.getLineColour();
    if (lineCol.equals(PSTricksConstants.DEFAULT_LINE_COLOR))
        colorName = null;
    else {
        colorName = getColourName(shape.getLineColour());
        addColour(colorName);
    }
    final String tokenPosition = shape.getTextPosition().getLatexToken();
    if (// $NON-NLS-1$
    tokenPosition == null || tokenPosition.isEmpty())
        // $NON-NLS-1$
        code.append("\\rput(");
    else
        // $NON-NLS-1$
        code.append("\\rput[").append(shape.getTextPosition().getLatexToken()).append(']').append('(');
    code.append(MathUtils.INST.getCutNumberFloat((shape.getX() - origin.getX()) / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat((origin.getY() - shape.getY()) / ppc)).append(')').append('{');
    // $NON-NLS-1$
    if (colorName != null)
        code.append("\\textcolor{").append(colorName).append('}').append('{');
    code.append(shape.getText()).append('}');
    if (colorName != null)
        code.append('}');
    if (rot != null)
        code.append('}');
    return code.toString();
}
Also used : Color(net.sf.latexdraw.models.interfaces.shape.Color)

Example 8 with Color

use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.

the class SVGBezierCurve method getShowPointsElement.

/**
 * Creates an SVG g element that contains the 'show points' plotting.
 * @param doc The owner document.
 * @return The created g element or null if the shape has not the 'show points' option activated.
 * @since 2.0.0
 */
protected SVGGElement getShowPointsElement(final SVGDocument doc) {
    if (!shape.isShowPts() || doc == null) {
        return null;
    }
    final double blackDash = shape.getDashSepBlack();
    final double whiteDash = shape.getDashSepWhite();
    final boolean hasDble = shape.hasDbleBord();
    final Color col = shape.getLineColour();
    final boolean isClosed = !shape.isOpened();
    final SVGGElement showPts = new SVGGElement(doc);
    final IArrow arrow1 = shape.getArrowAt(0);
    final IArrow arrow2 = shape.getArrowAt(-1);
    final double doubleSep = shape.getDbleBordSep();
    final double thick = (hasDble ? shape.getDbleBordSep() + shape.getThickness() * 2. : shape.getThickness()) / 2.;
    final double rad = (PSTricksConstants.DEFAULT_ARROW_DOTSIZE_DIM * IShape.PPC + PSTricksConstants.DEFAULT_ARROW_DOTSIZE_NUM * thick * 2.) / 2.;
    int i;
    final int size = shape.getNbPoints();
    showPts.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_SHOW_PTS);
    /* Plotting the lines. */
    for (i = 3; i < size; i += 2) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(i - 1), shape.getSecondCtrlPtAt(i - 1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(i - 1), shape.getFirstCtrlPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(i), shape.getPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    for (i = 2; i < size; i += 2) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(i - 1), shape.getSecondCtrlPtAt(i - 1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(i - 1), shape.getFirstCtrlPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(i), shape.getPtAt(i), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    if (isClosed) {
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(-1), shape.getSecondCtrlPtAt(-1), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(-1), shape.getSecondCtrlPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
        showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getSecondCtrlPtAt(0), shape.getPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
    }
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getPtAt(0), shape.getFirstCtrlPtAt(0), blackDash, whiteDash, hasDble, 1., doubleSep));
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(0), shape.getFirstCtrlPtAt(1), blackDash, whiteDash, hasDble, 1., doubleSep));
    showPts.appendChild(getShowPointsLine(doc, thick, col, shape.getFirstCtrlPtAt(1), shape.getPtAt(1), blackDash, whiteDash, hasDble, 1., doubleSep));
    // Plotting the dots.
    if (!arrow1.hasStyle() || isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(0), col));
    }
    if (!arrow2.hasStyle() || isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(-1), col));
    }
    for (i = 1; i < size - 1; i++) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getPtAt(i), col));
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(i), col));
    }
    for (i = 0; i < size; i++) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getFirstCtrlPtAt(i), col));
    }
    if (isClosed) {
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(-1), col));
        showPts.appendChild(SVGShape.getShowPointsDot(doc, rad, shape.getSecondCtrlPtAt(0), col));
    }
    return showPts;
}
Also used : SVGGElement(net.sf.latexdraw.parsers.svg.SVGGElement) Color(net.sf.latexdraw.models.interfaces.shape.Color) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 9 with Color

use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.

the class SVGShape method setHatchingsFromSVG.

private static void setHatchingsFromSVG(final IShape shape, final SVGPatternElement pat) {
    final Color c = pat.getBackgroundColor();
    final String str = pat.getAttribute(pat.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI) + LNamespace.XML_TYPE);
    double angle;
    double sep;
    final double width;
    final String attr;
    try {
        angle = Double.parseDouble(pat.getAttribute(pat.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI) + LNamespace.XML_ROTATION));
    } catch (final NumberFormatException ex) {
        angle = 0d;
    }
    attr = pat.getAttribute(pat.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI) + LNamespace.XML_SIZE);
    if (attr == null) {
        sep = pat.getHatchingSep();
    } else {
        try {
            sep = Double.parseDouble(attr);
        } catch (final NumberFormatException ex) {
            sep = 0d;
        }
    }
    if (PSTricksConstants.isValidFillStyle(str)) {
        shape.setFillingStyle(FillingStyle.getStyleFromLatex(str));
    }
    if (!Double.isNaN(angle)) {
        shape.setHatchingsAngle(angle);
    }
    shape.setFilled(c != null);
    shape.setFillingCol(c);
    shape.setHatchingsCol(pat.getHatchingColor());
    if (!Double.isNaN(sep)) {
        shape.setHatchingsSep(sep);
    }
    width = pat.getHatchingStrokeWidth();
    if (!Double.isNaN(width)) {
        shape.setHatchingsWidth(width);
    }
}
Also used : Color(net.sf.latexdraw.models.interfaces.shape.Color)

Example 10 with Color

use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.

the class SVGShape method setPlainFillFromSVG.

private static void setPlainFillFromSVG(final IShape shape, final String fill, final String opacity) {
    // Just getting the filling colour.
    final Color fillCol = CSSColors.INSTANCE.getRGBColour(fill);
    if (fillCol != null) {
        shape.setFillingCol(fillCol);
        shape.setFilled(true);
        if (opacity != null) {
            try {
                shape.setFillingCol(fillCol.newColorWithOpacity(Double.valueOf(opacity)));
            } catch (final NumberFormatException ignored) {
            }
        }
    }
}
Also used : Color(net.sf.latexdraw.models.interfaces.shape.Color)

Aggregations

Color (net.sf.latexdraw.models.interfaces.shape.Color)21 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)4 Test (org.junit.Test)3 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)2 Font (javafx.scene.text.Font)1 Text (javafx.scene.text.Text)1 IArrow (net.sf.latexdraw.models.interfaces.shape.IArrow)1 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)1 SVGTextElement (net.sf.latexdraw.parsers.svg.SVGTextElement)1 SVGTransform (net.sf.latexdraw.parsers.svg.SVGTransform)1 SVGTransformList (net.sf.latexdraw.parsers.svg.SVGTransformList)1