[canvaskit] Remove deprecated PathMeasure
This will make cleaning up the PosTan value easier. Change-Id: I13aa12f94c560bf8539aa2edb1f9e13779635692 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/362458 Reviewed-by: Nathaniel Nifong <nifong@google.com>
This commit is contained in:
parent
f6040ef2a7
commit
d62738d094
@ -38,6 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `Canvas.drawImageRect`, `Canvas.drawImage`, `Canvas.drawAtlas`,
|
||||
These rely on the Paint's FilterQuality, which is going away. Pass sampling options explicitly.
|
||||
|
||||
### Removed
|
||||
- `PathMeasure`, which was deprecated and replaced with `ContourMeasure`.
|
||||
|
||||
## [0.22.0] - 2020-12-17
|
||||
|
||||
### Added
|
||||
|
@ -1524,31 +1524,6 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
#endif
|
||||
;
|
||||
|
||||
// TODO(kjlubick) remove this now that we have SkContourMeasureIter
|
||||
class_<SkPathMeasure>("PathMeasure")
|
||||
.constructor<const SkPath&, bool, SkScalar>()
|
||||
.function("getLength", &SkPathMeasure::getLength)
|
||||
.function("getPosTan", optional_override([](SkPathMeasure& self,
|
||||
SkScalar distance) -> PosTan {
|
||||
SkPoint p{0, 0};
|
||||
SkVector v{0, 0};
|
||||
if (!self.getPosTan(distance, &p, &v)) {
|
||||
SkDebugf("zero-length path in getPosTan\n");
|
||||
}
|
||||
return PosTan{p.x(), p.y(), v.x(), v.y()};
|
||||
}))
|
||||
.function("getSegment", optional_override([](SkPathMeasure& self, SkScalar startD,
|
||||
SkScalar stopD, bool startWithMoveTo) -> SkPath {
|
||||
SkPath p;
|
||||
bool ok = self.getSegment(startD, stopD, &p, startWithMoveTo);
|
||||
if (ok) {
|
||||
return p;
|
||||
}
|
||||
return SkPath();
|
||||
}))
|
||||
.function("isClosed", &SkPathMeasure::isClosed)
|
||||
.function("nextContour", &SkPathMeasure::nextContour);
|
||||
|
||||
class_<SkPictureRecorder>("PictureRecorder")
|
||||
.constructor<>()
|
||||
.function("_beginRecording", optional_override([](SkPictureRecorder& self,
|
||||
|
@ -16,7 +16,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
} else {
|
||||
this._drawShapedText(str, x, y, paint);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Glyphs should be a Uint32Array of glyph ids, e.g. provided by Font.getGlyphIDs.
|
||||
// If using a Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs() to get the right type.
|
||||
@ -122,7 +122,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
CanvasKit._free(strPtr);
|
||||
CanvasKit._free(widthPtr);
|
||||
return retVal;
|
||||
}
|
||||
};
|
||||
|
||||
// arguments should all be arrayBuffers or be an array of arrayBuffers.
|
||||
CanvasKit.FontMgr.FromData = function() {
|
||||
@ -154,7 +154,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
CanvasKit._free(datasPtr);
|
||||
CanvasKit._free(sizesPtr);
|
||||
return fm;
|
||||
}
|
||||
};
|
||||
|
||||
// fontData should be an arrayBuffer
|
||||
CanvasKit.FontMgr.prototype.MakeTypefaceFromData = function(fontData) {
|
||||
@ -169,7 +169,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return null;
|
||||
}
|
||||
return font;
|
||||
}
|
||||
};
|
||||
|
||||
// Clients can pass in a Float32Array with length 4 to this and the results
|
||||
// will be copied into that array. Otherwise, a new TypedArray will be allocated
|
||||
@ -182,7 +182,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return optionalOutputArray;
|
||||
}
|
||||
return ta.slice();
|
||||
}
|
||||
};
|
||||
|
||||
CanvasKit.TextBlob.MakeOnPath = function(str, path, font, initialOffset) {
|
||||
if (!str || !str.length) {
|
||||
@ -205,14 +205,17 @@ CanvasKit._extraInitializations.push(function() {
|
||||
var widths = font.getWidths(str);
|
||||
|
||||
var rsx = new CanvasKit.RSXFormBuilder();
|
||||
var meas = new CanvasKit.PathMeasure(path, false, 1);
|
||||
var meas = new CanvasKit.ContourMeasureIter(path, false, 1);
|
||||
var cont = meas.next();
|
||||
var dist = initialOffset;
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
for (var i = 0; i < str.length && cont; i++) {
|
||||
var width = widths[i];
|
||||
dist += width/2;
|
||||
if (dist > meas.getLength()) {
|
||||
if (dist > cont.length()) {
|
||||
// jump to next contour
|
||||
if (!meas.nextContour()) {
|
||||
cont.delete();
|
||||
cont = meas.next();
|
||||
if (!cont) {
|
||||
// We have come to the end of the path - terminate the string
|
||||
// right here.
|
||||
str = str.substring(0, i);
|
||||
@ -223,7 +226,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
|
||||
// Gives us the (x, y) coordinates as well as the cos/sin of the tangent
|
||||
// line at that position.
|
||||
var xycs = meas.getPosTan(dist);
|
||||
var xycs = cont.getPosTan(dist);
|
||||
var cx = xycs[0];
|
||||
var cy = xycs[1];
|
||||
var cosT = xycs[2];
|
||||
@ -237,9 +240,10 @@ CanvasKit._extraInitializations.push(function() {
|
||||
}
|
||||
var retVal = this.MakeFromRSXform(str, rsx, font);
|
||||
rsx.delete();
|
||||
cont && cont.delete();
|
||||
meas.delete();
|
||||
return retVal;
|
||||
}
|
||||
};
|
||||
|
||||
CanvasKit.TextBlob.MakeFromRSXform = function(str, rsxBuilderOrArray, font) {
|
||||
// lengthBytesUTF8 and stringToUTF8Array are defined in the emscripten
|
||||
@ -264,7 +268,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return null;
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
};
|
||||
|
||||
// Glyphs should be a Uint32Array of glyph ids, e.g. provided by Font.getGlyphIDs.
|
||||
// If using a Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs() to get the right type.
|
||||
@ -287,7 +291,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return null;
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
};
|
||||
|
||||
// Glyphs should be a Uint32Array of glyph ids, e.g. provided by Font.getGlyphIDs.
|
||||
// If using a Malloc'd array, be sure to use CanvasKit.MallocGlyphIDs() to get the right type.
|
||||
@ -302,7 +306,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return null;
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
};
|
||||
|
||||
CanvasKit.TextBlob.MakeFromText = function(str, font) {
|
||||
// lengthBytesUTF8 and stringToUTF8Array are defined in the emscripten
|
||||
@ -320,7 +324,7 @@ CanvasKit._extraInitializations.push(function() {
|
||||
return null;
|
||||
}
|
||||
return blob;
|
||||
}
|
||||
};
|
||||
|
||||
// A helper to return the right type for GlyphIDs stored internally. When that changes, this
|
||||
// will also be changed, which will help avoid future breakages.
|
||||
|
@ -63,7 +63,7 @@ describe('Font Behavior', () => {
|
||||
bounds[0] += textBoxX; // left
|
||||
bounds[2] += textBoxX; // right
|
||||
bounds[1] += textBoxY; // top
|
||||
bounds[3] += textBoxY // bottom
|
||||
bounds[3] += textBoxY; // bottom
|
||||
|
||||
canvas.drawRect(bounds, paint);
|
||||
const SHAPE_TEST_TEXT = 'VAVAVAVAVAFIfi';
|
||||
|
@ -45,7 +45,7 @@ describe('Path Behavior', () => {
|
||||
|
||||
path.transform([2, 0, 0,
|
||||
0, 2, 0,
|
||||
0, 0, 1 ])
|
||||
0, 0, 1 ]);
|
||||
|
||||
canvas.drawPath(path, paint);
|
||||
|
||||
@ -384,33 +384,6 @@ describe('Path Behavior', () => {
|
||||
paint.delete();
|
||||
});
|
||||
|
||||
it('can measure a path', () => {
|
||||
const path = new CanvasKit.Path();
|
||||
path.moveTo(10, 10)
|
||||
.lineTo(40, 50); // should be length 50 because of the 3/4/5 triangle rule
|
||||
|
||||
path.moveTo(80, 0)
|
||||
.lineTo(80, 10)
|
||||
.lineTo(100, 5)
|
||||
.lineTo(80, 0);
|
||||
|
||||
const meas = new CanvasKit.PathMeasure(path, false, 1);
|
||||
expect(meas.getLength()).toBeCloseTo(50.0, 3);
|
||||
const pt = meas.getPosTan(28.7); // arbitrary point
|
||||
expect(pt[0]).toBeCloseTo(27.22, 3); // x
|
||||
expect(pt[1]).toBeCloseTo(32.96, 3); // y
|
||||
expect(pt[2]).toBeCloseTo(0.6, 3); // dy
|
||||
expect(pt[3]).toBeCloseTo(0.8, 3); // dy
|
||||
const subpath = meas.getSegment(20, 40, true); // make sure this doesn't crash
|
||||
|
||||
expect(meas.nextContour()).toBeTruthy();
|
||||
expect(meas.getLength()).toBeCloseTo(51.231, 3);
|
||||
|
||||
expect(meas.nextContour()).toBeFalsy();
|
||||
|
||||
path.delete();
|
||||
});
|
||||
|
||||
it('can measure the contours of a path', () => {
|
||||
const path = new CanvasKit.Path();
|
||||
path.moveTo(10, 10)
|
||||
@ -435,7 +408,7 @@ describe('Path Behavior', () => {
|
||||
|
||||
cont.delete();
|
||||
cont = meas.next();
|
||||
expect(cont).toBeTruthy()
|
||||
expect(cont).toBeTruthy();
|
||||
expect(cont.length()).toBeCloseTo(51.231, 3);
|
||||
|
||||
cont.delete();
|
||||
|
Loading…
Reference in New Issue
Block a user