1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-23 20:49:03 +00:00
plantuml/src/net/sourceforge/plantuml/graphic/FontConfiguration.java

137 lines
4.0 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
2011-08-08 17:48:29 +00:00
* Revision $Revision: 6837 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.graphic;
import java.util.EnumSet;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2010-11-15 20:35:36 +00:00
public class FontConfiguration {
private final EnumSet<FontStyle> styles;
2011-08-08 17:48:29 +00:00
private final UFont currentFont;
private final UFont motherFont;
private final HtmlColor motherColor;
private final HtmlColor currentColor;
private final HtmlColor extendedColor;
public FontConfiguration(UFont font, HtmlColor color) {
this(getStyles(font), font, color, font, color, null);
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
private static EnumSet<FontStyle> getStyles(UFont font) {
final boolean bold = font.isBold();
final boolean italic = font.isItalic();
if (bold && italic) {
return EnumSet.of(FontStyle.ITALIC, FontStyle.BOLD);
}
if (bold) {
return EnumSet.of(FontStyle.BOLD);
}
if (italic) {
return EnumSet.of(FontStyle.ITALIC);
}
return EnumSet.noneOf(FontStyle.class);
}
2010-11-15 20:35:36 +00:00
@Override
public String toString() {
2011-08-08 17:48:29 +00:00
return styles.toString() + " " + currentColor;
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
private FontConfiguration(EnumSet<FontStyle> styles, UFont motherFont, HtmlColor motherColor, UFont currentFont,
HtmlColor currentColor, HtmlColor extendedColor) {
2010-11-15 20:35:36 +00:00
this.styles = styles;
this.currentFont = currentFont;
this.motherFont = motherFont;
this.currentColor = currentColor;
this.motherColor = motherColor;
this.extendedColor = extendedColor;
}
FontConfiguration changeColor(HtmlColor htmlColor) {
2011-08-08 17:48:29 +00:00
return new FontConfiguration(styles, motherFont, motherColor, currentFont, htmlColor, extendedColor);
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
FontConfiguration changeExtendedColor(HtmlColor newExtendedColor) {
2010-11-15 20:35:36 +00:00
return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, newExtendedColor);
}
FontConfiguration changeSize(float size) {
2011-08-08 17:48:29 +00:00
return new FontConfiguration(styles, motherFont, motherColor, currentFont.deriveSize(size), currentColor,
extendedColor);
2010-11-15 20:35:36 +00:00
}
public FontConfiguration resetFont() {
return new FontConfiguration(styles, motherFont, motherColor, motherFont, motherColor, null);
}
FontConfiguration add(FontStyle style) {
final EnumSet<FontStyle> r = styles.clone();
r.add(style);
return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor);
}
2011-08-08 17:48:29 +00:00
public FontConfiguration italic() {
return add(FontStyle.ITALIC);
}
2010-11-15 20:35:36 +00:00
FontConfiguration remove(FontStyle style) {
final EnumSet<FontStyle> r = styles.clone();
r.remove(style);
return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor);
}
2011-08-08 17:48:29 +00:00
public UFont getFont() {
UFont result = currentFont;
2010-11-15 20:35:36 +00:00
for (FontStyle style : styles) {
result = style.mutateFont(result);
}
return result;
}
2011-08-08 17:48:29 +00:00
public HtmlColor getColor() {
2010-11-15 20:35:36 +00:00
return currentColor;
}
2011-08-08 17:48:29 +00:00
public HtmlColor getExtendedColor() {
2010-11-15 20:35:36 +00:00
return extendedColor;
}
public boolean containsStyle(FontStyle style) {
return styles.contains(style);
}
}