use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class PSTShapeView method getFillingCode.
/**
* @param ppc The number of pixels per centimetre.
* @return The PSTricks code for the filling of the shape. Null if there is no filling.
* @since 1.7
*/
protected StringBuilder getFillingCode(final float ppc) {
StringBuilder code;
final Color interiorColor = shape.getFillingCol();
switch(shape.getFillingStyle()) {
case NONE:
code = null;
break;
case PLAIN:
code = getFillingPlain();
break;
case GRAD:
code = getFillingGrad();
break;
case CLINES:
case CLINES_PLAIN:
case HLINES:
case HLINES_PLAIN:
case VLINES:
case VLINES_PLAIN:
code = getFillingHatchings(ppc);
break;
default:
code = null;
break;
}
if (!shape.isFilled() && shape.hasShadow() && shape.shadowFillsShape() && !interiorColor.equals(PSTricksConstants.DEFAULT_INTERIOR_COLOR)) {
if (code == null)
code = new StringBuilder();
else
code.append(',').append(' ');
// $NON-NLS-1$
code.append("fillcolor=").append(getColourName(interiorColor));
}
return code;
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class PSTShapeView method getShadowCode.
/**
* @param ppc The number of pixels per centimetre.
* @return The code of the shape shadow or null if there is no shadow.
* @since 3.0
*/
protected StringBuilder getShadowCode(final float ppc) {
final StringBuilder code;
if (shape.hasShadow()) {
final Color shadowColor = shape.getShadowCol();
code = new StringBuilder();
// $NON-NLS-1$
code.append("shadow=true");
if (!MathUtils.INST.equalsDouble(Math.toDegrees(shape.getShadowAngle()), PSTricksConstants.DEFAULT_SHADOW_ANGLE))
// $NON-NLS-1$
code.append(",shadowangle=").append(MathUtils.INST.getCutNumberFloat(Math.toDegrees(shape.getShadowAngle())));
// $NON-NLS-1$
code.append(",shadowsize=").append(MathUtils.INST.getCutNumberFloat(shape.getShadowSize() / ppc));
if (!shadowColor.equals(PSTricksConstants.DEFAULT_SHADOW_COLOR))
// $NON-NLS-1$
code.append(",shadowcolor=").append(getColourName(shadowColor));
} else
code = null;
return code;
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class SVGShape method setLineColour.
/**
* Sets the colour of the line of the shape with the given SVG stroke.
* @param shape The shape to set.
* @param stoke The stroke of the shape.
* @param opacity The possible stroke-opacity of the colour. May be null.
*/
public static void setLineColour(final IShape shape, final String stoke, final String opacity) {
if (shape != null && stoke != null) {
final Color col = CSSColors.INSTANCE.getRGBColour(stoke);
shape.setLineColour(col);
if (opacity != null) {
try {
shape.setLineColour(ShapeFactory.INST.createColor(col.getR(), col.getG(), col.getB(), Double.valueOf(opacity)));
} catch (final NumberFormatException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
}
}
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class SVGShape method setSVGShadowParameters.
/**
* Sets the shadow parameters of the figure by using an SVG element having "type:shadow".
* @param elt The source element.
*/
protected void setSVGShadowParameters(final SVGElement elt) {
if (elt == null || !shape.isShadowable())
return;
if (shape.isFillable()) {
final String fill = elt.getFill();
if (fill != null && !fill.equals(SVGAttributes.SVG_VALUE_NONE) && !fill.startsWith(SVG_URL_TOKEN_BEGIN)) {
shape.setShadowCol(CSSColors.INSTANCE.getRGBColour(fill));
}
}
final Color strok = elt.getStroke();
if (strok != null) {
shape.setShadowCol(strok);
}
final SVGTransformList tl = elt.getTransform();
SVGTransform t;
double tx;
double ty;
boolean sSize = false;
boolean sAngle = false;
for (int i = 0, size = tl.size(); i < size && (!sSize || !sAngle); i++) {
t = tl.get(i);
if (t.isTranslation()) {
tx = t.getTX();
ty = t.getTY();
if (MathUtils.INST.equalsDouble(ty, 0.) && !sSize) {
// It is shadowSize.
shape.setShadowSize(tx);
sSize = true;
} else {
final IPoint gravityCenter = shape.getGravityCentre();
double angle;
final double shSize = shape.getShadowSize();
if (MathUtils.INST.equalsDouble(ty, 0.)) {
angle = tx < 0. ? Math.PI : 0.;
} else {
if (MathUtils.INST.equalsDouble(shSize, Math.abs(tx))) {
angle = ty > 0. ? -Math.PI / 2. : Math.PI / 2.;
} else {
angle = Math.acos(gravityCenter.distance(gravityCenter.getX() + tx + shSize, gravityCenter.getY()) / gravityCenter.distance(gravityCenter.getX() + tx + shSize, gravityCenter.getY() + ty));
if (tx + shSize < 0) {
if (ty < 0.) {
angle = Math.PI - angle;
} else {
angle += Math.PI;
}
} else {
if (ty > 0.) {
angle *= -1;
}
}
}
}
shape.setShadowAngle(angle);
sAngle = true;
}
}
}
shape.setHasShadow(true);
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class SVGShape method setSVGParameters.
/**
* Sets the global parameters of the figure by using an SVG element.
* @param elt The SVG element.
*/
protected void setSVGParameters(final SVGElement elt) {
if (elt == null) {
return;
}
if (shape.isThicknessable()) {
shape.setThickness(elt.getStrokeWidth());
}
if (shape.isBordersMovable()) {
final String bp = elt.getAttribute(elt.getUsablePrefix(LNamespace.LATEXDRAW_NAMESPACE_URI) + LNamespace.XML_BORDERS_POS);
if (bp != null) {
shape.setBordersPosition(BorderPos.getStyle(bp));
}
}
shape.setLineColour(elt.getStroke());
final String opacityStr = elt.getSVGAttribute(SVGAttributes.SVG_STROKE_OPACITY, null);
final Color lineCol = shape.getLineColour();
if (opacityStr != null) {
try {
shape.setLineColour(ShapeFactory.INST.createColor(lineCol.getR(), lineCol.getG(), lineCol.getB(), Double.valueOf(opacityStr)));
} catch (final NumberFormatException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
}
if (shape.isLineStylable()) {
setDashedDotted(shape, elt.getStrokeDasharray(), elt.getStrokeLinecap());
}
if (shape.isFillable()) {
setFillFromSVG(shape, elt.getFill(), elt.getSVGAttribute(SVGAttributes.SVG_FILL_OPACITY, null), elt.getSVGRoot().getDefs());
}
CSSStylesGenerator.INSTANCE.setCSSStyles(shape, elt.getStylesCSS(), elt.getSVGRoot().getDefs());
}
Aggregations