mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-18 09:24:42 -04:00
reworked text formatting, closes #476
This commit is contained in:
parent
468435a68e
commit
2e74b0101e
@ -14,9 +14,11 @@ Head, planned as v0.25
|
||||
- The layout shape uses a slightly different algorithm to determine
|
||||
the pin positions. You may need to adjust usages of embedded circuits
|
||||
that use the layout shape.
|
||||
- The CommandLineTester has moved! Tests are now executed like
|
||||
- The CommandLineTester has moved! Tests are now executed like this:
|
||||
java -cp Digital.jar CLI test [file to test]
|
||||
[-tests [optional file with test cases]]
|
||||
- Text formatting was reworked. Disable formatting with a '\' in the
|
||||
beginning does not longer work. Use "\_" to escape a underscore.
|
||||
|
||||
v0.24, released on 1. Feb. 2020
|
||||
- Improved SVG export
|
||||
|
@ -11,7 +11,7 @@
|
||||
<string>~A</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="0" y="160"/>
|
||||
<pos x="-20" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -21,7 +21,7 @@
|
||||
<string>~{A<B}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="0" y="220"/>
|
||||
<pos x="-20" y="220"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -31,7 +31,7 @@
|
||||
<string>s_1^n</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="160"/>
|
||||
<pos x="300" y="160"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -41,7 +41,7 @@
|
||||
<string>s_1^{n+1}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="220"/>
|
||||
<pos x="300" y="220"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -51,7 +51,7 @@
|
||||
<string>~s_1^{n+1}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="280"/>
|
||||
<pos x="300" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -61,7 +61,7 @@
|
||||
<string>~{s_1^{n+1}}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="320" y="340"/>
|
||||
<pos x="300" y="340"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Text</elementName>
|
||||
@ -74,7 +74,7 @@ of ~{s_1^{n+1}} in detail.
|
||||
von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="-80" y="380"/>
|
||||
<pos x="-120" y="400"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -84,7 +84,7 @@ von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
<string>~ABC</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="0" y="280"/>
|
||||
<pos x="-20" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -94,7 +94,7 @@ von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
<string>~{A}BC</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="0" y="340"/>
|
||||
<pos x="-20" y="340"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
@ -111,11 +111,31 @@ von ~{s_1^{n+1}} im Detail erklärt.}}</string>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>\A_B</string>
|
||||
<string>A\_B</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="140" y="220"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>A\\B</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="140" y="280"/>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>\foo</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="140" y="340"/>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires/>
|
||||
<measurementOrdering/>
|
||||
|
@ -8,14 +8,23 @@ package de.neemann.digital.draw.graphics.text;
|
||||
import de.neemann.digital.draw.graphics.text.text.*;
|
||||
import de.neemann.digital.draw.graphics.text.text.Character;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* The text parser
|
||||
*/
|
||||
public class Parser {
|
||||
private static final HashMap<String, String> COMMANDS = new HashMap<>();
|
||||
|
||||
static {
|
||||
COMMANDS.put("sum", "∑");
|
||||
COMMANDS.put("prod", "∏");
|
||||
}
|
||||
|
||||
private final String text;
|
||||
private int pos;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
@ -67,8 +76,6 @@ public class Parser {
|
||||
* @throws ParseException ParseException
|
||||
*/
|
||||
public Text parse() throws ParseException {
|
||||
if (text.length() > 0 && text.charAt(0) == '\\')
|
||||
return new Simple(text.substring(1).trim());
|
||||
return parse('\0');
|
||||
}
|
||||
|
||||
@ -99,6 +106,24 @@ public class Parser {
|
||||
case '^':
|
||||
getChar();
|
||||
sentence.getIndex().addSuper(parseBrace());
|
||||
break;
|
||||
case '\\':
|
||||
getChar();
|
||||
char p = peekChar();
|
||||
switch (p) {
|
||||
case '\\':
|
||||
case '^':
|
||||
case '_':
|
||||
sentence.add(new Character(getChar()));
|
||||
break;
|
||||
default:
|
||||
String command = readWord();
|
||||
String t = COMMANDS.get(command);
|
||||
if (t == null)
|
||||
t = '\\' + command;
|
||||
sentence.add(new Simple(t).simplify());
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if (isNormal(peekChar()))
|
||||
|
@ -109,6 +109,10 @@ public final class LaTeXFormatter {
|
||||
return "\\textgreater{}";
|
||||
case '&':
|
||||
return "\\&";
|
||||
case '_':
|
||||
return "\\_";
|
||||
case '\\':
|
||||
return "\\\\";
|
||||
case '∑':
|
||||
if (inMath)
|
||||
return "\\sum ";
|
||||
|
@ -597,7 +597,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
||||
|
||||
private String createShortName(String name, String userDefined) {
|
||||
if (userDefined.isEmpty()) {
|
||||
if (name.endsWith(".dig")) return "\\" + name.substring(0, name.length() - 4);
|
||||
if (name.endsWith(".dig")) return name.substring(0, name.length() - 4).replace("_", "\\_");
|
||||
|
||||
String transName = Lang.getNull("elem_" + name);
|
||||
if (transName == null)
|
||||
|
@ -174,7 +174,7 @@ public final class ShapeFactory {
|
||||
attributes.getLabel(), true, attributes.get(Keys.WIDTH)) {
|
||||
@Override
|
||||
public String format(String s) {
|
||||
return "\\" + s;
|
||||
return s.replace("_", "\\_");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -23,6 +23,9 @@ public class ParserTest extends TestCase {
|
||||
t = new Parser("\\I^n_0").parse();
|
||||
assertTrue(t instanceof Simple);
|
||||
assertEquals("I^n_0", ((Simple) t).getText());
|
||||
|
||||
t = new Parser("A\\_B").parse();
|
||||
assertEquals("A_B", t.toString());
|
||||
}
|
||||
|
||||
public void testSimple() throws ParseException {
|
||||
@ -43,6 +46,9 @@ public class ParserTest extends TestCase {
|
||||
|
||||
assertEquals("Decorate{≥1, MATH}", new Parser("$≥1$").parse().toString());
|
||||
assertEquals("Decorate{MR, OVERLINE}", new Parser("~MR").parse().toString());
|
||||
|
||||
assertEquals("A=∑ b", new Parser("A=\\sum b").parse().toString());
|
||||
assertEquals("A=∑^{m}_{n=0}", new Parser("A=\\sum_{n=0}^m").parse().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user