QImage DviGenerator::image( Okular::PixmapRequest *request ) { dviPageInfo *pageInfo = new dviPageInfo(); pageSize ps; QImage ret; pageInfo->width = request->width(); pageInfo->height = request->height(); pageInfo->pageNumber = request->pageNumber() + 1; // pageInfo->resolution = m_resolution; QMutexLocker lock( userMutex() ); if ( m_dviRenderer ) { SimplePageSize s = m_dviRenderer->sizeOfPage( pageInfo->pageNumber ); /* if ( s.width() != pageInfo->width) */ // if (!useDocumentSpecifiedSize) // s = userPreferredSize; if (s.isValid()) { ps = s; /* it should be the user specified size, if any, instead */ } pageInfo->resolution = (double)(pageInfo->width)/ps.width().getLength_in_inch(); #if 0 kDebug(DviDebug) << *request << ", res:" << pageInfo->resolution << " - (" << pageInfo->width << "," << ps.width().getLength_in_inch() << ")," << ps.width().getLength_in_mm() << endl; #endif m_dviRenderer->drawPage( pageInfo ); if ( ! pageInfo->img.isNull() ) { kDebug(DviDebug) << "Image OK"; ret = pageInfo->img; if ( !m_linkGenerated[ request->pageNumber() ] ) { request->page()->setObjectRects( generateDviLinks( pageInfo ) ); m_linkGenerated[ request->pageNumber() ] = true; } } } lock.unlock(); delete pageInfo; return ret; }
void FaxRenderer::drawPage(double resolution, RenderedDocumentPage* page) { #ifdef KF_DEBUG kdDebug() << "FaxRenderer::drawPage(documentPage*) called, page number " << page->getPageNumber() << endl; #endif // Paranoid safety checks if (page == 0) { kdError() << "FaxRenderer::drawPage(documentPage*) called with argument == 0" << endl; return; } if (page->getPageNumber() == 0) { kdError() << "FaxRenderer::drawPage(documentPage*) called for a documentPage with page number 0" << endl; return; } // Wait for all access to this documentRenderer to finish mutex.lock(); // more paranoid safety checks if (page->getPageNumber() > numPages) { kdError() << "FaxRenderer::drawPage(documentPage*) called for a documentPage with page number " << page->getPageNumber() << " but the current fax file has only " << numPages << " pages." << endl; mutex.unlock(); return; } QImage img = fax.page(page->getPageNumber() - 1); SimplePageSize psize = pageSizes[page->getPageNumber() - 1]; if (psize.isValid()) { QPainter *foreGroundPaint = page->getPainter(); if (foreGroundPaint != 0) { // Compute an image for the page. // WARNING: It may be tempting to compute the image size in // pixel, using page->height() and page->width(). DON'T DO // THAT. KViewShell uses transformations e.g. to rotate the // page, and sets the argument 'resolution' accordingly. Similar // problems occur if KViewShell required a shrunken version of // the page, e.g. to print multiple pages on one sheet of paper. int width_in_pixel = qRound(resolution * psize.width().getLength_in_inch()); int height_in_pixel = qRound(resolution * psize.height().getLength_in_inch()); img = img.smoothScale(width_in_pixel, height_in_pixel); foreGroundPaint->drawImage(0, 0, img); page->returnPainter(foreGroundPaint); } } else kdError() << "FaxRenderer::drawPage() called, but page size for page " << page->getPageNumber() << " is invalid." << endl; // To indicate that the page was drawn, we set the appropriate flas in the page structure page->isEmpty = false; mutex.unlock(); }
void DviGenerator::fillViewportFromAnchor( Okular::DocumentViewport &vp, const Anchor &anch, int pW, int pH ) const { vp.pageNumber = anch.page - 1; SimplePageSize ps = m_dviRenderer->sizeOfPage( vp.pageNumber ); double resolution = 0; if (ps.isValid()) resolution = (double)(pW)/ps.width().getLength_in_inch(); else resolution = m_resolution; double py = (double)anch.distance_from_top.getLength_in_inch()*resolution + 0.5; vp.rePos.normalizedX = 0.5; vp.rePos.normalizedY = py/(double)pH; vp.rePos.enabled = true; vp.rePos.pos = Okular::DocumentViewport::Center; }