1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 10:59:01 +00:00

version 8050

This commit is contained in:
Arnaud Roques 2016-11-18 22:12:09 +01:00
parent 9f28832b09
commit c2f885ffb5
79 changed files with 2545 additions and 618 deletions

View File

@ -2,7 +2,7 @@
========================================================================
PlantUML : a free UML diagram generator
========================================================================
(C) Copyright 2009-2013, Arnaud Roques
(C) Copyright 2009-2017, Arnaud Roques
Project Info: http://plantuml.sourceforge.net
@ -51,6 +51,11 @@
<include name="*.png" />
</fileset>
</copy>
<copy todir="build/net/sourceforge/plantuml/math">
<fileset dir="src/net/sourceforge/plantuml/math">
<include name="*.js" />
</fileset>
</copy>
</target>
<target name="dist" depends="compile">
@ -60,7 +65,7 @@
<manifest>
<attribute name="Main-Class" value="net.sourceforge.plantuml.Run" />
<attribute name="SplashScreen-Image" value="net/sourceforge/plantuml/version/logo.png" />
<attribute name="Class-Path" value="batik-all-1.7.jar fop.jar vizjs.jar j2v8_win32_x86_64-3.1.6.jar j2v8_linux_x86_64-3.1.6.jar j2v8_macosx_x86_64-3.1.6.jar" />
<attribute name="Class-Path" value="batik-all-1.7.jar commons-io-1.3.1.jar commons-logging-1.1.1.jar jeuclid-core-3.1.9.jar xmlgraphics-commons-1.3.1.jar fop.jar vizjs.jar j2v8_win32_x86_64-3.1.6.jar j2v8_linux_x86_64-3.1.6.jar j2v8_macosx_x86_64-3.1.6.jar" />
</manifest>
</jar>
<delete dir="build" />

View File

@ -35,7 +35,7 @@
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>8050-SNAPSHOT</version>
<version>8051-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PlantUML</name>

View File

@ -30,8 +30,6 @@
*/
package net.sourceforge.plantuml;
import java.util.Properties;
import net.sourceforge.plantuml.command.BlocLines;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandExecutionResult;
@ -55,9 +53,8 @@ public abstract class AbstractPSystem implements Diagram {
toAppend.append(Version.versionString());
toAppend.append("(" + Version.compileTimeString() + ")\n");
toAppend.append("(" + License.getCurrent() + " source distribution)\n");
final Properties p = System.getProperties();
for (String name : OptionPrint.interestingProperties()) {
toAppend.append(p.getProperty(name));
toAppend.append(name);
toAppend.append('\n');
}
return toAppend.toString();

View File

@ -122,7 +122,8 @@ public enum FileFormat {
if (cpt == 0) {
return changeName(fileName, getFileSuffix());
}
return changeName(fileName, "_" + String.format("%03d", cpt) + getFileSuffix());
return changeName(fileName, OptionFlags.getInstance().getFileSeparator() + String.format("%03d", cpt)
+ getFileSuffix());
}
private String changeName(String fileName, String replacement) {
@ -145,6 +146,7 @@ public enum FileFormat {
if (i == 0) {
return name;
}
return name.replaceAll("\\" + getFileSuffix() + "$", "_" + String.format("%03d", i) + getFileSuffix());
return name.replaceAll("\\" + getFileSuffix() + "$",
OptionFlags.getInstance().getFileSeparator() + String.format("%03d", i) + getFileSuffix());
}
}

View File

@ -63,6 +63,7 @@ public class OptionFlags {
static public final boolean SWI2 = false;
// static public final boolean USE_COMPOUND = false;
static public final boolean OMEGA_CROSSING = false;
// static public final boolean LINK_BETWEEN_FIELDS = true;
// static public final boolean USE_JDOT = false;
@ -111,6 +112,7 @@ public class OptionFlags {
// private boolean failOnError;
private boolean encodesprite;
private boolean overwrite;
private String fileSeparator = "_";
private File logData;
private OptionFlags() {
@ -291,4 +293,12 @@ public class OptionFlags {
this.overwrite = overwrite;
}
public String getFileSeparator() {
return fileSeparator;
}
public void setFileSeparator(String fileSeparator) {
this.fileSeparator = fileSeparator;
}
}

View File

@ -31,6 +31,7 @@
package net.sourceforge.plantuml;
import java.io.File;
import java.net.InetAddress;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
@ -38,6 +39,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
@ -139,9 +141,8 @@ public class OptionPrint {
public static void printVersion() throws InterruptedException {
System.out.println("PlantUML version " + Version.versionString() + " (" + Version.compileTimeString() + ")");
System.out.println("(" + License.getCurrent() + " source distribution)");
final Properties p = System.getProperties();
for (String name : interestingProperties()) {
System.out.println(p.getProperty(name));
for (String v : interestingProperties()) {
System.out.println(v);
}
for (String v : interestingValues()) {
System.out.println(v);
@ -154,11 +155,20 @@ public class OptionPrint {
}
public static Collection<String> interestingProperties() {
return Arrays.asList("java.runtime.name", "java.vm.name", "java.runtime.version", "os.name", "file.encoding");
final Properties p = System.getProperties();
final List<String> all = Arrays.asList("java.runtime.name", "Java Runtime", "java.vm.name", "JVM",
"java.runtime.version", "Java Version", "os.name", "Operating System", "os.version", "OS Version",
"file.encoding", "Default Encoding", "user.language", "Language", "user.country", "Country");
final List<String> result = new ArrayList<String>();
for (int i = 0; i < all.size(); i += 2) {
result.add(all.get(i + 1) + ": " + p.getProperty(all.get(i)));
}
return result;
}
public static Collection<String> interestingValues() {
final List<String> strings = new ArrayList<String>();
strings.add("Machine: " + getHostName());
strings.add("PLANTUML_LIMIT_SIZE: " + GraphvizUtils.getenvImageLimit());
strings.add("Processors: " + Runtime.getRuntime().availableProcessors());
final long freeMemory = Runtime.getRuntime().freeMemory();
@ -174,6 +184,30 @@ public class OptionPrint {
return Collections.unmodifiableCollection(strings);
}
private static String hostname;
public static synchronized String getHostName() {
if (hostname == null) {
hostname = getHostNameSlow();
}
return hostname;
}
private static String getHostNameSlow() {
try {
final InetAddress addr = InetAddress.getLocalHost();
return addr.getHostName();
} catch (Throwable e) {
final Map<String, String> env = System.getenv();
if (env.containsKey("COMPUTERNAME")) {
return env.get("COMPUTERNAME");
} else if (env.containsKey("HOSTNAME")) {
return env.get("HOSTNAME");
}
}
return "Unknown Computer";
}
private static String format(final long value) {
return String.format(Locale.US, "%,d", value);
}

View File

@ -52,8 +52,8 @@ import net.sourceforge.plantuml.donors.PSystemDonorsFactory;
import net.sourceforge.plantuml.eggs.PSystemAppleTwoFactory;
import net.sourceforge.plantuml.eggs.PSystemCharlieFactory;
import net.sourceforge.plantuml.eggs.PSystemEggFactory;
import net.sourceforge.plantuml.eggs.PSystemEmptyFactory;
import net.sourceforge.plantuml.eggs.PSystemLostFactory;
import net.sourceforge.plantuml.eggs.PSystemMemorialFactory;
import net.sourceforge.plantuml.eggs.PSystemPathFactory;
import net.sourceforge.plantuml.eggs.PSystemRIPFactory;
import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory;
@ -61,6 +61,7 @@ import net.sourceforge.plantuml.font.PSystemListFontsFactory;
import net.sourceforge.plantuml.jcckit.PSystemJcckitFactory;
import net.sourceforge.plantuml.jungle.PSystemTreeFactory;
import net.sourceforge.plantuml.logo.PSystemLogoFactory;
import net.sourceforge.plantuml.math.PSystemMathFactory;
import net.sourceforge.plantuml.openiconic.PSystemListOpenIconicFactory;
import net.sourceforge.plantuml.openiconic.PSystemOpenIconicFactory;
import net.sourceforge.plantuml.oregon.PSystemOregonFactory;
@ -70,8 +71,9 @@ import net.sourceforge.plantuml.project2.PSystemProjectFactory2;
import net.sourceforge.plantuml.salt.PSystemSaltFactory;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
import net.sourceforge.plantuml.statediagram.StateDiagramFactory;
import net.sourceforge.plantuml.stats.PSystemStatsFactory;
import net.sourceforge.plantuml.stats.StatsUtils;
import net.sourceforge.plantuml.sudoku.PSystemSudokuFactory;
import net.sourceforge.plantuml.turing.PSystemTuringFactory;
import net.sourceforge.plantuml.ugraphic.sprite.PSystemListInternalSpritesFactory;
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.PSystemLicenseFactory;
@ -83,8 +85,10 @@ public class PSystemBuilder {
final public Diagram createPSystem(final List<CharSequence2> strings2) {
final long now = System.currentTimeMillis();
Diagram result = null;
try {
final List<PSystemFactory> factories = getAllFactories();
final DiagramType type = DiagramType.getTypeFromArobaseStart(strings2.get(0).toString2());
final UmlSource umlSource = new UmlSource(strings2, type == DiagramType.UML);
@ -96,21 +100,26 @@ public class PSystemBuilder {
}
final Diagram sys = systemFactory.createSystem(umlSource);
if (isOk(sys)) {
result = sys;
return sys;
}
errors.add((PSystemError) sys);
}
final PSystemError err = PSystemError.merge(errors);
// if (OptionFlags.getInstance().isQuiet() == false) {
// err.print(System.err);
// }
result = err;
return err;
} finally {
if (result != null) {
StatsUtils.onceMoreParse(System.currentTimeMillis() - now, result.getClass());
}
}
}
private List<PSystemFactory> getAllFactories() {
final List<PSystemFactory> factories = new ArrayList<PSystemFactory>();
factories.add(new PSystemEmptyFactory());
factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory());
factories.add(new ActivityDiagramFactory());
@ -139,8 +148,9 @@ public class PSystemBuilder {
factories.add(new PSystemJcckitFactory(DiagramType.UML));
factories.add(new PSystemLogoFactory());
factories.add(new PSystemSudokuFactory());
factories.add(new PSystemTuringFactory());
}
factories.add(new PSystemMathFactory(DiagramType.MATH));
factories.add(new PSystemStatsFactory());
factories.add(new PSystemCreoleFactory());
factories.add(new PSystemEggFactory());
factories.add(new PSystemAppleTwoFactory());
@ -149,7 +159,6 @@ public class PSystemBuilder {
factories.add(new PSystemPathFactory());
factories.add(new PSystemOregonFactory());
factories.add(new PSystemCharlieFactory());
factories.add(new PSystemMemorialFactory());
if (License.getCurrent() == License.GPL || License.getCurrent() == License.GPLV2) {
factories.add(new PSystemXearthFactory());
}

View File

@ -45,6 +45,7 @@ import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
@ -108,7 +109,7 @@ public class PSystemError extends AbstractPSystem {
}
final boolean useRed = fileFormat.isUseRedForError();
final GraphicStrings result = GraphicStrings.createDefault(getHtmlStrings(useRed), useRed);
final TextBlockBackcolored result = GraphicStrings.createForError(getHtmlStrings(useRed), useRed);
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);

View File

@ -47,15 +47,14 @@ import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.html.CucaDiagramHtmlMaker;
import net.sourceforge.plantuml.png.PngSplitter;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
import net.sourceforge.plantuml.stats.StatsUtils;
public class PSystemUtils {
public static List<File> exportDiagrams(Diagram system, File suggestedFile, FileFormatOption fileFormatOption)
throws IOException {
// if (system instanceof UmlDiagram) {
// final ISkinParam skinParam = ((UmlDiagram) system).getSkinParam();
// fileFormatOption = fileFormatOption.withSvgLinkTarget(skinParam.getSvgLinkTarget());
// }
final long now = System.currentTimeMillis();
try {
if (system instanceof NewpagedDiagram) {
return exportDiagramsNewpaged((NewpagedDiagram) system, suggestedFile, fileFormatOption);
}
@ -69,6 +68,9 @@ public class PSystemUtils {
return exportDiagramsActivityDiagram3((ActivityDiagram3) system, suggestedFile, fileFormatOption);
}
return exportDiagramsDefault(system, suggestedFile, fileFormatOption);
} finally {
StatsUtils.onceMoreGenerate(System.currentTimeMillis() - now, system.getClass(), fileFormatOption.getFileFormat());
}
}
private static List<File> exportDiagramsNewpaged(NewpagedDiagram system, File suggestedFile,

View File

@ -46,6 +46,7 @@ import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
@ -150,7 +151,7 @@ public class SourceStringReader {
}
private void noStartumlFound(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
final GraphicStrings error = GraphicStrings.createDefault(Arrays.asList("No @startuml found"),
final TextBlockBackcolored error = GraphicStrings.createForError(Arrays.asList("No @startuml found"),
fileFormatOption.isUseRedForError());
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, error.getBackcolor(), null,
null, 0, 0, null, false);

View File

@ -34,7 +34,6 @@ import java.awt.Color;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.HtmlColorSimple;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
public class SplitParam {

View File

@ -70,9 +70,9 @@ import net.sourceforge.plantuml.mjpeg.MJPEGGenerator;
import net.sourceforge.plantuml.pdf.PdfConverter;
import net.sourceforge.plantuml.svek.EmptySvgException;
import net.sourceforge.plantuml.svek.GraphvizCrash;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImage;
@ -244,7 +244,12 @@ public abstract class UmlDiagram extends AbstractPSystem implements Diagram, Ann
public static void exportDiagramError(OutputStream os, Throwable exception, FileFormatOption fileFormat,
String metadata, String flash, List<String> strings) throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
if (fileFormat.getFileFormat() == FileFormat.ATXT || fileFormat.getFileFormat() == FileFormat.UTXT) {
exportDiagramErrorText(os, exception, strings);
return;
}
strings.addAll(CommandExecutionResult.getStackTrace(exception));
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, HtmlColorUtils.WHITE,
@ -256,8 +261,7 @@ public abstract class UmlDiagram extends AbstractPSystem implements Diagram, Ann
GraphvizCrash.addDecodeHint(strings);
}
final GraphicStrings graphicStrings = new GraphicStrings(strings, font, HtmlColorUtils.BLACK,
HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON, IconLoader.getRandom(),
final TextBlockBackcolored graphicStrings = GraphicStrings.createBlackOnWhite(strings, IconLoader.getRandom(),
GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
if (im == null) {
@ -275,6 +279,18 @@ public abstract class UmlDiagram extends AbstractPSystem implements Diagram, Ann
imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private static void exportDiagramErrorText(OutputStream os, Throwable exception, List<String> strings) {
final PrintWriter pw = new PrintWriter(os);
exception.printStackTrace(pw);
pw.println();
pw.println();
for (String s : strings) {
s = s.replaceAll("\\</?\\w+?\\>", "");
pw.println(s);
}
pw.flush();
}
public String getFlashData() {
final UmlSource source = getSource();
if (source == null) {

View File

@ -142,7 +142,7 @@ public class UrlBuilder {
final Pattern2 p = MyPattern.cmpile("[%s]*" + URL_PATTERN + "[%s]*");
final Matcher2 m = p.matcher(label);
if (m.find() == false) {
throw new IllegalStateException();
return label;
}
final String url = m.group(0);
final int x = label.indexOf(url);

View File

@ -59,7 +59,8 @@ public class InstructionList extends WithNote implements Instruction, Instructio
}
public boolean isOnlySingleStop() {
return all.size() == 1 && getLast() instanceof InstructionStop;
return all.size() == 1 && getLast() instanceof InstructionStop
&& ((InstructionStop) getLast()).hasNotes() == false;
}
public InstructionList(Swimlane defaultSwimlane) {
@ -126,16 +127,26 @@ public class InstructionList extends WithNote implements Instruction, Instructio
}
public Swimlane getSwimlaneIn() {
if (getSwimlanes().size() == 0) {
return null;
}
return all.get(0).getSwimlaneIn();
return defaultSwimlane;
// final Set<Swimlane> swimlanes = getSwimlanes();
// if (swimlanes.size() == 0) {
// return null;
// }
// if (swimlanes.size() == 1) {
// return swimlanes.iterator().next();
// }
// System.err.println("foo1="+getClass());
// return all.get(0).getSwimlaneIn();
}
public Swimlane getSwimlaneOut() {
if (getSwimlanes().size() == 0) {
final Set<Swimlane> swimlanes = getSwimlanes();
if (swimlanes.size() == 0) {
return null;
}
if (swimlanes.size() == 1) {
return swimlanes.iterator().next();
}
return getLast().getSwimlaneOut();
}

View File

@ -62,4 +62,8 @@ public class WithNote {
return Collections.unmodifiableCollection(notes);
}
public boolean hasNotes() {
return notes.size() > 0;
}
}

View File

@ -259,7 +259,7 @@ class FtileRepeat extends AbstractFtile {
}
public void drawU(UGraphic ug) {
throw new UnsupportedOperationException();
// throw new UnsupportedOperationException();
}
public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) {

View File

@ -38,7 +38,6 @@ import java.util.List;
import java.util.Set;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.activitydiagram3.LinkRendering;
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection;
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile;

View File

@ -370,4 +370,8 @@ public class PlantUmlTask extends Task {
OptionFlags.getInstance().setOverwrite(flag);
}
public void setFileSeparator(String s) {
OptionFlags.getInstance().setFileSeparator(s);
}
}

View File

@ -25,14 +25,14 @@ package net.sourceforge.plantuml.api;
public interface INumberAnalyzed {
public int getNb();
public long getNb();
public int getSum();
public long getSum();
public int getMin();
public long getMin();
public int getMax();
public long getMax();
public int getMean();
public long getMean();
}

View File

@ -23,18 +23,61 @@
*/
package net.sourceforge.plantuml.api;
import java.util.prefs.Preferences;
public class NumberAnalyzed implements INumberAnalyzed {
private int nb;
private int sum;
private int min;
private int max;
public NumberAnalyzed() {
private long nb;
private long sum;
private long min;
private long max;
private final String name;
public NumberAnalyzed(String name) {
this.name = name;
}
private NumberAnalyzed(int nb, int sum, int min, int max) {
public NumberAnalyzed() {
this("");
}
public void save(Preferences prefs) {
if (name.length() == 0) {
throw new UnsupportedOperationException();
}
prefs.putLong(name + ".nb", nb);
prefs.putLong(name + ".sum", sum);
prefs.putLong(name + ".min", min);
prefs.putLong(name + ".max", max);
}
public static NumberAnalyzed load(String name, Preferences prefs) {
final long nb = prefs.getLong(name + ".nb", 0);
if (nb == 0) {
return null;
}
final long sum = prefs.getLong(name + ".sum", 0);
if (sum == 0) {
return null;
}
final long min = prefs.getLong(name + ".min", 0);
if (min == 0) {
return null;
}
final long max = prefs.getLong(name + ".max", 0);
if (max == 0) {
return null;
}
return new NumberAnalyzed(name, nb, sum, min, max);
}
@Override
public synchronized String toString() {
return "sum=" + sum + " nb=" + nb + " min=" + min + " max=" + max + " mean=" + getMean();
}
private NumberAnalyzed(String name, long nb, long sum, long min, long max) {
this(name);
this.nb = nb;
this.sum = sum;
this.min = min;
@ -42,11 +85,11 @@ public class NumberAnalyzed implements INumberAnalyzed {
}
public synchronized INumberAnalyzed getCopyImmutable() {
final NumberAnalyzed copy = new NumberAnalyzed(nb, sum, min, max);
final NumberAnalyzed copy = new NumberAnalyzed(name, nb, sum, min, max);
return copy;
}
public synchronized void addValue(int v) {
public synchronized void addValue(long v) {
nb++;
if (nb == 1) {
sum = v;
@ -63,27 +106,40 @@ public class NumberAnalyzed implements INumberAnalyzed {
}
}
synchronized public final int getNb() {
public synchronized void add(NumberAnalyzed other) {
synchronized (other) {
this.sum += other.sum;
this.nb += other.nb;
this.min = Math.min(this.min, other.min);
this.max = Math.max(this.max, other.max);
}
}
synchronized public final long getNb() {
return nb;
}
synchronized public final int getSum() {
synchronized public final long getSum() {
return sum;
}
synchronized public final int getMin() {
synchronized public final long getMin() {
return min;
}
synchronized public final int getMax() {
synchronized public final long getMax() {
return max;
}
synchronized public final int getMean() {
synchronized public final long getMean() {
if (nb == 0) {
return 0;
}
return sum / nb;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,73 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.asciiart;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextDelay extends AbstractComponentText {
private final Display stringsToDisplay;
public ComponentTextDelay(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) {
this.stringsToDisplay = stringsToDisplay;
}
public void drawU(UGraphic ug, Area area, Context2D context) {
final Dimension2D dimensionToUse = area.getDimensionToUse();
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int textWidth = StringUtils.getWidth(stringsToDisplay);
final int textPos = (width - textWidth) / 2;
final String desc = stringsToDisplay.get(0).toString();
charArea.drawStringLR(desc, textPos, 0);
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 1;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -35,16 +35,25 @@ import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextLine extends AbstractComponentText {
private final FileFormat fileFormat;
private static final int MAGIC_NUMBER = -3;
private char using;
public ComponentTextLine(FileFormat fileFormat) {
this.fileFormat = fileFormat;
public ComponentTextLine(ComponentType type, FileFormat fileFormat) {
if (fileFormat == FileFormat.UTXT) {
using = '\u2502';
} else {
using = '|';
}
if (type == ComponentType.DELAY_LINE) {
using = '.';
}
}
public void drawU(UGraphic ug, Area area, Context2D context) {
@ -52,11 +61,12 @@ public class ComponentTextLine extends AbstractComponentText {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
if (fileFormat == FileFormat.UTXT) {
charArea.drawVLine('\u2502', (width - 1) / 2, 0, height - 1);
} else {
charArea.drawVLine('|', (width - 1) / 2, 0, height - 1);
}
charArea.drawVLine(using, (width - 1) / 2, MAGIC_NUMBER, height);
// if (using == '.') {
// charArea.drawVLine(using, (width - 1) / 2, -3, height);
// } else {
// charArea.drawVLine(using, (width - 1) / 2, 0, height);
// }
}
public double getPreferredHeight(StringBounder stringBounder) {

View File

@ -66,13 +66,13 @@ public class TextSkin implements Skin {
return new ComponentTextSelfArrow(type, config, stringsToDisplay, fileFormat);
}
if (type == ComponentType.PARTICIPANT_LINE) {
return new ComponentTextLine(fileFormat);
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.CONTINUE_LINE) {
return new ComponentTextLine(fileFormat);
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.DELAY_LINE) {
return new ComponentTextLine(fileFormat);
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) {
return new ComponentTextActiveLine(fileFormat);
@ -104,6 +104,9 @@ public class TextSkin implements Skin {
if (type == ComponentType.NEWPAGE) {
return new ComponentTextNewpage(fileFormat);
}
if (type == ComponentType.DELAY_TEXT) {
return new ComponentTextDelay(type, stringsToDisplay, fileFormat);
}
throw new UnsupportedOperationException(type.toString());
}

View File

@ -45,7 +45,6 @@ import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
import net.sourceforge.plantuml.cucadiagram.LeafType;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.command;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

View File

@ -33,7 +33,7 @@ package net.sourceforge.plantuml.core;
import net.sourceforge.plantuml.utils.StartUtils;
public enum DiagramType {
UML, DITAA, DOT, PROJECT, JCCKIT, SALT, TURING, FLOW, CREOLE, JUNGLE, CUTE, UNKNOWN;
UML, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, UNKNOWN;
static public DiagramType getTypeFromArobaseStart(String s) {
s = s.toLowerCase();
@ -58,9 +58,6 @@ public enum DiagramType {
if (StartUtils.startsWithSymbolAnd("startsalt", s)) {
return SALT;
}
if (StartUtils.startsWithSymbolAnd("startturing", s)) {
return TURING;
}
if (StartUtils.startsWithSymbolAnd("startflow", s)) {
return FLOW;
}
@ -73,6 +70,9 @@ public enum DiagramType {
if (StartUtils.startsWithSymbolAnd("startcute", s)) {
return CUTE;
}
if (StartUtils.startsWithSymbolAnd("startmath", s)) {
return MATH;
}
return UNKNOWN;
}
}

View File

@ -30,12 +30,7 @@
*/
package net.sourceforge.plantuml.cucadiagram;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.VerticalAlignment;
public class DisplayPositionned {

View File

@ -193,6 +193,7 @@ public class MemberImpl implements Member {
}
public static boolean isMethod(String s) {
s = UrlBuilder.purgeUrl(s);
if (s.contains("{method}")) {
return true;
}

View File

@ -49,6 +49,7 @@ import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockLineBefore;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.TextBlockWidth;
import net.sourceforge.plantuml.graphic.TextBlockWithUrl;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.svek.Ports;
@ -184,7 +185,7 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlockW
}
private TextBlock getUBlock(final VisibilityModifier modifier) {
private TextBlock getUBlock(final VisibilityModifier modifier, Url url) {
if (modifier == null) {
return new AbstractTextBlock() {
@ -200,8 +201,8 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlockW
modifier.getBackground());
final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground());
final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back);
return uBlock;
final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back, url != null);
return TextBlockWithUrl.withUrl(uBlock, url);
}
public TextBlock asTextBlock(final double widthToUse) {
@ -232,7 +233,7 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlockW
for (Member att : members) {
final TextBlock bloc = createTextBlock(att);
final VisibilityModifier modifier = att.getVisibilityModifier();
group.add(getUBlock(modifier));
group.add(getUBlock(modifier, att.getUrl()));
group.add(bloc);
}
} else {

View File

@ -51,8 +51,8 @@ public class Dedication {
this.name = name;
}
private final BigInteger E = new BigInteger("47");
private final BigInteger N = new BigInteger(
static public final BigInteger E = new BigInteger("47");
static public final BigInteger N = new BigInteger(
"64194259632025692228025828504368542164501926620236990850309916606915924860847417702229807236946186163298479808527077315212362810246237044147835839820235668271044023359607622658694578433933680627840319408427732468918341837133798296090069295727323673222224923200718714534955390633175683720810506099934813509605263799234445827953809462431871169282281822048299576307847441008670575692934434087522877910989584374673170522742162366773143807761599862833698229067475807108264396251702152180676841544743258182370105404479387062985271422237607462447989728490398294623785717593446941673706569352249533885603771123718557406286501161336667835919957553680522213067630956498293529840163155604109185561515875171125161872265975088797712442352939352686113608345330266855433849127812528823634773975825170679786399199082599910532761710473383280738663105826045325480095451410448217715495894688594898541182351588505292424154550388343455540760277051977859647543838445735549451966254020972172982014944475678385523833120793348365125754234511467512831686599126674298367512469557219326026525667529348508876650236597163509336304607610284488623800062157659286940214435134423619711736992281071131245654755167288438258292694799131521268600284444731890784171372171309");
public InputStream getInputStream(String keepLetter) throws IOException {

View File

@ -63,6 +63,10 @@ public class QBlock {
return new QBlock(changed);
}
public byte[] getData() {
return big.toByteArray();
}
@Override
public String toString() {
return big.toByteArray().length + " " + big.toString();

View File

@ -37,6 +37,8 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.code.AsciiEncoder;
public class QBlocks {
private final List<QBlock> all = new ArrayList<QBlock>();
@ -70,4 +72,24 @@ public class QBlocks {
}
}
public String encodeAscii() {
final StringBuilder sb = new StringBuilder();
final AsciiEncoder encoder = new AsciiEncoder();
for (QBlock rsa : all) {
sb.append(encoder.encode(rsa.getData()));
sb.append("!");
}
return sb.toString();
}
public static QBlocks descodeAscii(String s) {
final QBlocks result = new QBlocks();
final AsciiEncoder encoder = new AsciiEncoder();
for (String bl : s.split("!")) {
final BigInteger bigInteger = new BigInteger(encoder.decode(bl));
result.all.add(new QBlock(bigInteger));
}
return result;
}
}

View File

@ -67,7 +67,7 @@ public class PSystemDot extends AbstractPSystem {
final Graphviz graphviz = GraphvizUtils.create(null, data,
StringUtils.goLowerCase(fileFormat.getFileFormat().name()));
if (graphviz.getExeState() != ExeState.OK) {
final TextBlock result = GraphicStrings.createDefault(
final TextBlock result = GraphicStrings.createForError(
Arrays.asList("There is an issue with your Dot/Graphviz installation"), false);
UGraphicUtils.writeImage(os, null, fileFormat, new ColorMapperIdentity(), HtmlColorUtils.WHITE, result);
return new ImageDataSimple();
@ -78,7 +78,7 @@ public class PSystemDot extends AbstractPSystem {
throw new IllegalStateException("Timeout1 " + state);
}
if (counter.getLength() == 0) {
final TextBlock result = GraphicStrings.createDefault(Arrays.asList("Graphivz has crashed"), false);
final TextBlock result = GraphicStrings.createForError(Arrays.asList("Graphivz has crashed"), false);
UGraphicUtils.writeImage(os, null, fileFormat, new ColorMapperIdentity(), HtmlColorUtils.WHITE, result);
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.donors;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -46,11 +45,9 @@ import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.version.PSystemVersion;
public class PSystemDonors extends AbstractPSystem {
@ -58,14 +55,14 @@ public class PSystemDonors extends AbstractPSystem {
public static final String DONORS = "UDfTKqjosp0CtUCKN6lIGoXsxDQ_PAmqdSaEbX29DaMe9ELKFbjtlLYXj3BfS2MC0F3zc9li_o47JnJ8gTm6jXfBUAOi7cvXmx5q7l9f50-mTF4N3L3G0NtGQDME6mkvhTYf9LEuqFZvzYOTKpjQs61oaGqmrrEX3UHnDP-Xw2E40POwkpsMOJMXx3qKWRg6h9enTy9lFjr37jRjfr5sC6EZhTfpxmbM_QV_sP65o5Hq6hO9QcpJKgxA3Vr2MucSiqRBrXhT84ptLzgsXbsAFbpWqUYp3CnrUHBarp_QmeE_hhO9Y8pECB-qEhX1RR3X2c4rYlxQeAnF-Z8oqIuvfq5aiXYaJ_09hjK_y7IwOMKhALqfcYpmu8OJl_kJbaL6nXvTq1Vu6hihXgqk6pBg7hKPKWRcaeBn7bQ4ziiAovyzUJNl3mx5InFvll0nKDcejKEF4L9D4j74iVSnMTAYrdpMQL0-el8z4jO8-oIyunKfp-meqrqIApwDojopGukckrEl590x3tiXYAvIQprQ2ml3RjHx--UtCH-cnq2O99mIfyqrJWudjKVNcrj6Fad8QDeJJc7PwnlukT6gGApa8RcQr0-oDRaxjSsVlnLv37h65fPqyu1I7MmfWMdLYt2OIuJNiTFHwBCydGqHF9pJTt16sCKbr4uWiuJKijUIahubjU2UGbIxzB18VVhW4hDXBwc80dUdQqbKeLlu2u2IDTa0";
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
private TextBlockBackcolored getGraphicStrings() throws IOException {
final List<String> lines = new ArrayList<String>();
lines.add("<b>Special thanks to our sponsors and donors !");
lines.add(" ");
@ -82,12 +79,8 @@ public class PSystemDonors extends AbstractPSystem {
}
}
lines.add(" ");
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final GraphicStrings graphicStrings = new GraphicStrings(lines, font, HtmlColorUtils.BLACK,
HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON, PSystemVersion.getPlantumlImage(),
GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
graphicStrings.setMaxLine(maxLine + 2);
return graphicStrings;
return GraphicStrings.createBlackOnWhite(lines, PSystemVersion.getPlantumlImage(),
GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT, maxLine + 2);
}
private List<String> getDonors() throws IOException {

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.eggs;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -48,11 +47,9 @@ import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemAppleTwo extends AbstractPSystem {
@ -60,7 +57,7 @@ public class PSystemAppleTwo extends AbstractPSystem {
private final BufferedImage image;
public PSystemAppleTwo() throws IOException {
strings.add(" <b><size:16>Apple //e for ever!");
strings.add(" <b><size:18>Apple //e for ever ! ");
strings.add(" ");
final InputStream is = new ByteArrayInputStream(imm);
@ -69,18 +66,19 @@ public class PSystemAppleTwo extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final GraphicStrings result = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
UAntiAliasing.ANTI_ALIASING_ON, image, GraphicPosition.BOTTOM);
result.setMinWidth(200);
private TextBlockBackcolored getGraphicStrings() throws IOException {
// final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final TextBlockBackcolored result = GraphicStrings.createBlackOnWhite(strings, image, GraphicPosition.BOTTOM);
// final GraphicStrings result = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
// image, GraphicPosition.BOTTOM);
// result.setMinWidth(200);
return result;
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.eggs;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -43,11 +42,9 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemEgg extends AbstractPSystem {
@ -61,16 +58,15 @@ public class PSystemEgg extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {

View File

@ -0,0 +1,94 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.eggs;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.version.PSystemVersion;
public class PSystemEmpty extends AbstractPSystem {
private final List<String> strings = new ArrayList<String>();
public PSystemEmpty() {
strings.add("<b>Welcome to PlantUML!");
strings.add(" ");
strings.add("If you use this software, you accept its license.");
strings.add("(details by typing \"\"license\"\" keyword)");
strings.add(" ");
strings.add("You can start with a simple UML Diagram like:");
strings.add(" ");
strings.add("\"\"Bob->Alice: Hello\"\"");
strings.add(" ");
strings.add("Or");
strings.add(" ");
strings.add("\"\"class Example\"\"");
strings.add(" ");
strings.add("You will find more information about PlantUML syntax on <u>http://plantuml.com</u>");
strings.add(" ");
strings.add(" ");
strings.add(" ");
strings.add(" ");
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
// imageBuilder.setUDrawable(TextBlockUtils.withMargin(result, 4, 4));
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private TextBlockBackcolored getGraphicStrings() throws IOException {
final TextBlockBackcolored result = GraphicStrings.createBlackOnWhite(strings, PSystemVersion.getPlantumlImage(),
GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
return result;
}
public DiagramDescription getDescription() {
return new DiagramDescriptionImpl("(Empty)", getClass());
}
}

View File

@ -0,0 +1,51 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.eggs;
import net.sourceforge.plantuml.api.PSystemFactory;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
public class PSystemEmptyFactory implements PSystemFactory {
public Diagram createSystem(UmlSource source) {
if (source.getTotalLineCount() == 2) {
return new PSystemEmpty();
}
return null;
}
public DiagramType getDiagramType() {
return DiagramType.UML;
}
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.eggs;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -42,11 +41,9 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemLost extends AbstractPSystem {
@ -57,17 +54,15 @@ public class PSystemLost extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON, null,
null);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {

View File

@ -1,102 +0,0 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.eggs;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.DateEventUtils;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.webp.Portrait;
public class PSystemMemorial extends AbstractPSystem {
public static final String PARIS = "A thought for those who died in Paris the 13th November 2015.";
private Portrait portrait;
PSystemMemorial(Portrait portrait) {
this.portrait = portrait;
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, HtmlColorUtils.WHITE,
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(new UDrawable() {
public void drawU(UGraphic ug) {
final String name = portrait.getName();
final String quote = portrait.getQuote();
final String age = "" + portrait.getAge() + " years old";
final UFont font = new UFont("SansSerif", Font.BOLD, 14);
final BufferedImage im = portrait.getBufferedImage();
final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK,
true);
final TextBlock top = DateEventUtils.getComment(Arrays.asList(PARIS), HtmlColorUtils.BLACK);
final TextBlock tb = Display.create(name, age, quote).create(fc, HorizontalAlignment.LEFT,
new SpriteContainerEmpty());
top.drawU(ug);
ug = ug.apply(new UTranslate(0, top.calculateDimension(ug.getStringBounder()).getHeight() + 10));
ug.draw(new UImage(im));
ug = ug.apply(new UTranslate(im.getWidth() + 10, 0));
tb.drawU(ug);
}
});
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
public DiagramDescription getDescription() {
return new DiagramDescriptionImpl("(Memorial)", getClass());
}
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.eggs;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -48,11 +47,9 @@ import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemRIP extends AbstractPSystem {
@ -76,20 +73,16 @@ public class PSystemRIP extends AbstractPSystem {
is.close();
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON,
image, GraphicPosition.BOTTOM);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings, image, GraphicPosition.BOTTOM);
}
public DiagramDescription getDescription() {
@ -462,5 +455,4 @@ public class PSystemRIP extends AbstractPSystem {
};
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.font;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.io.OutputStream;
@ -43,11 +42,9 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemListFonts extends AbstractPSystem {
@ -69,18 +66,15 @@ public class PSystemListFonts extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final GraphicStrings result = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
UAntiAliasing.ANTI_ALIASING_ON);
return result;
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {

View File

@ -39,7 +39,7 @@ import javax.imageio.ImageIO;
public class IconLoader {
private static final int NUMBER_OF_ICONS = 20;
private static final int NUMBER_OF_ICONS = 21;
private final static Map<String, BufferedImage> all = new ConcurrentHashMap<String, BufferedImage>();

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

View File

@ -30,152 +30,131 @@
*/
package net.sourceforge.plantuml.graphic;
import java.awt.Font;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.eggs.PSystemMemorial;
import net.sourceforge.plantuml.ugraphic.LimitFinder;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.version.PSystemVersion;
import net.sourceforge.plantuml.webp.Portrait;
import net.sourceforge.plantuml.webp.Portraits;
public class DateEventUtils {
public static TextBlock addEvent(final TextBlock textBlock, final HtmlColor color) {
try {
final String today = new SimpleDateFormat("MM-dd", Locale.US).format(new Date());
if ("11-05".equals(today)) {
final List<String> asList = Arrays.asList("<u>November 5th, 1955",
"Doc Brown's discovery of the Flux Capacitor, that makes time-travel possible.");
return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
} else if ("08-29".equals(today)) {
final List<String> asList = Arrays.asList("<u>August 29th, 1997",
"Skynet becomes self-aware at 02:14 AM Eastern Time.");
return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
} else if ("06-29".equals(today)) {
final List<String> asList = Arrays.asList("<u>June 29th, 1975",
"\"It was the first time in history that anyone had typed",
"a character on a keyboard and seen it show up on their",
"own computer's screen right in front of them.\"", "\t\t\t\t\t\t\t\t\t\t<i>Steve Wozniak");
return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
} else if ("01-07".equals(today) || ("01-08".equals(today) && getDayOfWeek() == Calendar.MONDAY)) {
return addCharlie(textBlock);
} else if ("11-13".equals(today) || ("11-14".equals(today) && getDayOfWeek() == Calendar.MONDAY)) {
return addMemorial(textBlock, color);
}
} catch (Throwable t) {
Log.debug("Error " + t);
}
return textBlock;
}
private synchronized static int getDayOfWeek() {
return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
}
private static TextBlock addMemorial(TextBlock textBlock, HtmlColor color) {
final Portrait portrait = Portraits.getOne();
if (portrait == null) {
return textBlock;
}
final BufferedImage im = portrait.getBufferedImage();
if (im == null) {
return textBlock;
}
final String name = portrait.getName();
final String quote = portrait.getQuote();
final String age = "" + portrait.getAge() + " years old";
final UFont font12 = new UFont("SansSerif", Font.BOLD, 12);
TextBlock comment = Display.create(name, age, quote).create(
new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
new SpriteContainerEmpty());
comment = TextBlockUtils.withMinWidth(TextBlockUtils.withMargin(comment, 4, 4), 800, HorizontalAlignment.LEFT);
final TextBlock bottom0 = getComment(Arrays.asList(PSystemMemorial.PARIS), color);
final TextBlock bottom1 = new AbstractTextBlock() {
private double margin = 10;
public void drawU(UGraphic ug) {
ug = ug.apply(new UTranslate(0, margin));
ug.draw(new UImage(im));
if (ug instanceof LimitFinder) {
return;
}
Portraits.nextOne();
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(im.getWidth(), margin + im.getHeight());
}
};
final TextBlock bottom = TextBlockUtils.mergeTB(bottom0,
TextBlockUtils.mergeLR(bottom1, comment, VerticalAlignment.CENTER), HorizontalAlignment.LEFT);
final TextBlock mergeTB = TextBlockUtils.mergeTB(textBlock, bottom, HorizontalAlignment.LEFT);
return addMajesty(mergeTB, color);
}
public static TextBlock addMajesty(TextBlock block, HtmlColor color) {
final UFont font12 = new UFont("SansSerif", Font.BOLD, 12);
final String arabic1 = "<size:16>\u0625\u0646 \u0627\u0644\u0625\u0631\u0647\u0627\u0628\u064A\u064A\u0646 \u0628\u0627\u0633\u0645 \u0627\u0644\u0625\u0633\u0644\u0627\u0645 \u0644\u064A\u0633\u0648\u0627 \u0645\u0633\u0644\u0645\u064A\u0646\u060C \u0648\u0644\u0627 \u064A\u0631\u0628\u0637\u0647\u0645 \u0628\u0627\u0644\u0625\u0633\u0644\u0627\u0645 \u0625\u0644\u0627 \u0627\u0644\u062F\u0648\u0627\u0641\u0639 \u0627\u0644\u062A\u064A \u064A\u0631\u0643\u0628\u0648\u0646 \u0639\u0644\u064A\u0647\u0627 \u0644\u062A\u0628\u0631\u064A\u0631 \u062C\u0631\u0627\u0626\u0645\u0647\u0645 \u0648\u062D\u0645\u0627\u0642\u0627\u062A\u0647\u0645.";
final String arabic2 = "<size:16>\u0641\u0647\u0645 \u0642\u0648\u0645 \u0636\u0627\u0644\u0648\u0646\u060C \u0645\u0635\u064A\u0631\u0647\u0645 \u062C\u0647\u0646\u0645 \u062E\u0627\u0644\u062F\u064A\u0646 \u0641\u064A\u0647\u0627 \u0623\u0628\u062F\u0627.";
final String english1 = "<size:10>Those who engage in terrorism, in the name of Islam, are not Muslims.";
final String english2 = "<size:10>Their only link to Islam is the pretexts they use to justify their crimes and their folly.";
final String english3 = "<size:10>They have strayed from the right path, and their fate is to dwell forever in hell.";
final TextBlock arabic = Display
.create(" ",
arabic1,
arabic2,
"<size:16>\u0635\u0627\u062D\u0628 \u0627\u0644\u062C\u0644\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0643 \u0645\u062D\u0645\u062F \u0627\u0644\u0633\u0627\u062F\u0633 \u0623\u0645\u064A\u0631 \u0627\u0644\u0645\u0624\u0645\u0646\u064A\u0646 \u0646\u0635\u0631\u0647 \u0627\u0644\u0644\u0647")
.create(new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.RIGHT,
new SpriteContainerEmpty());
final TextBlock english = Display.create(english1, english2, english3,
"<size:10>-- His Majesty the King Mohammed the Sixth, Commander of the Faithful").create(
new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
new SpriteContainerEmpty());
return TextBlockUtils.mergeTB(block, TextBlockUtils.mergeTB(arabic, english, HorizontalAlignment.LEFT),
HorizontalAlignment.LEFT);
}
private static TextBlock addCharlie(TextBlock textBlock) {
final TextBlock charlie = new AbstractTextBlock() {
private final BufferedImage charlie = PSystemVersion.getCharlieImage();
public void drawU(UGraphic ug) {
ug.draw(new UImage(charlie));
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(charlie.getWidth(), charlie.getHeight());
}
};
return TextBlockUtils.mergeTB(charlie, textBlock, HorizontalAlignment.LEFT);
}
public static TextBlock getComment(final List<String> asList, HtmlColor color) {
final UFont font = new UFont("SansSerif", Font.BOLD, 14);
TextBlock comment = Display.create(asList).create(
new FontConfiguration(font, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
new SpriteContainerEmpty());
comment = TextBlockUtils.withMargin(comment, 4, 4);
comment = new SimpleTextBlockBordered(comment, color);
comment = TextBlockUtils.withMargin(comment, 10, 10);
return comment;
}
// private static final String PARIS = "A thought for those who died in Paris the 13th November 2015.";
//
// private static TextBlock addEvent(final TextBlock textBlock, final HtmlColor color) {
// try {
// final String today = new SimpleDateFormat("MM-dd", Locale.US).format(new Date());
// if ("11-05".equals(today)) {
// final List<String> asList = Arrays.asList("<u>November 5th, 1955",
// "Doc Brown's discovery of the Flux Capacitor, that makes time-travel possible.");
// return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
// } else if ("08-29".equals(today)) {
// final List<String> asList = Arrays.asList("<u>August 29th, 1997",
// "Skynet becomes self-aware at 02:14 AM Eastern Time.");
// return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
// } else if ("06-29".equals(today)) {
// final List<String> asList = Arrays.asList("<u>June 29th, 1975",
// "\"It was the first time in history that anyone had typed",
// "a character on a keyboard and seen it show up on their",
// "own computer's screen right in front of them.\"", "\t\t\t\t\t\t\t\t\t\t<i>Steve Wozniak");
// return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT);
// } else if ("01-07".equals(today) || ("01-08".equals(today) && getDayOfWeek() == Calendar.MONDAY)) {
// return addCharlie(textBlock);
// } else if ("11-13".equals(today) || ("11-14".equals(today) && getDayOfWeek() == Calendar.MONDAY)) {
// return addMemorial(textBlock, color);
// }
// } catch (Throwable t) {
// Log.debug("Error " + t);
// }
// return textBlock;
// }
//
// private synchronized static int getDayOfWeek() {
// return Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
// }
//
// private static TextBlock addMemorial(TextBlock textBlock, HtmlColor color) {
// final Portrait portrait = Portraits.getOne();
// if (portrait == null) {
// return textBlock;
// }
// final BufferedImage im = portrait.getBufferedImage();
// if (im == null) {
// return textBlock;
// }
//
// final String name = portrait.getName();
// final String quote = portrait.getQuote();
// final String age = "" + portrait.getAge() + " years old";
// final UFont font12 = new UFont("SansSerif", Font.BOLD, 12);
// TextBlock comment = Display.create(name, age, quote).create(
// new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
// new SpriteContainerEmpty());
// comment = TextBlockUtils.withMinWidth(TextBlockUtils.withMargin(comment, 4, 4), 800, HorizontalAlignment.LEFT);
//
// final TextBlock bottom0 = getComment(Arrays.asList(PARIS), color);
// final TextBlock bottom1 = new AbstractTextBlock() {
// private double margin = 10;
//
// public void drawU(UGraphic ug) {
// ug = ug.apply(new UTranslate(0, margin));
// ug.draw(new UImage(im));
// if (ug instanceof LimitFinder) {
// return;
// }
// Portraits.nextOne();
// }
//
// public Dimension2D calculateDimension(StringBounder stringBounder) {
// return new Dimension2DDouble(im.getWidth(), margin + im.getHeight());
// }
// };
// final TextBlock bottom = TextBlockUtils.mergeTB(bottom0,
// TextBlockUtils.mergeLR(bottom1, comment, VerticalAlignment.CENTER), HorizontalAlignment.LEFT);
// final TextBlock mergeTB = TextBlockUtils.mergeTB(textBlock, bottom, HorizontalAlignment.LEFT);
// return addMajesty(mergeTB, color);
// }
//
// public static TextBlock addMajesty(TextBlock block, HtmlColor color) {
// final UFont font12 = new UFont("SansSerif", Font.BOLD, 12);
// final String arabic1 = "<size:16>\u0625\u0646 \u0627\u0644\u0625\u0631\u0647\u0627\u0628\u064A\u064A\u0646 \u0628\u0627\u0633\u0645 \u0627\u0644\u0625\u0633\u0644\u0627\u0645 \u0644\u064A\u0633\u0648\u0627 \u0645\u0633\u0644\u0645\u064A\u0646\u060C \u0648\u0644\u0627 \u064A\u0631\u0628\u0637\u0647\u0645 \u0628\u0627\u0644\u0625\u0633\u0644\u0627\u0645 \u0625\u0644\u0627 \u0627\u0644\u062F\u0648\u0627\u0641\u0639 \u0627\u0644\u062A\u064A \u064A\u0631\u0643\u0628\u0648\u0646 \u0639\u0644\u064A\u0647\u0627 \u0644\u062A\u0628\u0631\u064A\u0631 \u062C\u0631\u0627\u0626\u0645\u0647\u0645 \u0648\u062D\u0645\u0627\u0642\u0627\u062A\u0647\u0645.";
// final String arabic2 = "<size:16>\u0641\u0647\u0645 \u0642\u0648\u0645 \u0636\u0627\u0644\u0648\u0646\u060C \u0645\u0635\u064A\u0631\u0647\u0645 \u062C\u0647\u0646\u0645 \u062E\u0627\u0644\u062F\u064A\u0646 \u0641\u064A\u0647\u0627 \u0623\u0628\u062F\u0627.";
// final String english1 = "<size:10>Those who engage in terrorism, in the name of Islam, are not Muslims.";
// final String english2 = "<size:10>Their only link to Islam is the pretexts they use to justify their crimes and their folly.";
// final String english3 = "<size:10>They have strayed from the right path, and their fate is to dwell forever in hell.";
// final TextBlock arabic = Display
// .create(" ",
// arabic1,
// arabic2,
// "<size:16>\u0635\u0627\u062D\u0628 \u0627\u0644\u062C\u0644\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0643 \u0645\u062D\u0645\u062F \u0627\u0644\u0633\u0627\u062F\u0633 \u0623\u0645\u064A\u0631 \u0627\u0644\u0645\u0624\u0645\u0646\u064A\u0646 \u0646\u0635\u0631\u0647 \u0627\u0644\u0644\u0647")
// .create(new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.RIGHT,
// new SpriteContainerEmpty());
// final TextBlock english = Display.create(english1, english2, english3,
// "<size:10>-- His Majesty the King Mohammed the Sixth, Commander of the Faithful").create(
// new FontConfiguration(font12, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
// new SpriteContainerEmpty());
// return TextBlockUtils.mergeTB(block, TextBlockUtils.mergeTB(arabic, english, HorizontalAlignment.LEFT),
// HorizontalAlignment.LEFT);
// }
//
// private static TextBlock addCharlie(TextBlock textBlock) {
// final TextBlock charlie = new AbstractTextBlock() {
// private final BufferedImage charlie = PSystemVersion.getCharlieImage();
//
// public void drawU(UGraphic ug) {
// ug.draw(new UImage(charlie));
// }
//
// public Dimension2D calculateDimension(StringBounder stringBounder) {
// return new Dimension2DDouble(charlie.getWidth(), charlie.getHeight());
// }
// };
// return TextBlockUtils.mergeTB(charlie, textBlock, HorizontalAlignment.LEFT);
//
// }
//
// public static TextBlock getComment(final List<String> asList, HtmlColor color) {
// final UFont font = new UFont("SansSerif", Font.BOLD, 14);
// TextBlock comment = Display.create(asList).create(
// new FontConfiguration(font, color, HtmlColorUtils.BLUE, true), HorizontalAlignment.LEFT,
// new SpriteContainerEmpty());
// comment = TextBlockUtils.withMargin(comment, 4, 4);
// comment = new SimpleTextBlockBordered(comment, color);
// comment = TextBlockUtils.withMargin(comment, 10, 10);
// return comment;
// }
}

View File

@ -40,9 +40,7 @@ import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.svek.IEntityImage;
import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.UChangeColor;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
@ -51,11 +49,13 @@ import net.sourceforge.plantuml.ugraphic.UTranslate;
public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
private final double margin = 5;
private final HtmlColor background;
private final UFont font;
private final HtmlColor green;
private final HtmlColor maincolor;
private final HtmlColor hyperlinkColor = HtmlColorUtils.BLUE;
@ -67,54 +67,71 @@ public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
private final GraphicPosition position;
private final UAntiAliasing antiAliasing;
private int maxLine = 0;
private final ColorMapper colorMapper = new ColorMapperIdentity();
public static GraphicStrings createDefault(List<String> strings, boolean useRed) {
public static IEntityImage createForError(List<String> strings, boolean useRed) {
if (useRed) {
return new GraphicStrings(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorUtils.BLACK,
HtmlColorUtils.RED_LIGHT, UAntiAliasing.ANTI_ALIASING_ON);
HtmlColorUtils.RED_LIGHT, null, null);
}
return new GraphicStrings(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorSet.getInstance()
.getColorIfValid("#33FF02"), HtmlColorUtils.BLACK, UAntiAliasing.ANTI_ALIASING_ON);
.getColorIfValid("#33FF02"), HtmlColorUtils.BLACK, null, null);
}
public GraphicStrings(List<String> strings, UFont font, HtmlColor green, HtmlColor background,
UAntiAliasing antiAliasing) {
this(strings, font, green, background, antiAliasing, null, null);
public static TextBlockBackcolored createGreenOnBlackMonospaced(List<String> strings) {
return new GraphicStrings(strings, monospaced14(), HtmlColorUtils.GREEN, HtmlColorUtils.BLACK, null, null);
}
public GraphicStrings(List<String> strings, UFont font, HtmlColor green, HtmlColor background,
UAntiAliasing antiAliasing, BufferedImage image, GraphicPosition position) {
public static TextBlockBackcolored createBlackOnWhite(List<String> strings) {
return new GraphicStrings(strings, sansSerif12(), HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, null, null);
}
public static TextBlockBackcolored createBlackOnWhiteMonospaced(List<String> strings) {
return new GraphicStrings(strings, monospaced14(), HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, null, null);
}
public static TextBlockBackcolored createBlackOnWhite(List<String> strings, BufferedImage image,
GraphicPosition position, int maxLine) {
final GraphicStrings result = new GraphicStrings(strings, sansSerif12(), HtmlColorUtils.BLACK,
HtmlColorUtils.WHITE, image, position);
result.maxLine = maxLine;
return result;
}
public static TextBlockBackcolored createBlackOnWhite(List<String> strings, BufferedImage image,
GraphicPosition position) {
return new GraphicStrings(strings, sansSerif12(), HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, image, position);
}
private static UFont sansSerif12() {
return new UFont("SansSerif", Font.PLAIN, 12);
}
private static UFont monospaced14() {
return new UFont("Monospaced", Font.PLAIN, 14);
}
private GraphicStrings(List<String> strings, UFont font, HtmlColor maincolor, HtmlColor background,
BufferedImage image, GraphicPosition position) {
this.strings = strings;
this.font = font;
this.green = green;
this.maincolor = maincolor;
this.background = background;
this.image = image;
this.position = position;
this.antiAliasing = antiAliasing;
}
private double minWidth;
public void setMinWidth(double minWidth) {
this.minWidth = minWidth;
}
private int maxLine = 0;
private TextBlock getTextBlock() {
TextBlock result = null;
if (maxLine == 0) {
result = Display.create(strings).create(
new FontConfiguration(font, green, hyperlinkColor, useUnderlineForHyperlink),
new FontConfiguration(font, maincolor, hyperlinkColor, useUnderlineForHyperlink),
HorizontalAlignment.LEFT, new SpriteContainerEmpty());
} else {
for (int i = 0; i < strings.size(); i += maxLine) {
final int n = Math.min(i + maxLine, strings.size());
final TextBlock textBlock1 = Display.create(strings.subList(i, n)).create(
new FontConfiguration(font, green, hyperlinkColor, useUnderlineForHyperlink),
new FontConfiguration(font, maincolor, hyperlinkColor, useUnderlineForHyperlink),
HorizontalAlignment.LEFT, new SpriteContainerEmpty());
if (result == null) {
result = textBlock1;
@ -124,13 +141,14 @@ public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
}
}
}
result = DateEventUtils.addEvent(result, green);
// result = DateEventUtils.addEvent(result, green);
return result;
}
public void drawU(UGraphic ug) {
final Dimension2D size = calculateDimension(ug.getStringBounder());
getTextBlock().drawU(ug.apply(new UChangeColor(green)));
ug = ug.apply(new UTranslate(margin, margin));
final Dimension2D size = calculateDimensionInternal(ug.getStringBounder());
getTextBlock().drawU(ug.apply(new UChangeColor(maincolor)));
if (image != null) {
if (position == GraphicPosition.BOTTOM) {
@ -146,10 +164,11 @@ public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
Dimension2D dim = getTextBlock().calculateDimension(stringBounder);
if (dim.getWidth() < minWidth) {
dim = new Dimension2DDouble(minWidth, dim.getHeight());
return Dimension2DDouble.delta(calculateDimensionInternal(stringBounder), 2 * margin);
}
private Dimension2D calculateDimensionInternal(StringBounder stringBounder) {
Dimension2D dim = getTextBlock().calculateDimension(stringBounder);
if (image != null) {
if (position == GraphicPosition.BOTTOM) {
dim = new Dimension2DDouble(dim.getWidth(), dim.getHeight() + image.getHeight());
@ -178,8 +197,4 @@ public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
return false;
}
public final void setMaxLine(int maxLine) {
this.maxLine = maxLine;
}
}

View File

@ -97,7 +97,7 @@ public class QuoteUtils {
"Luke, I am your father.", //
"Blood, Sweat and Tears", //
"Houston, we have a problem.", //
"Boot failure, press any key to continue", //
"Keyboard failure, press any key to continue", //
"Big mistake!", //
"How many UML designers does it take to change a lightbulb ?", //
"Do you like movies about gladiators ?", //

View File

@ -0,0 +1,71 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.graphic;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.ugraphic.UGraphic;
public class TextBlockWithUrl implements TextBlock {
private final TextBlock block;
private final Url url;
public static TextBlock withUrl(TextBlock block, Url url) {
if (url == null) {
return block;
}
return new TextBlockWithUrl(block, url);
}
private TextBlockWithUrl(TextBlock block, Url url) {
this.block = block;
this.url = url;
}
public void drawU(UGraphic ug) {
ug.startUrl(url);
block.drawU(ug);
ug.closeAction();
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return block.calculateDimension(stringBounder);
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder) {
return block.getInnerPosition(member, stringBounder);
}
}

View File

@ -0,0 +1,128 @@
package net.sourceforge.plantuml.math;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.imageio.ImageIO;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import net.sourceforge.plantuml.Dimension2DDouble;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class AsciiMath {
private static final String ASCIIMATH_PARSER_JS_LOCATION = "/net/sourceforge/plantuml/math/";
private static String JAVASCRIPT_CODE;
static {
try {
final BufferedReader br = new BufferedReader(new InputStreamReader(
AsciiMath.class.getResourceAsStream(ASCIIMATH_PARSER_JS_LOCATION + "AsciiMathParser.js"), "UTF-8"));
final StringBuilder sb = new StringBuilder();
String s = null;
while ((s = br.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
br.close();
JAVASCRIPT_CODE = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
private final Node mathML;
public AsciiMath(String form) throws IOException, ScriptException, ParserConfigurationException,
NoSuchMethodException {
final ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
engine.eval(JAVASCRIPT_CODE);
final Invocable inv = (Invocable) engine;
final Document dom = createDocument();
mathML = (Node) inv.invokeFunction("plantuml", dom, form);
}
public static void main(String[] args) throws IOException, NoSuchMethodException, ScriptException,
ParserConfigurationException, ClassNotFoundException, SecurityException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
AsciiMath math = new AsciiMath("sum_(i=1)^n i^3=((n(n+1))/2)^2");
PrintWriter pw = new PrintWriter(new File("math2.svg"));
pw.println(math.getSvg());
pw.close();
ImageIO.write(math.getImage(), "png", new File("math2.png"));
}
private Document createDocument() throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
return document;
}
private Dimension2D dim;
public String getSvg() throws IOException, ClassNotFoundException, NoSuchMethodException, SecurityException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Class<?> clConverter = Class.forName("net.sourceforge.jeuclid.converter.Converter");
final Method getInstance = clConverter.getMethod("getInstance");
final Object conv = getInstance.invoke(null);
final Method convert = clConverter.getMethod("convert", Node.class, OutputStream.class, String.class,
Class.forName("net.sourceforge.jeuclid.LayoutContext"));
dim = (Dimension2D) convert.invoke(conv, mathML, baos, "image/svg+xml", getLayout());
return new String(baos.toByteArray());
}
public BufferedImage getImage() throws IOException, ClassNotFoundException, NoSuchMethodException,
SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchFieldException {
final Class<?> clConverter = Class.forName("net.sourceforge.jeuclid.converter.Converter");
final Method getInstance = clConverter.getMethod("getInstance");
final Object conv = getInstance.invoke(null);
// final LayoutContext layoutContext = LayoutContextImpl.getDefaultLayoutContext();
final Method render = clConverter.getMethod("render", Node.class,
Class.forName("net.sourceforge.jeuclid.LayoutContext"));
final BufferedImage result = (BufferedImage) render.invoke(conv, mathML, getLayout());
dim = new Dimension2DDouble(result.getWidth(), result.getHeight());
return result;
}
private Object getLayout() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException, IllegalArgumentException, NoSuchFieldException, SecurityException {
final Class<?> clLayoutContextIml = Class.forName("net.sourceforge.jeuclid.context.LayoutContextImpl");
final Class<?> clParameter = Class.forName("net.sourceforge.jeuclid.context.Parameter");
final Method getDefaultLayoutContext = clLayoutContextIml.getMethod("getDefaultLayoutContext");
final Object layoutContext = getDefaultLayoutContext.invoke(null);
final Method setParameter = clLayoutContextIml.getMethod("setParameter", clParameter, Object.class);
setParameter.invoke(layoutContext, clParameter.getDeclaredField("SCRIPTSIZEMULTIPLIER").get(null), (float) 2);
return layoutContext;
}
public Dimension2D getDimension() {
return dim;
}
}

View File

@ -0,0 +1,846 @@
/*
Copyright (c) 2011-2012, The University of Edinburgh
All Rights Reserved
This file is part of AsciiMathParser.js
AsciiMathParser.js is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
AsciiMathParser.js is 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 Lesser General Public License (at
http://www.gnu.org/licences/lgpl.html) for more details.
You should have received a copy of the GNU Lesser General Public License
along with AsciiMathParser.js. If not, see <http://www.gnu.org/licenses/lgpl.html>.
AsciiMathParser.js
==================
This is a modified and cut-down version of ASCIIMathML.js v2.1
that allows ASCIIMath to be used solely as a parser for ASCIIMath
input, generating an XML Element Node as a result.
This may allow you to integrate the ASCIIMath input format with
other software and does not need to be run in a browser.
The only requirement is that you can provide a DOM Document Object
when creating a parser. (Microsoft's implementation of Document is fine
too.)
*/
/************************************************************************/
/* This creates a new Object that you can use to parse ASCIIMath input.
*
* You must pass a DOM Document Object here that will be used to create
* new DOM Nodes. The Doucument itself will not be modified.
* A Microsoft DOM is acceptable.
*/
function AsciiMathParser(document) {
/* ASCIIMathML.js BEGINS BELOW.
*
* NOTE: I did a global search and replace to make NodeList traversal
* work with the Java DOM, so that childNodes[i] -> childNodes.item(i).
* This was done with the regexp s/(childNodes)\[(.+?)\]/$1.item($2)/g
*
* All other modifications made are shown below on
* lines starting with
* '//MOD: '
*/
//-------------------------------------------------------------
/*
ASCIIMathML.js
==============
This file contains JavaScript functions to convert ASCII math notation
and LaTeX to Presentation MathML. Simple graphics commands are also
translated to SVG images. The conversion is done while the (X)HTML
page loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet
Explorer 6/7 + MathPlayer (http://www.dessci.com/en/products/mathplayer/) +
Adobe SVGview 3.03 (http://www.adobe.com/svg/viewer/install/).
Just add the next line to your (X)HTML page with this file in the same folder:
<script type="text/javascript" src="ASCIIMathML.js"></script>
(using the graphics in IE also requires the file "d.svg" in the same folder).
This is a convenient and inexpensive solution for authoring MathML and SVG.
Version 2.1 Oct 8, 2008, (c) Peter Jipsen http://www.chapman.edu/~jipsen
This version extends ASCIIMathML.js with LaTeXMathML.js and ASCIIsvg.js.
Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
If you use it on a webpage, please send the URL to jipsen@chapman.edu
The LaTeXMathML modifications were made by Douglas Woodall, June 2006.
(for details see header on the LaTeXMathML part in middle of file)
Extensive clean-up and improvements by Paulo Soares, Oct 2007.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This program is 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 Lesser General Public License
(at http://www.gnu.org/licences/lgpl.html) for more details.
*/
//MOD: Most of the global variables defined next are not required,
//MOD: with the exception of the following:
var decimalsign = "."; // change to "," if you like, beware of `(1,2)`!
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//MOD: Everything from this point until the character list definitions starting
//MOD: with 'var AMcal' has been removed and replaced with the following:
// This should be false here, since we're generating an XML DOM, rather than
// something that will be aimed at a specific browser.
var isIE = false;
// New version of this method to overcome the lack of createElementNS() in MSXML
function createMmlNode(t,frag) {
var node;
if (document.createElementNS) {
node = document.createElementNS("http://www.w3.org/1998/Math/MathML", t);
}
else {
try {
/* MSXML */
node = document.createNode(1, t, "http://www.w3.org/1998/Math/MathML");
}
catch (e) {
throw "This DOM Document does not support either createElementNS() or createNS()";
}
}
if (frag) node.appendChild(frag);
return node;
}
// character lists for Mozilla/Netscape fonts
var AMcal = [0xEF35,0x212C,0xEF36,0xEF37,0x2130,0x2131,0xEF38,0x210B,0x2110,0xEF39,0xEF3A,0x2112,0x2133,0xEF3B,0xEF3C,0xEF3D,0xEF3E,0x211B,0xEF3F,0xEF40,0xEF41,0xEF42,0xEF43,0xEF44,0xEF45,0xEF46];
var AMfrk = [0xEF5D,0xEF5E,0x212D,0xEF5F,0xEF60,0xEF61,0xEF62,0x210C,0x2111,0xEF63,0xEF64,0xEF65,0xEF66,0xEF67,0xEF68,0xEF69,0xEF6A,0x211C,0xEF6B,0xEF6C,0xEF6D,0xEF6E,0xEF6F,0xEF70,0xEF71,0x2128];
var AMbbb = [0xEF8C,0xEF8D,0x2102,0xEF8E,0xEF8F,0xEF90,0xEF91,0x210D,0xEF92,0xEF93,0xEF94,0xEF95,0xEF96,0x2115,0xEF97,0x2119,0x211A,0x211D,0xEF98,0xEF99,0xEF9A,0xEF9B,0xEF9C,0xEF9D,0xEF9E,0x2124];
var CONST = 0, UNARY = 1, BINARY = 2, INFIX = 3, LEFTBRACKET = 4,
RIGHTBRACKET = 5, SPACE = 6, UNDEROVER = 7, DEFINITION = 8,
LEFTRIGHT = 9, TEXT = 10, BIG = 11, LONG = 12, STRETCHY = 13,
MATRIX = 14;; // token types
var AMquote = {input:"\"", tag:"mtext", output:"mbox", tex:null, ttype:TEXT};
var AMsymbols = [
//some greek symbols
{input:"alpha", tag:"mi", output:"\u03B1", tex:null, ttype:CONST},
{input:"beta", tag:"mi", output:"\u03B2", tex:null, ttype:CONST},
{input:"chi", tag:"mi", output:"\u03C7", tex:null, ttype:CONST},
{input:"delta", tag:"mi", output:"\u03B4", tex:null, ttype:CONST},
{input:"Delta", tag:"mo", output:"\u0394", tex:null, ttype:CONST},
{input:"epsi", tag:"mi", output:"\u03B5", tex:"epsilon", ttype:CONST},
{input:"varepsilon", tag:"mi", output:"\u025B", tex:null, ttype:CONST},
{input:"eta", tag:"mi", output:"\u03B7", tex:null, ttype:CONST},
{input:"gamma", tag:"mi", output:"\u03B3", tex:null, ttype:CONST},
{input:"Gamma", tag:"mo", output:"\u0393", tex:null, ttype:CONST},
{input:"iota", tag:"mi", output:"\u03B9", tex:null, ttype:CONST},
{input:"kappa", tag:"mi", output:"\u03BA", tex:null, ttype:CONST},
{input:"lambda", tag:"mi", output:"\u03BB", tex:null, ttype:CONST},
{input:"Lambda", tag:"mo", output:"\u039B", tex:null, ttype:CONST},
{input:"mu", tag:"mi", output:"\u03BC", tex:null, ttype:CONST},
{input:"nu", tag:"mi", output:"\u03BD", tex:null, ttype:CONST},
{input:"omega", tag:"mi", output:"\u03C9", tex:null, ttype:CONST},
{input:"Omega", tag:"mo", output:"\u03A9", tex:null, ttype:CONST},
{input:"phi", tag:"mi", output:"\u03C6", tex:null, ttype:CONST},
{input:"varphi", tag:"mi", output:"\u03D5", tex:null, ttype:CONST},
{input:"Phi", tag:"mo", output:"\u03A6", tex:null, ttype:CONST},
{input:"pi", tag:"mi", output:"\u03C0", tex:null, ttype:CONST},
{input:"Pi", tag:"mo", output:"\u03A0", tex:null, ttype:CONST},
{input:"psi", tag:"mi", output:"\u03C8", tex:null, ttype:CONST},
{input:"Psi", tag:"mi", output:"\u03A8", tex:null, ttype:CONST},
{input:"rho", tag:"mi", output:"\u03C1", tex:null, ttype:CONST},
{input:"sigma", tag:"mi", output:"\u03C3", tex:null, ttype:CONST},
{input:"Sigma", tag:"mo", output:"\u03A3", tex:null, ttype:CONST},
{input:"tau", tag:"mi", output:"\u03C4", tex:null, ttype:CONST},
{input:"theta", tag:"mi", output:"\u03B8", tex:null, ttype:CONST},
{input:"vartheta", tag:"mi", output:"\u03D1", tex:null, ttype:CONST},
{input:"Theta", tag:"mo", output:"\u0398", tex:null, ttype:CONST},
{input:"upsilon", tag:"mi", output:"\u03C5", tex:null, ttype:CONST},
{input:"xi", tag:"mi", output:"\u03BE", tex:null, ttype:CONST},
{input:"Xi", tag:"mo", output:"\u039E", tex:null, ttype:CONST},
{input:"zeta", tag:"mi", output:"\u03B6", tex:null, ttype:CONST},
//binary operation symbols
//{input:"-", tag:"mo", output:"\u0096", tex:null, ttype:CONST},
{input:"*", tag:"mo", output:"\u22C5", tex:"cdot", ttype:CONST},
{input:"**", tag:"mo", output:"\u22C6", tex:"star", ttype:CONST},
{input:"//", tag:"mo", output:"/", tex:null, ttype:CONST},
{input:"\\\\", tag:"mo", output:"\\", tex:"backslash", ttype:CONST},
{input:"setminus", tag:"mo", output:"\\", tex:null, ttype:CONST},
{input:"xx", tag:"mo", output:"\u00D7", tex:"times", ttype:CONST},
{input:"-:", tag:"mo", output:"\u00F7", tex:"divide", ttype:CONST},
{input:"@", tag:"mo", output:"\u26AC", tex:"circ", ttype:CONST},
{input:"o+", tag:"mo", output:"\u2295", tex:"oplus", ttype:CONST},
{input:"ox", tag:"mo", output:"\u2297", tex:"otimes", ttype:CONST},
{input:"o.", tag:"mo", output:"\u2299", tex:"odot", ttype:CONST},
{input:"sum", tag:"mo", output:"\u2211", tex:null, ttype:UNDEROVER},
{input:"prod", tag:"mo", output:"\u220F", tex:null, ttype:UNDEROVER},
{input:"^^", tag:"mo", output:"\u2227", tex:"wedge", ttype:CONST},
{input:"^^^", tag:"mo", output:"\u22C0", tex:"bigwedge", ttype:UNDEROVER},
{input:"vv", tag:"mo", output:"\u2228", tex:"vee", ttype:CONST},
{input:"vvv", tag:"mo", output:"\u22C1", tex:"bigvee", ttype:UNDEROVER},
{input:"nn", tag:"mo", output:"\u2229", tex:"cap", ttype:CONST},
{input:"nnn", tag:"mo", output:"\u22C2", tex:"bigcap", ttype:UNDEROVER},
{input:"uu", tag:"mo", output:"\u222A", tex:"cup", ttype:CONST},
{input:"uuu", tag:"mo", output:"\u22C3", tex:"bigcup", ttype:UNDEROVER},
//binary relation symbols
{input:"!=", tag:"mo", output:"\u2260", tex:"ne", ttype:CONST},
{input:":=", tag:"mo", output:":=", tex:null, ttype:CONST},
{input:"lt", tag:"mo", output:"<", tex:null, ttype:CONST},
{input:"<=", tag:"mo", output:"\u2264", tex:"le", ttype:CONST},
{input:"lt=", tag:"mo", output:"\u2264", tex:"leq", ttype:CONST},
{input:">=", tag:"mo", output:"\u2265", tex:"ge", ttype:CONST},
{input:"geq", tag:"mo", output:"\u2265", tex:null, ttype:CONST},
{input:"-<", tag:"mo", output:"\u227A", tex:"prec", ttype:CONST},
{input:"-lt", tag:"mo", output:"\u227A", tex:null, ttype:CONST},
{input:">-", tag:"mo", output:"\u227B", tex:"succ", ttype:CONST},
{input:"-<=", tag:"mo", output:"\u2AAF", tex:"preceq", ttype:CONST},
{input:">-=", tag:"mo", output:"\u2AB0", tex:"succeq", ttype:CONST},
{input:"in", tag:"mo", output:"\u2208", tex:null, ttype:CONST},
{input:"!in", tag:"mo", output:"\u2209", tex:"notin", ttype:CONST},
{input:"sub", tag:"mo", output:"\u2282", tex:"subset", ttype:CONST},
{input:"sup", tag:"mo", output:"\u2283", tex:"supset", ttype:CONST},
{input:"sube", tag:"mo", output:"\u2286", tex:"subseteq", ttype:CONST},
{input:"supe", tag:"mo", output:"\u2287", tex:"supseteq", ttype:CONST},
{input:"-=", tag:"mo", output:"\u2261", tex:"equiv", ttype:CONST},
{input:"~=", tag:"mo", output:"\u2245", tex:"cong", ttype:CONST},
{input:"~~", tag:"mo", output:"\u2248", tex:"approx", ttype:CONST},
{input:"prop", tag:"mo", output:"\u221D", tex:"propto", ttype:CONST},
//logical symbols
{input:"and", tag:"mtext", output:"and", tex:null, ttype:SPACE},
{input:"or", tag:"mtext", output:"or", tex:null, ttype:SPACE},
{input:"not", tag:"mo", output:"\u00AC", tex:"neg", ttype:CONST},
{input:"=>", tag:"mo", output:"\u21D2", tex:"implies", ttype:CONST},
{input:"if", tag:"mo", output:"if", tex:null, ttype:SPACE},
{input:"<=>", tag:"mo", output:"\u21D4", tex:"iff", ttype:CONST},
{input:"AA", tag:"mo", output:"\u2200", tex:"forall", ttype:CONST},
{input:"EE", tag:"mo", output:"\u2203", tex:"exists", ttype:CONST},
{input:"_|_", tag:"mo", output:"\u22A5", tex:"bot", ttype:CONST},
{input:"TT", tag:"mo", output:"\u22A4", tex:"top", ttype:CONST},
{input:"|--", tag:"mo", output:"\u22A2", tex:"vdash", ttype:CONST},
{input:"|==", tag:"mo", output:"\u22A8", tex:"models", ttype:CONST},
//grouping brackets
{input:"(", tag:"mo", output:"(", tex:null, ttype:LEFTBRACKET},
{input:")", tag:"mo", output:")", tex:null, ttype:RIGHTBRACKET},
{input:"[", tag:"mo", output:"[", tex:null, ttype:LEFTBRACKET},
{input:"]", tag:"mo", output:"]", tex:null, ttype:RIGHTBRACKET},
{input:"{", tag:"mo", output:"{", tex:null, ttype:LEFTBRACKET},
{input:"}", tag:"mo", output:"}", tex:null, ttype:RIGHTBRACKET},
{input:"|", tag:"mo", output:"|", tex:null, ttype:LEFTRIGHT},
//{input:"||", tag:"mo", output:"||", tex:null, ttype:LEFTRIGHT},
{input:"(:", tag:"mo", output:"\u2329", tex:"langle", ttype:LEFTBRACKET},
{input:":)", tag:"mo", output:"\u232A", tex:"rangle", ttype:RIGHTBRACKET},
{input:"<<", tag:"mo", output:"\u2329", tex:null, ttype:LEFTBRACKET},
{input:">>", tag:"mo", output:"\u232A", tex:null, ttype:RIGHTBRACKET},
{input:"{:", tag:"mo", output:"{:", tex:null, ttype:LEFTBRACKET, invisible:true},
{input:":}", tag:"mo", output:":}", tex:null, ttype:RIGHTBRACKET, invisible:true},
//miscellaneous symbols
{input:"int", tag:"mo", output:"\u222B", tex:null, ttype:CONST},
{input:"dx", tag:"mi", output:"{:d x:}", tex:null, ttype:DEFINITION},
{input:"dy", tag:"mi", output:"{:d y:}", tex:null, ttype:DEFINITION},
{input:"dz", tag:"mi", output:"{:d z:}", tex:null, ttype:DEFINITION},
{input:"dt", tag:"mi", output:"{:d t:}", tex:null, ttype:DEFINITION},
{input:"oint", tag:"mo", output:"\u222E", tex:null, ttype:CONST},
{input:"del", tag:"mo", output:"\u2202", tex:"partial", ttype:CONST},
{input:"grad", tag:"mo", output:"\u2207", tex:"nabla", ttype:CONST},
{input:"+-", tag:"mo", output:"\u00B1", tex:"pm", ttype:CONST},
{input:"O/", tag:"mo", output:"\u2205", tex:"emptyset", ttype:CONST},
{input:"oo", tag:"mo", output:"\u221E", tex:"infty", ttype:CONST},
{input:"aleph", tag:"mo", output:"\u2135", tex:null, ttype:CONST},
{input:"...", tag:"mo", output:"...", tex:"ldots", ttype:CONST},
{input:":.", tag:"mo", output:"\u2234", tex:"therefore", ttype:CONST},
{input:"/_", tag:"mo", output:"\u2220", tex:"angle", ttype:CONST},
{input:"\\ ", tag:"mo", output:"\u00A0", tex:null, ttype:CONST},
{input:"quad", tag:"mo", output:"\u00A0\u00A0", tex:null, ttype:CONST},
{input:"qquad", tag:"mo", output:"\u00A0\u00A0\u00A0\u00A0", tex:null, ttype:CONST},
{input:"cdots", tag:"mo", output:"\u22EF", tex:null, ttype:CONST},
{input:"vdots", tag:"mo", output:"\u22EE", tex:null, ttype:CONST},
{input:"ddots", tag:"mo", output:"\u22F1", tex:null, ttype:CONST},
{input:"diamond", tag:"mo", output:"\u22C4", tex:null, ttype:CONST},
{input:"square", tag:"mo", output:"\u25A1", tex:null, ttype:CONST},
{input:"|__", tag:"mo", output:"\u230A", tex:"lfloor", ttype:CONST},
{input:"__|", tag:"mo", output:"\u230B", tex:"rfloor", ttype:CONST},
{input:"|~", tag:"mo", output:"\u2308", tex:"lceiling", ttype:CONST},
{input:"~|", tag:"mo", output:"\u2309", tex:"rceiling", ttype:CONST},
{input:"CC", tag:"mo", output:"\u2102", tex:null, ttype:CONST},
{input:"NN", tag:"mo", output:"\u2115", tex:null, ttype:CONST},
{input:"QQ", tag:"mo", output:"\u211A", tex:null, ttype:CONST},
{input:"RR", tag:"mo", output:"\u211D", tex:null, ttype:CONST},
{input:"ZZ", tag:"mo", output:"\u2124", tex:null, ttype:CONST},
{input:"f", tag:"mi", output:"f", tex:null, ttype:UNARY, func:true},
{input:"g", tag:"mi", output:"g", tex:null, ttype:UNARY, func:true},
//standard functions
{input:"lim", tag:"mo", output:"lim", tex:null, ttype:UNDEROVER},
{input:"Lim", tag:"mo", output:"Lim", tex:null, ttype:UNDEROVER},
{input:"sin", tag:"mo", output:"sin", tex:null, ttype:UNARY, func:true},
{input:"cos", tag:"mo", output:"cos", tex:null, ttype:UNARY, func:true},
{input:"tan", tag:"mo", output:"tan", tex:null, ttype:UNARY, func:true},
{input:"sinh", tag:"mo", output:"sinh", tex:null, ttype:UNARY, func:true},
{input:"cosh", tag:"mo", output:"cosh", tex:null, ttype:UNARY, func:true},
{input:"tanh", tag:"mo", output:"tanh", tex:null, ttype:UNARY, func:true},
{input:"cot", tag:"mo", output:"cot", tex:null, ttype:UNARY, func:true},
{input:"sec", tag:"mo", output:"sec", tex:null, ttype:UNARY, func:true},
{input:"csc", tag:"mo", output:"csc", tex:null, ttype:UNARY, func:true},
{input:"log", tag:"mo", output:"log", tex:null, ttype:UNARY, func:true},
{input:"ln", tag:"mo", output:"ln", tex:null, ttype:UNARY, func:true},
{input:"det", tag:"mo", output:"det", tex:null, ttype:UNARY, func:true},
{input:"dim", tag:"mo", output:"dim", tex:null, ttype:CONST},
{input:"mod", tag:"mo", output:"mod", tex:null, ttype:CONST},
{input:"gcd", tag:"mo", output:"gcd", tex:null, ttype:UNARY, func:true},
{input:"lcm", tag:"mo", output:"lcm", tex:null, ttype:UNARY, func:true},
{input:"lub", tag:"mo", output:"lub", tex:null, ttype:CONST},
{input:"glb", tag:"mo", output:"glb", tex:null, ttype:CONST},
{input:"min", tag:"mo", output:"min", tex:null, ttype:UNDEROVER},
{input:"max", tag:"mo", output:"max", tex:null, ttype:UNDEROVER},
//arrows
{input:"uarr", tag:"mo", output:"\u2191", tex:"uparrow", ttype:CONST},
{input:"darr", tag:"mo", output:"\u2193", tex:"downarrow", ttype:CONST},
{input:"rarr", tag:"mo", output:"\u2192", tex:"rightarrow", ttype:CONST},
{input:"->", tag:"mo", output:"\u2192", tex:"to", ttype:CONST},
{input:">->", tag:"mo", output:"\u21A3", tex:"rightarrowtail", ttype:CONST},
{input:"->>", tag:"mo", output:"\u21A0", tex:"twoheadrightarrow", ttype:CONST},
{input:">->>", tag:"mo", output:"\u2916", tex:"twoheadrightarrowtail", ttype:CONST},
{input:"|->", tag:"mo", output:"\u21A6", tex:"mapsto", ttype:CONST},
{input:"larr", tag:"mo", output:"\u2190", tex:"leftarrow", ttype:CONST},
{input:"harr", tag:"mo", output:"\u2194", tex:"leftrightarrow", ttype:CONST},
{input:"rArr", tag:"mo", output:"\u21D2", tex:"Rightarrow", ttype:CONST},
{input:"lArr", tag:"mo", output:"\u21D0", tex:"Leftarrow", ttype:CONST},
{input:"hArr", tag:"mo", output:"\u21D4", tex:"Leftrightarrow", ttype:CONST},
//commands with argument
{input:"sqrt", tag:"msqrt", output:"sqrt", tex:null, ttype:UNARY},
{input:"root", tag:"mroot", output:"root", tex:null, ttype:BINARY},
{input:"frac", tag:"mfrac", output:"/", tex:null, ttype:BINARY},
{input:"/", tag:"mfrac", output:"/", tex:null, ttype:INFIX},
{input:"stackrel", tag:"mover", output:"stackrel", tex:null, ttype:BINARY},
{input:"_", tag:"msub", output:"_", tex:null, ttype:INFIX},
{input:"^", tag:"msup", output:"^", tex:null, ttype:INFIX},
{input:"hat", tag:"mover", output:"\u005E", tex:null, ttype:UNARY, acc:true},
{input:"bar", tag:"mover", output:"\u00AF", tex:"overline", ttype:UNARY, acc:true},
{input:"vec", tag:"mover", output:"\u2192", tex:null, ttype:UNARY, acc:true},
{input:"dot", tag:"mover", output:".", tex:null, ttype:UNARY, acc:true},
{input:"ddot", tag:"mover", output:"..", tex:null, ttype:UNARY, acc:true},
{input:"ul", tag:"munder", output:"\u0332", tex:"underline", ttype:UNARY, acc:true},
{input:"text", tag:"mtext", output:"text", tex:null, ttype:TEXT},
{input:"mbox", tag:"mtext", output:"mbox", tex:null, ttype:TEXT},
AMquote,
{input:"bb", tag:"mstyle", atname:"fontweight", atval:"bold", output:"bb", tex:null, ttype:UNARY},
{input:"mathbf", tag:"mstyle", atname:"fontweight", atval:"bold", output:"mathbf", tex:null, ttype:UNARY},
{input:"sf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"sf", tex:null, ttype:UNARY},
{input:"mathsf", tag:"mstyle", atname:"fontfamily", atval:"sans-serif", output:"mathsf", tex:null, ttype:UNARY},
{input:"bbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"bbb", tex:null, ttype:UNARY, codes:AMbbb},
{input:"mathbb", tag:"mstyle", atname:"mathvariant", atval:"double-struck", output:"mathbb", tex:null, ttype:UNARY, codes:AMbbb},
{input:"cc", tag:"mstyle", atname:"mathvariant", atval:"script", output:"cc", tex:null, ttype:UNARY, codes:AMcal},
{input:"mathcal", tag:"mstyle", atname:"mathvariant", atval:"script", output:"mathcal", tex:null, ttype:UNARY, codes:AMcal},
{input:"tt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"tt", tex:null, ttype:UNARY},
{input:"mathtt", tag:"mstyle", atname:"fontfamily", atval:"monospace", output:"mathtt", tex:null, ttype:UNARY},
{input:"fr", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"fr", tex:null, ttype:UNARY, codes:AMfrk},
{input:"mathfrak", tag:"mstyle", atname:"mathvariant", atval:"fraktur", output:"mathfrak", tex:null, ttype:UNARY, codes:AMfrk}
];
function compareNames(s1,s2) {
if (s1.input > s2.input) return 1
else return -1;
}
var AMnames = []; //list of input symbols
function initSymbols() {
var texsymbols = [], i;
for (i=0; i<AMsymbols.length; i++)
if (AMsymbols[i].tex)
texsymbols[texsymbols.length] = {input:AMsymbols[i].tex,
tag:AMsymbols[i].tag, output:AMsymbols[i].output, ttype:AMsymbols[i].ttype};
AMsymbols = AMsymbols.concat(texsymbols);
refreshSymbols();
}
function refreshSymbols(){
var i;
AMsymbols.sort(compareNames);
for (i=0; i<AMsymbols.length; i++) AMnames[i] = AMsymbols[i].input;
//MOD: The following lines are commented out as we're not supporting LaTeX input
// LMsymbols.sort(compareNames);
// for (i=0; i<LMsymbols.length; i++) LMnames[i] = LMsymbols[i].input;
}
function define(oldstr,newstr) {
//MOD: The following lines are commented out as we're not supporting LaTeX input
// if(oldstr.substr(0,1)=="\\")
// LMsymbols = LMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
// ttype:DEFINITION}]);
// else
AMsymbols = AMsymbols.concat([{input:oldstr, tag:"mo", output:newstr,
tex:null, ttype:DEFINITION}]);
refreshSymbols(); // this may be a problem if many symbols are defined!
}
function AMremoveCharsAndBlanks(str,n) {
//remove n characters and any following blanks
var st;
if (str.charAt(n)=="\\" && str.charAt(n+1)!="\\" && str.charAt(n+1)!=" ")
st = str.slice(n+1);
else st = str.slice(n);
for (var i=0; i<st.length && st.charCodeAt(i)<=32; i=i+1);
return st.slice(i);
}
function position(arr, str, n) {
// return position >=n where str appears or would be inserted
// assumes arr is sorted
if (n==0) {
var h,m;
n = -1;
h = arr.length;
while (n+1<h) {
m = (n+h) >> 1;
if (arr[m]<str) n = m; else h = m;
}
return h;
} else
for (var i=n; i<arr.length && arr[i]<str; i++);
return i; // i=arr.length || arr[i]>=str
}
function AMgetSymbol(str) {
//return maximal initial substring of str that appears in names
//return null if there is none
var k = 0; //new pos
var j = 0; //old pos
var mk; //match pos
var st;
var tagst;
var match = "";
var more = true;
for (var i=1; i<=str.length && more; i++) {
st = str.slice(0,i); //initial substring of length i
j = k;
k = position(AMnames, st, j);
if (k<AMnames.length && str.slice(0,AMnames[k].length)==AMnames[k]){
match = AMnames[k];
mk = k;
i = match.length;
}
more = k<AMnames.length && str.slice(0,AMnames[k].length)>=AMnames[k];
}
AMpreviousSymbol=AMcurrentSymbol;
if (match!=""){
AMcurrentSymbol=AMsymbols[mk].ttype;
return AMsymbols[mk];
}
// if str[0] is a digit or - return maxsubstring of digits.digits
AMcurrentSymbol=CONST;
k = 1;
st = str.slice(0,1);
var integ = true;
while ("0"<=st && st<="9" && k<=str.length) {
st = str.slice(k,k+1);
k++;
}
if (st == decimalsign) {
st = str.slice(k,k+1);
if ("0"<=st && st<="9") {
integ = false;
k++;
while ("0"<=st && st<="9" && k<=str.length) {
st = str.slice(k,k+1);
k++;
}
}
}
if ((integ && k>1) || k>2) {
st = str.slice(0,k-1);
tagst = "mn";
} else {
k = 2;
st = str.slice(0,1); //take 1 character
tagst = (("A">st || st>"Z") && ("a">st || st>"z")?"mo":"mi");
}
if (st=="-" && AMpreviousSymbol==INFIX) {
AMcurrentSymbol = INFIX; //trick "/" into recognizing "-" on second parse
return {input:st, tag:tagst, output:st, ttype:UNARY, func:true};
}
return {input:st, tag:tagst, output:st, ttype:CONST};
}
function AMremoveBrackets(node) {
var st;
if (node.nodeName=="mrow") {
st = node.firstChild.firstChild.nodeValue;
if (st=="(" || st=="[" || st=="{") node.removeChild(node.firstChild);
}
if (node.nodeName=="mrow") {
st = node.lastChild.firstChild.nodeValue;
if (st==")" || st=="]" || st=="}") node.removeChild(node.lastChild);
}
}
/*Parsing ASCII math expressions with the following grammar
v ::= [A-Za-z] | greek letters | numbers | other constant symbols
u ::= sqrt | text | bb | other unary symbols for font commands
b ::= frac | root | stackrel binary symbols
l ::= ( | [ | { | (: | {: left brackets
r ::= ) | ] | } | :) | :} right brackets
S ::= v | lEr | uS | bSS Simple expression
I ::= S_S | S^S | S_S^S | S Intermediate expression
E ::= IE | I/I Expression
Each terminal symbol is translated into a corresponding mathml node.*/
var AMnestingDepth,AMpreviousSymbol,AMcurrentSymbol;
function AMparseSexpr(str) { //parses str and returns [node,tailstr]
var symbol, node, result, i, st,// rightvert = false,
newFrag = document.createDocumentFragment();
str = AMremoveCharsAndBlanks(str,0);
symbol = AMgetSymbol(str); //either a token or a bracket or empty
if (symbol == null || symbol.ttype == RIGHTBRACKET && AMnestingDepth > 0) {
return [null,str];
}
if (symbol.ttype == DEFINITION) {
str = symbol.output+AMremoveCharsAndBlanks(str,symbol.input.length);
symbol = AMgetSymbol(str);
}
switch (symbol.ttype) { case UNDEROVER:
case CONST:
str = AMremoveCharsAndBlanks(str,symbol.input.length);
return [createMmlNode(symbol.tag, //its a constant
document.createTextNode(symbol.output)),str];
case LEFTBRACKET: //read (expr+)
AMnestingDepth++;
str = AMremoveCharsAndBlanks(str,symbol.input.length);
result = AMparseExpr(str,true);
AMnestingDepth--;
if (typeof symbol.invisible == "boolean" && symbol.invisible)
node = createMmlNode("mrow",result[0]);
else {
node = createMmlNode("mo",document.createTextNode(symbol.output));
node = createMmlNode("mrow",node);
node.appendChild(result[0]);
}
return [node,result[1]];
case TEXT:
if (symbol!=AMquote) str = AMremoveCharsAndBlanks(str,symbol.input.length);
if (str.charAt(0)=="{") i=str.indexOf("}");
else if (str.charAt(0)=="(") i=str.indexOf(")");
else if (str.charAt(0)=="[") i=str.indexOf("]");
else if (symbol==AMquote) i=str.slice(1).indexOf("\"")+1;
else i = 0;
if (i==-1) i = str.length;
st = str.slice(1,i);
if (st.charAt(0) == " ") {
node = createMmlNode("mspace");
node.setAttribute("width","1ex");
newFrag.appendChild(node);
}
newFrag.appendChild(
createMmlNode(symbol.tag,document.createTextNode(st)));
if (st.charAt(st.length-1) == " ") {
node = createMmlNode("mspace");
node.setAttribute("width","1ex");
newFrag.appendChild(node);
}
str = AMremoveCharsAndBlanks(str,i+1);
return [createMmlNode("mrow",newFrag),str];
case UNARY:
str = AMremoveCharsAndBlanks(str,symbol.input.length);
result = AMparseSexpr(str);
if (result[0]==null) return [createMmlNode(symbol.tag,
document.createTextNode(symbol.output)),str];
if (typeof symbol.func == "boolean" && symbol.func) { // functions hack
st = str.charAt(0);
if (st=="^" || st=="_" || st=="/" || st=="|" || st==",") {
return [createMmlNode(symbol.tag,
document.createTextNode(symbol.output)),str];
} else {
node = createMmlNode("mrow",
createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
node.appendChild(result[0]);
return [node,result[1]];
}
}
AMremoveBrackets(result[0]);
if (symbol.input == "sqrt") { // sqrt
return [createMmlNode(symbol.tag,result[0]),result[1]];
} else if (typeof symbol.acc == "boolean" && symbol.acc) { // accent
node = createMmlNode(symbol.tag,result[0]);
node.appendChild(createMmlNode("mo",document.createTextNode(symbol.output)));
return [node,result[1]];
} else { // font change command
// MOD: The following code generates invalid MathML, so is commented out for the time being.
// if (!isIE && typeof symbol.codes != "undefined") {
// for (i=0; i<result[0].childNodes.length; i++)
// if (result[0].childNodes.item(i).nodeName=="mi" || result[0].nodeName=="mi") {
// st = (result[0].nodeName=="mi"?result[0].firstChild.nodeValue:
// result[0].childNodes.item(i).firstChild.nodeValue);
// var newst = [];
// for (var j=0; j<st.length; j++)
// if (st.charCodeAt(j)>64 && st.charCodeAt(j)<91) newst = newst +
// String.fromCharCode(symbol.codes[st.charCodeAt(j)-65]);
// else newst = newst + st.charAt(j);
// if (result[0].nodeName=="mi") {
// result[0]=createMmlNode("mo").
// appendChild(document.createTextNode(newst));
// }
// else result[0].replaceChild(createMmlNode("mo").
// appendChild(document.createTextNode(newst)),
// result[0].childNodes.item(i));
// }
// }
node = createMmlNode(symbol.tag,result[0]);
node.setAttribute(symbol.atname,symbol.atval);
return [node,result[1]];
}
case BINARY:
str = AMremoveCharsAndBlanks(str,symbol.input.length);
result = AMparseSexpr(str);
if (result[0]==null) return [createMmlNode("mo",
document.createTextNode(symbol.input)),str];
AMremoveBrackets(result[0]);
var result2 = AMparseSexpr(result[1]);
if (result2[0]==null) return [createMmlNode("mo",
document.createTextNode(symbol.input)),str];
AMremoveBrackets(result2[0]);
if (symbol.input=="root" || symbol.input=="stackrel")
newFrag.appendChild(result2[0]);
newFrag.appendChild(result[0]);
if (symbol.input=="frac") newFrag.appendChild(result2[0]);
return [createMmlNode(symbol.tag,newFrag),result2[1]];
case INFIX:
str = AMremoveCharsAndBlanks(str,symbol.input.length);
return [createMmlNode("mo",document.createTextNode(symbol.output)),str];
case SPACE:
str = AMremoveCharsAndBlanks(str,symbol.input.length);
node = createMmlNode("mspace");
node.setAttribute("width","1ex");
newFrag.appendChild(node);
newFrag.appendChild(
createMmlNode(symbol.tag,document.createTextNode(symbol.output)));
node = createMmlNode("mspace");
node.setAttribute("width","1ex");
newFrag.appendChild(node);
return [createMmlNode("mrow",newFrag),str];
case LEFTRIGHT:
// if (rightvert) return [null,str]; else rightvert = true;
AMnestingDepth++;
str = AMremoveCharsAndBlanks(str,symbol.input.length);
result = AMparseExpr(str,false);
AMnestingDepth--;
var st = "";
if (result[0].lastChild!=null)
st = result[0].lastChild.firstChild.nodeValue;
if (st == "|") { // its an absolute value subterm
node = createMmlNode("mo",document.createTextNode(symbol.output));
node = createMmlNode("mrow",node);
node.appendChild(result[0]);
return [node,result[1]];
} else { // the "|" is a \mid so use unicode 2223 (divides) for spacing
node = createMmlNode("mo",document.createTextNode("\u2223"));
node = createMmlNode("mrow",node);
return [node,str];
}
default:
//alert("default");
str = AMremoveCharsAndBlanks(str,symbol.input.length);
return [createMmlNode(symbol.tag, //its a constant
document.createTextNode(symbol.output)),str];
}
}
function AMparseIexpr(str) {
var symbol, sym1, sym2, node, result, underover;
str = AMremoveCharsAndBlanks(str,0);
sym1 = AMgetSymbol(str);
result = AMparseSexpr(str);
node = result[0];
str = result[1];
symbol = AMgetSymbol(str);
if (symbol.ttype == INFIX && symbol.input != "/") {
str = AMremoveCharsAndBlanks(str,symbol.input.length);
// if (symbol.input == "/") result = AMparseIexpr(str); else ...
result = AMparseSexpr(str);
if (result[0] == null) // show box in place of missing argument
result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
else AMremoveBrackets(result[0]);
str = result[1];
// if (symbol.input == "/") AMremoveBrackets(node);
if (symbol.input == "_") {
sym2 = AMgetSymbol(str);
underover = (sym1.ttype == UNDEROVER);
if (sym2.input == "^") {
str = AMremoveCharsAndBlanks(str,sym2.input.length);
var res2 = AMparseSexpr(str);
AMremoveBrackets(res2[0]);
str = res2[1];
node = createMmlNode((underover?"munderover":"msubsup"),node);
node.appendChild(result[0]);
node.appendChild(res2[0]);
node = createMmlNode("mrow",node); // so sum does not stretch
} else {
node = createMmlNode((underover?"munder":"msub"),node);
node.appendChild(result[0]);
}
} else {
node = createMmlNode(symbol.tag,node);
node.appendChild(result[0]);
}
}
return [node,str];
}
function AMparseExpr(str,rightbracket) {
var symbol, node, result, i, nodeList = [],
newFrag = document.createDocumentFragment();
do {
str = AMremoveCharsAndBlanks(str,0);
result = AMparseIexpr(str);
node = result[0];
str = result[1];
symbol = AMgetSymbol(str);
if (symbol.ttype == INFIX && symbol.input == "/") {
str = AMremoveCharsAndBlanks(str,symbol.input.length);
result = AMparseIexpr(str);
if (result[0] == null) // show box in place of missing argument
result[0] = createMmlNode("mo",document.createTextNode("\u25A1"));
else AMremoveBrackets(result[0]);
str = result[1];
AMremoveBrackets(node);
node = createMmlNode(symbol.tag,node);
node.appendChild(result[0]);
newFrag.appendChild(node);
symbol = AMgetSymbol(str);
}
else if (node!=undefined) newFrag.appendChild(node);
} while ((symbol.ttype != RIGHTBRACKET &&
(symbol.ttype != LEFTRIGHT || rightbracket)
|| AMnestingDepth == 0) && symbol!=null && symbol.output!="");
if (symbol.ttype == RIGHTBRACKET || symbol.ttype == LEFTRIGHT) {
// if (AMnestingDepth > 0) AMnestingDepth--;
var len = newFrag.childNodes.length;
if (len>0 && newFrag.childNodes.item(len-1).nodeName == "mrow" && len>1 &&
newFrag.childNodes.item(len-2).nodeName == "mo" &&
newFrag.childNodes.item(len-2).firstChild.nodeValue == ",") { //matrix
var right = newFrag.childNodes.item(len-1).lastChild.firstChild.nodeValue;
if (right==")" || right=="]") {
var left = newFrag.childNodes.item(len-1).firstChild.firstChild.nodeValue;
if (left=="(" && right==")" && symbol.output != "}" ||
left=="[" && right=="]") {
var pos = []; // positions of commas
var matrix = true;
var m = newFrag.childNodes.length;
for (i=0; matrix && i<m; i=i+2) {
pos[i] = [];
node = newFrag.childNodes.item(i);
if (matrix) matrix = node.nodeName=="mrow" &&
(i==m-1 || node.nextSibling.nodeName=="mo" &&
node.nextSibling.firstChild.nodeValue==",")&&
node.firstChild.firstChild.nodeValue==left &&
node.lastChild.firstChild.nodeValue==right;
if (matrix)
for (var j=0; j<node.childNodes.length; j++)
if (node.childNodes.item(j).firstChild.nodeValue==",")
pos[i][pos[i].length]=j;
if (matrix && i>1) matrix = pos[i].length == pos[i-2].length;
}
if (matrix) {
var row, frag, n, k, table = document.createDocumentFragment();
for (i=0; i<m; i=i+2) {
row = document.createDocumentFragment();
frag = document.createDocumentFragment();
node = newFrag.firstChild; // <mrow>(-,-,...,-,-)</mrow>
n = node.childNodes.length;
k = 0;
node.removeChild(node.firstChild); //remove (
for (j=1; j<n-1; j++) {
if (typeof pos[i][k] != "undefined" && j==pos[i][k]){
node.removeChild(node.firstChild); //remove ,
row.appendChild(createMmlNode("mtd",frag));
k++;
} else frag.appendChild(node.firstChild);
}
row.appendChild(createMmlNode("mtd",frag));
if (newFrag.childNodes.length>2) {
newFrag.removeChild(newFrag.firstChild); //remove <mrow>)</mrow>
newFrag.removeChild(newFrag.firstChild); //remove <mo>,</mo>
}
table.appendChild(createMmlNode("mtr",row));
}
node = createMmlNode("mtable",table);
if (typeof symbol.invisible == "boolean" && symbol.invisible) node.setAttribute("columnalign","left");
newFrag.replaceChild(node,newFrag.firstChild);
}
}
}
}
str = AMremoveCharsAndBlanks(str,symbol.input.length);
if (typeof symbol.invisible != "boolean" || !symbol.invisible) {
node = createMmlNode("mo",document.createTextNode(symbol.output));
newFrag.appendChild(node);
}
}
return [newFrag,str];
}
//MOD: The rest of the code is not required!
//-------------------------------------------------------------
/* ASCIIMathML.js has ended! */
initSymbols();
/* Parses the given ASCIIMathInput, returning a <math> DOM Element */
this.parseAsciiMathInput = function(asciiMathInput) {
var options = arguments[1] || {};
/* Call up ASCIIMath to do the actual parsing, generating a document fragment */
var content = AMparseExpr(asciiMathInput.replace(/^\s+/g,""), false)[0];
/* If adding source annotation, then we need to wrap things up appropriately */
if (options.addSourceAnnotation) {
var semantics = createMmlNode("semantics", content.length==1 ? content : createMmlNode("mrow", content));
var annotation = createMmlNode("annotation", document.createTextNode(asciiMathInput));
annotation.setAttribute("encoding", "ASCIIMathInput");
semantics.appendChild(annotation);
content = semantics;
}
/* Create the containing <math> element */
var math = createMmlNode("math", content);
if (options.displayMode) {
math.setAttribute("display", "block");
}
return math;
};
// (end of unindented constructor defined at top of file)
};
function plantuml(dom, asciiMathInput) {
var asciiMathParser = new AsciiMathParser(dom);
var mathElement = asciiMathParser.parseAsciiMathInput(asciiMathInput);
return mathElement;
}

View File

@ -0,0 +1,102 @@
package net.sourceforge.plantuml.math;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
public class AsciiMathSafe {
private AsciiMath math;
private final String form;
public AsciiMathSafe(String form) {
this.form = form;
try {
this.math = new AsciiMath(form);
} catch (Exception e) {
Log.info("Error parsing " + form);
}
}
public static void main(String[] args) throws IOException {
AsciiMathSafe math = new AsciiMathSafe("sum_(i=1)^n i^3=((n(n+1))/2)^2");
PrintWriter pw = new PrintWriter(new File("math2.svg"));
pw.println(math.getSvg());
pw.close();
ImageIO.write(math.getImage(), "png", new File("math2.png"));
}
private ImageData dimSvg;
public String getSvg() {
try {
final String svg = math.getSvg();
dimSvg = new ImageDataSimple(math.getDimension());
return svg;
} catch (Exception e) {
final ImageBuilder imageBuilder = getRollback();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
dimSvg = imageBuilder.writeImageTOBEMOVED(new FileFormatOption(FileFormat.SVG), baos);
} catch (IOException e1) {
return null;
}
return new String(baos.toByteArray());
}
}
public BufferedImage getImage() {
try {
return math.getImage();
} catch (Exception e) {
final ImageBuilder imageBuilder = getRollback();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
imageBuilder.writeImageTOBEMOVED(new FileFormatOption(FileFormat.PNG), baos);
return ImageIO.read(new ByteArrayInputStream(baos.toByteArray()));
} catch (IOException e1) {
return null;
}
}
}
private ImageBuilder getRollback() {
final TextBlock block = GraphicStrings.createBlackOnWhiteMonospaced(Arrays.asList(form));
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, null, null, null, 0, 0,
null, false);
imageBuilder.setUDrawable(block);
return imageBuilder;
}
public ImageData export(OutputStream os, FileFormatOption fileFormat) throws IOException {
if (fileFormat.getFileFormat() == FileFormat.PNG) {
final BufferedImage image = getImage();
ImageIO.write(image, "png", os);
return new ImageDataSimple(image.getWidth(), image.getHeight());
}
if (fileFormat.getFileFormat() == FileFormat.SVG) {
os.write(getSvg().getBytes());
return dimSvg;
}
return null;
}
}

View File

@ -0,0 +1,62 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.math;
import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
public class PSystemMath extends AbstractPSystem {
private String math = "";
public PSystemMath() {
}
public DiagramDescription getDescription() {
return new DiagramDescriptionImpl("(Math)", getClass());
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
AsciiMathSafe asciiMath = new AsciiMathSafe(math);
return asciiMath.export(os, fileFormat);
}
public void doCommandLine(String line) {
this.math = line;
}
}

View File

@ -26,47 +26,31 @@
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.turing;
package net.sourceforge.plantuml.math;
import net.sourceforge.plantuml.command.PSystemBasicFactory;
import net.sourceforge.plantuml.core.DiagramType;
public class PSystemTuringFactory extends PSystemBasicFactory<PSystemTuring> {
public class PSystemMathFactory extends PSystemBasicFactory<PSystemMath> {
private StringBuilder prg;
private StringBuilder input;
public PSystemTuringFactory() {
super(DiagramType.TURING);
public PSystemMathFactory(DiagramType type) {
super(type);
}
public PSystemTuring init(String startLine) {
prg = null;
input = null;
if ("@startturing".equalsIgnoreCase(startLine)) {
prg = new StringBuilder();
public PSystemMath init(String startLine) {
if (getDiagramType() == DiagramType.MATH) {
return new PSystemMath();
}
return null;
}
@Override
public PSystemTuring executeLine(PSystemTuring system, String line) {
if (prg == null) {
return null;
}
if (input == null) {
if (line.length() == 0) {
input = new StringBuilder();
} else {
prg.append(line);
prg.append('\n');
}
} else {
input.append(line);
input.append('\n');
}
return new PSystemTuring(prg.toString(), input == null ? "" : input.toString());
public PSystemMath executeLine(PSystemMath system, String line) {
system.doCommandLine(line);
return system;
}
}

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.openiconic;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -45,24 +44,22 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.openiconic.data.DummyIcon;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemListOpenIconic extends AbstractPSystem {
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
private TextBlockBackcolored getGraphicStrings() throws IOException {
final List<String> lines = new ArrayList<String>();
lines.add("<b>List Open Iconic");
lines.add("<i>Credit to");
@ -77,11 +74,7 @@ public class PSystemListOpenIconic extends AbstractPSystem {
}
br.close();
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final GraphicStrings graphicStrings = new GraphicStrings(lines, font, HtmlColorUtils.BLACK,
HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON);
graphicStrings.setMaxLine(35);
return graphicStrings;
return GraphicStrings.createBlackOnWhite(lines, null, null, 35);
}
private InputStream getRessourceAllTxt() {

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.oregon;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -43,11 +42,9 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemOregon extends AbstractPSystem {
@ -94,17 +91,15 @@ public class PSystemOregon extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("Monospaced", Font.PLAIN, 14);
return new GraphicStrings(getScreen().getLines(), font, HtmlColorUtils.GREEN, HtmlColorUtils.BLACK,
UAntiAliasing.ANTI_ALIASING_OFF);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createGreenOnBlackMonospaced(getScreen().getLines());
}
public DiagramDescription getDescription() {

View File

@ -44,7 +44,6 @@ import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.SplitParam;
import net.sourceforge.plantuml.graphic.HtmlColorSimple;
public class PngSplitter {

View File

@ -30,8 +30,6 @@
*/
package net.sourceforge.plantuml.preproc;
import gen.lib.pack.pack__c;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

View File

@ -34,7 +34,6 @@ import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.png.PngTitler;
import net.sourceforge.plantuml.utils.MathUtils;

View File

@ -78,7 +78,8 @@ public enum VisibilityModifier {
};
}
public TextBlock getUBlock(final int size, final HtmlColor foregroundColor, final HtmlColor backgoundColor) {
public TextBlock getUBlock(final int size, final HtmlColor foregroundColor, final HtmlColor backgoundColor,
final boolean withInvisibleRectanble) {
return new AbstractTextBlock() {
public Dimension2D calculateDimension(StringBounder stringBounder) {
@ -91,6 +92,9 @@ public enum VisibilityModifier {
}
public void drawU(UGraphic ug) {
if (withInvisibleRectanble) {
ug.apply(new UChangeColor(null)).draw(new URectangle(size * 2, size));
}
drawInternal(ug, size, foregroundColor, backgoundColor, 0, 0);
}
};

View File

@ -0,0 +1,90 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.stats;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import net.sourceforge.plantuml.FileFormat;
public class FormatCounter {
private ConcurrentMap<FileFormat, AtomicLong> data = new ConcurrentHashMap<FileFormat, AtomicLong>();
public FormatCounter() {
for (FileFormat format : FileFormat.values()) {
data.put(format, new AtomicLong());
}
}
public void plusOne(FileFormat fileFormat, long duration) {
final AtomicLong n = data.get(fileFormat);
n.addAndGet(1);
}
public void printTable(List<String> strings) {
Stats.addLine(strings, false, "Format", "#");
long total = 0;
for (Map.Entry<FileFormat, AtomicLong> ent : data.entrySet()) {
final long value = ent.getValue().get();
Stats.addLine(strings, false, ent.getKey().name(), value);
total += value;
}
Stats.addLine(strings, true, "Total", total);
}
public void reload(String prefix, Preferences prefs) throws BackingStoreException {
for (String key : prefs.keys()) {
if (key.startsWith(prefix)) {
try {
final FileFormat format = FileFormat.valueOf(key.substring(prefix.length()));
final long value = prefs.getLong(key, 0);
data.put(format, new AtomicLong(value));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public void save(String prefix, Preferences prefs, FileFormat fileFormat) {
final String key = prefix + fileFormat.name();
prefs.putLong(key, data.get(fileFormat).get());
}
}

View File

@ -27,9 +27,8 @@
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.turing;
package net.sourceforge.plantuml.stats;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -40,47 +39,38 @@ import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemTuring extends AbstractPSystem {
public class PSystemStats extends AbstractPSystem {
private final String program;
private final String input;
private final List<String> strings = new ArrayList<String>();
PSystemTuring(String program, String input) {
this.program = program;
this.input = input;
PSystemStats() throws IOException {
final Stats stats = StatsUtils.getStats();
stats.printMe(strings);
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
final List<String> strings = new ArrayList<String>();
final BFMachine machine = new BFMachine(program, input);
/* final boolean ok = */machine.run();
final String output = machine.getOutput();
for (String s : output.split("\n")) {
strings.add(s);
public static PSystemStats create() throws IOException {
return new PSystemStats();
}
final UFont font = new UFont("Monospaced", Font.PLAIN, 14);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON,
null, GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {
return new DiagramDescriptionImpl("(Turing)", getClass());
return new DiagramDescriptionImpl("(Stats)", getClass());
}
}

View File

@ -26,22 +26,25 @@
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.eggs;
package net.sourceforge.plantuml.stats;
import java.io.IOException;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.command.PSystemSingleLineFactory;
import net.sourceforge.plantuml.webp.Portrait;
import net.sourceforge.plantuml.webp.Portraits;
public class PSystemMemorialFactory extends PSystemSingleLineFactory {
public class PSystemStatsFactory extends PSystemSingleLineFactory {
@Override
protected AbstractPSystem executeLine(String line) {
final Portrait portrait = Portraits.getOne(line);
if (portrait != null) {
return new PSystemMemorial(portrait);
try {
if (line.matches("(?i)^stats\\s*$")) {
return PSystemStats.create();
}
} catch (IOException e) {
Log.error("Error " + e);
}
return null;
}

View File

@ -0,0 +1,134 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.stats;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentMap;
import net.sourceforge.plantuml.api.NumberAnalyzed;
public class Stats {
private final long firstEverStartingTime;
private final long lastStartingTime;
private final long currentStartingTime;
private final long jvmcounting;
private final Map<String, NumberAnalyzed> parsingEver;
private final Map<String, NumberAnalyzed> generatingEver;
private final Map<String, NumberAnalyzed> parsingCurrent;
private final Map<String, NumberAnalyzed> generatingCurrent;
private final FormatCounter formatCounterCurrent;
private final FormatCounter formatCounterEver;
Stats(long firstEverStartingTime, long lastStartingTime, long thisStartingTime, long jvmcounting,
Map<String, NumberAnalyzed> parsingEver, Map<String, NumberAnalyzed> generatingEver,
ConcurrentMap<String, NumberAnalyzed> parsingCurrent,
ConcurrentMap<String, NumberAnalyzed> generatingCurrent, FormatCounter formatCounterCurrent,
FormatCounter formatCounterEver) {
this.firstEverStartingTime = firstEverStartingTime;
this.lastStartingTime = lastStartingTime;
this.currentStartingTime = thisStartingTime;
this.jvmcounting = jvmcounting;
this.parsingEver = parsingEver;
this.generatingEver = generatingEver;
this.parsingCurrent = parsingCurrent;
this.generatingCurrent = generatingCurrent;
this.formatCounterCurrent = formatCounterCurrent;
this.formatCounterEver = formatCounterEver;
}
public void printMe(List<String> strings) {
strings.add("<b><size:16>Statistics</b>");
strings.add("| Parameter | Value |");
strings.add("| <i>First Starting Time Ever</i> | " + new Date(firstEverStartingTime) + "|");
strings.add("| <i>Last Starting Time</i> | " + new Date(lastStartingTime) + "|");
strings.add("| <i>Current Starting Time</i> | " + new Date(currentStartingTime) + "|");
strings.add("| <i>Total launch</i> | " + jvmcounting + "|");
strings.add(" ");
strings.add("<b><size:16>Current session statistics</b>");
printTable(strings, parsingCurrent, generatingCurrent);
strings.add(" ");
formatCounterCurrent.printTable(strings);
strings.add(" ");
strings.add("<b><size:16>General statistics since ever</b>");
printTable(strings, parsingEver, generatingEver);
strings.add(" ");
formatCounterEver.printTable(strings);
}
private static void printTable(List<String> strings, Map<String, NumberAnalyzed> parsingEver,
Map<String, NumberAnalyzed> generatingEver) {
final TreeSet<String> keys = new TreeSet<String>(parsingEver.keySet());
keys.addAll(generatingEver.keySet());
addLine(strings, false, "Diagram type", "# Parsed", "Mean parsing\\ntime (ms)", "Max parsing\\ntime (ms)",
"# Generated", "Mean generation\\ntime (ms)", "Max generation\\ntime (ms)");
NumberAnalyzed totalParsing = new NumberAnalyzed();
NumberAnalyzed totalGenerating = new NumberAnalyzed();
for (String key : keys) {
NumberAnalyzed parse = parsingEver.get(key);
if (parse == null) {
parse = new NumberAnalyzed();
}
NumberAnalyzed generate = generatingEver.get(key);
if (generate == null) {
generate = new NumberAnalyzed();
}
totalParsing.add(parse);
totalGenerating.add(generate);
addLine(strings, false, key, parse.getNb(), parse.getMean(), parse.getMax(), generate.getNb(),
generate.getMean(), generate.getMax());
}
addLine(strings, true, "Total", totalParsing.getNb(), totalParsing.getMean(), totalParsing.getMax(),
totalGenerating.getNb(), totalGenerating.getMean(), totalGenerating.getMax());
}
static void addLine(List<String> strings, boolean bold, Object... data) {
final StringBuilder result = new StringBuilder();
for (Object v : data) {
result.append("| ");
if (bold) {
result.append("<b>");
}
result.append(v.toString());
if (bold) {
result.append("</b>");
}
result.append(" ");
}
result.append("|");
strings.add(result.toString());
}
}

View File

@ -0,0 +1,175 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.stats;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.core.Diagram;
public class StatsUtils {
public static void onceMoreParse(long duration, Class<? extends Diagram> type) {
}
public static void onceMoreGenerate(long duration, Class<? extends Diagram> type, FileFormat fileFormat) {
}
public static Stats getStats() {
return null;
}
// final private static Preferences prefs = Preferences.userNodeForPackage(StatsUtils.class);
//
// private static long firstEverStartingTime;
// private static long lastStartingTime;
// private static final long currentStartingTime;
// private static final long jvmCounting;
//
// private static ConcurrentMap<String, NumberAnalyzed> parsingEver = new ConcurrentHashMap<String,
// NumberAnalyzed>();
// private static ConcurrentMap<String, NumberAnalyzed> generatingEver = new ConcurrentHashMap<String,
// NumberAnalyzed>();
// private static ConcurrentMap<String, NumberAnalyzed> parsingCurrent = new ConcurrentHashMap<String,
// NumberAnalyzed>();
// private static ConcurrentMap<String, NumberAnalyzed> generatingCurrent = new ConcurrentHashMap<String,
// NumberAnalyzed>();
//
// private static FormatCounter formatCounterCurrent = new FormatCounter();
// private static FormatCounter formatCounterEver = new FormatCounter();
//
// public static void onceMoreParse(long duration, Class<? extends Diagram> type) {
// getNumber("parse.", type, parsingCurrent).addValue(duration);
// final NumberAnalyzed n1 = getNumber("parse.", type, parsingEver);
// n1.addValue(duration);
// n1.save(prefs);
// }
//
// public static void onceMoreGenerate(long duration, Class<? extends Diagram> type, FileFormat fileFormat) {
// getNumber("generate.", type, generatingCurrent).addValue(duration);
// final NumberAnalyzed n1 = getNumber("generate.", type, generatingEver);
// n1.addValue(duration);
// formatCounterCurrent.plusOne(fileFormat, duration);
// formatCounterEver.plusOne(fileFormat, duration);
// formatCounterEver.save("format.", prefs, fileFormat);
// n1.save(prefs);
// }
//
// public static Stats getStats() {
// return new Stats(firstEverStartingTime, lastStartingTime, currentStartingTime, jvmCounting, parsingEver,
// generatingEver, parsingCurrent, generatingCurrent, formatCounterCurrent, formatCounterEver);
// }
//
// private static NumberAnalyzed getNumber(String prefix, Class<? extends Diagram> type,
// ConcurrentMap<String, NumberAnalyzed> map) {
// final String name = name(type);
// NumberAnalyzed n = map.get(name);
// if (n == null) {
// map.putIfAbsent(name, new NumberAnalyzed(prefix + name));
// n = map.get(name);
// }
// return n;
// }
//
// private static String name(Class<? extends Diagram> type) {
// if (type == PSystemError.class) {
// return "Error";
// }
// if (type == ActivityDiagram3.class) {
// return "ActivityDiagramBeta";
// }
// if (type == PSystemSalt.class) {
// return "Salt";
// }
// if (type == PSystemSudoku.class) {
// return "Sudoku";
// }
// if (type == PSystemDot.class) {
// return "Dot";
// }
// if (type == PSystemEmpty.class) {
// return "Welcome";
// }
// if (type == PSystemDitaa.class) {
// return "Ditaa";
// }
// if (type == PSystemJcckit.class) {
// return "Jcckit";
// }
// final String name = type.getSimpleName();
// if (name.endsWith("Diagram")) {
// return name;
// }
// // return "Other " + name;
// return "Other";
// }
//
// static {
// // try {
// // prefs.clear();
// // } catch (BackingStoreException e1) {
// // e1.printStackTrace();
// // }
// currentStartingTime = System.currentTimeMillis();
// firstEverStartingTime = prefs.getLong("firstEverStartingTime", 0);
// if (firstEverStartingTime == 0) {
// firstEverStartingTime = currentStartingTime;
// prefs.putLong("firstEverStartingTime", firstEverStartingTime);
// }
// lastStartingTime = prefs.getLong("lastStartingTime", 0);
// if (lastStartingTime == 0) {
// lastStartingTime = currentStartingTime;
// }
// prefs.putLong("lastStartingTime", currentStartingTime);
// jvmCounting = prefs.getLong("JVMcounting", 0) + 1;
// prefs.putLong("JVMcounting", jvmCounting);
// try {
// reload("parse.", parsingEver);
// reload("generate.", generatingEver);
// formatCounterEver.reload("format.", prefs);
// } catch (BackingStoreException e) {
// Log.error("Error reloading stats " + e);
// parsingEver.clear();
// generatingEver.clear();
// }
// }
//
// private static void reload(final String tree, Map<String, NumberAnalyzed> data) throws BackingStoreException {
// for (String key : prefs.keys()) {
// if (key.startsWith(tree) && key.endsWith(".nb")) {
// final String name = key.substring(0, key.length() - 3);
// final NumberAnalyzed numberAnalyzed = NumberAnalyzed.load(name, prefs);
// if (numberAnalyzed != null) {
// data.put(name.substring(tree.length()), numberAnalyzed);
// }
// }
// }
// }
}

View File

@ -257,7 +257,7 @@ public final class DotDataImageBuilder {
msg.add(" ");
msg.add("java -jar plantuml.jar -testdot");
msg.add(" ");
return GraphicStrings.createDefault(msg, false);
return GraphicStrings.createForError(msg, false);
}
private void printEntities(DotStringFactory dotStringFactory, Collection<ILeaf> entities2) {

View File

@ -30,13 +30,13 @@
*/
package net.sourceforge.plantuml.svek;
import java.awt.Font;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.OptionPrint;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
import net.sourceforge.plantuml.flashcode.FlashCodeUtils;
@ -48,8 +48,6 @@ import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.graphic.QuoteUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.UTranslate;
@ -57,16 +55,14 @@ import net.sourceforge.plantuml.version.Version;
public class GraphvizCrash extends AbstractTextBlock implements IEntityImage {
private static final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
private final GraphicStrings graphicStrings;
private final TextBlockBackcolored graphicStrings;
private final BufferedImage flashCode;
public GraphvizCrash(String text) {
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
flashCode = utils.exportFlashcode(text);
this.graphicStrings = new GraphicStrings(init(), font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
UAntiAliasing.ANTI_ALIASING_ON, IconLoader.getRandom(), GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
this.graphicStrings = GraphicStrings.createBlackOnWhite(init(), IconLoader.getRandom(),
GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
}
public static List<String> anErrorHasOccured(Throwable exception) {
@ -108,7 +104,6 @@ public class GraphvizCrash extends AbstractTextBlock implements IEntityImage {
strings.add(" - a problem in GraphViz");
}
private List<String> init() {
final List<String> strings = anErrorHasOccured(null);
strings.add("For some reason, dot/Graphviz has crashed.");
@ -138,17 +133,13 @@ public class GraphvizCrash extends AbstractTextBlock implements IEntityImage {
}
public static void addProperties(final List<String> strings) {
addTextProperty(strings, "os.version");
addTextProperty(strings, "os.name");
addTextProperty(strings, "java.vm.vendor");
addTextProperty(strings, "java.vm.version");
addTextProperty(strings, "java.version");
addTextProperty(strings, "user.language");
strings.addAll(OptionPrint.interestingProperties());
strings.addAll(OptionPrint.interestingValues());
}
private static void addTextProperty(final List<String> strings, String prop) {
strings.add(prop + ": " + System.getProperty(prop));
}
// private static void addTextProperty(final List<String> strings, String prop) {
// strings.add(prop + ": " + System.getProperty(prop));
// }
public boolean isHidden() {
return false;

View File

@ -86,7 +86,7 @@ public class EntityImageClassHeader2 extends AbstractEntityImage {
final HtmlColor back = rose.getHtmlColor(skinParam, modifier.getBackground());
final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground());
final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back);
final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back, false);
name = TextBlockUtils.mergeLR(uBlock, name, VerticalAlignment.CENTER);
name = TextBlockUtils.withMargin(name, 3, 3, 0, 0);
}

View File

@ -411,6 +411,8 @@ public class SvgGraphics {
String textBackColor) {
if (hidden == false) {
final Element elt = (Element) document.createElement("text");
// required for web-kit based browsers
// elt.setAttribute("text-rendering", "geometricPrecision");
elt.setAttribute("x", format(x));
elt.setAttribute("y", format(y));
elt.setAttribute("fill", fill);

View File

@ -71,6 +71,7 @@ import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.GeneratedImage;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.version.PSystemVersion;
@ -279,7 +280,7 @@ class ImageWindow2 extends JFrame {
}
} catch (IOException ex) {
final String msg = "Error reading file: " + ex.toString();
final GraphicStrings error = GraphicStrings.createDefault(Arrays.asList(msg), false);
final TextBlockBackcolored error = GraphicStrings.createForError(Arrays.asList(msg), false);
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, error.getBackcolor(),
null, null, 0, 0, null, false);
imageBuilder.setUDrawable(error);

View File

@ -103,7 +103,7 @@ public class MainWindow2 extends JFrame {
}
private String getDefaultFileExtensions() {
return "txt, tex, java, htm, html, c, h, cpp, apt, pu";
return "txt, tex, java, htm, html, c, h, cpp, apt, pu, puml";
}
private void changeExtensions(String ext) {

View File

@ -58,12 +58,14 @@ public class TikzGraphics {
private Color color = Color.BLACK;
private Color fillcolor = Color.BLACK;
private double thickness = 1.0;
private final double scale;
private String dash = null;
private final Map<Color, String> colornames = new LinkedHashMap<Color, String>();
public TikzGraphics(boolean withPreamble) {
public TikzGraphics(double scale, boolean withPreamble) {
this.withPreamble = withPreamble;
this.scale = scale;
}
private String getColorName(Color c) {
@ -130,11 +132,17 @@ public class TikzGraphics {
out(os, definecolor(ent.getValue(), ent.getKey()));
}
if (scale != 1) {
out(os, "\\scalebox{" + format(scale) + "}{");
}
out(os, "\\begin{tikzpicture}[yscale=-1]");
for (String s : cmd) {
out(os, s);
}
out(os, "\\end{tikzpicture}");
if (scale != 1) {
out(os, "}");
}
if (withPreamble) {
out(os, "\\end{document}");
}

View File

@ -369,9 +369,9 @@ public class ImageBuilder {
case VDX:
return new UGraphicVdx(colorMapper);
case LATEX:
return new UGraphicTikz(colorMapper, true);
return new UGraphicTikz(colorMapper, dpiFactor, true);
case LATEX_NO_PREAMBLE:
return new UGraphicTikz(colorMapper, false);
return new UGraphicTikz(colorMapper, dpiFactor, false);
case BRAILLE_PNG:
return new UGraphicBraille(colorMapper, fileFormat);
default:

View File

@ -37,7 +37,6 @@ import net.sourceforge.plantuml.EnsureVisible;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
public class UGraphicNull extends AbstractUGraphic<String> implements EnsureVisible, UGraphic2 {

View File

@ -30,7 +30,6 @@
*/
package net.sourceforge.plantuml.ugraphic.sprite;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -42,23 +41,21 @@ import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemListInternalSprites extends AbstractPSystem {
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormat, os);
}
private GraphicStrings getGraphicStrings() throws IOException {
private TextBlockBackcolored getGraphicStrings() throws IOException {
final List<String> lines = new ArrayList<String>();
lines.add("<b>List Current Sprits");
lines.add("<i>Credit to");
@ -75,11 +72,7 @@ public class PSystemListInternalSprites extends AbstractPSystem {
}
}
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
final GraphicStrings graphicStrings = new GraphicStrings(lines, font, HtmlColorUtils.BLACK,
HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON);
graphicStrings.setMaxLine(35);
return graphicStrings;
return GraphicStrings.createBlackOnWhite(lines, null, null, 35);
}
public DiagramDescription getDescription() {

View File

@ -64,8 +64,8 @@ public class UGraphicTikz extends AbstractUGraphic<TikzGraphics> implements Clip
}
public UGraphicTikz(ColorMapper colorMapper, boolean withPreamble) {
this(colorMapper, new TikzGraphics(withPreamble));
public UGraphicTikz(ColorMapper colorMapper, double scale, boolean withPreamble) {
this(colorMapper, new TikzGraphics(scale, withPreamble));
}

View File

@ -29,7 +29,6 @@
*/
package net.sourceforge.plantuml.version;
import java.awt.Font;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -40,13 +39,10 @@ import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.DiagramDescriptionImpl;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemLicense extends AbstractPSystem {
@ -57,7 +53,7 @@ public class PSystemLicense extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = getGraphicStrings();
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
@ -68,10 +64,8 @@ public class PSystemLicense extends AbstractPSystem {
return new PSystemLicense();
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON,
null, GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
private TextBlockBackcolored getGraphicStrings() throws IOException {
return GraphicStrings.createBlackOnWhite(strings);
}
public DiagramDescription getDescription() {

View File

@ -29,7 +29,6 @@
*/
package net.sourceforge.plantuml.version;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
@ -41,7 +40,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -57,11 +55,9 @@ import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
import net.sourceforge.plantuml.ugraphic.UFont;
public class PSystemVersion extends AbstractPSystem {
@ -134,7 +130,8 @@ public class PSystemVersion extends AbstractPSystem {
}
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException {
final GraphicStrings result = getGraphicStrings();
final TextBlockBackcolored result = GraphicStrings.createBlackOnWhite(strings, image,
GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
imageBuilder.setUDrawable(result);
@ -150,9 +147,8 @@ public class PSystemVersion extends AbstractPSystem {
strings.addAll(GraphvizUtils.getTestDotStrings(true));
strings.add(" ");
final Properties p = System.getProperties();
for (String name : OptionPrint.interestingProperties()) {
strings.add(p.getProperty(name));
strings.add(name);
}
for (String v : OptionPrint.interestingValues()) {
strings.add(v);
@ -260,12 +256,6 @@ public class PSystemVersion extends AbstractPSystem {
return new PSystemVersion(false, strings);
}
private GraphicStrings getGraphicStrings() throws IOException {
final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
UAntiAliasing.ANTI_ALIASING_ON, image, GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT);
}
public DiagramDescription getDescription() {
return new DiagramDescriptionImpl("(Version)", getClass());
}

View File

@ -0,0 +1,114 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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.version;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.prefs.Preferences;
import net.sourceforge.plantuml.OptionPrint;
import net.sourceforge.plantuml.dedication.DecoderInputStream;
import net.sourceforge.plantuml.dedication.Dedication;
import net.sourceforge.plantuml.dedication.QBlocks;
public class Professionnal {
final private static Preferences prefs = Preferences.userNodeForPackage(Professionnal.class);
private final String hostname;
private final String organization;
private final String mail;
private final Date date1;
private final Date date2;
private Professionnal(String hostname, String organization, String mail, int date1, int date2) {
this.hostname = hostname;
this.organization = organization;
this.mail = mail;
this.date1 = new Date(date1 * 1000L);
this.date2 = new Date(date2 * 1000L);
}
public static Professionnal decodeNow(final String license) throws IOException {
final QBlocks data = QBlocks.descodeAscii(license);
final QBlocks decrypted = data.change(Dedication.E, Dedication.N);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
decrypted.writeTo(baos, Dedication.SIZE);
baos.close();
final String hostname = OptionPrint.getHostName();
InputStream source1 = null;
try {
source1 = new DecoderInputStream(new ByteArrayInputStream(baos.toByteArray()), hostname);
final DataInputStream src = new DataInputStream(source1);
final int version = src.readByte();
if (version != 42) {
throw new IOException();
}
final String host1 = src.readUTF();
final String organization = src.readUTF();
final String mail = src.readUTF();
final int date1 = src.readInt();
final int date2 = src.readInt();
return new Professionnal(host1, organization, mail, date1, date2);
} finally {
if (source1 != null) {
source1.close();
}
}
}
public String getHostname() {
return hostname;
}
public String getMail() {
return mail;
}
public String getOrganization() {
return organization;
}
public Date getDate1() {
return date1;
}
public Date getDate2() {
return date2;
}
}

View File

@ -36,7 +36,7 @@ import java.util.Date;
public class Version {
public static int version() {
return 8049;
return 8050;
}
public static String versionString() {
@ -68,7 +68,7 @@ public class Version {
}
public static long compileTime() {
return 1478283413822L;
return 1479491794397L;
}
public static String compileTimeString() {