/* cn-test.c -- test program for Chinese language support. * Copyright (C) 1999 FastIO Systems, All Rights Reserved. * For conditions of use, license, and distribution, see LICENSE.pdf * included in the distribution or /LICENSE.pdf To display the generated PDF file, your system must have both traditional and simplified Chinese fonts installed. For Adobe Acrobat Reader 4.x and 5.0, these fonts are available for free downloading from: http://www.adobe.com/products/acrobat/acrrasianfontpack.html Errors will result if either of these fonts is missing. ------------------------------------------------------------------------------------ 1999-09-27 [io] Chinese version cc -Wall -o cn-test -I/usr/local/include cn-test.c -lcpdfpm The Chinese text data and the English original are from: ftp://ftp.tex.ac.uk/tex-archive/language/chinese/CJK/4_2.0/examples/ */ #include #include #include /* EUC-Big 5 : Traditional Chinse (Taiwan) */ char *euc_b5_text[] = { "¥»±`°Ý°Ýµª¶°~(FAQ list)~¬O±q¤@¨Ç¸g±`³Q°Ý¨?º°ÝÃD¤Î¨ä¾A·?º¸Ñ", "µª¤¤¡A¥H¤è«Kªº§Î¦¡ºK­n¦Ó¥Xªº¡C¸ò¤W¤@ª©¤£¦Pªº¬O¡A¨ä½s±Æµ²ºc¤w¹ý©³§?Ü¡C", "¦³Ãö·sµ²ºcªº²Ó¸`¡A¥i°Ñ¦Ò¡u¦p¦ó¾\\Ū¥»°Ýµª¶°¤Î¤F¸Ñ¨ä½s±Æµ²ºc¡v¸Ó", "¶µ¤¤ªº»¡©ú¡C", NULL }; /* EUC-GB : Simplified Chinese (PR China) */ char *euc_gb_text[] = { "±¾³£ÎÊÎÊ´ð¼¯~(FAQ list)~ÊÇ´ÓһЩ¾­³£±»Îʵ½µÄÎÊÌâ¼°ÆäÊʵ±µÄ½?, "´ð×У¬ÒÔ·½±ãµÄÐÎʽժҪ¶ø³öµÄ¡£¸úÊÏÒ»°æ²»Í¬µÄÊÇ£¬Æä±àÅŽṹÒѳ¹µ×¸Ä±ä¡£", "ÓйØÐ½ṹµÄϸ½Ú£¬¿É²Î¿¼¡¸ÈçºÎÔĶÁ±¾Îʴ𼯼°Á˽âÆä±àÅŽṹ¡¹¸Ã", "Ï?еÄ˵Ã÷¡£", NULL }; /* English */ char *english_text[] = { "This FAQ list was made to summarize some frequently asked", "questions and their answers in a convenient form. The structure of", "this FAQ list has drastically changed since the last version.", "For details of the new structure, see the entry of `How to", "read this FAQ and its structure'.", "", "The Chinese text data and the English original are from:", "ftp://ftp.tex.ac.uk/tex-archive/language/chinese/CJK/4_2.0/examples/", NULL }; int main(int argc, char *argv[]) { int i; CPDFdoc *pdf; float fontsize = 12.0; float x = 1.0; float y = 10.0; int alignmode = TEXTPOS_LL; float ybump = 0.25; /* == Initialization == */ pdf = cpdf_open(0, NULL); cpdf_enableCompression(pdf, YES); /* use Flate/Zlib compression */ cpdf_init(pdf); cpdf_pageInit(pdf, 1, PORTRAIT, LETTER, LETTER); /* page orientation */ /* Traditional Chinese Big-5 encoding */ cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "MHei-Medium", "ETen-B5-H", fontsize); /* Gothic type font */ for(i = 0; euc_b5_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_b5_text[i]); y -= ybump; } cpdf_endText(pdf); y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "MHei-Medium,Bold", "ETen-B5-H", fontsize); /* Gothic Bold type font */ for(i = 0; euc_b5_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_b5_text[i]); y -= ybump; } cpdf_endText(pdf); /* Traditional Chinese Big-5 encoding */ y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "MSung-Light", "ETen-B5-H", fontsize); /* Light type font */ for(i = 0; euc_b5_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_b5_text[i]); y -= ybump; } cpdf_endText(pdf); y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "MSung-Light,Bold", "ETen-B5-H", fontsize); /* Light Bold type font */ for(i = 0; euc_b5_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_b5_text[i]); y -= ybump; } cpdf_endText(pdf); /* Simplified Chinese: GB encoding */ y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "STSong-Light", "GBK-EUC-H", fontsize); /* STSong-Light font */ for(i = 0; euc_gb_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_gb_text[i]); y -= ybump; } cpdf_endText(pdf); y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "STSong-Light,BoldItalic", "GBK-EUC-H", fontsize); /* STSong-Light BoldItalic font */ for(i = 0; euc_gb_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, euc_gb_text[i]); y -= ybump; } cpdf_endText(pdf); y -= ybump; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "Helvetica", "MacRomanEncoding", fontsize); for(i = 0; english_text[i] != NULL; i++) { cpdf_textAligned(pdf, x, y, 0.0, alignmode, english_text[i]); y -= ybump; } cpdf_endText(pdf); cpdf_finalizeAll(pdf); /* PDF file/memstream is actually written here */ cpdf_savePDFmemoryStreamToFile(pdf, "cn-test.pdf"); cpdf_launchPreview(pdf); /* launch Acrobat/PDF viewer on the output file */ /* == Clean up == */ cpdf_close(pdf); /* shut down */ return 0; }