Problem with FOP Image scaling in Java - java

Okay, so here's my problem:
We use FOP for creating "pretty" report output. We use the pdf option if the user wants a file, AWT for previewing, and the -print option for printing them. We are using FOP 0.25.x, which I fully recognize is not the newest version, but upgrading to 0.95 appears to be a non-trivial task that I don't necessarily want to undertake.
Anyway, it was noticed by one of our users that when printing ID cards (generated via FOP -print option) to the id card printer, the images on the cards (pictures of the employees) had some corruption in them...sort of like like green and reds dots and lines. We also discovered that if we sent the exact same print request to one of our HP color laserjets, it printed fine. To add to the strangeness, if we use FOP to create a PDF of the ID card and then print it via acrobat reader on the card printer, it prints fine.
I eventually discovered that it had something to do with the scaling of the images...we were scaling 600px high images down to something like 120px. If I presized the images down, even just halfing them, the corruption went down noticeably. Similarly, when I upsized the images, the corruption went up.
So my question: anybody have ANY idea what is going on here? Or has ever run into such a thing?
Since I don't know why this is happening, I don't know how to fix the root cause, but I've been working through some various workarounds:
1) Use FOP to create a pdf of the image and then print that via Java. This seems like an obvious answer, but some Googling around showed that printing a PDF via Java is not trivial. I've seen the PDF Renderer project on java.net, but seems pretty bulky for a single very specific application.
2) Try to resize the images before giving it to FOP. This also seemed pretty straightforward, however our various users can setup stylesheets for these id cards however they want and using "pt" and "in" sizing in them seems to be pretty common...I don't know of any good way to map that to a pixel resizing.
If anybody has any insight into the root cause, ways to make these work arounds work, and/or another idea, you'd be in my debt.

Most certain explanation:
image corruption? it's a bug.
Why not use 0.95? Sooner or later you have to upgrade, Apache consortium won't
fix bugs in 0.25.x versions.
You can't hope to find workarounds for every bugs which might occur in future.

I ended up doing the second thing I mention in the original question...i.e. resizing it before giving it to FOP. I found that I could retrieve the dpi of the printer I was printing to and do some math on it to get pixel sizing. Seems to work perfectly in all my testing...not a real solution but an adequate workaround.

Related

Sikuli issue - capturing an area

What I am trying to accomplish is to select an area on the screen with the mouse (outside of the may frame) and get the resulting region coordinates using Sikuli.
The code that should do this looks is below:
Screen screen = Screen.getPrimaryScreen();
Region region = screen.selectRegion("Select the area.");
What happens is that the cursor turns into a selector cross (the ones you usually see when you expect this function), but I can't select the area and actually the only way I can get back from the application is by killing it. Not too many examples I have found so I am asking for help here.
How can I make this work?
Also one other question:
I have downloaded the following script version:
Sikuli-IDE-1.0.0-Win64.zip
This means if I want to create a crossplatform solution I have to include like 6 jars? I have found a more universal Java API it seems (that is what it is called actually):
https://code.google.com/p/sikuli-api/
With all required supported OS but I can't find a single example on what I am trying to do that is similar to the little code snippet I pasted here. The sikuli script I am using now and this Sikuli API (apparently not the same) seems to be just different enough to amke this difficult.
Any suggestions? Thanks a lot in advance.
As it turns out, this only happens if I put this functionality on a Swing button's actionhandler. I have reported the bug to Sikuli and it will be probably fixed in the next release.

Java converter for CgBI images to RGBA?

I have a need to be able to programmatically convert a PNG file that has been optimized for an iOS application and remove the optimizations. A number of posts reveal the mechanism for doing this, but I was hoping there was some Java code already out there for doing this before I go do this on my own.
Does anyone know of a Java converter for CgBI images to RGBA?
I got interested on the topic and made some research on the area. On one related page on PNG conversions I ended up to a jar package type of converter which may be something that you'd be pleased of. I suppose it to be some sort of Open Source solution, because the source was announced to be found from the same place.
I wrote a command line C program that does the same. In addition to the other converters (I have yet to test the online one), mine can handle multiple IDAT chunks, Adam7 interlacing, and all row filter types -- the latter is necessary to de-multiply color pixels with their alpha. All of this leads to, AFAIK, the very same image that got fried.
See my website for the full C source code.

Searching for Java library to build an app that interacts with data

I have a project where I should analyse data via cluster analysis. Basically the data should be visualised like this picture shows
Each dataset - for example let it be people - is one horizontal row, where vertical lines showing the attributes like sex, age, and so on.
Now if this data could be shown I also want to move the rows horizontal and also vertical a) via code and b) via drag & drop.
Do anybody know a good library for that?
Important
Target is desktop application
Expected datasets around 500
Attributes for each data set around 60
There is an app in Java/SWT already, so solutions in this direction would be preferred
The OS is Win7 so C# or similar would be a stopgap
I really like d3.js, and would prefer a similar lock & feel (but in 3D)
If somebody has recommendations for a library which helps to analyze the data, please step forward too!
Check What is the best open-source java charting library? and Libraries for pretty charts in SWT? for more info.
I did used JFreeChart with SWT (2 years ago). The code is quite horrible (you have to write tons of code), but it works and is directly renderable with SWT components (no need of SWT_AWT bridge).
EDIT
When I thought about it again, I realized, that you can use the JavaScript library through Browser widget. It's quite heavyweight solution, but it might work..
You can do this in d3 but it is a very involved process in which you need to deal with the ismoetric perspective and the rest. It shouldn't be terribly complicated but it will not be an out-of-the-box solution.

Scaling images/icons in Java

A project I am working on needs to be resized when the monitor resolution changes. Due to legacy code and other issues, we do it by using a custom library which scales all the components to the appropriate sizes when the resolution changes.
However, when we scale some of the images/icons used in the project, they become blurry/fuzzy/aliased. Mostly because they are all raster gifs.
One solution we thought might work to mitigate this issue is to either use Vector images and convert them into raster images on the fly (and cache them for performance improvements).
What do you all think? Would this be a good way to go? Or are there better alternatives to my chosen method?
If this is a better way, then can someone give pointers to how to go about the svg conversion to say jpg or png(preferably). Available (and commercially usable) libraries?
Thanks
The algo's in java are pretty good. The fundamental problem sounds as if your original images/icons are already too small so scaling them up leaves you with artefacts. A real simple approach is to have the images sent along with the app to be at the larger size and only scale down. I would say a policy on images sizes (pixels height and width) is necessary as you seem to indicate that only some have problems.
Of course if you can go for vector graphics, you can scale infinitely and this may be a better long term investments depending upon your application and the likely hood of needing to support large output formats (not just screens but printing). It may well be fairly complex to approach things this way. (More information would be needed to help you further with the points in this para.)
Batik can convert svgs into pngs or jpegs
The icons in the Metal (cross-platform) PL&F are drawn into a buffered image, in order to blend in with whatever machine it happens to find itself running on. It's a fast technique, doesn't add dependencies and there's no need to learn any extra APIs (or languages!). See src.zip in your Sun JDK.

fonts on org.eclipse.swt.widgets.Composite are messed up on Linux

I extend org.eclipse.swt.widgets.Composite and create many widgets on it, (labels, table, text etc). The problem I am facing is that the labels' text is getting truncated on linux while it appears fine on windows. When I change the linux's font to gothic the truncation is little less but still there. Is there way to homogenize the windows and linux display. What could be the best font to use in linux in such a case.
More likely it is related to this eclipse bug which I just lobbied to have re-opened: https://bugs.eclipse.org/bugs/show_bug.cgi?id=151322
It sounds like you are using absolute positioning instead of dynamic layouts. (If this isn't the case, perhaps you could post code demonstrating the problem). Using a dynamic layout should ensure that controls are resized to accommodate their contents. (They're also great if you ever translate a product, because then you don't have to rejig every dialog for every language.)
To complete McDowel's answer, there is also a bug related to the way Linux check for wrapping label:
It is fixed since 3.4M7.
Even though it may not be related to your case, it would be useful to know which version of eclipse you are using and if you can reproduce your bug with the latest ones (like a 3.5M6)

Categories