English 中文(简体)
我怎样才能在iText使用一个黑体式的Unicode?
原标题:How can I use a bold version of Arial Unicode in iText?
  • 时间:2011-03-29 20:47:19
  •  标签:
  • fonts
  • itext

我想在iText中使用标准黑体字,但如果特性不成黑体,我想不加入Arial Unicode。 是否有办法将字塔连接起来? 我曾搜索过一个黑色的阿里亚统法协会密码,但我无法找到。

问题回答

纤维通常被作为“填充型体”。 你们可以通过改变文本“放任方式”来增加一些宽度的中风。

And it looks like iText has already implemented this very feature (along with "poor man s italic", in PdfChunk.java. It uses a stroke width of 1/30 the font size.

因此,如果你只是要求用黑体联盟编码,那么你就应当获得“穷人的 bold”已经果敢。

至于联合体,我不知道有这样的制度,即没有。 你们可以做像在更高一级那样的事情,打破chu。 类似:

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);

请注意,上述代码无意试图看到某一个果园是否可在<条码>中提取。 有可能改写如下:addTextToPara(),以掌握一系列的字体,但I m并非几乎照亮;]

根据上述法典,你可以与你一样创建基地基金会,我更喜欢那里98%的病例的“实体H”。 <代码>mainFont 可在 font和backupFont上建立 或许是Else。 He,你甚至可以做这样的事情:

BaseFont mainFont = BaseFont.createFont(arialBoldPath, BaseFont.WINANSI, false);
BaseFont backupFont = BaseFont.createFont(arialBoldPath, BaseFont.IDENTITY_H, true);

Use the same system-level font for both, and only embed the characters that fall outside "the norm". This still produces two separate font resources in the PDF, but one is not embedded (and used most of the time), and the other is an embedded subset of hopefully-rare characters.





相关问题
Java (AWT): fitting text in a box

I have an application that extends a Frame. Then, it ll display a few lines of text using: Font f = new Font("Arial", Font.PLAIN, 10); g.setFont(f); g.drawString("Test|great Yes ^.", x, y + 10); Now ...

Embed font into PDF file by using iText

I defined a tag map, and got a XML data file. I want to convert the XML data file to PDF by using iText. The question is how to embed fonts (e.g. Polish font, Chinese font) into the target PDF when ...

Font Rendering between Mozilla and webkit

I m not sure if this has anything to do with the recent Safari update, but I m beginning to notice this a lot. There is a drastic difference in the way each browser is rendering fonts. for instance, ...

Embedding Fonts in AS3 - Dynamic Text Field disappears

This is hopefully a new problem or just me missing something obvious. Please help! I m embedding a font into my AS3 application. I m doing everything by-the-book and it half-works. In my main class, ...

Dynamic GD image width text

I m trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text ...

How do I combine @font-face and @media declarations?

I d like to build a common typography stylesheet with a very small number of selectors. As such, I d far prefer to use @media sections for the various versions rather than create different files, each ...

热门标签