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

📄 qpaintengine_raster.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                ++e;                QT_FT_Vector ep_fixed = { qreal_to_fixed_26_6((e)->x()),                                          qreal_to_fixed_26_6((e)->y()) };                m_points << cp1_fixed << cp2_fixed << ep_fixed;                m_tags << QT_FT_CURVE_TAG_CUBIC                       << QT_FT_CURVE_TAG_CUBIC                       << QT_FT_CURVE_TAG_ON;                types += 2;                i += 2;            }            break;        default:            break;        }        ++types;        ++e;    }    // close the very last subpath    m_contours << m_points.size() - 1;    m_outline.n_contours = m_contours.size();    m_outline.n_points = m_points.size();    m_outline.points = m_points.data();    m_outline.tags = m_tags.data();    m_outline.contours = m_contours.data();#ifdef QT_DEBUG_CONVERT    printf("QFTOutlineMapper::endOutline\n");    printf(" - contours: %d\n", m_outline.n_contours);    for (int i=0; i<m_outline.n_contours; ++i) {        printf("   - %d\n", m_outline.contours[i]);    }    printf(" - points: %d\n", m_outline.n_points);    for (int i=0; i<m_outline.n_points; ++i) {        printf("   - %d -- %.2f, %.2f, (%d, %d)\n", i,               m_outline.points[i].x / 64.0,               m_outline.points[i].y / 64.0,               m_outline.points[i], m_outline.points[i]);    }#endif}void QFTOutlineMapper::clipElements(const QPointF *elements,                                    const QPainterPath::ElementType *types,                                    int element_count){    // We could save a bit of time by actually implementing them fully    // instead of going through convenience functionallity, but since    // this part of code hardly every used, it shouldn't matter.    QPainterPath path;    for (int i=0; i<element_count; ++i) {        switch (types[i]) {        case QPainterPath::MoveToElement:            path.moveTo(elements[i]);            break;        case QPainterPath::LineToElement:            path.lineTo(elements[i]);            break;        case QPainterPath::CurveToElement:            path.cubicTo(elements[i], elements[i+1], elements[i+2]);            i += 2;            break;        default:            break;        }    }    QPolygonF polygon = path.toFillPolygon();    QPointF *clipped_points;    int clipped_count;    m_clipper.clipPolygon((QRasterFloatPoint *) polygon.constData(), polygon.size(),                          ((QRasterFloatPoint **) &clipped_points), &clipped_count, true);#ifdef QT_DEBUG_CONVERT    printf(" - shape was clipped\n");    for (int i=0; i<clipped_count; ++i) {        printf("   - %.2f, -%.2f\n", clipped_points[i].x(), clipped_points[i].y());    }#endif    if (!clipped_count) {        m_valid = false;        return;    }    QPainterPath::ElementType *point_types = new QPainterPath::ElementType[clipped_count];    point_types[0] = QPainterPath::MoveToElement;    for (int i=0; i<clipped_count; ++i) point_types[i] = QPainterPath::LineToElement;    convertElements(clipped_points, point_types, clipped_count);    delete[] point_types;}static void qt_ft_outline_move_to(qfixed x, qfixed y, void *data){    ((QFTOutlineMapper *) data)->moveTo(QPointF(qt_fixed_to_real(x), qt_fixed_to_real(y)));}static void qt_ft_outline_line_to(qfixed x, qfixed y, void *data){    ((QFTOutlineMapper *) data)->lineTo(QPointF(qt_fixed_to_real(x), qt_fixed_to_real(y)));}static void qt_ft_outline_cubic_to(qfixed c1x, qfixed c1y,                             qfixed c2x, qfixed c2y,                             qfixed ex, qfixed ey,                             void *data){    ((QFTOutlineMapper *) data)->curveTo(QPointF(qt_fixed_to_real(c1x), qt_fixed_to_real(c1y)),                                         QPointF(qt_fixed_to_real(c2x), qt_fixed_to_real(c2y)),                                         QPointF(qt_fixed_to_real(ex), qt_fixed_to_real(ey)));}#if !defined(QT_NO_DEBUG) && 0static void qt_debug_path(const QPainterPath &path){    const char *names[] = {        "MoveTo     ",        "LineTo     ",        "CurveTo    ",        "CurveToData"    };    printf("\nQPainterPath: elementCount=%d\n", path.elementCount());    for (int i=0; i<path.elementCount(); ++i) {        const QPainterPath::Element &e = path.elementAt(i);        Q_ASSERT(e.type >= 0 && e.type <= QPainterPath::CurveToDataElement);        printf(" - %3d:: %s, (%.2f, %.2f)\n", i, names[e.type], e.x, e.y);    }}#endifQRasterPaintEngine::QRasterPaintEngine()    : QPaintEngine(*(new QRasterPaintEnginePrivate),                   QPaintEngine::PaintEngineFeatures(AllFeatures)        ){    init();}QRasterPaintEngine::QRasterPaintEngine(QRasterPaintEnginePrivate &dd)    : QPaintEngine(dd, QPaintEngine::PaintEngineFeatures(AllFeatures)){    init();}void QRasterPaintEngine::init(){    Q_D(QRasterPaintEngine);    d->rasterPoolSize = 4096;    d->rasterPoolBase =#if defined(Q_WS_WIN64)        (unsigned char *) _aligned_malloc(d->rasterPoolSize, __alignof(void*));#else        (unsigned char *) malloc(d->rasterPoolSize);#endif    // The antialiasing raster.    d->grayRaster = new QT_FT_Raster;    qt_ft_grays_raster.raster_new(0, d->grayRaster);    qt_ft_grays_raster.raster_reset(*d->grayRaster, d->rasterPoolBase, d->rasterPoolSize);    // Initialize the standard raster.    d->blackRaster = new QT_FT_Raster;    qt_ft_standard_raster.raster_new(0, d->blackRaster);    qt_ft_standard_raster.raster_reset(*d->blackRaster, d->rasterPoolBase, d->rasterPoolSize);    d->rasterBuffer = new QRasterBuffer();#ifdef Q_WS_WIN    d->fontRasterBuffer = new QRasterBuffer();#endif    d->outlineMapper = new QFTOutlineMapper;    d->dashStroker = 0;    d->flushOnEnd = true;    d->basicStroker.setMoveToHook(qt_ft_outline_move_to);    d->basicStroker.setLineToHook(qt_ft_outline_line_to);    d->basicStroker.setCubicToHook(qt_ft_outline_cubic_to);    d->dashStroker = 0;}QRasterPaintEngine::~QRasterPaintEngine(){    Q_D(QRasterPaintEngine);#if defined(Q_WS_WIN64)    _aligned_free(d->rasterPoolBase);#else    free(d->rasterPoolBase);#endif    qt_ft_grays_raster.raster_done(*d->grayRaster);    delete d->grayRaster;    qt_ft_standard_raster.raster_done(*d->blackRaster);    delete d->blackRaster;    delete d->rasterBuffer;    delete d->outlineMapper;#ifdef Q_WS_WIN    delete d->fontRasterBuffer;#endif    delete d->dashStroker;}bool QRasterPaintEngine::begin(QPaintDevice *device){    Q_D(QRasterPaintEngine);    // ####### move to QApp    qInitDrawhelperAsm();    d->deviceDepth = device->depth();    d->antialiased = false;    d->bilinear = false;    d->mono_surface = false;    d->fast_pen = true;    d->int_xform = true;    d->user_clip_enabled = false;    d->inverseScale = qreal(1);#if defined(Q_WS_WIN)    d->clear_type_text = false;    QT_WA({        UINT result;        BOOL ok;        ok = SystemParametersInfoW(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);        if (ok)            d->clear_type_text = (result == FE_FONTSMOOTHINGCLEARTYPE);    }, {        UINT result;        BOOL ok;        ok = SystemParametersInfoA(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0);        if (ok)            d->clear_type_text = (result == FE_FONTSMOOTHINGCLEARTYPE);    });#endif    d->rasterBuffer->init();#if defined(Q_WS_WIN)    d->fontRasterBuffer->setupHDC(d->clear_type_text);#endif    d->deviceRect = QRect(0, 0, device->width(), device->height());    gccaps &= ~PorterDuff;    // reset paintevent clip    d->baseClip = QPainterPath();    if (device->devType() == QInternal::Widget) {        QRegion sysClip = systemClip();        if (!sysClip.isEmpty()) {            d->baseClip.addRegion(sysClip);            d->deviceRect = sysClip.boundingRect();            // Shift the baseclip to absolute            d->baseClip = d->baseClip * QMatrix(1, 0, 0, 1,                                                -d->deviceRect.x(),                                                -d->deviceRect.y());        }        gccaps &= ~PaintOutsidePaintEvent;    }#if defined(Q_WS_QWS)    else if (device->devType() == QInternal::Pixmap) {        // Only embedded uses system clipping on pixmaps        QRegion sysClip = systemClip();        if (!sysClip.isEmpty())            d->baseClip.addRegion(sysClip);    }#endif    else {        QRegion sysClip = systemClip();        if (!sysClip.isEmpty()) {            d->baseClip.addRegion(sysClip);        }    }#if defined(Q_WS_WIN) || defined(Q_WS_QWS)    if (device->devType() == QInternal::Pixmap) {        QPixmap *pixmap = static_cast<QPixmap *>(device);        if (pixmap->isNull()) {            qWarning("Cannot paint on a null pixmap");            return false;        }        QPixmapData *data = static_cast<QPixmap *>(device)->data;        device = &data->image;    }#endif    if (device->devType() == QInternal::Image) {        QImage *image = static_cast<QImage *>(device);        int format = image->format();        d->flushOnEnd = false;        d->rasterBuffer->prepare(image);        if (format == QImage::Format_MonoLSB) {            d->mono_surface = true;        } else if (format == QImage::Format_Mono) {            d->mono_surface = true;        } else if (format == QImage::Format_RGB32) {            ;        } else if (format == QImage::Format_ARGB32_Premultiplied) {            gccaps |= PorterDuff;        } else if (format == QImage::Format_ARGB32) {            gccaps |= PorterDuff;#ifdef Q_WS_QWS        } else if (format == QImage::Format_RGB16) {            ;#endif        } else {            qWarning("QRasterPaintEngine::begin(), unsupported image format (%d)\n"                     "Supported image formats: Format_RGB32 and Format_ARGB32_Premultiplied",                     format);            return false;        }    } else {        d->rasterBuffer->prepare(d->deviceRect.width(), d->deviceRect.height());    }    d->rasterBuffer->resetClip();    d->matrix = QMatrix();    d->txop = QPainterPrivate::TxNone;    d->outlineMapper->setMatrix(d->matrix, d->txop);    d->outlineMapper->m_clipper.setBoundingRect(d->deviceRect.adjusted(-10, -10, 10, 10));    if (device->depth() == 1) {        d->pen = QPen(Qt::color1);        d->brush = QBrush(Qt::color0);    } else {        d->pen = QPen(Qt::black);        d->brush = QBrush(Qt::NoBrush);    }    d->penData.init(d->rasterBuffer);    d->penData.setup(d->pen.brush());    d->stroker = &d->basicStroker;    d->basicStroker.setClipRect(d->deviceRect);    d->brushData.init(d->rasterBuffer);    d->brushData.setup(d->brush);    updateClipPath(QPainterPath(), Qt::NoClip);    setDirty(DirtyBrushOrigin);    setActive(true);    return true;}bool QRasterPaintEngine::end(){    Q_D(QRasterPaintEngine);    if (d->flushOnEnd)        flush(d->pdev, QPoint());    if (d->rasterBuffer->disabled_clip) {        delete d->rasterBuffer->disabled_clip;        d->rasterBuffer->disabled_clip = 0;    }    setActive(false);    return true;}void QRasterPaintEngine::releaseBuffer()

⌨️ 快捷键说明

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