Skip to content

Commit

Permalink
klighd.piccolo.freehep, klighd.piccolo.test, klighd.ui: some improvem…
Browse files Browse the repository at this point in the history
…ents in changes for #44 as suggested by reviewers
  • Loading branch information
sailingKieler authored and NiklasRentzCAU committed Sep 18, 2020
1 parent b3daa34 commit 307dc41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,6 @@ public void writeHeader() throws IOException {
os.println(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
os.println(" xmlns:ev=\"http://www.w3.org/2001/xml-events\"");
os.println(" xmlns:klighd=\"http://de.cau.cs.kieler/klighd\"");
// KIPRA-1637: preserve multiple spaces when displaying an svg
// this affects all <text> elements of the document
os.println(" xml:space=\"preserve\"");
}
os.println(" x=\"" + x + "px\"");
os.println(" y=\"" + y + "px\"");
Expand Down Expand Up @@ -858,14 +855,18 @@ protected void writeString(String str, double x, double y)
}
style.put("stroke", "none");

// related to KIPRA-1637: preserve multiple spaces when displaying text strings
if (isProperty(STYLABLE))
style.put("white-space", "pre");
else
// avoid using the deprecated property 'xml:space' (https://docs.w3cub.com/svg/attribute/xml:space/)
// and sneak in the (css-based) replacement (https://www.w3schools.com/cssref/pr_text_white-space.asp)
// via a 'style' property definition
style.put("style", "white-space: pre");

// convert tags to string values
str = XMLWriter.normalizeText(str);

// replace leading space by &#00a0; otherwise firefox 1.5 fails
if (str.startsWith(" ")) {
str = "&#x00a0;" + str.substring(1);
}

final AffineTransform textOffset = new AffineTransform(1, 0, 0, 1, x, y);
textOffset.concatenate(getTransform());
final boolean isSingleLine = str.indexOf('\n') == -1;
Expand Down Expand Up @@ -907,7 +908,7 @@ protected void writeString(String str, double x, double y)

private String getTextsString(String text, Properties style, String indentation) {
final String[] lines = text.split("\\r?\\n|\\r");
final boolean isMultiLine = lines.length > 1;
final boolean isSingleLine = lines.length <= 1;
final StringBuffer content = new StringBuffer();

int i = 0;
Expand All @@ -933,15 +934,15 @@ private String getTextsString(String text, Properties style, String indentation)
// if we have a multi-line text and a configured nextTextLength
// we need to recalculate the designated textLength per line
// otherwise we can stick to the given 'nextTextLength' value
boolean noTextLengthPerLineCalcRequired = nextLength == null || !isMultiLine;
boolean noTextLengthPerLineCalcRequired = nextLength == null || isSingleLine;
final FontData fontData = noTextLengthPerLineCalcRequired ? null : getFontData(getFont());

float y = firstLineHeight;
for (final String line : lines) {
content.append("\n" + indentation);
content.append("<text x=\"0\" y=\"").append(y).append("\"");
// style
content.append(isMultiLine ? "" : " " + style(style));
content.append(isSingleLine ? " " + style(style) : "");

final Double nextLineLength = noTextLengthPerLineCalcRequired ? nextLength :
// need to box the result here as the type of the ternary operation would be 'double' otherwise
Expand All @@ -951,7 +952,8 @@ private String getTextsString(String text, Properties style, String indentation)
// text length
content.append(textLength(nextLineLength));
// semantic data
content.append(isMultiLine ? tSpanAttributes(line, i++) : attributes(false));
content.append(isSingleLine ? attributes(false) : "");
content.append(textLineAttributes(line, i++));
content.append(">");
content.append(line);
content.append("</text>");
Expand All @@ -962,18 +964,18 @@ private String getTextsString(String text, Properties style, String indentation)
} else {
// without a display just use the pt size as line height for multiline text

// use tspans to emulate multiline text
final int fontSize = getFont().getSize();
float y = fontSize;
for (final String line : lines) {
content.append("\n" + indentation);
content.append("<text x=\"0\" y=\"").append(y).append("\"");
content.append(isMultiLine ? tSpanAttributes(line, i++) : " "
content.append(isSingleLine ? " "
// style
+ style(style)
// semantic data
+ attributes(false)
+ attributes(false) : ""
);
content.append(textLineAttributes(line, i++));
content.append(">");
content.append(line);
content.append("</text>");
Expand Down Expand Up @@ -1626,7 +1628,7 @@ private String attributes(boolean resetSemData) {
return sb.toString();
}

private String tSpanAttributes(final String textLine, final int noOfLine) {
private String textLineAttributes(final String textLine, final int noOfLine) {
if (semanticData == null) {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -73,11 +72,6 @@
*/
public class SaveAsImageDialog extends Dialog {

/** the default dialog width. */
private static final int DEFAULT_WIDTH = 500;
/** the default dialog height. */
private static final int DEFAULT_HEIGHT = 400;

/** the preference key for the file path. */
private static final String PREFERENCE_FILE_PATH = "saveAsImageDialog.filePath"; //$NON-NLS-1$
/** the preference key for the workspace path. */
Expand Down Expand Up @@ -646,14 +640,6 @@ protected void configureShell(final Shell shell) {
shell.setText(Messages.SaveAsImageDialog_title);
}

/**
* {@inheritDoc}
*/
@Override
protected Point getInitialSize() {
return new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}

/**
* @return the currentExporter
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<stringAttribute key="product" value="org.eclipse.equinox.p2.director.app.product"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
<stringAttribute key="selected_target_plugins" value="com.google.guava@default:default,com.google.inject@default:default,com.ibm.icu@default:default,edu.umd.cs.piccolo@default:default,javax.annotation@default:default,javax.inject@default:default,javax.xml@default:default,org.antlr.runtime@default:default,org.apache.batik.constants@default:default,org.apache.batik.css@default:default,org.apache.batik.i18n@default:default,org.apache.batik.util@default:default,org.apache.commons.io@default:default,org.apache.commons.jxpath@default:default,org.apache.commons.logging@default:default,org.apache.felix.scr@1:true,org.apache.log4j@default:default,org.apache.xmlgraphics@default:default,org.eclipse.ant.core@default:default,org.eclipse.compare.core@default:default,org.eclipse.core.commands@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.databinding.observable@default:default,org.eclipse.core.databinding.property@default:default,org.eclipse.core.databinding@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.filesystem.linux.x86_64@default:false,org.eclipse.core.filesystem.macosx@default:false,org.eclipse.core.filesystem.win32.x86_64@default:false,org.eclipse.core.filesystem@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.resources.win32.x86_64@default:false,org.eclipse.core.resources@default:default,org.eclipse.core.runtime@default:true,org.eclipse.core.variables@default:default,org.eclipse.draw2d@default:default,org.eclipse.e4.core.commands@default:default,org.eclipse.e4.core.contexts@default:default,org.eclipse.e4.core.di.annotations@default:default,org.eclipse.e4.core.di.extensions.supplier@default:default,org.eclipse.e4.core.di.extensions@default:default,org.eclipse.e4.core.di@default:default,org.eclipse.e4.core.services@default:default,org.eclipse.e4.emf.xpath@default:default,org.eclipse.e4.ui.bindings@default:default,org.eclipse.e4.ui.css.core@default:default,org.eclipse.e4.ui.css.swt.theme@default:default,org.eclipse.e4.ui.css.swt@default:default,org.eclipse.e4.ui.di@default:default,org.eclipse.e4.ui.model.workbench@default:default,org.eclipse.e4.ui.services@default:default,org.eclipse.e4.ui.widgets@default:default,org.eclipse.e4.ui.workbench.addons.swt@default:default,org.eclipse.e4.ui.workbench.renderers.swt.cocoa@default:false,org.eclipse.e4.ui.workbench.renderers.swt@default:default,org.eclipse.e4.ui.workbench.swt@default:default,org.eclipse.e4.ui.workbench3@default:default,org.eclipse.e4.ui.workbench@default:default,org.eclipse.elk.alg.common@default:default,org.eclipse.elk.alg.layered@default:default,org.eclipse.elk.core.service@default:default,org.eclipse.elk.core@default:default,org.eclipse.elk.graph@default:default,org.eclipse.emf.common@default:default,org.eclipse.emf.ecore.change@default:default,org.eclipse.emf.ecore.xmi@default:default,org.eclipse.emf.ecore@default:default,org.eclipse.emf.edit@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.event@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.help@default:default,org.eclipse.jface.databinding@default:default,org.eclipse.jface@default:default,org.eclipse.osgi.compatibility.state@default:false,org.eclipse.osgi.services@default:default,org.eclipse.osgi.util@default:default,org.eclipse.osgi@-1:true,org.eclipse.pde.ds.lib@default:default,org.eclipse.swt.cocoa.macosx.x86_64@default:false,org.eclipse.swt.gtk.linux.x86_64@default:false,org.eclipse.swt.win32.win32.x86_64@default:false,org.eclipse.swt@default:default,org.eclipse.team.core@default:default,org.eclipse.ui.cocoa@default:false,org.eclipse.ui.trace@default:default,org.eclipse.ui.workbench@default:default,org.eclipse.ui@default:default,org.eclipse.xtend.lib.macro@default:default,org.eclipse.xtend.lib@default:default,org.eclipse.xtext.common.types@default:default,org.eclipse.xtext.logging@default:false,org.eclipse.xtext.util@default:default,org.eclipse.xtext.xbase.lib@default:default,org.eclipse.xtext.xbase@default:default,org.eclipse.xtext@default:default,org.hamcrest.core@default:default,org.hamcrest.library@default:default,org.junit@default:default,org.objectweb.asm*7.0.0.v20181030-2244@default:default,org.w3c.css.sac@default:default,org.w3c.dom.events@default:default,org.w3c.dom.smil@default:default,org.w3c.dom.svg@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="de.cau.cs.kieler.kgraph.text@default:default,de.cau.cs.kieler.klighd.kgraph@default:default,de.cau.cs.kieler.klighd.krendering.extensions@default:default,de.cau.cs.kieler.klighd.krendering@default:default,de.cau.cs.kieler.klighd.piccolo.test@default:default,de.cau.cs.kieler.klighd.piccolo@default:default,de.cau.cs.kieler.klighd.test@default:default,de.cau.cs.kieler.klighd@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="de.cau.cs.kieler.kgraph.text@default:default,de.cau.cs.kieler.klighd.kgraph@default:default,de.cau.cs.kieler.klighd.krendering.extensions@default:default,de.cau.cs.kieler.klighd.krendering@default:default,de.cau.cs.kieler.klighd.piccolo.freehep@default:default,de.cau.cs.kieler.klighd.piccolo.test@default:default,de.cau.cs.kieler.klighd.piccolo@default:default,de.cau.cs.kieler.klighd.test@default:default,de.cau.cs.kieler.klighd@default:default"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class FreeHEPSVGOffscreenRenderingTest {
<g fill="none" stroke-opacity="1" stroke="#000000">
<path d="M 0.5 0.5 L 99.5 0.5 L 99.5 99.5 L 0.5 99.5 L 0.5 0.5 z"/>
</g>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">NodeLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">NodeLabel</text>
</g>
'''.equalsSVGwithTextLengthsOf[
addKNodeWithSizeOf(100, 100) => [
Expand All @@ -153,7 +153,7 @@ class FreeHEPSVGOffscreenRenderingTest {
</g>
</g>
<g transform="matrix(1, 0, 0, 1, 106, 45)">
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
</g>
</g>
'''.equalsSVGwithTextLengthsOf[
Expand Down Expand Up @@ -189,7 +189,7 @@ class FreeHEPSVGOffscreenRenderingTest {
</g>
</g>
<g transform="matrix(1, 0, 0, 1, 0, 45)">
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
</g>
</g>
'''.equalsSVGwithTextLengthsOf[
Expand Down Expand Up @@ -267,7 +267,7 @@ class FreeHEPSVGOffscreenRenderingTest {
<path d="M 0.5 0.5 L 99.5 0.5 L 99.5 99.5 L 0.5 99.5 L 0.5 0.5 z"/>
</g>
<g id="MyLabel" class="MyLabelClass" klighd:MyKey="MyValue" klighd:My2ndKey="KLabel:0">
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">NodeLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">NodeLabel</text>
</g>
</g>
'''.equalsSVGwithTextLengthsOf[
Expand All @@ -290,7 +290,7 @@ class FreeHEPSVGOffscreenRenderingTest {
<g fill="none" stroke-opacity="1" stroke="#000000">
<path d="M 0.5 0.5 L 99.5 0.5 L 99.5 99.5 L 0.5 99.5 L 0.5 0.5 z"/>
</g>
<g fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<g fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<text x="0" y="<Y>">NodeLabel:</text>
<text x="0" y="<Y>">Some additional info</text>
</g>
Expand All @@ -316,7 +316,7 @@ class FreeHEPSVGOffscreenRenderingTest {
<path d="M 0.5 0.5 L 99.5 0.5 L 99.5 99.5 L 0.5 99.5 L 0.5 0.5 z"/>
</g>
<g id="MyLabel" class="MyLabelClass" klighd:MyKey="MyValue" klighd:My2ndKey="KLabel:0">
<g fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<g fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<text x="0" y="<Y>" klighd:MyTextLineKey="0">NodeLabel:</text>
<text x="0" y="<Y>" klighd:MyTextLineKey="1">Some additional info</text>
</g>
Expand Down Expand Up @@ -355,7 +355,7 @@ class FreeHEPSVGOffscreenRenderingTest {
</g>
<g id="MyLabel" class="MyLabelClass" klighd:MyKey="MyValue" klighd:My2ndKey="KLabel:0">
<g transform="matrix(1, 0, 0, 1, 106, 45)">
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs">PortLabel</text>
</g>
</g>
</g>
Expand Down Expand Up @@ -399,7 +399,7 @@ class FreeHEPSVGOffscreenRenderingTest {
</g>
<g id="MyLabel" class="MyLabelClass" klighd:MyKey="MyValue" klighd:My2ndKey="KLabel:0">
<g transform="matrix(1, 0, 0, 1, 106, 45)">
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">PortLabel</text>
<text x="0" y="<Y>" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" textLength="50.0px" lengthAdjust="spacingAndGlyphs" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0" klighd:MyTextLineKey="0">PortLabel</text>
</g>
</g>
</g>
Expand Down Expand Up @@ -447,7 +447,7 @@ class FreeHEPSVGOffscreenRenderingTest {
</g>
</g>
<g id="MyLabel" class="MyLabelClass" klighd:MyKey="MyValue" klighd:My2ndKey="KLabel:0">
<g transform="matrix(1, 0, 0, 1, 106, 45)" fill-opacity="1" font-style="normal" font-family="Helvetica" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<g transform="matrix(1, 0, 0, 1, 106, 45)" fill-opacity="1" font-style="normal" font-family="Helvetica" style="white-space: pre" font-weight="normal" stroke="none" fill="#000000" font-size="<FONT_SIZE>" id="MyText" class="MyTextClass" klighd:MyKey="MyValue" klighd:My2ndKey="KText:0">
<text x="0" y="<Y>" klighd:MyTextLineKey="0">PortLabel:</text>
<text x="0" y="<Y>" klighd:MyTextLineKey="1">Some additional info</text>
</g>
Expand Down

0 comments on commit 307dc41

Please sign in to comment.