I am building an Excel file with Apache POI. After I add all of the content I autosize the columns using sheet.autoSizeColumn(i).
Sometimes it doesn't quite give enough space. I have tried Verdana and Calibri-Regular (had to switch to Calibri-Regular from Calibri because the autosize was going completely crazy all of a sudden on our Windows 7 boxes but worked fine on our Linux boxes, which is a mystery to me). Is there something I can do to fix this? Or is there a way to add a little padding after autosizing?
Edit:
On my Windows dev box I tried setting the font to Verdana with font.setFontName("Verdana"). All of the content definitely changes to Verdana and the sizing on the columns is perfect. On the Linux production box I used the bit of Java code that Gagravarr referenced in the below comments to print out a list of the fonts that Java sees. I tried Monospaced but the spacing was identical to the above screenshot. I then tried Dingbats and the content was still readable (which it shouldn't have been) while the spacing was really off (see screenshot below).
Also openjdk and Oracle JDK do not use the same font engine (SUN∕Oracle kept its legacy engine for fear any change would break badly coded apps). It's quite possible openjdk will work better on linux for font stuff, since it reuses the same font libraries as the rest of the system, instead of reinventing a square wheel.
Fonts are a legal nightmare; Linux fonts licensing is usually liberal enough you can copy, modify and deploy them anywhere but the reverse is not true (Microsoft was very careful to create vendor lock-in for anyone foolish enough to build apps depending on Windows fonts)
I am not sure whether this will resolve your problem or not, but if you have asked about "is there a way to add a little padding after autosizing?".... yes you can do it by following way.
testSheet.autoSizeColumn(ColIndex);
testSheet.setColumnWidth(ColIndex ,testSheet.getColumnWidth(ColIndex)+PaddingWidth);
Related
I am using Pentaho Report Designer 3.8.3 and I have small, aesthetic problem with fonts.
I have implemented, or better say, I am aimplementing OpenSans font into my pentaho.
Its cirrent state is, that i have installed this font into Linux(which is my pentaho runing on) and also into java. But i still have 2 problems with fonts:
1.) I see OpenSans font in html only when i open it on PC where it actually is installed. Whenever i open report with openSans font on machine where it is not installed, it change it for something else, Arial for example.
(I have added OpenSans to: '/usr/lib/jvm/' and also into: '/usr/share/fonts')
2.) After publishing report to PDF, I see only '?' instead of accentuated characters. But in html, I see no '?', each letter is as it should be.
(I have added
org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Encoding=ISO 639-1 #my language code, Slovak
into '/home/pentaho/pentaho/biserver-ce/tomcat/webapps/pentaho/WEB-INF/classes/classic-engine.properties' file)
Does anyone have an idea wht else should I try to make it work properly?
I'm not sure what you can do with html export other than doing the usual approach of setting the font-family so it has something to fall back to.
However in PDF look carefully at the pdf export options, you'll see there's a "embed fonts" option. Enable that and your pdf will work anywhere!
I'm generating a pdf report with Jasper Reports 3.1.2. I have a multi line text field that contains several lines: this field is split over 2 consecutive pages.
The problem is that on AiX and Linux systems the last line in the first page is always missing (on Windows systems everything is fine). I've tried modifying margins, sizes and fonts but nothing happens: the last line of the first page is always missing
Any idea?
Thanks in advance
What font are you using? Problems like this are usually† caused by fonts not being available. Use font extensions to ensure that you know what font is being used, and then it should render well everywhere.
Also make sure to set this in jasperreports.properties:
net.sf.jasperreports.awt.ignore.missing.font=false
That's great for testing since it catches missing fonts immediately.
†By "usually" I mean "so often that it's indistinguishable from always". But of course it's theoretically possible that there is some other source in this case.
I think the answer here is no (ie if the fontmetrics don't exist, then how could you). But I figure it's better to ask.
I need to figure out soft line breaks in a Java program that oftentimes is run on a Linux box. The fonts specified for the text we are breaking comes from a Word file so it uses the fonts found on a Windows system like Times New Roman.
Most Linux systems don't have Times New Roman installed. Is there any way to get accurate breaks with the specified font not installed?
And second question - we have found copying the Windows fonts to a Linux box will give us different breaks than we get on the Windows system. Do the fontmetrics have to be tuned to an O/S and/or to a Java implementation?
thanks - dave
I'm working on an application that accepts text in English and performs transliteration with a custom 3rd party API into an Indic language (one of several that are supported). The application is targeted at Windows XP/7 and Ubuntu.
We use a custom input method that loads the required Indic font, and uses it render text. Also, the user can correct the transliterated text by typing in English and pressing space (similar to how Google Transliterate works).
The problem is that with certain Indic fonts, typing in English shows up empty box characters (even though the actual characters typed are detected and transliterated accordingly).
I have used the ttf-indic-fonts-0.5.0 font pack that comes with Ubuntu, and was able to substitute some of them. For the others, if I copy the corresponding font from Windows (I'm developing this on Windows 7) then all problems are solved.
However, we cannot redistribute Windows fonts with our application and want an open alternative.
Other than trying to find a substitute font, is there anything else that we're doing wrong, or need to check, to make sure that English characters can be typed in a JTextField when an Indic font is being used?
As an example - from the Ubuntu package mentioned above, the lohit_pa.ttf font for Punjabi has this problem. If I copy the default Windows font for Punjabi (raavi.ttf) then it works fine.
I found a solution to the problem. I installed the fonts on Windows (open the font, click install) and browsed the contents using Character Map. These fonts only have glyphs for the language in question, not English.
I used FontForge to merge the 2 fonts. (Fontforge's author doesn't provide binaries anymore - but if you have access to Ubuntu you can install it from the repository. No such luck if you only have Windows).
After this, I'm able to type in English again.
I am trying to make IBM jre to use PCF fonts from default X11 installation on my linux box. In particular adobe-helvetica font. I have toyed to modify fontconfig.properties in jre/lib folder but no matter what I do Java seams to use some other fonts. I guess there is some algorithm how java VM tries to link java logical fonts to actual physical fonts in the system even in case when font specified in config could not be used. On Windows it is pretty straight forward, but on Linux I was unable to make it work with anything except TrueType fonts.
Anybody have experience with configuring fonts on IBM jre on Linux?
I've spent all morning learning about Java fonts. There's a lot of limitations, some of which are removed in Java 1.6. I don't have any answers, but here is some information I have that might be helpful.
Java distinguishes internally between system fonts and created fonts. (News flash to Sun: it'd be nice to make that clear through subclassing!) The system fonts seem to be fonts installed in the JRE possibly plus some of the fonts installed on your system. But apparently not all of the fonts installed on your system; I, too, have adobe-helvetica on my Linux system but it doesn't seem to be accessible from Java under any name I can think of.
Meanwhile, you can create fonts from a font file with the Font.createFont() method. You have to specify the font file type. The only constants I found to specify these types in the Font class are TRUETYPE_FONT and TYPE1_FONT. So it looks like if PCF fonts are available, it isn't made explicit through providing a constant to specify them. Maybe somebody else knows more. I did see some information online about using bitmap fonts in Java ME, so it must somehow be possible to use other types of fonts.
Once you have a created font, you can add it to the JVM's concept of available fonts with the GraphicsEnvironment.registerFont() call, but that is only available on Java 1.6 and later.
The PCFFont package seems to provide the ability to use PCF fonts from Java. Unfortunately I think it does so with a custom PCFFont class which does not extend the java.awt.Font class, so I would say its usefulness is probably limited. However, it might give some pointers to implementation details for writing a custom subclass of Font which can handle PCF fonts. Finding the source code isn't immediately obvious; code for that exact class is here.
I would say the author seems a little confused, because he talks about converting TrueType fonts to PCF so you can use them with his library, and Java already supports TrueType fonts natively. But he appears to be an engineer from Sun, so maybe he knew more than I think; also, this could just be very out of date (was there ever a time when Java didn't support TrueType?).