我想在iText中使用標準的粗體Arial字體,但是如果字符不存在爲粗體,我想默認爲Arial Unicode。有沒有在iText中結合字體的方法?我已經搜索了Arial Unicode的大膽的ttf文件,但我一直無法找到一個。如何在iText中使用Arial Unicode的大膽版本?
0
A
回答
0
字體通常繪製爲「填充形狀」。您可以通過更改文本渲染模式來添加一些寬度的筆劃,從而實現「窮人粗體」。
它看起來像iText的已經實現了這個非常有(伴隨着「窮人的斜體」,在PdfChunk.java。它採用的1/30字體大小筆劃寬度。
所以,如果你只是要求Arial Unicode的大膽版本,你應該已經得到「窮人的粗體」了。
至於組合字體,我不知道系統是這樣做的,不,你可以在例如:
void addTextToPara(Paragraph paragraph, String string, Font font, Font otherFont) {
BaseFont mainfont = font.getBaseFont();
StringBuffer curChunk = new StringBuffer();
StringBuffer otherChunk = new StringBuffer();
for (int curCharIdx = 0; curCharIdx< string.length(); ++curCharIdx) {
char curChar = string.charAt(curCharIdx);
byte charBytes[] = mainFont.convertToBytes(curChar);
if (charBytes == null || charBytes.length == 0) {
// can't represent that character in the main font
if (curChunk.length() > 0) {
paragraph.add(new Chunk(curChunk.toString(), font);
curChunk.setLength(0);
}
otherChunk.append(curChar);
} else {
if (otherChunk.length() > 0) {
paragraph.add(new Chunk(otherChunk.toString(), otherFont);
otherChunk.setLength(0);
}
curChunk.append(curChar);
// can represent the character with the main font
}
}
if (curChunk.length() > 0) {
paragraph.add(new Chunk(curChunk.toString(), font);
} else if (otherChunk.length() > 0) {
paragraph.add(new Chunk(otherChunk.toString(), otherFont);
}
}
BaseFont arialBoldBaseFont = BaseFont.createFont(arialBoldPath, BaseFont.WINANSI, false); // not embedded
BaseFont arialUnicodeBaseFont = BaseFont.createFont(arialUniPath, BaseFont.IDENTITY_H, true); // IDENITY_H forces an embedded subset, ignores "embedded" param.
Font mainFont = new Font(arialBoldBaseFont, size);
Font backupFont = new Font(arialUnicodeBaseFont, size, Font.BOLD);
...
addTextToPara(paragraph, string, mainFont, backupFont);
注意事項上面的代碼不會嘗試查看是否可以在otherFont
中繪製給定的字符。可以重寫addTextToPara()
以獲得一組字體,但我幾乎沒有那麼無聊。 ;)
通過上面的代碼,你可以用你喜歡的任何編碼創建BaseFonts,我只是比98%的情況更喜歡「身份H」。 mainFont
可以從WinAnsiEncoding
字體構建,並且backupFont
可以是其他東西。哎呀,你甚至可以做這樣的事情:
BaseFont mainFont = BaseFont.createFont(arialBoldPath, BaseFont.WINANSI, false);
BaseFont backupFont = BaseFont.createFont(arialBoldPath, BaseFont.IDENTITY_H, true);
使用相同的系統級字體兩種,只有嵌入落在外面「規範」的字符。這仍然會在PDF中產生兩個單獨的字體資源,但其中一個不是嵌入的(並且大部分時間都是使用的),另一個是希望的罕見字符的嵌入子集。
相關問題
- 1. iText的與大膽,從CSS樣式
- 2. 如何獲得UIFont的prefferedFontForTextStyle的大膽版本?
- 3. Javascript使文本大膽?
- 4. 在iText的(Java版本)
- 5. 如何使備用李大膽?
- 6. itext JavaScript版本
- 7. 如何在CSS中使用arial窄?
- 8. 使得在textarea的大膽
- 9. Coldfusion 9使用什麼版本的iText?
- 10. iText的地方文字與Arial粗體和一些顏色
- 11. 製作常規ttf字體的大膽版本
- 12. 拉繩大膽和普通文本
- 13. 以大膽顯示文本
- 14. bouncycastle和iText版本
- 15. 標,大膽使用GGPLOT2
- 16. iText中的Unicode字符PDF
- 17. 如何使文本的一部分TextView的大膽
- 18. 在ColdFusion中使用不同版本的iText
- 19. 大膽
- 20. iText unicode in annotaion
- 21. Khmer Unicode in iText
- 22. 如何在谷歌Apps腳本在Browser.msgBox內大膽的文字
- 23. 大膽
- 24. 大膽的TitledBorder
- 25. 如何使用不同的字體的LabelField如Arial,TimesNewRoman黑莓
- 26. 相當於Arial Unicode的字體MS
- 27. 如何做大膽而簡單的文本回聲在PHP
- 28. 如何拼湊SHGetFileInfo(c#)的unicode版本?
- 29. php mysql搜索腳本,如何使匹配結果大膽
- 30. Java版本支持的Unicode版本6
向短語添加這樣的內容很有意義。嗯... – 2011-03-30 18:14:28