On pdflib Chinese output (v)--artificial generation of bold and italic font

Source: Internet
Author: User
Tags italic font pdflib printf

In general, each basic font will have additional fonts that change the glyph on its basis. For example, the font Arial has its additional font Arial Bold (bold), Arial Italic (italic), and Arial Bold Italic (Bold italic). Generally you can find or purchase the appropriate additional fonts.

But sometimes there is no strict requirement for a contingency, or for font glyphs. In such cases, we can use artificial glyph generation (Artificial font styles). The Artificial font styles is a feature of Acrobat that simulates the generation of bold, italic, and bold italic based on the basic glyphs. Pdflib supports this feature and complies with Acrobat's limitations on this feature. The current functionality is limited to:

1. Acrobat standard font, in the Simplified Chinese is the pdflib Stsong-light,adobesongstd-light-acro, and stsongstd-light-acro three Simplified Chinese fonts.

2. Pdflib can access the. OTF OpenType font and use the Encoding of Table 1.1 (see), and the "embedding" parameter is set to False.

The following is a related example--c source program (attached to the generated PDF file –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 = x, 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 objec
        T (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 + 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; }

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.