am working on generating font metrics on server-side by giving ttf file as input.
Iam trying to Font , FontRenderContext , GlyphVector and GlyphMetrics classes.I have also tried Apache FOP but the metrics generated are not help me.
Would like to know if the following operations are possible?
given unicode , how do I know if this has an independent glyph or it has to be compounded with another glyph etc.
Is it possible to generate font metrics with all these details and use it for calculating my line width
How do I know if a glyph is a ligature and how can I get the glyph width post rendering?
Can I assume that a compounded glyph will always appear to the right?
any pointers to these will help?
Related
To register my custom lato font I use this method: PdfFontFactory.register. Afterwards I print out all fonts to verify it gets registered.
Then I use the font like so
setFont(PdfFontFactory.createRegisteredFont("lato-regular"))
However there are very subtle differences in the display using the same ttf file on my website vs my pdf.
For example, the dot above the "i" is not circular but more of a rectangle with rounded edges when using iText. Any ideas?
I'm creating a game and I'd like to use Java's Font.MONOSPACED font, because it is easy to use (even though it looks disgusting). The problem is that I have no idea about the fonts width-height-ratio, which is very important. I couldn't find a answer online after searching for a while.
If someone knows it or how to find it out, I'd be very grateful.
java.awt.FontMetrics is going to be your friend here.
You get access to it through a Graphics2d object:
Graphics2D gfx = ...;
gfx.setFont(...); // select your preferred font, monospaced or otherwise
FontMetrics metrics = gfx.getFontMetrics();
having done so you can get: (all from the above link to docs)
The width of any single char:
charWidth(char ch)
Returns the advance width of the specified character in this Font.
The width of a string:
stringWidth(String str)
Returns the total advance width for showing the specified String in this Font.
The height of a line
getHeight()
Gets the standard height of a line of text in this font.
I assume you can figure out how to get a width-height ratio from the above, and you can get lots of other information from different FontMetrics methods - check it out.
I'm using Jfree chart in my application. The internationalization works perfectly for German,Russian,French...But in Chinese, Japanese the x and y axis texts are looks like square box. How to solve this problem?
Thanks.
Check the link below, it seems to be talking about the exactly same problem:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=109313
You need to ensure that you are using a font that supports the
characters you are trying to display. If you see squares, that's an
indication that the font doesn't have glyphs for the unicode character
you are trying to show.
I have seen http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/font/GlyphVector.html but I don't know how you would use it to display a glyph on the screen. Lets say you want to print glyph number 1042 (likely to be different in each font and unlikely (but possible) to be the same as Unicode 1042) to the screen. How do you go from the number to the character on screen? Is GlyphVector the way to go or is there a better method?
That GlyphVector class is not available on Android. There don’t seem to be any public API calls in Android graphics that allow access to font glyphs without going through the Unicode encoding.
Your obvious option would seem to be direct parsing of the TrueType font file. Perhaps find some library somewhere that has been ported to Android, or could be so ported (Freetype?).
I'm making a unicode Sinhala-English translator. When I print a Sinhala unicode letter with font size < 100, the letter is not correctly rendered. But when I use font size > 100, all letters are rendered smoothly. I can't find why this happening. On the other hand, all Sinhala unicode fonts do the same & it's not a bug of the font that I used. An Example is shown here.
Please help me.
I'm not aware that Java uses its own font rendering on Windows 7. So it should be a Windows bug but if that was the case, you'd see the problem in all Windows apps - but you see it only in Java.
You may want to try the Java 2D API. For example render the font with 140px and scale the Graphics2D by 0.5 to get 70px fonts.
[Old answer]
You're not saying which OS but my guess is that this is on Linux. If that's the case, then it might be because of "font hinting" in FreeType.
Basically, if a font becomes "too small" to render, the true type file can contain "render hints." In your example, you can see that the large font has smooth edges but the small example is more square-edged. You can see the pixels; anti-aliasing should prevent that.
So my guess is that you're a victim of the Font Hinting patent. The patent in question has expired last year. Try to find a newer version of "freetype" for your system.