Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1778 Path cropping #1873

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

zero41120
Copy link
Contributor

Issue: #1778
Implemented a cropping logic for path using canvas transformation.

Above Here is the original polygon cropping feature.
209

This is the new path cropping feature
211

The example rectangular shape in polygon and path has the same dimension,
showing that the new path cropping crops correct location.
213

zero41120 and others added 9 commits August 14, 2020 20:59
My lack of understanding of sketch canvas causes the cropping path not translated correctly. My assumption is that if we can idsable it on an devices like iOS, then we should be able to use it without the sketch canvas
User can optionally set the cropWithoutSketch to false to use the sketch canvas when needed.
@zero41120
Copy link
Contributor Author

@iangilman In our enterprise software, we have been using this feature for long time and didn't notice any major issue.
Would you take look and see if something is missing?

Copy link
Member

@iangilman iangilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for taking so long to get to this! I really fell off of the OSD track in 2020. I'm trying to get back to it, though!

This looks like a great new feature... good to be able to add curves in to our cropping! I have a number of comments/questions, but hopefully we can work through them all if you're still up for it :) Thank you for contributing this!


/**
* This function converts the top left viewport coordinates to pixels coordinates
* @param {Boolean} current Pass true for the current location; defaults to false (target location).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a documentation line for withPixelDensityRatio.

@@ -1883,6 +1939,56 @@ function compareTiles( previousBest, tile ) {
return previousBest;
}

/**
* This function checks if the path cropping is ready.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be marked as private with @private.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to add a little more documentation about what this function does and what its purpose is.

}

/**
* This function crops the view with tiledImage._croppingPaths by transforming
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mark this as @private and document the useSketch argument.

@@ -201,6 +201,37 @@ $.Drawer.prototype = {
context.clip();
},

/**
* This function will create multiple polygon paths on the drawing context by provided polygons,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get clear with our terminology. We already have clipping by polygon, and now we are adding clipping by path. In the doc comment here, we shouldn't refer to the paths as polygons.

/**
* This function will create multiple polygon paths on the drawing context by provided polygons,
* then clip the context to the paths.
* @param {Path2D} - path objects to clip with.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSeadragon supports IE11, which does not support Path2D. We should add something to the doc comments for this feature to make it clear that it's up to the developer to come up with an alternate strategy for IE11 if they support that browser.

* var pathData = "M 500,500 h 200 v 200 h -200 z";
* var pathObj = document.createElementNS("http://www.w3.org/2000/svg", "path");
* pathObj.setAttribute('d', pathData);
* @param cropWithoutSketch - optional - indicate that cropping path should not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this? Seems like an implementation detail we wouldn't necessarily want to expose.

@@ -678,6 +678,38 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
this._setScale(height / this.normHeight, immediately);
},

/**
* Sets an array of paths to crop the TiledImage during draw tiles.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure this function is going to be where people are most likely to look to learn about this feature, so this is the place to do some extra documentation, including the fact that this feature doesn't work on IE11, and the fact that you can't crop with both paths and polygons.

On that latter point, setCroppingPolygons should be updated to include a doc comment on the same point.

* pathObj.setAttribute('d', pathData);
* @param cropWithoutSketch - optional - indicate that cropping path should not
* use the sketch canvas default to true.
* @param preventSketchTransform - optional - indicate that the cropping path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this?

* @param {Boolean} current Pass true for the current location; defaults to false (target location).
* @returns {OpenSeadragon.Point}
*/
getOriginPixelCoordinate: function(current, withPixelDensityRatio) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about whether we need this as part of the public API. My initial thought is that it should be private.

Either way, it needs a better name, as "pixel" isn't specific enough. Maybe getOriginDrawerCoordinate.

tiledImage.getRotation(true) % 360 === 0 && // TODO: support tile edge smoothing with tiled image rotation.
$.supportsCanvas) {
// When zoomed in a lot (>100%) the tile edges are visible.
// So we have to composite them at ~100% and scale them up together.
// Note: Disabled on iOS devices per default as it causes a native crash
// Node: Disabled when _croppingPaths are provided because stacking translation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: I assume "node" should be "note".

@zero41120
Copy link
Contributor Author

Thanks for the feedback/comments.
I'm a bit busy recently. I will get back to this pull request once I have some free time.

@iangilman
Copy link
Member

@zero41120 great! No rush (clearly it took me a while to get back to you), but when you can, it would be lovely :)

try {
var context = tiledImage._drawer._getContext(useSketch);
var viewport = tiledImage._drawer.viewport;
var oldMatrix = context.getTransform();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #1912, this won't work on IE 11, which we still support. That said, IE 11 also doesn't support Path2D, so it's actually fine to use in this context (in other words, you won't be using this feature at all on IE 11). We just need to make sure this code doesn't get hit when not using this feature (which certainly seems to be the case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants