Development Tips
-
Avoid unnecessary initialization.
The context variable is allocated in
fpAllocateContext()
. This structure must be immediatelymemset()
to zero. This sets allBOOL
values toFALSE
, all pointers toNULL
, and all integers to0
. Only non-zero, non-NULL
andBOOL
s that must beTRUE
need to be initialized. This is best done infpInitDoc()
. -
Know where you are in the input source file.
If you are processing headers, footers, notes, or (in the case of
rtfsr
) tables, you must be able to reposition the file pointer as required. -
Check buffer boundaries continuously.
Whenever you advance through the buffer, you need to know whether there is enough of the input stream to completely process the current command. If not, you need to append the next section of the input file before continuing.
-
Strive for a "clean" token stream.
Use
filtertest
with the-d
command-line option to generate a token version of the document. If there are redundant tokens, the reader is producing an inefficient token stream. You can keep the token stream free from redundancies by storing the state of the document and then applying the changes only when content is encountered. Content can be text, tabs, or picture objects. Thefiltertest.exe
is in the directoryinstall\samples\utf8\bin
, whereinstall
is the path name of the Filter installation directory. -
Avoid large
switch()
statements whenever possible. They make both development and debugging more complicated than necessary. If there is a fixed set of commands, consider using a hash table that enables you to quickly identify a pointer to the function that handles that command. -
Filtering document metadata is a separate process.
Remember that
fpGetSummaryInfo()
is a completely separate process from the rest of your code. It creates its own context variable structure. It does not have to callfpFillBuffer()
. -
Use caution when processing headers, footers, and notes.
If you need to process these items, the structured access layer calls
fpOpenStream()
andfpCloseStream()
. It is critical that you save the state of your document and the file pointer position prior to returning fromfpOpenStream()
. Prior to returning fromfpCloseStream()
, you must restore the file pointer and the previous state of your document. -
Test your code.
The structured access layer for each SDK is unique. Test your code in Filter SDK, Export SDK, and Viewing SDK.