/* fontlist.c -- Font list of 41 fonts * Copyright (C) 1998, 1999 FastIO Systems, All Rights Reserved. * For conditions of use, license, and distribution, see LICENSE.txt or LICENSE.pdf. NEXTSTEP/OPENSTEP cc -Wall -s -object -o fontlist fontlist.c -I/usr/local/include -lcpdfpm BSDI/gcc gcc -Wall -o fontlist fontlist.c -L. -lcpdfm -lm SunOS5.4/CC-4.0 cc -o fontlist fontlist.c -Xa -L. -lcpdfm -lm HP-UX B.11.00 (assuming header and lib are installed, or in examples directory below): cc -O -Aa -Ae +Z +DA1.0 -DHPUX -I /usr/local/include -I.. -L.. -o fontlist fontlist.c -lcpdfm -lm 1999-08-22 [io] for v2.00 1998-03-07 [io] --- */ #include #include #include #include #include "cpdflib.h" #define STRWIDTHMAX 6.7 char *textdata = "We the People of the United States, in Order to form a more perfect Union,\ establish Justice, insure domestic Tranquility, provide for the common\ defence, promote the general Welfare, and secure the Blessings of Liberty to\ ourselves and our Posterity, do ordain and establish this Constitution for the\ United States of America."; char *symboldata = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn"; int main(int argc, char *argv[]) { CPDFdoc *pdf; int i; float ybump = 0.22; float y = 9.75; char strbuf[4096], *p, *plast; /* == Initialization == */ pdf = cpdf_open(0, NULL); cpdf_enableCompression(pdf, YES); /* use Flate/Zlib compression */ cpdf_init(pdf); cpdf_setTitle(pdf, "Font Sample"); cpdf_setSubject(pdf, "Font listing for 41 fonts in ClibPDF v2.00"); cpdf_pageInit(pdf, 1, PORTRAIT, LETTER, LETTER); /* create page */ cpdf_setgray(pdf, 0.2); cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "CPDF-SmallCap", "MacRomanEncoding", 24.0); cpdf_text(pdf, 1.0, 10.4, 0.0, "List of Fonts Supported by ClibPDF v2.00"); cpdf_endText(pdf); cpdf_setlinewidth(pdf, 10.0); cpdf_setrgbcolor(pdf, 0.4, 0.4, 1.0); /* Blue */ cpdf_moveto(pdf, 1.0, 10.25); cpdf_lineto(pdf, 7.8, 10.25); cpdf_moveto(pdf, 1.0, 0.5); cpdf_lineto(pdf, 7.8, 0.5); cpdf_stroke(pdf); cpdf_setgray(pdf, 0.0); for(i=0; i< 41; i++) { cpdf_beginText(pdf, 0); if(i != 12 && i != 13) { /* Not symbol font */ cpdf_setFont(pdf, cpdf_fontnamelist[i], "MacRomanEncoding", 12.0); /* Adjust string length so that it will fit on the page */ p = plast = strbuf; sprintf(strbuf, "%s: %s", cpdf_fontnamelist[i], textdata); while( (p = strchr(p, ' ')) != NULL) { *p = '\0'; /* break string at this space */ if(cpdf_stringWidth(pdf, strbuf) > STRWIDTHMAX*inch) break; /* still fits, so find next space */ plast = p; /* save the last word break at which the string still fits */ *p = ' '; /* put back space */ p++; /* move over to next char */ } *plast = '\0'; cpdf_text(pdf, 1.0, y, 0.0, strbuf); cpdf_endText(pdf); } else { /* Symbol: 12 ZapfDingbats: 13 */ cpdf_setFont(pdf, "Times-Roman", "MacRomanEncoding", 12.0); sprintf(strbuf, "%s:", cpdf_fontnamelist[i]); cpdf_text(pdf, 1.0, y, 0.0, strbuf); /* Font name in roman font */ cpdf_endText(pdf); cpdf_beginText(pdf, 0); cpdf_setFont(pdf, cpdf_fontnamelist[i], "MacRomanEncoding", 12.0); /* set symbol font */ cpdf_text(pdf, 2.05, y, 0.0, symboldata); /* Font name in roman font */ cpdf_endText(pdf); } y -= ybump; } /* for(i=0...) */ y -= ybump*0.5; cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "Times-Italic", "MacRomanEncoding", 8.0); cpdf_text(pdf, 1.0, y, 0.0, "Note: CPDF-Monospace and CPDF-SmallCap will not be rendered correctly by most non-Adobe PDF viewers (e.g., Ghostscript, xpdf, PDFView.app)."); cpdf_endText(pdf); cpdf_beginText(pdf, 0); cpdf_setFont(pdf, "CPDF-Monospace", "MacRomanEncoding", 10.0); cpdf_setHorizontalScaling(pdf, 125.0); sprintf(strbuf, "[Generated by: %s]", cpdf_version()); cpdf_text(pdf, 1.0, 0.3, 0.0, strbuf); cpdf_setHorizontalScaling(pdf, 100.0); cpdf_endText(pdf); /* == generate output and clean up == */ cpdf_finalizeAll(pdf); /* PDF file/memstream is actually written here */ cpdf_savePDFmemoryStreamToFile(pdf, "fontlist.pdf"); /* == Clean up == */ cpdf_launchPreview(pdf); /* launch Acrobat/PDF viewer on the output file */ cpdf_close(pdf); /* shut down */ return(0); }