Changeset 14328 in josm for trunk/src/com/kitfox/svg/Gradient.java
- Timestamp:
- 2018-10-14T15:15:50+02:00 (8 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/Gradient.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Gradient.java
r11525 r14328 160 160 } 161 161 162 private void buildStops() 163 { 164 ArrayList<Stop> stopList = new ArrayList<>(stops); 165 stopList.sort((o1, o2) -> Float.compare(o1.offset, o2.offset)); 166 167 //Remove doubles 168 for (int i = stopList.size() - 2; i > 0; --i) 169 { 170 if (stopList.get(i + 1).offset == stopList.get(i).offset) 171 { 172 stopList.remove(i + 1); 173 } 174 } 175 176 stopFractions = new float[stopList.size()]; 177 stopColors = new Color[stopList.size()]; 178 int idx = 0; 179 for (Stop stop : stopList) 180 { 181 int stopColorVal = stop.color.getRGB(); 182 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); 183 184 stopColors[idx] = stopColor; 185 stopFractions[idx] = stop.offset; 186 idx++; 187 } 188 } 189 162 190 public float[] getStopFractions() 163 191 { … … 173 201 } 174 202 175 stopFractions = new float[stops.size()]; 176 int idx = 0; 177 for (Stop stop : stops) { 178 float val = stop.offset; 179 if (idx != 0 && val < stopFractions[idx - 1]) 180 { 181 val = stopFractions[idx - 1]; 182 } 183 stopFractions[idx++] = val; 184 } 203 buildStops(); 185 204 186 205 return stopFractions; … … 200 219 } 201 220 202 stopColors = new Color[stops.size()]; 203 int idx = 0; 204 for (Stop stop : stops) { 205 int stopColorVal = stop.color.getRGB(); 206 Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); 207 stopColors[idx++] = stopColor; 208 } 221 buildStops(); 209 222 210 223 return stopColors; 211 }212 213 public void setStops(Color[] colors, float[] fractions)214 {215 if (colors.length != fractions.length)216 {217 throw new IllegalArgumentException();218 }219 220 this.stopColors = colors;221 this.stopFractions = fractions;222 stopRef = null;223 224 } 224 225
Note:
See TracChangeset
for help on using the changeset viewer.
