Font refactor to a class rather than an enum in IPainter

This commit is contained in:
Martin Pernollet 2021-04-22 20:59:26 +02:00
parent 2dac900bd1
commit 362b2f0862
18 changed files with 105 additions and 70 deletions

View File

@ -0,0 +1,9 @@
package org.jzy3d.painters;
public class AWTFont {
public static java.awt.Font toAWT(Font font) {
return new java.awt.Font(font.getName(), java.awt.Font.PLAIN, font.getHeight());
}
}

View File

@ -1,5 +1,7 @@
package org.jzy3d.painters;
import org.checkerframework.checker.fenum.qual.AwtFlowLayout;
/**
* A Font subset supported both by OpenGL 1 and AWT. These fonts can be used both for charts based
* on native OpenGL and charts based on raw AWT.
@ -20,6 +22,7 @@ package org.jzy3d.painters;
* {@link IPainter#BITMAP_HELVETICA_12} will apply.
*/
public class Font {
private static final int STYLE_UNDEFINED = -1;
// Font constants below are picked from GLU object in JOGL
protected static final int STROKE_ROMAN = 0;
protected static final int STROKE_MONO_ROMAN = 1;
@ -46,28 +49,37 @@ public class Font {
protected String name;
protected int code;
protected int height;
protected int style;
public Font(int code, int height) {
this.code = code;
this.style = STYLE_UNDEFINED;
this.height = height;
detectFontNameFromOpenGLCode(code);
}
public Font(String name, int height) {
this(name, STYLE_UNDEFINED, height);
}
/**
* Build a font from its name.
*
* Its OpenGL code will be guessed to ensure the font is usable with OpenGL 1 renderer supporting
* a limited font set. If the font name is not recognized among such set, the default
* {@link #BITMAP_HELVETICA_12} will be loaded
* {@link #BITMAP_HELVETICA_12} will be loaded.
*
* See also {@link AWTFont.toAWT(font)} to convert to AWT an font.
*
* @param name
* @param style a style value. May not be supported by the text renderer
* @param height
*/
public Font(String name, int height) {
public Font(String name, int style, int height) {
this.name = name;
this.style = style;
this.height = height;
detectOpenGLFontCodeFromName(name, height);

View File

@ -357,8 +357,8 @@ public class AxisBox implements IAxis {
* if(spaceTransformer!=null){ labelPosition = spaceTransformer.compute(labelPosition); }
*/
BoundingBox3d labelBounds = textRenderer.drawText(painter, axeLabel, labelPosition,
Horizontal.CENTER, Vertical.CENTER, color);
BoundingBox3d labelBounds = textRenderer.drawText(painter, getLayout().getFont(),
axeLabel, labelPosition, Horizontal.CENTER, Vertical.CENTER, color);
if (labelBounds != null)
ticksTxtBounds.add(labelBounds);
}
@ -504,7 +504,7 @@ public class AxisBox implements IAxis {
painter.glScalef(scale.x, scale.y, scale.z);
BoundingBox3d tickBounds =
textRenderer.drawText(painter, tickLabel, tickPosition, hAlign, vAlign, color);
textRenderer.drawText(painter, getLayout().getFont(), tickLabel, tickPosition, hAlign, vAlign, color);
if (tickBounds != null)
ticksTxtBounds.add(tickBounds);
}

View File

@ -5,6 +5,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.graphs.AbstractDrawableGraph2d;
import org.jzy3d.plot3d.text.align.Horizontal;
@ -60,7 +61,7 @@ public class DefaultDrawableGraph2d<V, E> extends AbstractDrawableGraph2d<V, E>
protected void drawVertexLabel(IPainter painter, V v, Coord2d coord, Color color) {
Coord3d textPosition = new Coord3d(coord, Z);
txt.drawText(painter, v.toString(), textPosition, Horizontal.CENTER, Vertical.BOTTOM, color);
txt.drawText(painter, Font.Helvetica_12, v.toString(), textPosition, Horizontal.CENTER, Vertical.BOTTOM, color);
}
protected void drawEdge(IPainter painter, E e, Coord2d c1, Coord2d c2, Color color) {

View File

@ -4,6 +4,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Utils;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.Drawable;
import org.jzy3d.plot3d.primitives.Geometry;
@ -67,8 +68,8 @@ public class CameraDistanceAnnotation extends Point {
// System.out.println(drawable.getBarycentre() );
txt.setSpaceTransformer(drawable.getSpaceTransformer());
txt.drawText(painter, Utils.num2str(d, 4), drawable.getBarycentre(), h, v, colorBary,
screenOffset);
txt.drawText(painter, Font.Helvetica_12, Utils.num2str(d, 4), drawable.getBarycentre(), h, v,
colorBary, screenOffset);
}
private void drawPolygonPointsDistanceToCamera(IPainter painter, Horizontal h, Vertical v,
@ -83,7 +84,7 @@ public class CameraDistanceAnnotation extends Point {
// System.out.println(pt.xyz);
txt.setSpaceTransformer(pt.getSpaceTransformer());
txt.drawText(painter, Utils.num2str(d, 4), pt.getCoord(), h, v, colorPt, screenOffset);
txt.drawText(painter, Font.Helvetica_12, Utils.num2str(d, 4), pt.getCoord(), h, v, colorPt, screenOffset);
}
}
}

View File

@ -4,6 +4,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.text.align.Horizontal;
import org.jzy3d.plot3d.text.align.Vertical;
@ -20,21 +21,21 @@ public abstract class AbstractTextRenderer implements ITextRenderer {
}
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign,
Vertical valign, Color color) {
return drawText(painter, s, position, halign, valign, color, defScreenOffset, defSceneOffset);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal halign, Vertical valign, Color color) {
return drawText(painter, font, s, position, halign, valign, color, defScreenOffset, defSceneOffset);
}
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset) {
return drawText(painter, s, position, halign, valign, color, screenOffset, defSceneOffset);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset) {
return drawText(painter, font, s, position, halign, valign, color, screenOffset, defSceneOffset);
}
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord3d sceneOffset) {
return drawText(painter, s, position, halign, valign, color, defScreenOffset, sceneOffset);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord3d sceneOffset) {
return drawText(painter, font, s, position, halign, valign, color, defScreenOffset, sceneOffset);
}
@Override

View File

@ -4,6 +4,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.Drawable;
import org.jzy3d.plot3d.text.align.Horizontal;
@ -43,7 +44,7 @@ public class DrawableTextWrapper extends Drawable {
public void draw(IPainter painter) {
doTransform(painter);
BoundingBox3d box =
renderer.drawText(painter, txt, position, halign, valign, color, screenOffset, sceneOffset);
renderer.drawText(painter, Font.Helvetica_12, txt, position, halign, valign, color, screenOffset, sceneOffset);
if (box != null)
bbox = box.scale(new Coord3d(1 / 10, 1 / 10, 1 / 10));
else

View File

@ -4,21 +4,20 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.text.align.Horizontal;
import org.jzy3d.plot3d.text.align.Vertical;
import org.jzy3d.plot3d.transform.space.SpaceTransformer;
public interface ITextRenderer {
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign, Vertical valign, Color color);
/** The main text renderer method to implement. Other are shortcuts implemented by {@link AbstractTextRenderer}*/
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset);
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset);
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord2d screenOffset);
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord3d sceneOffset);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position, Horizontal halign, Vertical valign, Color color);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord2d screenOffset);
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position, Horizontal halign, Vertical valign, Color color, Coord3d sceneOffset);
public SpaceTransformer getSpaceTransformer();
public void setSpaceTransformer(SpaceTransformer transformer);
}

View File

@ -4,6 +4,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.painters.PixelStore;
import org.jzy3d.plot3d.text.AbstractTextRenderer;
@ -51,8 +52,8 @@ public class TextBillboardRenderer extends AbstractTextRenderer implements IText
* according to the current Camera configuration.
*/
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
glRaster(painter, position, color);
BillBoardSize dims = printString(painter, s, halign, valign);

View File

@ -50,8 +50,8 @@ public class TextBitmapRenderer extends AbstractTextRenderer implements ITextRen
* according to the current Camera configuration.
*/
@Override
public BoundingBox3d drawText(IPainter painter, String text, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String text, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
painter.color(color);
// compute a corrected 3D position according to the 2D layout on screen

View File

@ -8,6 +8,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.text.align.Horizontal;
import org.jzy3d.plot3d.text.align.Vertical;
@ -17,8 +18,8 @@ public class MockTextBitmapRenderer extends TextBitmapRenderer {
List<Map<String, Object>> callArguments = new ArrayList<>();
@Override
public BoundingBox3d drawText(IPainter painter, String text, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String text, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("text", text);
args.put("position", position);

View File

@ -5,6 +5,7 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.axis.AxisBox;
import org.jzy3d.plot3d.primitives.axis.layout.IAxisLayout;
@ -70,11 +71,11 @@ public class AxisBox2d extends AxisBox {
if (isXDisplayed(direction)) {
// doTransform(gl);
labelBounds = textRenderer.drawText(painter, axeLabel, labelPosition, Horizontal.CENTER,
Vertical.CENTER, color);
labelBounds = textRenderer.drawText(painter, getLayout().getFont(), axeLabel,
labelPosition, Horizontal.CENTER, Vertical.CENTER, color);
} else if (isYDisplayed(direction)) {
labelBounds = textRenderer.drawText(painter, axeLabel, labelPosition, Horizontal.CENTER,
Vertical.CENTER, color);
labelBounds = textRenderer.drawText(painter, getLayout().getFont(), axeLabel,
labelPosition, Horizontal.CENTER, Vertical.CENTER, color);
// labelBounds = txtRotation.drawText(gl, glu, cam, axeLabel, labelPosition, Halign.CENTER,
// Valign.CENTER, color);
}
@ -91,8 +92,8 @@ public class AxisBox2d extends AxisBox {
public class RotatedTextBitmapRenderer extends TextBitmapRenderer {
@Override
public BoundingBox3d drawText(IPainter painter, String text, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String text, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
painter.color(color);
// compute a corrected position according to layout

View File

@ -119,8 +119,8 @@ public class AxisBoxWithTxtRenderer extends AxisBox implements IAxis {
txtRenderer.appendText(painter, axeLabel, labelPosition, Horizontal.CENTER, Vertical.CENTER,
color);
else {
BoundingBox3d labelBounds = textRenderer.drawText(painter, axeLabel, labelPosition,
Horizontal.CENTER, Vertical.CENTER, color);
BoundingBox3d labelBounds = textRenderer.drawText(painter, getLayout().getFont(),
axeLabel, labelPosition, Horizontal.CENTER, Vertical.CENTER, color);
if (labelBounds != null)
ticksTxtBounds.add(labelBounds);
}
@ -196,7 +196,7 @@ public class AxisBoxWithTxtRenderer extends AxisBox implements IAxis {
txtRenderer.appendText(painter, tickLabel, tickPosition, hAlign, vAlign, color);
else {
BoundingBox3d tickBounds =
textRenderer.drawText(painter, tickLabel, tickPosition, hAlign, vAlign, color);
textRenderer.drawText(painter, getLayout().getFont(), tickLabel, tickPosition, hAlign, vAlign, color);
if (tickBounds != null)
ticksTxtBounds.add(tickBounds);
}

View File

@ -124,8 +124,8 @@ public class ContourAxisBox extends AxisBox {
if (label != null && level != null) {
for (LineStrip strip : contour.getLines()) {
Coord3d position = strip.get(strip.size() / 2).xyz;
textRenderer.drawText(painter, label, position, Horizontal.CENTER, Vertical.CENTER,
Color.BLACK);
textRenderer.drawText(painter, getLayout().getFont(), label, position,
Horizontal.CENTER, Vertical.CENTER, Color.BLACK);
}
}
}

View File

@ -1,10 +1,11 @@
package org.jzy3d.plot3d.text.drawable.cells;
import java.awt.Font;
import java.util.List;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.PlaneAxis;
import org.jzy3d.painters.Font;
import org.jzy3d.plot3d.primitives.pickable.PickableTexture;
import org.jzy3d.plot3d.primitives.textured.NativeDrawableImage;
import org.jzy3d.plot3d.rendering.textures.BufferedImageTexture;
@ -38,7 +39,7 @@ public class DrawableTextCell extends PickableTexture {
/******************************/
// default image generation @ construction
protected static Font DEFAULT_FONT = new Font("Serif", Font.PLAIN, 16);
protected static Font DEFAULT_FONT = new Font("Serif", 16);
protected static BufferedImageTexture makeImage(int n, String text) {
return new TextCellRenderer(n, text, DEFAULT_FONT).getImage();

View File

@ -1,7 +1,6 @@
package org.jzy3d.plot3d.text.drawable.cells;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
@ -9,6 +8,8 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.IntegerCoord2d;
import org.jzy3d.painters.AWTFont;
import org.jzy3d.painters.Font;
import org.jzy3d.plot3d.rendering.textures.BufferedImageTexture;
import org.jzy3d.plot3d.text.align.Horizontal;
import org.jzy3d.plot3d.text.drawable.TextImageRenderer;
@ -27,7 +28,7 @@ public class TextCellRenderer extends TextImageRenderer {
}
public TextCellRenderer(int n, String txt, Font font, Horizontal halign, boolean drawBorder) {
super(txt, font);
super(txt, AWTFont.toAWT(font));
this.n = n;
this.h = halign;
this.drawBorder = drawBorder;
@ -134,7 +135,7 @@ public class TextCellRenderer extends TextImageRenderer {
/***************/
protected IntegerCoord2d guessImageDimension(int n, Font font) {
protected IntegerCoord2d guessImageDimension(int n, java.awt.Font font) {
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
g.setFont(font);

View File

@ -1,11 +1,12 @@
package org.jzy3d.plot3d.text.renderers.jogl;
import java.awt.Font;
import org.jzy3d.colors.AWTColor;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.AWTFont;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
@ -37,7 +38,7 @@ import com.jogamp.opengl.util.awt.TextRenderer.RenderDelegate;
* @author Martin Pernollet
*/
public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRenderer {
protected Font font;
protected java.awt.Font awtFont;
protected TextRenderer renderer;
protected TextRenderer.RenderDelegate renderDelegate;
protected float scaleFactor = 0.01f;
@ -45,7 +46,7 @@ public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRen
protected AWTTextLayout layout = new AWTTextLayout();
public JOGLTextRenderer2d() {
this(new Font("Arial", Font.PLAIN, 16));
this(new Font("Arial", 16));
}
public JOGLTextRenderer2d(Font font) {
@ -57,28 +58,29 @@ public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRen
* @param renderDelegate may be null if no particular custom styling should be applied.
*/
public JOGLTextRenderer2d(Font font, RenderDelegate renderDelegate) {
this.font = font;
this.renderer = new TextRenderer(font, true, true, renderDelegate);
this.awtFont = AWTFont.toAWT(font);
this.renderer = new TextRenderer(awtFont, true, true, renderDelegate);
this.renderDelegate = renderDelegate;
}
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal horizontal,
Vertical vertical, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal horizontal, Vertical vertical, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
// configureRenderer();
resetTextColor(color);
// Reset to a polygon mode suitable for rendering the texture handling the text
painter.glPolygonMode(PolygonMode.FRONT_AND_BACK, PolygonFill.FILL);
drawText2D(painter, s, position, color, horizontal, vertical);
drawText2D(painter, font, s, position, color, horizontal, vertical);
return null;
}
/** Draws a 2D text (facing camera) at the specified 3D position */
protected void drawText2D(IPainter painter, String text, Coord3d position, Color color,
Horizontal horizontal, Vertical vertical) {
/** Draws a 2D text (facing camera) at the specified 3D position
* @param font TODO*/
protected void drawText2D(IPainter painter, Font font, String text, Coord3d position,
Color color, Horizontal horizontal, Vertical vertical) {
// Canvas size
int width = painter.getView().getCanvas().getRendererWidth();
@ -86,7 +88,7 @@ public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRen
// Text screen position
Coord3d screen = painter.getCamera().modelToScreen(painter, position);
Coord2d textSize = layout.getBounds(text, font, renderer.getFontRenderContext());
Coord2d textSize = layout.getBounds(text, awtFont, renderer.getFontRenderContext());
screen = layout.align(textSize.x, textSize.y, horizontal, vertical, screen);
// Render text
@ -96,6 +98,8 @@ public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRen
renderer.flush();
renderer.endRendering();
}
@ -106,7 +110,7 @@ public class JOGLTextRenderer2d extends AbstractTextRenderer implements ITextRen
if (renderDelegate != null) {
if (renderDelegate instanceof DefaultTextStyle) {
((DefaultTextStyle) renderDelegate).setColor(AWTColor.toAWT(color));
renderer = new TextRenderer(font, true, true, renderDelegate);
renderer = new TextRenderer(awtFont, true, true, renderDelegate);
}
}
}

View File

@ -1,12 +1,14 @@
package org.jzy3d.plot3d.text.renderers.jogl;
import java.awt.Font;
import java.awt.geom.Rectangle2D;
import org.jzy3d.colors.AWTColor;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.AWTFont;
import org.jzy3d.painters.Font;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
@ -39,7 +41,7 @@ import com.jogamp.opengl.util.awt.TextRenderer;
* @author Martin Pernollet
*/
public class JOGLTextRenderer3d extends AbstractTextRenderer implements ITextRenderer {
protected Font font;
protected java.awt.Font awtFont;
protected TextRenderer renderer;
protected TextRenderer.RenderDelegate renderDelegate;
protected float scaleFactor = 0.01f;
@ -50,7 +52,7 @@ public class JOGLTextRenderer3d extends AbstractTextRenderer implements ITextRen
public JOGLTextRenderer3d() {
this(new Font("Arial", Font.PLAIN, 16));
this(new Font("Arial", 16));
}
public JOGLTextRenderer3d(Font font) {
@ -64,14 +66,14 @@ public class JOGLTextRenderer3d extends AbstractTextRenderer implements ITextRen
* @param is3D the text will be facing camera if false.
*/
public JOGLTextRenderer3d(Font font, TextRenderer.RenderDelegate renderDelegate) {
this.font = font;
this.renderer = new TextRenderer(font, true, true, renderDelegate);
this.awtFont = AWTFont.toAWT(font);
this.renderer = new TextRenderer(awtFont, true, true, renderDelegate);
this.renderDelegate = renderDelegate;
}
@Override
public BoundingBox3d drawText(IPainter painter, String s, Coord3d position, Horizontal halign,
Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
public BoundingBox3d drawText(IPainter painter, Font font, String s, Coord3d position,
Horizontal halign, Vertical valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
// configureRenderer();
resetTextColor(color);
@ -138,7 +140,7 @@ public class JOGLTextRenderer3d extends AbstractTextRenderer implements ITextRen
// work in progress, used to compute bounding box of the text
protected void drawText3DWithLayout(IPainter painter, String s, Coord3d position,
Coord3d sceneOffset) {
Rectangle2D d = renderDelegate.getBounds(s, font, renderer.getFontRenderContext());
Rectangle2D d = renderDelegate.getBounds(s, awtFont, renderer.getFontRenderContext());
Coord3d left2d = painter.getCamera().modelToScreen(painter, position);
Coord2d right2d =
new Coord2d(left2d.x + (float) d.getWidth(), left2d.y + (float) d.getHeight());
@ -168,7 +170,7 @@ public class JOGLTextRenderer3d extends AbstractTextRenderer implements ITextRen
if (renderDelegate != null) {
if (renderDelegate instanceof DefaultTextStyle) {
((DefaultTextStyle) renderDelegate).setColor(AWTColor.toAWT(color));
renderer = new TextRenderer(font, true, true, renderDelegate);
renderer = new TextRenderer(awtFont, true, true, renderDelegate);
}
}
}