#include "pdfutils.h"
#include "fontembed/embed.h"
-void pdfOut_printf(pdfOut *pdf,const char *fmt,...) // {{{
+void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...) // {{{
{
assert(pdf);
int len;
}
// }}}
-void pdfOut_putString(pdfOut *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
+void cfPDFOutPutString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
{
assert(pdf);
assert(str);
}
// }}}
-void pdfOut_putHexString(pdfOut *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
+void cfPDFOutPutHexString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
{
assert(pdf);
assert(str);
}
// }}}
-pdfOut *pdfOut_new() // {{{ - NULL on error
+cf_pdf_out_t *cfPDFOutNew() // {{{ - NULL on error
{
- pdfOut *ret=malloc(sizeof(pdfOut));
+ cf_pdf_out_t *ret=malloc(sizeof(cf_pdf_out_t));
if (ret) {
- memset(ret,0,sizeof(pdfOut));
+ memset(ret,0,sizeof(cf_pdf_out_t));
}
return ret;
// }}}
// NOTE: uses statically allocated buffer
-const char *pdfOut_to_pdfdate(struct tm *curtm) // {{{
+const char *cfPDFOutToPDFDate(struct tm *curtm) // {{{
{
static char curdate[250];
if (!curtm) {
}
// }}}
-int pdfOut_add_xref(pdfOut *pdf) // {{{ - returns obj_no
+int cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{ - returns obj_no
{
assert(pdf);
assert(pdf->xrefsize<=pdf->xrefalloc);
}
// }}}
-int pdfOut_add_page(pdfOut *pdf,int obj) // {{{ - returns false on error
+int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj) // {{{ - returns false on error
{
assert(pdf);
assert(obj>0);
}
// }}}
-int pdfOut_add_kv(pdfOut *pdf,const char *key,const char *val) // {{{ - returns false on error
+int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val) // {{{ - returns false on error
{
assert(pdf);
assert(pdf->kvsize<=pdf->kvalloc);
if (pdf->kvsize==pdf->kvalloc) {
- struct keyval_t *tmp;
+ struct cf_keyval_t *tmp;
pdf->kvalloc+=10;
- tmp=realloc(pdf->kv,sizeof(struct keyval_t)*pdf->kvalloc);
+ tmp=realloc(pdf->kv,sizeof(struct cf_keyval_t)*pdf->kvalloc);
if (!tmp) {
pdf->kvalloc=-1;
return 0;
}
// }}}
-int pdfOut_begin_pdf(pdfOut *pdf) // ,...output_device?...) // {{{ - false on error
+int cfPDFOutBeginPDF(cf_pdf_out_t *pdf) // ,...output_device?...) // {{{ - false on error
{
assert(pdf);
assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
pdf->xrefsize=pdf->pagessize=0;
pdf->filepos=0;
- pages_obj=pdfOut_add_xref(pdf); // fixed later
+ pages_obj=cfPDFOutAddXRef(pdf); // fixed later
if (pages_obj!=1) {
return 0;
}
- pdfOut_printf(pdf,"%%PDF-1.3\n");
+ cfPDFOutPrintF(pdf,"%%PDF-1.3\n");
return 1;
}
// }}}
-void pdfOut_finish_pdf(pdfOut *pdf) // {{{
+void cfPDFOutFinishPDF(cf_pdf_out_t *pdf) // {{{
{
int iA;
int root_obj,info_obj=0,xref_start;
// pages
const int pages_obj=1;
pdf->xref[0]=pdf->filepos; // now fix it
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Pages\n"
" /Count %d\n"
" /Kids [",
pages_obj,pdf->pagessize);
for (iA=0;iA<pdf->pagessize;iA++) {
- pdfOut_printf(pdf,"%d 0 R ",pdf->pages[iA]);
+ cfPDFOutPrintF(pdf,"%d 0 R ",pdf->pages[iA]);
}
- pdfOut_printf(pdf,"]\n"
+ cfPDFOutPrintF(pdf,"]\n"
">>\n"
"endobj\n");
// rootdict
- root_obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ root_obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Catalog\n"
" /Pages %d 0 R\n"
">>\n"
// info
if (pdf->kvsize) {
- info_obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ info_obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<<\n",
info_obj);
for (iA=0;iA<pdf->kvsize;iA++) {
- pdfOut_printf(pdf," /%s ",pdf->kv[iA].key);
- pdfOut_putString(pdf,pdf->kv[iA].value,-1);
- pdfOut_printf(pdf,"\n");
+ cfPDFOutPrintF(pdf," /%s ",pdf->kv[iA].key);
+ cfPDFOutPutString(pdf,pdf->kv[iA].value,-1);
+ cfPDFOutPrintF(pdf,"\n");
}
- pdfOut_printf(pdf,">>\n"
+ cfPDFOutPrintF(pdf,">>\n"
"endobj\n");
}
// TODO: some return-value checking (??)
// write xref
xref_start=pdf->filepos;
- pdfOut_printf(pdf,"xref\n"
+ cfPDFOutPrintF(pdf,"xref\n"
"%d %d\n"
"%010d 65535 f \n",
0,pdf->xrefsize+1,0);
for (iA=0;iA<pdf->xrefsize;iA++) {
- pdfOut_printf(pdf,"%010ld 00000 n \n",
+ cfPDFOutPrintF(pdf,"%010ld 00000 n \n",
pdf->xref[iA]);
}
- pdfOut_printf(pdf,"trailer\n"
+ cfPDFOutPrintF(pdf,"trailer\n"
"<<\n"
" /Size %d\n"
" /Root %d 0 R\n",
pdf->xrefsize+1,
root_obj);
if (info_obj) {
- pdfOut_printf(pdf," /Info %d 0 R\n",info_obj);
+ cfPDFOutPrintF(pdf," /Info %d 0 R\n",info_obj);
}
- pdfOut_printf(pdf,">>\n"
+ cfPDFOutPrintF(pdf,">>\n"
"startxref\n"
"%d\n"
"%%%%EOF\n",
}
// }}}
-void pdfOut_free(pdfOut *pdf) // {{{
+void cfPDFOutFree(cf_pdf_out_t *pdf) // {{{
{
if (pdf) {
assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
static void pdfOut_outfn(const char *buf,int len,void *context) // {{{
{
- pdfOut *pdf=(pdfOut *)context;
+ cf_pdf_out_t *pdf=(cf_pdf_out_t *)context;
if (fwrite(buf,1,len,stdout)!=len) {
perror("Short write");
}
// }}}
-int pdfOut_write_font(pdfOut *pdf,EMB_PARAMS *emb) // {{{
+int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{
{
assert(pdf);
assert(emb);
EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
if (!fdes) {
if (emb->outtype==EMB_FMT_STDFONT) { // std-14 font
- const int f_obj=pdfOut_add_xref(pdf);
+ const int f_obj=cfPDFOutAddXRef(pdf);
char *res=emb_pdf_simple_stdfont(emb);
if (!res) {
return 0;
}
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%s"
"endobj\n"
,f_obj,res);
return 0;
}
- const int ff_obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ const int ff_obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Length %d 0 R\n"
,ff_obj,ff_obj+1);
if (emb_pdf_get_fontfile_subtype(emb)) {
- pdfOut_printf(pdf," /Subtype /%s\n",
+ cfPDFOutPrintF(pdf," /Subtype /%s\n",
emb_pdf_get_fontfile_subtype(emb));
}
if (emb->outtype==EMB_FMT_TTF) {
- pdfOut_printf(pdf," /Length1 %d 0 R\n"
+ cfPDFOutPrintF(pdf," /Length1 %d 0 R\n"
,ff_obj+2);
} else if (emb->outtype==EMB_FMT_T1) { // TODO
- pdfOut_printf(pdf," /Length1 ?\n"
+ cfPDFOutPrintF(pdf," /Length1 ?\n"
" /Length2 ?\n"
" /Length3 ?\n"
);
}
- pdfOut_printf(pdf,">>\n"
+ cfPDFOutPrintF(pdf,">>\n"
"stream\n");
long streamsize=-pdf->filepos;
const int outlen=emb_embed(emb,pdfOut_outfn,pdf);
streamsize+=pdf->filepos;
- pdfOut_printf(pdf,"\nendstream\n"
+ cfPDFOutPrintF(pdf,"\nendstream\n"
"endobj\n");
- const int l0_obj=pdfOut_add_xref(pdf);
+ const int l0_obj=cfPDFOutAddXRef(pdf);
assert(l0_obj==ff_obj+1);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%ld\n"
"endobj\n"
,l0_obj,streamsize);
if (emb->outtype==EMB_FMT_TTF) {
- const int l1_obj=pdfOut_add_xref(pdf);
+ const int l1_obj=cfPDFOutAddXRef(pdf);
assert(l1_obj==ff_obj+2);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%d\n"
"endobj\n"
,l1_obj,outlen);
}
- const int fd_obj=pdfOut_add_xref(pdf);
+ const int fd_obj=cfPDFOutAddXRef(pdf);
char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_obj);
if (!res) {
free(fdes);
return 0;
}
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%s"
"endobj\n"
,fd_obj,res);
free(fdes);
return 0;
}
- const int f_obj=pdfOut_add_xref(pdf);
+ const int f_obj=cfPDFOutAddXRef(pdf);
res=emb_pdf_simple_font(emb,fdes,fwid,fd_obj);
if (!res) {
free(fwid);
free(fdes);
return 0;
}
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%s"
"endobj\n"
,f_obj,res);
free(fdes);
return 0;
}
- const int cf_obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ const int cf_obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%s"
"endobj\n"
,cf_obj,res);
one_page(...parent,resources,mediabox,contents);
{
// " /Resources %d 0 R\n"
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Page\n"
" /Parent 1 0 R\n"
" /MediaBox [0 0 %d %d]\n"
*
*/
#include <time.h>
+#include <fontembed/embed.h>
-struct keyval_t {
+struct cf_keyval_t {
char *key,*value;
};
long *xref;
int kvsize,kvalloc;
- struct keyval_t *kv;
-} pdfOut;
+ struct cf_keyval_t *kv;
+} cf_pdf_out_t;
-/* allocates a new pdfOut structure
+/* allocates a new cf_pdf_out_t structure
* returns NULL on error
*/
-pdfOut *pdfOut_new();
-void pdfOut_free(pdfOut *pdf);
+cf_pdf_out_t *cfPDFOutNew();
+void cfPDFOutFree(cf_pdf_out_t *pdf);
/* start outputting a pdf
* returns false on error
*/
-int pdfOut_begin_pdf(pdfOut *pdf);
-void pdfOut_finish_pdf(pdfOut *pdf);
+int cfPDFOutBeginPDF(cf_pdf_out_t *pdf);
+void cfPDFOutFinishPDF(cf_pdf_out_t *pdf);
/* General output routine for our pdf.
* Keeps track of characters actually written out
*/
-void pdfOut_printf(pdfOut *pdf,const char *fmt,...)
+void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...)
__attribute__((format(printf, 2, 3)));
/* write out an escaped pdf string: e.g. (Text \(Test\)\n)
* >len==-1: use strlen(str)
*/
-void pdfOut_putString(pdfOut *pdf,const char *str,int len);
-void pdfOut_putHexString(pdfOut *pdf,const char *str,int len);
+void cfPDFOutPutString(cf_pdf_out_t *pdf,const char *str,int len);
+void cfPDFOutPutHexString(cf_pdf_out_t *pdf,const char *str,int len);
/* Format the broken up timestamp according to
* pdf requirements for /CreationDate
* NOTE: uses statically allocated buffer
*/
-const char *pdfOut_to_pdfdate(struct tm *curtm);
+const char *cfPDFOutToPDFDate(struct tm *curtm);
/* begin a new object at current point of the
* output stream and add it to the xref table.
* returns the obj number.
*/
-int pdfOut_add_xref(pdfOut *pdf);
+int cfPDFOutAddXRef(cf_pdf_out_t *pdf);
/* adds page dictionary >obj to the global Pages tree
* returns false on error
*/
-int pdfOut_add_page(pdfOut *pdf,int obj);
+int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj);
/* add a >key,>val pair to the document's Info dictionary
* returns false on error
*/
-int pdfOut_add_kv(pdfOut *pdf,const char *key,const char *val);
+int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val);
/* Writes the font >emb including descriptor to the pdf
* and returns the object number.
* On error 0 is returned.
*/
-struct _EMB_PARAMS;
-int pdfOut_write_font(pdfOut *pdf,struct _EMB_PARAMS *emb);
+int cfPDFOutWriteFont(cf_pdf_out_t *pdf,struct _EMB_PARAMS *emb);
unsigned char Codes[65536]; /* Unicode glyph mapping to font */
int Widths[256]; /* Widths of each font */
int Directions[256];/* Text directions for each font */
- pdfOut *pdf;
+ cf_pdf_out_t *pdf;
int FontResource; /* Object number of font resource dictionary */
float FontScaleX, FontScaleY; /* The font matrix */
lchar_t *Title, *Date; /* The title and date strings */
if ((!emb->subset) ||
(bits_used(emb->subset, emb->font->sfnt->numGlyphs)))
{
- emb->font->fobj=pdfOut_write_font(doc->pdf,emb);
+ emb->font->fobj=cfPDFOutWriteFont(doc->pdf,emb);
assert(emb->font->fobj);
}
}
// now fix FontResource
doc->pdf->xref[doc->FontResource-1]=doc->pdf->filepos;
- pdfOut_printf(doc->pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
"<<\n",
doc->FontResource);
EMB_PARAMS *emb=doc->Fonts[j][i];
if (emb->font->fobj) // used
{
- pdfOut_printf(doc->pdf," /%s%02x %d 0 R\n",names[i],j,emb->font->fobj);
+ cfPDFOutPrintF(doc->pdf," /%s%02x %d 0 R\n",names[i],j,emb->font->fobj);
}
}
}
- pdfOut_printf(doc->pdf,">>\n"
+ cfPDFOutPrintF(doc->pdf,">>\n"
"endobj\n");
- pdfOut_finish_pdf(doc->pdf);
+ cfPDFOutFinishPDF(doc->pdf);
- pdfOut_free(doc->pdf);
+ cfPDFOutFree(doc->pdf);
}
/*
{
int line; /* Current line */
- int content=pdfOut_add_xref(doc->pdf);
- pdfOut_printf(doc->pdf,"%d 0 obj\n"
+ int content=cfPDFOutAddXRef(doc->pdf);
+ cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
"<</Length %d 0 R\n"
">>\n"
"stream\n"
write_line(line, doc->Page[line], doc);
size+= ((doc->pdf->filepos)+2);
- pdfOut_printf(doc->pdf,"Q\n"
+ cfPDFOutPrintF(doc->pdf,"Q\n"
"endstream\n"
"endobj\n");
- int len_obj=pdfOut_add_xref(doc->pdf);
+ int len_obj=cfPDFOutAddXRef(doc->pdf);
assert(len_obj==content+1);
- pdfOut_printf(doc->pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
"%ld\n"
"endobj\n",
len_obj,size);
- int obj=pdfOut_add_xref(doc->pdf);
- pdfOut_printf(doc->pdf,"%d 0 obj\n"
+ int obj=cfPDFOutAddXRef(doc->pdf);
+ cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
"<</Type/Page\n"
" /Parent 1 0 R\n"
" /MediaBox [0 0 %.0f %.0f]\n"
"endobj\n",
obj,doc->PageWidth, doc->PageLength, content,
doc->FontResource);
- pdfOut_add_page(doc->pdf,obj);
+ cfPDFOutAddPage(doc->pdf,obj);
memset(doc->Page[0], 0,
sizeof(lchar_t) * (doc->SizeColumns) * (doc->SizeLines));
*/
assert(!(doc->pdf));
- doc->pdf = pdfOut_new();
+ doc->pdf = cfPDFOutNew();
assert(doc->pdf);
- pdfOut_begin_pdf(doc->pdf);
- pdfOut_printf(doc->pdf,"%%cupsRotation: %d\n",
+ cfPDFOutBeginPDF(doc->pdf);
+ cfPDFOutPrintF(doc->pdf,"%%cupsRotation: %d\n",
(doc->Orientation & 3) * 90); // TODO?
- pdfOut_add_kv(doc->pdf,"Creator","texttopdf/" PACKAGE_VERSION);
+ cfPDFOutAddKeyValue(doc->pdf,"Creator","texttopdf/" PACKAGE_VERSION);
curtime = time(NULL);
curtm = localtime(&curtime);
strftime(curdate, sizeof(curdate), "%c", curtm);
- pdfOut_add_kv(doc->pdf,"CreationDate",pdfOut_to_pdfdate(curtm));
- pdfOut_add_kv(doc->pdf,"Title",title);
- pdfOut_add_kv(doc->pdf,"Author",user); // was(PostScript): /For
+ cfPDFOutAddKeyValue(doc->pdf,"CreationDate",cfPDFOutToPDFDate(curtm));
+ cfPDFOutAddKeyValue(doc->pdf,"Title",title);
+ cfPDFOutAddKeyValue(doc->pdf,"Author",user); // was(PostScript): /For
// }}}
/*
doc->FontScaleY=68.0 / (doc->LinesPerInch);
// allocate now, for pages to use. will be fixed in epilogue
- doc->FontResource=pdfOut_add_xref(doc->pdf);
+ doc->FontResource=cfPDFOutAddXRef(doc->pdf);
if (doc->PrettyPrint)
{
y -= 36.0 / (float)(doc->LinesPerInch);
if (attr & ATTR_UNDERLINE)
- pdfOut_printf(doc->pdf,"q 0.5 w 0 g %.3f %.3f m %.3f %.3f l S Q ",
+ cfPDFOutPrintF(doc->pdf,"q 0.5 w 0 g %.3f %.3f m %.3f %.3f l S Q ",
x, y - 6.8 / (doc->LinesPerInch),
x + (float)len * 72.0 / (float)(doc->CharsPerInch),
y - 6.8 / (doc->LinesPerInch));
{
if (doc->ColorDevice) {
if (attr & ATTR_RED)
- pdfOut_printf(doc->pdf,"0.5 0 0 rg\n");
+ cfPDFOutPrintF(doc->pdf,"0.5 0 0 rg\n");
else if (attr & ATTR_GREEN)
- pdfOut_printf(doc->pdf,"0 0.5 0 rg\n");
+ cfPDFOutPrintF(doc->pdf,"0 0.5 0 rg\n");
else if (attr & ATTR_BLUE)
- pdfOut_printf(doc->pdf,"0 0 0.5 rg\n");
+ cfPDFOutPrintF(doc->pdf,"0 0 0.5 rg\n");
else
- pdfOut_printf(doc->pdf,"0 g\n");
+ cfPDFOutPrintF(doc->pdf,"0 g\n");
} else {
if ( (attr & ATTR_RED)||(attr & ATTR_GREEN)||(attr & ATTR_BLUE) )
- pdfOut_printf(doc->pdf,"0.2 g\n");
+ cfPDFOutPrintF(doc->pdf,"0.2 g\n");
else
- pdfOut_printf(doc->pdf,"0 g\n");
+ cfPDFOutPrintF(doc->pdf,"0 g\n");
}
}
else
- pdfOut_printf(doc->pdf,"0 g\n");
+ cfPDFOutPrintF(doc->pdf,"0 g\n");
write_font_str(x,y,attr & ATTR_FONT,s,len, doc);
}
if (len==-1) {
for (len=0;str[len].ch;len++);
}
- pdfOut_printf(doc->pdf,"BT\n");
+ cfPDFOutPrintF(doc->pdf,"BT\n");
if (x == (int)x)
- pdfOut_printf(doc->pdf," %.0f ", x);
+ cfPDFOutPrintF(doc->pdf," %.0f ", x);
else
- pdfOut_printf(doc->pdf," %.3f ", x);
+ cfPDFOutPrintF(doc->pdf," %.3f ", x);
if (y == (int)y)
- pdfOut_printf(doc->pdf,"%.0f Td\n", y);
+ cfPDFOutPrintF(doc->pdf,"%.0f Td\n", y);
else
- pdfOut_printf(doc->pdf,"%.3f Td\n", y);
+ cfPDFOutPrintF(doc->pdf,"%.3f Td\n", y);
int lastfont,font;
if (otf) // TODO?
{
- pdfOut_printf(doc->pdf," %.3f Tz\n",
+ cfPDFOutPrintF(doc->pdf," %.3f Tz\n",
doc->FontScaleX * 600.0 /
(otf_get_width(otf, 4) * 1000.0 /
otf->unitsPerEm) * 100.0 / (doc->FontScaleY)); // TODO?
}
else
{
- pdfOut_printf(doc->pdf," %.3f Tz\n",
+ cfPDFOutPrintF(doc->pdf," %.3f Tz\n",
doc->FontScaleX*100.0/(doc->FontScaleY)); // TODO?
}
- pdfOut_printf(doc->pdf," /%s%02x %.3f Tf <",
+ cfPDFOutPrintF(doc->pdf," /%s%02x %.3f Tf <",
names[fontid],lastfont,doc->FontScaleY);
while (len > 0)
if (otf) // TODO
{
const unsigned short gid=emb_get(emb,ch);
- pdfOut_printf(doc->pdf, "%04x", gid);
+ cfPDFOutPrintF(doc->pdf, "%04x", gid);
}
else // std 14 font with 7-bit us-ascii uses single byte encoding, TODO
{
- pdfOut_printf(doc->pdf, "%02x", ch);
+ cfPDFOutPrintF(doc->pdf, "%02x", ch);
}
len --;
str ++;
}
- pdfOut_printf(doc->pdf,"> Tj\n");
+ cfPDFOutPrintF(doc->pdf,"> Tj\n");
}
- pdfOut_printf(doc->pdf,"ET\n");
+ cfPDFOutPrintF(doc->pdf,"ET\n");
}
// }}}
static void write_pretty_header(texttopdf_doc_t *doc) // {{{
{
float x,y;
- pdfOut_printf(doc->pdf,"q\n"
+ cfPDFOutPrintF(doc->pdf,"q\n"
"0.9 g\n");
if (doc->Duplex && (doc->NumPages & 1) == 0)
y = doc->PageTop + 72.0f / (doc->LinesPerInch);
}
- pdfOut_printf(doc->pdf,"1 0 0 1 %.3f %.3f cm\n",x,y); // translate
- pdfOut_printf(doc->pdf,"0 0 %.3f %.3f re f\n",
+ cfPDFOutPrintF(doc->pdf,"1 0 0 1 %.3f %.3f cm\n",x,y); // translate
+ cfPDFOutPrintF(doc->pdf,"0 0 %.3f %.3f re f\n",
doc->PageRight - doc->PageLeft, 144.0f / (doc->LinesPerInch));
- pdfOut_printf(doc->pdf,"0 g 0 G\n");
+ cfPDFOutPrintF(doc->pdf,"0 g 0 G\n");
if (doc->Duplex && (doc->NumPages & 1) == 0)
{
write_font_str(x, y, ATTR_BOLD, pagestr, -1, doc);
free(pagestr);
- pdfOut_printf(doc->pdf, "Q\n");
+ cfPDFOutPrintF(doc->pdf, "Q\n");
}
// }}}
int main()
{
- pdfOut *pdf;
+ cf_pdf_out_t *pdf;
- pdf=pdfOut_new();
+ pdf=cfPDFOutNew();
assert(pdf);
- pdfOut_begin_pdf(pdf);
+ cfPDFOutBeginPDF(pdf);
// bad font
- int font_obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ int font_obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Font\n"
" /Subtype /Type1\n" // /TrueType,/Type3
" /BaseFont /%s\n"
,font_obj,"Courier");
// test
const int PageWidth=595,PageLength=842;
- int cobj=pdfOut_add_xref(pdf);
+ int cobj=cfPDFOutAddXRef(pdf);
const char buf[]="BT /a 10 Tf (abc) Tj ET";
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Length %d\n"
">>\n"
"stream\n"
"endobj\n"
,cobj,strlen(buf),buf);
- int obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ int obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Page\n"
" /Parent 1 0 R\n"
" /MediaBox [0 0 %d %d]\n"
">>\n"
"endobj\n"
,obj,PageWidth,PageLength,cobj,font_obj); // TODO: into pdf->
- pdfOut_add_page(pdf,obj);
- pdfOut_finish_pdf(pdf);
+ cfPDFOutAddPage(pdf,obj);
+ cfPDFOutFinishPDF(pdf);
- pdfOut_free(pdf);
+ cfPDFOutFree(pdf);
return 0;
}
#include <stdio.h>
-static inline void write_string(pdfOut *pdf,EMB_PARAMS *emb,const char *str) // {{{
+static inline void write_string(cf_pdf_out_t *pdf,EMB_PARAMS *emb,const char *str) // {{{
{
assert(pdf);
assert(emb);
emb_get(emb,(unsigned char)str[iA]);
// TODO: pdf: otf_from_pdf_default_encoding
}
- pdfOut_putString(pdf,str,-1);
+ cfPDFOutPutString(pdf,str,-1);
}
}
// }}}
int main()
{
- pdfOut *pdf;
+ cf_pdf_out_t *pdf;
- pdf=pdfOut_new();
+ pdf=cfPDFOutNew();
assert(pdf);
- pdfOut_begin_pdf(pdf);
+ cfPDFOutBeginPDF(pdf);
// font, pt.1
const char *fn=TESTFONT;
// test
const int PageWidth=595,PageLength=842;
- const int cobj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ const int cobj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Length %d 0 R\n"
">>\n"
"stream\n"
,cobj,cobj+1);
long streamlen=-pdf->filepos;
- pdfOut_printf(pdf,"BT /a 10 Tf ");
+ cfPDFOutPrintF(pdf,"BT /a 10 Tf ");
write_string(pdf,emb,"Test");
- pdfOut_printf(pdf," Tj ET");
+ cfPDFOutPrintF(pdf," Tj ET");
streamlen+=pdf->filepos;
- pdfOut_printf(pdf,"\nendstream\n"
+ cfPDFOutPrintF(pdf,"\nendstream\n"
"endobj\n");
- const int clobj=pdfOut_add_xref(pdf);
+ const int clobj=cfPDFOutAddXRef(pdf);
assert(clobj==cobj+1);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%d\n"
"endobj\n"
,clobj,streamlen);
// font
- int font_obj=pdfOut_write_font(pdf,emb);
+ int font_obj=cfPDFOutWriteFont(pdf,emb);
assert(font_obj);
- int obj=pdfOut_add_xref(pdf);
- pdfOut_printf(pdf,"%d 0 obj\n"
+ int obj=cfPDFOutAddXRef(pdf);
+ cfPDFOutPrintF(pdf,"%d 0 obj\n"
"<</Type/Page\n"
" /Parent 1 0 R\n"
" /MediaBox [0 0 %d %d]\n"
">>\n"
"endobj\n"
,obj,PageWidth,PageLength,cobj,font_obj); // TODO: into pdf->
- pdfOut_add_page(pdf,obj);
- pdfOut_finish_pdf(pdf);
+ cfPDFOutAddPage(pdf,obj);
+ cfPDFOutFinishPDF(pdf);
- pdfOut_free(pdf);
+ cfPDFOutFree(pdf);
emb_close(emb);