Home
Analytics
Properly Displaying a Barcode when Rotated 90 degrees
lenburt
<p>Hello there - this is probably more of a font question than a BIRT question but i thought some of you out there may have had a similar requirement. </p>
<p> </p>
<p>We have letters generated through BIRT that need to go to a centralized print room which expects the second side of each sheet of a letter to have a 2 of 5 Interleaved barcode on the left margin of the page. At first i was stumped on how to rotate the font 90 degrees but some of you pinted me to a plugin text object that provides that functionality.</p>
<p> </p>
<p>Now, when i place the barcode rotated in the Developer, it looks fine until i actually preview it and then it looks faded (attached). I am using a TrueType font but i am guessing i need a font which knows how to draw itself when rotated but i am new to the world of barcodes.</p>
<p> </p>
<p>Any help would be appreciated! -- len</p>
Find more posts tagged with
Comments
Matthew L.
<p>What barcode font are you using (Name/Code format/etc)?</p>
<p>Or where did the barcode font come from (website/company name/etc)?</p>
<p> </p>
<p>Note: There are several types of barcode font (Code 39, Code 128, etc).</p>
<p>Some fonts (Code 128) also require encoding the text so the encoded 'bars' are readable by a scanner.</p>
lenburt
<p>Matthew - the rptdesign i am using is attached...it is a TrueType (Code 2 of 5 Interleaved )font provided by someone in the print operations group. -- len</p>
Matthew L.
<p>Looking over this issue more closely, I believe this is caused by a possible Unicode error interpreted between the rotation text plugin and the barcode font.</p>
<p> </p>
<p>Using the following Code 2 of 5 interleaved font: <a data-ipb='nomediaparse' href='
http://grandzebu.net/informatique/codbar-en/code25I.htm'>http://grandzebu.net/informatique/codbar-en/code25I.htm</a></p>
;
<p>and using the rotation text plugin without rotating the text, still shows the empty boxes ௅ (Unicode error?).</p>
<p>This issue seems to happen with some other but not all barcode fonts I have installed when using this rotation plugin.</p>
<p> </p>
<p>Other barcode fonts I've tried such as the I2OF5TXT font seem to work without issue as long as the angle isn't 90 or 270.</p>
<p>If using those angles it causes a bug in the plugin which is documented on the site: <a data-ipb='nomediaparse' href='
https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/issues/detail?id=10'>https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/issues/detail?id=10</a></p>
;
<p> </p>
<p>Since it seems that the rotation text project has stalled (Last update in 2010), finding a font that is compatible without running into the bug listed above might be challenging.</p>
lenburt
<p>Matthew - thanks for the research. I tried various angles 88, 92, 45 and none of them seem to work so we will need either look for another font or see if we can print it horizontally anywhere. -- len</p>
lenburt
<p>Matthew (or others) -- we have not found a solution to trying to rotate and render this barcode font 90 degrees and it may be a show stopper for us -- we would not be able to use BIRT to create the letters we need. The print operation has machinery which reads this barcode to know how many sheets of paper to get stuff into an envelope.</p>
<p> </p>
<p>I was wondering if i could place and render the barcode as a normal (i.e. horizontal) text field and then write some code to rotate it 90 degrees myself. Outside of BIRT i have been able to capture the barcode image and rotate it 90 degrees and save it as a JPEG and place it that way but the barcode data payload is dynamic so that will not work. Any suggestions are welcome....i have invoked Java classess from BIRT before but nothing having to do with rotating a text field. -- len</p>
Matthew L.
<p>From my previous post, I believe that there is something wrong with the fonts used.</p>
<p>Testing with the following font from: <a data-ipb='nomediaparse' href='
http://grandzebu.net/informatique/codbar-en/code25I.htm'>http://grandzebu.net/informatique/codbar-en/code25I.htm</a></p>
;
<p>This works with BIRT using standard elements (Text/Label/etc).</p>
<p>Looking through the source of the Rotate plugin for BIRT: <a data-ipb='nomediaparse' href='
https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/'>https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/</a></p>
;
<p>I see that it creates an image based on the text string, rotates it, and inserts the image into the report.</p>
<p>Attempting to replicate this in the report using JavaScript, I noticed that the Java BufferedImage Graphics2D seems unable to align the text to the cmap? of the "Code 2 of 5 interleaved" font. This produces the boxes that appear in the Rotate plugin.</p>
<p> </p>
<p>Other 'Code 2 of 5 I' fonts produce similar issues. While not a font expert, I believe that this could be due to the way that unicode to glyphs are defined in the font package.</p>
<p> </p>
<p>Attached is my test example of this that I've been working on.</p>
<p>Also code for image onCreate method is here for reference:</p>
<pre class="_prettyXprint _lang-js">
//Font used: http://grandzebu.net/informatique/codbar-en/code25I.htm
//code: http://stackoverflow.com/questions/18800717/convert-text-content-to-image
//code: http://stackoverflow.com/a/8722380
importPackage(Packages.java.awt);
importPackage(Packages.java.awt.geom);
importPackage(Packages.java.awt.image);
importPackage(Packages.java.io);
importPackage(Packages.javax.imageio);
var str = "É-CYÊ"; //Encoded string = 123456
var text = new String(str);
var img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
var g2d = img.createGraphics();
var font = new Font("Code 2 of 5 interleaved", Font.PLAIN, 48);
g2d.setFont(font);
var fm = g2d.getFontMetrics();
var width = fm.stringWidth(text);
var height = fm.getHeight();
g2d.dispose();
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2d.setFont(font);
fm = g2d.getFontMetrics();
g2d.setColor(Color.BLACK);
g2d.drawString(text, 0, fm.getAscent());
g2d.dispose();
var angle = '90';
angle = java.lang.Math.toRadians(angle);
var sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
var w = img.getWidth(), h = img.getHeight();
var neww = Math.floor(w*cos+h*sin), newh = Math.floor(h*cos+w*sin);
var tx = new AffineTransform();
tx.translate((neww-w)/2, (newh-h)/2);
tx.rotate(angle, w/2, h/2);
var op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
img = op.filter(img, null);
var out = new ByteArrayOutputStream();
ImageIO.write(img, "png", out);
var bytes = out.toByteArray();
this.data = bytes;
bais = new ByteArrayInputStream( bytes);
bufimg = ImageIO.read(bais);
this.setHeight(bufimg.getHeight() +"px");
this.setWidth(bufimg.getWidth() +"px");
</pre>
lenburt
<p>Matthew - just so i understand you correctly. It seems that since the barcode renders fine in horizontal mode, couldn't a temporary image fille be created on the fly from this text item and then that rotated 90 degrees using Java?....is that what you are trying to accomplish? I have been trying to develop a Report Label Item extension based on chapter 18 of Extending BIRT but that is based on an older version of Eclipse and this is my first attempt at creating a plugin. I appreciate your efforts. -- len</p>
Matthew L.
<p>Len - The barcode renders fine with standard BIRT text elements, similar to how the barcode font works in other software such as a spreadsheet or word processor.</p>
<p>However like you mentioned, I am trying to use the Graphics2D Java engine to create the image on the fly.</p>
<p>The issue with this is that I cannot get the Graphics2D engine to correctly select the character in the font package (See top right section of my previous screenshot).</p>
<p>This issue also occurs when using Chinese fonts, however converting the byte string to UTF-8 resolves this.</p>
<p>Unfortunately the same trick doesn't work with this barcode font.</p>
<p> </p>
<p>There are however many other barcode fonts that work using the Graphics2D engine as well as the BIRT Rotate plugin.</p>
<p>Because other barcode fonts work (Cp1252? encoding) and Chinese fonts work when converting to the correct byte string (UTF-8 encoding), I believe that this due to some way this font was created or how the glyphs are defined in the font package.</p>
<p> </p>
<p>While not exactly ideal, I am currently using a font editor to see how the font is encoded and how the glyphs are defined to determine if there is a way to make this all work.</p>
<p>I'll keep you updated on my findings. </p>
lenburt
<p>Matthew - thanks for the update -- i really appreciate the effort. -- len</p>
Matthew L.
<p>I managed to get this working with the font from: <a data-ipb='nomediaparse' href='
http://grandzebu.net/informatique/codbar-en/code25I.htm'>http://grandzebu.net/informatique/codbar-en/code25I.htm</a></p>
;
<p>And while using the BIRT Rotate Text element from: <a data-ipb='nomediaparse' href='
https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/'>https://code.google.com/a/eclipselabs.org/p/birt-controls-lib/</a></p>
;
<p> </p>
<p> </p>
<p>Please note that I am not a font expert, so my understanding of why this works is unclear (perhaps an expert of Font knowledge could chime in someday?)</p>
<p>However I opened the code25I.ttf font file with a font editor (<a data-ipb='nomediaparse' href='
http://fontforge.github.io/en-US/'>FontForge</a>)
, changed the name and uniqueID, saved and generated the new font, installed the new font on my OS, and used this new font in my report design with and without the BIRT Rotate Text plugin and the font appeared correctly.</p>
<p> </p>
<p>Attached are my image documented steps taken to fix? the font which allows it to work with both the Java code previously posted as well as the BIRT Rotate Text plugin.</p>
<p> </p>
<p>Hopefully these same steps work as a workaround for you in order to correct the behavior and allow you to continue with your project.</p>
<p> </p>
<p> </p>
lenburt
<p>Matthew - very creative!...i will try it out...i can live with a work around....i will re-post once i can verify that it works for me. -- len</p>