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

📄 kwqpixmap.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
字号:
/*
 * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
 * Portions Copyright (c) 2005 Nokia Corporation, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "KWQPixmap.h"

#include "WebCoreImageRenderer.h"
#include "WebCoreImageRendererFactory.h"

#include <e32std.h>

QPixmap *KWQLoadPixmap(const char *name)
{
	QString str = QString::fromLatin1(name);
	TPtrC ptrStr = str.Des();
    QPixmap *p = new QPixmap(TWebCoreImageRendererFactory::Factory()->ImageRendererWithName(ptrStr));
    return p;
}

bool canRenderImageType(const QString &type)
{
	TPtrC tType = type.Des();

    CArrayFix<TPtrC>* mimes = TWebCoreImageRendererFactory::Factory()->SupportedMIMETypes();
    if (!mimes)
        return false;
    TKeyArrayFix key(0,ECmpNormal);
    TInt index;
    return (mimes->Find((tType),key,index))==0;
}

QPixmap::QPixmap()
{
    imageRenderer = NULL;
    needCopyOnWrite = false;
}

QPixmap::QPixmap( const QPixmap& other )
	: imageRenderer( other.imageRenderer )
    , mimeType( other.mimeType )
	, needCopyOnWrite( other.needCopyOnWrite )
	{
    if (imageRenderer)
        imageRenderer->Ref();
	}

QPixmap& QPixmap::operator=( const QPixmap& other )
{
    mimeType = other.mimeType;

    if (imageRenderer)
        imageRenderer->Deref();
	imageRenderer = other.imageRenderer;
    if (imageRenderer)
        {
        imageRenderer->Ref();
        needCopyOnWrite = true;
        }
	return *this;
}

QPixmap::QPixmap(MWebCoreImageRenderer* r)
{
    imageRenderer = r;
    if (imageRenderer)
        imageRenderer->Ref();
    needCopyOnWrite = false;
}


QPixmap::QPixmap(QString MIME)
{
    imageRenderer = NULL;
    needCopyOnWrite = false;
    mimeType = MIME;
}

QPixmap::QPixmap(const QSize &sz)
{
    // never called
    ASSERT(0);
}

QPixmap::QPixmap(const QByteArray &bytes)
{
	TPtrC8 str;
	str.Set((const unsigned char*)bytes.data(), (TInt)bytes.size());
    imageRenderer = TWebCoreImageRendererFactory::Factory()->ImageRendererWithBytes(str);
    if (imageRenderer)
        imageRenderer->Ref();
    needCopyOnWrite = false;
}

QPixmap::QPixmap(const QByteArray &bytes, QString MIME)
{
    needCopyOnWrite = false;
    mimeType = MIME;
	TPtrC8 str((const unsigned char*)bytes.data(), (TInt)bytes.size());
    imageRenderer = TWebCoreImageRendererFactory::Factory()->ImageRendererWithBytes(str, mimeType.Des());
    if (imageRenderer)
        imageRenderer->Ref();
}

QPixmap::QPixmap(int w, int h)
{
    // never called
    ASSERT(0);
}


QPixmap::~QPixmap()
{
    if (imageRenderer)
        imageRenderer->Deref();
}

bool QPixmap::receivedData(const QByteArray &bytes, bool isComplete, khtml::CachedImageCallback *decoderCallback)
{

    // ### TODO decoderCallback
	if( isComplete ) {
	    if (imageRenderer == NULL) {
            imageRenderer = TWebCoreImageRendererFactory::Factory()->ImageRendererWithMimeType(mimeType.Des());
	        if (imageRenderer)
	            imageRenderer->Ref();
	    }
		TPtrC8 str((const unsigned char*)bytes.data(), (TInt)bytes.size());
        CWebCoreImageCallbackWrapper* wrapper = imageRenderer->InitCallbackWrapper();
        wrapper->SetCallback( decoderCallback );
	    return imageRenderer->IncrementalLoadWithBytes(str, isComplete);
	}

	return false;
}

bool QPixmap::mask() const
{
    return false;
}

bool QPixmap::isNull() const
{
    return (imageRenderer == NULL) || (imageRenderer->IsNull());
}

QSize QPixmap::size() const
{
    if (imageRenderer == NULL) {
        return QSize(0, 0);
    }
    TSize sz = imageRenderer->Size();
    return QSize((int)sz.iWidth, (int)sz.iHeight);
}

QRect QPixmap::rect() const
{
    if (imageRenderer == NULL) {
        return QRect(0, 0, 0, 0);
    }
    TSize sz = imageRenderer->Size();
    return QRect(0, 0, (int)sz.iWidth, (int)sz.iHeight);
}

int QPixmap::width() const
{
    if (imageRenderer == NULL) {
        return 0;
    }
    return (int)(imageRenderer->Size().iWidth);
}

int QPixmap::height() const
{
    if (imageRenderer == NULL) {
        return 0;
    }
    return (int)(imageRenderer->Size().iHeight);
}

void QPixmap::resize(const QSize &sz)
{
    resize(sz.width(),sz.height());
}


void QPixmap::resize(int w, int h)
{
    if (needCopyOnWrite) {
        MWebCoreImageRenderer* newr = imageRenderer->Copy();
        decreaseUseCount();
        imageRenderer = newr;
        increaseUseCount();
        needCopyOnWrite = false;
    }
    imageRenderer->Resize(TSize(w, h));
}

QPixmap QPixmap::xForm(const QWMatrix &xmatrix) const
{
    // This function is only called when an image needs to be scaled.
    // We can depend on render_image.cpp to call resize AFTER
    // creating a copy of the image to be scaled. So, this
    // implementation simply returns a copy of the image. Note,
    // this assumption depends on the implementation of
    // RenderImage::printObject.
    return *this;
}


void QPixmap::increaseUseCount() const
{
	if( imageRenderer )
    	imageRenderer->Ref();
}

void QPixmap::decreaseUseCount() const
{
	if( imageRenderer )
	    imageRenderer->Deref();
}

void QPixmap::stopAnimations()
{
	if( imageRenderer )
	    imageRenderer->StopAnimation();
}

void QPixmap::flushRasterCache()
{
	if( imageRenderer )
	    imageRenderer->FlushRasterCache();
}

bool QPixmap::shouldUseThreadedDecoding()
{
    return true;
}

void QPixmap::resetAnimation()
{
    /*if (imageRenderer) {
        [imageRenderer resetAnimation];
    }*/
}

⌨️ 快捷键说明

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