gpt4 book ai didi

android - 我想在我的 Android 应用程序中显示区域语言 (Gurmukhi)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:44:33 25 4
gpt4 key购买 nike

我想要如下图所示的输出

This is in Gurumukhi Font

这是一本使用区域字体 (Gurumukhi) 的锡克教圣书,我想制作此文本的 xml 文件以使用 xml 解析在我的应用程序中显示。但问题是当我将这种字体粘贴到我的 xml 文件中时,它会转换成如下所示的一些字母和符号

jpujI swihb
<> siq nwmu krqw purKu inrBau inrvYru
Akwl mUriq AjUnI sYBM gur pRswid ]
] jpu ]
Awid scu jugwid scu ]
hY BI scu nwnk hosI BI scu ]1]
socY soic n hoveI jy socI lK vwr ]
cupY cup n hoveI jy lwie rhw ilv qwr ]
BuiKAw BuK n auqrI jy bMnw purIAw Bwr ]
shs isAwxpw lK hoih q iek n clY nwil ]
ikv sicAwrw hoeIAY ikv kUVY qutY pwil ]
hukim rjweI clxw nwnk iliKAw nwil ]1]
hukmI hovin Awkwr hukmu n kihAw jweI ]
hukmI hovin

我在 Assets 文件夹中放置了一个 Gurumukhi 字体文件,并使用下面的代码,效果很好

Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/bulara_5.ttf");
textView = (TextView) findViewById(R.id.textView1);
textView.setTypeface(tf);
textView.setMovementMethod(new ScrollingMovementMethod());
textView.setText(" <>siq nwmu krqw purKu inrBau inrvYru")

通过这种方式,该 TextView 中的文本将转换为 Gurumukhi,但我如何为其中的此类文本创建我的 Xml 文件。或者 给我一些好的建议,告诉我哪种方法更适合处理此类应用程序和处理文本。我必须在一个应用程序中显示 4-5 本圣书,每本有 20-25 页。任何帮助表示赞赏。

最佳答案

我已经对 xml 进行了一些更改,请记住,更改是必需的。

我在 Assets 文件夹中制作了一个 data.xml xml 如下所示

    <?xml version="1.0" encoding="UTF-8"?>
<book1>
<page1>&#60;&#62; siq nwmu krqw purKu inrBau inrvYru
Akwl mUriq AjUnI sYBM gur pRswid ]
] jpu ]
Awid scu jugwid scu ]
hY BI scu nwnk hosI BI scu ]1]
socY soic n hoveI jy socI lK vwr ]
cupY cup n hoveI jy lwie rhw ilv qwr ]
BuiKAw BuK n auqrI jy bMnw purIAw Bwr ]
shs isAwxpw lK hoih q iek n clY nwil ]
ikv sicAwrw hoeIAY ikv kUVY qutY pwil ]
hukim rjweI clxw nwnk iliKAw nwil ]1]
hukmI hovin Awkwr hukmu n kihAw jweI ]
hukmI hovin jIA hukim imlY vifAweI ]
hukmI auqmu nIcu hukim iliK duK suK pweIAih ]
ieknw hukmI bKsIs ieik hukmI sdw BvweIAih ]
hukmY AMdir sBu ko bwhir hukm n koie ]
nwnk hukmY jy buJY q haumY khY n koie ]2]
gwvY ko qwxu hovY iksY qwxu ]</page1>
</book1>

之后看到我的 StudyParser.class 如下所示

  import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;



public class StudyParser {
public StudyParser() {

}

public final static Document XMLfromString(String xml){
Document doc = null;

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);
try {

DocumentBuilder db = dbf.newDocumentBuilder();

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);

} catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}

return doc;

}
public static String getXMLstring(String xml){
String line = null;

try {

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(xml);

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);

} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
}

return line;

}
public static String getXML(InputStream is)throws IOException {

BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
byte b = (byte)result;
buf.write(b);
result = bis.read();
}
return buf.toString();
}
public final static String getElementValue( Node elem ) {
Node kid;
if( elem != null){
if (elem.hasChildNodes()){
for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){
if( kid.getNodeType() == Node.TEXT_NODE ){
return kid.getNodeValue();
}

}
}
}
return "";
}
public static int numResults(Document doc){
Node results = doc.getDocumentElement();
int res = -1;

try{
res = Integer.valueOf(results.getAttributes().getNamedItem("Categories").getNodeValue());
}catch(Exception e ){
res = -1;
}

return res;
}

public static String getValue(Element item, String str) {
NodeList n = item.getElementsByTagName(str);
return StudyParser.getElementValue(n.item(0));
}


}

我的activity中的代码如下所示

 TextView txt;
try{
txt = (TextView)findViewById(R.id.tv);
String xml= StudyParser.getXML(getAssets().open("data.xml"));

Document doc = StudyParser.XMLfromString(xml);
NodeList n = doc.getElementsByTagName("book1");
Element eid = (Element) n.item(0);
String Js=StudyParser.getValue(eid, "page1");
Typeface tf = Typeface.createFromAsset(getAssets(),"bulara_5.ttf");
txt.setTypeface(tf);
txt.setText(Js);
}catch(Exception e){
Log.e("error",e.toString());
}

关于android - 我想在我的 Android 应用程序中显示区域语言 (Gurmukhi),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11238909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com