use of net.sf.latexdraw.model.api.shape.Color in project latexdraw by arnobl.
the class SVGGrid method createSVGGrid.
/**
* Creates the SVG element corresponding to the grid.
*/
void createSVGGrid(final SVGElement elt, final SVGDocument document) {
if (elt == null || document == null) {
return;
}
// Initialisation of the parameters.
final String prefix = LNamespace.LATEXDRAW_NAMESPACE + ':';
final double unit = shape.getUnit();
final int subGridDiv = shape.getSubGridDiv();
double xStep = Shape.PPC * unit;
final double xSubStep;
double yStep = Shape.PPC * unit;
final double ySubStep;
xStep *= shape.getGridEndX() < shape.getGridStartX() ? -1 : 1;
yStep *= shape.getGridEndY() < shape.getGridStartY() ? -1 : 1;
xSubStep = xStep / subGridDiv;
ySubStep = yStep / subGridDiv;
final int subGridDots = shape.getSubGridDots();
final Point tl = shape.getTopLeftPoint();
final Point br = shape.getBottomRightPoint();
double tlx = tl.getX();
double tly = tl.getY();
double brx = br.getX();
double bry = br.getY();
final double minX = shape.getGridMinX();
final double maxX = shape.getGridMaxX();
final double minY = shape.getGridMinY();
final double maxY = shape.getGridMaxY();
final double absStep = Math.abs(xStep);
final Color subGridColor = shape.getSubGridColour();
final Color linesColor = shape.getLineColour();
final double gridWidth = shape.getGridWidth();
final double posX = Math.min(shape.getGridStartX(), shape.getGridEndX()) * Shape.PPC * unit;
final double posY = -Math.min(shape.getGridStartY(), shape.getGridEndY()) * Shape.PPC * unit;
final Point position = shape.getPosition();
tlx -= position.getX();
brx -= position.getX();
tly -= position.getY();
bry -= position.getY();
elt.setAttribute(SVGAttributes.SVG_TRANSFORM, new SVGTransform.SVGTranslateTransformation(position.getX(), position.getY()).toString());
// Creation of the sub-grid
if (subGridDots > 0) {
createSVGSubGridDots(document, elt, prefix, subGridDiv, unit, xSubStep, ySubStep, minX, maxX, minY, maxY, subGridDots, shape.getSubGridWidth(), tlx, tly, brx, bry, subGridColor);
} else {
if (subGridDiv > 1) {
createSVGSubGridDiv(document, elt, prefix, subGridDiv, xSubStep, ySubStep, minX, maxX, minY, maxY, subGridDots, shape.getSubGridWidth(), tlx, tly, brx, bry, subGridColor, posX, posY, xStep, yStep);
}
}
if (shape.getGridDots() > 0) {
createSVGGridDots(document, elt, prefix, absStep, minX, maxX, minY, maxY, tlx, tly, brx, bry, unit, posX, posY, xStep, yStep, gridWidth, linesColor);
} else {
createSVGGridDiv(document, elt, prefix, minX, maxX, minY, maxY, tlx, tly, brx, bry, posX, posY, xStep, yStep, gridWidth, linesColor);
}
if (shape.getLabelsSize() > 0) {
createSVGGridLabels(document, elt, prefix, minX, maxX, minY, maxY, tlx, tly, xStep, yStep, gridWidth, absStep);
}
if (MathUtils.INST.equalsDouble(shape.getRotationAngle() % (Math.PI * 2), 0.)) {
setSVGRotationAttribute(elt);
}
}
use of net.sf.latexdraw.model.api.shape.Color in project latexdraw by arnobl.
the class PSTGridView method getParamsCode.
/**
* Returns the PST code of the parameters of the grid.
*/
@NotNull
private StringBuilder getParamsCode(final float ppc, final double unit) {
final Color gridLabelsColor = shape.getGridLabelsColour();
final Color subGridColor = shape.getSubGridColour();
final Color linesColor = shape.getLineColour();
final StringBuilder params = new StringBuilder();
// NON-NLS
params.append("gridwidth=").append(MathUtils.INST.getCutNumberFloat(shape.getGridWidth() / ppc));
// NON-NLS
params.append(", subgridwidth=").append(MathUtils.INST.getCutNumberFloat(shape.getSubGridWidth() / ppc));
// NON-NLS
params.append(", gridlabels=").append(MathUtils.INST.getCutNumber(shape.getLabelsSize() * 0.6f)).append("pt");
if (shape.getSubGridDiv() != PSTricksConstants.DEFAULT_SUBGRIDDIV) {
// NON-NLS
params.append(", subgriddiv=").append(shape.getSubGridDiv());
}
if (shape.getGridDots() != PSTricksConstants.DEFAULT_GRIDDOTS) {
// NON-NLS
params.append(", griddots=").append(shape.getGridDots());
}
if (shape.getSubGridDots() != PSTricksConstants.DEFAULT_SUBGRIDDOTS) {
// NON-NLS
params.append(", subgriddots=").append(shape.getSubGridDots());
}
if (!PSTricksConstants.DEFAULT_LABELGRIDCOLOR.equals(gridLabelsColor)) {
// NON-NLS
params.append(", gridlabelcolor=").append(getColourName(gridLabelsColor));
}
if (!MathUtils.INST.equalsDouble(unit, PSTricksConstants.DEFAULT_UNIT)) {
// NON-NLS
params.append(", unit=").append(MathUtils.INST.getCutNumberFloat(unit)).append(PSTricksConstants.TOKEN_CM);
}
if (!PSTricksConstants.DEFAULT_GRIDCOLOR.equals(linesColor)) {
// NON-NLS
params.append(", gridcolor=").append(getColourName(linesColor));
}
// NON-NLS
params.append(", subgridcolor=").append(getColourName(subGridColor));
return params;
}
use of net.sf.latexdraw.model.api.shape.Color in project latexdraw by arnobl.
the class TestDviPsColors method testGetUserColorsCodeKO.
@Test
void testGetUserColorsCodeKO() {
final Color c = ShapeFactory.INST.createColor(230d / 255d, 65d / 255d, 78d / 255d, 1d);
assertNotNull(DviPsColors.INSTANCE.getUsercolourCode(null));
assertNotNull(DviPsColors.INSTANCE.getUsercolourCode(DviPsColors.INSTANCE.addUserColour(c).orElseThrow()));
}
use of net.sf.latexdraw.model.api.shape.Color in project latexdraw by arnobl.
the class TestDviPsColors method testGetUserColorsCodeOK.
@Test
void testGetUserColorsCodeOK() {
final Color c = ShapeFactory.INST.createColor(0.5, 0.2, 0.9, 0.8);
assertEquals("\\definecolor{colour0}{rgb}{0.5,0.2,0.9}", DviPsColors.INSTANCE.getUsercolourCode(DviPsColors.INSTANCE.addUserColour(c).orElseThrow()));
}
use of net.sf.latexdraw.model.api.shape.Color 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 Color gridLabelsColor = shape.getGridLabelsColour();
final SVGElement texts = new SVGGElement(document);
final double originX = shape.getOriginX();
final double originY = shape.getOriginY();
final double xorigin = xStep * originX;
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 yorigin = shape.isXLabelSouth() ? yStep * originY + labelHeight : yStep * originY - 2d;
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()));
}
produceSVGGridLabelsTexts(document, texts, gridWidth, xorigin, yorigin, fooText, minX, maxX, minY, maxY, tlx, tly, labelWidth, labelHeight, absStep);
elt.appendChild(texts);
}
Aggregations