en fr

nyctergatis.com

NPWBase.h File Reference

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

Go to the source code of this file.

Data Structures

struct  NPWXRef
 Cross-reference description. More...
struct  NPWPage
 Page description. More...
struct  NPWActionCBData
 Callback and user data for performing an action. More...
struct  NPW_struct
 NPW main structure. More...

Defines

#define NULL   0
 null pointer
#define FALSE   0
 false boolean value
#define TRUE   1
 true boolean value
#define kNPWUnitMM   2.835
 conversion factor from mm to pt
#define kNPWUnitCM   28.35
 conversion factor from cm to pt
#define kNPWUnitInch   72
 conversion factor from inch to pt
#define NPWFilterNameASCIIHex   "/AHx"
 hexadecimal filter name
#define NPWFilterNameASCII85   "/A85"
 base-85 filter name
#define NPWFilterNameRunLength   "/RL"
 run-length filter name
#define NPWFilterNameDCT   "/DCT"
 DCT filter name (JPEG)
#define NPWFontNameCourier   "/FC"
 Courier font name.
#define NPWFontNameCourierOblique   "/FCo"
 Courier Oblique font name.
#define NPWFontNameCourierBold   "/FCb"
 Courier Bold font name.
#define NPWFontNameCourierBoldOblique   "/FCbo"
 Courier Bold Oblique font name.
#define NPWFontNameHelvetica   "/FH"
 Helvetica font name.
#define NPWFontNameHelveticaOblique   "/FHo"
 Helvetica Oblique font name.
#define NPWFontNameHelveticaBold   "/FHb"
 Helvetica Bold font name.
#define NPWFontNameHelveticaBoldOblique   "/FHbo"
 Helvetica Bold Oblique font name.
#define NPWFontNameTimesRoman   "/FT"
 Times Roman font name.
#define NPWFontNameTimesItalic   "/FTi"
 Time Italic font name.
#define NPWFontNameTimesBold   "/FTb"
 Times Bold font name.
#define NPWFontNameTimesBoldItalic   "/FTbi"
 Times Bold Italic font name.
#define NPWFontNameSymbol   "/FS"
 Symbol font name.
#define NPWFontNameZapfDingbats   "/FZ"
 Zapf Dingbats font name.

Typedefs

typedef char NPWChar
 Character (8-bit; processing possible with compatible charsets like UTF-8 or Shift-JIS)
typedef NPWCharNPWText
 Text.
typedef NPWChar const * NPWConstText
 Constant text.
typedef int NPWInt
 Integer.
typedef NPWInt NPWRef
 Object reference.
typedef NPWInt NPWOffset
 Offset in PDF file.
typedef unsigned char NPWByte
 Unsigned 8-bit integer.
typedef unsigned long NPWUInt32
 Unsigned 32-bit integer.
typedef short PDFInt16
 Signed 16-bit integer.
typedef double NPWFloat
 Floating-point number.
typedef int NPWBoolean
 Boolean.
typedef NPWErr(* NPWWriteCB )(NPWConstText str, NPWInt length, void *userData)
 Callback to write data to PDF file.
typedef NPWErr(* NPWAllocCB )(void **p, NPWInt size, void *userData)
 Callback to allocate, resize or free block of memory.
typedef NPWErr(* NPWActionCB )(struct NPW_struct *pdf, void *userData)
 Callback to perform some action.
typedef struct NPW_struct NPW
 NPW main structure.

Enumerations

enum  { kNPWNoRef = -1 }
 Special references. More...
enum  NPWErr {
  kNPWErrOk = 0, kNPWErrNotEnoughMemory, kNPWErrUnexpectedEndPage, kNPWErrUnexpectedCommand,
  kNPWErrNestedObject, kNPWErrUnbalancedObj, kNPWUnknownFont, kNPWNumTooLarge,
  kNPWErrIncomplete, kNPWErrSuspended, kNPWErrDataNotFound, kNPWErrFileIO,
  kNPWErrInternal
}
 Error codes. More...
enum  {
  kNPWPaperHeightA3 = 1191, kNPWPaperWidthA3 = 842, kNPWPaperHeightA4 = 842, kNPWPaperWidthA4 = 595,
  kNPWPaperHeightA5 = 595, kNPWPaperWidthA5 = 420, kNPWPaperHeightA6 = 420, kNPWPaperWidthA6 = 298,
  kNPWPaperHeightB3 = 1417, kNPWPaperWidthB3 = 1001, kNPWPaperHeightB4 = 1001, kNPWPaperWidthB4 = 709,
  kNPWPaperHeightB5 = 709, kNPWPaperWidthB5 = 499, kNPWPaperHeightB6 = 499, kNPWPaperWidthB6 = 354,
  kNPWPaperHeightC3 = 1298, kNPWPaperWidthC3 = 918, kNPWPaperHeightC4 = 918, kNPWPaperWidthC4 = 649,
  kNPWPaperHeightC5 = 649, kNPWPaperWidthC5 = 459, kNPWPaperHeightC6 = 459, kNPWPaperWidthC6 = 323,
  kNPWPaperHeightDL = 312, kNPWPaperWidthDL = 624, kNPWPaperHeightID1 = 153, kNPWPaperWidthID1 = 243,
  kNPWPaperHeightID2 = 210, kNPWPaperWidthID2 = 298, kNPWPaperHeightID3 = 249, kNPWPaperWidthID3 = 354,
  kNPWPaperHeightLetter = 792, kNPWPaperWidthLetter = 612, kNPWPaperHeightLegal = 1008, kNPWPaperWidthLegal = 612,
  kNPWPaperHeightExecutive = 756, kNPWPaperWidthExecutive = 522, kNPWPaperHeightLedger = 1224, kNPWPaperWidthLedger = 792
}
 Paper size. More...
enum  { kNPWFilterNone = 0, kNPWFilterASCIIHex = 1, kNPWFilterASCII85 = 2, kNPWFilterRunLength = 4 }
 Filter flags (encoding: first rl, then hex or 85) More...
enum  {
  kNPWFontCourier = 1, kNPWFontCourierOblique = 2, kNPWFontCourierBold = 4, kNPWFontCourierBoldOblique = 010,
  kNPWFontHelvetica = 020, kNPWFontHelveticaOblique = 040, kNPWFontHelveticaBold = 0100, kNPWFontHelveticaBoldOblique = 0200,
  kNPWFontTimesRoman = 0400, kNPWFontTimesItalic = 01000, kNPWFontTimesBold = 02000, kNPWFontTimesBoldItalic = 04000,
  kNPWFontSymbol = 010000, kNPWFontZapfDingbats = 020000, kNPWFontNone = 0, kNPWFontAll = 037777
}
 Standard font flags. More...

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 NPWTerminate (NPW *pdf)
 Terminate PDF and flush output.
NPWErr NPWDataAlloc (NPW *pdf, NPWConstText key, NPWInt size, void **addr)
 Allocate a block of data which can be retrieved by key and index.
NPWInt NPWDataCount (NPW *pdf, NPWConstText key)
 Count number of data of a given type.
NPWErr NPWDataGetNext (NPW *pdf, NPWConstText key, void **addr)
 Get next data of a given type.
NPWErr NPWDataGetNth (NPW *pdf, NPWConstText key, NPWInt nth, void **addr)
 Get nth data of a given type.
void NPWDataDebug (NPW *pdf)
 Display (add to output) a list of data of all types.
NPWErr NPWBeginPage (NPW *pdf, NPWInt width, NPWInt height)
 Begin a new page (end the current page first if NPWEndPage hasn't been called).
NPWErr NPWEndPage (NPW *pdf)
 End the current page.
NPWBoolean NPWIsWritingPage (NPW *pdf)
 Check if is currently writing a page.
NPWErr NPWAddResourceCB (NPW *pdf, NPWActionCB cb, void *userData)
 Add a callback which will be called at appropriate time to add resources to the Resources dictionary.
NPWErr NPWAddDelayedActionCB (NPW *pdf, NPWActionCB cb, void *userData)
 Add a callback which will be called at the end, after writing the pages.
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).
NPWErr NPWBeginObj (NPW *pdf, NPWRef *ref)
 Begin writing an object.
NPWErr NPWEndObj (NPW *pdf)
 End writing an object.
void NPWFilterBegin (NPW *pdf, NPWInt filter)
 Begin writing filtered data to PDF.
NPWErr NPWFilterWrite (NPW *pdf, NPWByte const *b, NPWInt n)
 Write filtered data to PDF.
NPWErr NPWFilterEnd (NPW *pdf)
 End writing filtered data to PDF.

Detailed Description

NPW (base functions to write PDF files)

Author:
Yves Piguet.

Definition in file NPWBase.h.


Typedef Documentation

typedef NPWErr(* NPWActionCB)(struct NPW_struct *pdf, void *userData)

Callback to perform some action.

Parameters:
pdfreference to NPW structure
userDataapplication-specific data
Returns:
kNPWErrOk for success, else error code

Definition at line 308 of file NPWBase.h.

typedef NPWErr(* NPWAllocCB)(void **p, NPWInt size, void *userData)

Callback to allocate, resize or free block of memory.

Parameters:
[in,out]ppointer to memory (NULL to allocate new block)
[in]sizesize of block (negative to free it)
userDataapplication-specific data
Returns:
kNPWErrOk for success, else error code

Definition at line 301 of file NPWBase.h.

typedef NPWErr(* NPWWriteCB)(NPWConstText str, NPWInt length, void *userData)

Callback to write data to PDF file.

Parameters:
[in]straddress of string
[in]lengthlength of string in bytes
userDataapplication-specific data
Returns:
kNPWErrOk for success, else error code

Definition at line 293 of file NPWBase.h.


Enumeration Type Documentation

anonymous enum

Special references.

Enumerator:
kNPWNoRef 

Special value for nonexistent reference.

Definition at line 203 of file NPWBase.h.

anonymous enum

Paper size.

Enumerator:
kNPWPaperHeightA3 

portrait A3 height (420 mm)

kNPWPaperWidthA3 

portrait A3 width (297 mm)

kNPWPaperHeightA4 

portrait A4 height (297 mm)

kNPWPaperWidthA4 

portrait A4 width (210 mm)

kNPWPaperHeightA5 

portrait A5 height (210 mm)

kNPWPaperWidthA5 

portrait A5 width (148 mm)

kNPWPaperHeightA6 

portrait A6 height (148 mm)

kNPWPaperWidthA6 

portrait A6 width (105 mm)

kNPWPaperHeightB3 

portrait B3 height (500 mm)

kNPWPaperWidthB3 

portrait B3 width (353 mm)

kNPWPaperHeightB4 

portrait B4 height (353 mm)

kNPWPaperWidthB4 

portrait B4 width (250 mm)

kNPWPaperHeightB5 

portrait B5 height (250 mm)

kNPWPaperWidthB5 

portrait B5 width (176 mm)

kNPWPaperHeightB6 

portrait B6 height (176 mm)

kNPWPaperWidthB6 

portrait B6 width (125 mm)

kNPWPaperHeightC3 

portrait C3 height (458 mm)

kNPWPaperWidthC3 

portrait C3 width (324 mm)

kNPWPaperHeightC4 

portrait C4 height (324 mm)

kNPWPaperWidthC4 

portrait C4 width (229 mm)

kNPWPaperHeightC5 

portrait C5 height (229 mm)

kNPWPaperWidthC5 

portrait C5 width (162 mm)

kNPWPaperHeightC6 

portrait C6 height (162 mm)

kNPWPaperWidthC6 

portrait C6 width (114 mm)

kNPWPaperHeightDL 

DL envelope height(110 mm)

kNPWPaperWidthDL 

DL envelope width (220 mm)

kNPWPaperHeightID1 

ID-1 (banking cards) height (53.98 mm)

kNPWPaperWidthID1 

ID-1 (banking card) width (85.6 mm)

kNPWPaperHeightID2 

ID-2 (A7) height (74 mm)

kNPWPaperWidthID2 

ID-2 (A7) width (105 mm)

kNPWPaperHeightID3 

ID-3 (B7, passport) height (88 mm)

kNPWPaperWidthID3 

ID-3 (B7, passport) width (125 mm)

kNPWPaperHeightLetter 

Letter height (279 mm)

kNPWPaperWidthLetter 

Letter height (216 mm)

kNPWPaperHeightLegal 

Legal height (356 mm)

kNPWPaperWidthLegal 

Legal height (216 mm)

kNPWPaperHeightExecutive 

Executive height (266.7 mm)

kNPWPaperWidthExecutive 

Executive height (184.2 mm)

kNPWPaperHeightLedger 

Ledger/Tabloid height (431.8 mm)

kNPWPaperWidthLedger 

Ledger/Tabloid height (279.4 mm)

Definition at line 228 of file NPWBase.h.

anonymous enum

Filter flags (encoding: first rl, then hex or 85)

Enumerator:
kNPWFilterNone 

no filter

kNPWFilterASCIIHex 

ASCII Hexadecimal filter.

kNPWFilterASCII85 

ASCII base-85 filter.

kNPWFilterRunLength 

run-length compression filter

Definition at line 327 of file NPWBase.h.

anonymous enum

Standard font flags.

Enumerator:
kNPWFontCourier 

Courier.

kNPWFontCourierOblique 

Courier oblique.

kNPWFontCourierBold 

Courier bold.

kNPWFontCourierBoldOblique 

Courier bold oblique.

kNPWFontHelvetica 

Helvetica.

kNPWFontHelveticaOblique 

Helvetica oblique.

kNPWFontHelveticaBold 

Helvetica bold.

kNPWFontHelveticaBoldOblique 

Helvetica bold oblique.

kNPWFontTimesRoman 

Times roman.

kNPWFontTimesItalic 

Times italic.

kNPWFontTimesBold 

Times bold.

kNPWFontTimesBoldItalic 

Times bold italic.

kNPWFontSymbol 

Symbol.

kNPWFontZapfDingbats 

Zapf Dingbats.

kNPWFontNone 

no font

kNPWFontAll 

all fonts

Definition at line 382 of file NPWBase.h.

enum NPWErr

Error codes.

Enumerator:
kNPWErrOk 

no error

kNPWErrNotEnoughMemory 

not enough memory

kNPWErrUnexpectedEndPage 

NPWEndPage without matching NPWBeginPage.

kNPWErrUnexpectedCommand 

graphical command not between NPWBeginPage and NPWEndPage

kNPWErrNestedObject 

try to start a new object without having ended previous one

kNPWErrUnbalancedObj 

endobj without obj

kNPWUnknownFont 

unknown font

kNPWNumTooLarge 

floating-point number too large

kNPWErrIncomplete 

incomplete operation

kNPWErrSuspended 

operation suspended by callback to permit a lower-level action

kNPWErrDataNotFound 

NPWDataGetNext cannot find more data.

kNPWErrFileIO 

file I/O error

kNPWErrInternal 

internal error (should never occur)

Definition at line 209 of file NPWBase.h.


Function Documentation

NPWErr NPWAddDelayedActionCB ( NPW pdf,
NPWActionCB  cb,
void *  userData 
)

Add a callback which will be called at the end, after writing the pages.

Parameters:
pdfreference to NPW structure
[in]cbcallback
[in]userDatacallback user data
Returns:
error code (kNPWErrOk for success)

Definition at line 893 of file NPWBase.c.

NPWErr NPWAddResourceCB ( NPW pdf,
NPWActionCB  cb,
void *  userData 
)

Add a callback which will be called at appropriate time to add resources to the Resources dictionary.

Parameters:
pdfreference to NPW structure
[in]cbcallback
[in]userDatacallback user data
Returns:
error code (kNPWErrOk for success)

Definition at line 882 of file NPWBase.c.

NPWErr NPWBeginObj ( NPW pdf,
NPWRef ref 
)

Begin writing an object.

Parameters:
pdfreference to NPW structure
[out]refobject reference number
Returns:
error code (kNPWErrOk for success)

Definition at line 469 of file NPWBase.c.

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

Begin a new page (end the current page first if NPWEndPage hasn't been called).

Parameters:
pdfreference to NPW structure
[in]widthpage width
[in]heightpage height
Returns:
error code (kNPWErrOk for success)

Definition at line 814 of file NPWBase.c.

NPWErr NPWDataAlloc ( NPW pdf,
NPWConstText  key,
NPWInt  size,
void **  addr 
)

Allocate a block of data which can be retrieved by key and index.

Parameters:
pdfreference to NPW structure
[in]keykey (whose address is stored)
[in]sizesize in bytes
[out]addraddress of allocated data
Returns:
kNPWErrOk for success, else error code

Definition at line 714 of file NPWBase.c.

NPWInt NPWDataCount ( NPW pdf,
NPWConstText  key 
)

Count number of data of a given type.

Parameters:
pdfreference to NPW structure
[in]keykey (whose address is used)
Returns:
number of data

Definition at line 746 of file NPWBase.c.

void NPWDataDebug ( NPW pdf)

Display (add to output) a list of data of all types.

Parameters:
pdfreference to NPW structure

Definition at line 793 of file NPWBase.c.

NPWErr NPWDataGetNext ( NPW pdf,
NPWConstText  key,
void **  addr 
)

Get next data of a given type.

Parameters:
pdfreference to NPW structure
[in]keykey (whose address is used)
[in,out]addrdata address (NULL on input to get first one)
Returns:
kNPWErrOk for success, kNPWErrDataNotFound if not found

Definition at line 763 of file NPWBase.c.

NPWErr NPWDataGetNth ( NPW pdf,
NPWConstText  key,
NPWInt  nth,
void **  addr 
)

Get nth data of a given type.

Parameters:
pdfreference to NPW structure
[in]keykey (whose address is used)
[in]nthindex of the data to retrieve
[out]addrdata address
Returns:
kNPWErrOk for success, kNPWErrDataNotFound if not found

Definition at line 782 of file NPWBase.c.

NPWErr NPWEndObj ( NPW pdf)

End writing an object.

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

Definition at line 518 of file NPWBase.c.

NPWErr NPWEndPage ( NPW pdf)

End the current page.

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

Definition at line 850 of file NPWBase.c.

void NPWFilterBegin ( NPW pdf,
NPWInt  filter 
)

Begin writing filtered data to PDF.

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

Definition at line 310 of file NPWBase.c.

NPWErr NPWFilterEnd ( NPW pdf)

End writing filtered data to PDF.

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

Definition at line 419 of file NPWBase.c.

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

Write filtered data to PDF.

Parameters:
pdfreference to NPW structure
[in]baddress of unfiltered data
[in]nnumber of unfiltered bytes
Returns:
error code (kNPWErrOk for success)

Definition at line 362 of file NPWBase.c.

void NPWInit ( NPW pdf)

Initialize PDF.

Parameters:
[out]pdfreference to NPW structure

Definition at line 45 of file NPWBase.c.

NPWBoolean NPWIsWritingPage ( NPW pdf)

Check if is currently writing a page.

Parameters:
pdfreference to NPW structure
Returns:
TRUE if between NPWBeginPage and NPWEndPage, else FALSE

Definition at line 877 of file NPWBase.c.

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

Set memory allocation callback.

Parameters:
pdfreference to NPW structure
[in]allocmemory allocation callback
[in]userDatacallback user data

Definition at line 62 of file NPWBase.c.

void NPWSetFonts ( NPW pdf,
NPWInt  fonts 
)

Specify which standard fonts should be made available.

Parameters:
pdfreference to NPW structure
[in]fontsfont flags (kNPWFontAll for all)

Definition at line 76 of file NPWBase.c.

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

Set write callback.

Parameters:
pdfreference to NPW structure
[in]writeallocation callback
[in]userDatacallback user data

Definition at line 69 of file NPWBase.c.

NPWErr NPWTerminate ( NPW pdf)

Terminate PDF and flush output.

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

Definition at line 904 of file NPWBase.c.

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

Write a string.

Parameters:
pdfreference to NPW structure
[in]straddress of first character
[in]lengthnumber of bytes, or -1 if str is null-terminated
Returns:
error code (kNPWErrOk for success)

Definition at line 81 of file NPWBase.c.

NPWErr NPWWriteFloat ( NPW pdf,
NPWFloat  x 
)

Write an floating-point value.

Parameters:
pdfreference to NPW structure
[in]xnumber
Returns:
error code (kNPWErrOk for success)

Definition at line 131 of file NPWBase.c.

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

Write an integer.

Parameters:
pdfreference to NPW structure
[in]inumber
[in]padnumber of digits (0-padded), or -1
Returns:
error code (kNPWErrOk for success)

Definition at line 94 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:
pdfreference to NPW structure
[in]strstring
[in]lengthstring length in bytes, or -1 for null-terminated string
Returns:
error code (kNPWErrOk for success)

Definition at line 174 of file NPWBase.c.