Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
0066c625
Commit
0066c625
authored
10 years ago
by
cyril andreichuk
Browse files
Options
Download
Email Patches
Plain Diff
color blend: fixed gradient's stops order
parent
8f779fcb
master
netstandard2
nuget2.4.2
nuget2.4.1
nuget2.4
nuget2.3
nuget2.2.2
nuget2.2.1
nuget1.7
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/Painting/SvgGradientServer.cs
+24
-19
Source/Painting/SvgGradientServer.cs
Source/Painting/SvgRadialGradientServer.cs
+26
-26
Source/Painting/SvgRadialGradientServer.cs
with
50 additions
and
45 deletions
+50
-45
Source/Painting/SvgGradientServer.cs
+
24
-
19
View file @
0066c625
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Collections
;
using
System.Text
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Drawing.Drawing2D
;
...
@@ -106,13 +103,14 @@ namespace Svg
...
@@ -106,13 +103,14 @@ namespace Svg
/// <param name="opacity">The opacity of the colour blend.</param>
/// <param name="opacity">The opacity of the colour blend.</param>
protected
ColorBlend
GetColourBlend
(
SvgVisualElement
owner
,
float
opacity
)
protected
ColorBlend
GetColourBlend
(
SvgVisualElement
owner
,
float
opacity
)
{
{
ColorBlend
blend
=
new
ColorBlend
();
int
colourBlends
=
this
.
Stops
.
Count
;
int
colourBlends
=
this
.
Stops
.
Count
;
bool
insertStart
=
false
;
bool
insertStart
=
false
;
bool
insertEnd
=
false
;
bool
insertEnd
=
false
;
//gradient.Transform = renderingElement.Transforms.Matrix;
//gradient.Transform = renderingElement.Transforms.Matrix;
//stops should be processed in reverse order
// May need to increase the number of colour blends because the range *must* be from 0.0 to 1.0.
// May need to increase the number of colour blends because the range *must* be from 0.0 to 1.0.
// E.g. 0.5 - 0.8 isn't valid therefore the rest need to be calculated.
// E.g. 0.5 - 0.8 isn't valid therefore the rest need to be calculated.
...
@@ -120,8 +118,8 @@ namespace Svg
...
@@ -120,8 +118,8 @@ namespace Svg
if
(
this
.
Stops
[
0
].
Offset
.
Value
>
0
)
if
(
this
.
Stops
[
0
].
Offset
.
Value
>
0
)
{
{
colourBlends
++;
colourBlends
++;
// Indicate that a colour has to be dynamically added at the
start
// Indicate that a colour has to be dynamically added at the
end
insert
Start
=
true
;
insert
End
=
true
;
}
}
// If the last stop doesn't end at 1 a stop
// If the last stop doesn't end at 1 a stop
...
@@ -129,12 +127,11 @@ namespace Svg
...
@@ -129,12 +127,11 @@ namespace Svg
if
(
lastValue
<
100
||
lastValue
<
1
)
if
(
lastValue
<
100
||
lastValue
<
1
)
{
{
colourBlends
++;
colourBlends
++;
// Indicate that a colour has to be dynamically added at the
end
// Indicate that a colour has to be dynamically added at the
start
insert
End
=
true
;
insert
Start
=
true
;
}
}
blend
.
Positions
=
new
float
[
colourBlends
];
ColorBlend
blend
=
new
ColorBlend
(
colourBlends
);
blend
.
Colors
=
new
Color
[
colourBlends
];
// Set positions and colour values
// Set positions and colour values
int
actualStops
=
0
;
int
actualStops
=
0
;
...
@@ -144,15 +141,21 @@ namespace Svg
...
@@ -144,15 +141,21 @@ namespace Svg
for
(
int
i
=
0
;
i
<
colourBlends
;
i
++)
for
(
int
i
=
0
;
i
<
colourBlends
;
i
++)
{
{
mergedOpacity
=
opacity
*
this
.
Stops
[
actualStops
].
Opacity
;
var
currentStop
=
this
.
Stops
[
this
.
Stops
.
Count
-
1
-
actualStops
];
position
=
(
this
.
Stops
[
actualStops
].
Offset
.
ToDeviceValue
(
owner
)
/
owner
.
Bounds
.
Width
);
colour
=
Color
.
FromArgb
((
int
)(
mergedOpacity
*
255
),
this
.
Stops
[
actualStops
++].
Colour
);
mergedOpacity
=
opacity
*
currentStop
.
Opacity
;
position
=
1
-
(
currentStop
.
Offset
.
ToDeviceValue
(
owner
)
/
owner
.
Bounds
.
Width
);
colour
=
Color
.
FromArgb
((
int
)(
mergedOpacity
*
255
),
currentStop
.
Colour
);
actualStops
++;
// Insert this colour before itself at position 0
// Insert this colour before itself at position 0
if
(
insertStart
&&
i
==
0
)
if
(
insertStart
&&
i
==
0
)
{
{
blend
.
Positions
[
i
]
=
0.0f
;
blend
.
Positions
[
i
]
=
0.0f
;
blend
.
Colors
[
i
++]
=
colour
;
blend
.
Colors
[
i
]
=
colour
;
i
++;
}
}
blend
.
Positions
[
i
]
=
position
;
blend
.
Positions
[
i
]
=
position
;
...
@@ -161,8 +164,10 @@ namespace Svg
...
@@ -161,8 +164,10 @@ namespace Svg
// Insert this colour after itself at position 0
// Insert this colour after itself at position 0
if
(
insertEnd
&&
i
==
colourBlends
-
2
)
if
(
insertEnd
&&
i
==
colourBlends
-
2
)
{
{
blend
.
Positions
[
i
+
1
]
=
1.0f
;
i
++;
blend
.
Colors
[++
i
]
=
colour
;
blend
.
Positions
[
i
]
=
1.0f
;
blend
.
Colors
[
i
]
=
colour
;
}
}
}
}
...
@@ -184,12 +189,12 @@ namespace Svg
...
@@ -184,12 +189,12 @@ namespace Svg
public
override
SvgElement
DeepCopy
<
T
>()
public
override
SvgElement
DeepCopy
<
T
>()
{
{
var
newObj
=
base
.
DeepCopy
<
T
>()
as
SvgGradientServer
;
var
newObj
=
base
.
DeepCopy
<
T
>()
as
SvgGradientServer
;
newObj
.
SpreadMethod
=
this
.
SpreadMethod
;
newObj
.
SpreadMethod
=
this
.
SpreadMethod
;
newObj
.
GradientUnits
=
this
.
GradientUnits
;
newObj
.
GradientUnits
=
this
.
GradientUnits
;
newObj
.
InheritGradient
=
this
.
InheritGradient
;
newObj
.
InheritGradient
=
this
.
InheritGradient
;
return
newObj
;
return
newObj
;
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/Painting/SvgRadialGradientServer.cs
+
26
-
26
View file @
0066c625
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Drawing.Drawing2D
;
...
@@ -79,14 +76,19 @@ namespace Svg
...
@@ -79,14 +76,19 @@ namespace Svg
public
override
Brush
GetBrush
(
SvgVisualElement
renderingElement
,
float
opacity
)
public
override
Brush
GetBrush
(
SvgVisualElement
renderingElement
,
float
opacity
)
{
{
float
radius
=
this
.
Radius
.
ToDeviceValue
(
renderingElement
);
if
(
radius
<=
0
)
{
return
null
;
}
GraphicsPath
path
=
new
GraphicsPath
();
GraphicsPath
path
=
new
GraphicsPath
();
float
left
=
this
.
CenterX
.
ToDeviceValue
(
renderingElement
);
float
left
=
this
.
CenterX
.
ToDeviceValue
(
renderingElement
);
float
top
=
this
.
CenterY
.
ToDeviceValue
(
renderingElement
,
true
);
float
top
=
this
.
CenterY
.
ToDeviceValue
(
renderingElement
,
true
);
float
radius
=
this
.
Radius
.
ToDeviceValue
(
renderingElement
);
RectangleF
boundingBox
=
(
this
.
GradientUnits
==
SvgCoordinateUnits
.
ObjectBoundingBox
)
?
renderingElement
.
Bounds
:
renderingElement
.
OwnerDocument
.
GetDimensions
();
RectangleF
boundingBox
=
(
this
.
GradientUnits
==
SvgCoordinateUnits
.
ObjectBoundingBox
)
?
renderingElement
.
Bounds
:
renderingElement
.
OwnerDocument
.
GetDimensions
();
if
(
radius
>
0
)
{
path
.
AddEllipse
(
path
.
AddEllipse
(
boundingBox
.
Left
+
left
-
radius
,
boundingBox
.
Left
+
left
-
radius
,
boundingBox
.
Top
+
top
-
radius
,
boundingBox
.
Top
+
top
-
radius
,
...
@@ -105,9 +107,6 @@ namespace Svg
...
@@ -105,9 +107,6 @@ namespace Svg
return
brush
;
return
brush
;
}
}
return
null
;
}
public
override
SvgElement
DeepCopy
()
public
override
SvgElement
DeepCopy
()
{
{
...
@@ -118,13 +117,14 @@ namespace Svg
...
@@ -118,13 +117,14 @@ namespace Svg
public
override
SvgElement
DeepCopy
<
T
>()
public
override
SvgElement
DeepCopy
<
T
>()
{
{
var
newObj
=
base
.
DeepCopy
<
T
>()
as
SvgRadialGradientServer
;
var
newObj
=
base
.
DeepCopy
<
T
>()
as
SvgRadialGradientServer
;
newObj
.
CenterX
=
this
.
CenterX
;
newObj
.
CenterX
=
this
.
CenterX
;
newObj
.
CenterY
=
this
.
CenterY
;
newObj
.
CenterY
=
this
.
CenterY
;
newObj
.
Radius
=
this
.
Radius
;
newObj
.
Radius
=
this
.
Radius
;
newObj
.
FocalX
=
this
.
FocalX
;
newObj
.
FocalX
=
this
.
FocalX
;
newObj
.
FocalY
=
this
.
FocalY
;
newObj
.
FocalY
=
this
.
FocalY
;
return
newObj
;
return
newObj
;
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help