nyctergatis.com

Contact

Projects
Sysquake Remote Live
NME
PDF
Hike
Sudoku
GifBuilder
jpeglib for Palm OS
MySQL Client
Cross-GCC for Mac OS

NPWBase.c File Reference

NPW (base functions to write PDF files). More...

#include "NPWBase.h"
#include <math.h>

Go to the source code of this file.


Defines

#define kHeaderStr   "%PDF-1.5\n"
 PDF header string.
#define Chk(e)
 Check error returned by a function and returns it unless kNPWErrOk.
#define ChkG(e)
 Check error returned by a function and goto error unless kNPWErrOk.
#define kDigits   8
 maximum number of digits
#define hex(n)   ((n) >= 10 ? 'a' - 10 + (n) : '0' + (n))
 Convert a value in [0,15] to its ASCII hexadecimal representation.
#define kRLEOD   128
 end of data

Functions

void NPWInit (NPW *pdf)
 Initialize PDF.
void NPWSetAllocCallback (NPW *pdf, NPWAllocCB alloc, void *userData)
 Set memory allocation callback.
void NPWSetWriteCallback (NPW *pdf, NPWWriteCB write, void *userData)
 Set write callback.
void NPWSetFonts (NPW *pdf, NPWInt fonts)
 Specify which standard fonts should be made available.
NPWErr NPWWrite (NPW *pdf, NPWConstText str, NPWInt length)
 Write a string.
NPWErr NPWWriteInt (NPW *pdf, NPWInt i, NPWInt pad)
 Write an integer.
NPWErr NPWWriteFloat (NPW *pdf, NPWFloat x)
 Write an floating-point value.
NPWErr NPWWriteString (NPW *pdf, NPWConstText str, NPWInt length)
 Write a string value (should be ISO Latin 1 to match encoding set for standard fonts).
static void RLInit (RLState *rl)
 Initialize run-length filter state.
static NPWByte RLNextByte (RLState *rl, NPWByte const *b, NPWInt len)
 Get next output byte of run-length filtered stream.
void NPWFilterBegin (NPW *pdf, NPWInt filter)
 Begin writing filtered data to PDF.
static NPWErr writeA85 (NPW *pdf, NPWByte const b[], NPWInt n, NPWBoolean end)
 Write 4 bytes, or less if last bytes of stream, encoded with base-85.
static NPWErr writeAHex (NPW *pdf, NPWByte b)
 Write a byte as ASCII hexadecimal.
NPWErr NPWFilterWrite (NPW *pdf, NPWByte const *b, NPWInt n)
 Write filtered data to PDF.
NPWErr NPWFilterEnd (NPW *pdf)
 End writing filtered data to PDF.
static NPWErr addXRef (NPW *pdf)
 Add an entry to the cross-reference table.
static NPWErr reserveXRef (NPW *pdf, NPWRef *ref)
 Reserve an entry in the cross-reference table.
static NPWErr writeHeader (NPW *pdf)
 Write PDF header.
NPWErr NPWBeginObj (NPW *pdf, NPWRef *ref)
 Begin writing an object.
static NPWErr beginReservedObj (NPW *pdf, NPWRef *ref)
 Write the beginning of an object with the last xref obtained with reserveXRef.
NPWErr NPWEndObj (NPW *pdf)
 End writing an object.
static NPWErr writePage (NPW *pdf, NPWInt i, NPWRef parent, NPWRef *ref)
static NPWErr writePages (NPW *pdf, NPWRef *ref)
static NPWErr writeCatalog (NPW *pdf, NPWRef pages, NPWRef *ref)
 Write PDF catalog.
NPWErr NPWBeginPage (NPW *pdf, NPWInt width, NPWInt height)
 Beginning of page.
NPWErr NPWEndPage (NPW *pdf)
 End of page.
NPWErr NPWTerminate (NPW *pdf)
 Terminate PDF and flush output.

Detailed Description

NPW (base functions to write PDF files).

Author:
Yves Piguet. Copyright 2008-2010, Yves Piguet.

Definition in file NPWBase.c.


Define Documentation

#define Chk (  ) 

Value:

do { \
        err = (e); \
        if (err != kNPWErrOk) \
            return err; \
    } while (0)
Check error returned by a function and returns it unless kNPWErrOk.

Definition at line 19 of file NPWBase.c.

#define ChkG (  ) 

Value:

do { \
        err = (e); \
        if (err != kNPWErrOk) \
            goto error; \
    } while (0)
Check error returned by a function and goto error unless kNPWErrOk.

Definition at line 27 of file NPWBase.c.


Function Documentation

static NPWErr addXRef ( NPW pdf  )  [static]

Add an entry to the cross-reference table.

Parameters:
pdf reference to NPW structure

Definition at line 423 of file NPWBase.c.

static NPWErr beginReservedObj ( NPW pdf,
NPWRef ref 
) [static]

Write the beginning of an object with the last xref obtained with reserveXRef.

Parameters:
pdf reference to NPW structure
[out] ref 
Returns:
kNPWErrOk for success, else error code

Definition at line 504 of file NPWBase.c.

NPWErr NPWBeginObj ( NPW pdf,
NPWRef ref 
)

Begin writing an object.

Parameters:
pdf reference to NPW structure
[out] ref object reference number
Returns:
error code (kNPWErrOk for success)

Definition at line 482 of file NPWBase.c.

NPWErr NPWBeginPage ( NPW pdf,
NPWInt  width,
NPWInt  height 
)

Beginning of page.

Parameters:
pdf reference to NPW structure
[in] width page width
[in] height page height
Returns:
error code (kNPWErrOk for success)

Definition at line 692 of file NPWBase.c.

NPWErr NPWEndObj ( NPW pdf  ) 

End writing an object.

Parameters:
pdf reference to NPW structure
Returns:
error code (kNPWErrOk for success)

Definition at line 526 of file NPWBase.c.

NPWErr NPWEndPage ( NPW pdf  ) 

End of page.

Parameters:
pdf reference to NPW structure
Returns:
error code (kNPWErrOk for success)

Definition at line 730 of file NPWBase.c.

void NPWFilterBegin ( NPW pdf,
NPWInt  filter 
)

Begin writing filtered data to PDF.

Parameters:
pdf reference to NPW structure
[in] filter (kNPWFilterNone for none)

Definition at line 303 of file NPWBase.c.

NPWErr NPWFilterEnd ( NPW pdf  ) 

End writing filtered data to PDF.

Parameters:
pdf reference to NPW structure
Returns:
error code (kNPWErrOk for success)

Definition at line 412 of file NPWBase.c.

NPWErr NPWFilterWrite ( NPW pdf,
NPWByte const *  b,
NPWInt  n 
)

Write filtered data to PDF.

Parameters:
pdf reference to NPW structure
[in] b address of unfiltered data
[in] n number of unfiltered bytes
Returns:
error code (kNPWErrOk for success)

Definition at line 355 of file NPWBase.c.

void NPWInit ( NPW pdf  ) 

Initialize PDF.

Parameters:
[out] pdf reference to NPW structure

Definition at line 39 of file NPWBase.c.

void NPWSetAllocCallback ( NPW pdf,
NPWAllocCB  alloc,
void *  userData 
)

Set memory allocation callback.

Parameters:
pdf reference to NPW structure
[in] alloc memory allocation callback
[in] userData callback user data

Definition at line 55 of file NPWBase.c.

void NPWSetFonts ( NPW pdf,
NPWInt  fonts 
)

Specify which standard fonts should be made available.

Parameters:
pdf reference to NPW structure
[in] fonts font flags (kNPWFontAll for all)

Definition at line 69 of file NPWBase.c.

void NPWSetWriteCallback ( NPW pdf,
NPWWriteCB  write,
void *  userData 
)

Set write callback.

Parameters:
pdf reference to NPW structure
[in] write allocation callback
[in] userData callback user data

Definition at line 62 of file NPWBase.c.

NPWErr NPWTerminate ( NPW pdf  ) 

Terminate PDF and flush output.

Parameters:
pdf reference to NPW structure
Returns:
kNPWErrOk for success, else error code

Definition at line 748 of file NPWBase.c.

NPWErr NPWWrite ( NPW pdf,
NPWConstText  str,
NPWInt  length 
)

Write a string.

Parameters:
pdf reference to NPW structure
[in] str address of first character
[in] length number of bytes, or -1 if str is null-terminated
Returns:
error code (kNPWErrOk for success)

Definition at line 74 of file NPWBase.c.

NPWErr NPWWriteFloat ( NPW pdf,
NPWFloat  x 
)

Write an floating-point value.

Parameters:
pdf reference to NPW structure
[in] x number
Returns:
error code (kNPWErrOk for success)

Definition at line 124 of file NPWBase.c.

NPWErr NPWWriteInt ( NPW pdf,
NPWInt  i,
NPWInt  pad 
)

Write an integer.

Parameters:
pdf reference to NPW structure
[in] i number
[in] pad number of digits (0-padded), or -1
Returns:
error code (kNPWErrOk for success)

Definition at line 87 of file NPWBase.c.

NPWErr NPWWriteString ( NPW pdf,
NPWConstText  str,
NPWInt  length 
)

Write a string value (should be ISO Latin 1 to match encoding set for standard fonts).

Parameters:
pdf reference to NPW structure
[in] str string
[in] length string length in bytes, or -1 for null-terminated string
Returns:
error code (kNPWErrOk for success)

Definition at line 167 of file NPWBase.c.

static NPWErr reserveXRef ( NPW pdf,
NPWRef ref 
) [static]

Reserve an entry in the cross-reference table.

Parameters:
pdf reference to NPW structure
[out] ref object reference

Definition at line 449 of file NPWBase.c.

static void RLInit ( RLState *  rl  )  [static]

Initialize run-length filter state.

Parameters:
[out] rl run-length filter state

Definition at line 239 of file NPWBase.c.

static NPWByte RLNextByte ( RLState *  rl,
NPWByte const *  b,
NPWInt  len 
) [static]

Get next output byte of run-length filtered stream.

Parameters:
[in,out] rl run-length filter state
[in] b input data
[in] len number of bytes in b
Returns:
output byte

Definition at line 254 of file NPWBase.c.

static NPWErr writeA85 ( NPW pdf,
NPWByte const   b[],
NPWInt  n,
NPWBoolean  end 
) [static]

Write 4 bytes, or less if last bytes of stream, encoded with base-85.

Parameters:
pdf reference to NPW structure
[in] b bytes
[in] n number of bytes (1-4)
[in] end TRUE to write the end marker
Returns:
error code (kNPWErrOk for success)

Definition at line 317 of file NPWBase.c.

static NPWErr writeAHex ( NPW pdf,
NPWByte  b 
) [static]

Write a byte as ASCII hexadecimal.

Parameters:
pdf reference to NPW structure
[in] b byte
Returns:
error code (kNPWErrOk for success)

Definition at line 346 of file NPWBase.c.

static NPWErr writeCatalog ( NPW pdf,
NPWRef  pages,
NPWRef ref 
) [static]

Write PDF catalog.

Parameters:
pdf reference to NPW structure
[in] pages reference of the Pages object
[out] ref reference of the PDF catalog
Returns:
error code (kNPWErrOk for success)

Definition at line 680 of file NPWBase.c.

static NPWErr writeHeader ( NPW pdf  )  [static]

Write PDF header.

Parameters:
pdf reference to NPW structure
Returns:
kNPWErrOk for success, else error code

Definition at line 477 of file NPWBase.c.

static NPWErr writePage ( NPW pdf,
NPWInt  i,
NPWRef  parent,
NPWRef ref 
) [static]

< TRUE iff all pages have the same size inherited from Pages

Definition at line 534 of file NPWBase.c.

static NPWErr writePages ( NPW pdf,
NPWRef ref 
) [static]

< TRUE iff all pages have the same size

Definition at line 567 of file NPWBase.c.

Generated by Doxygen.
Copyright 2007-2010, Yves Piguet.
All rights reserved.