2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include <ZLStringUtil.h>
21 #include <ZLInputStream.h>
26 inline static char convertXDigit(char d
) {
29 } else if (islower(d
)) {
36 void RtfImage::read() const {
37 shared_ptr
<ZLInputStream
> stream
= ZLFile(myFileName
).inputStream();
38 if (!stream
.isNull() && stream
->open()) {
39 myData
= new std::string();
40 myData
->reserve(myLength
/ 2);
41 stream
->seek(myStartOffset
, false);
42 const size_t bufferSize
= 1024;
43 char *buffer
= new char[bufferSize
];
44 for (unsigned int i
= 0; i
< myLength
; i
+= bufferSize
) {
45 size_t toRead
= std::min(bufferSize
, myLength
- i
);
46 if (stream
->read(buffer
, toRead
) != toRead
) {
49 for (size_t j
= 0; j
< toRead
; j
+= 2) {
50 *myData
+= (convertXDigit(buffer
[j
]) << 4) + convertXDigit(buffer
[j
+ 1]);
58 const shared_ptr
<std::string
> RtfImage::stringData() const {
59 if (myData
.isNull()) {