Re: gtktextview with gdkpixbuf saving into file
- From: Johnson Wong <jjwh tpg com au>
- To: gtk-app-devel-list gnome org
- Subject: Re: gtktextview with gdkpixbuf saving into file
- Date: Sat, 15 Nov 2008 23:45:39 +1100
solved the issue by scanning the textbuffer for pixbufs and replace them
with tags. so loading the file into a textbuffer/textview then simply
means parsing the tags and load pixbuf on the go.
text text text
..
<img=pixbuf>
..
text text text
if there is a better way to do save/load on textview with embeeded
pixbuf, please let me know.
cheers
Johnson
------------------------
void
SaveFileCB(GtkTextBuffer *textBuffer)
{
GtkTextIter start;
GtkTextIter end;
GtkTextIter begin;
GtkTextIter now;
gunichar c;
gunichar pixbufC = 0xFFFC;
gchar *buf;
gchar *contents;
gchar *newContents;
gint pngCount = 0;
gchar pngFile[30];
GError *err = NULL;
gtk_text_buffer_get_start_iter(textBuffer, &start);
gtk_text_buffer_get_end_iter(textBuffer, &end);
begin = start;
now = start;
contents = g_strdup("");
// scan all characters
while ((c = gtk_text_iter_get_char(&now)) != 0)
{
// found pixbuf, concat string from 'begin' to 'now' + pixbuf
file to contents
if (c == pixbufC)
{
buf = gtk_text_buffer_get_text(textBuffer, &begin, &now,
FALSE);
sprintf(pngFile, "<img=\"book_img%03d.png\">", pngCount
++);
newContents = g_strconcat(contents, buf, pngFile, NULL);
g_free(buf);
g_free(contents);
contents = newContents;
}
gtk_text_iter_forward_char(&now);
// 'begin' now the next iter when found pixbuf
if (c == pixbufC)
begin = now;
}
// finish off last concat from begin to now
buf = gtk_text_buffer_get_text(textBuffer, &begin, &now, FALSE);
newContents = g_strconcat(contents, buf, NULL);
g_free(buf);
g_free(contents);
contents = newContents;
g_file_set_contents("outputFile.txt", contents, -1, &err);
g_free(contents);
if (err == NULL) { ...error checking ... }
}
On Sat, 2008-11-15 at 03:33 +1100, Johnson Wong wrote:
hihi
anyone know a way to save a gtktextview/gtktextbuffer with embedded
gdkpixbuf into a file. I am calling gtk_text_buffer_get_slice then
g_file_set_contents. Idealy it will be good if i can just call
g_file_get_contents to output the saved buffer onto the gtktextview.
many thanks
Johnson
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]