bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const { ASSERT(applier); cairo_t* cr = platformPath()->context(); GraphicsContext gc(cr); applier->strokeStyle(&gc); return cairo_in_stroke(cr, point.x(), point.y()); }
static void checkWinObjCSDK() { const BuildSettings bs(NULL); String sdkRoot = bs.getValue("WINOBJC_SDK_ROOT"); String baseErrMsg = "Invalid WINOBJC_SDK_ROOT specified: \"" + platformPath(sdkRoot) + "\". "; sbValidate(!sb_realpath(sdkRoot).empty(), baseErrMsg + "The SDK directory does not exist."); String templateDir = bs.getValue("VSIMPORTER_TEMPLATES_DIR"); sbValidate(!sb_realpath(templateDir).empty(), baseErrMsg + "The SDK directory is missing vsimporter templates."); }
void Path::addEllipse(const FloatRect& rect) { cairo_t* cr = platformPath()->m_cr; cairo_save(cr); float yRadius = .5 * rect.height(); float xRadius = .5 * rect.width(); cairo_translate(cr, rect.x() + xRadius, rect.y() + yRadius); cairo_scale(cr, xRadius, yRadius); cairo_arc(cr, 0., 0., 1., 0., 2 * piDouble); cairo_restore(cr); }
Path& Path::operator=(const Path& other) { if (&other == this) return *this; clear(); cairo_t* cr = platformPath()->context(); OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(other.platformPath()->context())); cairo_append_path(cr, pathCopy.get()); return *this; }
bool Path::contains(const FloatPoint& point, WindRule rule) const { if (!isfinite(point.x()) || !isfinite(point.y())) return false; cairo_t* cr = platformPath()->context(); cairo_fill_rule_t cur = cairo_get_fill_rule(cr); cairo_set_fill_rule(cr, rule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); bool contains = cairo_in_fill(cr, point.x(), point.y()); cairo_set_fill_rule(cr, cur); return contains; }
FloatRect Path::boundingRect() const { cairo_t* cr = platformPath()->m_cr; double x0, x1, y0, y1; #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 6, 0) cairo_path_extents(cr, &x0, &y0, &x1, &y1); #else cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); #endif return FloatRect(x0, y0, x1 - x0, y1 - y0); }
FloatPoint Path::currentPoint() const { if (isNull()) return FloatPoint(); // FIXME: Is this the correct way? double x; double y; cairo_get_current_point(platformPath()->context(), &x, &y); return FloatPoint(x, y); }
FloatRect Path::boundingRect() const { // Should this be isEmpty() or can an empty path have a non-zero origin? if (isNull()) return FloatRect(); cairo_t* cr = platformPath()->context(); double x0, x1, y0, y1; cairo_path_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
Path& Path::operator=(const Path& other) { if (&other == this) return *this; clear(); cairo_t* cr = platformPath()->m_cr; cairo_path_t* p = cairo_copy_path(other.platformPath()->m_cr); cairo_append_path(cr, p); cairo_path_destroy(p); return *this; }
bool Path::isEmpty() const { cairo_t* cr = platformPath()->m_cr; #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,10) return !cairo_has_current_point(cr); #else cairo_path_t* p = cairo_copy_path(cr); bool hasData = p->num_data; cairo_path_destroy(p); return !hasData; #endif }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { cairo_t* cr = platformPath()->context(); if (applier) { GraphicsContext gc(cr); applier->strokeStyle(&gc); } double x0, x1, y0, y1; cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
void Path::addArc(const FloatPoint& p, float r, float sa, float ea, bool anticlockwise) { // http://bugs.webkit.org/show_bug.cgi?id=16449 // cairo_arc() functions hang or crash when passed inf as radius or start/end angle if (!isfinite(r) || !isfinite(sa) || !isfinite(ea)) return; cairo_t* cr = platformPath()->m_cr; if (anticlockwise) cairo_arc_negative(cr, p.x(), p.y(), r, sa, ea); else cairo_arc(cr, p.x(), p.y(), r, sa, ea); }
/* * inspired by libsvg-cairo */ void Path::addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point) { cairo_t* cr = platformPath()->m_cr; double x, y; double x1 = controlPoint.x(); double y1 = controlPoint.y(); double x2 = point.x(); double y2 = point.y(); cairo_get_current_point(cr, &x, &y); cairo_curve_to(cr, x + 2.0 / 3.0 * (x1 - x), y + 2.0 / 3.0 * (y1 - y), x2 + 2.0 / 3.0 * (x1 - x2), y2 + 2.0 / 3.0 * (y1 - y2), x2, y2); }
VCProject* SBWorkspace::generateGlueProject() const { // Get a set of all configurations appearing in all projects StringSet slnConfigs; for (auto project : m_openProjects) { const StringSet& configs = project.second->getSelectedConfigurations(); slnConfigs.insert(configs.begin(), configs.end()); } // Get the template VSTemplate* vstemplate = VSTemplate::getTemplate("WinRT"); sbAssertWithTelemetry(vstemplate, "Failed to get WinRT VS template"); // Set up basis template parameters string projectName = getName() + "WinRT"; VSTemplateParameters templateParams; templateParams.setProjectName(projectName); // Expand the template and get the template project vstemplate->expand(sb_dirname(getPath()), templateParams); const VSTemplateProjectVec& projTemplates = vstemplate->getProjects(); sbAssertWithTelemetry(projTemplates.size() == 1, "Unexpected WinRT template size"); // Create the glue project and add it to the solution VCProject* glueProject = new VCProject(projTemplates.front()); // Get path to WinObjC SDK BuildSettings globalBS(NULL); String useRelativeSdkPath = globalBS.getValue("VSIMPORTER_RELATIVE_SDK_PATH"); String sdkDir = globalBS.getValue("WINOBJC_SDK_ROOT"); // Try to create a relative path to the SDK, if requested if (strToUpper(useRelativeSdkPath) == "YES") { String projectDir = sb_dirname(projTemplates.front()->getPath()); sdkDir = getRelativePath(projectDir, sdkDir); } glueProject->addGlobalProperty("WINOBJC_SDK_ROOT", platformPath(sdkDir), "'$(WINOBJC_SDK_ROOT)' == ''"); // Set configuration properties for (auto configName : slnConfigs) { VCProjectConfiguration *projConfig = glueProject->addConfiguration(configName); projConfig->setProperty("TargetName", getName()); } // Set RootNamespace glueProject->addGlobalProperty("RootNamespace", getName()); return glueProject; }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { // Should this be isEmpty() or can an empty path have a non-zero origin? if (isNull()) return FloatRect(); cairo_t* cr = platformPath()->context(); if (applier) { GraphicsContext gc(cr); applier->strokeStyle(&gc); } double x0, x1, y0, y1; cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); return FloatRect(x0, y0, x1 - x0, y1 - y0); }
bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const { GraphicsContext* scratch = scratchContext(); scratch->save(); applier->strokeStyle(scratch); SkPaint paint; scratch->setupStrokePaint(&paint); SkPath strokePath; paint.getFillPath(*platformPath(), &strokePath); bool contains = SkPathContainsPoint(&strokePath, point, SkPath::kWinding_FillType); scratch->restore(); return contains; }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { GraphicsContext* scratch = scratchContext(); scratch->save(); if (applier) applier->strokeStyle(scratch); SkPaint paint; scratch->setupStrokePaint(&paint); SkPath boundingPath; paint.getFillPath(*platformPath(), &boundingPath); FloatRect r = boundingPath.getBounds(); scratch->restore(); return r; }
bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const { ASSERT(applier); CGContextRef context = scratchContext(); CGContextSaveGState(context); CGContextBeginPath(context); CGContextAddPath(context, platformPath()); GraphicsContext gc(context); applier->strokeStyle(&gc); bool hitSuccess = CGContextPathContainsPoint(context, point, kCGPathStroke); CGContextRestoreGState(context); return hitSuccess; }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { CGContextRef context = scratchContext(); CGContextSaveGState(context); CGContextBeginPath(context); CGContextAddPath(context, platformPath()); if (applier) { GraphicsContext graphicsContext(context); applier->strokeStyle(&graphicsContext); } CGContextReplacePathWithStrokedPath(context); CGRect box = CGContextIsPathEmpty(context) ? CGRectZero : CGContextGetPathBoundingBox(context); CGContextRestoreGState(context); return box; }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { if (isNull()) return FloatRect(); GraphicsContext* scratch = scratchContext(); scratch->save(); if (applier) applier->strokeStyle(scratch); SkPaint paint; scratch->platformContext()->setupPaintForStroking(&paint, 0, 0); SkPath boundingPath; paint.getFillPath(*platformPath(), &boundingPath); FloatRect r = boundingPath.getBounds(); scratch->restore(); return r; }
FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) { // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer // on each call. OwnPtr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1), false); GraphicsContext* gc = scratchImage->context(); QPainterPathStroker stroke; if (applier) { applier->strokeStyle(gc); QPen pen = gc->pen(); stroke.setWidth(pen.widthF()); stroke.setCapStyle(pen.capStyle()); stroke.setJoinStyle(pen.joinStyle()); stroke.setMiterLimit(pen.miterLimit()); stroke.setDashPattern(pen.dashPattern()); stroke.setDashOffset(pen.dashOffset()); } return (stroke.createStroke(*platformPath())).boundingRect(); }
bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point) const { if (isNull()) return false; ASSERT(applier); GraphicsContext* scratch = scratchContext(); scratch->save(); applier->strokeStyle(scratch); SkPaint paint; scratch->platformContext()->setupPaintForStroking(&paint, 0, 0); SkPath strokePath; paint.getFillPath(*platformPath(), &strokePath); bool contains = SkPathContainsPoint(&strokePath, point, SkPath::kWinding_FillType); scratch->restore(); return contains; }
void Path::apply(void* info, PathApplierFunction function) const { if (isNull()) return; cairo_t* cr = platformPath()->context(); OwnPtr<cairo_path_t> pathCopy = adoptPtr(cairo_copy_path(cr)); cairo_path_data_t* data; PathElement pelement; FloatPoint points[3]; pelement.points = points; for (int i = 0; i < pathCopy->num_data; i += pathCopy->data[i].header.length) { data = &pathCopy->data[i]; switch (data->header.type) { case CAIRO_PATH_MOVE_TO: pelement.type = PathElementMoveToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); function(info, &pelement); break; case CAIRO_PATH_LINE_TO: pelement.type = PathElementAddLineToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); function(info, &pelement); break; case CAIRO_PATH_CURVE_TO: pelement.type = PathElementAddCurveToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y); pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y); function(info, &pelement); break; case CAIRO_PATH_CLOSE_PATH: pelement.type = PathElementCloseSubpath; function(info, &pelement); break; } } }
void Path::apply(void* info, PathApplierFunction function) const { cairo_t* cr = platformPath()->m_cr; cairo_path_t* path = cairo_copy_path(cr); cairo_path_data_t* data; PathElement pelement; FloatPoint points[3]; pelement.points = points; for (int i = 0; i < path->num_data; i += path->data[i].header.length) { data = &path->data[i]; switch (data->header.type) { case CAIRO_PATH_MOVE_TO: pelement.type = PathElementMoveToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); function(info, &pelement); break; case CAIRO_PATH_LINE_TO: pelement.type = PathElementAddLineToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); function(info, &pelement); break; case CAIRO_PATH_CURVE_TO: pelement.type = PathElementAddCurveToPoint; pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y); pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y); function(info, &pelement); break; case CAIRO_PATH_CLOSE_PATH: pelement.type = PathElementCloseSubpath; function(info, &pelement); break; } } cairo_path_destroy(path); }
String Path::debugString() const { if (isEmpty()) return String(); String pathString; cairo_path_t* path = cairo_copy_path(platformPath()->m_cr); cairo_path_data_t* data; for (int i = 0; i < path->num_data; i += path->data[i].header.length) { data = &path->data[i]; switch (data->header.type) { case CAIRO_PATH_MOVE_TO: if (i < (path->num_data - path->data[i].header.length)) pathString += String::format("M%.2f,%.2f ", data[1].point.x, data[1].point.y); break; case CAIRO_PATH_LINE_TO: pathString += String::format("L%.2f,%.2f ", data[1].point.x, data[1].point.y); break; case CAIRO_PATH_CURVE_TO: pathString += String::format("C%.2f,%.2f,%.2f,%.2f,%.2f,%.2f ", data[1].point.x, data[1].point.y, data[2].point.x, data[2].point.y, data[3].point.x, data[3].point.y); break; case CAIRO_PATH_CLOSE_PATH: pathString += "Z "; break; } } cairo_path_destroy(path); return pathString.simplifyWhiteSpace(); }
void Path::moveTo(const FloatPoint& p) { cairo_t* cr = platformPath()->m_cr; cairo_move_to(cr, p.x(), p.y()); }
void Path::translate(const FloatSize& p) { cairo_t* cr = platformPath()->m_cr; cairo_translate(cr, p.width(), p.height()); }
void Path::clear() { cairo_t* cr = platformPath()->m_cr; cairo_new_path(cr); }
void Path::closeSubpath() { cairo_t* cr = platformPath()->m_cr; cairo_close_path(cr); }
void Path::addRect(const FloatRect& rect) { cairo_t* cr = platformPath()->m_cr; cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); }