Sunday, August 07, 2011

gnocl::rtf

Just created a binding to the Osxcart module which provided rtf import and export for GtkTextBuffers. Its a lot of coding for what is effectively a couple of library calls! The API allows for loading from files, but it seems more appropriate to import and export strings.

#---------------
# test-rtf.tcl
#---------------
# Created by William J Giddings
# 07-August-2011
#---------------
# Description:
# Import/Export rtf formatted files from gnocl::text widgets.
#---------------

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl
package require GnoclOsxCart

set txt [gnocl::text]

gnocl::window -child $txt

gnocl::rtf register $txt

set fp1 [open "p006a_hello_world.rtf" "r"]
set fp2 [open "test.rtf" "w"]

gnocl::rtf import $txt [read $fp1]
close $fp1

puts $fp2 [gnocl::rtf export $txt]
close $fp2