/**************************************************************************** ** ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** GNU Lesser General Public License Usage ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU General ** Public License version 3.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of this ** file. Please review the following information to ensure the GNU General ** Public License version 3.0 requirements will be met: ** http://www.gnu.org/copyleft/gpl.html. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms and ** conditions contained in a signed written agreement between you and Nokia. ** ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qoutlinemapper_p.h" #include #include "qmath.h" #include QT_BEGIN_NAMESPACE static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; #define qreal_to_fixed_26_6(f) (int(f * 64)) static const QRectF boundingRect(const QPointF *points, int pointCount) { const QPointF *e = points; const QPointF *last = points + pointCount; qreal minx, maxx, miny, maxy; minx = maxx = e->x(); miny = maxy = e->y(); while (++e < last) { if (e->x() < minx) minx = e->x(); else if (e->x() > maxx) maxx = e->x(); if (e->y() < miny) miny = e->y(); else if (e->y() > maxy) maxy = e->y(); } return QRectF(QPointF(minx, miny), QPointF(maxx, maxy)); } QT_FT_Outline *QOutlineMapper::convertPath(const QPainterPath &path) { Q_ASSERT(!path.isEmpty()); int elmCount = path.elementCount(); #ifdef QT_DEBUG_CONVERT printf("QOutlineMapper::convertPath(), size=%d\n", elmCount); #endif beginOutline(path.fillRule()); for (int index=0; index(path.points()); for (int index = 0; index < count; ++index) { switch (elements[index]) { case QPainterPath::MoveToElement: if (index == count - 1) continue; moveTo(points[index]); break; case QPainterPath::LineToElement: lineTo(points[index]); break; case QPainterPath::CurveToElement: curveTo(points[index], points[index+1], points[index+2]); index += 2; break; default: break; // This will never hit.. } } } else { // ### We can kill this copying and just use the buffer straight... m_elements.resize(count); if (count) memcpy(m_elements.data(), path.points(), count* sizeof(QPointF)); m_element_types.resize(0); } endOutline(); return outline(); } void QOutlineMapper::endOutline() { closeSubpath(); int element_count = m_elements.size(); if (element_count == 0) { memset(&m_outline, 0, sizeof(m_outline)); return; } QPointF *elements; // Transform the outline if (m_txop == QTransform::TxNone) { elements = m_elements.data(); } else { if (m_txop == QTransform::TxTranslate) { for (int i=0; i QT_RASTER_COORD_LIMIT || controlPointRect.top() < -QT_RASTER_COORD_LIMIT || controlPointRect.bottom() > QT_RASTER_COORD_LIMIT || controlPointRect.width() > QT_RASTER_COORD_LIMIT || controlPointRect.height() > QT_RASTER_COORD_LIMIT)); if (do_clip) { clipElements(elements, elementTypes(), element_count); } else { convertElements(elements, elementTypes(), element_count); } } void QOutlineMapper::convertElements(const QPointF *elements, const QPainterPath::ElementType *types, int element_count) { if (types) { // Translate into FT coords const QPointF *e = elements; for (int i=0; ix()), qreal_to_fixed_26_6(e->y()) }; if (i != 0) m_contours << m_points.size() - 1; m_points << pt_fixed; m_tags << QT_FT_CURVE_TAG_ON; } break; case QPainterPath::LineToElement: { QT_FT_Vector pt_fixed = { qreal_to_fixed_26_6(e->x()), qreal_to_fixed_26_6(e->y()) }; m_points << pt_fixed; m_tags << QT_FT_CURVE_TAG_ON; } break; case QPainterPath::CurveToElement: { QT_FT_Vector cp1_fixed = { qreal_to_fixed_26_6(e->x()), qreal_to_fixed_26_6(e->y()) }; ++e; QT_FT_Vector cp2_fixed = { qreal_to_fixed_26_6((e)->x()), qreal_to_fixed_26_6((e)->y()) }; ++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; } } else { // Plain polygon... const QPointF *last = elements + element_count; const QPointF *e = elements; while (e < last) { QT_FT_Vector pt_fixed = { qreal_to_fixed_26_6(e->x()), qreal_to_fixed_26_6(e->y()) }; m_points << pt_fixed; m_tags << QT_FT_CURVE_TAG_ON; ++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("QOutlineMapper::endOutline\n"); printf(" - contours: %d\n", m_outline.n_contours); for (int i=0; i