如何知道ctext与Itext中的字体兼容? [英] How to know cmap compatible with font in Itext?

查看:192
本文介绍了如何知道ctext与Itext中的字体兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查我的字体编码(字体的类型是OpenType字体),结果如下:

I check my font's encoding (the font's type is OpenType Font), the result is below :

PostScript name: HiraKakuProN-W3
Available code pages:
encoding[0] = 1252 Latin 1
encoding[1] = 1251 Cyrillic
encoding[2] = 1253 Greek
encoding[3] = 932 JIS/Japan

然后,按代码创建字体:

Then, creat font by code :

Font f = new Font(BaseFont.createFont("hirafont.otf", "Identity-V", BaseFont.EMBEDDED));

除身份-V和身份-H外,我不能使用其他cmaps等as(UniJISX0213-UTF32-H / V ......)。
在这个字体中,我看到许多字形以90度的旋转显示。如何将unicode中的char映射到字体中旋转的char字形?

Except "Identity-V" and "Identity-H", i can't use other cmaps such as ("UniJISX0213-UTF32-H/V ..."). And in this font i see many glyphs which is displayed in rotation of 90 degrees. How to map char in unicode to char's glyph which is rotation in font?

示例:'〔'(0x3014 12308 LEFT TORTOISE SHELL BRACKET)地图索引9265 in font

Example : '〔 ' (0x3014 12308 LEFT TORTOISE SHELL BRACKET) map with index 9265 in font

---------更新代码--------

---------update code--------

PdfEncodings.loadCmap("UniJISX0213-UTF32-V", PdfEncodings.CRLF_CID_NEWLINE);
String temp = "a";

byte[] text = temp.getBytes("Shift_JIS");
String cid = PdfEncodings.convertCmap("UniJISX0213-UTF32-V", text);
BaseFont bf = BaseFont.createFont("hiraginoFont.otf",BaseFont.IDENTITY_V, BaseFont.EMBEDDED);
Paragraph p = new Paragraph(cid, new Font(bf, 14));


推荐答案

我不得不深入研究我的第一本书参考你所问的问题。很久以前,我们曾经分发过以下jar: itext-asiancmaps.jar
这个jar不要与用于CJK字体的itext-asian.jar混淆。

I had to dig into my first book to find a reference to what you're asking. A long time ago, we used to distribute the following jar: itext-asiancmaps.jar. This jar is not to be confused with itext-asian.jar which is used for CJK fonts.

我花了一段时间才找到它的副本罐。你可以在这个旧的ZIP文件中找到它: extrajars-2.1.zip

It took me a while to find a copy of that jar. You'll find it in this old ZIP file: extrajars-2.1.zip

根据我的第一本书(2005-2006编写),您可以将此jar用于itext-asian中CMaps不支持的编码。 jar

According to my first book (written in 2005-2006), you can use this jar for encodings that are not supported by the CMaps in itext-asian.jar

它的用法如下:

PdfEncodings.loadCmap("GBK2K-H", PdfEncodings.CRLF_CID_NEWLINE);
byte[] text = my_GB_encoded_text;
String cid = PdfEncodings.convertCmap("GBK2K-H", text);
BaseFont bf = BaseFont.createFont("STSong-Light",
    BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Paragraph p = new Paragraph(cid, new Font(bf, 14));
document.add(p);

如您所知 BaseFont.IDENTITY_H BaseFont.IDENTITY_V 是2字节CID的水平和垂直标识映射。 PdfEncodings 类可以将特定编码中的 String 转换为 String 具有2字节CID。在这种情况下,原始字符串在GB 18030-2000中编码;我们需要将其转换为另一个 String ,以便iText可以使用 IDENTITY_H 编码。

As you know BaseFont.IDENTITY_H and BaseFont.IDENTITY_V are the horizontal and vertical identity mappings for 2-byte CIDs. The PdfEncodings class can convert a String in a specific encoding to a String with 2-byte CIDs. In this case, the original String was encoded in the GB 18030-2000; we needed to convert this to another String so that iText could use the IDENTITY_H encoding.

在我的第一本书中,我写道:为了完整起见,我插入了这个样本。在过去的三年中,只有少数人发布过有关此问题的问题。当我写第二本书(2009-2010)时,没有人问过这个功能,所以我放弃了用cmaps分发jar,示例没有写第二本书。

In my first book, I wrote: "I insert this sample for the sake of completeness. In the past three years, only a handful of people have posted questions about this." By the time I wrote my second book (2009-2010), nobody was asking about this functionality, so I dropped distributing the jar with the cmaps and the example didn't make the second book.

我现在正在复兴这个旧例子,希望它有用。我在2005年或2006年测试了一次,然后就开始工作了。我不能保证它今天仍然有效。

I am now reviving this old example in the hope that it is useful. I tested it once in 2005 or 2006, and it worked back then. I can't guarantee that it still works today.

这篇关于如何知道ctext与Itext中的字体兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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