LibRTF Homepage

Page under construction.
SourceForge.net Logo
SourceForge project page

1. Features
2. 5 minutes tutorials :
  2.1. for C
  2.2. for C++
3. Samples
4. Documentation
5. Resources
6. Download / Sources
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.
#include "librtf.h"

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 ); // now my_src is reading from 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> ); // now all errors and warnings writen to my_logger are redirected to 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 { Pointer to object which can be accessed from __processor \ pointer which is passed to every following function call. void * object; // add attribute to last block void (* attr_push)(struct __processor *, int attr, int param ); // remove last attribute from last last block if it is equal to attr int (* attr_pop)(struct __processor *, int attr); // add new block void (* attrstack_push)(struct __processor *); // remove last block and rollback all attributes void (* attrstack_drop) (struct __processor *); // clear last block without rollingback attributes void (* attr_drop_all) (struct __processor *); // rollback all attributes from last block and removes all attributes from last block void (* attr_pop_all) (struct __processor *); // rollback all attributes from last block without removing them void (* attr_pop_dump) (struct __processor *); // remove all possible attribues from last block void (* attr_remove ) (struct __processor *, int * tab, int size ); // push attributes from registred style void (* attr_push_style ) (struct __processor *, enum TextStyleType type, int id ); // Begin of document. void (* begin) (struct __processor *); // End of document. void (* end) (struct __processor *); // Title. void (* title) (struct __processor *, const char * ); // Keywords void (* keywords) (struct __processor *, const char * ); // Autors, separated by ',' (???) void (* author) (struct __processor *, const char * ); // Number of words, characters etc in document. void (* summary) (struct __processor *, enum document_summary type, int param ); // Base path for hyperlinks. void (* hyperlink_base) (struct __processor *, const char * url ); // Not used. void (* font_smaller_begin ) ( struct __processor * ); // Not used. void (* font_smaller_end ) ( struct __processor * ); // Not used. char* (* translate_char) (struct __processor *, int ); // Main function called each time when text is processed. void (*print) ( struct __processor * , const char * ); // Symbol character. void (*print_symbol) ( struct __processor *, const char * ); // Space character. void (*print_forced_space) ( struct __processor * ); // Unicore character. Return 0 if unicde support is not available. int (*print_unicode) (struct __processor *, int ); // Link void (*hyperlink) ( struct __processor *, const char * ); // Special character, see special characters here <- TODO link needed. void (*print_char) ( struct __processor *, enum special_char ); // Begining of table. void (*table_begin) ( struct __processor *); // End of table. void (*table_end) ( struct __processor *); // Begining of new cell in row. void (*table_cell_begin) ( struct __processor *); // End of current cell in row. void (*table_cell_end) ( struct __processor *); // Begining of new row in table. void (*table_row_begin) (struct __processor *); // End of current row in table. void (*table_row_end) (struct __processor *); // Begining of image. Return NULL or object where image will be stored. image_mgr * (*image_begin) ( struct __processor *, const image_descr * ); // End of image data. Image might be displayed. void (*image_end) ( struct __processor *, image_mgr * ); // Changing of charset. void (* charset) (struct __processor *, int charset_id ); // Changing of codepage. void (* codepage) (struct __processor *, int cp_id ); // Registring font. id is passed to attribute functions with FONT attribute as param. void (* register_font ) (struct __processor *, int id, const char * font_name ); // Registring of color. void (* register_color ) (struct __processor *, unsigned char r, unsigned char g, unsigned char b ); // Registring of style. 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