
On Mon, Feb 08, 2010 at 12:47:50AM +0100, Ronny Klier wrote:
I think there is a bug in label encoding in Format6Encoder. For some string length the last encoded byte is not stored.
E.g. having a string "10007" the encoded byte buffer looks like this
[0] [0x86] [1] [0x8] [2] [0x20] [3] [0x9f] [4] [0xf0]
The number of stored bytes is 4. So the 0xf0 will not show up in the final image file.
Index: Format6Encoder.java =================================================================== --- Format6Encoder.java (Revision 1541) +++ Format6Encoder.java (Arbeitskopie) @@ -86,7 +86,7 @@
buf = put6(buf, off++, 0xff);
- int len = ((off - 1) * 6) / 8 + 1; + int len = (int)Math.ceil((off * 6) / 8.0);
You can do this with integer math, truncating division. Your example was off=6 (5 chars and the end-of-string code), and I suppose we would get len=4 instead of 5: (6-1)*6 / 8 + 1 = 30/8 + 1 = 3.75 + 1 = 4 If you want to round up to full blocks, the normal trick is to add divisor-1 before dividing, like this: int len = ((off - 1) * 6 + 7) / 8 + 1 = 4.625 + 1 = 5 I don't know if the off-1 and the +1 are correct. An integer version of your formula would also work in this case: int len = (off * 6 + 7) / 8 = 43/8 = 5.375 = 5 This formula is clear to me: it will clearly convert the "off" 6-byte chars (including the end-of-string code) to the number of required 8-bit octets. Best regards, Marko