1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-07 02:40:52 +00:00

Emoji color fix

This commit is contained in:
Arnaud Roques 2022-01-07 19:04:36 +01:00
parent 89a9227afd
commit 24bd088e01
26 changed files with 294 additions and 710 deletions

View File

@ -212,8 +212,8 @@ public class Splash extends Window implements MouseListener, MouseMotionListener
final int y = 33;
final int barWidth = 170;
final int barHeight = (int) (rect.getHeight() + 2);
final int grey = 230;
g.setColor(new Color(grey, grey, grey));
final int gray = 230;
g.setColor(new Color(gray, gray, gray));
final int value = barWidth * intValue / totalValue;
g.fillRect(x, y, value, barHeight);
g.setColor(Color.BLACK);

View File

@ -91,7 +91,7 @@ public class CollisionDetector extends UGraphicNo {
public void drawDebug(UGraphic ug) {
for (MinMax minmax : rectangles) {
if (collision(minmax)) {
minmax.drawGrey(ug);
minmax.drawGray(ug);
}
}
final HColor color = HColorUtils.BLACK;

View File

@ -56,7 +56,7 @@ public class Zad {
ug = ug.apply(HColorUtils.BLUE.bg()).apply(HColorUtils.RED_LIGHT);
for (MinMax minMax : rectangles) {
System.err.println("minmax=" + minMax);
minMax.drawGrey(ug);
minMax.drawGray(ug);
}
}

View File

@ -1,5 +1,6 @@
package net.sourceforge.plantuml.emoji;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -19,6 +20,7 @@ import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.ColorChangerMonochrome;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
@ -48,6 +50,8 @@ public class Emoji {
}
private final List<String> data = new ArrayList<>();
private int minGray = 999;
private int maxGray = -1;
private final String unicode;
private final String shortcut;
@ -116,6 +120,12 @@ public class Emoji {
e.printStackTrace();
}
UGraphicWithScale ugs = new UGraphicWithScale(ug, scale);
synchronized (this) {
if (colorForMonochrome != null && maxGray == -1)
computeMinMaxGray();
}
final List<UGraphicWithScale> stack = new ArrayList<>();
for (String s : data) {
if (s.contains("<path ")) {
@ -139,6 +149,39 @@ public class Emoji {
}
}
private void computeMinMaxGray() {
for (String s : data) {
if (s.contains("<path ")) {
final int gray = getGray(justExtractColor(s));
minGray = Math.min(minGray, gray);
maxGray = Math.max(maxGray, gray);
} else if (s.contains("</g>")) {
// Nothing
} else if (s.contains("<g>")) {
// Nothing
} else if (s.contains("<g ")) {
final int gray = getGray(justExtractColor(s));
minGray = Math.min(minGray, gray);
maxGray = Math.max(maxGray, gray);
} else if (s.contains("<circle ")) {
final int gray = getGray(justExtractColor(s));
minGray = Math.min(minGray, gray);
maxGray = Math.max(maxGray, gray);
} else if (s.contains("<ellipse ")) {
final int gray = getGray(justExtractColor(s));
minGray = Math.min(minGray, gray);
maxGray = Math.max(maxGray, gray);
} else {
// Nothing
}
}
}
private int getGray(HColor col) {
final Color tmp = new ColorChangerMonochrome().getChangedColor(col);
return tmp.getGreen();
}
private UGraphicWithScale applyFill(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
final String fillString = extractData("fill", s);
if (fillString == null)
@ -165,12 +208,31 @@ public class Emoji {
return ugs;
}
private HColor justExtractColor(String s) {
final String fillString = extractData("fill", s);
if (fillString == null)
return null;
if (fillString.equals("none")) {
final String strokeString = extractData("stroke", s);
if (strokeString == null)
return null;
final HColor stroke = getTrueColor(strokeString, null);
return stroke;
} else {
final HColor fill = getTrueColor(fillString, null);
return fill;
}
}
private HColor getTrueColor(String code, HColor colorForMonochrome) {
final HColorSimple result = (HColorSimple) HColorSet.instance().getColorOrWhite(code);
if (colorForMonochrome == null)
return result;
return result.asMonochrome((HColorSimple) colorForMonochrome);
return result.asMonochrome((HColorSimple) colorForMonochrome, this.minGray, this.maxGray);
}
private void drawCircle(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {

View File

@ -1,364 +0,0 @@
package net.sourceforge.plantuml.emoji;
import java.awt.geom.AffineTransform;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.emoji.data.Dummy;
import net.sourceforge.plantuml.openiconic.SvgPath;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorSimple;
// Emojji from https://twemoji.twitter.com/
// Shorcut from https://api.github.com/emojis
public class EmojiTmp {
private final static Map<String, EmojiTmp> ALL = new HashMap<>();
static {
final InputStream is = Dummy.class.getResourceAsStream("emoji.txt");
try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String s = null;
while ((s = br.readLine()) != null) {
new EmojiTmp(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static Map<String, EmojiTmp> getAll() {
return Collections.unmodifiableMap(new TreeMap<>(ALL));
}
private final List<String> data = new ArrayList<>();
private final String unicode;
private final String shortcut;
private EmojiTmp(String unicode) {
final int x = unicode.indexOf(';');
if (x == -1) {
this.shortcut = null;
} else {
this.shortcut = unicode.substring(x + 1);
ALL.put(this.shortcut, this);
unicode = unicode.substring(0, x);
}
this.unicode = unicode;
ALL.put(unicode, this);
}
public static String pattern() {
final StringBuilder sb = new StringBuilder("\\<(#\\w+)?:(");
for (String s : ALL.keySet()) {
if (sb.toString().endsWith("(") == false)
sb.append("|");
sb.append(s);
}
sb.append("):\\>");
return sb.toString();
}
public static EmojiTmp retrieve(String name) {
return ALL.get(name.toLowerCase());
}
private String extractData(String name, String s) {
final Pattern p = Pattern.compile(name + "=\"([^\"]+)\"");
final Matcher m = p.matcher(s);
if (m.find())
return m.group(1);
return null;
}
private synchronized void loadIfNeed() throws IOException {
if (data.size() > 0)
return;
try (BufferedReader br = new BufferedReader(
new InputStreamReader(Dummy.class.getResourceAsStream(unicode + ".svg")))) {
final String singleLine = br.readLine();
final Pattern p = Pattern.compile("\\<[^<>]+\\>");
final Matcher m = p.matcher(singleLine);
while (m.find()) {
final String s = m.group(0);
if (s.contains("<path") || s.contains("<g ") || s.contains("<g>") || s.contains("</g>")
|| s.contains("<circle ") || s.contains("<ellipse "))
data.add(s);
else
System.err.println("???=" + s);
}
}
}
public void drawU(UGraphic ug, double scale, HColor colorForMonochrome) {
try {
loadIfNeed();
} catch (IOException e) {
e.printStackTrace();
}
UGraphicWithScale ugs = new UGraphicWithScale(ug, scale);
final List<UGraphicWithScale> stack = new ArrayList<>();
for (String s : data) {
if (s.contains("<path ")) {
drawPath(ugs, s, colorForMonochrome);
} else if (s.contains("</g>")) {
ugs = stack.remove(0);
} else if (s.contains("<g>")) {
stack.add(0, ugs);
} else if (s.contains("<g ")) {
stack.add(0, ugs);
ugs = applyFill(ugs, s, colorForMonochrome);
ugs = applyTransform(ugs, s);
} else if (s.contains("<circle ")) {
drawCircle(ugs, s, colorForMonochrome);
} else if (s.contains("<ellipse ")) {
drawEllipse(ugs, s, colorForMonochrome);
} else {
System.err.println("**?=" + s);
}
}
}
private UGraphicWithScale applyFill(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
final String fillString = extractData("fill", s);
if (fillString == null)
return ugs;
if (fillString.equals("none")) {
final String strokeString = extractData("stroke", s);
if (strokeString == null)
return ugs;
ugs = ugs.apply(new HColorNone().bg());
final HColor stroke = getTrueColor(strokeString, colorForMonochrome);
ugs = ugs.apply(stroke);
final String strokeWidth = extractData("stroke-width", s);
if (strokeWidth != null) {
ugs = ugs.apply(new UStroke(Double.parseDouble(strokeWidth)));
}
} else {
final HColor fill = getTrueColor(fillString, colorForMonochrome);
ugs = ugs.apply(fill).apply(fill.bg());
}
return ugs;
}
private HColor getTrueColor(String code, HColor colorForMonochrome) {
final HColorSimple result = (HColorSimple) HColorSet.instance().getColorOrWhite(code);
if (colorForMonochrome == null)
return result;
return result.asMonochrome((HColorSimple) colorForMonochrome);
}
private void drawCircle(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
if (s.contains("matrix(") || s.contains("rotate(")) {
System.err.println("Warning " + s);
return;
}
ugs = applyFill(ugs, s, colorForMonochrome);
ugs = applyTransform(ugs, s);
final double scalex = ugs.getAffineTransform().getScaleX();
final double scaley = ugs.getAffineTransform().getScaleY();
final double deltax = ugs.getAffineTransform().getTranslateX();
final double deltay = ugs.getAffineTransform().getTranslateY();
final double cx = Double.parseDouble(extractData("cx", s)) * scalex;
final double cy = Double.parseDouble(extractData("cy", s)) * scaley;
final double rx = Double.parseDouble(extractData("r", s)) * scalex;
final double ry = Double.parseDouble(extractData("r", s)) * scaley;
final UTranslate translate = new UTranslate(deltax + cx - rx, deltay + cy - ry);
ugs.apply(translate).draw(new UEllipse(rx * 2, ry * 2));
}
private void drawEllipse(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
ugs = applyFill(ugs, s, colorForMonochrome);
final double scalex = ugs.getAffineTransform().getScaleX();
final double scaley = ugs.getAffineTransform().getScaleY();
final double deltax = ugs.getAffineTransform().getTranslateX();
final double deltay = ugs.getAffineTransform().getTranslateY();
final double cx = Double.parseDouble(extractData("cx", s)) * scalex;
final double cy = Double.parseDouble(extractData("cy", s)) * scaley;
final double rx = Double.parseDouble(extractData("rx", s)) * scalex;
final double ry = Double.parseDouble(extractData("ry", s)) * scaley;
if (s.contains("matrix(") || s.contains("rotate(")) {
final UTranslate translate = new UTranslate(deltax + cx + rx, deltay + cy);
final String tmp = ellipseAsPath((int) rx, (int) ry);
final SvgPath svgPath = new SvgPath(tmp);
ugs = ugs.applyTranslate(translate.getDx(), translate.getDy());
// ugs = applyTransform(ugs, s);
AffineTransform rot = getRotate(s);
System.err.println("rot=" + rot);
AffineTransform current = new AffineTransform(ugs.getAffineTransform());
current.concatenate(rot);
svgPath.drawMe(ugs.getUg(), current);
} else {
ugs = applyTransform(ugs, s);
final UTranslate translate = new UTranslate(deltax + cx - rx, deltay + cy - ry);
ugs.apply(translate).draw(new UEllipse(rx * 2, ry * 2));
}
}
private String ellipseAsPath(int rx, int ry) {
return "M " + (-2 * rx) + ",0 a " + rx + "," + ry + " 0 1,0 " + (2 * rx) + ",0 a " + rx + "," + ry + " 0 1,0 "
+ (-2 * rx) + ",0";
}
private void drawPath(UGraphicWithScale ugs, String s, HColor colorForMonochrome) {
s = s.replace("id=\"", "ID=\"");
ugs = applyFill(ugs, s, colorForMonochrome);
ugs = applyTransform(ugs, s);
final int x1 = s.indexOf("d=\"");
final int x2 = s.indexOf('"', x1 + 3);
final String tmp = s.substring(x1 + 3, x2);
final SvgPath svgPath = new SvgPath(tmp);
svgPath.drawMe(ugs.getUg(), ugs.getAffineTransform());
}
private UGraphicWithScale applyTransform(UGraphicWithScale ugs, String s) {
final String transform = extractData("transform", s);
if (transform == null)
return ugs;
if (transform.contains("rotate("))
return applyRotate(ugs, transform);
if (transform.contains("matrix("))
return applyMatrix(ugs, transform);
final double[] scale = getScale(transform);
final UTranslate translate = getTranslate(transform);
ugs = ugs.applyTranslate(translate.getDx(), translate.getDy());
return ugs.applyScale(scale[0], scale[1]);
}
private UGraphicWithScale applyMatrix(UGraphicWithScale ugs, final String transform) {
final Pattern p3 = Pattern.compile(
"matrix\\(([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)\\)");
final Matcher m3 = p3.matcher(transform);
if (m3.find()) {
final double v1 = Double.parseDouble(m3.group(1));
final double v2 = Double.parseDouble(m3.group(2));
final double v3 = Double.parseDouble(m3.group(3));
final double v4 = Double.parseDouble(m3.group(4));
final double v5 = Double.parseDouble(m3.group(5));
final double v6 = Double.parseDouble(m3.group(6));
ugs = ugs.applyMatrix(v1, v2, v3, v4, v5, v6);
} else
System.err.println("WARNING: " + transform);
return ugs;
}
private AffineTransform getRotate(String transform) {
final Pattern p3 = Pattern.compile("rotate\\(([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)\\)");
final Matcher m3 = p3.matcher(transform);
if (m3.find()) {
final double angle = Double.parseDouble(m3.group(1));
final double x = Double.parseDouble(m3.group(2));
final double y = Double.parseDouble(m3.group(3));
System.err.println("angle=" + angle);
System.err.println("x=" + x);
System.err.println("y=" + y);
final AffineTransform copy = new AffineTransform();
copy.rotate(angle * Math.PI / 180, 11, 30);
return copy;
} else
System.err.println("WARNING: " + transform);
return null;
}
private UGraphicWithScale applyRotate(UGraphicWithScale ugs, final String transform) {
final Pattern p3 = Pattern.compile("rotate\\(([-.0-9]+)[ ,]+([-.0-9]+)[ ,]+([-.0-9]+)\\)");
final Matcher m3 = p3.matcher(transform);
if (m3.find()) {
final double angle = Double.parseDouble(m3.group(1));
final double x = Double.parseDouble(m3.group(2));
final double y = Double.parseDouble(m3.group(3));
ugs = ugs.applyRotate(angle, x, y);
} else
System.err.println("WARNING: " + transform);
return ugs;
}
private UTranslate getTranslate(String transform) {
double x = 0;
double y = 0;
final Pattern p3 = Pattern.compile("translate\\(([-.0-9]+)[ ,]+([-.0-9]+)\\)");
final Matcher m3 = p3.matcher(transform);
if (m3.find()) {
x = Double.parseDouble(m3.group(1));
y = Double.parseDouble(m3.group(2));
} else {
final Pattern p4 = Pattern.compile("translate\\(([-.0-9]+)\\)");
final Matcher m4 = p4.matcher(transform);
if (m4.find()) {
x = Double.parseDouble(m4.group(1));
y = Double.parseDouble(m4.group(1));
}
}
return new UTranslate(x, y);
}
private double[] getScale(String transform) {
final double scale[] = new double[] { 1, 1 };
final Pattern p1 = Pattern.compile("scale\\(([-.0-9]+)\\)");
final Matcher m1 = p1.matcher(transform);
if (m1.find()) {
scale[0] = Double.parseDouble(m1.group(1));
scale[1] = scale[0];
} else {
final Pattern p2 = Pattern.compile("scale\\(([-.0-9]+)[ ,]+([-.0-9]+)\\)");
final Matcher m2 = p2.matcher(transform);
if (m2.find()) {
scale[0] = Double.parseDouble(m2.group(1));
scale[1] = Double.parseDouble(m2.group(2));
}
}
return scale;
}
public String getShortcut() {
return shortcut;
}
}

View File

@ -37,46 +37,44 @@ package net.sourceforge.plantuml.sequencediagram;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.PaddingParam;
import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.real.Real;
import net.sourceforge.plantuml.real.RealUtils;
import net.sourceforge.plantuml.sequencediagram.teoz.LivingSpace;
import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.style.WithStyle;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class Doll extends DollAbstract {
public class Doll implements WithStyle {
final private List<Participant> participants = new ArrayList<>();
private final List<Doll> leafs = new ArrayList<>();
final private Real core1;
final private Real core2;
private double marginX = 0;
public static Doll createGroup(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder,
boolean isTeoz) {
return new Doll(englober, tileArguments, styleBuilder, isTeoz);
}
final private ParticipantEnglober englober;
final private StyleBuilder styleBuilder;
final private TileArguments tileArguments;
public static Doll createPuma(ParticipantEnglober englober, Participant first, ISkinParam skinParam, Rose skin,
StringBounder stringBounder, StyleBuilder styleBuilder) {
return new Doll(englober, convertFunctionToBeRemoved(skinParam, skin, stringBounder), styleBuilder, false,
first);
return new Doll(englober, convertFunctionToBeRemoved(skinParam, skin, stringBounder), styleBuilder, first);
}
public static Doll createTeoz(ParticipantEnglober englober, Participant first, TileArguments tileArguments,
StyleBuilder styleBuilder) {
final Doll result = new Doll(englober, tileArguments, styleBuilder, true, first);
return result;
public static Doll createTeoz(ParticipantEnglober englober, TileArguments tileArguments) {
return new Doll(englober, tileArguments, tileArguments.getSkinParam().getCurrentStyleBuilder(), null);
}
private static TileArguments convertFunctionToBeRemoved(ISkinParam skinParam, Rose skin,
@ -84,24 +82,47 @@ public class Doll extends DollAbstract {
return new TileArguments(stringBounder, null, skin, skinParam, null);
}
private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz,
private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder,
Participant first) {
super(englober, tileArguments, styleBuilder, isTeoz);
this.participants.add(first);
final double preferredWidth = getPreferredWidth();
if (tileArguments.getLivingSpaces() == null) {
this.core1 = null;
this.core2 = null;
} else {
this.core1 = getMiddle().addFixed(-preferredWidth / 2);
this.core2 = getMiddle().addFixed(preferredWidth / 2);
this.englober = Objects.requireNonNull(englober);
this.styleBuilder = styleBuilder;
this.tileArguments = Objects.requireNonNull(tileArguments);
if (first != null) {
this.participants.add(first);
}
}
private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) {
super(englober, tileArguments, styleBuilder, isTeoz);
this.core1 = null;
this.core2 = null;
final public StyleSignature getDefaultStyleDefinition() {
return ComponentType.ENGLOBER.getDefaultStyleDefinition();
}
final public Style[] getUsedStyles() {
Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder);
final HColor backColor = englober.getBoxColor();
if (tmp != null)
tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor);
return new Style[] { tmp };
}
final public ParticipantEnglober getParticipantEnglober() {
return englober;
}
private Component getComponent() {
final ParticipantEnglober englober = getParticipantEnglober();
final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam()
: new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor());
return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s,
englober.getTitle());
}
public double getTitlePreferredHeight() {
final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null,
tileArguments.getSkinParam(), getParticipantEnglober().getTitle());
return comp.getPreferredHeight(tileArguments.getStringBounder());
}
public final Participant getFirst2TOBEPRIVATE() {
@ -112,33 +133,28 @@ public class Doll extends DollAbstract {
return participants.get(participants.size() - 1);
}
private Real getMiddle() {
return RealUtils.middle(getPosB(), getPosD());
private Real getPosA(StringBounder stringBounder) {
return getFirstLivingSpace().getPosA(stringBounder);
}
private Real getPosB() {
return getFirstLivingSpace().getPosB();
private Real getPosB(StringBounder stringBounder) {
return getFirstLivingSpace().getPosB(stringBounder);
}
private Real getPosD() {
return getLastLivingSpace().getPosD(tileArguments.getStringBounder());
private Real getPosD(StringBounder stringBounder) {
return getLastLivingSpace().getPosD(stringBounder);
}
private Real getPosAA() {
private Real getPosE(StringBounder stringBounder) {
return getLastLivingSpace().getPosE(stringBounder);
}
private Real getPosAA(StringBounder stringBounder) {
final LivingSpace previous = tileArguments.getLivingSpaces().previous(getFirstLivingSpace());
if (previous == null) {
return tileArguments.getOrigin();
}
return previous.getPosD(tileArguments.getStringBounder());
}
private Real getPosZZ() {
final LivingSpace next = tileArguments.getLivingSpaces().next(getLastLivingSpace());
if (next == null) {
// return tileArguments.getMaxAbsolute();
return null;
}
return next.getPosB();
return previous.getPosD(stringBounder);
}
private LivingSpace getFirstLivingSpace() {
@ -154,58 +170,22 @@ public class Doll extends DollAbstract {
}
public void addParticipant(Participant p) {
if (participants.contains(p))
throw new IllegalArgumentException();
participants.add(p);
}
public void addDoll(Doll doll) {
this.leafs.add(doll);
participants.add(Objects.requireNonNull(p));
}
@Override
public String toString() {
return "DollLeaf:" + englober.getTitle().toString() + " " + participants;
}
private double getPreferredWidth() {
if (isTeoz) {
return 10;
}
return getTitleWidth();
return "Doll:" + englober.getTitle().toString() + " " + participants;
}
private double getTitleWidth() {
return getComponent().getPreferredWidth(tileArguments.getStringBounder());
}
public void drawGroup(UGraphic ug, double height, Context2D context) {
if (leafs.size() == 0)
throw new IllegalArgumentException();
final double x1 = getGroupX1();
final double x2 = getGroupX2();
final Dimension2DDouble dim = new Dimension2DDouble(x2 - x1, height);
getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context);
}
private double getGroupX1() {
double result = leafs.get(0).getX1().getCurrentValue() - 6;
if (participants.size() > 0)
result = Math.min(result, getX1().getCurrentValue() - 6);
return result;
}
private double getGroupX2() {
double result = leafs.get(leafs.size() - 1).getX2().getCurrentValue() + 6;
if (participants.size() > 0)
result = Math.max(result, getX2().getCurrentValue() + 6);
return result;
}
public void drawMe(UGraphic ug, double height, Context2D context, Doll group) {
final double x1 = getX1().getCurrentValue() - 4;
final double x2 = getX2().getCurrentValue() + 4;
final StringBounder stringBounder = ug.getStringBounder();
final double x1 = getPosA(stringBounder).getCurrentValue() - 4;
final double x2 = getPosE(stringBounder).getCurrentValue() + 4;
if (group != null) {
final double titlePreferredHeight = group.getTitlePreferredHeight();
@ -217,49 +197,38 @@ public class Doll extends DollAbstract {
getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context);
}
private Real getX1() {
if (core1 == null)
return getPosB().addFixed(-marginX);
return RealUtils.min(getPosB(), core1).addFixed(-marginX);
}
private Real getX2() {
if (core2 == null)
return getPosD().addFixed(marginX);
return RealUtils.max(getPosD(), core2).addFixed(marginX);
}
public void addInternalConstraints() {
assert isTeoz;
public void addInternalConstraints(StringBounder stringBounder) {
final double titleWidth = getTitleWidth();
final double x1 = getX1().getCurrentValue();
final double x2 = getX2().getCurrentValue();
final double x1 = getPosB(stringBounder).getCurrentValue();
final double x2 = getPosD(stringBounder).getCurrentValue();
final double actualWidth = x2 - x1;
if (titleWidth > actualWidth + 20)
this.marginX = (titleWidth - actualWidth - 20) / 2;
final double marginX = (titleWidth + 10 - actualWidth) / 2;
if (marginX > 0) {
getFirstLivingSpace().ensureMarginBefore(marginX);
getLastLivingSpace().ensureMarginAfter(marginX);
}
getPosA(stringBounder).ensureBiggerThan(getPosAA(stringBounder).addFixed(10 + padding()));
getX1().ensureBiggerThan(getPosAA().addFixed(10 + padding()));
final Real posZZ = getPosZZ();
final Real limit = getX2().addFixed(10 + padding());
if (posZZ != null)
posZZ.ensureBiggerThan(limit);
}
public void addConstraintAfter(StringBounder stringBounder) {
final LivingSpace next = tileArguments.getLivingSpaces().next(getLastLivingSpace());
if (next == null)
return;
next.getPosA(stringBounder).ensureBiggerThan(getPosE(stringBounder).addFixed(20 + 2 * padding()));
}
private double padding() {
return tileArguments.getSkinParam().getPadding(PaddingParam.BOX);
}
public void addConstraintAfter(Doll current) {
current.getX1().ensureBiggerThan(getX2().addFixed(10 + 2 * padding()));
}
public Real getMinX(StringBounder stringBounder) {
return getX1();
return getPosA(stringBounder);
}
public Real getMaxX(StringBounder stringBounder) {
return getX2().addFixed(10);
return getPosE(stringBounder).addFixed(10);
}
}

View File

@ -1,98 +0,0 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.sequencediagram;
import java.util.Objects;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.style.WithStyle;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public abstract class DollAbstract implements WithStyle {
final protected ParticipantEnglober englober;
final protected StyleBuilder styleBuilder;
final protected boolean isTeoz;
final protected TileArguments tileArguments;
DollAbstract(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) {
this.englober = Objects.requireNonNull(englober);
this.styleBuilder = styleBuilder;
this.isTeoz = isTeoz;
this.tileArguments = Objects.requireNonNull(tileArguments);
}
final public StyleSignature getDefaultStyleDefinition() {
return ComponentType.ENGLOBER.getDefaultStyleDefinition();
}
final public Style[] getUsedStyles() {
Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder);
final HColor backColor = englober.getBoxColor();
if (tmp != null)
tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor);
return new Style[] { tmp };
}
final public ParticipantEnglober getParticipantEnglober() {
return englober;
}
final protected Component getComponent() {
final ParticipantEnglober englober = getParticipantEnglober();
final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam()
: new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor());
return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s,
englober.getTitle());
}
public double getTitlePreferredHeight() {
final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null,
tileArguments.getSkinParam(), getParticipantEnglober().getTitle());
return comp.getPreferredHeight(tileArguments.getStringBounder());
}
}

View File

@ -35,6 +35,10 @@
*/
package net.sourceforge.plantuml.sequencediagram;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.ugraphic.color.HColor;
@ -45,7 +49,7 @@ public class ParticipantEnglober {
final private Display title;
final private HColor boxColor;
final private Stereotype stereotype;
@Override
public String toString() {
return title.toString();
@ -82,4 +86,14 @@ public class ParticipantEnglober {
return parent;
}
public final List<ParticipantEnglober> getGenealogy() {
final LinkedList<ParticipantEnglober> result = new LinkedList<>();
ParticipantEnglober current = this;
while (current != null) {
result.addFirst(current);
current = current.getParent();
}
return Collections.unmodifiableList(result);
}
}

View File

@ -256,9 +256,9 @@ public class SequenceDiagram extends UmlDiagram {
if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT)
return new SequenceDiagramTxtMaker(this, fileFormat);
if (fileFormat.name().startsWith("XMI"))
if (fileFormat.name().startsWith("XMI"))
return new SequenceDiagramXmiMaker(this, fileFormat);
if (modeTeoz())
return new SequenceDiagramFileMakerTeoz(this, skin2, fileFormatOption, index);

View File

@ -263,7 +263,7 @@ public class CommunicationTile extends AbstractTile {
if (isReverse(stringBounder)) {
return livingSpace2.getPosD(stringBounder);
}
return livingSpace2.getPosB();
return livingSpace2.getPosB(stringBounder);
}
return livingSpace2.getPosC(stringBounder);
}

View File

@ -36,7 +36,7 @@
package net.sourceforge.plantuml.sequencediagram.teoz;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -51,50 +51,42 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
public class Dolls {
private final List<Doll> dolls = new ArrayList<>();
private final Map<ParticipantEnglober, Doll> groups = new HashMap<>();
private final Map<ParticipantEnglober, Doll> alls = new LinkedHashMap<>();
public Dolls(TileArguments tileArguments) {
Doll pending = null;
for (Participant p : tileArguments.getLivingSpaces().participants()) {
final ParticipantEnglober englober = tileArguments.getLivingSpaces().get(p).getEnglober();
if (englober == null) {
pending = null;
continue;
}
assert englober != null;
if (pending != null && englober == pending.getParticipantEnglober()) {
pending.addParticipant(p);
continue;
}
if (englober != null)
for (ParticipantEnglober pe : englober.getGenealogy())
addParticipant(p, pe, tileArguments);
if (groups.containsKey(englober)) {
groups.get(englober).addParticipant(p);
continue;
}
final ParticipantEnglober parent = englober.getParent();
pending = Doll.createTeoz(englober, p, tileArguments,
tileArguments.getSkinParam().getCurrentStyleBuilder());
if (parent != null && groups.containsKey(parent) == false)
groups.put(parent, Doll.createGroup(parent, tileArguments,
tileArguments.getSkinParam().getCurrentStyleBuilder(), true));
if (parent != null)
getParent(pending).addDoll(pending);
dolls.add(pending);
}
}
private void addParticipant(Participant p, ParticipantEnglober englober, TileArguments tileArguments) {
Doll already = alls.get(englober);
if (already == null) {
already = Doll.createTeoz(englober, tileArguments);
alls.put(englober, already);
}
already.addParticipant(p);
}
private Doll getParent(Doll doll) {
final ParticipantEnglober parent = doll.getParticipantEnglober().getParent();
if (parent == null)
return null;
return alls.get(parent);
}
public int size() {
return dolls.size();
return alls.size();
}
public double getOffsetForEnglobers(StringBounder stringBounder) {
double result = 0;
for (Doll doll : dolls) {
for (Doll doll : alls.values()) {
double height = doll.getTitlePreferredHeight();
final Doll group = getParent(doll);
if (group != null)
@ -108,41 +100,18 @@ public class Dolls {
}
public void addConstraints(StringBounder stringBounder) {
Doll last = null;
for (Doll doll : dolls) {
doll.addInternalConstraints();
if (last != null)
last.addConstraintAfter(doll);
last = doll;
for (Doll doll : alls.values()) {
doll.addInternalConstraints(stringBounder);
}
for (Doll doll : alls.values()) {
doll.addConstraintAfter(stringBounder);
}
}
private Doll getParent(Doll doll) {
final ParticipantEnglober parent = doll.getParticipantEnglober().getParent();
if (parent == null)
return null;
return groups.get(parent);
}
public void drawEnglobers(UGraphic ug, double height, Context2D context) {
for (Doll group : groups.values()) {
group.drawGroup(ug, height, context);
}
// DollGroup pending = null;
// for (DollLeaf doll : dolls) {
// final DollGroup group = doll.getGroup();
// if (group==null) {
//
// }
// // if (pending==null || pending.equals(group))
// if (group != null) {
// // group.drawMe(ug, height, context, doll.getX1().getCurrentValue(), doll.getX2().getCurrentValue());
// }
// }
for (Doll doll : dolls)
for (Doll doll : alls.values())
doll.drawMe(ug, height, context, getParent(doll));
}
@ -152,7 +121,7 @@ public class Dolls {
throw new IllegalStateException();
final List<Real> result = new ArrayList<>();
for (Doll doll : dolls)
for (Doll doll : alls.values())
result.add(doll.getMinX(stringBounder));
return RealUtils.min(result);
@ -163,7 +132,7 @@ public class Dolls {
throw new IllegalStateException();
final List<Real> result = new ArrayList<>();
for (Doll doll : dolls)
for (Doll doll : alls.values())
result.add(doll.getMaxX(stringBounder));
return RealUtils.max(result);

View File

@ -114,7 +114,7 @@ public class LifeEventTile extends AbstractTile {
public Real getMinX() {
// return tileArguments.getLivingSpace(lifeEvent.getParticipant()).getPosB();
return livingSpace.getPosB();
return livingSpace.getPosB(getStringBounder());
}
public Real getMaxX() {

View File

@ -221,7 +221,7 @@ public class LivingSpace {
return posD;
}
public Real getPosB() {
public Real getPosB(StringBounder stringBounder) {
return posB;
}
@ -247,4 +247,27 @@ public class LivingSpace {
return englober;
}
private double marginBefore;
private double marginAfter;
public void ensureMarginBefore(double margin) {
if (margin < 0)
throw new IllegalArgumentException();
this.marginBefore = Math.max(marginBefore, margin);
}
public void ensureMarginAfter(double margin) {
if (margin < 0)
throw new IllegalArgumentException();
this.marginAfter = Math.max(marginAfter, margin);
}
public Real getPosA(StringBounder stringBounder) {
return getPosB(stringBounder).addFixed(-marginBefore);
}
public Real getPosE(StringBounder stringBounder) {
return getPosD(stringBounder).addFixed(marginAfter);
}
}

View File

@ -62,8 +62,8 @@ public class LivingSpaces {
LivingSpace previous = null;
for (LivingSpace current : all.values()) {
if (previous != null) {
final Real point1 = previous.getPosD(stringBounder);
final Real point2 = current.getPosB();
final Real point1 = previous.getPosE(stringBounder);
final Real point2 = current.getPosA(stringBounder);
point2.ensureBiggerThan(point1.addFixed(10));
}
previous = current;
@ -108,7 +108,7 @@ public class LivingSpaces {
final StringBounder stringBounder = ug.getStringBounder();
final double headHeight = getHeadHeight(stringBounder);
for (LivingSpace livingSpace : values()) {
final double x = livingSpace.getPosB().getCurrentValue();
final double x = livingSpace.getPosB(stringBounder).getCurrentValue();
double y = 0;
if (verticalAlignment == VerticalAlignment.BOTTOM) {
final Dimension2D dimHead = livingSpace.getHeadPreferredDimension(stringBounder);

View File

@ -112,7 +112,7 @@ public class NoteTile extends AbstractTile implements Tile {
final Dimension2D dim = comp.getPreferredDimension(stringBounder);
final double width = dim.getWidth();
if (note.getPosition() == NotePosition.OVER_SEVERAL) {
final double x1 = livingSpace1.getPosB().getCurrentValue();
final double x1 = livingSpace1.getPosB(stringBounder).getCurrentValue();
final double x2 = livingSpace2.getPosD(stringBounder).getCurrentValue();
final double w = x2 - x1;
if (width < w) {
@ -157,7 +157,7 @@ public class NoteTile extends AbstractTile implements Tile {
public Real getMinX() {
final Real result = getX(getStringBounder());
if (note.getPosition() == NotePosition.OVER_SEVERAL) {
final Real x1 = livingSpace1.getPosB();
final Real x1 = livingSpace1.getPosB(getStringBounder());
return RealUtils.min(result, x1);
}
return result;

View File

@ -75,7 +75,7 @@ public class ReferenceTile extends AbstractTile implements Tile {
final LivingSpace livingSpace = tileArguments.getLivingSpace(p);
final Real pos = livingSpace.getPosC(stringBounder);
if (first == null || pos.getCurrentValue() < first.getCurrentValue()) {
this.first = livingSpace.getPosB();
this.first = livingSpace.getPosB(stringBounder);
}
if (last == null || pos.getCurrentValue() > last.getCurrentValue()) {
this.last = livingSpace.getPosD(stringBounder);

View File

@ -56,17 +56,17 @@ public class SpriteColor implements Sprite {
private final int width;
private final int height;
private final int grey[][];
private final int gray[][];
private final int color[][];
public SpriteColor(int width, int height) {
this.width = width;
this.height = height;
this.grey = new int[height][width];
this.gray = new int[height][width];
this.color = new int[height][width];
}
public void setGrey(int x, int y, int level) {
public void setGray(int x, int y, int level) {
if (x < 0 || x >= width) {
return;
}
@ -76,7 +76,7 @@ public class SpriteColor implements Sprite {
if (level < 0 || level >= 16) {
throw new IllegalArgumentException();
}
grey[y][x] = level;
gray[y][x] = level;
color[y][x] = -1;
}
@ -87,7 +87,7 @@ public class SpriteColor implements Sprite {
if (y < 0 || y >= height) {
return;
}
grey[y][x] = -1;
gray[y][x] = -1;
color[y][x] = col;
}
@ -113,7 +113,7 @@ public class SpriteColor implements Sprite {
for (int line = 0; line < height; line++) {
final int localColor = color[line][col];
if (localColor == -1) {
final double coef = 1.0 * grey[line][col] / (16 - 1);
final double coef = 1.0 * gray[line][col] / (16 - 1);
final Color c = gradient.getColor(colorMapper, coef);
im.setRGB(col, line, c.getRGB());
} else {

View File

@ -55,7 +55,7 @@ public class SpriteColorBuilder {
final char charColor = strings.get(line).charAt(col);
final int idx = "0123456789ABCDEF".indexOf(charColor);
if (idx != -1) {
result.setGrey(col, line, idx);
result.setGray(col, line, idx);
} else {
final Color rgb = COLOR_PALETTE.getColorFor(charColor);
result.setColor(col, line, rgb.getRGB() & 0xFFFFFF);

View File

@ -166,8 +166,8 @@ public enum SpriteGrayLevel {
return 0;
}
final Color g = mono.getChangedColor(new Color(img.getRGB(x, y)));
final int grey = 255 - g.getRed();
return grey / 16;
final int gray = 255 - g.getRed();
return gray / 16;
}
public Sprite buildSprite(int width, int height, List<String> strings) {
@ -193,7 +193,7 @@ public enum SpriteGrayLevel {
if (strings.get(line).charAt(col) != '0') {
final String s = "" + strings.get(line).charAt(col);
final int x = Integer.parseInt(StringUtils.goUpperCase(s), 16);
result.setGrey(col, line, x);
result.setGray(col, line, x);
}
}
}
@ -210,8 +210,8 @@ public enum SpriteGrayLevel {
final int v = AsciiEncoder.decode6bit(strings.get(line).charAt(col));
final int w1 = v / 8;
final int w2 = v % 8;
result.setGrey(col, line * 2, w1);
result.setGrey(col, line * 2 + 1, w2);
result.setGray(col, line * 2, w1);
result.setGray(col, line * 2 + 1, w2);
}
}
@ -230,9 +230,9 @@ public enum SpriteGrayLevel {
v = v % 16;
final int w2 = v / 4;
final int w3 = v % 4;
result.setGrey(col, line * 3, w1);
result.setGrey(col, line * 3 + 1, w2);
result.setGrey(col, line * 3 + 2, w3);
result.setGray(col, line * 3, w1);
result.setGray(col, line * 3 + 1, w2);
result.setGray(col, line * 3 + 2, w3);
}
}
@ -290,7 +290,7 @@ public enum SpriteGrayLevel {
int cpt = 0;
for (int line = 0; line < result.getHeight(); line++) {
for (int col = 0; col < result.getWidth(); col++) {
result.setGrey(col, line, img.getByteAt(cpt++));
result.setGray(col, line, img.getByteAt(cpt++));
}
}

View File

@ -60,7 +60,7 @@ public class SpriteMonochrome implements Sprite {
private final int width;
private final int height;
private final int grayLevel;
private final int grey[][];
private final int gray[][];
public boolean isSameKind(SpriteMonochrome other) {
if (this.width != other.width) {
@ -81,7 +81,7 @@ public class SpriteMonochrome implements Sprite {
}
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (this.grey[j][i] != other.grey[j][i]) {
if (this.gray[j][i] != other.gray[j][i]) {
return false;
}
}
@ -102,7 +102,7 @@ public class SpriteMonochrome implements Sprite {
final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
result.grey[j][i] = this.grey[j][i] ^ other.grey[j][i];
result.gray[j][i] = this.gray[j][i] ^ other.gray[j][i];
}
}
return result;
@ -115,21 +115,21 @@ public class SpriteMonochrome implements Sprite {
this.width = width;
this.height = height;
this.grayLevel = grayLevel;
this.grey = new int[height][width];
this.gray = new int[height][width];
}
public SpriteMonochrome xSymetric() {
final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
result.setGrey(i, j, this.getGrey(i, j));
result.setGray(i, j, this.getGray(i, j));
}
}
for (int j = 0; j < height; j++) {
for (int i = 0; i < width / 2; i++) {
final int i2 = width - 1 - i;
final int level = result.getGrey(i, j) ^ result.getGrey(i2, j);
result.setGrey(i2, j, level);
final int level = result.getGray(i, j) ^ result.getGray(i2, j);
result.setGray(i2, j, level);
}
}
return result;
@ -139,20 +139,20 @@ public class SpriteMonochrome implements Sprite {
final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
result.setGrey(i, j, this.getGrey(i, j));
result.setGray(i, j, this.getGray(i, j));
}
}
for (int i = 0; i < width; i++) {
for (int j = 0; j < height / 2; j++) {
final int j2 = height - 1 - j;
final int level = result.getGrey(i, j) ^ result.getGrey(i, j2);
result.setGrey(i, j2, level);
final int level = result.getGray(i, j) ^ result.getGray(i, j2);
result.setGray(i, j2, level);
}
}
return result;
}
public void setGrey(int x, int y, int level) {
public void setGray(int x, int y, int level) {
if (x < 0 || x >= width) {
return;
}
@ -162,17 +162,17 @@ public class SpriteMonochrome implements Sprite {
if (level < 0 || level >= grayLevel) {
throw new IllegalArgumentException("level=" + level + " grayLevel=" + grayLevel);
}
grey[y][x] = level;
gray[y][x] = level;
}
public int getGrey(int x, int y) {
public int getGray(int x, int y) {
if (x >= width) {
throw new IllegalArgumentException("x=" + x + " width=" + width);
}
if (y >= height) {
throw new IllegalArgumentException("y=" + y + " height=" + height);
}
return grey[y][x];
return gray[y][x];
}
public int getHeight() {
@ -198,7 +198,7 @@ public class SpriteMonochrome implements Sprite {
final HColorGradient gradient = new HColorGradient(backcolor, color, '\0');
for (int col = 0; col < width; col++) {
for (int line = 0; line < height; line++) {
final double coef = 1.0 * grey[line][col] / (grayLevel - 1);
final double coef = 1.0 * gray[line][col] / (grayLevel - 1);
final Color c = gradient.getColor(colorMapper, coef);
im.setRGB(col, line, c.getRGB());
}
@ -213,7 +213,7 @@ public class SpriteMonochrome implements Sprite {
final HColor backColorLocal = new HColorSimple(backcolor.getColor(colorMapper, 1.0 * line / height),
false);
final HColorGradient gradient = new HColorGradient(backColorLocal, color, '\0');
final double coef = 1.0 * grey[line][col] / (grayLevel - 1);
final double coef = 1.0 * gray[line][col] / (grayLevel - 1);
final Color c = gradient.getColor(colorMapper, coef);
im.setRGB(col, line, c.getRGB());
}
@ -238,8 +238,8 @@ public class SpriteMonochrome implements Sprite {
public void exportSprite1(OutputStream fos) throws IOException {
for (int y = 0; y < this.getHeight(); y += 2) {
for (int x = 0; x < this.getWidth(); x += 1) {
int b1 = this.getGrey(x, y);
int b2 = y + 1 < this.getHeight() ? this.getGrey(x, y + 1) : b1;
int b1 = this.getGray(x, y);
int b2 = y + 1 < this.getHeight() ? this.getGray(x, y + 1) : b1;
fos.write(b1 * 16 + b2);
}
}

View File

@ -153,7 +153,7 @@ public class MinMax {
return new Dimension2DDouble(maxX - minX, maxY - minY);
}
public void drawGrey(UGraphic ug) {
public void drawGray(UGraphic ug) {
draw(ug, HColorUtils.GRAY);
}

View File

@ -129,8 +129,8 @@ public class PixelImage implements MutableImage {
// if (isTransparent(color)) {
// continue;
// }
final int grey = ColorUtils.getGrayScale(rgb);
if (darkerRgb == -1 || grey < ColorUtils.getGrayScale(darkerRgb)) {
final int gray = ColorUtils.getGrayScale(rgb);
if (darkerRgb == -1 || gray < ColorUtils.getGrayScale(darkerRgb)) {
darkerRgb = rgb;
}
}

View File

@ -40,11 +40,18 @@ import java.awt.Color;
public class ColorChangerMonochrome {
public Color getChangedColor(Color color) {
if (color == null) {
if (color == null)
return null;
}
final int grayScale = ColorUtils.getGrayScale(color);
return new Color(grayScale, grayScale, grayScale);
}
public Color getChangedColor(HColor color) {
if (color == null)
return null;
return getChangedColor(((HColorSimple) color).getColor999());
}
}

View File

@ -97,7 +97,7 @@ public class ColorUtils {
return new Color(red2, green2, blue2);
}
public static Color greyToColor(Color color, int grey) {
public static Color grayToColor(double coef, Color color) {
final int red = color.getRed();
final int green = color.getGreen();
final int blue = color.getBlue();
@ -108,7 +108,7 @@ public class ColorUtils {
final double s = hsluv[1];
double l = hsluv[2];
l = l + (100 - l) * (grey / 255.0);
l = l + (100 - l) * coef;
final double rgb[] = HUSLColorConverter.hsluvToRgb(new double[] { h, s, l });

View File

@ -122,12 +122,14 @@ public class HColorSimple extends HColorAbstract implements HColor {
return new HColorSimple(new ColorChangerMonochrome().getChangedColor(color), monochrome);
}
public HColor asMonochrome(HColorSimple colorForMonochrome) {
public HColor asMonochrome(HColorSimple colorForMonochrome, double minGray, double maxGray) {
final Color tmp = new ColorChangerMonochrome().getChangedColor(color);
final int grey = tmp.getGreen();
assert grey == tmp.getBlue();
assert grey == tmp.getRed();
Color result = ColorUtils.greyToColor(colorForMonochrome.color, grey);
final int gray = tmp.getGreen();
assert gray == tmp.getBlue();
assert gray == tmp.getRed();
final double coef = (gray - minGray) / 256.0;
final Color result = ColorUtils.grayToColor(coef, colorForMonochrome.color);
return new HColorSimple(result, monochrome);
}

View File

@ -80,7 +80,7 @@ public class Version {
}
public static int beta() {
final int beta = 9;
final int beta = 10;
return beta;
}