1. Features
- It's free, on LGPL license.
- Developer implementation is based on callbacks (C) or virtual functions (C++).
- Styles, colors, fonts.
- Based on RTF Specification 2003 <- link needed.
- Handling errors, warnings and progress by developer.
- Low memory usage.
- Pictures support.
- Ports to other languages and platrofms like .NET .
- Header infromation like authors, keywords, number of words etc.
2.1. 5 minutes tutorial for C
This tutorial refers to librtf-0.0.4 which is not yet available.
All needed functions and structures can be found in following header file:
Where are declarations.
To parse RTF text use function :
void rtf_process( source * src, processor * proc, observer * log );
Where src is RTF source provider, proc is your processor and log is event handler.
To create source provider which uses stream, buildin function can be used:
void rtf_src_stream_init( source * src, FILE * stream );
For example:
Creating new source provider using stream.
#include "librtf.h"
#include <stdio.h>
int main( )
{
source my_src;
FILE * stream;
stream = fopen( "/path/to/rtf/file.rtf", "r");
rtf_src_stream_init( &my_src, stream );
rtf_src_stream_free( &my_src, stream );
fclose(stream);
}
Note: To see how to implement own source provider please see here.
observer structure provides two types of information which are errors and warnings.
In future there will be also progress information.
To redirect errors and warnings to stderr also buildin function can be used which is:
void rtf_log_stream_init( observer * log, FILE * errors, FILE * warnings );
It can be used like in following example:
Creating observer using streams.
#include "librtf.h"
#include <stdlib.h>
int main( )
{
observer my_logger;
rtf_log_stream_init( &my_src, stderr, stderr> );
rtf_log_stream_free( &my_src, stream );
}
Last thing and also most importatnt is processor which functions are called on every text change.
processor has following structure and each member has to be set to proper function:
processor structure.
typedef struct __processor
{
void * object;
void (* attr_push)(struct __processor *, int attr, int param );
int (* attr_pop)(struct __processor *, int attr);
void (* attrstack_push)(struct __processor *);
void (* attrstack_drop) (struct __processor *);
void (* attr_drop_all) (struct __processor *);
void (* attr_pop_all) (struct __processor *);
void (* attr_pop_dump) (struct __processor *);
void (* attr_remove ) (struct __processor *, int * tab, int size );
void (* attr_push_style ) (struct __processor *, enum TextStyleType type, int id );
void (* begin) (struct __processor *);
void (* end) (struct __processor *);
void (* title) (struct __processor *, const char * );
void (* keywords) (struct __processor *, const char * );
void (* author) (struct __processor *, const char * );
void (* summary) (struct __processor *, enum document_summary type, int param );
void (* hyperlink_base) (struct __processor *, const char * url );
void (* font_smaller_begin ) ( struct __processor * );
void (* font_smaller_end ) ( struct __processor * );
char* (* translate_char) (struct __processor *, int );
void (*print) ( struct __processor * , const char * );
void (*print_symbol) ( struct __processor *, const char * );
void (*print_forced_space) ( struct __processor * );
int (*print_unicode) (struct __processor *, int );
void (*hyperlink) ( struct __processor *, const char * );
void (*print_char) ( struct __processor *, enum special_char );
void (*table_begin) ( struct __processor *);
void (*table_end) ( struct __processor *);
void (*table_cell_begin) ( struct __processor *);
void (*table_cell_end) ( struct __processor *);
void (*table_row_begin) (struct __processor *);
void (*table_row_end) (struct __processor *);
image_mgr * (*image_begin) ( struct __processor *, const image_descr * );
void (*image_end) ( struct __processor *, image_mgr * );
void (* charset) (struct __processor *, int charset_id );
void (* codepage) (struct __processor *, int cp_id );
void (* register_font ) (struct __processor *, int id, const char * font_name );
void (* register_color ) (struct __processor *, unsigned char r, unsigned char g, unsigned char b );
void (* register_style ) (struct __processor *, const TextStyle * style );
} processor;
Rest of this tutorial will be soon.
2.2. 5 minutes tutorial for C++
#include "librtfcpp.h"
int main( )
{
// please see sample in tarball, or here
}
3. Samples
Here will be some links to sample programs.
4. Documentation
Doxygen documentation can be found here
5. Resources
Unrtf : application to convering RTF file to HTML or other formats.
rtf2xml
docfrac
NRTFTree
Gios WORD .NET Library
6. Download
Tarballs can be found here
|