- return wxGIFHandler_Write(stream, buf, sizeof(buf))
- && wxGIFHandler_Write(stream, text.data(), len)
- && wxGIFHandler_WriteZero(stream);
+ /*
+ If comment is longer than 255 bytes write it in blocks of maximum 255
+ bytes each.
+ */
+ wxCharBuffer text( comment.mb_str() );
+
+ size_t pos = 0, fullLength = text.length();
+
+ do
+ {
+ size_t blockLength = wxMin(fullLength - pos, 255);
+
+ if ( !wxGIFHandler_WriteByte(stream, (wxUint8) blockLength)
+ || !wxGIFHandler_Write(stream, &text.data()[pos], blockLength) )
+ {
+ return false;
+ }
+
+ pos += blockLength;
+ }while (pos < fullLength);
+
+
+ // Write comment footer.
+ return wxGIFHandler_WriteZero(stream);