nini9140 / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

jZebra.setEncoding and append64 #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Print incorrect characters:
   document.jZebra.setEncoding("cp866");
   document.jZebra.append64("0J/RgNC40LLQtdGC");

2. Produce correct printer output:
   document.jZebra.setEncoding("cp866"); 
   document.jZebra.append('Привет');
3.
seems that append64 didn't rely on charset setting by setencoding.

jZebra 1.1.5 sources inspected:
Public void append64(string BASE64) {        try { 
            pr.append(Base64.decode(base64)); 
        } CATCH (ioexception e) {            set(e); 
        } } 

PUBLIC void append(string s) {        try { 
            pr.append(s.getBytes(charset.name()));
        } CATCH (unsupportedencodingexception ex) "
{            LogIt.log(Level.WARNING, "Could not append using specified charset 
encoding: " 
                    + charset + ". Using default.", e); 
            pr.append(s); "
        } } ";

Original issue reported on code.google.com by sunflic...@gmail.com on 28 May 2011 at 6:29

GoogleCodeExporter commented 9 years ago
May be solution like this will be acceptable:

Public void append64(string BASE64) {        
 try {
        String Decodedstring = new String(Base64.decode(base64));
            pr.append(Decodedstring.getBytes(charset.name())); 

     } CATCH (ioexception e) 
     {           
       set(e); 
     }  
} 

Original comment by sunflic...@gmail.com on 28 May 2011 at 6:44

GoogleCodeExporter commented 9 years ago
Thanks for looking into this.

I have had no luck doing charset encoding from within Java.   The parameter 
I've supplied through the API does not seem to do anything.  My only success, 
though limited was to set via command line/env variable. Can you try this 
command line option?

       $ export JAVA_TOOL_OPTIONS=-Dfile.encoding=Cp866;google-chrome
       // OR
       $ export JAVA_TOOLS_OPTIONS=-Dfile.encoding=Cp866;firefox
       // You should then see
       $ Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=Cp866

Also, Cp866 is case sensitive. Taken from: 
http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html

Original comment by tres.fin...@gmail.com on 28 May 2011 at 12:50

GoogleCodeExporter commented 9 years ago
I think I have found the root of the problem for encoding mismatch and 
incorrect character printed on different OS.
PrintApplet.java, you should add this code between line 668 & 669 :
pr.setCharset(this.charset);

so line 668-670 will be like this (I'd modified line 670 a bit to show the bug 
that happened when line 669 is commented out) :
668:          this.charset = Charset.forName(charset);
669:            pr.setCharset(this.charset);
670:            LogIt.log("Current charset encoding: " + this.charset.name() + 
"\nCurrent printer charset encoding: " + pr.getCharset().name());

This is because in jZebra there are 2 main object : PrintApplet (interface to 
web browser & user ) and PrintRaw (interface to the printer).
when user change the encoding through PrintApplet, the object that changed the 
encoding is just the PrintApplet. Although, when the PrintApllet initially 
start, it had synchronized the encoding with the PrintRaw (PrintApplet.java 
line 117).

This patch will change the encoding for the PrintRaw too. 

For incorrect character (and images) that printed accross different OS, you can 
set the encoding before print, ie. document.jZebra.setEncoding('windows-1252');
Usually, the extended ASCII code ( > 127) that printed normally on windows will 
misprinted on linux. You can use the line above (use windows-1252 to print 
extened ASCII) to correct it before print anything (even images).

Or you can easily download the attached file to replace the jzebra.jar on your 
system.

Original comment by erik.luk...@gmail.com on 18 Aug 2011 at 9:13

Attachments:

GoogleCodeExporter commented 9 years ago
Great find.  Committing the fix now.

Original comment by tres.fin...@gmail.com on 20 Aug 2011 at 1:33

GoogleCodeExporter commented 9 years ago
Bug 24 is duplicate.

Fixed in version 1.1.8 using setEncoding().  Confirmed by Eko.  Please contact 
mailing list for usage instructions until the wiki has been updated to reflect 
changes.

http://code.google.com/p/jzebra/downloads/list

Original comment by tres.fin...@gmail.com on 17 Sep 2011 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by tres.fin...@gmail.com on 17 Sep 2011 at 5:24

GoogleCodeExporter commented 9 years ago
Wiki has been updated.

http://code.google.com/p/jzebra/wiki/TutorialWebApplet?ts=1325082551&updated=Tut
orialWebApplet#Printing_Special_Characters

Original comment by tres.fin...@gmail.com on 28 Dec 2011 at 2:34