Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unicode Subscript issue (Khmer Script)

Status
Not open for further replies.

subin83

Programmer
Aug 7, 2010
5
DE
Hi,

I am having an issue with Khmer Unicode font. The program reads from a UTF-8 file and then writes the string to a JPEG file. In Khmer font there are subscripts for each character. These subscripts are appearing as a separate character in the JPG file. Please see "not_needed.png"( in the attachment. The needed.png( shows the correct display as shown in the text editor. I am able to get the correct format by using Javascript also. But not with Java.
Do someone have any idea as to why Java separates the subscript unicode character? I use Kh-Battambang.ttf as the font for displaying. As far as I know in Indic fonts also subscript is there.

I would be very thankful if someone could give me pointers to where the issue is. Thanks in advance.

Regards,
Subin
 
Maybe it's just me but I don't get the problem. Are you using Java for generating the jpegs from a text file? If so, can you show us some code?

Cheers,
Dian
 
Hi Dian,

Thanks a lot for the mail. Yes I am using Java to generate JPEG's from text file. Please see the abstract of the code below.

Also I tried an online applet ( which basically is an online Khmer keyboard. There it is possible to open an UTF-8 document and also paste the khmer text. I tried it and there also i am getting the same issue. I read that from Java v 1.6 khmer is supported and I run v 1.6.
Also if you see in this conversion site ( for decimal NCR (ថៃ្ងសម្រាក) we get the corresponding text as ?????????? If I copy this text and paste to the online applet described above, I still get the issue where the subscript is removed from the parent.
Does this have to with my font settings in the java lib directory? or is this incompatibility of the font?


############Code############################

public class Khmer {


public Khmer(BufferedImage image, String ttxt, String file_name, float font_size, Color font_color, String ext) throws Exception {
drawText(image, ttxt, font_size, font_color);
save(image, file_name, ext);
}

private void drawText(BufferedImage image, String text2, float size, Color font_color) throws Exception {

Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
File f = new File("Kh-System.ttf");
FileInputStream in = new FileInputStream(f);
Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
Font dynamicFont32Pt = dynamicFont.deriveFont(size);

Font font = dynamicFont32Pt;
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
float width = (float) font.getStringBounds(text2, frc).getWidth();
LineMetrics lm = font.getLineMetrics(text2, frc);
float height = lm.getAscent() + lm.getDescent();
float x = (image.getWidth() - width) / 2f;
float y = (image.getHeight() + height) / 2f - lm.getDescent();
g2.setPaint(font_color);
g2.drawString(text2, x, y);
g2.dispose();
}

private void save(BufferedImage image, String file_name, String ext) throws Exception {

File file = new File(file_name + "." + ext);

try {
ImageIO.write(image, ext, file);
System.out.println(print_out);
} catch (IOException e) {
System.out.println("write error: " + e.getMessage());
}
}

public static void main(String[] args) throws Exception {


File file = new File(file_name_arg);

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file_name_arg), "UTF8"));


while ((strLine = br.readLine()) != null) {
toSend = "";
temp_file_data = strLine.split(cc_delimiter);
file_name = temp_file_data[0];

m = MY_PATTERN.matcher(file_name);
while (m.find()) {
file_name = m.group(1);
}
for (int li = 1; li < temp_file_data.length; li++) {
if(li > 1 )
toSend = toSend+cc_delimit_const+temp_file_data[li];
else
toSend = toSend+temp_file_data[li];
}
File file3 = new File("blank.jpg");
BufferedImage image = ImageIO.read(file3);
hei_wid = widthandheight(image, toSend, fnt_sze);

graphics2D = image2.createGraphics();
graphics2D.setColor(Color.WHITE);
graphics2D.fillRect(0, 0, x1, y1);
new Khmer(image2, toSend, file_name, fnt_sze, pass_fnt_color, cc_imgtype);

}



Thanks,
Subin
 
Please use [ code] codetags [ /code].
(without the blanks.
Code:
public class Khmer {
        public Khmer (BufferedImage image, String ttxt,
             String file_name, float font_size, Color font_color, String ext)
                     throws Exception {
                drawText (image, ttxt, font_size, font_color);
                save (image, file_name, ext);
    }

don't visit my homepage:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top