为什么PdfFontFactory无法在我的unity android游戏中注册位于应用程序持久数据路径中的本地语言字体



我正在使用Itext7以我的本地语言创建pdf。在standalone_windows上一切都很好,但在android中,PdfFontFactory无法注册这些字体。

在Standalone_Windows 中,我从流媒体资产中提取原始文件,它们工作得很好。

在Android中,我使用UnityWebRequest将字体从流式资产路径下载到持久数据路径

这是用于从流式资产下载字体字节并将其写入持久数据路径的代码:

string fontpath1 = System.IO.Path.Combine(Application.streamingAssetsPath, "LEOPALMHINDI15K710.TTF");
string fontpath2 = System.IO.Path.Combine(Application.streamingAssetsPath, "LEOPALMHINDI14K240.TTF");
//Request Hindi Font 1
UnityWebRequest request = UnityWebRequest.Get(fontpath1);
request.SendWebRequest();
while (!request.isDone)
{

}
System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath , "LEOPALMHINDI15K710.TTF"),request.downloadHandler.data); 
request.Dispose();
//Request Hindi Font 2
UnityWebRequest font2 = UnityWebRequest.Get(fontpath2);
font2.SendWebRequest();
while (!font2.isDone)
{

}
System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI14K240.TTF"), font2.downloadHandler.data);
font2.Dispose();

这是我使用filePath字符串读取字体文件时使用的代码:

string HFOnt = System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI15K710.TTF");
string HFOnt2 = System.IO.Path.Combine(Application.persistentDataPath, "LEOPALMHINDI14K240.TTF");
PdfFontFactory.Register(HFOnt, "HindiFont1");
PdfFont myHindiFont1 = PdfFontFactory.CreateRegisteredFont("HindiFont1", PdfEncodings.IDENTITY_H, true);

PdfFontFactory.Register(HFOnt2, "HindiFont2");
PdfFont myHindiFont2 = PdfFontFactory.CreateRegisteredFont("HindiFont2", PdfEncodings.IDENTITY_H, true);

//Create Writer

if (File.Exists(path))
{
File.Delete(path);
}
PdfWriter writer = new PdfWriter(path);


//Create Pdf Document Object
PdfDocument pdf = new PdfDocument(writer);

//Create A Document
Document document = new Document(pdf, PageSize.A4);
document.SetMargins(90f, 36f, 120f, 36f);
PdfPage page1 = pdf.AddNewPage();
document.Add(new iText.Layout.Element.AreaBreak());

//Get Page Size and Canvas
PdfCanvas canvas = new PdfCanvas(page1);
Rectangle pageSize = page1.GetPageSize();
canvas.BeginText()
.MoveText(pageSize.GetWidth() / 2-35, pageSize.GetHeight() - 400)
.SetFontAndSize(myHindiFont1, 9f)
.ShowText("lfdZy uacj dqvk uacj gS")
.EndText();

document.Close();

我正在使用UnityWebRequest将这些字体从流式资产下载到持久数据路径。

我使用file检查文件是否存在。在处理Unity Web请求后存在于持久数据路径中,并且在两个字体文件的跟踪中都返回true

这是我在设备监视器中得到的错误:

03-02 13:40:57.084:E/Unity(18347(:NotSupportedException:找不到编码1252数据。请确保安装并启用了正确的国际代码集程序集。

03-02 13:40:57.084:E/Unity(18347(:在系统。文本编码。<中的GetEncoding(System.Int32代码页([0x023f];7ba07f088431485bb722f3b373e87ee>:0

03-02 13:40:57.084:E/Unity(18347(:在系统。文本编码。<中的GetEncoding(System.String名称([0x0012];7ba07f088431485bb722f3b373e87ee>:0

03-02 13:40:57.084:E/Unity(18347(:在iText。IO.Util.JavaUtil.GetStringForBytes(System.Byte[]字节,System.Int32偏移量,System.Int32length,System.String编码([0x0000];57da1b8d8a184e278c732544ebe6412a>:0

03-02 13:40:57.084:E/Unity(18347(:在iText。<中的IO.Util.JavaUtil.GetStringForBytes(System.Byte[]字节,System.String编码([0x0000];57da1b8d8a184e278c732544ebe6412a>:0

03-02 13:40:57.084:E/Unity(18347(:在iText。<中的IO.Source.RandomAccessFileOrArray.ReadString(System.Int32长度,System.String编码([0x000e];57da1b8d8a184e278c732544ebe6412a>:0

03-02 13:40:57.084:E/Unity(18347(:在iText。<中的IO.Font.OpenTypeParser.ReadStandardString(System.Int32长度([0x0000];57da1b8d8a184e278c732544ebe6412a>:0

03-02 13:40:57.084:E/Unity(18347(:在iText。IO.Font.OpenTypeParser.Process(([0x0

有人可以查看这个帮助我注册字体的信息吗?

只需在我的项目中保存i18n.dll文件,它就可以工作了。感谢前面的所有线程。

最新更新