1 /*
2  * Copyright (c) 2019 Helmut Neemann.
3  * Use of this source code is governed by the GPL v3 license
4  * that can be found in the LICENSE file.
5  */
6 package de.neemann.digital.draw.graphics;
7 
8 import de.neemann.digital.draw.graphics.text.ParseException;
9 import de.neemann.digital.draw.graphics.text.Parser;
10 import de.neemann.digital.draw.graphics.text.formatter.SVGFormatter;
11 import de.neemann.digital.draw.graphics.text.text.Decorate;
12 import de.neemann.digital.draw.graphics.text.text.Text;
13 
14 import java.awt.*;
15 
16 final class TextFormatSVG implements GraphicSVG.TextStyle {
17     @Override
format(String text, Style style)18     public String format(String text, Style style) {
19         try {
20             Text t = new Parser(text).parse();
21             if (style.getFontStyle() == Font.ITALIC)
22                 t = Decorate.math(t);
23             return SVGFormatter.format(t);
24         } catch (ParseException e) {
25             e.printStackTrace();
26         }
27         return text;
28     }
29 }
30