Skip to content

Commit

Permalink
fix: improve style support
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Nov 5, 2024
1 parent e9d1ab8 commit d5dba02
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/filesdiagram/FEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private TextBlock getTextBlock(FontConfiguration fontConfiguration, ISkinParam s

private Opale createOpale(ISkinParam skinParam) {

final StyleSignatureBasic signature = StyleSignatureBasic.of(SName.root, SName.element, SName.timingDiagram,
final StyleSignatureBasic signature = StyleSignatureBasic.of(SName.root, SName.element, SName.filesDiagram,
SName.note);
final Style style = signature.getMergedStyle(skinParam.getCurrentStyleBuilder());

Expand Down
25 changes: 23 additions & 2 deletions src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,38 @@
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.jsondiagram.StyleExtractor;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.style.parser.StyleParsingException;
import net.sourceforge.plantuml.text.StringLocated;

public class FilesDiagram extends UmlDiagram {

private final FilesListing list;

public FilesDiagram(UmlSource source) {
public FilesDiagram(UmlSource source, StyleExtractor styleExtractor) {
super(source, UmlDiagramType.FILES, null);
this.list = new FilesListing(getSkinParam());

final ISkinParam skinParam = getSkinParam();
try {
styleExtractor.applyStyles(skinParam);
} catch (StyleParsingException e) {
e.printStackTrace();
}
final Style style = StyleSignatureBasic.of(SName.root, SName.element, SName.filesDiagram) //
.getMergedStyle(skinParam.getCurrentStyleBuilder());

// final FontConfiguration fontConfiguration =
// FontConfiguration.blackBlueTrue(UFont.courier(14));
final FontConfiguration fontConfiguration = style.getFontConfiguration(skinParam.getIHtmlColorSet());

this.list = new FilesListing(skinParam, fontConfiguration);

final Iterator<StringLocated> it = source.iterator2();
it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.jsondiagram.StyleExtractor;

public class FilesDiagramFactory extends PSystemAbstractFactory {

Expand All @@ -50,7 +51,9 @@ public FilesDiagramFactory() {

@Override
public Diagram createSystem(UmlSource source, Map<String, String> skinParam) {
return new FilesDiagram(source);
final StyleExtractor styleExtractor = new StyleExtractor(source.iterator2());

return new FilesDiagram(source, styleExtractor);
}

}
6 changes: 3 additions & 3 deletions src/net/sourceforge/plantuml/filesdiagram/FilesListing.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.font.UFont;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
import net.sourceforge.plantuml.style.ISkinParam;

public class FilesListing extends AbstractTextBlock {

private final ISkinParam skinParam;
private final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(UFont.courier(14));
private final FontConfiguration fontConfiguration;
private final FEntry root;
private FEntry lastCreated;

public FilesListing(ISkinParam skinParam) {
public FilesListing(ISkinParam skinParam, FontConfiguration fontConfiguration) {
this.skinParam = skinParam;
this.fontConfiguration = fontConfiguration;
this.root = FEntry.createRoot();
}

Expand Down
2 changes: 0 additions & 2 deletions src/net/sourceforge/plantuml/jsondiagram/StyleExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.util.Iterator;
import java.util.List;

import net.sourceforge.plantuml.Scale;
import net.sourceforge.plantuml.ScaleSimple;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
Expand Down
34 changes: 11 additions & 23 deletions src/net/sourceforge/plantuml/regexdiagram/PSystemRegex.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import net.sourceforge.plantuml.ebnf.ETileRegexGroup;
import net.sourceforge.plantuml.ebnf.ETileZeroOrMore;
import net.sourceforge.plantuml.ebnf.Symbol;
import net.sourceforge.plantuml.jsondiagram.StyleExtractor;
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColorSet;
import net.sourceforge.plantuml.klimt.color.HColors;
Expand All @@ -73,14 +74,23 @@
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.parser.StyleParsingException;
import net.sourceforge.plantuml.utils.BlocLines;
import net.sourceforge.plantuml.utils.CharInspector;

public class PSystemRegex extends TitledDiagram {

public PSystemRegex(UmlSource source) {
super(source, UmlDiagramType.REGEX, null);
final StyleExtractor styleExtractor = new StyleExtractor(source.iterator2());

final ISkinParam skinParam = getSkinParam();
try {
styleExtractor.applyStyles(skinParam);
} catch (StyleParsingException e) {
e.printStackTrace();
}

this.style = ETile.getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder());
this.fontConfiguration = style.getFontConfiguration(skinParam.getIHtmlColorSet());
this.colorSet = skinParam.getIHtmlColorSet();
Expand All @@ -97,28 +107,6 @@ public DiagramDescription getDescription() {
private final HColorSet colorSet;
private final HColor lineColor;

// public CommandExecutionResult addBlocLines(BlocLines blines, String commentAbove, String commentBelow) {
// final boolean isCompact = getPragma().isDefine("compact");
// final CharIterator it = new CharIteratorImpl(blines);
// final EbnfExpression tmp1 = EbnfExpression.create(it, isCompact, commentAbove, commentBelow);
// if (tmp1.isEmpty())
// return CommandExecutionResult.error("Unparsable expression");
// expressions.add(tmp1);
// return CommandExecutionResult.ok();
//
// }
//
// public CommandExecutionResult addNote(final Display note, Colors colors) {
// expressions.add(new TextBlockable() {
// @Override
// public TextBlock getUDrawable(ISkinParam skinParam) {
// final FloatingNote f = FloatingNote.create(note, skinParam, SName.ebnf);
// return TextBlockUtils.withMargin(f, 0, 0, 5, 15);
// }
// });
// return CommandExecutionResult.ok();
// }

@Override
protected ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
Expand All @@ -134,7 +122,7 @@ protected TextBlock getTextMainBlock(FileFormatOption fileFormatOption) {

@Override
public void drawU(UGraphic ug) {
peekFirst.drawU(ug.apply(HColors.BLACK));
peekFirst.drawU(ug.apply(lineColor));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/net/sourceforge/plantuml/style/SName.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public enum SName {
start, //
stop, //
file, //
filesDiagram, //
folder, //
footer, //
frame, //
Expand Down

0 comments on commit d5dba02

Please sign in to comment.