|
浅谈PDFlib中文输出(五) 一般来说, 每种基本字体, 都会有在其基础上变化字形的附加字体。比如,字体Arial, 就有其附加字体Arial Bold (粗体), Arial Italic(斜体), 及Arial Bold Italic(粗斜体)。一般你都可以找到或购买到相应的附加字体。 下面是一个相关的例子--C 源程序(附上生成的pdf文件 –PDFlib_cs5.pdf)。 /*******************************************************************/
/* This example demostrates the usage of Artificial 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", "myi@pdflib.com");
PDF_set_info(p, "Title", "Usage of Artificial 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, "Artificial 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;
}
相关链接: PDFLIB官方网站: http://www.pdflib.com PDFLIB官方下载专页:http://www.pdflib.com/products/pdflib/download/index.html VC知识库PDFLIB下载:http://www.vckbase.com/tools (全文完) |
背景:
阅读新闻
浅谈PDFlib中文输出(五)人工生成粗体及斜体字形
| [日期:2006-11-20] | 作者: | [字体:大 中 小] |
阅读: 次
【 打印 】
【 打印 】
相关新闻
相关关键词:
全站导航
gmail.com