Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit e42a1115 authored by Nico Mack's avatar Nico Mack

Added support for specifying font face to used

Fixed bug in ShapeBackground inner class
parent 028d0748
......@@ -26,6 +26,7 @@ import com.kennycason.kumo.CollisionMode;
import com.kennycason.kumo.WordFrequency;
import com.kennycason.kumo.bg.Background;
import com.kennycason.kumo.collide.Collidable;
import com.kennycason.kumo.font.KumoFont;
import com.kennycason.kumo.font.scale.FontScalar;
import com.kennycason.kumo.nlp.FrequencyAnalyzer;
import com.kennycason.kumo.palette.ColorPalette;
......@@ -36,6 +37,7 @@ import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
......@@ -59,6 +61,7 @@ public class WordCloud extends Corona implements InformationReceiver<String> {
protected String textContent;
protected int width;
protected int height;
protected Font font;
protected FrequencyAnalyzer analyzer;
protected ColorPalette palette;
......@@ -85,15 +88,19 @@ public class WordCloud extends Corona implements InformationReceiver<String> {
private class ShapeBackground implements Background {
private Shape background;
private java.awt.Point shapeCentre;
public ShapeBackground(Shape shape) {
this.background = shape;
Rectangle2D bounds = this.background.getBounds2D();
shapeCentre = new java.awt.Point((int) bounds.getWidth() / 2, (int) bounds.getHeight() / 2);
}
/** {@inheritDoc} */
@Override
public boolean isInBounds(Collidable collidable) {
final java.awt.Point position = collidable.getPosition();
final java.awt.Point position = (java.awt.Point) collidable.getPosition().clone();
position.translate(-shapeCentre.x, -shapeCentre.y);
return this.background.contains(position);
}
}
......@@ -115,6 +122,7 @@ public class WordCloud extends Corona implements InformationReceiver<String> {
public WordCloud(BaseWordCloudBuilder<?> builder) {
super(builder);
this.textContent = builder.textContent;
this.font = builder.font;
this.width = builder.width;
this.height = builder.height;
this.analyzer = builder.analyzer;
......@@ -135,6 +143,7 @@ public class WordCloud extends Corona implements InformationReceiver<String> {
public WordCloud(WordCloud original) {
super(original);
this.textContent = original.textContent;
this.font = original.font;
this.width = original.width;
this.height = original.height;
this.analyzer = original.analyzer;
......@@ -163,6 +172,11 @@ public class WordCloud extends Corona implements InformationReceiver<String> {
this.cloud.setBackground(new ShapeBackground(this.shape));
this.cloud.setColorPalette(this.palette);
this.cloud.setFontScalar(this.scaler);
if (this.font != null) {
this.cloud.setKumoFont(new KumoFont(this.font));
}
}
// ---------------------------------------------------------------------------
......
......@@ -43,6 +43,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
......@@ -75,6 +76,8 @@ public abstract class BaseWordCloudBuilder<B extends BaseWordCloudBuilder<B>> ex
/** */
public int height;
public Font font;
public FrequencyAnalyzer analyzer;
public ColorPalette palette;
......@@ -189,6 +192,8 @@ public abstract class BaseWordCloudBuilder<B extends BaseWordCloudBuilder<B>> ex
}
}
font = BootstrappingUtils.getContentAsFont(rootElement, Externalization.FONT_NODE, BootstrappingUtils.OPTIONAL, null, context);
width = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.WIDTH_NODE, BootstrappingUtils.OPTIONAL, -1, context);
height = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.HEIGHT_NODE, BootstrappingUtils.OPTIONAL, -1, context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment