mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-25 22:37:33 +00:00
Merge pull request #938 from kolrami/chru-ditaa-font-force
Force Font Size if sepcified instead of Deriving it
This commit is contained in:
commit
87d472f122
@ -65,11 +65,12 @@ public class PSystemDitaa extends AbstractPSystem {
|
||||
private final float scale;
|
||||
private final boolean transparentBackground;
|
||||
private final Font font;
|
||||
private final boolean forceFontSize;
|
||||
private final boolean performSeparationOfCommonEdges;
|
||||
private final boolean allCornersAreRound;
|
||||
|
||||
public PSystemDitaa(UmlSource source, String data, boolean performSeparationOfCommonEdges, boolean dropShadows,
|
||||
boolean allCornersAreRound, boolean transparentBackground, float scale, Font font) {
|
||||
boolean allCornersAreRound, boolean transparentBackground, float scale, Font font, boolean forceFontSize) {
|
||||
super(source);
|
||||
this.data = data;
|
||||
this.dropShadows = dropShadows;
|
||||
@ -90,11 +91,12 @@ public class PSystemDitaa extends AbstractPSystem {
|
||||
this.transparentBackground = transparentBackground;
|
||||
this.scale = scale;
|
||||
this.font = font;
|
||||
this.forceFontSize = forceFontSize;
|
||||
}
|
||||
|
||||
PSystemDitaa add(String line) {
|
||||
return new PSystemDitaa(getSource(), data + line + BackSlash.NEWLINE, performSeparationOfCommonEdges,
|
||||
dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||
dropShadows, allCornersAreRound, transparentBackground, scale, font, forceFontSize);
|
||||
}
|
||||
|
||||
public DiagramDescription getDescription() {
|
||||
@ -127,6 +129,10 @@ public class PSystemDitaa extends AbstractPSystem {
|
||||
final Method setFont = renderingOptions.getClass().getMethod("setFont", Font.class);
|
||||
setFont.invoke(renderingOptions, font);
|
||||
|
||||
// renderingOptions.setForceFontSize(font);
|
||||
final Method setForceFontSize = renderingOptions.getClass().getMethod("setForceFontSize", boolean.class);
|
||||
setForceFontSize.invoke(renderingOptions, forceFontSize);
|
||||
|
||||
// renderingOptions.setScale(scale);
|
||||
final Method setScale = renderingOptions.getClass().getMethod("setScale", float.class);
|
||||
setScale.invoke(renderingOptions, scale);
|
||||
|
@ -74,12 +74,16 @@ public class PSystemDitaaFactory extends PSystemBasicFactory<PSystemDitaa> {
|
||||
if (startLine != null && (startLine.contains("-T") || startLine.contains("--transparent")))
|
||||
transparentBackground = true;
|
||||
|
||||
boolean forceFontSize = false;
|
||||
if (startLine != null && startLine.contains("--font-size"))
|
||||
forceFontSize = true;
|
||||
|
||||
final float scale = extractScale(startLine);
|
||||
final Font font = extractFont(startLine);
|
||||
if (getDiagramType() == DiagramType.UML)
|
||||
return null;
|
||||
else if (getDiagramType() == DiagramType.DITAA)
|
||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font, forceFontSize);
|
||||
else
|
||||
throw new IllegalStateException(getDiagramType().name());
|
||||
|
||||
@ -104,9 +108,13 @@ public class PSystemDitaaFactory extends PSystemBasicFactory<PSystemDitaa> {
|
||||
if (line.contains("-T") || line.contains("--transparent"))
|
||||
transparentBackground = true;
|
||||
|
||||
boolean forceFontSize = false;
|
||||
if (line.contains("--font-size"))
|
||||
forceFontSize = true;
|
||||
|
||||
final float scale = extractScale(line);
|
||||
final Font font = extractFont(line);
|
||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font);
|
||||
return new PSystemDitaa(source, "", performSeparationOfCommonEdges, dropShadows, allCornersAreRound, transparentBackground, scale, font, forceFontSize);
|
||||
}
|
||||
if (system == null)
|
||||
return null;
|
||||
|
@ -45,6 +45,7 @@ public class RenderingOptions {
|
||||
private Color backgroundColor = Color.white;
|
||||
|
||||
private Font font = new Font("Dialog", Font.BOLD, 12);
|
||||
private boolean forceFontSize = false;
|
||||
|
||||
/**
|
||||
* @return
|
||||
@ -140,4 +141,13 @@ public class RenderingOptions {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public boolean getForceFontSize()
|
||||
{
|
||||
return forceFontSize;
|
||||
}
|
||||
|
||||
public void setForceFontSize(boolean forceFontSize)
|
||||
{
|
||||
this.forceFontSize = forceFontSize;
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ public class Diagram {
|
||||
this.cellWidth = options.renderingOptions.getCellWidth();
|
||||
this.cellHeight = options.renderingOptions.getCellHeight();
|
||||
|
||||
FontMeasurer fontMeasurer = new FontMeasurer(options.renderingOptions.getFont());
|
||||
FontMeasurer fontMeasurer = new FontMeasurer(
|
||||
options.renderingOptions.getFont(), options.renderingOptions.getForceFontSize());
|
||||
|
||||
width = grid.getWidth() * cellWidth;
|
||||
height = grid.getHeight() * cellHeight;
|
||||
|
@ -34,11 +34,13 @@ import java.awt.image.BufferedImage;
|
||||
public class FontMeasurer {
|
||||
|
||||
private final Font baseFont;
|
||||
private boolean forceFontSize;
|
||||
private FontRenderContext fakeRenderContext;
|
||||
private Graphics2D fakeGraphics;
|
||||
|
||||
public FontMeasurer(Font font){
|
||||
baseFont = font;
|
||||
public FontMeasurer(Font font, boolean forceFontSize){
|
||||
this.baseFont = font;
|
||||
this.forceFontSize = forceFontSize;
|
||||
|
||||
BufferedImage image = new BufferedImage(1,1, BufferedImage.TYPE_INT_RGB);
|
||||
fakeGraphics = image.createGraphics();
|
||||
@ -83,6 +85,12 @@ public class FontMeasurer {
|
||||
}
|
||||
|
||||
public Font getFontFor(final int maxWidth, final String string){
|
||||
if (forceFontSize)
|
||||
{
|
||||
return baseFont;
|
||||
}
|
||||
else
|
||||
{
|
||||
FontPredicate predicate = new FontPredicate() {
|
||||
@Override
|
||||
public boolean test(Font font)
|
||||
@ -91,11 +99,17 @@ public class FontMeasurer {
|
||||
return width > maxWidth;
|
||||
}
|
||||
};
|
||||
|
||||
return deriveFont(predicate, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public Font getFontFor(final int pixelHeight){
|
||||
if (forceFontSize)
|
||||
{
|
||||
return baseFont;
|
||||
}
|
||||
else
|
||||
{
|
||||
FontPredicate predicate = new FontPredicate() {
|
||||
@Override
|
||||
public boolean test(Font font)
|
||||
@ -105,9 +119,9 @@ public class FontMeasurer {
|
||||
return ascent > pixelHeight;
|
||||
}
|
||||
};
|
||||
|
||||
return deriveFont(predicate, 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
private Font deriveFont(FontPredicate predicate, float sizeDelta)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user