1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2012 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#ifndef SkPathWriter_DEFINED 8cb93a386Sopenharmony_ci#define SkPathWriter_DEFINED 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#include "include/core/SkPath.h" 11cb93a386Sopenharmony_ci#include "include/private/SkTArray.h" 12cb93a386Sopenharmony_ci#include "include/private/SkTDArray.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_ciclass SkOpPtT; 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_ci// Construct the path one contour at a time. 17cb93a386Sopenharmony_ci// If the contour is closed, copy it to the final output. 18cb93a386Sopenharmony_ci// Otherwise, keep the partial contour for later assembly. 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ciclass SkPathWriter { 21cb93a386Sopenharmony_cipublic: 22cb93a386Sopenharmony_ci SkPathWriter(SkPath& path); 23cb93a386Sopenharmony_ci void assemble(); 24cb93a386Sopenharmony_ci void conicTo(const SkPoint& pt1, const SkOpPtT* pt2, SkScalar weight); 25cb93a386Sopenharmony_ci void cubicTo(const SkPoint& pt1, const SkPoint& pt2, const SkOpPtT* pt3); 26cb93a386Sopenharmony_ci bool deferredLine(const SkOpPtT* pt); 27cb93a386Sopenharmony_ci void deferredMove(const SkOpPtT* pt); 28cb93a386Sopenharmony_ci void finishContour(); 29cb93a386Sopenharmony_ci bool hasMove() const { return !fFirstPtT; } 30cb93a386Sopenharmony_ci void init(); 31cb93a386Sopenharmony_ci bool isClosed() const; 32cb93a386Sopenharmony_ci const SkPath* nativePath() const { return fPathPtr; } 33cb93a386Sopenharmony_ci void quadTo(const SkPoint& pt1, const SkOpPtT* pt2); 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ciprivate: 36cb93a386Sopenharmony_ci bool changedSlopes(const SkOpPtT* pt) const; 37cb93a386Sopenharmony_ci void close(); 38cb93a386Sopenharmony_ci const SkTDArray<const SkOpPtT*>& endPtTs() const { return fEndPtTs; } 39cb93a386Sopenharmony_ci void lineTo(); 40cb93a386Sopenharmony_ci bool matchedLast(const SkOpPtT*) const; 41cb93a386Sopenharmony_ci void moveTo(); 42cb93a386Sopenharmony_ci const SkTArray<SkPath>& partials() const { return fPartials; } 43cb93a386Sopenharmony_ci bool someAssemblyRequired(); 44cb93a386Sopenharmony_ci SkPoint update(const SkOpPtT* pt); 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci SkPath fCurrent; // contour under construction 47cb93a386Sopenharmony_ci SkTArray<SkPath> fPartials; // contours with mismatched starts and ends 48cb93a386Sopenharmony_ci SkTDArray<const SkOpPtT*> fEndPtTs; // possible pt values for partial starts and ends 49cb93a386Sopenharmony_ci SkPath* fPathPtr; // closed contours are written here 50cb93a386Sopenharmony_ci const SkOpPtT* fDefer[2]; // [0] deferred move, [1] deferred line 51cb93a386Sopenharmony_ci const SkOpPtT* fFirstPtT; // first in current contour 52cb93a386Sopenharmony_ci}; 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ci#endif /* defined(__PathOps__SkPathWriter__) */ 55