在Unity3D和ItextSharp中使用自定义字体 [英] Use Custom font with Unity3D and ItextSharp

查看:167
本文介绍了在Unity3D和ItextSharp中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这个问题是从Unity Answers复制而来的,没有运气 得到任何解决方案.如果这种方法不可接受,那就让我 知道.

First of all, this question is copied from Unity Answers with no luck getting any solution. If this approach is not acceptable just let me know.

因为我需要使用特殊字符,而集成的itextsharp字体无法处理它们,所以我需要使用自己的自定义字体.我的应用程序中自定义字体的集成在编辑器中有效,但在Android设备中无效.

Because I need to use special characters, integrated itextsharp font cant handle them, I need to use my own custom font. The integration of custom font in my app is working in Editor but in Android device not.

任何人都知道如何在Android上访问与itextsharp一起使用的字体吗?

Does any body know how to access font on android for use with itextsharp?

我正在使用的字体路径:

For my font path I'm using:

 string fontPath = Application.dataPath + "/" + "FreeSans" + ".ttf";

我也尝试过:

string fontPath = Application.persistentDataPath + "/" + "FreeSans" + ".ttf";

对于字体创建,我使用:

And for font creation I use:

BaseFont bf = BaseFont.CreateFont(fontPath , BaseFont.CP1250, true);

当我使用第一个选项时,它仅在Unity编辑器中有效.

When I use first option it works only in Unity Editor.

我也很幸运地尝试了这两个选择.一个路径直接进入apk文件中的流资产文件夹,另一路径位于android文件夹设备中,在该文件夹中,字体是从流资产文件夹中复制的.每次,PDF都会在中间被取消,并且过程会停止.

I also tried with no luck this two options. One path goes directly to streaming assets folder located in apk file and the other one is located on android folder device, where font was copied from streaming assets folder. Every time, PDF was canceled in the middle and the process was stopped.

path = "jar:" + Application.dataPath + "!/assets/" + "FreeSans" + ".ttf";

 path = System.IO.Path.Combine(Application.streamingAssetsPath, "FreeSans.ttf");

当您在Android上制作PDF时,itextsharp的表现确实很奇怪.

itextsharp is behaving really odd in case when you are making PDF on android.

任何人都知道如何从android系统访问系统字体,以在设备上定位字体.也许itextsharp可以管理这种路径?

Does any body know how to access system font from android system, to locate font on device. Maybe itextsharp could manage this kind of path?

谢谢.

J.

推荐答案

所以.经过数小时的挠挠,我终于明白了.

So. After hours of scratching my head I finally got it right.

解决方案的第一部分写在这里.您必须将一些DLL文件放入项目文件夹.哪一种取决于您必须使用哪种编码.

The first part of solution is written here. You have to put some DLL files to project folder. Which one depends what encoding you have to use.

http: //answers.unity3d.com/questions/42955/codepage-1252-not-supported-works-in-editor-but-no.html

第二部分是这样的:

首先,您必须使用字体名称创建指向Android系统字体目录的路径:

First of all you have to make path to Android system font directory with font name:

path = Path.Combine("/system/fonts/", "DroidSans.ttf");

用FontFactory注册该字体:

Register that font with FontFactory:

iTextSharp.text.FontFactory.Register(path, "DroidSans");

之后,只需使用FontFactory.GetFont声明字体:

After that, you just declare font with FontFactory.GetFont:

font = iTextSharp.text.FontFactory.GetFont("DroidSans", 
                                BaseFont.IDENTITY_H,
                                false, 
                                10, 
                                iTextSharp.text.Font.NORMAL);

就这样!

这篇关于在Unity3D和ItextSharp中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆