[plt-scheme] Troubles with write-to-file and read-from-file in text%
Like has been suggested to me, I may use write-to-file and
read-from-file to get or set text including styles. Unfortunately, the
code below (public methods inside a text% subclass) doesn't seem to
work. According to my home-brewn debug calls, the string returned by
get-rich-text looks good and includes a standard header plus the text
data (sample far below), but insert-rich-text simply does nothing.
Strange enough, I've checked (send input-stream ok?) and it returns
true.
(DrScheme, version 203.6-cvs18mar2003)
What am I doing wrong?
Greetings,
Erich
;;;; code:
; Get a part of the editor, including all styles, etc.
; Returns a string containing private data, as returned from
editor-stream-out-string-base%.
;
(define (get-rich-text start end)
(debug 'verbose 'gui-framework (format "(get-rich-text ~a ~a)"
start end))
(let* ((base (make-object editor-stream-out-string-base%))
(output-stream (make-object editor-stream-out% base)))
(send this write-to-file output-stream
(get-absolute-position start)
(get-absolute-position end))
(send base get-string)))
; Insert text from private string data, including all styles, etc.
;
(define (insert-rich-text data start)
(debug 'verbose 'gui-framework (format "(insert-rich-text ~s
~a)" data start))
(let* ((base (make-object editor-stream-in-string-base% data))
(input-stream (make-object editor-stream-in% base)))
(send this read-from-file input-stream (get-absolute-position
start) #f)))
; Turn a standard position, i.e. a number or a symbol in '(start end
first eof)
; into an absolute position, i.e. the number
;
(define (get-absolute-position pos)
(cond ((symbol? pos) (case pos
((start) (get-start-position))
((end) (get-end-position))
((first) 0)
((eof) (last-position))
(else (error 'basic-wordprocessor%
"Cannot convert a symbolic
to an absolute position, because the given position '~a' is unknown"
pos))))
(else pos)))
;;;; sample string (from my debug calls)
GUI-FRAMEWORK (insert-rich-text
"\0\0\0\0\1\4\0\tStandard\0\0F\1\0?ð\0\0\0\0\0\0\0ZZZZ\0\0\0\0?ð\0\0\0\0
\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0
\0\0\0\0\0\0\0\1\1\1\1\0\0F\1\0?ð\0\0\0\0\0\0\0\\\\ZZ\0\0\0\0?ð\0\0\0\0\
0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\
0\0\0\0\0\0\0\1\1\1\1\0\0F\1\0?ð\0\0\0\0\0\0\0ZZ]]\0\0\0\0?ð\0\0\0\0\0\0
?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0?ð\0\0\0\0\0\0\0
\0\0\0\0\0\1\1\0\0\0\4Áÿ\0\0\0\0Áÿ\0\0\0\0Áÿ\0\0\0\0Áÿ\0\0\0\0\4Áÿ\1\3\2
0This is a Test: \0Áÿ\2\3\4bold\0Áÿ\1\3\1 \0Áÿ\3\3\6italic\0\0\0\0"
start)