Issue1261231
Created on 2005-08-16.18:55:01 by ptaney, last changed 2007-12-02.21:05:25 by cgroves.
| Messages | |||
|---|---|---|---|
| msg1020 (view) | Author: paul taney (ptaney) | Date: 2005-08-16.18:55:01 | |
Frank Wierzbicki wrote:
>> ...but this jython only posts the hex string:
>>
>> box.add(swing.JButton("\u0F00"))
>> or
>> box.add(swing.JButton(unicode("\u0F00")))
>>
>> Similar problem with the textpane.
>>
>> How do I inform widgets about the font, or what's up?
>> I am on a Mac running 10.4.2 and jython2.2a1
>Does this work if you do it in regular Java? Does in work in Jython
>2.1?
>There is very new support for more CPython-like unicode behavior
for
>strings like u"xxx". There could be some problems with it. If this
>works in either or both Java and Jython 2.1 please submit a bug
>report.
I have tried various workarounds to no avail, so here are test
programs in java and jython. The java works fine; the jython posts
garbage.
import java.awt.*;
import java.awt.font.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.io.*;
public class TibFontTest extends Canvas {
// pick up the font at
// http://cvs.sourceforge.net/viewcvs.py/thdltools/Fonts/
TibetanMachineUni and put it in the local dir
// see what they look like: http://www.unicode.org/charts/PDF/
U0F00.pdf
JFrame f;
File fh1;
FileInputStream fis;
Font myfont;
public TibFontTest(String title) {
f = new JFrame(title);
setSize(500, 400);
try {
fh1 = new File("TibetanMachineUniAlphaVolt.ttf");
fis = new FileInputStream(fh1);
myfont = Font.createFont(Font.TRUETYPE_FONT, fis);
myfont = myfont.deriveFont(Font.PLAIN, 20);
}
catch (Exception e) {
System.out.println("Font problem. Exiting.");
System.exit(0);
}
f.getContentPane().setLayout(new GridLayout(6, 3));
f.getContentPane().add(new JButton("\u0F00"));
f.getContentPane().add(new JButton("\u0F01"));
f.getContentPane().add(new JButton("\u0F02"));
f.getContentPane().add(new JButton("\u0F03"));
f.getContentPane().add(new JButton("\u0F04"));
f.getContentPane().add(new JButton("\u0F05"));
f.getContentPane().add(new JButton("\u0F06"));
f.getContentPane().add(new JButton("\u0F07"));
f.getContentPane().add(new JButton("\u0F40"));
f.getContentPane().add(new JButton("\u0F41"));
f.getContentPane().add(new JButton("\u0F42"));
f.getContentPane().add(new JButton("\u0F43"));
f.getContentPane().add(new JButton("\u0F44"));
f.getContentPane().add(new JButton("\u0F45"));
f.getContentPane().add(new JButton("\u0F46"));
f.getContentPane().add(new JButton("\u0F47"));
f.getContentPane().add(new JButton("\u0F49"));
f.getContentPane().add(new JButton("\u0F4A"));
f.pack();
f.setVisible(true);
}
public static void main(String args[]) {
TibFontTest f1 = new TibFontTest("Font Test Window");
}
}
====
from pawt import swing
from java import awt
from java import io
class TibFontTest3(awt.Canvas):
'''pick up the font at
http://cvs.sourceforge.net/viewcvs.py/thdltools/Fonts/
TibetanMachineUni/ and put it in the local dir
see what they look like: http://www.unicode.org/charts/PDF/
U0F00.pdf''' or look at the java buttons
def __init__(self, title,
fontfilename="TibetanMachineUniAlphaVolt.ttf"):
f = swing.JFrame(title)
self.setSize(500, 400)
self.pointsize = 15
fh1 = io.File(fontfilename)
fis = io.FileInputStream(fh1)
self.myfont = awt.Font.createFont
(awt.Font.TRUETYPE_FONT, fis)
self.myfont = self.myfont.deriveFont(awt.Font.PLAIN,
self.pointsize)
f.contentPane.setLayout(awt.GridLayout(6, 3))
f.contentPane.add(swing.JButton('\u0F00'.encode('utf-16')))
f.contentPane.add(swing.JButton('\u0F01'.encode('utf-16')))
f.contentPane.add(swing.JButton('\u0F02'.encode('utf-16')))
f.contentPane.add(swing.JButton('\u0F03'.encode('utf-16')))
f.contentPane.add(swing.JButton('\u0F04'.encode('utf-16')))
f.contentPane.add(swing.JButton('\u0F05'.encode('utf-16')))
# now with u'\u
f.contentPane.add(swing.JButton(u'\u0F06'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'\u0F07'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'\u0F40'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'\u0F41'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'\u0F42'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'\u0F43'.encode('utf-16')))
# now with u'
f.contentPane.add(swing.JButton(u'0F44'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'0F45'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'0F46'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'0F47'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'0F49'.encode('utf-16')))
f.contentPane.add(swing.JButton(u'0F4A'.encode('utf-16')))
f.pack()
f.setVisible(True)
if __name__ == "__main__":
f3 = TibFontTest3("Font Test Window")
|
|||
| msg1021 (view) | Author: Santiago Gala (sgala) | Date: 2005-08-30.00:00:19 | |
Logged In: YES
user_id=178886
When I tested them (I couldn't see the font either with java
or jython, but fontforge showed it), I found that jython
works with:
u'\u0F06' (no encode('utf-16')
At least, is shows just one (empty square) glyph. In fact,
this string is already encoded, and encoding it again won't
help.
and, using python2.2 or jython2.2a1:
>>> print "".join([unichr(i) for i in
xrange(3840,3847)])+"".join([unichr(i) for i in
xrange(3880,3890)])
()*+,-./01
is working from command line, as I paste it here. This after
I installed this font in /usr/fonts/local.
Not sure why java/jython don't show the font, though.
|
|||
| msg1022 (view) | Author: Charlie Groves (cgroves) | Date: 2007-12-02.21:05:25 | |
This code works for me:
from javax.swing import JButton, JFrame
from java.awt import Font
f = JFrame('Font Test')
font = Font.createFont(Font.TRUETYPE_FONT, open("TibetanMachineUniAlphaVolt.ttf"))
f.contentPane.add(JButton(u'\u0F06'))
f.pack()
f.visible = True
So I'm calling this fixed.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2005-08-16 18:55:01 | ptaney | create | |
Supported by Python Software Foundation,
Powered by Roundup