usvg/tree/filter.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//! SVG filter types.
use strict_num::PositiveF32;
use crate::{BlendMode, Color, Group, NonEmptyString, NonZeroF32, NonZeroRect, Opacity};
/// A filter element.
///
/// `filter` element in the SVG.
#[derive(Debug)]
pub struct Filter {
pub(crate) id: NonEmptyString,
pub(crate) rect: NonZeroRect,
pub(crate) primitives: Vec<Primitive>,
}
impl Filter {
/// Element's ID.
///
/// Taken from the SVG itself.
/// Used only during SVG writing. `resvg` doesn't rely on this property.
pub fn id(&self) -> &str {
self.id.get()
}
/// Filter region.
///
/// `x`, `y`, `width` and `height` in the SVG.
pub fn rect(&self) -> NonZeroRect {
self.rect
}
/// A list of filter primitives.
pub fn primitives(&self) -> &[Primitive] {
&self.primitives
}
}
/// A filter primitive element.
#[derive(Clone, Debug)]
pub struct Primitive {
pub(crate) rect: NonZeroRect,
pub(crate) color_interpolation: ColorInterpolation,
pub(crate) result: String,
pub(crate) kind: Kind,
}
impl Primitive {
/// Filter subregion.
///
/// `x`, `y`, `width` and `height` in the SVG.
pub fn rect(&self) -> NonZeroRect {
self.rect
}
/// Color interpolation mode.
///
/// `color-interpolation-filters` in the SVG.
pub fn color_interpolation(&self) -> ColorInterpolation {
self.color_interpolation
}
/// Assigned name for this filter primitive.
///
/// `result` in the SVG.
pub fn result(&self) -> &str {
&self.result
}
/// Filter primitive kind.
pub fn kind(&self) -> &Kind {
&self.kind
}
}
/// A filter kind.
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub enum Kind {
Blend(Blend),
ColorMatrix(ColorMatrix),
ComponentTransfer(ComponentTransfer),
Composite(Composite),
ConvolveMatrix(ConvolveMatrix),
DiffuseLighting(DiffuseLighting),
DisplacementMap(DisplacementMap),
DropShadow(DropShadow),
Flood(Flood),
GaussianBlur(GaussianBlur),
Image(Image),
Merge(Merge),
Morphology(Morphology),
Offset(Offset),
SpecularLighting(SpecularLighting),
Tile(Tile),
Turbulence(Turbulence),
}
impl Kind {
/// Checks that `FilterKind` has a specific input.
pub fn has_input(&self, input: &Input) -> bool {
match self {
Kind::Blend(ref fe) => fe.input1 == *input || fe.input2 == *input,
Kind::ColorMatrix(ref fe) => fe.input == *input,
Kind::ComponentTransfer(ref fe) => fe.input == *input,
Kind::Composite(ref fe) => fe.input1 == *input || fe.input2 == *input,
Kind::ConvolveMatrix(ref fe) => fe.input == *input,
Kind::DiffuseLighting(ref fe) => fe.input == *input,
Kind::DisplacementMap(ref fe) => fe.input1 == *input || fe.input2 == *input,
Kind::DropShadow(ref fe) => fe.input == *input,
Kind::Flood(_) => false,
Kind::GaussianBlur(ref fe) => fe.input == *input,
Kind::Image(_) => false,
Kind::Merge(ref fe) => fe.inputs.iter().any(|i| i == input),
Kind::Morphology(ref fe) => fe.input == *input,
Kind::Offset(ref fe) => fe.input == *input,
Kind::SpecularLighting(ref fe) => fe.input == *input,
Kind::Tile(ref fe) => fe.input == *input,
Kind::Turbulence(_) => false,
}
}
}
/// Identifies input for a filter primitive.
#[allow(missing_docs)]
#[derive(Clone, PartialEq, Debug)]
pub enum Input {
SourceGraphic,
SourceAlpha,
Reference(String),
}
/// A color interpolation mode.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum ColorInterpolation {
SRGB,
LinearRGB,
}
impl Default for ColorInterpolation {
fn default() -> Self {
ColorInterpolation::LinearRGB
}
}
/// A blend filter primitive.
///
/// `feBlend` element in the SVG.
#[derive(Clone, Debug)]
pub struct Blend {
pub(crate) input1: Input,
pub(crate) input2: Input,
pub(crate) mode: BlendMode,
}
impl Blend {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input1(&self) -> &Input {
&self.input1
}
/// Identifies input for the given filter primitive.
///
/// `in2` in the SVG.
pub fn input2(&self) -> &Input {
&self.input2
}
/// A blending mode.
///
/// `mode` in the SVG.
pub fn mode(&self) -> BlendMode {
self.mode
}
}
/// A color matrix filter primitive.
///
/// `feColorMatrix` element in the SVG.
#[derive(Clone, Debug)]
pub struct ColorMatrix {
pub(crate) input: Input,
pub(crate) kind: ColorMatrixKind,
}
impl ColorMatrix {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A matrix kind.
///
/// `type` in the SVG.
pub fn kind(&self) -> &ColorMatrixKind {
&self.kind
}
}
/// A color matrix filter primitive kind.
#[derive(Clone, Debug)]
#[allow(missing_docs)]
pub enum ColorMatrixKind {
Matrix(Vec<f32>), // Guarantee to have 20 numbers.
Saturate(PositiveF32),
HueRotate(f32),
LuminanceToAlpha,
}
impl Default for ColorMatrixKind {
fn default() -> Self {
ColorMatrixKind::Matrix(vec![
1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
])
}
}
/// A component-wise remapping filter primitive.
///
/// `feComponentTransfer` element in the SVG.
#[derive(Clone, Debug)]
pub struct ComponentTransfer {
pub(crate) input: Input,
pub(crate) func_r: TransferFunction,
pub(crate) func_g: TransferFunction,
pub(crate) func_b: TransferFunction,
pub(crate) func_a: TransferFunction,
}
impl ComponentTransfer {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// `feFuncR` in the SVG.
pub fn func_r(&self) -> &TransferFunction {
&self.func_r
}
/// `feFuncG` in the SVG.
pub fn func_g(&self) -> &TransferFunction {
&self.func_g
}
/// `feFuncB` in the SVG.
pub fn func_b(&self) -> &TransferFunction {
&self.func_b
}
/// `feFuncA` in the SVG.
pub fn func_a(&self) -> &TransferFunction {
&self.func_a
}
}
/// A transfer function used by `FeComponentTransfer`.
///
/// <https://www.w3.org/TR/SVG11/filters.html#transferFuncElements>
#[derive(Clone, Debug)]
pub enum TransferFunction {
/// Keeps a component as is.
Identity,
/// Applies a linear interpolation to a component.
///
/// The number list can be empty.
Table(Vec<f32>),
/// Applies a step function to a component.
///
/// The number list can be empty.
Discrete(Vec<f32>),
/// Applies a linear shift to a component.
#[allow(missing_docs)]
Linear { slope: f32, intercept: f32 },
/// Applies an exponential shift to a component.
#[allow(missing_docs)]
Gamma {
amplitude: f32,
exponent: f32,
offset: f32,
},
}
/// A composite filter primitive.
///
/// `feComposite` element in the SVG.
#[derive(Clone, Debug)]
pub struct Composite {
pub(crate) input1: Input,
pub(crate) input2: Input,
pub(crate) operator: CompositeOperator,
}
impl Composite {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input1(&self) -> &Input {
&self.input1
}
/// Identifies input for the given filter primitive.
///
/// `in2` in the SVG.
pub fn input2(&self) -> &Input {
&self.input2
}
/// A compositing operation.
///
/// `operator` in the SVG.
pub fn operator(&self) -> CompositeOperator {
self.operator
}
}
/// An images compositing operation.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum CompositeOperator {
Over,
In,
Out,
Atop,
Xor,
Arithmetic { k1: f32, k2: f32, k3: f32, k4: f32 },
}
/// A matrix convolution filter primitive.
///
/// `feConvolveMatrix` element in the SVG.
#[derive(Clone, Debug)]
pub struct ConvolveMatrix {
pub(crate) input: Input,
pub(crate) matrix: ConvolveMatrixData,
pub(crate) divisor: NonZeroF32,
pub(crate) bias: f32,
pub(crate) edge_mode: EdgeMode,
pub(crate) preserve_alpha: bool,
}
impl ConvolveMatrix {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A convolve matrix.
pub fn matrix(&self) -> &ConvolveMatrixData {
&self.matrix
}
/// A matrix divisor.
///
/// `divisor` in the SVG.
pub fn divisor(&self) -> NonZeroF32 {
self.divisor
}
/// A kernel matrix bias.
///
/// `bias` in the SVG.
pub fn bias(&self) -> f32 {
self.bias
}
/// An edges processing mode.
///
/// `edgeMode` in the SVG.
pub fn edge_mode(&self) -> EdgeMode {
self.edge_mode
}
/// An alpha preserving flag.
///
/// `preserveAlpha` in the SVG.
pub fn preserve_alpha(&self) -> bool {
self.preserve_alpha
}
}
/// A convolve matrix representation.
///
/// Used primarily by [`ConvolveMatrix`].
#[derive(Clone, Debug)]
pub struct ConvolveMatrixData {
pub(crate) target_x: u32,
pub(crate) target_y: u32,
pub(crate) columns: u32,
pub(crate) rows: u32,
pub(crate) data: Vec<f32>,
}
impl ConvolveMatrixData {
/// Returns a matrix's X target.
///
/// `targetX` in the SVG.
pub fn target_x(&self) -> u32 {
self.target_x
}
/// Returns a matrix's Y target.
///
/// `targetY` in the SVG.
pub fn target_y(&self) -> u32 {
self.target_y
}
/// Returns a number of columns in the matrix.
///
/// Part of the `order` attribute in the SVG.
pub fn columns(&self) -> u32 {
self.columns
}
/// Returns a number of rows in the matrix.
///
/// Part of the `order` attribute in the SVG.
pub fn rows(&self) -> u32 {
self.rows
}
/// The actual matrix.
pub fn data(&self) -> &[f32] {
&self.data
}
}
impl ConvolveMatrixData {
/// Creates a new `ConvolveMatrixData`.
///
/// Returns `None` when:
///
/// - `columns` * `rows` != `data.len()`
/// - `target_x` >= `columns`
/// - `target_y` >= `rows`
pub(crate) fn new(
target_x: u32,
target_y: u32,
columns: u32,
rows: u32,
data: Vec<f32>,
) -> Option<Self> {
if (columns * rows) as usize != data.len() || target_x >= columns || target_y >= rows {
return None;
}
Some(ConvolveMatrixData {
target_x,
target_y,
columns,
rows,
data,
})
}
/// Returns a matrix value at the specified position.
///
/// # Panics
///
/// - When position is out of bounds.
pub fn get(&self, x: u32, y: u32) -> f32 {
self.data[(y * self.columns + x) as usize]
}
}
/// An edges processing mode.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum EdgeMode {
None,
Duplicate,
Wrap,
}
/// A displacement map filter primitive.
///
/// `feDisplacementMap` element in the SVG.
#[derive(Clone, Debug)]
pub struct DisplacementMap {
pub(crate) input1: Input,
pub(crate) input2: Input,
pub(crate) scale: f32,
pub(crate) x_channel_selector: ColorChannel,
pub(crate) y_channel_selector: ColorChannel,
}
impl DisplacementMap {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input1(&self) -> &Input {
&self.input1
}
/// Identifies input for the given filter primitive.
///
/// `in2` in the SVG.
pub fn input2(&self) -> &Input {
&self.input2
}
/// Scale factor.
///
/// `scale` in the SVG.
pub fn scale(&self) -> f32 {
self.scale
}
/// Indicates a source color channel along the X-axis.
///
/// `xChannelSelector` in the SVG.
pub fn x_channel_selector(&self) -> ColorChannel {
self.x_channel_selector
}
/// Indicates a source color channel along the Y-axis.
///
/// `yChannelSelector` in the SVG.
pub fn y_channel_selector(&self) -> ColorChannel {
self.y_channel_selector
}
}
/// A color channel.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum ColorChannel {
R,
G,
B,
A,
}
/// A drop shadow filter primitive.
///
/// This is essentially `feGaussianBlur`, `feOffset` and `feFlood` joined together.
///
/// `feDropShadow` element in the SVG.
#[derive(Clone, Debug)]
pub struct DropShadow {
pub(crate) input: Input,
pub(crate) dx: f32,
pub(crate) dy: f32,
pub(crate) std_dev_x: PositiveF32,
pub(crate) std_dev_y: PositiveF32,
pub(crate) color: Color,
pub(crate) opacity: Opacity,
}
impl DropShadow {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// The amount to offset the input graphic along the X-axis.
pub fn dx(&self) -> f32 {
self.dx
}
/// The amount to offset the input graphic along the Y-axis.
pub fn dy(&self) -> f32 {
self.dy
}
/// A standard deviation along the X-axis.
///
/// `stdDeviation` in the SVG.
pub fn std_dev_x(&self) -> PositiveF32 {
self.std_dev_x
}
/// A standard deviation along the Y-axis.
///
/// `stdDeviation` in the SVG.
pub fn std_dev_y(&self) -> PositiveF32 {
self.std_dev_y
}
/// A flood color.
///
/// `flood-color` in the SVG.
pub fn color(&self) -> Color {
self.color
}
/// A flood opacity.
///
/// `flood-opacity` in the SVG.
pub fn opacity(&self) -> Opacity {
self.opacity
}
}
/// A flood filter primitive.
///
/// `feFlood` element in the SVG.
#[derive(Clone, Copy, Debug)]
pub struct Flood {
pub(crate) color: Color,
pub(crate) opacity: Opacity,
}
impl Flood {
/// A flood color.
///
/// `flood-color` in the SVG.
pub fn color(&self) -> Color {
self.color
}
/// A flood opacity.
///
/// `flood-opacity` in the SVG.
pub fn opacity(&self) -> Opacity {
self.opacity
}
}
/// A Gaussian blur filter primitive.
///
/// `feGaussianBlur` element in the SVG.
#[derive(Clone, Debug)]
pub struct GaussianBlur {
pub(crate) input: Input,
pub(crate) std_dev_x: PositiveF32,
pub(crate) std_dev_y: PositiveF32,
}
impl GaussianBlur {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A standard deviation along the X-axis.
///
/// `stdDeviation` in the SVG.
pub fn std_dev_x(&self) -> PositiveF32 {
self.std_dev_x
}
/// A standard deviation along the Y-axis.
///
/// `stdDeviation` in the SVG.
pub fn std_dev_y(&self) -> PositiveF32 {
self.std_dev_y
}
}
/// An image filter primitive.
///
/// `feImage` element in the SVG.
#[derive(Clone, Debug)]
pub struct Image {
pub(crate) root: Group,
}
impl Image {
/// `feImage` children.
pub fn root(&self) -> &Group {
&self.root
}
}
/// A diffuse lighting filter primitive.
///
/// `feDiffuseLighting` element in the SVG.
#[derive(Clone, Debug)]
pub struct DiffuseLighting {
pub(crate) input: Input,
pub(crate) surface_scale: f32,
pub(crate) diffuse_constant: f32,
pub(crate) lighting_color: Color,
pub(crate) light_source: LightSource,
}
impl DiffuseLighting {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A surface scale.
///
/// `surfaceScale` in the SVG.
pub fn surface_scale(&self) -> f32 {
self.surface_scale
}
/// A diffuse constant.
///
/// `diffuseConstant` in the SVG.
pub fn diffuse_constant(&self) -> f32 {
self.diffuse_constant
}
/// A lighting color.
///
/// `lighting-color` in the SVG.
pub fn lighting_color(&self) -> Color {
self.lighting_color
}
/// A light source.
pub fn light_source(&self) -> LightSource {
self.light_source
}
}
/// A specular lighting filter primitive.
///
/// `feSpecularLighting` element in the SVG.
#[derive(Clone, Debug)]
pub struct SpecularLighting {
pub(crate) input: Input,
pub(crate) surface_scale: f32,
pub(crate) specular_constant: f32,
pub(crate) specular_exponent: f32,
pub(crate) lighting_color: Color,
pub(crate) light_source: LightSource,
}
impl SpecularLighting {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A surface scale.
///
/// `surfaceScale` in the SVG.
pub fn surface_scale(&self) -> f32 {
self.surface_scale
}
/// A specular constant.
///
/// `specularConstant` in the SVG.
pub fn specular_constant(&self) -> f32 {
self.specular_constant
}
/// A specular exponent.
///
/// Should be in 1..128 range.
///
/// `specularExponent` in the SVG.
pub fn specular_exponent(&self) -> f32 {
self.specular_exponent
}
/// A lighting color.
///
/// `lighting-color` in the SVG.
pub fn lighting_color(&self) -> Color {
self.lighting_color
}
/// A light source.
pub fn light_source(&self) -> LightSource {
self.light_source
}
}
/// A light source kind.
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug)]
pub enum LightSource {
DistantLight(DistantLight),
PointLight(PointLight),
SpotLight(SpotLight),
}
/// A distant light source.
///
/// `feDistantLight` element in the SVG.
#[derive(Clone, Copy, Debug)]
pub struct DistantLight {
/// Direction angle for the light source on the XY plane (clockwise),
/// in degrees from the x axis.
///
/// `azimuth` in the SVG.
pub azimuth: f32,
/// Direction angle for the light source from the XY plane towards the z axis, in degrees.
///
/// `elevation` in the SVG.
pub elevation: f32,
}
/// A point light source.
///
/// `fePointLight` element in the SVG.
#[derive(Clone, Copy, Debug)]
pub struct PointLight {
/// X location for the light source.
///
/// `x` in the SVG.
pub x: f32,
/// Y location for the light source.
///
/// `y` in the SVG.
pub y: f32,
/// Z location for the light source.
///
/// `z` in the SVG.
pub z: f32,
}
/// A spot light source.
///
/// `feSpotLight` element in the SVG.
#[derive(Clone, Copy, Debug)]
pub struct SpotLight {
/// X location for the light source.
///
/// `x` in the SVG.
pub x: f32,
/// Y location for the light source.
///
/// `y` in the SVG.
pub y: f32,
/// Z location for the light source.
///
/// `z` in the SVG.
pub z: f32,
/// X point at which the light source is pointing.
///
/// `pointsAtX` in the SVG.
pub points_at_x: f32,
/// Y point at which the light source is pointing.
///
/// `pointsAtY` in the SVG.
pub points_at_y: f32,
/// Z point at which the light source is pointing.
///
/// `pointsAtZ` in the SVG.
pub points_at_z: f32,
/// Exponent value controlling the focus for the light source.
///
/// `specularExponent` in the SVG.
pub specular_exponent: PositiveF32,
/// A limiting cone which restricts the region where the light is projected.
///
/// `limitingConeAngle` in the SVG.
pub limiting_cone_angle: Option<f32>,
}
/// A merge filter primitive.
///
/// `feMerge` element in the SVG.
#[derive(Clone, Debug)]
pub struct Merge {
pub(crate) inputs: Vec<Input>,
}
impl Merge {
/// List of input layers that should be merged.
///
/// List of `feMergeNode`'s in the SVG.
pub fn inputs(&self) -> &[Input] {
&self.inputs
}
}
/// A morphology filter primitive.
///
/// `feMorphology` element in the SVG.
#[derive(Clone, Debug)]
pub struct Morphology {
pub(crate) input: Input,
pub(crate) operator: MorphologyOperator,
pub(crate) radius_x: PositiveF32,
pub(crate) radius_y: PositiveF32,
}
impl Morphology {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// A filter operator.
///
/// `operator` in the SVG.
pub fn operator(&self) -> MorphologyOperator {
self.operator
}
/// A filter radius along the X-axis.
///
/// A value of zero disables the effect of the given filter primitive.
///
/// `radius` in the SVG.
pub fn radius_x(&self) -> PositiveF32 {
self.radius_x
}
/// A filter radius along the Y-axis.
///
/// A value of zero disables the effect of the given filter primitive.
///
/// `radius` in the SVG.
pub fn radius_y(&self) -> PositiveF32 {
self.radius_y
}
}
/// A morphology operation.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum MorphologyOperator {
Erode,
Dilate,
}
/// An offset filter primitive.
///
/// `feOffset` element in the SVG.
#[derive(Clone, Debug)]
pub struct Offset {
pub(crate) input: Input,
pub(crate) dx: f32,
pub(crate) dy: f32,
}
impl Offset {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
/// The amount to offset the input graphic along the X-axis.
pub fn dx(&self) -> f32 {
self.dx
}
/// The amount to offset the input graphic along the Y-axis.
pub fn dy(&self) -> f32 {
self.dy
}
}
/// A tile filter primitive.
///
/// `feTile` element in the SVG.
#[derive(Clone, Debug)]
pub struct Tile {
pub(crate) input: Input,
}
impl Tile {
/// Identifies input for the given filter primitive.
///
/// `in` in the SVG.
pub fn input(&self) -> &Input {
&self.input
}
}
/// A turbulence generation filter primitive.
///
/// `feTurbulence` element in the SVG.
#[derive(Clone, Copy, Debug)]
pub struct Turbulence {
pub(crate) base_frequency_x: PositiveF32,
pub(crate) base_frequency_y: PositiveF32,
pub(crate) num_octaves: u32,
pub(crate) seed: i32,
pub(crate) stitch_tiles: bool,
pub(crate) kind: TurbulenceKind,
}
impl Turbulence {
/// Identifies the base frequency for the noise function.
///
/// `baseFrequency` in the SVG.
pub fn base_frequency_x(&self) -> PositiveF32 {
self.base_frequency_x
}
/// Identifies the base frequency for the noise function.
///
/// `baseFrequency` in the SVG.
pub fn base_frequency_y(&self) -> PositiveF32 {
self.base_frequency_y
}
/// Identifies the number of octaves for the noise function.
///
/// `numOctaves` in the SVG.
pub fn num_octaves(&self) -> u32 {
self.num_octaves
}
/// The starting number for the pseudo random number generator.
///
/// `seed` in the SVG.
pub fn seed(&self) -> i32 {
self.seed
}
/// Smooth transitions at the border of tiles.
///
/// `stitchTiles` in the SVG.
pub fn stitch_tiles(&self) -> bool {
self.stitch_tiles
}
/// Indicates whether the filter primitive should perform a noise or turbulence function.
///
/// `type` in the SVG.
pub fn kind(&self) -> TurbulenceKind {
self.kind
}
}
/// A turbulence kind for the `feTurbulence` filter.
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TurbulenceKind {
FractalNoise,
Turbulence,
}