/* * test2 -- ファイルの大きさの確認 */ Result test2() { /* ファイルの正しいページ数が得られるかどうかをチェック */ if (getNumPages(TEST_FILE1) != FILE_SIZE) { fprintf(stderr, "Number of pages is wrong.\n"); return NG; } if (getNumPages(TEST_FILE2) != FILE_SIZE) { fprintf(stderr, "Number of pages is wrong.\n"); return NG; } return OK; }
void MLPageView::resized() { int w = getWidth(); int h = getHeight(); Rectangle<int> myBounds(0, 0, w, h); MLLookAndFeel* myLookAndFeel = (&(getRootViewResources(this).mLookAndFeel)); int u = myLookAndFeel->getGridUnitSize(); int margin = u; int numPages = getNumPages(); for(int i=0; i<numPages; ++i) { mPages[i]->setVisible(i == mCurrPage); mPages[i]->setBounds(myBounds.translated((w + margin)*(i - mCurrPage), 0)); mPages[i]->repaint(); } }
void MLPageView::changeListenerCallback (ChangeBroadcaster* pSender) { if (pSender == &mAnimator) { if(mAnimator.isAnimating(mPages[mCurrPage])) { // animation start // turn off openGL timers ////debug() << "anim off\n" ; } else { ////debug() << "anim on\n" ; // animation end // make invisible all but new page int numPages = getNumPages(); for(int i=0; i<numPages; ++i) { mPages[i]->setVisible(i == mCurrPage); } } } }
GLuint gmshPopplerWrapper::getTextureForPage(double xres, double yres) { int iPage = _currentPage; int numPages = getNumPages(); if(iPage < 0) iPage = 0; if(iPage > numPages - 1) iPage = numPages - 1; std::map<int, GLuint>::iterator it = _pages2textures.find(iPage); if(it != _pages2textures.end()) return it->second; if(!_currentDoc) return 0; poppler::page *page = _currentDoc->create_page(iPage); poppler::page_renderer pr; pr.set_render_hint(poppler::page_renderer::text_antialiasing, true); pr.set_render_hint(poppler::page_renderer::antialiasing, true); poppler::image im = pr.render_page(page, xres, yres, -1, -1, -1); im.save("hop.jpeg", "jpeg"); Fl_RGB_Image *img = new Fl_JPEG_Image("hop.jpeg"); // Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(2048, 2048); glPixelStorei(GL_UNPACK_ROW_LENGTH, img->w()); GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w(), img->h(), 0, (img->d() == 4) ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, img->array); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); _w = img->w(); _h = img->h(); delete img; // delete img2; _pages2textures[iPage] = texture; return texture; }
void Global::generatePDFs(QString dirname) { size_t pageCount = 0; for (size_t s = 0; s < getNumStudents(); s++) { Student& student = db()->getStudent(s); // Use the student name to form the file name for the repot QString clean = student.getStudentName(); // Convert all non alpha/num chars into an underscore for (QString::iterator i = clean.begin(); i != clean.end(); i++) { if (!i->isLetterOrNumber()) *i = '_'; } if (clean.length() == 0) { GINFODIALOG(QString("Cannot render PDF because student %1 does not have a name assigned").arg(s+1)); return; } QString pdfname (dirname + "/report-" + clean + ".pdf"); GDEBUG ("Generating PDF [%s] for student [%s]", qPrintable(pdfname), qPrintable(student.getStudentId())); QPrinter printer (QPrinter::HighResolution); printer.setOutputFormat (QPrinter::PdfFormat); printer.setOutputFileName (pdfname); printer.setPageSize(QPrinter::Letter); printer.setResolution(150); // DPI for the printing printer.setColorMode(QPrinter::GrayScale); QPainter painter; if (!painter.begin(&printer)) // Check for errors here GFATAL("Failed to do QPainter begin()"); // Can use this code to change the text color, but causes larger PDF files // since it must use a color output format instead. //QPen penColor(QColor("#000090")); // Change text to dark blue //painter.setPen(penColor); for (size_t p = 0; p < getNumPagesPerStudent(); p++) { pageCount++; // Add spaces at the end so the widget can resize into the reserved space without a re-layout Global::getStatusLabel()->setText(QString("Generating PDF for student %1 of %2, page %3 of %4 (%5 percent) "). arg(s+1).arg(getNumStudents()).arg(p+1).arg(getNumPagesPerStudent()).arg(rint(0.5+100.0*pageCount/(1.0*getNumPages())))); // Flush out Qt events so that the UI update occurs inside this handler Global::getQApplication()->processEvents(); GDEBUG ("Printing page %zu of %zu for report [%s]", p+1, getNumPagesPerStudent(), qPrintable(pdfname)); QPixmap pix = getPages()->getQPixmap(p+s*getNumPagesPerStudent()); // Scale the pixmap to fit the printer pix = pix.scaled(printer.pageRect().width(), printer.pageRect().height(), Qt::KeepAspectRatio); // Draw the pixmap to the printer painter.drawPixmap (0, 0, pix); // Print out the student details at the top of the page QString title = QString("Name: %1 ID: %2 Page: %3 of %4 Final Grade: %5 of %6").arg(student.getStudentName()).arg(student.getStudentId()).arg(p+1).arg(getNumPagesPerStudent()).arg(student.getTotal()).arg(db()->getTotalMaximum()); painter.drawText(0, 0, title); // Build up a results string to print onto the page QString grades ("Results:"); size_t pageTotal = 0; size_t pageMax = 0; for (size_t q = 0; q < getNumQuestions(); q++) { // See if the question is on this page GASSERT(Global::db()->getQuestionPage(q) != 0, "Cannot have page 0 assigned for question %zu", q); if (Global::db()->getQuestionPage(q) < 0) { GINFODIALOG(QString("Cannot render PDF because question %1 does not have a page assigned").arg(q+1)); return; } if (Global::db()->getQuestionPage(q) == ((int)p+1)) { if (student.getGrade(q) < 0) { GINFODIALOG(QString("Cannot render PDF for student [%1] because question %2 has no grade assigned").arg(student.getStudentName()).arg(q+1)); return; } pageTotal += student.getGrade(q); pageMax += Global::db()->getQuestionMaximum(q); grades += QString(" Q%1 = %2/%3").arg(q+1).arg(student.getGrade(q)).arg(Global::db()->getQuestionMaximum(q)); if (student.getFeedback(q) != "") grades += QString(" [%1]").arg(student.getFeedback(q)); } } grades += QString(" Totals = %1/%2").arg(pageTotal).arg(pageMax); if (pageMax == 0) grades = QString("No Results For This Page"); // Wrap the text to fit a bounding box that is the width of the page, align to the bottom of the page painter.drawText(0, 30, printer.pageRect().width(), printer.pageRect().height()-30, Qt::TextWordWrap | Qt::AlignBottom, grades); // Insert a new page except on the last one if (p < getNumPagesPerStudent()-1) if (!printer.newPage()) // Check for errors here GFATAL("Failed to do newPage() call"); } painter.end(); } Global::getStatusLabel()->setText(""); }