Monday, September 29, 2008

Step 0.1 - Papildomi reikalavimai

Sveiki, jei turite pastabų ar pageidavimų meskite kaip komentarus.

Dėkui.

Wednesday, September 24, 2008

Step 3 - SVG template fitting with data.

Current status. Now I have a SVG viewer and SVG printer. Both of them are working, one issue  what I left with is a precise size of the printed out SVG document, but almost sure I will be able to fix it.

Now I have to merge product's data from database with SVG template and get an output SVG file suitable for printing. All SVG template files are produced by professional graphic designers, they are designed on Corel Draw and then exported to SVG file format. These template files have to be updated with data what are retrieved from database. To do that job I see two general options, to use any templating language or XSLT. Independently on any chosen option it's preferable to have a clean easy readable and ordered SVG file.

Few days ago, I took a first look at source of exported SVG file. I wasn't been impressed by it's quality. I did expect to have to do some manual editing of produced file, but never thought about so horrible result. Actually I found a few major issues, what I had to solve. The first issue was , text was distributed over separate small text nodes. Some sentences was chunked to separate words, even some words had separate text node for every single letter. Other issue, oder of text information in template file was randomly distributed over all the file. 

As I said in my previous posts I have quite a few options to use: FreeMarker, XSLT, Velocity. After some tests I bet on Velocity. Some samples will follow in following posts. 

The hardest part is how to get exact visual result of the label. In order to achieve that I was forced to start using some SVG tags from SVG version 1.2. Result I got back is good enough, still have to do some little tweaking.


Step 2 - SVG printer - Continued

As I mentioned before in the previous post, I was not able to find a batik print example. It turned out, that information about SVG printing I was able to find in batik-user mailing list. It took some time to collect working solution from little parts. So mailing list helped again.

Printed out SVG document looks as it should, currently haven't noticed any issues. This is definitely a good sign. 

Here is a java code that works for me.


public void actionPerformed(ActionEvent e) {

PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printerJob.defaultPage();

PrintTranscoder transcoder = new PrintTranscoder();
TranscoderInput ti = new TranscoderInput(svgCanvas.getSVGDocument());
transcoder.transcode(ti, null);

if (printerJob.pageDialog(pageFormat) != pageFormat) {
if (printerJob.printDialog()) {
printerJob.setPrintable(transcoder);
try {
printerJob.print();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
} else {
System.err.println("Print was cancelled");
}
}







Monday, September 22, 2008

Step 2 - SVG printing

Because I have managed to show label's template in SVG format on the screen, next logical step is to have it printed out. And of course I have to get that from java swing application. 
As always there is no easy straightforward way to get it right at the first time. The question is. Is't possible to get something minimal in few minutes time. I did some browsing and googled but was not able to find a straight answer to that question. There was no sample code or explanation, how can I do that with batik. Sad news, more work will be involved. I thought it's common task to have a SVG printed out. Only thing I managed to find on batik site is a "pretty printing", what actually is not what I need. 

I have some thoughts how to do that, but I would rather expect to read somewhere on the batik site, a guide for SVG printing. Any library has it's own unique thoughts about achieving different tasks, it's better to know a preferred way to do that. Should I convert SVG to raster image and print it out, can I use some helper class which will help me.

So I have to find out a easiest way to output SVG file content to the printer. There is my plan for this step:
  1. Will try to go throughout official batik mailing list
  2. Will try to find an forum or IRC channel
  3. If I will not be able to find any solution till that time I still have a source code of squiggle application which comes together with batik.
Will see how will it go.


Step 1 - SVG Viewer

For the first step I jumped straight to most obvious task. No matter what will happen and how will I do, I have to have a way to show an SVG file on the screen. As I said before in requirements post, I did some research and I have decided to try out apache batik as SVG library. Batik has a quick start sample on Batik Swing Components page. As starting point, I took code and added into my fresh NetBeans project. Still have no clue why all these classes are needed, but I need a fast result, so nothing bad to few extra lines in my code. Most important is to have something going.

Nice, just 10 minutes passed on project setup and copy and paste operation and I have an SVG viewer. 

Next step would be to be able to print it out. I think this part will take some time. My experience shows that printing from java is not an easy task. Will see how it goes. 


Gathering Requirements

As always the first and most important step in any product development is to gather all requirements. This of course is a perfect way to do software, but I'm not going to do that. I will try to be more extreme or agile on this project. Maybe too extreme. I will use this project to gather requirements. And will try to produce a working prototype, which actually will be in use. Yes I no, prototype can not be used in production as final product. Blame me kill me or do whatever you want, but I will do that in this way. I count on my experience and it's much better to have an imperfect working application instead of perfect documentation, which does not work. It will be also a research project and I hope, experience gathered from this task will be reused for future project related with SVG.

Basic requirements

Basic workflow, use cases and some requirements and hopes in one place. If everything will go as is intended requirements will be reviewed updated as time will go.

  • Graphic designer has produced label in a Vector Graphic Designer application such as Corel Draw, Adobe Illustrator, Inkscape or any other which does it or is able to export to SVG format.
  • Exported document will be used as template to produce actual labels for printing. Labels will be produces by merging cleaned label template with product's data from database.
  • Label's design exported to SVG is not very useful, it can not be used as template without manual editing. So manual work have to be done in order to make it useful for automatic label generation. Just because SVG file format is an XML data file, it's not too difficult to any Java programmer, who has fall in love or hate with XML file.
  • Cleaned label template have to be merged with real product's data. The actual products data will be retrieved from product's database where every product has all technical specification data. Product database is already written and is in use. So one thing what has left to do is to merge Data with Product Label template and output to the final label which will be shown on the screen for preview and print.
  • In order to merge template and data into one output label which will be printed out and used in the shop I have to chose some technology how to use it. Currently I see a few possibilities: XSLT, FreeMarker or Apache Velocity. Decisions should be made based on little research. I have experience on all of these technologies and that will be a fun to see which one and why will take lead.
  • Because I already have Java swing application, this is a desktop application written on java, I have to add swing user interface for SVG preview and SVG print functionality.
  • For SVG part I evaluating and probably will use Apache Batik project.
  • Also will try to use JUnit v4 TestNG for testing, Apache Ant as a build tool and maybe Hudson as a CI tool.
  • Hmm just forgot to mention SVN for versioning control and Trac???? Not sure about track. It's good bud it's a pain in a but to setup it. Would like to have something similar or event better what runs on Tomcat or even better on Glassfish.
That's all for beginning.

Not bad for beginning. Today is enough I'm going to go to celebrate my birthday, very, very quietly.

Nice job done.

Blogo paskirtis

Hello world.

Šis blogas skirtas naujai kuriamo, SVG produkto etiketės modulis, programos kūrimo procesui dokumentuoti. Čia bus pateikta visa surinkta ir nors šiek tiek naudinga informacija. Taip pat bus pateiktas kūrimo procesas, sprendimai, ir veiksniai įtakojantys produkto kūrimo eigą.

Just for notice this blog is about software development process for one of my clients. Sorry most of informations will be provided in Lithuanian language. Just because this work interrelates with other my soul's projects and has one common technology SVG, this blog may or better to say definitely will have some information related with Java and SVG.

So, lets get started.