Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements svg #168

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Bundle-ManifestVersion: 2
Bundle-Name: ELK
Bundle-SymbolicName: net.sourceforge.plantuml.lib.elk
Bundle-Version: 0.7.1
Fragment-Host: net.sourceforge.plantuml.lib;bundle-version="1.2022.1"
Fragment-Host: net.sourceforge.plantuml.lib;bundle-version="1.2023.5"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: lib/elk-full.jar
2 changes: 1 addition & 1 deletion bundles/net.sourceforge.plantuml.lib/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/plantuml-epl-1.2022.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/plantuml-epl-1.2023.5.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
10 changes: 5 additions & 5 deletions bundles/net.sourceforge.plantuml.lib/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plantuml library plug-in
Bundle-SymbolicName: net.sourceforge.plantuml.lib
Bundle-Version: 1.2022.1
Bundle-Version: 1.2023.5
Bundle-Vendor: PlantUML Team
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: net.sourceforge.plantuml;version="1.2022.1",
net.sourceforge.plantuml.core;version="1.2022.1",
net.sourceforge.plantuml.security;version="1.2022.1"
Bundle-ClassPath: lib/plantuml-epl-1.2022.1.jar
Export-Package: net.sourceforge.plantuml;version="1.2023.5",
net.sourceforge.plantuml.core;version="1.2023.5",
net.sourceforge.plantuml.security;version="1.2023.5"
Bundle-ClassPath: lib/plantuml-epl-1.2023.5.jar
2 changes: 1 addition & 1 deletion bundles/net.sourceforge.plantuml.lib/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin.includes = META-INF/,\
epl-v10.html,\
lib/,\
lib/plantuml-epl-1.2022.1.jar
lib/plantuml-epl-1.2023.5.jar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public abstract class AbstractSvg2HtmlConverter implements Svg2HtmlConverter {
protected AbstractSvg2HtmlConverter() {
}

protected final String idAttrPrefix = "<svg", idAttr = " id='plantuml'";
protected final String idAttrPrefix = "<svg", idAttr = " id=\"plantuml\"";

protected String cleanSvg(String svg) {
if (svg.startsWith("<?xml")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,133 +1,136 @@
package net.sourceforge.plantuml.eclipse.svg;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

import net.sourceforge.plantuml.eclipse.Activator;
import net.sourceforge.plantuml.eclipse.imagecontrol.ILinkSupport;
import net.sourceforge.plantuml.eclipse.views.AbstractPlantUmlView;
import net.sourceforge.plantuml.util.DiagramData;

public class PlantUmlSvgView extends AbstractPlantUmlView implements ILinkSupport {

private Browser browser;

private Svg2HtmlConverter svg2HtmlConverter;

@Override
protected void createDiagramControl(final Composite parent) {
final GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
parent.setLayout(layout);
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
browser.setJavascriptEnabled(true);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(final LocationEvent event) {
openLink(event.location);
}

@Override
public void changed(final LocationEvent event) {
}
});
svg2HtmlConverter = new SvgMustache2HtmlConverter();
}

@Override
public void dispose() {
browser = null;
super.dispose();
}

/**
* Passing the focus request to the viewer's control.
*/
@Override
public void setFocus() {
if (isValidControl(browser)) {
browser.setFocus();
}
}

protected void updateSvg2HtmlConverter() {
if (svg2HtmlConverter instanceof SvgMustache2HtmlConverter) {
final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
final String templateUrlPreference = SvgPreferencePage.getTemplateUrlPreference(preferenceStore);
((SvgMustache2HtmlConverter) svg2HtmlConverter).setTemplateUrl(templateUrlPreference);
}
}

private String diagramHtml = null;

@Override
protected void updateDiagram(final DiagramData diagramData, final IProgressMonitor monitor) {
final String svg = diagramData.getSvg(0);
updateSvg2HtmlConverter();
this.diagramHtml = svg2HtmlConverter.convert2Html(svg);
setDiagramViewStatus(ViewStatus.DIAGRAM_VIEW_DATA, diagramHtml);
asyncExec(() -> {
if (isValidControl(browser) && shouldUpdateView(diagramData)) {
browser.setText(diagramHtml);
setDiagramViewStatus(ViewStatus.DIAGRAM_VIEW, diagramHtml);
}
});
}

@Override
public Object getLink(final int x, final int y) {
return null;
}

//

@Override
protected void addViewActions(final IContributionManager toolBarManager) {
super.addViewActions(toolBarManager);
addActions(toolBarManager, new Action("Open in external browser", ImageDescriptor.createFromFile(this.getClass(), "/icons/external_browser.png")) {
@Override
public void run() {
openInBrowser(true);
}
});
}

private final int browserStyle = IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.STATUS;

protected void openInBrowser(final boolean external) {
if (this.diagramHtml != null) {
try {
final IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
final IWebBrowser extBrowser = (external ? browserSupport.getExternalBrowser()
: browserSupport.createBrowser(browserStyle, toString(), getPartName(), getTitle()));
final Path tempFile = Files.createTempFile(getClass().getSimpleName(), ".html");
Files.write(tempFile, this.diagramHtml.getBytes());
extBrowser.openURL(tempFile.toUri().toURL());
} catch (final PartInitException e) {
// couldn't open browser
} catch (final IOException e) {
// couldn't write to temp file
}
}
}
}
package net.sourceforge.plantuml.eclipse.svg;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;

import net.sourceforge.plantuml.eclipse.Activator;
import net.sourceforge.plantuml.eclipse.imagecontrol.ILinkSupport;
import net.sourceforge.plantuml.eclipse.views.AbstractPlantUmlView;
import net.sourceforge.plantuml.util.DiagramData;

public class PlantUmlSvgView extends AbstractPlantUmlView implements ILinkSupport {

private Browser browser;

private Svg2HtmlConverter svg2HtmlConverter;

@Override
protected void createDiagramControl(final Composite parent) {
final GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
parent.setLayout(layout);
browser = new Browser(parent, SWT.NONE);
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
browser.setJavascriptEnabled(true);
browser.addLocationListener(new LocationListener() {
@Override
public void changing(final LocationEvent event) {
openLink(event.location);
if(!"about:blank".equals(event.location)) {
event.doit = false;
}
}

@Override
public void changed(final LocationEvent event) {
}
});
svg2HtmlConverter = new SvgMustache2HtmlConverter();
}

@Override
public void dispose() {
browser = null;
super.dispose();
}

/**
* Passing the focus request to the viewer's control.
*/
@Override
public void setFocus() {
if (isValidControl(browser)) {
browser.setFocus();
}
}

protected void updateSvg2HtmlConverter() {
if (svg2HtmlConverter instanceof SvgMustache2HtmlConverter) {
final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
final String templateUrlPreference = SvgPreferencePage.getTemplateUrlPreference(preferenceStore);
((SvgMustache2HtmlConverter) svg2HtmlConverter).setTemplateUrl(templateUrlPreference);
}
}

private String diagramHtml = null;

@Override
protected void updateDiagram(final DiagramData diagramData, final IProgressMonitor monitor) {
final String svg = diagramData.getSvg(0);
updateSvg2HtmlConverter();
this.diagramHtml = svg2HtmlConverter.convert2Html(svg);
setDiagramViewStatus(ViewStatus.DIAGRAM_VIEW_DATA, diagramHtml);
asyncExec(() -> {
if (isValidControl(browser) && shouldUpdateView(diagramData)) {
browser.setText(diagramHtml);
setDiagramViewStatus(ViewStatus.DIAGRAM_VIEW, diagramHtml);
}
});
}

@Override
public Object getLink(final int x, final int y) {
return null;
}

//

@Override
protected void addViewActions(final IContributionManager toolBarManager) {
super.addViewActions(toolBarManager);
addActions(toolBarManager, new Action("Open in external browser", ImageDescriptor.createFromFile(this.getClass(), "/icons/external_browser.png")) {
@Override
public void run() {
openInBrowser(true);
}
});
}

private final int browserStyle = IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR | IWorkbenchBrowserSupport.STATUS;

protected void openInBrowser(final boolean external) {
if (this.diagramHtml != null) {
try {
final IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
final IWebBrowser extBrowser = (external ? browserSupport.getExternalBrowser()
: browserSupport.createBrowser(browserStyle, toString(), getPartName(), getTitle()));
final Path tempFile = Files.createTempFile(getClass().getSimpleName(), ".html");
Files.write(tempFile, this.diagramHtml.getBytes());
extBrowser.openURL(tempFile.toUri().toURL());
} catch (final PartInitException e) {
// couldn't open browser
} catch (final IOException e) {
// couldn't write to temp file
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String convert2Html(final String svg) {
final Template template = getTemplate();
final Map<String, Object> context = getTemplateContext(svg);
final String converted = template.execute(context);
return converted;
return converted.replace("\r\n", "\n");
} catch (final Exception e) {
return "<verbatim>" + e.getMessage() + "</verbatim>";
}
Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions features/net.sourceforge.plantuml.lib.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="net.sourceforge.plantuml.lib.feature"
label="%featureName"
version="1.2022.1"
version="1.2023.5"
provider-name="PlantUML Team">

<description url="http://plantuml.sourceforge.net/">
Expand All @@ -21,6 +21,6 @@
id="net.sourceforge.plantuml.lib"
download-size="0"
install-size="0"
version="1.2022.1"/>
version="1.2023.5"/>

</feature>
2 changes: 1 addition & 1 deletion releng/net.sourceforge.plantuml.composite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/gh-pages/plantuml.lib/1.2022.1</outputDirectory>
<outputDirectory>${basedir}/target/gh-pages/plantuml.lib/1.2023.5</outputDirectory>
<resources>
<resource>
<directory>../net.sourceforge.plantuml.lib.repository/target/repository</directory>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<feature url="features/net.sourceforge.plantuml.lib.feature_1.2022.1.jar" id="net.sourceforge.plantuml.lib.feature" version="1.2022.1">
<feature url="features/net.sourceforge.plantuml.lib.feature_1.2023.5.jar" id="net.sourceforge.plantuml.lib.feature" version="1.2023.5">
<category name="net.sourceforge.plantuml.lib.feature"/>
</feature>
<feature url="features/net.sourceforge.plantuml.lib.jlatexmath.feature_1.0.7.jar" id="net.sourceforge.plantuml.lib.jlatexmath.feature" version="1.0.7">
Expand Down