|
Clarification on private fonts |
Posted by Adrian on Jul-23-2014 12:05 |
|
Hi,
in this link http://www.advsofteng.com/doc/cdjavadoc/fontspec.htm
It says I can use my own fonts. All I have to do is put them into my webapp WEB-INF/classes directory.
- Can I put it into a specific package(folder) or do i have to put them all in the classes directory?
- Does it have to be TTF type?
- Is there a way to detect what font chartdirector will use at the end?
Currently I have this Java code
TextBox title = null;
title = c.addTitle("My Title", "Times New Roman;Liberation Sans;Arial Unicode MS", 12, Constants.HEX_COLOR_BLACK);
title.setMargin2(0, 0, 5, 15);
Is there a way to tell what font CD is actually using when the chart is created?
Thanks |
Re: Clarification on private fonts |
Posted by Peter Kwan on Jul-23-2014 18:45 |
|
Hi Adrian,
For "ChartDirector for Java", ChartDirector can use any font that is known to your Java
VM. You may use the standard Java API
GraphicsEnvironment.getAvailableFontFamilyNames to determine which fonts are known to
your Java VM. See:
http://docs.oracle.com/javase/7/docs/api/java/awt/GraphicsEnvironment.html#getAvailab
leFontFamilyNames()
If you are using a font that is not known to your Java VM by default, there are several
options:
(a) Install the font to your Java system, so that it is known by your Java VM. Please
refer to the documentation of your Java VM on how to add a font to it.
(b) Load the font file using Font.createFont, then register it to your Java VM using
GraphicsEnvironment.registerFont. The font is then known to your Java VM and can be
used by ChartDirector.
(c) Pass the font file name as the font to the ChartDirector API. ChartDirector will search
several places for the file, including seraching the Java class path. If the file is found, it
will load the font and use it.
With (a) and (b), you can use any font format that is supported by your Java VM. With
(c), you can only use true type font.
Note that with (c), you need to specify the font file name or path name (or more
accurately, the resource name), not the "postscript font name", because ChartDirector
needs to find the file in order to load it. For example, you need to use something like:
c.addTitle("My Title", "ARIALUNI.TTF");
With (c), you can put the font files in any directory in your Java class path. If you are
writing a JSP application, the "WEB-INF/classes" should be in the Java class path of your
JSP application, so you can put the font file there. You can also put the file into a
package if your package is in the Java class path.
If you use "Times New Roman;Liberation Sans;Arial Unicode MS" as the font, then all the
fonts must be fonts known to your Java VM (as they are not font file names).
ChartDirector will use the first font that contains the character you need to display. For
example, if the first character in your title is "M", then it will choose "Times New Roman"
(assuming Java knows this font). If the second character is a Japanese character, then
the ChartDirector will use "Arial Unicode MS", as only this font contains Japanese
characters. That means each character in your title can use a different font, and the
actual font used depends on the characters in your title. If your Java VM does not know
any of the fonts in the list, it is possible it will use a substitute font instead.
If you want to check if ChartDirector can successfully open a font, you may use the
ChartDirector API Chart.testFont. See:
http://www.advsofteng.com/doc/cdjava.htm#Chart.testFont.htm
Hope this can help.
Regards
Peter Kwan |
Re: Clarification on private fonts |
Posted by Adrian on Jul-24-2014 01:48 |
|
Thanks for you in depth reply. I will give your suggestions a try.
One last question. We are moving our app from one version of Linux to another version (centos). I noticed that even though the new version uses the same fonts as the old version, the fonts appear pixelated. I tried using c.antialias(1, "true") but to no effect.
I've read your replies and you mentioned that its mostly up to the JVM.
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=&thread=1119926834
That reply was a while back and for CD 4. Has anything changed since then? Any new solutions that you've heard of? Can I for example use a font that is cleartype only, or will the JVM always convert it back to pixelated mode? Or perhaps a setting in the JVM arguments?
Thanks |
Re: Clarification on private fonts |
Posted by Peter Kwan on Jul-24-2014 04:07 |
|
Hi Adrian,
For "ChartDirector for Java", the text are rendered by the Java VM, not by ChartDirector.
ChartDirector only requests the Java VM to render the text using the specified font, and
use ClearType if your specify ClearType. On Linux, it is quite possible the Java VM does
not render as specified because of various reasons. For example:
(a) The Java font system may not be working. By default, many Java VM on Linux/UNIX
rely on X Window services to support fonts. If X Windows services are not enabled, the
Java font system will not work. In this case, there is no font support at all, but
ChartDirector can still use some bitmap substitute fonts as a last resort, and they are not
anti-aliased. In Java 1.4 or above, you may enable "headless mode" to allow the Java
font system to work on systems without X Windows. See:
http://www.oracle.com/technetwork/articles/javase/headless-136834.html
In brief, when you start the Java VM, please try to add "-Djava.awt.headless=true" in the
command line.
(b) The Linux may not have the required font installed. For example, the Arial font is
copyrighted Microsoft, so it is unlikely Linux will have such font pre-installed. (You can
however download it legally yourself subjected to Microsoft licensing terms.) If the Linux
does not have the font, the Java VM may use a substitute font, which can be pixelated.
(c) The Java VM may not support ClearType at all. It is known that SUN Java 1.6.0 or
above supports ClearType. You may want to use the latest version of Java from SUN.
There is a diagnostic JSP script "cdinfo.jsp" that comes with ChartDirector, and it includes
a font loading test. You may try this script and see what it says.
Regards
Peter Kwan |
Re: Clarification on private fonts |
Posted by Adrian on Jul-24-2014 04:39 |
|
Thanks for the info.
I ran the cdinfo.jsp file. This is what it returned :
Font Loading Test :
Trying to open font Arial at 8.0 pts.
Using ChartDirector internal font system.
Font Arial is mapped to helv.font.
Font helv.font successfully opened.
Using Java font system (java.awt.Font).
Font Arial successfully opened as java.awt.Font[family=Arial,name=Arial,style=plain,size=11].
I'm not sure I understand the results. Is it running in headless mode? Did it find the fonts on the system? can it load the fonts on the system?
I also have a custom jsp that I use (below) that finds all Fonts on the machine. When I run that, it returns all fonts that I know are installed. So I imagine that CD is finding my fonts? Am I right?
Available fonts are :
<%
String[] f = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (int i = 0; i < f.length; ++i)
{
%>
<%=f[i]%>
<%
}
%> |
Re: Clarification on private fonts |
Posted by Peter Kwan on Jul-25-2014 02:01 |
|
Hi Adrian,
From the output, it seems the Java font system is working fine. However, for some reasons,
ChartDirector still prefer to use the internal backup fonts for Arial.
To force ChartDirector to use Java fonts, there are two methods:
(a) Instead of using ChartDirector.jar, please use ChartDirector_s.jar. The
ChartDirector_s.jar is in the ChartDirector/javademo subdirectory. It is the same as
ChartDirector.jar but without the internal backup fonts. With no backup fonts, it will always
use the Java font system.
(b) In your source code, instead of using "Arial" font, you can use "java:Arial". This will
force the Java version of the Arial font be used. As this involves changing the source code,
I think method (a) is preferrable.
Please kindly let me know if this can solve the problem.
Regards
Peter Kwan |
|