浅谈PDFlib中文输出(五)----人工生成粗体及斜体字形

翻译|其它|编辑:郝浩|2005-09-02 09:29:00.000|阅读 2229 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


    一般来说, 每种基本字体, 都会有在其基础上变化字形的附加字体。比如,字体Arial, 就 有其附加字体Arial Bold (粗体), Arial Italic(斜体), 及Arial Bold Italic(粗斜体)。一般你都可以找到或购买到相应的附加字体。

    但有时为了应急,或对字体字形没有非常严格的要求。在这样的情况下,我们可以采用人工字形生成(Artifical font styles)。Artifical font styles是Acrobat的一个功能,它根据基本字形而模拟生成粗体,斜体及粗斜体。PDFlib支持这一功能,并遵守Acrobat对此功能的限制。目前此功能之局限于:

   1. Acrobat标准字体, 就简体中文来说也就是PDFlib自带的STSong-Light,AdobeSongStd-Light-Acro,及STSongStd-Light-Acro三种简体中文字体。

   2. PDFlib可以访问的.otf OpenType字体,并使用表1.1的编码(见浅谈PDFlib中文输出<一>), 且“embedding”参数设为假。

下面是一个相关的例子--C 源程序(附上生成的pdf文件 –PDFlib_cs5.pdf)。

/*******************************************************************/
/* This example demostrates the usage of artifical font styles
/* under Chinese Simplifed Windows.
/*******************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pdflib.h"

int main(void)
  {
    PDF *p = NULL;
    int Font_H = 0, Font_CS = 0, Left = 50, y = 700;
    const int INCRY = 25;
    const char TextUnicode[] = "\x80\x7B\x53\x4F\x2D\x4E\x87\x65";
    const int TEXTLEN = 8;

/* create a new PDFlib object */
if ((p = PDF_new()) == (PDF *) 0)
  {
    printf("Couldn't create PDFlib object (out of memory)!\n");
    return(2);
 }

PDF_TRY(p) {
    if (PDF_begin_document(p, "pdflib_cs5.pdf", 0, "") == -1)
      {
         printf("Error: %s\n", PDF_get_errmsg(p));
         return(2);
      }

     PDF_set_info(p, "Creator", "pdflib_cs5.c");
     PDF_set_info(p, "Author", "bowriver2001@yahoo.ca");
     PDF_set_info(p, "Title", "Usage of artifical font styles");

/* Start a new page. */
PDF_begin_page_ext(p, a4_width, a4_height, "");
Font_H = PDF_load_font(p, "Helvetica-Bold", 0, "winansi", "");
PDF_setfont(p, Font_H, 24);
PDF_show_xy(p, "Artifical Font Styles", Left + 100, y);

/* Normal */
y -= 2 * INCRY;
PDF_setfont(p, Font_H, 14);
PDF_show_xy(p, "Normal", Left, y);
y -= INCRY;
Font_CS = PDF_load_font(p, "STSong-Light", 0, "UniGB-UCS2-H", "");
PDF_setfont(p, Font_CS, 14);
PDF_show_xy2(p, TextUnicode, TEXTLEN, Left, y);

/* Italic */
y -= 2 * INCRY;
PDF_setfont(p, Font_H, 14);
PDF_show_xy(p, "Italic", Left, y);
y -= INCRY;
Font_CS = PDF_load_font(p, "STSong-Light", 0, "UniGB-UCS2-H", "fontstyle italic");
PDF_setfont(p, Font_CS, 14);
PDF_show_xy2(p, TextUnicode, TEXTLEN, Left, y);

/* Bold */
y -= 2 * INCRY;
PDF_setfont(p, Font_H, 14);
PDF_show_xy(p, "Bold", Left, y);
y -= INCRY;
Font_CS = PDF_load_font(p, "STSong-Light", 0, "UniGB-UCS2-H", "fontstyle bold");
PDF_setfont(p, Font_CS, 14);
PDF_show_xy2(p, TextUnicode, TEXTLEN, Left, y);

/* Bold-italic */
y -= 2 * INCRY;
PDF_setfont(p, Font_H, 14);
PDF_show_xy(p, "Bold-italic", Left, y);
y -= INCRY;
Font_CS = PDF_load_font(p, "STSong-Light", 0, "UniGB-UCS2-H",
"fontstyle bolditalic");
PDF_setfont(p, Font_CS, 14);
PDF_show_xy2(p, TextUnicode, TEXTLEN, Left, y);

/* End of page. */
PDF_end_page_ext(p, "");
PDF_end_document(p, "");
}

PDF_CATCH(p) {
    printf("PDFlib exception occurred in pdflib_cs5 sample:\n");
    printf("[%d] %s: %s\n", PDF_get_errnum(p), PDF_get_apiname(p),
    PDF_get_errmsg(p));
    PDF_delete(p);
    return(2);
  }

   PDF_delete(p);
   return 0;
}
 


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP