Ignore:
Timestamp:
2018-10-14T15:15:50+02:00 (8 years ago)
Author:
Don-vip
Message:

see #14319, see #16838 - update to svgSalamander 1.1.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/Gradient.java

    r11525 r14328  
    160160    }
    161161
     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
    162190    public float[] getStopFractions()
    163191    {
     
    173201        }
    174202
    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();
    185204
    186205        return stopFractions;
     
    200219        }
    201220
    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();
    209222
    210223        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;
    223224    }
    224225
Note: See TracChangeset for help on using the changeset viewer.