-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement filter region (#2441)
# Summary Implement proper handling for filter region according to the specs: * [FilterEffectsRegion](https://www.w3.org/TR/SVG11/filters.html#FilterEffectsRegion) * [FilterPrimitiveSubRegion](https://www.w3.org/TR/SVG11/filters.html#FilterPrimitiveSubRegion) enabling user to specify * `filterUnits` * `primitiveUnits` * `x` * `y` * `width` * `height` on `Filter` element and the last four on filter primitives. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ✅ | | Android | ✅ | | Web | ✅ |
- Loading branch information
Showing
15 changed files
with
271 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.horcrux.svg; | ||
|
||
import android.graphics.Rect; | ||
import android.graphics.RectF; | ||
import com.facebook.react.bridge.Dynamic; | ||
|
||
public class FilterRegion { | ||
SVGLength mX; | ||
SVGLength mY; | ||
SVGLength mW; | ||
SVGLength mH; | ||
|
||
public void setX(Dynamic x) { | ||
mX = SVGLength.from(x); | ||
} | ||
|
||
public void setY(Dynamic y) { | ||
mY = SVGLength.from(y); | ||
} | ||
|
||
public void setWidth(Dynamic width) { | ||
mW = SVGLength.from(width); | ||
} | ||
|
||
public void setHeight(Dynamic height) { | ||
mH = SVGLength.from(height); | ||
} | ||
|
||
public Rect getCropRect(VirtualView view, FilterProperties.Units units, RectF renderableBounds) { | ||
double x, y, width, height; | ||
if (units == FilterProperties.Units.USER_SPACE_ON_USE) { | ||
x = view.relativeOn(this.mX, view.getSvgView().getCanvasWidth()); | ||
y = view.relativeOn(this.mY, view.getSvgView().getCanvasHeight()); | ||
width = view.relativeOn(this.mW, view.getSvgView().getCanvasWidth()); | ||
height = view.relativeOn(this.mH, view.getSvgView().getCanvasHeight()); | ||
return new Rect((int) x, (int) y, (int) (x + width), (int) (y + height)); | ||
} else { // FilterProperties.Units.OBJECT_BOUNDING_BOX | ||
x = view.relativeOnFraction(this.mX, renderableBounds.width()); | ||
y = view.relativeOnFraction(this.mY, renderableBounds.height()); | ||
width = view.relativeOnFraction(this.mW, renderableBounds.width()); | ||
height = view.relativeOnFraction(this.mH, renderableBounds.height()); | ||
return new Rect( | ||
(int) (renderableBounds.left + x), | ||
(int) (renderableBounds.top + y), | ||
(int) (renderableBounds.left + x + width), | ||
(int) (renderableBounds.top + y + height)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.