void DjVuSource::ReadAnnotations(GP<ByteStream> pInclStream, set<GUTF8String>& processed, GP<ByteStream> pAnnoStream) { // Look for shared annotations GUTF8String strInclude; char buf[1024]; int nLength; while ((nLength = pInclStream->read(buf, 1024))) strInclude += GUTF8String(buf, nLength); // Eat '\n' in the beginning and at the end while (strInclude.length() > 0 && strInclude[0] == '\n') strInclude = strInclude.substr(1, static_cast<unsigned int>(-1)); while (strInclude.length() > 0 && strInclude[static_cast<int>(strInclude.length()) - 1] == '\n') strInclude.setat(strInclude.length() - 1, 0); if (strInclude.length() > 0 && processed.find(strInclude) == processed.end()) { processed.insert(strInclude); GURL urlInclude = m_pDjVuDoc->id_to_url(strInclude); GP<DataPool> pool = m_pDjVuDoc->request_data(NULL, urlInclude); GP<ByteStream> stream = pool->get_stream(); GP<IFFByteStream> iff(IFFByteStream::create(stream)); // Check file format GUTF8String chkid; if (!iff->get_chunk(chkid) || (chkid != "FORM:DJVI" && chkid != "FORM:DJVU" && chkid != "FORM:PM44" && chkid != "FORM:BM44")) { return; } // Find chunk with page info while (iff->get_chunk(chkid) != 0) { GP<ByteStream> chunk_stream = iff->get_bytestream(); if (chkid == "INCL") { ReadAnnotations(pInclStream, processed, pAnnoStream); } else if (chkid == "FORM:ANNO") { pAnnoStream->copy(*chunk_stream); } else if (chkid == "ANTa" || chkid == "ANTz") { const GP<IFFByteStream> iffout = IFFByteStream::create(pAnnoStream); iffout->put_chunk(chkid); iffout->copy(*chunk_stream); iffout->close_chunk(); } iff->seek_close_chunk(); } } }
void lt_XMLParser::Impl::ChangeText( const int width, const int height, DjVuFile &dfile, const lt_XMLTags &tags ) { dfile.resume_decode(true); GP<DjVuText> text = DjVuText::create(); GP<DjVuTXT> txt = text->txt = DjVuTXT::create(); // to store the new text GP<ByteStream> textbs = ByteStream::create(); GP<DjVuInfo> info=(dfile.info); if(info) { const int h=info->height; const int w=info->width; txt->page_zone.text_start = 0; DjVuTXT::Zone &parent=txt->page_zone; parent.rect.xmin=0; parent.rect.ymin=0; parent.rect.ymax=h; parent.rect.xmax=w; double ws=1.0; if(width && width != w) { ws=((double)w)/((double)width); } double hs=1.0; if(height && height != h) { hs=((double)h)/((double)height); } make_child_layer(parent, tags, *textbs, h, ws,hs); textbs->write8(0); long len = textbs->tell(); txt->page_zone.text_length = len; textbs->seek(0,SEEK_SET); textbs->read(txt->textUTF8.getbuf(len), len); dfile.change_text(txt,false); } }
void analyze_incl_chunk(const GURL &url) { GP<ByteStream> gbs = ByteStream::create(url,"rb"); char buffer[24]; memset(buffer, 0, sizeof(buffer)); gbs->read(buffer,sizeof(buffer)); char *s = buffer; if (!strncmp(s, "AT&T", 4)) s += 4; if (strncmp(s, "FORM", 4) || strncmp(s+8, "DJVI", 4)) G_THROW("Expecting a valid FORM:DJVI chunk in the included file"); gbs->seek(0); GP<IFFByteStream> giff=IFFByteStream::create(gbs); GUTF8String chkid; giff->get_chunk(chkid); // FORM:DJVI for(; giff->get_chunk(chkid); giff->close_chunk()) if (chkid=="Djbz") analyze_djbz_chunk(giff->get_bytestream()); }