您的位置:逆风者 VC++ 正文
 添加时间:2007-09-01 原文发表:2007-08-31 人气:20 来源:vckbase.com

本文章共2245字,分2页,当前第1页,快速翻页:
 

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

作者:Michelle Yi

下载源代码

逆@风@者

一般来说, 每种基本字体, 都会有在其基础上变化字形的附加字体。比如,字体Arial, 就有其附加字体Arial Bold (粗体), Arial Italic(斜体), 及Arial Bold Italic(粗斜体)。一般你都可以找到或购买到相应的附加字体。
但有时为了应急,或对字体字形没有非常严格的要求。在这样的情况下,我们可以采用人工字形生成(Artificial font styles)。Artificial 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 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;

}

 
 
本文章更多内容1 - 2 - 下一页>>
相关文章

系统分析员考试回顾
加密 Windows CE系统
WinSock学习笔记(一)
如何实现24位色工具条
树型控件实现数据库的访问
JScript 内存泄露、获取 XmlDataDocument 以
Windows中回收站(Recycle Bin)的存取方法
一个可重用的RAS 类
C语言之四书五经
MySQL数据库接口的VC实现与应用
在WinCE5中编程查找并连接周围的蓝牙设备并
语法高亮控件 PfxEditCtrl
Windows SDK笔记(五):非模式对话框
N皇后问题摆法算法描述
COM组件设计与应用(十八)——属性包
Security Briefs...小心完全信任的代码
如何在服务(Service)程序中显示对话框
如何在编辑框中使用IAutoComplete接口
基于SHA-256的HMAC文件校验器
VC学习笔记之一:怎样实现XP风格按钮

相关评论


本文章所属分类:首页 VC++

  热门关键字: