user interface - Java - How to correctly display ANSI art in a JTextPane -


i having trouble displaying ansi art in jtextpane.

i thought chosing fixed-width or monospace font , removing line-spacing of jtextpane's styleddocument via simpleattributeset enough correctly display some different pieces of ansi art, after trying different fonts , settings realized has more that.

i've been using damn nfo viewer compare jtextpane in order see if code displaying the piece of digital art correctly.

i set jtextpane font same font damn nfo viewer using (according settings courier new, 8, default) via arttextpane.setfont(new java.awt.font("courier new", 0, 8)). however, if apply line-spacing settings via styleddocument.setparagraphattributes(int, int, attributeset, boolean) jtextpane not display art correctly. here 2 screenshots show differences:

damn nfo viewer (courier new, 8):

damn nfo viewer courier new 8

my jtextpane (courier new 8):

jtextpane courier new 8

what strange when setting jtextpane's font-size 9 alignment seems correct bit unsharp. zooming onto characters form g in art piece shows blueish pixels right make unsharp:

my jtextpane (courier new 9):

jtextpane courier new 9

also noticed opening art.txt in notepad displays damn nfo viewer does. jtextpane seems displaying smaller, like, 'casket' in character drawn appears smaller.

first thought damn nfo viewer using different version of font courier new, dug through directories , found following registry file:

[hkey_current_user\software\damn\damn nfo viewer\nfo] "fontname"="[built-in] courier new" "fontdata"=hex:91,00,03,01 "window"=dword:00000023 "backgroundcolor"=hex:ff,ff,ff,00 "textcolor"=hex:00,00,00,00 "hyperlinkcolor"=hex:bf,cd,db,00 "hyperlinkhovercolor"=hex:99,b4,d1,00 "text"=dword:00000400 

which makes me think may use derived version of courier new settings "fontdata"=hex:91,00,03,01. have no idea how reproduce derivation in java.

could tell me doing wrong trying display text file in jtextpane same way damn nfo viewer it?

edit: added test/example code working with, trying font displayed "correctly" (in way not deface ansi art). created test gui using netbeans ide's built-in gui builder "mantisse", may not perfect example should show difference screenshots of damn nfo viewer.

package jtextpanetest;  public class jtextpanetestui extends javax.swing.jframe {  /**  * creates new form jtextpanetestui  */ public jtextpanetestui() {     initcomponents(); }  /**  * method called within constructor initialize form.  * warning: not modify code. content of method  * regenerated form editor.  */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code">                           private void initcomponents() {      scrollpane = new javax.swing.jscrollpane();     panel = new javax.swing.jpanel();     textpanessrollpane = new javax.swing.jscrollpane();     textpane = new javax.swing.jtextpane();      setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close);      panel.setlayout(new java.awt.borderlayout());      textpane.setfont(new java.awt.font("courier new", 0, 8)); // noi18n     textpane.settext("▀▀▀▀▀▀▀▀▀▄▄▄▄\n███████▄▄▄▄ ▀▀▀▄▄\n▄ ▀█▓█████████▄▄ ▀▀█▄\n █  ▓█▓▄ ▀▀█▓███▓▄  ██\n  █ ▒▓▒▓    ▒█▓█▒▓  █▓█\n  █ ░▒░▒█ █ ░▓▒▓░▒█ █▒▓█\n  █ ░░░░▓ █ ░▒░▒░░▓ ▓░▒█\n  █ ▒░▒░▒ █ ▒░░░▒░▒ ▒░░█\n  █ ▓▒▓▒░ █ ▓░▒░▓▒░ ░▒░█\n  █ █▓█▓▀ █ █▒▓▒█▓░ ░▓▒█\n  █ ██▀ ▄▀█ █▓█▓██  ▒██\n  █ █ ▄▀▄█  █████▀  ▓█\n  ░ █ ░ █ ▄██▀▀ ▄▄█ █░\n  ▒▄▄▄▒ ░▄▄▄▄▄▀▀  █ █\n          █ ██▀ ▄▀                   \n          █ █▌▄▀  \n          ░ █ █                  \n          ▒▄▄▄░ \n\n █████████\n███████████\n███████████\n███████████\n█████ █████\n█████ █████\n█████ █████\n█████ █████\n█████ █████\n███████████\n███████████\n ██████████\n     ██████\n███████████\n██████████      ");     textpanessrollpane.setviewportview(textpane);      panel.add(textpanessrollpane, java.awt.borderlayout.center);      scrollpane.setviewportview(panel);      javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane());     getcontentpane().setlayout(layout);     layout.sethorizontalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addcomponent(scrollpane, javax.swing.grouplayout.default_size, 400, short.max_value)     );     layout.setverticalgroup(         layout.createparallelgroup(javax.swing.grouplayout.alignment.leading)         .addcomponent(scrollpane, javax.swing.grouplayout.default_size, 300, short.max_value)     );      pack(); }// </editor-fold>                          /**  * @param args command line arguments  */ public static void main(string args[]) {     /* set nimbus , feel */     //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) ">     /* if nimbus (introduced in java se 6) not available, stay default , feel.      * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html       */     try {         (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) {             if ("nimbus".equals(info.getname())) {                 javax.swing.uimanager.setlookandfeel(info.getclassname());                 break;             }         }     } catch (classnotfoundexception | instantiationexception | illegalaccessexception | javax.swing.unsupportedlookandfeelexception ex) {         java.util.logging.logger.getlogger(jtextpanetestui.class.getname()).log(java.util.logging.level.severe, null, ex);     }     //</editor-fold>      /* create , display form */     java.awt.eventqueue.invokelater(new runnable() {         @override         public void run() {             new jtextpanetestui().setvisible(true);         }     }); }   private javax.swing.jpanel panel; private javax.swing.jscrollpane scrollpane; private javax.swing.jtextpane textpane; private javax.swing.jscrollpane textpanessrollpane;  } 

edit2: suggested me render art image, need editable, not option guess. hints appreciated!

the main issue here text in jtextpane rendered space between lines. same issue arise other widgets. actual spacing depends on font (and therefore jvm). blue blur can observe courier 9 caused anti-aliasing.

your code renders java 1.7.0_55-b13 on macos x: original rendering

with jtextpane, can reduce line spacing follows (before calling jtextpane.settext):

javax.swing.text.mutableattributeset set = new javax.swing.text.simpleattributeset(textpane.getparagraphattributes()); javax.swing.text.styleconstants.setlinespacing(set, (float)-0.1); textpane.setparagraphattributes(set, false); 

the -0.1 value fixes line spaces, might need value font or font size.

removed space between lines

you may need reduce tracking (the space between letters) well:

java.awt.font font = new java.awt.font("courier new", 0, 8); java.util.map<java.awt.font.textattribute, object> attributes = new java.util.hashmap<java.awt.font.textattribute, object>(); attributes.put(java.awt.font.textattribute.tracking, -0.1); java.awt.font font2 = font.derivefont(attributes); textpane.setfont(font2); 

rendering tracking


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -