Hi All,
I am facing an issue which I couldnt solve after much repeated search. Hope you all can help me.
I have a txt file(ASCII) containing the decimal representation of an Unicode exកម្មវិធី
I have a function which will convert this decimal value to hexadecimal unicode ie in this case (\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8)
The logic is that I take each line from the file, convert it into unicode hex representation and then write to a JPG file.
The issue here is with the hexValue variable. Its getting the correct value but when I use it in the function call i.e. ConvertUnicode(image, hexValue); its not working. If I equate the variable with the corresponding value(ie \u1780..) its working fine. I checked for extra carriage returns, spaces etc but still issue is there.
I tried printing decoded = "-"+decoded+"-"; in the function and got -\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8- and showing no extra characters.
Am I doing some mistake in the file encoding part? I tried with UTF encoding and read appropriately but still same issue is there. I would be very thankful for any pointers regarding this.
String strLine = "";
String hexValue;
try {
FileInputStream fstream = new FileInputStream(args[0]);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in);
while ((strLine = br.readLine()) != null) {
hexValue = ConvertDectoHex(strLine); // though hexValue gives \u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8 as output, it not able to display the font on the image
//hexValue = "\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8"; if I set it like this I am able to get everything fine
File file = new File("blank.jpg");
BufferedImage image = ImageIO.read(file);
System.out.println(hexValue);
new ConvertUnicode(image, hexValue);
}
in.close();
--------------------------
public static String ConvertDectoHex(String dec) {
String temp;
String[] ret_coma;
temp = dec.replaceAll("&#", "");
ret_coma = semicommaSeparatedStringToStringArray(temp);
for (i=0; i< ret_coma.length ; i++) {
ret_coma = ret_coma.trim();
if (ret_coma.length() > 0 && ret_coma != null) {
hexstr = Integer.toHexString(Integer.parseInt(ret_coma));
decoded = decoded + "\\u" + hexstr;
}
}
return decoded;
}
private static String[] semicommaSeparatedStringToStringArray(String aString){
String[] splittArray = null;
if (aString != null || !aString.equalsIgnoreCase("")){
splittArray = aString.split(";");
//System.out.println(aString + " " + splittArray);
}
return splittArray;
}
public ConvertUnicode(BufferedImage image, String ttxt) throws Exception {
drawText(image, ttxt);
File file = save(image);
show(file);
}
Regards,
Subin
I am facing an issue which I couldnt solve after much repeated search. Hope you all can help me.
I have a txt file(ASCII) containing the decimal representation of an Unicode exកម្មវិធី
I have a function which will convert this decimal value to hexadecimal unicode ie in this case (\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8)
The logic is that I take each line from the file, convert it into unicode hex representation and then write to a JPG file.
The issue here is with the hexValue variable. Its getting the correct value but when I use it in the function call i.e. ConvertUnicode(image, hexValue); its not working. If I equate the variable with the corresponding value(ie \u1780..) its working fine. I checked for extra carriage returns, spaces etc but still issue is there.
I tried printing decoded = "-"+decoded+"-"; in the function and got -\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8- and showing no extra characters.
Am I doing some mistake in the file encoding part? I tried with UTF encoding and read appropriately but still same issue is there. I would be very thankful for any pointers regarding this.
String strLine = "";
String hexValue;
try {
FileInputStream fstream = new FileInputStream(args[0]);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in);
while ((strLine = br.readLine()) != null) {
hexValue = ConvertDectoHex(strLine); // though hexValue gives \u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8 as output, it not able to display the font on the image
//hexValue = "\u1780\u1798\u17d2\u1798\u179c\u17b7\u1792\u17b8"; if I set it like this I am able to get everything fine
File file = new File("blank.jpg");
BufferedImage image = ImageIO.read(file);
System.out.println(hexValue);
new ConvertUnicode(image, hexValue);
}
in.close();
--------------------------
public static String ConvertDectoHex(String dec) {
String temp;
String[] ret_coma;
temp = dec.replaceAll("&#", "");
ret_coma = semicommaSeparatedStringToStringArray(temp);
for (i=0; i< ret_coma.length ; i++) {
ret_coma = ret_coma.trim();
if (ret_coma.length() > 0 && ret_coma != null) {
hexstr = Integer.toHexString(Integer.parseInt(ret_coma));
decoded = decoded + "\\u" + hexstr;
}
}
return decoded;
}
private static String[] semicommaSeparatedStringToStringArray(String aString){
String[] splittArray = null;
if (aString != null || !aString.equalsIgnoreCase("")){
splittArray = aString.split(";");
//System.out.println(aString + " " + splittArray);
}
return splittArray;
}
public ConvertUnicode(BufferedImage image, String ttxt) throws Exception {
drawText(image, ttxt);
File file = save(image);
show(file);
}
Regards,
Subin