From 8a6cdb1b534b7b6101222bcf53d47465a0bd7a91 Mon Sep 17 00:00:00 2001 From: acspike Date: Tue, 13 Jun 2006 02:13:02 +0000 Subject: [PATCH] patch [ 1503869 ] ODF formatting fix --- src/dom/io/base64stream.cpp | 6 +- src/dom/io/base64stream.h | 2 +- src/dom/io/bufferstream.cpp | 5 +- src/dom/io/bufferstream.h | 2 +- src/dom/io/domstream.cpp | 339 ++++++++++++++++++++++++++++++++- src/dom/io/domstream.h | 16 +- src/dom/io/gzipstream.cpp | 6 +- src/dom/io/gzipstream.h | 2 +- src/dom/io/stringstream.cpp | 3 +- src/dom/io/stringstream.h | 2 +- src/dom/io/uristream.cpp | 14 +- src/dom/io/uristream.h | 4 +- src/extension/internal/odf.cpp | 6 +- 13 files changed, 366 insertions(+), 41 deletions(-) diff --git a/src/dom/io/base64stream.cpp b/src/dom/io/base64stream.cpp index f71532e8b..2cab2b3f4 100644 --- a/src/dom/io/base64stream.cpp +++ b/src/dom/io/base64stream.cpp @@ -292,12 +292,12 @@ void Base64OutputStream::putCh(int ch) /** * Writes the specified byte to this output stream. */ -void Base64OutputStream::put(XMLCh ch) +int Base64OutputStream::put(XMLCh ch) { if (closed) { //probably throw an exception here - return; + return -1; } outBuf <<= 8; @@ -324,6 +324,8 @@ void Base64OutputStream::put(XMLCh ch) bitCount = 0; outBuf = 0L; } + + return 1; } diff --git a/src/dom/io/base64stream.h b/src/dom/io/base64stream.h index 23ec1ce07..c6d0ad35d 100644 --- a/src/dom/io/base64stream.h +++ b/src/dom/io/base64stream.h @@ -108,7 +108,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); /** * Sets the maximum line length for base64 output. If diff --git a/src/dom/io/bufferstream.cpp b/src/dom/io/bufferstream.cpp index 4664b07e9..6c3956a60 100644 --- a/src/dom/io/bufferstream.cpp +++ b/src/dom/io/bufferstream.cpp @@ -146,11 +146,12 @@ void BufferOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void BufferOutputStream::put(XMLCh ch) +int BufferOutputStream::put(XMLCh ch) { if (closed) - return; + return -1; buffer.push_back(ch); + return 1; } diff --git a/src/dom/io/bufferstream.h b/src/dom/io/bufferstream.h index a8f7ea319..bdf4eb2ab 100644 --- a/src/dom/io/bufferstream.h +++ b/src/dom/io/bufferstream.h @@ -100,7 +100,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); virtual std::vector &getBuffer() { return buffer; } diff --git a/src/dom/io/domstream.cpp b/src/dom/io/domstream.cpp index 3ffba53fe..7b0a7e1d2 100644 --- a/src/dom/io/domstream.cpp +++ b/src/dom/io/domstream.cpp @@ -34,6 +34,7 @@ * */ +#include #include #include "domstream.h" @@ -65,6 +66,305 @@ void pipeStream(InputStream &source, OutputStream &dest) dest.flush(); } + + +//######################################################################### +//# F O R M A T T E D P R I N T I N G +//######################################################################### + +static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz"; + +static int dprintInt(Writer &outs, + long arg, int base, + int flag, int width, int precision) +{ + + DOMString buf; + + //### Get the digits + while (arg > 0) + { + int ch = arg % base; + buf.insert(buf.begin(), digits[ch]); + arg /= base; + } + + if (flag == '#' && base == 16) + { + buf.insert(buf.begin(), 'x'); + buf.insert(buf.begin(), '0'); + } + + //### Output the result + for (unsigned int i=0 ; i 0) + pad -= precision + 1; + else if (flag == '#') + pad--; + + + //### Signs + if (negative) + buf.push_back('-'); + else if (flag == '+') + buf.push_back('+'); + + //### Prefix pad + if (pad > 0 && flag == '0') + { + while (pad--) + buf.push_back('0'); + } + + //### Integer digits + intPart = (intPart + 0.1 ) / scale; // turn 12345.678 to .12345678 + while (intDigits--) + { + intPart *= 10.0; + double dig; + intPart = modf(intPart, &dig); + char ch = '0' + (int)dig; + buf.push_back(ch); + } + + //### Decimal point + if (flag == '#' || precision > 0) + { + buf.push_back('.'); + } + + //### Fractional digits + while (precision--) + { + fracPart *= 10.0; + double dig; + fracPart = modf(fracPart, &dig); + char ch = '0' + (int)dig; + buf.push_back(ch); + } + + //### Left justify if requested + if (pad > 0 && flag == '-') + { + while (pad--) + buf.push_back(' '); + } + + //### Output the result + for (unsigned int i=0 ; i= '0' && *s <= '9') + { + val = val * 10 + (*s - '0'); + s++; + } + if (has_sign) + val = -val; + + *ret = val; + + return s; +} + + + +static int dprintf(Writer &outs, const char *fmt, va_list ap) +{ + + char *s = (char *) fmt; + + while (*s) + { + unsigned char ch = *s++; + + if (ch != '%') + { + if (outs.put(ch)<0) + { + return -1; + } + } + else + //expecting %[flag][width][.precision][length][char] + { + if (!*s) + { + return -1; + } + if (*s == '%') // escaped '%' + { + if (outs.put('%')<0) + { + return -1; + } + s++; + continue; + } + char flag = '\0'; + if (*s == '-' || *s == '+' || *s == ' ' || + *s == '#' || *s == '0') + { + flag = *s++; + if (!*s) + { + return -1; + } + } + int width = 0; + int precision = 0; + s = getint(s, &width); + if (!*s) + { + return -1; + } + if (*s == '.') + { + s++; + if (!*s) + { + return -1; + } + s = getint(s, &precision); + } + char length = '\0'; + if (*s == 'l' || *s == 'h') + { + length = *s++; + if (!*s) + { + return -1; + } + } + ch = *s++; + if (!ch) + { + return -1; + } + switch (ch) + { + case 'f': + case 'g': + { + double val = va_arg(ap, double); + dprintDouble(outs, val, flag, width, precision); + break; + } + case 'd': + { + long val = 0; + if (length == 'l') + val = va_arg(ap, long); + else if (length == 'h') + val = (long)va_arg(ap, int); + else + val = (long)va_arg(ap, int); + dprintInt(outs, val, 10, flag, width, precision); + break; + } + case 'x': + { + long val = 0; + if (length == 'l') + val = va_arg(ap, long); + else if (length == 'h') + val = (long)va_arg(ap, int); + else + val = (long)va_arg(ap, int); + dprintInt(outs, val, 16, flag, width, precision); + break; + } + case 's': + { + char *val = va_arg(ap, char *); + dprintString(outs, val, flag, width, precision); + break; + } + default: + { + break; + } + } + } + + } + + + return 1; +} + + //######################################################################### //# B A S I C I N P U T S T R E A M //######################################################################### @@ -155,11 +455,13 @@ void BasicOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void BasicOutputStream::put(XMLCh ch) +int BasicOutputStream::put(XMLCh ch) { if (closed) - return; - destination.put(ch); + return -1; + if (destination.put(ch) < 0) + return -1; + return 1; } @@ -529,15 +831,17 @@ void BasicWriter::flush() /** * Writes the specified byte to this output writer. */ -void BasicWriter::put(XMLCh ch) +int BasicWriter::put(XMLCh ch) { - if (destination) - destination->put(ch); + if (destination && destination->put(ch)>=0) + return 1; + return -1; } /** * Provide printf()-like formatting */ +/* Writer &BasicWriter::printf(char *fmt, ...) { va_list args; @@ -549,6 +853,17 @@ Writer &BasicWriter::printf(char *fmt, ...) return *this; } +*/ +Writer &BasicWriter::printf(char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + dprintf(*this, fmt, args); + + return *this; +} + + /** * Writes the specified character to this output writer. */ @@ -710,11 +1025,13 @@ void OutputStreamWriter::flush() * Overloaded to redirect the output chars from the next Writer * in the chain to an OutputStream instead. */ -void OutputStreamWriter::put(XMLCh ch) +int OutputStreamWriter::put(XMLCh ch) { //Do we need conversions here? int intCh = (int) ch; - outputStream.put(intCh); + if (outputStream.put(intCh) < 0) + return -1; + return 1; } //######################################################################### @@ -762,11 +1079,13 @@ void StdWriter::flush() * Overloaded to redirect the output chars from the next Writer * in the chain to an OutputStream instead. */ -void StdWriter::put(XMLCh ch) +int StdWriter::put(XMLCh ch) { //Do we need conversions here? int intCh = (int) ch; - outputStream->put(intCh); + if (outputStream->put(intCh) < 0) + return -1; + return 1; } diff --git a/src/dom/io/domstream.h b/src/dom/io/domstream.h index 05862f944..4a68ba1c1 100644 --- a/src/dom/io/domstream.h +++ b/src/dom/io/domstream.h @@ -215,7 +215,7 @@ public: /** * Send one byte to the destination stream. */ - virtual void put(XMLCh ch) = 0; + virtual int put(XMLCh ch) = 0; }; // class OutputStream @@ -238,7 +238,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); protected: @@ -264,8 +264,8 @@ public: void flush() { } - void put(XMLCh ch) - { putchar(ch); } + int put(XMLCh ch) + { putchar(ch); return 1; } }; @@ -489,7 +489,7 @@ public: virtual void flush() = 0; - virtual void put(XMLCh ch) = 0; + virtual int put(XMLCh ch) = 0; /* Formatted output */ virtual Writer& printf(char *fmt, ...) = 0; @@ -539,7 +539,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); @@ -626,7 +626,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); private: @@ -654,7 +654,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); private: diff --git a/src/dom/io/gzipstream.cpp b/src/dom/io/gzipstream.cpp index 19369b6dc..f634acbe7 100644 --- a/src/dom/io/gzipstream.cpp +++ b/src/dom/io/gzipstream.cpp @@ -214,17 +214,17 @@ void GzipOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void GzipOutputStream::put(XMLCh ch) +int GzipOutputStream::put(XMLCh ch) { if (closed) { //probably throw an exception here - return; + return -1; } //Add char to buffer buffer.push_back(ch); - + return 1; } diff --git a/src/dom/io/gzipstream.h b/src/dom/io/gzipstream.h index 6396772a5..4af5ada2b 100644 --- a/src/dom/io/gzipstream.h +++ b/src/dom/io/gzipstream.h @@ -101,7 +101,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); private: diff --git a/src/dom/io/stringstream.cpp b/src/dom/io/stringstream.cpp index 93fb0c0b5..f2745a107 100644 --- a/src/dom/io/stringstream.cpp +++ b/src/dom/io/stringstream.cpp @@ -140,9 +140,10 @@ void StringOutputStream::flush() /** * Writes the specified byte to this output stream. */ -void StringOutputStream::put(XMLCh ch) +int StringOutputStream::put(XMLCh ch) { buffer.push_back(ch); + return 1; } diff --git a/src/dom/io/stringstream.h b/src/dom/io/stringstream.h index 8bb4e76b1..38aaf7235 100644 --- a/src/dom/io/stringstream.h +++ b/src/dom/io/stringstream.h @@ -98,7 +98,7 @@ public: virtual void flush(); - virtual void put(XMLCh ch); + virtual int put(XMLCh ch); virtual DOMString &getString() { return buffer; } diff --git a/src/dom/io/uristream.cpp b/src/dom/io/uristream.cpp index 1cc540bd5..8928921e4 100644 --- a/src/dom/io/uristream.cpp +++ b/src/dom/io/uristream.cpp @@ -411,10 +411,10 @@ void UriOutputStream::flush() throw(StreamException) /** * Writes the specified byte to this output stream. */ -void UriOutputStream::put(XMLCh ch) throw(StreamException) +int UriOutputStream::put(XMLCh ch) throw(StreamException) { if (closed) - return; + return -1; switch (scheme) { @@ -422,7 +422,7 @@ void UriOutputStream::put(XMLCh ch) throw(StreamException) case URI::SCHEME_FILE: { if (!outf) - return; + return -1; unsigned char uch = (unsigned char)(ch & 0xff); fputc(uch, outf); //fwrite(uch, 1, 1, outf); @@ -436,7 +436,7 @@ void UriOutputStream::put(XMLCh ch) throw(StreamException) } }//switch - + return 1; } @@ -479,10 +479,12 @@ void UriWriter::flush() throw(StreamException) /** * */ -void UriWriter::put(XMLCh ch) throw(StreamException) +int UriWriter::put(XMLCh ch) throw(StreamException) { int ich = (int)ch; - outputStream->put(ich); + if (outputStream->put(ich) < 0) + return -1; + return 1; } diff --git a/src/dom/io/uristream.h b/src/dom/io/uristream.h index 892ac5c68..45d44b71d 100644 --- a/src/dom/io/uristream.h +++ b/src/dom/io/uristream.h @@ -146,7 +146,7 @@ public: virtual void flush() throw(StreamException); - virtual void put(XMLCh ch) throw(StreamException); + virtual int put(XMLCh ch) throw(StreamException); private: @@ -187,7 +187,7 @@ public: virtual void flush() throw(StreamException); - virtual void put(XMLCh ch) throw(StreamException); + virtual int put(XMLCh ch) throw(StreamException); private: diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 1d3648048..3e62ea999 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1361,9 +1361,9 @@ bool OdfOutput::writeStyle(Writer &outs) outs.printf(" \n"); + outs.printf(" draw:luminance=\"0%%\" draw:contrast=\"0%%\" draw:gamma=\"100%%\" draw:red=\"0%%\"\n"); + outs.printf(" draw:green=\"0%%\" draw:blue=\"0%%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n"); + outs.printf(" draw:image-opacity=\"100%%\" style:mirror=\"none\"/>\n"); outs.printf("\n"); outs.printf("\n"); outs.printf(" \n"); -- 2.30.2