Changeset 21828 in webkit
- Timestamp:
- May 27, 2007 6:24:43 PM (17 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r21827 r21828 1 2007-05-27 Alp Toker <alp.toker@collabora.co.uk> 2 3 Reviewed by Sam and Oliver. 4 5 Implement PathCairo. This patch is based on changes in Mike Emmel's 6 WebKit fork with some additional clean-ups and updates. 7 8 * platform/graphics/Path.h: 9 * platform/graphics/cairo/CairoPath.h: Added. 10 (CairoPath::CairoPath): 11 (CairoPath::~CairoPath): 12 * platform/graphics/cairo/GraphicsContextCairo.cpp: 13 (WebCore::GraphicsContext::clip): 14 * platform/graphics/cairo/PathCairo.cpp: 15 (WebCore::Path::Path): 16 (WebCore::Path::~Path): 17 (WebCore::Path::operator=): 18 (WebCore::Path::clear): 19 (WebCore::Path::isEmpty): 20 (WebCore::Path::translate): 21 (WebCore::Path::moveTo): 22 (WebCore::Path::addLineTo): 23 (WebCore::Path::addRect): 24 (WebCore::Path::addQuadCurveTo): 25 (WebCore::Path::addBezierCurveTo): 26 (WebCore::Path::addArc): 27 (WebCore::Path::addArcTo): 28 (WebCore::Path::addEllipse): 29 (WebCore::Path::closeSubpath): 30 (WebCore::Path::boundingRect): 31 (WebCore::Path::contains): 32 (WebCore::Path::apply): 33 (WebCore::Path::transform): 34 (WebCore::Path::debugString): 35 1 36 2007-05-27 Kevin Ollivier <kevino@theolliviers.com> 2 37 -
trunk/WebCore/platform/graphics/Path.h
r21601 r21828 33 33 class QPainterPath; 34 34 typedef QPainterPath PlatformPath; 35 #elif PLATFORM(CAIRO) 36 typedef struct CairoPath PlatformPath; 35 37 #else 36 38 typedef void PlatformPath; -
trunk/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
r21827 r21828 30 30 #if PLATFORM(CAIRO) 31 31 32 #include "CairoPath.h" 32 33 #include "FloatRect.h" 33 34 #include "Font.h" 34 35 #include "FontData.h" 35 36 #include "IntRect.h" 37 #include "NotImplemented.h" 38 #include "Path.h" 36 39 #include <cairo.h> 37 40 #include <math.h> 38 41 #include <stdio.h> 39 42 #include <wtf/MathExtras.h> 40 #include "NotImplemented.h"41 43 42 44 #if PLATFORM(WIN) … … 684 686 } 685 687 686 void GraphicsContext::clip(const Path&) 687 { 688 notImplemented(); 688 void GraphicsContext::clip(const Path& path) 689 { 690 if (paintingDisabled()) 691 return; 692 cairo_t* cr = m_data->context; 693 cairo_path_t *p = cairo_copy_path(path.platformPath()->m_cr); 694 cairo_append_path(cr, p); 695 cairo_path_destroy(p); 696 cairo_clip(cr); 689 697 } 690 698 -
trunk/WebCore/platform/graphics/cairo/PathCairo.cpp
r21827 r21828 1 1 /* 2 * Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com> 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 2 Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com> 3 Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org> 4 2004, 2005, 2006 Rob Buis <buis@kde.org> 5 2005, 2007 Apple Inc. All Rights reserved. 6 2007 Alp Toker <alp.toker@collabora.co.uk> 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Library General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Library General Public License for more details. 17 18 You should have received a copy of the GNU Library General Public License 19 aint with this library; see the file COPYING.LIB. If not, write to 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 Boston, MA 02111-1307, USA. 22 */ 27 23 28 24 #include "config.h" 29 25 #include "Path.h" 30 26 27 #include "AffineTransform.h" 28 #include "CairoPath.h" 31 29 #include "FloatRect.h" 32 30 #include "NotImplemented.h" 31 #include "PlatformString.h" 32 #include <cairo.h> 33 #include <math.h> 33 34 #include <stdio.h> 34 35 35 #include "NotImplemented.h"36 37 36 namespace WebCore { 38 37 39 38 Path::Path() 40 { 39 : m_path(new CairoPath()) 40 { 41 } 42 43 Path::~Path() 44 { 45 delete m_path; 46 } 47 48 Path::Path(const Path& other) 49 : m_path(new CairoPath()) 50 { 51 cairo_t* cr = platformPath()->m_cr; 52 cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr); 53 cairo_append_path(cr, p); 54 cairo_path_destroy(p); 55 } 56 57 Path& Path::operator=(const Path& other) 58 { 59 if (&other == this) 60 return *this; 61 62 clear(); 63 cairo_t* cr = platformPath()->m_cr; 64 cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr); 65 cairo_append_path(cr, p); 66 cairo_path_destroy(p); 67 return *this; 68 } 69 70 void Path::clear() 71 { 72 cairo_t* cr = platformPath()->m_cr; 73 cairo_new_path(cr); 74 } 75 76 bool Path::isEmpty() const 77 { 78 // FIXME: if/when the patch to get current pt return status is applied 79 // double dx,dy; 80 // return cairo_get_current_point(cr, &dx, &dy); 81 82 cairo_t* cr = platformPath()->m_cr; 83 cairo_path_t* p = cairo_copy_path(platformPath()->m_cr); 84 bool hasData = p->num_data; 85 cairo_path_destroy(p); 86 return !hasData; 87 } 88 89 void Path::translate(const FloatSize& p) 90 { 91 cairo_t* cr = platformPath()->m_cr; 92 cairo_translate(cr, p.width(), p.height()); 93 } 94 95 void Path::moveTo(const FloatPoint& p) 96 { 97 cairo_t* cr = platformPath()->m_cr; 98 cairo_move_to(cr, p.x(), p.y()); 99 } 100 101 void Path::addLineTo(const FloatPoint& p) 102 { 103 cairo_t* cr = platformPath()->m_cr; 104 cairo_line_to(cr, p.x(), p.y()); 105 } 106 107 void Path::addRect(const FloatRect& rect) 108 { 109 cairo_t* cr = platformPath()->m_cr; 110 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); 111 } 112 113 /* 114 * inspired by libsvg-cairo 115 */ 116 void Path::addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point) 117 { 118 cairo_t* cr = platformPath()->m_cr; 119 double x, y; 120 double x1 = controlPoint.x(); 121 double y1 = controlPoint.y(); 122 double x2 = point.x(); 123 double y2 = point.y(); 124 cairo_get_current_point(cr, &x, &y); 125 cairo_curve_to(cr, 126 x + 2.0 / 3.0 * (x1 - x), y + 2.0 / 3.0 * (y1 - y), 127 x2 + 2.0 / 3.0 * (x1 - x2), y2 + 2.0 / 3.0 * (y1 - y2), 128 x2, y2); 129 } 130 131 void Path::addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& controlPoint3) 132 { 133 cairo_t* cr = platformPath()->m_cr; 134 cairo_curve_to(cr, controlPoint1.x(), controlPoint1.y(), 135 controlPoint2.x(), controlPoint2.y(), 136 controlPoint3.x(), controlPoint3.y()); 137 } 138 139 void Path::addArc(const FloatPoint& p, float r, float sa, float ea, bool clockwise) 140 { 141 cairo_t* cr = platformPath()->m_cr; 142 if (clockwise) 143 cairo_arc(cr, p.x(), p.y(), r, sa, ea); 144 else 145 cairo_arc_negative(cr, p.x(), p.y(), r, sa, ea); 146 } 147 148 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) 149 { 150 // FIXME: cairo_arc_to not yet in cairo see cairo.h 151 // cairo_arc_to(m_cr, p1.x(), p1.y(), p2.x(), p2.y()); 41 152 notImplemented(); 42 153 } 43 154 44 Path::~Path() 45 { 46 notImplemented(); 47 } 48 49 Path::Path(const Path&) 50 { 51 notImplemented(); 52 } 53 54 bool Path::contains(const FloatPoint&, WindRule rule) const 55 { 56 notImplemented(); 57 return false; 58 } 59 60 void Path::translate(const FloatSize&) 61 { 62 notImplemented(); 63 } 64 65 FloatRect Path::boundingRect() const 66 { 67 notImplemented(); 68 return FloatRect(); 69 } 70 71 Path& Path::operator=(const Path&) 72 { 73 notImplemented(); 74 return * this; 75 } 76 77 void Path::clear() 78 { 79 notImplemented(); 80 } 81 82 void Path::moveTo(const FloatPoint&) 83 { 84 notImplemented(); 85 } 86 87 void Path::addLineTo(const FloatPoint&) 88 { 89 notImplemented(); 90 } 91 92 void Path::addQuadCurveTo(const FloatPoint&, const FloatPoint&) 93 { 94 notImplemented(); 95 } 96 97 void Path::addBezierCurveTo(const FloatPoint&, const FloatPoint&, const FloatPoint&) 98 { 99 notImplemented(); 100 } 101 102 void Path::addArcTo(const FloatPoint&, const FloatPoint&, float) 103 { 104 notImplemented(); 105 } 106 107 void Path::closeSubpath() 108 { 109 notImplemented(); 110 } 111 112 void Path::addArc(const FloatPoint&, float, float, float, bool) 113 { 114 notImplemented(); 115 } 116 117 void Path::addRect(const FloatRect&) 118 { 119 notImplemented(); 120 } 121 122 void Path::addEllipse(const FloatRect&) 123 { 124 notImplemented(); 125 } 126 127 void Path::transform(const AffineTransform&) 128 { 129 notImplemented(); 130 } 131 132 void Path::apply(void* , PathApplierFunction) const 133 { 134 notImplemented(); 135 } 136 137 } 155 void Path::addEllipse(const FloatRect& rect) 156 { 157 cairo_t* cr = platformPath()->m_cr; 158 cairo_save(cr); 159 float yRadius = .5 * rect.height(); 160 float xRadius = .5 * rect.width(); 161 cairo_translate(cr, rect.x() + xRadius, rect.y() + yRadius); 162 cairo_scale(cr, xRadius, yRadius); 163 cairo_arc(cr, 0., 0., 1., 0., 2 * M_PI); 164 cairo_restore(cr); 165 } 166 167 void Path::closeSubpath() 168 { 169 cairo_t* cr = platformPath()->m_cr; 170 cairo_close_path(cr); 171 } 172 173 FloatRect Path::boundingRect() const 174 { 175 cairo_t* cr = platformPath()->m_cr; 176 double x, y, w, h; 177 cairo_fill_extents(cr, &x, &y, &w, &h); 178 return FloatRect(x, y, w, h); 179 } 180 181 bool Path::contains(const FloatPoint& point, WindRule rule) const 182 { 183 cairo_t* cr = platformPath()->m_cr; 184 cairo_fill_rule_t cur = cairo_get_fill_rule(cr); 185 cairo_set_fill_rule(cr, rule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); 186 bool contains = cairo_in_fill(cr, static_cast<double>(point.x()), static_cast<double>(point.y())); 187 cairo_set_fill_rule(cr, cur); 188 return contains; 189 } 190 191 void Path::apply(void* info, PathApplierFunction function) const 192 { 193 cairo_t* cr = platformPath()->m_cr; 194 cairo_path_t* path = cairo_copy_path(cr); 195 cairo_path_data_t* data; 196 PathElement pelement; 197 FloatPoint points[3]; 198 pelement.points = points; 199 200 for (int i = 0; i < path->num_data; i += path->data[i].header.length) { 201 data = &path->data[i]; 202 switch (data->header.type) { 203 case CAIRO_PATH_MOVE_TO: 204 pelement.type = PathElementMoveToPoint; 205 pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); 206 function(info, &pelement); 207 break; 208 case CAIRO_PATH_LINE_TO: 209 pelement.type = PathElementAddLineToPoint; 210 pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); 211 function(info, &pelement); 212 break; 213 case CAIRO_PATH_CURVE_TO: 214 pelement.type = PathElementAddCurveToPoint; 215 pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); 216 pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y); 217 pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y); 218 function(info, &pelement); 219 break; 220 case CAIRO_PATH_CLOSE_PATH: 221 pelement.type = PathElementCloseSubpath; 222 function(info, &pelement); 223 break; 224 } 225 } 226 cairo_path_destroy(path); 227 } 228 229 void Path::transform(const AffineTransform& trans) 230 { 231 cairo_t* m_cr = platformPath()->m_cr; 232 cairo_matrix_t c_matrix = cairo_matrix_t(trans); 233 cairo_transform(m_cr, &c_matrix); 234 } 235 236 String Path::debugString() const 237 { 238 String string = ""; 239 cairo_path_t* path = cairo_copy_path(platformPath()->m_cr); 240 cairo_path_data_t* data; 241 242 if (!path->num_data ) 243 string = "EMPTY"; 244 245 for (int i = 0; i < path->num_data; i += path->data[i].header.length) { 246 data = &path->data[i]; 247 switch (data->header.type) { 248 case CAIRO_PATH_MOVE_TO: 249 string += String::format("M %.2f,%.2f", 250 data[1].point.x, data[1].point.y); 251 break; 252 case CAIRO_PATH_LINE_TO: 253 string += String::format("L %.2f,%.2f", 254 data[1].point.x, data[1].point.y); 255 break; 256 case CAIRO_PATH_CURVE_TO: 257 string += String::format("C %.2f,%.2f,%.2f,%.2f,%.2f,%.2f", 258 data[1].point.x, data[1].point.y, 259 data[2].point.x, data[2].point.y, 260 data[3].point.x, data[3].point.y); 261 break; 262 case CAIRO_PATH_CLOSE_PATH: 263 string += "X"; 264 break; 265 } 266 } 267 cairo_path_destroy(path); 268 return string; 269 } 270 271 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.