Why does my UnicodeFont (Slick2D) not draw? - java

So I am trying to draw a font using Slick2D's UnicodeFont. The code that loads the font:
Font font = new Font("Arial", Font.BOLD, 20);
UnicodeFont uFont = new UnicodeFont(font);
uFont.addAsciiGlyphs();
uFont.getEffects().add(new ColorEffect(java.awt.Color.BLACK));
uFont.loadGlyphs();
It's more or less copied and pasted from the wiki. Next, during a frame I use gluOrtho2d() and reset the projection and modelview matrices. Then I call
this.font.drawString(100, 50, "some text goes here");
to actually draw the text. But all I get is an empty screen, an no errors of any kind.

Considering that UnicodeFonts are depreciated in the current version of slick 2d, I recomend you folow my steps for using AngelCodeFonts on this related question: Slick2D Fonts don't work

Related

Generate a png of a chart in Java [duplicate]

How does one programmatically render image files from JFreeChart . I have code for ChartPanel: is it possible to render directly to an image - without creating AWT/GUI components?
val chart = .. // Imagine code to generate chart data here..
val panel = new ChartPanel(chart)
panel.renderToImage() // replace this with logic to save image file
Use one of the ChartUtilities methods, such as writeChartAsJPEG() or writeChartAsPNG(), that can write to a java.io.OutputStream; or saveChartAsJPEG() or saveChartAsPNG(), that can write to a java.io.File. Some examples are seen here and here. For example,
ChartUtilities.saveChartAsPNG(new File("chart.png"), chart, width, height);
You'll also want to look into headless mode, mentioned here.

How to Embed Font in JavaFX?

How can I embed a custom font in a JavaFX Application? I've tried making a fonts.mf file, and following the instructions to a similar question linked below. I don't want to use CSS if I don't have to. I want to focus on learning core JavaFX stuff.
Here is what I've been messing around with:
private static Label makeTitle() {
Label title = new Label("Bandit King");
Font font = new Font("OldStyle", 40);
title.setFont(font);
return title;
}
my fonts.mf file contains just this line:
OldStyle = /home/myName/Desktop/My_Java_Projects/Bandit_King/banditKing/OLDSH.TTF
This is not a duplicate of this question. Eclipse says, "CustomFontApp, cannot be resolved to a type".
I've tried making a fonts.mf file
You don't need it.
This is not a duplicate of this question. Eclipse says, "CustomFontApp, cannot be resolved to a type".
CustomFontApp is just the name of a class used in the answer you linked - your class name is obviously different, and you should've changed it.
This line:
Font font = new Font("OldStyle", 40);
will load OldStyle font only if it's installed on your system. You aren't using an installed font, but the embedded one, so that won't work.
You need to use Font.loadFont(InputStream, double) or Font.loadFont(String, double) to load your custom font from disk:
// use this to load font from your application's resource folder (`res/fonts/OLDSIH.TTF`)
Font font = Font.loadFont(getClass().getResourceAsStream("/fonts/OLDSIH.TTF"), 40);
// or this one to load font from the specified (absolute) path
// (not recommended, use the method above or, at least, change this into relative path):
Font font = Font.loadFont("file:///home/myName/Desktop/My_Java_Projects/Bandit_King/banditKing/OLDSH.TTF", 40);

Server-side/ non-interactive rendering of Charts to image files from JFreeChart

How does one programmatically render image files from JFreeChart . I have code for ChartPanel: is it possible to render directly to an image - without creating AWT/GUI components?
val chart = .. // Imagine code to generate chart data here..
val panel = new ChartPanel(chart)
panel.renderToImage() // replace this with logic to save image file
Use one of the ChartUtilities methods, such as writeChartAsJPEG() or writeChartAsPNG(), that can write to a java.io.OutputStream; or saveChartAsJPEG() or saveChartAsPNG(), that can write to a java.io.File. Some examples are seen here and here. For example,
ChartUtilities.saveChartAsPNG(new File("chart.png"), chart, width, height);
You'll also want to look into headless mode, mentioned here.

Adding maps at iText Java

I am using java and iText to create a pdf. Is it possible to add a map with a pointer on it so the user will know where the starting point is?
Clarification (from a meanwhile deleted answer by the OP which should have been an edit of the question)
my problem is can i add at iText google map from web and not as an image
Since you didn't answer my counter-question added in comment, I'm providing you two examples. If these are not what you're looking for, you really should clarify your question.
Example 1: add a custom shape as extra content on top of a map
This is demonstrated in the AddPointer example:
PdfContentByte canvas = writer.getDirectContent();
canvas.setColorStroke(BaseColor.RED);
canvas.setLineWidth(3);
canvas.moveTo(220, 330);
canvas.lineTo(240, 370);
canvas.arc(200, 350, 240, 390, 0, (float) 180);
canvas.lineTo(220, 330);
canvas.closePathStroke();
canvas.setColorFill(BaseColor.RED);
canvas.circle(220, 370, 10);
canvas.fill();
If we know the coordinates of the pointer, we can draw lines and curves that result in a the red pointer shown here (see the red pin near the Cambridge Innovation Center):
Example 2: add a line annotation on top of a map
This is demonstrated in the AddPointerAnnotation example:
Rectangle rect = new Rectangle(220, 350, 475, 595);
PdfAnnotation annotation = PdfAnnotation.createLine(writer, rect, "Cambridge Innovation Center", 225, 355, 470, 590);
PdfArray le = new PdfArray();
le.add(new PdfName("OpenArrow"));
le.add(new PdfName("None"));
annotation.setTitle("You are here:");
annotation.setColor(BaseColor.RED);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setBorderStyle(
new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID));
annotation.put(new PdfName("LE"), le);
annotation.put(new PdfName("IT"), new PdfName("LineArrow"));
writer.addAnnotation(annotation);
The result is an annotation (which isn't part of the real content, but part of an interactive layer on top of the real content):
It is interactive in the sense that extra info is shown when the user clicks the annotation:
Many other options are possible, but once again: your question wasn't entirely clear.

How to customize series fill in area chart via BIRT chart API?

I am trying to create a gradient fill for a series in an area chart that I am building through the BIRT chart API, but the book "Integrating and Extending BIRT" and the Interwebs seem curiously silent about how to get it to work. It seems no matter what I do, I always get a flat color from the default palette. I've tried using SeriesDefinition.getSeriesPalette().update(Gradient) and even creating my own Palette with the gradient fill in it and setting that on the SeriesDefinition, but to no avail. I've also noticed that if I do not perform a shift() on the Palette, even if it's shift(0), which the Javadocs claim will do nothing, I get NullPointerException when I try to generate the chart:
Caused by: java.lang.NullPointerException
at org.eclipse.birt.chart.render.Area.renderDataPoints(Area.java:521)
at org.eclipse.birt.chart.render.Line.renderSeries(Line.java:570)
at org.eclipse.birt.chart.render.AxesRenderer.renderPlot(AxesRenderer.java:2181)
at org.eclipse.birt.chart.render.AxesRenderer.render(AxesRenderer.java:314)
at org.eclipse.birt.chart.factory.Generator.render(Generator.java:1368)
... 108 more
Here's the latest (non-working) code that I've tried:
Gradient gradient = FillUtil.createDefaultGradient(BirtReportBuilder.COLOR_WHITE);
gradient.setStartColor(ColorDefinitionImpl.WHITE());
gradient.setEndColor(ColorDefinitionImpl.create(76, 116, 131));
gradient.setDirection(90);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getQuery().setDefinition("\"Quantity\"");
Palette pal = PaletteImpl.create(gradient);
pal.shift(0);
sdY.setSeriesPalette(pal);
sdY.getSeries().add(as1);
yAxisPrimary.getSeriesDefinitions().add(sdY);
So what's the magic incantation to get the BIRT charting API to use my Gradient as the area fill?
This code works for me, I get a ugly coloured serie...
sdY.getSeriesPalette().update(GradientImpl.create(ColorDefinitionImpl.create(255,255,255), ColorDefinitionImpl.create(200,0,0,150), 90, false));
Hope it will help you ;p

Categories