use of net.sf.latexdraw.models.interfaces.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 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);
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class SVGGrid method createSVGGrid.
/**
* Creates the SVG element corresponding to the grid.
*/
protected 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 = IShape.PPC * unit;
final double xSubStep;
double yStep = IShape.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 IPoint tl = shape.getTopLeftPoint();
final IPoint 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()) * IShape.PPC * unit;
final double posY = -Math.min(shape.getGridStartY(), shape.getGridEndY()) * IShape.PPC * unit;
final IPoint position = shape.getPosition();
tlx -= position.getX();
brx -= position.getX();
tly -= position.getY();
bry -= position.getY();
elt.setAttribute(SVGAttributes.SVG_TRANSFORM, SVGTransform.createTranslation(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.models.interfaces.shape.Color in project latexdraw by arnobl.
the class ViewText method getLaTeXDocument.
private String getLaTeXDocument() {
final String code = model.getText();
final StringBuilder doc = new StringBuilder();
final Color textColour = model.getLineColour();
boolean coloured = false;
// We must scale the text to fit its latex size: latexdrawDPI/latexDPI is the ratio to scale the created png picture.
final double scale = IShape.PPC * PSTricksConstants.INCH_VAL_CM / PSTricksConstants.INCH_VAL_PT * SCALE_COMPILE;
// $NON-NLS-1$
doc.append("\\documentclass{standalone}\n\\usepackage[usenames,dvipsnames]{pstricks}");
doc.append(LaTeXGenerator.getPackages()).append('\n');
// $NON-NLS-1$
doc.append("\\begin{document}\n\\psscalebox{");
doc.append((float) MathUtils.INST.getCutNumber(scale)).append(' ');
doc.append((float) MathUtils.INST.getCutNumber(scale)).append('}').append('{');
if (!textColour.equals(PSTricksConstants.DEFAULT_LINE_COLOR)) {
final String name = DviPsColors.INSTANCE.getColourName(textColour).orElse(DviPsColors.INSTANCE.addUserColour(textColour).orElse(""));
coloured = true;
// $NON-NLS-1$
doc.append(DviPsColors.INSTANCE.getUsercolourCode(name)).append("\\textcolor{").append(name).append('}').append('{');
}
doc.append(code);
if (coloured) {
doc.append('}');
}
// $NON-NLS-1$
doc.append("}\n\\end{document}");
return doc.toString();
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class PSTGridView method getParamsCode.
/**
* Returns the PST code of the parameters of the grid.
*/
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-1$
params.append("gridwidth=").append(MathUtils.INST.getCutNumberFloat(shape.getGridWidth() / ppc));
// $NON-NLS-1$
params.append(", subgridwidth=").append(MathUtils.INST.getCutNumberFloat(shape.getSubGridWidth() / ppc));
// $NON-NLS-1$ //$NON-NLS-2$
params.append(", gridlabels=").append(MathUtils.INST.getCutNumber(shape.getLabelsSize() * 0.6f)).append("pt");
if (shape.getSubGridDiv() != PSTricksConstants.DEFAULT_SUBGRIDDIV)
// $NON-NLS-1$
params.append(", subgriddiv=").append(shape.getSubGridDiv());
if (shape.getGridDots() != PSTricksConstants.DEFAULT_GRIDDOTS)
// $NON-NLS-1$
params.append(", griddots=").append(shape.getGridDots());
if (shape.getSubGridDots() != PSTricksConstants.DEFAULT_SUBGRIDDOTS)
// $NON-NLS-1$
params.append(", subgriddots=").append(shape.getSubGridDots());
if (!gridLabelsColor.equals(PSTricksConstants.DEFAULT_LABELGRIDCOLOR))
// $NON-NLS-1$
params.append(", gridlabelcolor=").append(getColourName(gridLabelsColor));
if (!MathUtils.INST.equalsDouble(unit, PSTricksConstants.DEFAULT_UNIT))
// $NON-NLS-1$
params.append(", unit=").append(MathUtils.INST.getCutNumberFloat(unit)).append(PSTricksConstants.TOKEN_CM);
if (!linesColor.equals(PSTricksConstants.DEFAULT_GRIDCOLOR))
// $NON-NLS-1$
params.append(", gridcolor=").append(getColourName(linesColor));
// $NON-NLS-1$
params.append(", subgridcolor=").append(getColourName(subGridColor));
return params;
}
use of net.sf.latexdraw.models.interfaces.shape.Color in project latexdraw by arnobl.
the class TestDviPsColors method testGetColorNameOK.
@SuppressWarnings("all")
@Test
public void testGetColorNameOK() {
Color c2 = ShapeFactory.INST.createColor(218d / 255d, 29d / 255d, 78d / 255d, 1d);
Optional<String> nameColour = DviPsColors.INSTANCE.addUserColour(c2);
assertEquals(nameColour.get(), DviPsColors.INSTANCE.getColourName(c2).get());
}
Aggregations