⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generator_pdf.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    resannot->style.opacity=ann->style.opacity;    resannot->style.width=ann->style.width;    resannot->style.style=(Poppler::Annotation::LineStyle)ann->style.style;    resannot->style.xCorners=ann->style.xCorners;    resannot->style.yCorners=ann->style.yCorners;    resannot->style.marks=ann->style.marks;    resannot->style.spaces=ann->style.spaces;    resannot->style.effect=(Poppler::Annotation::LineEffect)ann->style.effect;    resannot->style.effectIntensity=ann->style.effectIntensity;    resannot->window.flags=ann->window.flags;    resannot->window.topLeft=QPointF(ann->window.topLeft.x,ann->window.topLeft.y);    resannot->window.width=ann->window.width;    resannot->window.height=ann->window.height;    resannot->window.title=ann->window.title;    resannot->window.summary=ann->window.summary;    resannot->window.text=ann->window.text;        foreach(Annotation::Revision arev, ann->revisions)    {        Poppler::Annotation::Revision trev;        trev.annotation=getPopplerAnnot(arev.annotation);        trev.scope=(Poppler::Annotation::RevScope)arev.scope;        trev.type=(Poppler::Annotation::RevType)arev.type;        resannot->revisions.append(trev);    }        return resannot;}Annotation* getokularAnnot(Poppler::Annotation* ann){    if(!ann)        return NULL;    Annotation* resannot;    if(ann->subType()==Poppler::Annotation::AText)    {        Poppler::TextAnnotation * a=(Poppler::TextAnnotation *)ann;        TextAnnotation * t=new TextAnnotation();        resannot=t;                t->textType = (TextAnnotation::TextType)a->textType;        t->textIcon = a->textIcon;        t->textFont = a->textFont;        t->inplaceAlign = a->inplaceAlign;        t->inplaceText = a->inplaceText;        t->inplaceIntent = (TextAnnotation::InplaceIntent)a->inplaceIntent;        for(int i=0;i<3;i++)        {            t->inplaceCallout[i]=NormalizedPoint(a->inplaceCallout[i].x(),a->inplaceCallout[i].y());        }    }    else if(ann->subType()==Poppler::Annotation::ALine)    {        Poppler::LineAnnotation * a=(Poppler::LineAnnotation *)ann;        LineAnnotation * t=new LineAnnotation();        resannot=t;        foreach(QPointF pt, a->linePoints)        {                t->linePoints.append(NormalizedPoint(pt.x(), pt.y()));        }        t->lineStartStyle = (LineAnnotation::TermStyle)a->lineStartStyle;        t->lineEndStyle = (LineAnnotation::TermStyle)a->lineEndStyle;        t->lineClosed = a->lineClosed;        t->lineInnerColor = a->lineInnerColor;        t->lineLeadingFwdPt = a->lineLeadingFwdPt;        t->lineLeadingBackPt = a->lineLeadingBackPt;        t->lineShowCaption = a->lineShowCaption;        t->lineIntent =  (LineAnnotation::LineIntent) a->lineIntent;    }    else if(ann->subType()==Poppler::Annotation::AGeom)    {        Poppler::GeomAnnotation *a = (Poppler::GeomAnnotation*) ann;        GeomAnnotation * t=new GeomAnnotation();        resannot=t;                t->geomType = (GeomAnnotation::GeomType)a->geomType;        t->geomInnerColor = a->geomInnerColor;        t->geomWidthPt = a->geomWidthPt;    }    else if(ann->subType()==Poppler::Annotation::AHighlight)    {        Poppler::HighlightAnnotation *a = (Poppler::HighlightAnnotation*) ann;        HighlightAnnotation * t=new HighlightAnnotation();        resannot=t;        t->highlightType = (HighlightAnnotation::HighlightType)a->highlightType;        foreach(Poppler::HighlightAnnotation::Quad ua, a->highlightQuads)        {            HighlightAnnotation::Quad ut;            for(int i=0;i<4;i++)            {                ut.points[i]=NormalizedPoint(ua.points[i].x(),ua.points[i].y());            }            ut.capStart=ua.capStart;            ut.capEnd=ua.capEnd;            ut.feather=ua.feather;            t->highlightQuads.append(ut);        }    }    else if(ann->subType()==Poppler::Annotation::AStamp)    {        Poppler::StampAnnotation *a=(Poppler::StampAnnotation*)ann;        StampAnnotation * t=new StampAnnotation();        resannot=t;        t->stampIconName = a->stampIconName;    }    else if(ann->subType()==Poppler::Annotation::AInk)    {        Poppler::InkAnnotation *a=(Poppler::InkAnnotation*)ann;        InkAnnotation * t=new InkAnnotation();        resannot=t;                foreach(QLinkedList<QPointF> alist, a->inkPaths)        {            QLinkedList<NormalizedPoint> lt;            foreach(QPointF pa, alist)            {                lt.append(NormalizedPoint(pa.x(),pa.y()));            }            t->inkPaths.append(lt);        }    }    else    {        resannot=new Annotation();    }     //COMMON params:    resannot->author=ann->author;    resannot->contents=ann->contents;    resannot->uniqueName=ann->uniqueName;    resannot->modifyDate=ann->modifyDate;    resannot->creationDate=ann->creationDate;    resannot->flags=ann->flags;    resannot->boundary=NormalizedRect(ann->boundary.left(),ann->boundary.top(),                                      ann->boundary.right(),ann->boundary.bottom());    resannot->style.color=ann->style.color;    resannot->style.opacity=ann->style.opacity;    resannot->style.width=ann->style.width;    resannot->style.style=(Annotation::LineStyle)ann->style.style;    resannot->style.xCorners=ann->style.xCorners;    resannot->style.yCorners=ann->style.yCorners;    resannot->style.marks=ann->style.marks;    resannot->style.spaces=ann->style.spaces;    resannot->style.effect=(Annotation::LineEffect)ann->style.effect;    resannot->style.effectIntensity=ann->style.effectIntensity;    resannot->window.flags=ann->window.flags;    resannot->window.topLeft=NormalizedPoint(ann->window.topLeft.x(),ann->window.topLeft.y());    resannot->window.width=ann->window.width;    resannot->window.height=ann->window.height;    resannot->window.title=ann->window.title;    resannot->window.summary=ann->window.summary;    resannot->window.text=ann->window.text;        foreach(Poppler::Annotation::Revision arev, ann->revisions)    {        Annotation::Revision trev;        trev.annotation=getokularAnnot(arev.annotation);        trev.scope=(Annotation::RevScope)arev.scope;        trev.type=(Annotation::RevType)arev.type;        resannot->revisions.append(trev);    }           //a->window.width = (int)(page->width() * a->window.width);        //a->window.height = (int)(page->height() * a->window.height);        //a->window.width = a->window.width < 200 ? 200 : a->window.width;        // a->window.height = a->window.height < 120 ? 120 : a->window.height;        // resize annotation's geometry to an icon        // TODO okular geom.right = geom.left + 22.0 / page->width();        // TODO okular geom.bottom = geom.top + 22.0 / page->height();    return resannot;        }        bool PDFGenerator::saveDocumentAs(const QString &filePath){    if(!pdfdoc)        return false;    //set annotations    for(int i=0;i<pdfdoc->numPages();i++)    {        Poppler::Page * popplerpage=pdfdoc->page(i);        const KPDFPage * pdfpage=m_document->page(i);        const QLinkedList< Annotation * > okularannots=pdfpage->getAnnotations();        QList<Poppler::Annotation*> popplerannots;        foreach(Annotation * ann, okularannots)        {            Poppler::Annotation* pann = getPopplerAnnot(ann);            popplerannots.append(pann);        }        popplerpage->setAnnotations(popplerannots);    }    QString filename=filePath;    if(filename.startsWith("file://"))    {        filename.remove(0, 7);    }    kDebug()<<"astario:   save file as:"<<filename<<endl;    return pdfdoc->saveAs(filename);}bool PDFGenerator::closeDocument(){    // remove internal objects    docLock.lock();    delete pdfdoc;    pdfdoc = 0;    docLock.unlock();    return true;}void PDFGenerator::loadPages(QVector<KPDFPage*> &pagesVector, int rotation, bool clear){    // TODO XPDF 3.01 check    int count=pagesVector.count(),w=0,h=0;    for ( int i = 0; i < count ; i++ )    {        // get xpdf page        Poppler::Page * p = pdfdoc->page( i );        QSize pSize = p->pageSize();        w = pSize.width();        h = pSize.height();        int orientation=0;        switch (p->orientation())        {          case Poppler::Page::Landscape: orientation = 1; break;          case Poppler::Page::UpsideDown: orientation = 2; break;          case Poppler::Page::Seascape: orientation = 3; break;          case Poppler::Page::Portrait: orientation = 0; break;        }        if (rotation % 2 == 1)          qSwap(w,h);        // init a kpdfpage, add transition and annotation information        KPDFPage * page = new KPDFPage( i, w, h, orientation );        addTransition( p, page );        if ( true ) //TODO real check          addAnnotations( p, page );// 	    kWarning() << page->width() << "x" << page->height() << endl;// need a way to find efficient (maybe background textpage generation)	kDebug() << "loadpages with rotation" << rotation << " and orientation " << orientation << endl;	docLock.lock();	QList<Poppler::TextBox*> textList = p->textList((Poppler::Page::Rotation)rotation);	docLock.unlock();	page->setSearchPage(abstractTextPage(textList, page->height(), page->width(), orientation));		qDeleteAll(textList);	delete p;        if (clear && pagesVector[i])            delete pagesVector[i];        // set the kpdfpage at the right position in document's pages vector        pagesVector[i] = page;// 	kWarning() << page->width() << "x" << page->height() << endl;    }}QString PDFGenerator::getText( const RegularAreaRect * area, KPDFPage * page  ){    QRect rect = area->first()->geometry((int)page->width(),(int)page->height());    Poppler::Page *pp = pdfdoc->page( page->number() );    QString text = pp->text(rect);    delete pp;    return text;}RegularAreaRect * PDFGenerator::findText (const QString & text, SearchDir dir,     const bool strictCase, const RegularAreaRect * sRect, KPDFPage * page ){    dir = sRect ? NextRes : FromTop;    QRectF rect;    if ( dir == NextRes )    {        // when using thein ternal search we only play with normrects        rect.setLeft( sRect->first()->left * page->width() );        rect.setTop( sRect->first()->top * page->height() );        rect.setRight( sRect->first()->right * page->width() );        rect.setBottom( sRect->first()->bottom * page->height() );    }    // this loop is only for 'bad case' Reses    bool found = false;    Poppler::Page *pp = pdfdoc->page( page->number() );    docLock.lock();    Poppler::Page::SearchMode sm;    if (strictCase) sm = Poppler::Page::CaseSensitive;    else sm = Poppler::Page::CaseInsensitive;    while ( !found )    {        if ( dir == FromTop ) found = pp->search(text, rect, Poppler::Page::FromTop, sm);        else if ( dir == NextRes ) found = pp->search(text, rect, Poppler::Page::NextResult, sm);        else if ( dir == PrevRes ) found = pp->search(text, rect, Poppler::Page::PreviousResult, sm);        // if not found (even in case unsensitive search), terminate        if ( !found )            break;    }    docLock.unlock();    delete pp;    // if the page was found, return a new normalizedRect    if ( found )    {        RegularAreaRect *ret=new RegularAreaRect;        ret->append (new NormalizedRect( rect.left() / page->width(), rect.top() / page->height(),             rect.right() / page->width(), rect.bottom() / page->height() ) );        return ret;    }    return 0;}const DocumentInfo * PDFGenerator::generateDocumentInfo(){    if ( docInfoDirty )    {        docLock.lock();                docInfo.set( "mimeType", "application/pdf" );                if ( pdfdoc )        {            // compile internal structure reading properties from PDFDoc            docInfo.set( "title", pdfdoc->info("Title"), i18n("Title") );            docInfo.set( "subject", pdfdoc->info("Subject"), i18n("Subject") );            docInfo.set( "author", pdfdoc->info("Author"), i18n("Author") );            docInfo.set( "keywords", pdfdoc->info("Keywords"), i18n("Keywords") );            docInfo.set( "creator", pdfdoc->info("Creator"), i18n("Creator") );            docInfo.set( "producer", pdfdoc->info("Producer"), i18n("Producer") );            docInfo.set( "creationDate", KGlobal::locale()->formatDateTime( pdfdoc->date("CreationDate"), false, true ), i18n("Created") );            docInfo.set( "modificationDate", KGlobal::locale()->formatDateTime( pdfdoc->date("ModDate"), false, true ), i18n("Modified") );            docInfo.set( "format", i18nc( "PDF v. <version>", "PDF v. %1",                         QString::number( pdfdoc->pdfVersion() ) ), i18n( "Format" ) );            docInfo.set( "encryption", pdfdoc->isEncrypted() ? i18n( "Encrypted" ) : i18n( "Unencrypted" ),                         i18n("Security") );            docInfo.set( "optimization", pdfdoc->isLinearized() ? i18n( "Yes" ) : i18n( "No" ),                         i18n("Optimized") );            docInfo.set( "pages", QString::number( pdfdoc->numPages() ), i18n("Pages") );        }        else        {            // TODO not sure one can reach here, check and if it is not possible, remove the code            docInfo.set( "title", i18n("Unknown"), i18n("Title") );            docInfo.set( "subject", i18n("Unknown"), i18n("Subject") );            docInfo.set( "author", i18n("Unknown"), i18n("Author") );            docInfo.set( "keywords", i18n("Unknown"), i18n("Keywords") );            docInfo.set( "creator", i18n("Unknown"), i18n("Creator") );            docInfo.set( "producer", i18n("Unknown"), i18n("Producer") );            docInfo.set( "creationDate", i18n("Unknown Date"), i18n("Created") );            docInfo.set( "modificationDate", i18n("Unknown Date"), i18n("Modified") );            docInfo.set( "format", "PDF", i18n( "Format" ) );            docInfo.set( "encryption", i18n( "Unknown Encryption" ), i18n( "Security" ) );            docInfo.set( "optimization", i18n( "Unknown Optimization" ), i18n( "Optimized" ) );            docInfo.set( "pages", i18n("Unknown"), i18n("Pages") );        }        docLock.unlock();        // if pdfdoc is valid then we cached good info -> don't cache them again        if ( pdfdoc )            docInfoDirty = false;    }    return &docInfo;}const DocumentSynopsis * PDFGenerator::generateDocumentSynopsis(){    if ( !docSynopsisDirty )        return &docSyn;    if ( !pdfdoc )        return NULL;    docLock.lock();    QDomDocument *toc = pdfdoc->toc();    docLock.unlock();    if ( !toc )        return NULL;    docSyn = DocumentSynopsis();    addSynopsisChildren(toc, &docSyn);    delete toc;    docSynopsisDirty = false;    return &docSyn;}const DocumentFonts * PDFGenerator::generateDocumentFonts(){    if ( !docFontsDirty )        return &docFonts;    // initialize fonts dom    docFonts = DocumentFonts();    docFonts.appendChild( docFonts.createElement( "Fonts" ) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -