fontembed/aglfn13.c \
fontembed/dynstring.c \
fontembed/dynstring-private.h \
+ fontembed/debug-internal.h \
fontembed/embed.c \
fontembed/embed-sfnt.c \
fontembed/embed-sfnt-int-private.h \
cupsfilters/cmyk.c \
cupsfilters/colord.c \
cupsfilters/colormanager.c \
+ cupsfilters/debug.c \
+ cupsfilters/debug-internal.h \
cupsfilters/dither.c \
cupsfilters/filter.c \
cupsfilters/ghostscript.c \
--- /dev/null
+/*
+ * Internal debugging macros for libcupsfilters.
+ *
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2005 by Easy Software Products.
+ *
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
+ */
+
+#ifndef _CUPS_FILTERS_DEBUG_INTERNAL_H_
+# define _CUPS_FILTERS_DEBUG_INTERNAL_H_
+
+
+/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+
+/*
+ * The debug macros are used if you compile with DEBUG defined.
+ *
+ * Usage:
+ *
+ * DEBUG_puts("string");
+ * DEBUG_printf(("format string", arg, arg, ...));
+ * DEBUG_assert(boolean expression);
+ *
+ * Note the extra parenthesis around the DEBUG_printf macro...
+ */
+
+# ifdef DEBUG
+# include <assert.h>
+# define DEBUG_puts(x) _cf_debug_puts(x)
+# define DEBUG_printf(x) _cf_debug_printf x
+# define DEBUG_assert(x) assert(x)
+# else
+# define DEBUG_puts(x)
+# define DEBUG_printf(x)
+# define DEBUG_assert(x)
+# endif /* DEBUG */
+
+# ifdef DEBUG
+extern void _cf_debug_printf(const char *format, ...);
+extern void _cf_debug_puts(const char *s);
+# endif /* DEBUG */
+
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+
+#endif /* !_CUPS_FILTERS_DEBUG_INTERNAL_H_ */
--- /dev/null
+/*
+ * Debugging functions for cupsfilters.
+ *
+ * Copyright © 2008-2018 by Apple Inc.
+ *
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
+ */
+
+
+/*
+ * Include necessary headers...
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+
+/*
+ * '_cf_debug_printf()' - Write a formatted line to the log.
+ */
+
+void
+_cf_debug_printf(const char *format, /* I - Printf-style format string */
+ ...) /* I - Additional arguments as needed */
+{
+ va_list ap; /* Pointer to arguments */
+
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fflush(stderr);
+}
+
+
+/*
+ * '_cf_debug_puts()' - Write a single line to the log.
+ */
+
+void
+_cf_debug_puts(const char *s) /* I - String to output */
+{
+ fputs(s, stderr);
+ fflush(stderr);
+}
#include <sys/types.h>
#include <stdio.h>
#define NDEBUG
-#include <assert.h>
+#include "debug-internal.h"
#include <stdlib.h>
always (unless we get an error while reading the first char)
NUL-terminate the line buffer. */
- assert(*n - nchars_avail == read_pos - *lineptr);
+ DEBUG_assert(*n - nchars_avail == read_pos - *lineptr);
if (nchars_avail < 1)
{
if (*n > MIN_CHUNK)
if (!*lineptr)
return -1;
read_pos = *n - nchars_avail + *lineptr;
- assert(*n - nchars_avail == read_pos - *lineptr);
+ DEBUG_assert(*n - nchars_avail == read_pos - *lineptr);
}
if (c == EOF || ferror (stream))
#include <config.h>
#include "ieee1284.h"
+#include "debug-internal.h"
#include <cups/cups.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
-#define DEBUG_printf(x)
-#define DEBUG_puts(x)
/*
#include "intervalset-private.h"
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <limits>
#include <algorithm>
void _cfPDFToPDFIntervalSet::unite(value_t &aret,const value_t &b) const // {{{
{
- assert(intersect(aret,b));
+ DEBUG_assert(intersect(aret,b));
if (b.first<aret.first) {
aret.first=b.first;
}
#include "nup-private.h"
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <string.h>
#include <utility>
nup(param.nupX*param.nupY),
subpage(nup)
{
- assert( (param.nupX>0)&&(param.nupY>0) );
+ DEBUG_assert( (param.nupX>0)&&(param.nupY>0) );
}
// }}}
bool _cfPDFToPDFParseNupLayout(const char *val,_cfPDFToPDFNupParameters &ret) // {{{
{
- assert(val);
+ DEBUG_assert(val);
auto pos0=parsePosition(val[0],val[1]);
if (pos0.second==CENTER) {
return false;
#include "pdftopdf-processor-private.h"
#include "qpdf-pdftopdf-processor-private.h"
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <numeric>
void BookletMode_dump(pdftopdf_booklet_mode_e bkm,pdftopdf_doc_t *doc) // {{{
if (signature<0) {
signature=(numPages+3)&~0x3;
}
- assert(signature%4==0);
+ DEBUG_assert(signature%4==0);
std::vector<int> ret;
ret.reserve(numPages+signature-1);
#include <config.h>
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <cups/cups.h>
#if (CUPS_VERSION_MAJOR > 1) || (CUPS_VERSION_MINOR > 6)
#define HAVE_CUPS_1_7 1
static bool optGetInt(const char *name,int num_options,cups_option_t *options,int *ret) // {{{
{
- assert(ret);
+ DEBUG_assert(ret);
const char *val=cupsGetOption(name,num_options,options);
if (val) {
*ret=atoi(val);
static bool optGetFloat(const char *name,int num_options,cups_option_t *options,float *ret) // {{{
{
- assert(ret);
+ DEBUG_assert(ret);
const char *val=cupsGetOption(name,num_options,options);
if (val) {
*ret=atof(val);
static bool _cfPDFToPDFParseBorder(const char *val,pdftopdf_border_type_e &ret) // {{{
{
- assert(val);
+ DEBUG_assert(val);
if (strcasecmp(val,"none")==0) {
ret=pdftopdf_border_type_e::NONE;
} else if (strcasecmp(val,"single")==0) {
#include "pptypes-private.h"
#include <utility>
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_doc_t *doc) // {{{
{
void _cfPDFToPDFPositionDump(pdftopdf_position_e pos,pdftopdf_axis_e axis,pdftopdf_doc_t *doc) // {{{
{
- assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y));
+ DEBUG_assert((axis == pdftopdf_axis_e::X) || (axis == pdftopdf_axis_e::Y));
if ((pos < LEFT) || (pos > RIGHT)) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_DEBUG,
"cfFilterPDFToPDF: Position %s: (bad position: %d)",
if (mult==1.0) {
return;
}
- assert(mult!=0.0);
+ DEBUG_assert(mult!=0.0);
bottom*=mult;
left*=mult;
#include "qpdf-cm-private.h"
#include <stdio.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <stdexcept>
#include "qpdf-pdftopdf-processor-private.h"
#include <stdio.h>
#include <stdarg.h>
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <stdexcept>
#include <qpdf/QPDFWriter.hh>
#include <qpdf/QUtil.hh>
: no(0),
rotation(ROT_0)
{
- assert(pdf);
+ DEBUG_assert(pdf);
page=QPDFObjectHandle::parse(
"<<"
" /Type /Page"
// TODO? for non-existing (either drop comment or facility to create split streams needed)
void _cfPDFToPDFQPDFPageHandle::add_border_rect(const _cfPDFToPDFPageRect &_rect,pdftopdf_border_type_e border,float fscale) // {{{
{
- assert(is_existing());
- assert(border!=pdftopdf_border_type_e::NONE);
+ DEBUG_assert(is_existing());
+ DEBUG_assert(border!=pdftopdf_border_type_e::NONE);
// straight from pstops
const double lw=(border&THICK)?0.5:0.24;
_cfPDFToPDFPageRect rect=ungetRect(_rect,*this,rotation,page);
- assert(rect.left<=rect.right);
- assert(rect.bottom<=rect.top);
+ DEBUG_assert(rect.left<=rect.right);
+ DEBUG_assert(rect.bottom<=rect.top);
std::string boxcmd="q\n";
boxcmd+=" "+QUtil::double_to_string(line_width)+" w 0 G \n";
// return;
// }
- assert(page.getOwningQPDF()); // existing pages are always indirect
+ DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
#ifdef DEBUG // draw it on top
static const char *pre="%pdftopdf q\n"
"q\n",
void _cfPDFToPDFQPDFPageHandle::add_subpage(const std::shared_ptr<_cfPDFToPDFPageHandle> &sub,float xpos,float ypos,float scale,const _cfPDFToPDFPageRect *crop) // {{{
{
auto qsub=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(sub.get());
- assert(qsub);
+ DEBUG_assert(qsub);
std::string xoname="/X"+QUtil::int_to_string((qsub->no!=-1)?qsub->no:++no);
if (crop) {
// content.append(std::string("1 0 0 1 0 0 cm\n ");
content.append(xoname+" Do\n");
- assert(!is_existing());
+ DEBUG_assert(!is_existing());
}
static const char *pre="%pdftopdf cm\n";
void _cfPDFToPDFQPDFPageHandle::add_label(const _cfPDFToPDFPageRect &_rect, const std::string label) // {{{
{
- assert(is_existing());
+ DEBUG_assert(is_existing());
_cfPDFToPDFPageRect rect = ungetRect (_rect, *this, rotation, page);
boxcmd += "Q\n";
- assert(page.getOwningQPDF()); // existing pages are always indirect
+ DEBUG_assert(page.getOwningQPDF()); // existing pages are always indirect
static const char *pre="%pdftopdf q\n"
"q\n",
*post="%pdftopdf Q\n"
void _cfPDFToPDFQPDFPageHandle::debug(const _cfPDFToPDFPageRect &rect,float xpos,float ypos) // {{{
{
- assert(!is_existing());
+ DEBUG_assert(!is_existing());
content.append(debug_box(rect,xpos,ypos));
}
// }}}
void _cfPDFToPDFQPDFProcessor::start(int flatten_forms) // {{{
{
- assert(pdf);
+ DEBUG_assert(pdf);
if (flatten_forms) {
QPDFAcroFormDocumentHelper afdh(*pdf);
if (!pdf) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: No PDF loaded");
- assert(0);
+ DEBUG_assert(0);
return ret;
}
const int len=orig_pages.size();
if (!pdf) {
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_ERROR,
"cfFilterPDFToPDF: No PDF loaded");
- assert(0);
+ DEBUG_assert(0);
return std::shared_ptr<_cfPDFToPDFPageHandle>();
}
return std::shared_ptr<_cfPDFToPDFQPDFPageHandle>(new _cfPDFToPDFQPDFPageHandle(pdf.get(),width,height));
void _cfPDFToPDFQPDFProcessor::add_page(std::shared_ptr<_cfPDFToPDFPageHandle> page,bool front) // {{{
{
- assert(pdf);
+ DEBUG_assert(pdf);
auto qpage=dynamic_cast<_cfPDFToPDFQPDFPageHandle *>(page.get());
if (qpage) {
pdf->addPage(qpage->get(),front);
void _cfPDFToPDFQPDFProcessor::multiply(int copies,bool collate) // {{{
{
- assert(pdf);
- assert(copies>0);
+ DEBUG_assert(pdf);
+ DEBUG_assert(copies>0);
std::vector<QPDFObjectHandle> pages=pdf->getAllPages(); // need copy
const int len=pages.size();
// TODO? elsewhere?
void _cfPDFToPDFQPDFProcessor::auto_rotate_all(bool dst_lscape,pdftopdf_rotation_e normal_landscape) // {{{
{
- assert(pdf);
+ DEBUG_assert(pdf);
const int len=orig_pages.size();
for (int iA=0;iA<len;iA++) {
// TODO
void _cfPDFToPDFQPDFProcessor::add_cm(const char *defaulticc,const char *outputicc) // {{{
{
- assert(pdf);
+ DEBUG_assert(pdf);
if (_cfPDFToPDFHasOutputIntent(*pdf)) {
return; // nothing to do
extraheader.clear();
const int len=comments.size();
for (int iA=0;iA<len;iA++) {
- assert(comments[iA].at(0)=='%');
+ DEBUG_assert(comments[iA].at(0)=='%');
extraheader.append(comments[iA]);
extraheader.push_back('\n');
}
#include "qpdf-pdftopdf-private.h"
-#include <assert.h>
+#include "cupsfilters/debug-internal.h"
#include <stdexcept>
#include <qpdf/QUtil.hh>
ctm[1]=-ctm[1];
break;
default:
- assert(0);
+ DEBUG_assert(0);
}
return *this;
}
*
*/
#include <stdio.h>
-#include <assert.h>
+#include "debug-internal.h"
#include <stdarg.h>
#include <memory.h>
#include <stdlib.h>
void cfPDFOutPrintF(cf_pdf_out_t *pdf,const char *fmt,...) // {{{
{
- assert(pdf);
+ DEBUG_assert(pdf);
int len;
va_list ap;
void cfPDFOutPutString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
{
- assert(pdf);
- assert(str);
+ DEBUG_assert(pdf);
+ DEBUG_assert(str);
if (len==-1) {
len=strlen(str);
}
void cfPDFOutPutHexString(cf_pdf_out_t *pdf,const char *str,int len) // {{{ - >len==-1: strlen()
{
- assert(pdf);
- assert(str);
+ DEBUG_assert(pdf);
+ DEBUG_assert(str);
if (len==-1) {
len=strlen(str);
}
int cfPDFOutAddXRef(cf_pdf_out_t *pdf) // {{{ - returns obj_no
{
- assert(pdf);
- assert(pdf->xrefsize<=pdf->xrefalloc);
+ DEBUG_assert(pdf);
+ DEBUG_assert(pdf->xrefsize<=pdf->xrefalloc);
if (pdf->xrefsize==pdf->xrefalloc) {
long *tmp;
int cfPDFOutAddPage(cf_pdf_out_t *pdf,int obj) // {{{ - returns false on error
{
- assert(pdf);
- assert(obj>0);
- assert(pdf->pagessize<=pdf->pagesalloc);
+ DEBUG_assert(pdf);
+ DEBUG_assert(obj>0);
+ DEBUG_assert(pdf->pagessize<=pdf->pagesalloc);
if (pdf->pagessize==pdf->pagesalloc) {
int *tmp;
int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf,const char *key,const char *val) // {{{ - returns false on error
{
- assert(pdf);
- assert(pdf->kvsize<=pdf->kvalloc);
+ DEBUG_assert(pdf);
+ DEBUG_assert(pdf->kvsize<=pdf->kvalloc);
if (pdf->kvsize==pdf->kvalloc) {
struct cf_keyval_t *tmp;
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
+ DEBUG_assert(pdf);
+ DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
int pages_obj;
pdf->xrefsize=pdf->pagessize=0;
{
int iA;
int root_obj,info_obj=0,xref_start;
- assert( (pdf)&&(pdf->filepos!=-1) );
+ DEBUG_assert( (pdf)&&(pdf->filepos!=-1) );
// pages
const int pages_obj=1;
void cfPDFOutFree(cf_pdf_out_t *pdf) // {{{
{
if (pdf) {
- assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
+ DEBUG_assert(pdf->kvsize==0); // otherwise: finish_pdf has not been called
free(pdf->kv);
free(pdf->pages);
free(pdf->xref);
if (fwrite(buf,1,len,stdout)!=len) {
perror("Short write");
- assert(0);
+ DEBUG_assert(0);
return;
}
pdf->filepos+=len;
int cfPDFOutWriteFont(cf_pdf_out_t *pdf,EMB_PARAMS *emb) // {{{
{
- assert(pdf);
- assert(emb);
+ DEBUG_assert(pdf);
+ DEBUG_assert(emb);
EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
if (!fdes) {
"endobj\n");
const int l0_obj=cfPDFOutAddXRef(pdf);
- assert(l0_obj==ff_obj+1);
+ DEBUG_assert(l0_obj==ff_obj+1);
cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%ld\n"
"endobj\n"
if (emb->outtype==EMB_FMT_TTF) {
const int l1_obj=cfPDFOutAddXRef(pdf);
- assert(l1_obj==ff_obj+2);
+ DEBUG_assert(l1_obj==ff_obj+2);
cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%d\n"
"endobj\n"
* Include necessary headers...
*/
-#include <assert.h>
+#include "debug-internal.h"
#include <config.h>
#include "cupsfilters/pdfutils.h"
#include "cupsfilters/raster.h"
}
FONTFILE *ff = fontfile_open_sfnt(otf);
- assert(ff);
+ DEBUG_assert(ff);
EMB_PARAMS *emb = emb_new(ff,
EMB_DEST_PDF16,
EMB_C_FORCE_MULTIBYTE|
EMB_C_TAKE_FONTFILE);
- assert(emb);
- assert(emb->plan&EMB_A_MULTIBYTE);
+ DEBUG_assert(emb);
+ DEBUG_assert(emb->plan&EMB_A_MULTIBYTE);
return emb;
}
static EMB_PARAMS *font_std(const char *name)
{
FONTFILE *ff = fontfile_open_std(name);
- assert(ff);
+ DEBUG_assert(ff);
EMB_PARAMS *emb = emb_new(ff,
EMB_DEST_PDF16,
EMB_C_TAKE_FONTFILE);
- assert(emb);
+ DEBUG_assert(emb);
return emb;
}
(bits_used(emb->subset, emb->font->sfnt->numGlyphs)))
{
emb->font->fobj=cfPDFOutWriteFont(doc->pdf,emb);
- assert(emb->font->fobj);
+ DEBUG_assert(emb->font->fobj);
}
}
}
"endobj\n");
int len_obj=cfPDFOutAddXRef(doc->pdf);
- assert(len_obj==content+1);
+ DEBUG_assert(len_obj==content+1);
cfPDFOutPrintF(doc->pdf,"%d 0 obj\n"
"%ld\n"
"endobj\n",
* {{{ Output the PDF header...
*/
- assert(!(doc->pdf));
+ DEBUG_assert(!(doc->pdf));
doc->pdf = cfPDFOutNew();
- assert(doc->pdf);
+ DEBUG_assert(doc->pdf);
cfPDFOutBeginPDF(doc->pdf);
cfPDFOutPrintF(doc->pdf,"%%cupsRotation: %d\n",
#include <memory.h>
#include <ctype.h>
#include <stdarg.h>
-#include <assert.h>
#include <unistd.h>
#include <sys/wait.h>
#include <math.h>
jobparams_t * get_current_job()
{
- assert(job);
return job;
}
#include "util.h"
#include <stdlib.h>
#include <ctype.h>
-#include <assert.h>
#include <regex.h>
#include <string.h>
#include <math.h>
static choice_t * option_find_choice(option_t *opt, const char *name)
{
choice_t *choice;
- assert(opt && name);
+ if (!opt || !name)
+ return NULL;
for (choice = opt->choicelist; choice; choice = choice->next) {
if (!strcasecmp(choice->value, name))
return choice;
if (!opt->proto && !strcmp(opt->name, "PageSize"))
{
choice_t *choice = option_find_choice(opt, "Custom");
- char ** paramvalues = paramvalues_from_string(opt, values);
+ char **paramvalues = NULL;
char width[30], height[30];
int pos;
- assert(choice);
+ if (!choice)
+ return;
+
+ paramvalues = paramvalues_from_string(opt, values);
/* Get rid of the trailing ".00000", it confuses ghostscript */
snprintf(width, 20, "%d", atoi(paramvalues[0]));
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
-#include <assert.h>
#include <errno.h>
{
listitem_t *item;
- assert(list);
+ if (!list)
+ return;
item = malloc(sizeof(listitem_t));
item->data = data;
{
listitem_t *item;
- assert(list);
+ if (!list)
+ return;
item = malloc(sizeof(listitem_t));
item->data = data;
void list_remove(list_t *list, listitem_t *item)
{
- assert(item);
+ if (!list || !item)
+ return;
if (item->prev)
item->prev->next = item->next;
#include "pdfutils.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <string.h>
int main()
cf_pdf_out_t *pdf;
pdf=cfPDFOutNew();
- assert(pdf);
+ DEBUG_assert(pdf);
cfPDFOutBeginPDF(pdf);
#include "pdfutils.h"
#include "config.h"
-#include <assert.h>
+#include "debug-internal.h"
#include "fontembed/embed.h"
#include "fontembed/sfnt.h"
static inline void write_string(cf_pdf_out_t *pdf,EMB_PARAMS *emb,const char *str) // {{{
{
- assert(pdf);
- assert(emb);
+ DEBUG_assert(pdf);
+ DEBUG_assert(emb);
int iA;
if (emb->plan&EMB_A_MULTIBYTE) {
cf_pdf_out_t *pdf;
pdf=cfPDFOutNew();
- assert(pdf);
+ DEBUG_assert(pdf);
cfPDFOutBeginPDF(pdf);
printf("Font %s was not loaded, exiting.\n", TESTFONT);
return 1;
}
- assert(otf);
+ DEBUG_assert(otf);
FONTFILE *ff=fontfile_open_sfnt(otf);
EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
cfPDFOutPrintF(pdf,"\nendstream\n"
"endobj\n");
const int clobj=cfPDFOutAddXRef(pdf);
- assert(clobj==cobj+1);
+ DEBUG_assert(clobj==cobj+1);
cfPDFOutPrintF(pdf,"%d 0 obj\n"
"%ld\n"
"endobj\n"
// font
int font_obj=cfPDFOutWriteFont(pdf,emb);
- assert(font_obj);
+ DEBUG_assert(font_obj);
int obj=cfPDFOutAddXRef(pdf);
cfPDFOutPrintF(pdf,"%d 0 obj\n"
--- /dev/null
+/*
+ * Internal debugging macros for libfontembed.
+ *
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2005 by Easy Software Products.
+ *
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
+ */
+
+#ifndef _FONTEMBED_DEBUG_INTERNAL_H_
+# define _FONTEMBED_DEBUG_INTERNAL_H_
+
+
+/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+
+/*
+ * The debug macros are used if you compile with DEBUG defined.
+ *
+ * Usage:
+ *
+ * DEBUG_assert(boolean expression);
+ */
+
+# ifdef DEBUG
+# include <assert.h>
+# define DEBUG_assert(x) assert(x)
+# else
+# define DEBUG_assert(x)
+# endif /* DEBUG */
+
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+
+#endif /* !_FONTEMBED_DEBUG_INTERNAL_H_ */
#include "dynstring-private.h"
+#include "debug-internal.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
int dyn_init(DYN_STRING *ds,int reserve_size) // {{{
{
- assert(ds);
- assert(reserve_size>0);
+ DEBUG_assert(ds);
+ DEBUG_assert(reserve_size>0);
ds->len=0;
ds->alloc=reserve_size;
ds->buf=malloc(ds->alloc+1);
if (!ds->buf) {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
ds->len=-1;
return -1;
}
void dyn_free(DYN_STRING *ds) // {{{
{
- assert(ds);
+ DEBUG_assert(ds);
ds->len=-1;
ds->alloc=0;
int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
{
- assert(ds);
- assert(free_space);
+ DEBUG_assert(ds);
+ DEBUG_assert(free_space);
if (ds->len<0) {
return -1;
if (!tmp) {
ds->len=-1;
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
return -1;
}
ds->buf=tmp;
int dyn_vprintf(DYN_STRING *ds,const char *fmt,va_list ap) // {{{
{
- assert(ds);
+ DEBUG_assert(ds);
int need,len=strlen(fmt)+100;
va_list va;
#include "embed-pdf.h" // already included fron embed.h ...
#include "embed-pdf-int-private.h"
#include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <errno.h>
#include <string.h>
#include <time.h>
static const char *emb_pdf_escape_name(const char *name,int len) // {{{ // - statically allocated buffer
{
- assert(name);
+ DEBUG_assert(name);
if (len==-1) {
len=strlen(name);
}
- assert(len<=127); // pdf implementation limit
+ DEBUG_assert(len<=127); // pdf implementation limit
static char buf[128*3];
int iA,iB;
// this is in the font dict
const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
{
- assert(emb);
+ DEBUG_assert(emb);
return emb_pdf_font_subtype[emb->outtype][emb_multibyte(emb)];
}
// }}}
// in font descriptor
const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
{
- assert(emb);
+ DEBUG_assert(emb);
return emb_pdf_fontfile_key[emb->outtype];
}
// }}}
// this is what to put in the font-stream dict
const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
{
- assert(emb);
+ DEBUG_assert(emb);
return emb_pdf_fontfile_subtype[emb->outtype][emb_multibyte(emb)];
}
// }}}
const char *cid_ordering, // or supplement==-1
int cid_supplement) // -1 for non-cid
{
- assert(fontname);
+ DEBUG_assert(fontname);
EMB_PDF_FONTDESCR *ret;
int len=sizeof(EMB_PDF_FONTDESCR);
if (subset_tag) {
- assert(strlen(subset_tag)==6);
+ DEBUG_assert(strlen(subset_tag)==6);
len+=7;
}
len+=strlen(fontname)+1;
if (cid_supplement>=0) { // cid font
len+=12; // space for panose
- assert(cid_registry);
- assert(cid_ordering);
+ DEBUG_assert(cid_registry);
+ DEBUG_assert(cid_ordering);
len+=strlen(cid_registry)+1;
len+=strlen(cid_ordering)+1;
}
ret=calloc(1,len);
if (!ret) {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ - to be freed by user
{
- assert(emb);
+ DEBUG_assert(emb);
const char *subset_tag=NULL;
// {{{ generate pdf subtag
const char *fontname=NULL;
if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
- assert(emb->font->sfnt);
+ DEBUG_assert(emb->font->sfnt);
fontname=emb_otf_get_fontname(emb->font->sfnt);
} else if (emb->outtype==EMB_FMT_STDFONT) {
return NULL;
} else {
fprintf(stderr,"NOT IMPLEMENTED\n");
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
emb_otf_get_pdf_fontdescr(emb->font->sfnt,ret);
} else {
- assert(0);
+ DEBUG_assert(0);
}
return ret;
}
EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize) // {{{
{
- assert(datasize>=0);
+ DEBUG_assert(datasize>=0);
EMB_PDF_FONTWIDTHS *ret=calloc(1,sizeof(EMB_PDF_FONTWIDTHS)+datasize*sizeof(int));
if (!ret) {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
return ret;
// if default_width==-1: default_width will be estimated
EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default_width,int (*getGlyphWidth)(void *context,int gid),void *context) // {{{ glyphs==NULL -> output all
{
- assert(getGlyphWidth);
+ DEBUG_assert(getGlyphWidth);
FREQUENT *freq=NULL;
if (default_width<0) {
default_width=frequent_get(freq,0);
free(freq);
}
- assert(default_width>0);
+ DEBUG_assert(default_width>0);
// now create the array
EMB_PDF_FONTWIDTHS *ret=emb_pdf_fw_new(size+1);
// -> encoding has a "len"; len<256
EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
{
- assert(emb);
+ DEBUG_assert(emb);
if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
- assert(emb->font->sfnt);
+ DEBUG_assert(emb->font->sfnt);
if (emb->plan&EMB_A_MULTIBYTE) {
return emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset);
} else {
}
} else {
fprintf(stderr,"NOT IMPLEMENTED\n");
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
}
#define NEXT /* {{{ */ \
if ( (len<0)||(len>=size) ) { \
- assert(0); \
+ DEBUG_assert(0); \
free(ret); \
return NULL; \
} \
// TODO? /CIDSet TODO... /FontFamily /FontStretch /FontWeight (PDF1.5?) would be nice...
char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontfile_obj_ref) // {{{ - to be freed by user
{
- assert(emb);
- assert(fdes);
+ DEBUG_assert(emb);
+ DEBUG_assert(fdes);
char *ret=NULL,*pos;
int len,size;
len=snprintf(pos,size," /Style << /Panose <");
NEXT;
if (size<30) {
- assert(0);
+ DEBUG_assert(0);
free(ret);
return NULL;
}
char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref) // {{{ - to be freed by user
{
- assert(emb);
- assert(fdes);
- assert(fwid);
+ DEBUG_assert(emb);
+ DEBUG_assert(fdes);
+ DEBUG_assert(fwid);
int iA,iB;
DYN_STRING ret;
fontdescr_obj_ref);
if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
- assert(fwid->warray);
+ DEBUG_assert(fwid->warray);
dyn_printf(&ret," /CIDSystemInfo <<\n"
" /Registry (%s)\n"
" /Ordering (%s)\n"
dyn_printf(&ret,"]\n");
}
} else { // "not std14"
- assert(fwid->widths);
+ DEBUG_assert(fwid->widths);
dyn_printf(&ret,
" /Encoding /MacRomanEncoding\n" // optional; TODO!!!!!
// " /ToUnicode ?\n" // optional
dyn_printf(&ret,">>\n");
if (ret.len==-1) {
dyn_free(&ret);
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
// NOTE: this is _additionally_ to emb_pdf_simple_font()!
char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref) // {{{ - to be freed by user
{
- assert(emb);
- assert(fontname);
+ DEBUG_assert(emb);
+ DEBUG_assert(fontname);
char *ret=NULL,*pos;
int len,size;
char *emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
{
- assert(emb);
- assert(emb->font->stdname);
+ DEBUG_assert(emb);
+ DEBUG_assert(emb->font->stdname);
char *ret=NULL,*pos;
int len,size;
#include "embed-sfnt-int-private.h"
#include "sfnt.h"
#include "sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (os2) {
const unsigned short os2_version=get_USHORT(os2);
// check len
- assert( (os2_version!=0x0000)||(len==78) );
- assert( (os2_version!=0x0001)||(len==86) );
- assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
+ DEBUG_assert( (os2_version!=0x0000)||(len==78) );
+ DEBUG_assert( (os2_version!=0x0001)||(len==86) );
+ DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
if (os2_version<=0x0004) {
// get rights
unsigned short fsType=get_USHORT(os2+8);
// TODO
// ... fill in struct
char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
- assert(head); // version is 1.0 from otf_load
+ DEBUG_assert(head); // version is 1.0 from otf_load
ret->bbxmin=get_SHORT(head+36)*1000/otf->unitsPerEm;
ret->bbymin=get_SHORT(head+38)*1000/otf->unitsPerEm;
ret->bbxmax=get_SHORT(head+40)*1000/otf->unitsPerEm;
free(head);
char *post=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
- assert(post);
+ DEBUG_assert(post);
const unsigned int post_version=get_ULONG(post);
// check length
- assert( (post_version!=0x00010000)||(len==32) );
- assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
- assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
- assert( (post_version!=0x00030000)||(len==32) );
- assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
-// assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
+ DEBUG_assert( (post_version!=0x00010000)||(len==32) );
+ DEBUG_assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
+ DEBUG_assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
+ DEBUG_assert( (post_version!=0x00030000)||(len==32) );
+ DEBUG_assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
+// DEBUG_assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
// TODO: v4 (apple) : uint16 reencoding[numGlyphs]
if ( (post_version==0x00010000)||
(post_version==0x00020000)||
if (os2) {
const unsigned short os2_version=get_USHORT(os2);
// check len
- assert( (os2_version!=0x0000)||(len==78) );
- assert( (os2_version!=0x0001)||(len==86) );
- assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
+ DEBUG_assert( (os2_version!=0x0000)||(len==78) );
+ DEBUG_assert( (os2_version!=0x0001)||(len==86) );
+ DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
if (os2_version<=0x0004) {
// from PDF14Deltas.pdf, pg 113
const unsigned short d_gid=otf_from_unicode(otf,'.');
if (d_gid) { // stemV=bbox['.'].width;
len=otf_get_glyph(otf,d_gid);
- assert(len>=10);
+ DEBUG_assert(len>=10);
ret->stemV=(get_SHORT(otf->gly+6)-get_SHORT(otf->gly+2))*1000/otf->unitsPerEm;
} else {
if (macStyle&1) { // bold
// HINT: caller sets len == otf->numGlyphs (only when not using encoding...)
EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs) // {{{ glyphs==NULL -> all from 0 to len
{
- assert(otf);
+ DEBUG_assert(otf);
int first=len,last=0;
int iA;
const int gid=(encoding)?encoding[first]:otf_from_unicode(otf,first); // TODO
if (gid>=otf->numGlyphs) {
fprintf(stderr,"Bad glyphid\n");
- assert(0);
+ DEBUG_assert(0);
free(ret);
return NULL;
}
EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyphs) // {{{ // glyphs==NULL -> output all
{
- assert(otf);
+ DEBUG_assert(otf);
// ensure hmtx is there
if (!otf->hmtx) {
}
} else if (post_version==0x00020000) {
const unsigned short num_glyphs=get_USHORT(post+32);
- // assert(num_glyphs==otf->numGlyphs);
+ // DEBUG_assert(num_glyphs==otf->numGlyphs);
if (gid<num_glyphs) {
unsigned short idx=get_USHORT(post+34+2*gid);
if (idx<258) {
#include "embed.h"
#include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
static inline int copy_file(FILE *f,OUTPUT_FN output,void *context) // {{{
{
- assert(f);
- assert(output);
+ DEBUG_assert(f);
+ DEBUG_assert(output);
char buf[4096];
int iA,ret=0;
EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) // {{{
{
- assert(font);
+ DEBUG_assert(font);
EMB_PARAMS *ret=calloc(1,sizeof(EMB_PARAMS));
if (!ret) {
ret->intype=EMB_FMT_STDFONT;
ret->rights=EMB_RIGHT_NONE;
} else {
- assert(0);
+ DEBUG_assert(0);
}
/*
if ( (ret->intype==EMB_FMT_CFF)&&
int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
{
- assert(emb);
+ DEBUG_assert(emb);
if (emb->dest==EMB_DEST_NATIVE) {
} else if (emb->dest<=EMB_DEST_PS) {
}
} else if (emb->dest<=EMB_DEST_PDF16) {
if (emb->outtype==EMB_FMT_TTF) {
- assert(emb->font->sfnt);
+ DEBUG_assert(emb->font->sfnt);
if (emb->plan&EMB_A_SUBSET) {
return otf_subset(emb->font->sfnt,emb->subset,output,context);
} else if (emb->font->sfnt->numTTC) { //
if (emb->plan&EMB_A_T1_TO_CFF) {
// TODO
} else {
- // assert(emb->font->cff);
+ // DEBUG_assert(emb->font->cff);
// TODO
}
} else {
- assert(emb->font->sfnt);
+ DEBUG_assert(emb->font->sfnt);
if (emb->plan&EMB_A_SUBSET) {
return otf_subset_cff(emb->font->sfnt,emb->subset,output,context);
} else {
}
} else if (emb->outtype==EMB_FMT_CFF) {
if (emb->plan&EMB_A_OTF_TO_CFF) {
- assert(emb->font->sfnt);
+ DEBUG_assert(emb->font->sfnt);
if (emb->plan&EMB_A_SUBSET) {
// TODO
} else {
}
fprintf(stderr,"NOT IMPLEMENTED\n");
- assert(0);
+ DEBUG_assert(0);
return -1;
}
// }}}
#include "fontfile.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <string.h>
//FONTFILE *fontfile_open(const char *filename);
FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
{
if (!otf) {
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
FONTFILE *ret=calloc(1,sizeof(FONTFILE));
FONTFILE *fontfile_open_std(const char *name) // {{{
{
- assert(name);
+ DEBUG_assert(name);
FONTFILE *ret=calloc(1,sizeof(FONTFILE));
ret->stdname=strdup(name);
#include "frequent-private.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <stdlib.h>
// misra-gries
// size is the precision/return size: in sequence with n _add(), it will find at most >size elements with occurence > n/(size+1) times
FREQUENT *frequent_new(int size) // {{{ - just free() it
{
- assert(size>0);
+ DEBUG_assert(size>0);
FREQUENT *ret=malloc(sizeof(ret[0])+sizeof(ret->pair[0])*size);
if (!ret) {
return NULL;
void frequent_add(FREQUENT *freq,intptr_t key) // {{{
{
- assert(freq);
+ DEBUG_assert(freq);
int iA,zero=-1;
for (iA=freq->size-1;iA>=0;iA--) {
if (freq->pair[iA].key==key) {
// true frequency is somewhere between (count-zero) and count
intptr_t frequent_get(FREQUENT *freq,int pos) // {{{
{
- assert(freq);
+ DEBUG_assert(freq);
if (!freq->sorted) {
// sort by (count-zero)
qsort(freq->pair,freq->size,sizeof(freq->pair[0]),frequent_cmp);
#include "sfnt.h"
#include "sfnt-int-private.h"
+#include "bitset.h"
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
-#include "bitset.h"
int otf_ttc_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{
{
- assert(otf);
- assert(output);
- assert(otf->numTTC);
+ DEBUG_assert(otf);
+ DEBUG_assert(output);
+ DEBUG_assert(otf->numTTC);
int iA;
struct _OTF_WRITE *otw;
do {
flags=get_USHORT(cur);
const unsigned short sub_gid=get_USHORT(cur+2);
- assert(sub_gid<otf->numGlyphs);
+ DEBUG_assert(sub_gid<otf->numGlyphs);
if (!bit_check(glyphs,sub_gid)) {
// bad: temporarily load sub glyph
const int len=otf_get_glyph(otf,sub_gid);
- assert(len>0);
+ DEBUG_assert(len>0);
bit_set(glyphs,sub_gid);
if (sub_gid<donegid) {
ret+=len;
ret+=otf_subset_glyf(otf,sub_gid,donegid,glyphs); // composite of composites?, e.g. in DejaVu
}
- const int res=otf_get_glyph(otf,curgid); // reload current glyph
- assert(res);
+#ifdef DEBUG
+ const int res =
+#endif
+ otf_get_glyph(otf,curgid); // reload current glyph
+ DEBUG_assert(res);
}
// skip parameters
// TODO: cmap only required in non-CID context
int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
{
- assert(otf);
- assert(glyphs);
- assert(output);
+ DEBUG_assert(otf);
+ DEBUG_assert(glyphs);
+ DEBUG_assert(output);
int iA,b,c;
if (glyphs[b]&c) {
int len=otf_get_glyph(otf,iA);
if (len<0) {
- assert(0);
+ DEBUG_assert(0);
return -1;
} else if (len>0) {
glyfSize+=len;
len=otf_subset_glyf(otf,iA,iA,glyphs);
if (len<0) {
- assert(0);
+ DEBUG_assert(0);
return -1;
}
glyfSize+=len;
char *new_glyf=malloc(glyfSize);
if ( (!new_loca)||(!new_glyf) ) {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
free(new_loca);
free(new_glyf);
return -1;
c=1;
}
- assert(offset%2==0);
+ DEBUG_assert(offset%2==0);
// TODO? change format? if glyfSize<0x20000
if (otf->indexToLocFormat==0) {
set_USHORT(new_loca+iA*2,offset/2);
if (glyphs[b]&c) {
const int len=otf_get_glyph(otf,iA);
- assert(len>=0);
+ DEBUG_assert(len>=0);
memcpy(new_glyf+offset,otf->gly,len);
offset+=len;
}
} else { // ==1
set_ULONG(new_loca+otf->numGlyphs*4,offset);
}
- assert(offset==glyfSize);
+ DEBUG_assert(offset==glyfSize);
// determine new tables.
struct _OTF_WRITE otw[]={ // sorted
// TODO no subsetting actually done (for now)
int otf_subset_cff(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
{
- assert(otf);
- assert(output);
+ DEBUG_assert(otf);
+ DEBUG_assert(output);
// TODO char *new_cff=cff_subset(...);
static int copy_block(FILE *f,long pos,int length,OUTPUT_FN output,void *context) // {{{
{
- assert(f);
- assert(output);
+ DEBUG_assert(f);
+ DEBUG_assert(output);
char buf[4096];
int iA,ret;
int otf_cff_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
{
- assert(otf);
- assert(output);
+ DEBUG_assert(otf);
+ DEBUG_assert(output);
int idx=otf_find_table(otf,OTF_TAG('C','F','F',' '));
if (idx==-1) {
char *new_cff=malloc(cffSize);
if (!new_cff) {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- assert(0);
+ DEBUG_assert(0);
return -1;
}
#include "sfnt.h"
+#include "sfnt-int-private.h"
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
-#include "sfnt-int-private.h"
// TODO?
// get_SHORT(head+48) // fontDirectionHint
int *entrySelector,
int *rangeShift)
{
- assert(num>0);
- assert(searchRange);
- assert(entrySelector);
- assert(rangeShift);
+ DEBUG_assert(num>0);
+ DEBUG_assert(searchRange);
+ DEBUG_assert(entrySelector);
+ DEBUG_assert(rangeShift);
int iA,iB;
for (iA=1,iB=0;iA<=num;iA<<=1,iB++) {}
static OTF_FILE *otf_new(FILE *f) // {{{
{
- assert(f);
+ DEBUG_assert(f);
OTF_FILE *ret;
ret=calloc(1,sizeof(OTF_FILE));
if (length==0) {
return buf;
} else if (length<0) {
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
void otf_close(OTF_FILE *otf) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
if (otf) {
free(otf->gly);
free(otf->cmap);
return -1;
}
char target[]={(tag>>24),(tag>>16),(tag>>8),tag};
- // assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
+ // DEBUG_assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
char *result=otf_bsearch(tables,target,4,
get_USHORT(buf+6),
get_USHORT(buf+8),
char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len) // {{{
{
- assert(otf);
- assert(ret_len);
+ DEBUG_assert(otf);
+ DEBUG_assert(ret_len);
const int idx=otf_find_table(otf,tag);
if (idx==-1) {
int otf_load_glyf(OTF_FILE *otf) // {{{ - 0 on success
{
- assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
+ DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
int iA,len;
// {{{ find glyf table
iA=otf_find_table(otf,OTF_TAG('g','l','y','f'));
}
if (otf->glyphOffsets) {
free(otf->glyphOffsets);
- assert(0);
+ DEBUG_assert(0);
}
otf->glyphOffsets=malloc((otf->numGlyphs+1)*sizeof(unsigned int));
if (!otf->glyphOffsets) {
}
if (otf->gly) {
free(otf->gly);
- assert(0);
+ DEBUG_assert(0);
}
otf->gly=malloc(maxGlyfLen*sizeof(char));
if (!otf->gly) {
}
if (otf->hmtx) {
free(otf->hmtx);
- assert(0);
+ DEBUG_assert(0);
}
otf->hmtx=hmtx;
// }}}
}
if (otf->name) {
free(otf->name);
- assert(0);
+ DEBUG_assert(0);
}
otf->name=name;
// }}}
(get_USHORT(cmap)!=0x0000)|| // version
(len<get_USHORT(cmap+2)*8+4) ) {
fprintf(stderr,"Unsupported OTF font / cmap table \n");
- assert(0);
+ DEBUG_assert(0);
return -1;
}
// check bounds, find (3,0) or (3,1) [TODO?]
(offset+get_USHORT(ndata+2)>len) ) {
fprintf(stderr,"Bad cmap table \n");
free(cmap);
- assert(0);
+ DEBUG_assert(0);
return -1;
}
if ( (get_USHORT(nrec)==3)&&
}
if (otf->cmap) {
free(otf->cmap);
- assert(0);
+ DEBUG_assert(0);
}
otf->cmap=cmap;
int otf_get_width(OTF_FILE *otf,unsigned short gid) // {{{ -1 on error
{
- assert(otf);
+ DEBUG_assert(otf);
if (gid>=otf->numGlyphs) {
return -1;
const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languageID,int nameID,int *ret_len) // {{{
{
- assert(otf);
- assert(ret_len);
+ DEBUG_assert(otf);
+ DEBUG_assert(ret_len);
// ensure name is there
if (!otf->name) {
if (otf_load_more(otf)!=0) {
*ret_len=-1;
- assert(0);
+ DEBUG_assert(0);
return NULL;
}
}
int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly, returns length, -1 on error
{
- assert(otf);
- assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
+ DEBUG_assert(otf);
+ DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
if (gid>=otf->numGlyphs) {
return -1;
// ensure >glyphOffsets and >gly is there
if ( (!otf->gly)||(!otf->glyphOffsets) ) {
if (otf_load_more(otf)!=0) {
- assert(0);
+ DEBUG_assert(0);
return -1;
}
}
return 0;
}
- assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
+ DEBUG_assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
if (!otf_read(otf,otf->gly,
otf->glyfTable->offset+otf->glyphOffsets[gid],len)) {
return -1;
unsigned short otf_from_unicode(OTF_FILE *otf,int unicode) // {{{ 0 = missing
{
- assert(otf);
- assert( (unicode>=0)&&(unicode<65536) );
-// assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF, other method!
+ DEBUG_assert(otf);
+ DEBUG_assert( (unicode>=0)&&(unicode<65536) );
+// DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF, other method!
// ensure >cmap and >unimap is there
if (!otf->cmap) {
if (otf_load_cmap(otf)!=0) {
- assert(0);
+ DEBUG_assert(0);
return 0; // TODO?
}
}
get_USHORT(otf->unimap+10),
get_USHORT(otf->unimap+12),1);
if (result>=otf->unimap+14+segCountX2) { // outside of endCode[segCount]
- assert(0); // bad font, no 0xffff sentinel
+ DEBUG_assert(0); // bad font, no 0xffff sentinel
return 0;
}
{
OTF_FILE *otf=param;
const int table_no=otf_find_table(otf,OTF_TAG('h','e','a','d')); // we can't have csum AND table_no ... never mind!
- assert(table_no!=-1);
+ DEBUG_assert(table_no!=-1);
const OTF_DIRENT *table=otf->tables+table_no;
if (!output) { // get checksum and unpadded length
for (iA=0;iA<numTables;iA++) {
char *entry=start+12+16*order[iA];
const int res=(*otw[order[iA]].action)(otw[order[iA]].param,otw[order[iA]].length,NULL,&csum);
- assert(res>=0);
+ DEBUG_assert(res>=0);
if (otw[order[iA]].tag==OTF_TAG('h','e','a','d')) {
headAt=order[iA];
}
free(start);
return -1;
}
- assert(((res+3)&~3)==res); // correctly padded? (i.e. next line is just ret+=res;)
+ DEBUG_assert(((res+3)&~3)==res); // correctly padded? (i.e. next line is just ret+=res;)
ret+=(res+3)&~3;
}
- assert(offset==ret);
+ DEBUG_assert(offset==ret);
free(order);
free(start);
#include "embed.h"
#include "config.h"
#include "embed-sfnt-int-private.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
void show_post(OTF_FILE *otf) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
int len=0;
char *buf;
buf=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
if (!buf) {
- assert(len==-1);
+ DEBUG_assert(len==-1);
printf("No post table\n");
return;
}
void show_name(OTF_FILE *otf) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
int iA,len=0;
char *buf;
buf=otf_get_table(otf,OTF_TAG('n','a','m','e'),&len);
if (!buf) {
- assert(len==-1);
+ DEBUG_assert(len==-1);
printf("No name table\n");
return;
}
void show_cmap(OTF_FILE *otf) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
int iA,len=0;
char *cmap=otf_get_table(otf,OTF_TAG('c','m','a','p'),&len);
if (!cmap) {
- assert(len==-1);
+ DEBUG_assert(len==-1);
printf("No cmap table\n");
return;
}
printf("cmap:\n");
- assert(get_USHORT(cmap)==0x0000); // version
+ DEBUG_assert(get_USHORT(cmap)==0x0000); // version
const int numTables=get_USHORT(cmap+2);
printf(" numTables: %d\n",numTables);
for (iA=0;iA<numTables;iA++) {
const char *nrec=cmap+4+8*iA;
const char *ndata=cmap+get_ULONG(nrec+4);
- assert(ndata>=cmap+4+8*numTables);
+ DEBUG_assert(ndata>=cmap+4+8*numTables);
printf(" platformID/encodingID: %d/%d\n"
" offset: %d data (format: %d, length: %d, language: %d);\n",
get_USHORT(nrec),get_USHORT(nrec+2),
void show_glyf(OTF_FILE *otf,int full) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
// ensure >glyphOffsets and >gly is there
if ( (!otf->gly)||(!otf->glyphOffsets) ) {
if (otf_load_glyf(otf)!=0) {
- assert(0);
+ DEBUG_assert(0);
return;
}
}
int compGlyf=0,zeroGlyf=0;
// {{{ glyf
- assert(otf->gly);
+ DEBUG_assert(otf->gly);
for (iA=0;iA<otf->numGlyphs;iA++) {
int len=otf_get_glyph(otf,iA);
if (len==0) {
void show_hmtx(OTF_FILE *otf) // {{{
{
- assert(otf);
+ DEBUG_assert(otf);
int iA;
otf_get_width(otf,0); // load table.
return 1;
}
- assert(otf);
+ DEBUG_assert(otf);
if (otf->numTTC) {
printf("TTC has %d fonts, using %d\n",otf->numTTC,otf->useTTC);
}
#include "embed.h"
#include "config.h"
#include "sfnt.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
FILE *f=(FILE *)context;
if (fwrite(buf,1,len,f)!=len) {
fprintf(stderr,"Short write: %m\n");
- assert(0);
+ DEBUG_assert(0);
return;
}
}
static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
{
- assert(f);
- assert(emb);
+ DEBUG_assert(f);
+ DEBUG_assert(emb);
int iA;
if (emb->plan&EMB_A_MULTIBYTE) {
printf("Font %s was not loaded, exiting.\n", TESTFONT);
return 1;
}
- assert(otf);
+ DEBUG_assert(otf);
FONTFILE *ff=fontfile_open_sfnt(otf);
EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
EMB_C_TAKE_FONTFILE);
FILE *f=fopen("test.pdf","w");
- assert(f);
+ DEBUG_assert(f);
int xref[100],xrefpos=3;
int stream_len;
// {{{ do font
EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
- assert(fdes);
+ DEBUG_assert(fdes);
EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
- assert(fwid);
+ DEBUG_assert(fwid);
STREAMDICT;
int ff_ref=xrefpos;
OBJ;
const int fd_ref=xrefpos;
char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_ref);
- assert(res);
+ DEBUG_assert(res);
fputs(res,f);
free(res);
ENDOBJ;
OBJ;
int f_ref=xrefpos;
res=emb_pdf_simple_font(emb,fdes,fwid,fd_ref);
- assert(res);
+ DEBUG_assert(res);
fputs(res,f);
free(res);
ENDOBJ;
OBJ;
res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_ref);
f_ref=xrefpos;
- assert(res);
+ DEBUG_assert(res);
fputs(res,f);
free(res);
ENDOBJ;
#include "embed.h"
#include "config.h"
#include "sfnt.h"
-#include <assert.h>
+#include "debug-internal.h"
#include <stdio.h>
#include <stdlib.h>
FILE *f=(FILE *)context;
if (fwrite(buf,1,len,f)!=len) {
fprintf(stderr,"Short write: %m\n");
- assert(0);
+ DEBUG_assert(0);
return;
}
}
static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
{
- assert(f);
- assert(emb);
+ DEBUG_assert(f);
+ DEBUG_assert(emb);
int iA;
if (emb->plan&EMB_A_MULTIBYTE) {
printf("Font %s was not loaded, exiting.\n", TESTFONT);
return 1;
}
- assert(otf);
+ DEBUG_assert(otf);
FONTFILE *ff=fontfile_open_sfnt(otf);
EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PS,
EMB_C_TAKE_FONTFILE);
FILE *f=fopen("test.ps","w");
- assert(f);
+ DEBUG_assert(f);
fprintf(f,"%%!PS-Adobe-2.0\n");
*/
# ifdef DEBUG
+# include <assert.h>
# define DEBUG_puts(x) _ppd_debug_puts(x)
# define DEBUG_printf(x) _ppd_debug_printf x
+# define DEBUG_assert(x) assert(x)
# else
# define DEBUG_puts(x)
# define DEBUG_printf(x)
+# define DEBUG_assert(x)
# endif /* DEBUG */
* Globals...
*/
-static int _ppd_debug_fd = -1;
+int _ppd_debug_fd = -1;
/* Debug log file descriptor */
-static int _ppd_debug_level = 1;
+int _ppd_debug_level = 1;
/* Log level (0 to 9) */
static regex_t *debug_filter = NULL;
/* Filter expression for messages */
static int debug_init = 0; /* Did we initialize debugging? */
-static _ppd_mutex_t debug_init_mutex = _PPD_MUTEX_INITIALIZER,
- /* Mutex to control initialization */
- debug_log_mutex = _PPD_MUTEX_INITIALIZER;
- /* Mutex to serialize log entries */
/*
{
int result; /* Filter result */
- _ppdMutexLock(&debug_init_mutex);
result = regexec(debug_filter, format, 0, NULL, 0);
- _ppdMutexUnlock(&debug_init_mutex);
if (result)
return;
* Write it out...
*/
- _ppdMutexLock(&debug_log_mutex);
write(_ppd_debug_fd, buffer, (size_t)bytes);
- _ppdMutexUnlock(&debug_log_mutex);
}
{
int result; /* Filter result */
- _ppdMutexLock(&debug_init_mutex);
result = regexec(debug_filter, s, 0, NULL, 0);
- _ppdMutexUnlock(&debug_init_mutex);
if (result)
return;
* Write it out...
*/
- _ppdMutexLock(&debug_log_mutex);
write(_ppd_debug_fd, buffer, (size_t)bytes);
- _ppdMutexUnlock(&debug_log_mutex);
}
const char *filter, /* I - Filter string or NULL */
int force) /* I - Force initialization */
{
- _ppdMutexLock(&debug_init_mutex);
if (!debug_init || force)
{
debug_init = 1;
}
- _ppdMutexUnlock(&debug_init_mutex);
}
#ifdef DEBUG
if (attr)
DEBUG_printf(("1ppdCacheGetPageSize: Found attribute %s (%s)",
- attr->name, ippTagString(attr->value_tag)));
+ ippGetName(attr), ippTagString(ippGetValueTag(attr))));
else
DEBUG_puts("1ppdCacheGetPageSize: Did not find media attribute.");
#endif /* DEBUG */
ll_CC);
else
{
- snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword);
+ snprintf(ckeyword, sizeof(ckeyword), "Custom%.34s", option->keyword);
locattr = ppdLocalizedAttr(ppd, ckeyword, "True", ll_CC);
}
fabs(header->PageSize[0] - size->right + size->left) / size->width < 0.01 &&
(size_matched == NULL || !strcasecmp(pageSizeRequested, size->name)))
{
- DEBUG_printf("Imageable area fit");
+ DEBUG_puts("Imageable area fit\n");
size_matched = size;
if (landscape) *landscape = 0;
if (image_fit) *image_fit = 1;
fabs(header->PageSize[1] - size->right + size->left) / size->width < 0.01 &&
(size_matched == NULL || !strcasecmp(pageSizeRequested, size->name)))
{
- DEBUG_printf("Imageable area fit");
+ DEBUG_puts("Imageable area fit\n");
size_matched = size;
if (landscape) *landscape = 1;
if (image_fit) *image_fit = 1;
/*
* Custom size...
*/
- DEBUG_printf("size = Custom");
+ DEBUG_puts("size = Custom\n");
for (i = 0; i < 2; i ++)
dimensions[i] = header->PageSize[i];
for (i = 0; i < 4; i ++)
#include <string.h>
#include <limits.h>
#include <signal.h>
-#include <assert.h>
+#include "debug-internal.h"
#include <zlib.h>
/*
ret = deflate(&strm, flush);
/* check whether state is not clobbered */
- assert(ret != Z_STREAM_ERROR);
+ DEBUG_assert(ret != Z_STREAM_ERROR);
have = alloc - strm.avail_out;
if (fwrite(out, 1, have, doc->outputfp) != have)
{
} while (strm.avail_out == 0);
/* all input will be used */
- assert(strm.avail_in == 0);
+ DEBUG_assert(strm.avail_in == 0);
/* done when last data in file processed */
free(pixdata);
} while (flush != Z_FINISH);
/* stream will be complete */
- assert(ret == Z_STREAM_END);
+ DEBUG_assert(ret == Z_STREAM_END);
/* clean up and return */
(void)deflateEnd(&strm);
strcasestr(pdl, "image/"))) {
value[0] = '\0';
if (strcasestr(pdl, "application/pdf"))
- strncat(value, ",PDF", sizeof(value));
+ strncat(value, ",PDF", sizeof(value) - 1);
if (strcasestr(pdl, "application/PCLm"))
- strncat(value, ",PCLM", sizeof(value));
+ strncat(value, ",PCLM", sizeof(value) - 1);
if (strcasestr(pdl, "application/postscript"))
- strncat(value, ",PS", sizeof(value));
+ strncat(value, ",PS", sizeof(value) - 1);
if (strcasestr(pdl, "application/vnd.hp-PCL"))
- strncat(value, ",PCL", sizeof(value));
+ strncat(value, ",PCL", sizeof(value) - 1);
if (strcasestr(pdl, "image/pwg-raster"))
- strncat(value, ",PWGRaster", sizeof(value));
+ strncat(value, ",PWGRaster", sizeof(value) - 1);
if (strcasestr(pdl, "image/urf"))
- strncat(value, ",AppleRaster", sizeof(value));
+ strncat(value, ",AppleRaster", sizeof(value) - 1);
for (ptr = strcasestr(pdl, "image/"); ptr;
ptr = strcasestr(ptr, "image/")) {
char *valptr = value + strlen(value);