Ejemplo n.º 1
0
GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image, BindOptions options)
{
    if (image.isNull())
        return 0;
    QMutexLocker locker(&m_mutex);
    qint64 key = image.cacheKey();

    // A QPainter is active on the image - take the safe route and replace the texture.
    if (!image.paintingActive()) {
        QOpenGLCachedTexture *entry = m_cache.object(key);
        if (entry && entry->options() == options) {
            context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
            return entry->id();
        }
    }

    QImage img = image;
    if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
        // Scale the pixmap if needed. GL textures needs to have the
        // dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL
        // 2.0 or use the GL_TEXTURE_RECTANGLE texture target
        int tx_w = qNextPowerOfTwo(image.width() - 1);
        int tx_h = qNextPowerOfTwo(image.height() - 1);
        if (tx_w != image.width() || tx_h != image.height()) {
            img = img.scaled(tx_w, tx_h);
        }
    }

    GLuint id = bindTexture(context, key, img, options);
    if (id > 0)
        QImagePixmapCleanupHooks::enableCleanupHooks(image);

    return id;
}
STDMETHODIMP CThumbnailProvider::GetThumbnail(UINT cx, 
                                              HBITMAP *phbmp, 
                                              WTS_ALPHATYPE *pdwAlpha)
{
	*phbmp = NULL; 
    *pdwAlpha = WTSAT_ARGB;

    int width, height;
    QSize size = renderer.defaultSize();

    if(size.width() == size.height()){
        width = cx;
        height = cx;
    } else if (size.width() > size.height()){
        width = cx;
        height = size.height() * ((double)cx / (double)size.width());
    } else {
        width = size.width() * ((double)cx / (double)size.height());
        height = cx;
    }

    QFile * f = new QFile("C:\\dev\\svg.log");
    f->open(QFile::Append);
    f->write(QString("Size: %1 \n.").arg(cx).toAscii());
    f->flush();
    f->close();

    QImage * device = new QImage(width, height, QImage::Format_ARGB32);
    device->fill(Qt::transparent);
    QPainter * painter = new QPainter();
    QFont font;
    QColor color_font = QColor(255, 0, 0);

    painter->begin(device);
    painter->setRenderHints(QPainter::Antialiasing |
                            QPainter::SmoothPixmapTransform |
                            QPainter::TextAntialiasing);
    assert(device->paintingActive() && painter->isActive());
    if(loaded){
        renderer.render(painter);
    } else {
        int font_size = cx / 10;

        font.setStyleHint(QFont::Monospace);
        font.setPixelSize(font_size);

        painter->setPen(color_font);
        painter->setFont(font);
        painter->drawText(font_size, (cx - font_size) / 2, "Invalid SVG file.");
    }
    painter->end();

    assert(!device->isNull());
#ifndef NDEBUG
    device->save(QString("C:\\dev\\%1.png").arg(QDateTime::currentMSecsSinceEpoch()), "PNG");
#endif
    *phbmp = QPixmap::fromImage(*device).toWinHBITMAP(QPixmap::Alpha);
    assert(*phbmp != NULL);

    delete painter;
    delete device;

	if( *phbmp != NULL )
		return NOERROR;
	return E_NOTIMPL;

}