void IWORKCollector::drawMedia(const IWORKMediaPtr_t &media) { if (bool(media) && bool(media->m_geometry) && bool(media->m_content) && bool(media->m_content->m_data) && bool(media->m_content->m_data->m_stream)) { const glm::dmat3 trafo = m_levelStack.top().m_trafo; const RVNGInputStreamPtr_t input = media->m_content->m_data->m_stream; string mimetype(media->m_content->m_data->m_mimeType); if (mimetype.empty()) mimetype = detectMimetype(input); if (!mimetype.empty()) { input->seek(0, librevenge::RVNG_SEEK_END); const unsigned long size = input->tell(); input->seek(0, librevenge::RVNG_SEEK_SET); unsigned long readBytes = 0; const unsigned char *const bytes = input->read(size, readBytes); if (readBytes != size) throw GenericException(); const glm::dvec3 pos = trafo * glm::dvec3(0, 0, 1); const double width = media->m_geometry->m_size.m_width; const double height = media->m_geometry->m_size.m_height; const glm::dvec3 dim = trafo * glm::dvec3(width, height, 0); drawMedia(pos[0], pos[1], dim[0], dim[1], mimetype, librevenge::RVNGBinaryData(bytes, size)); } } }
IWORKMemoryStream::IWORKMemoryStream(const RVNGInputStreamPtr_t &input) : m_data() , m_length(0) , m_pos(0) { const auto begin = (unsigned long) input->tell(); if (input->seek(0, librevenge::RVNG_SEEK_END)) { while (!input->isEnd()) readU8(input); } const auto end = (unsigned long) input->tell(); input->seek((long) begin, librevenge::RVNG_SEEK_SET); read(input, static_cast<unsigned>(end - begin)); }
void IWAObjectIndex::scanFragment(const unsigned id, const RVNGInputStreamPtr_t &stream) try { while (!stream->isEnd()) { // scan a single object const uint64_t headerLen = readUVar(stream); const long start = stream->tell(); const IWAMessage header(stream, headerLen); uint64_t dataLen = 0; optional<unsigned> type; bool ok=true; for (auto const &info : header.message(2)) // go through all data information { if (!info.uint64(3)) { ok=false; break; } dataLen += info.uint64(3).get(); if (!type) type=info.uint32(1).optional(); // normally, all data must define the same type } if (!ok) break; if (header.uint32(1)) { const ObjectRecord rec(stream, get_optional_value_or(type, 0), start, (unsigned long)(headerLen), (unsigned long)(dataLen)); m_fragmentObjectMap[header.uint32(1).get()] = make_pair(id, rec); } if (stream->seek(start + long(headerLen) + long(dataLen), librevenge::RVNG_SEEK_SET) != 0) break; } } catch (...) { // just read as much as possible }
void IWORKMemoryStream::read(const RVNGInputStreamPtr_t &input, const unsigned length) { if (0 == length) return; if (!bool(input)) throw EndOfStreamException(); unsigned long readBytes = 0; const unsigned char *const data = input->read(length, readBytes); if (length != readBytes) throw EndOfStreamException(); m_length = (long) length; assign(data, length); }
RVNGInputStreamPtr_t uncompress(const RVNGInputStreamPtr_t &input) { vector<unsigned char> data; while (!input->isEnd()) { readU8(input); const unsigned long blockLength = readU16(input); readU8(input); if (!uncompressBlock(input, (std::min)(blockLength, getRemainingLength(input)), data)) throw CompressionException(); } return boost::make_shared<IWORKMemoryStream>(data); }