/*******************************************************************************
* Copyright 2011 See AUTHORS file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.tools.hiero.unicodefont.effects;
import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
import com.badlogic.gdx.tools.hiero.unicodefont.Glyph;
import com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont;
/** Strokes glyphs with an outline.
* @author Nathan Sweet */
public class OutlineEffect implements ConfigurableEffect {
private Color color = Color.black;
private int join = BasicStroke.JOIN_BEVEL;
public OutlineEffect () {
public OutlineEffect (int width, Color color) {
public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
g = (Graphics2D)g.create();
g.setStroke(getStroke());
g.draw(glyph.getShape());
public float getWidth () {
/** Sets the width of the outline. The glyphs will need padding so the outline doesn't get clipped. */
public void setWidth (int width) {
public Color getColor () {
public void setColor (Color color) {
public Stroke getStroke () {
if (stroke == null) return new BasicStroke(width, BasicStroke.CAP_SQUARE, join);
/** Sets the stroke to use for the outline. If this is set, the other outline settings are ignored. */
public void setStroke (Stroke stroke) {
/** Sets how the corners of the outline are drawn. This is usually only noticeable at large outline widths.
* @param join One of: {@link BasicStroke#JOIN_BEVEL}, {@link BasicStroke#JOIN_MITER}, {@link BasicStroke#JOIN_ROUND} */
public void setJoin (int join) {
public String toString () {
public List getValues () {
List values = new ArrayList();
values.add(EffectUtil.colorValue("Color", color));
values.add(EffectUtil.floatValue("Width", width, 0.1f, 999, "This setting controls the width of the outline. "
+ "The glyphs will need padding so the outline doesn't get clipped."));
values.add(EffectUtil.optionValue("Join", String.valueOf(join), new String[][] { {"Bevel", BasicStroke.JOIN_BEVEL + ""},
{"Miter", BasicStroke.JOIN_MITER + ""}, {"Round", BasicStroke.JOIN_ROUND + ""}},
"This setting defines how the corners of the outline are drawn. "
+ "This is usually only noticeable at large outline widths."));
public void setValues (List values) {
for (Iterator iter = values.iterator(); iter.hasNext();) {
Value value = (Value)iter.next();
if (value.getName().equals("Color")) {
color = (Color)value.getObject();
} else if (value.getName().equals("Width")) {
width = ((Float)value.getObject()).floatValue();
} else if (value.getName().equals("Join")) {
join = Integer.parseInt((String)value.getObject());