1 Debian patch touch this file
-
Fix ivy dependencies.
- Author
- Bas Couwenberg <[email protected]>
- Bug
- https://josm.openstreetmap.de/ticket/24839
- Forwarded
- not-needed
| •1 | /* |
| 2 | * MIT License |
| 3 | * |
| 4 | * Copyright (c) 2023-2025 Jannis Weis |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 7 | * associated documentation files (the "Software"), to deal in the Software without restriction, |
| 8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in all copies or |
| 13 | * substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 16 | * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | * |
| 21 | */ |
| 22 | package com.github.weisj.jsvg.paint.impl.jdk; |
| 23 | |
| 24 | import java.awt.*; |
| 25 | import java.awt.geom.AffineTransform; |
| 26 | import java.awt.image.ColorModel; |
| 27 | import java.lang.ref.SoftReference; |
| 28 | |
| 29 | import org.jetbrains.annotations.NotNull; |
| 30 | |
| 31 | /* |
| 32 | * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. DO NOT ALTER OR |
| 33 | * REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 34 | * |
| 35 | * This code is free software; you can redistribute it and/or modify it under the terms of the GNU |
| 36 | * General Public License version 2 only, as published by the Free Software Foundation. Oracle |
| 37 | * designates this particular file as subject to the "Classpath" exception as provided by Oracle in |
| 38 | * the LICENSE file that accompanied this code. |
| 39 | * |
| 40 | * This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without |
| 41 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 42 | * General Public License version 2 for more details (a copy is included in the LICENSE file that |
| 43 | * accompanied this code). |
| 44 | * |
| 45 | * You should have received a copy of the GNU General Public License version 2 along with this work; |
| 46 | * if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 47 | * 02110-1301 USA. |
| 48 | * |
| 49 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or visit www.oracle.com |
| 50 | * if you need additional information or have any questions. |
| 51 | */ |
| 52 | |
| 53 | /** |
| 54 | * This is the superclass for Paints which use a multiple color |
| 55 | * gradient to fill in their raster. It provides storage for variables and |
| 56 | * enumerated values common to |
| 57 | * {@code LinearGradientPaint} and {@code RadialGradientPaint}. |
| 58 | * |
| 59 | * @author Nicholas Talian, Vincent Hardy, Jim Graham, Jerry Evans |
| 60 | * @since 1.6 |
| 61 | */ |
| 62 | public abstract class SVGMultipleGradientPaint implements Paint { |
| 63 | |
| 64 | /** The transparency of this paint object. */ |
| 65 | final int transparency; |
| 66 | |
| 67 | /** Gradient keyframe values in the range 0 to 1. */ |
| 68 | final float @NotNull [] fractions; |
| 69 | |
| 70 | /** Gradient colors. */ |
| 71 | final @NotNull Color @NotNull [] colors; |
| 72 | |
| 73 | /** Transform to apply to gradient. */ |
| 74 | final @NotNull AffineTransform gradientTransform; |
| 75 | |
| 76 | /** The method to use when painting outside the gradient bounds. */ |
| 77 | final @NotNull MultipleGradientPaint.CycleMethod cycleMethod; |
| 78 | |
| 79 | /** The color space in which to perform the gradient interpolation. */ |
| 80 | final @NotNull MultipleGradientPaint.ColorSpaceType colorSpace; |
| 81 | |
| 82 | /** |
| 83 | * The following fields are used only by MultipleGradientPaintContext |
| 84 | * to cache certain values that remain constant and do not need to be |
| 85 | * recalculated for each context created from this paint instance. |
| 86 | */ |
| 87 | ColorModel model; |
| 88 | float[] normalizedIntervals; |
| 89 | boolean isSimpleLookup; |
| 90 | SoftReference<int[][]> gradients; |
| 91 | SoftReference<int[]> gradient; |
| 92 | int fastGradientArraySize; |
| 93 | |
| 94 | /** |
| 95 | * Package-private constructor. |
| 96 | * |
| 97 | * @param fractions numbers ranging from 0.0 to 1.0 specifying the |
| 98 | * distribution of colors along the gradient |
| 99 | * @param colors array of colors corresponding to each fractional value |
| 100 | * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT}, |
| 101 | * or {@code REPEAT} |
| 102 | * @param colorSpace which color space to use for interpolation, |
| 103 | * either {@code SRGB} or {@code LINEAR_RGB} |
| 104 | * @param gradientTransform transform to apply to the gradient |
| 105 | * |
| 106 | * @throws NullPointerException |
| 107 | * if {@code fractions} array is null, |
| 108 | * or {@code colors} array is null, |
| 109 | * or {@code gradientTransform} is null, |
| 110 | * or {@code cycleMethod} is null, |
| 111 | * or {@code colorSpace} is null |
| 112 | * @throws IllegalArgumentException |
| 113 | * if {@code fractions.length != colors.length}, |
| 114 | * or {@code colors} is less than 2 in size, |
| 115 | * or a {@code fractions} value is less than 0.0 or greater than 1.0, |
| 116 | * or the {@code fractions} are not provided in strictly increasing order |
| 117 | */ |
| 118 | SVGMultipleGradientPaint(float @NotNull [] fractions, |
| 119 | @NotNull Color @NotNull [] colors, |
| 120 | @NotNull MultipleGradientPaint.CycleMethod cycleMethod, |
| 121 | @NotNull MultipleGradientPaint.ColorSpaceType colorSpace, |
| 122 | @NotNull AffineTransform gradientTransform) { |
| 123 | if (fractions.length != colors.length) { |
| 124 | throw new IllegalArgumentException("Colors and fractions must have equal size"); |
| 125 | } |
| 126 | |
| 127 | if (colors.length < 2) { |
| 128 | throw new IllegalArgumentException("User must specify at least 2 colors"); |
| 129 | } |
| 130 | |
| 131 | // check that values are in the proper range and progress |
| 132 | // in increasing order from 0 to 1 |
| 133 | float previousFraction = -1.0f; |
| 134 | for (float currentFraction : fractions) { |
| 135 | if (currentFraction < 0f || currentFraction > 1f) { |
| 136 | throw new IllegalArgumentException("Fraction values must be in the range 0 to 1: " + currentFraction); |
| 137 | } |
| 138 | |
| 139 | if (currentFraction <= previousFraction) { |
| 140 | throw new IllegalArgumentException("Keyframe fractions must be increasing: " + currentFraction); |
| 141 | } |
| 142 | |
| 143 | previousFraction = currentFraction; |
| 144 | } |
| 145 | |
| 146 | if (fractions[0] != 0f) { |
| 147 | throw new IllegalStateException("Gradient start point must be equal to zero"); |
| 148 | } |
| 149 | |
| 150 | if (fractions[fractions.length - 1] != 1f) { |
| 151 | throw new IllegalStateException("Gradient end point must be equal to one"); |
| 152 | } |
| 153 | |
| 154 | this.fractions = fractions; |
| 155 | this.colors = colors; |
| 156 | |
| 157 | // copy some flags |
| 158 | this.colorSpace = colorSpace; |
| 159 | this.cycleMethod = cycleMethod; |
| 160 | |
| 161 | // copy the gradient transform |
| 162 | this.gradientTransform = gradientTransform; |
| 163 | |
| 164 | // determine transparency |
| 165 | boolean opaque = true; |
| 166 | for (Color color : colors) { |
| 167 | opaque = opaque && (color.getAlpha() == 0xff); |
| 168 | } |
| 169 | this.transparency = opaque ? OPAQUE : TRANSLUCENT; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public int getTransparency() { |
| 174 | return transparency; |
| 175 | } |
| 176 | } |