Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
45e02daf
Unverified
Commit
45e02daf
authored
Oct 23, 2020
by
Cyp
Committed by
GitHub
Oct 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly handle centerSlice with resoultion-aware assets. (#68325)
parent
1edec6fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
decoration_image.dart
packages/flutter/lib/src/painting/decoration_image.dart
+8
-8
paint_image_test.dart
packages/flutter/test/painting/paint_image_test.dart
+20
-0
No files found.
packages/flutter/lib/src/painting/decoration_image.dart
View file @
45e02daf
...
@@ -448,12 +448,9 @@ void paintImage({
...
@@ -448,12 +448,9 @@ void paintImage({
Size
inputSize
=
Size
(
image
.
width
.
toDouble
(),
image
.
height
.
toDouble
());
Size
inputSize
=
Size
(
image
.
width
.
toDouble
(),
image
.
height
.
toDouble
());
Offset
?
sliceBorder
;
Offset
?
sliceBorder
;
if
(
centerSlice
!=
null
)
{
if
(
centerSlice
!=
null
)
{
sliceBorder
=
Offset
(
sliceBorder
=
inputSize
/
scale
-
centerSlice
.
size
as
Offset
;
centerSlice
.
left
+
inputSize
.
width
-
centerSlice
.
right
,
centerSlice
.
top
+
inputSize
.
height
-
centerSlice
.
bottom
,
);
outputSize
=
outputSize
-
sliceBorder
as
Size
;
outputSize
=
outputSize
-
sliceBorder
as
Size
;
inputSize
=
inputSize
-
sliceBorder
as
Size
;
inputSize
=
inputSize
-
sliceBorder
*
scale
as
Size
;
}
}
fit
??=
centerSlice
==
null
?
BoxFit
.
scaleDown
:
BoxFit
.
fill
;
fit
??=
centerSlice
==
null
?
BoxFit
.
scaleDown
:
BoxFit
.
fill
;
assert
(
centerSlice
==
null
||
(
fit
!=
BoxFit
.
none
&&
fit
!=
BoxFit
.
cover
));
assert
(
centerSlice
==
null
||
(
fit
!=
BoxFit
.
none
&&
fit
!=
BoxFit
.
cover
));
...
@@ -559,7 +556,7 @@ void paintImage({
...
@@ -559,7 +556,7 @@ void paintImage({
}
}
}
}
final
bool
needSave
=
repeat
!=
ImageRepeat
.
noRepeat
||
flipHorizontally
;
final
bool
needSave
=
centerSlice
!=
null
||
repeat
!=
ImageRepeat
.
noRepeat
||
flipHorizontally
;
if
(
needSave
)
if
(
needSave
)
canvas
.
save
();
canvas
.
save
();
if
(
repeat
!=
ImageRepeat
.
noRepeat
)
if
(
repeat
!=
ImageRepeat
.
noRepeat
)
...
@@ -581,11 +578,12 @@ void paintImage({
...
@@ -581,11 +578,12 @@ void paintImage({
canvas
.
drawImageRect
(
image
,
sourceRect
,
tileRect
,
paint
);
canvas
.
drawImageRect
(
image
,
sourceRect
,
tileRect
,
paint
);
}
}
}
else
{
}
else
{
canvas
.
scale
(
1
/
scale
);
if
(
repeat
==
ImageRepeat
.
noRepeat
)
{
if
(
repeat
==
ImageRepeat
.
noRepeat
)
{
canvas
.
drawImageNine
(
image
,
centerSlice
,
destinationRect
,
paint
);
canvas
.
drawImageNine
(
image
,
_scaleRect
(
centerSlice
,
scale
),
_scaleRect
(
destinationRect
,
scale
)
,
paint
);
}
else
{
}
else
{
for
(
final
Rect
tileRect
in
_generateImageTileRects
(
rect
,
destinationRect
,
repeat
))
for
(
final
Rect
tileRect
in
_generateImageTileRects
(
rect
,
destinationRect
,
repeat
))
canvas
.
drawImageNine
(
image
,
centerSlice
,
tileRect
,
paint
);
canvas
.
drawImageNine
(
image
,
_scaleRect
(
centerSlice
,
scale
),
_scaleRect
(
tileRect
,
scale
)
,
paint
);
}
}
}
}
if
(
needSave
)
if
(
needSave
)
...
@@ -619,3 +617,5 @@ Iterable<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, Im
...
@@ -619,3 +617,5 @@ Iterable<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, Im
yield
fundamentalRect
.
shift
(
Offset
(
i
*
strideX
,
j
*
strideY
));
yield
fundamentalRect
.
shift
(
Offset
(
i
*
strideX
,
j
*
strideY
));
}
}
}
}
Rect
_scaleRect
(
Rect
rect
,
double
scale
)
=>
Rect
.
fromLTRB
(
rect
.
left
*
scale
,
rect
.
top
*
scale
,
rect
.
right
*
scale
,
rect
.
bottom
*
scale
);
packages/flutter/test/painting/paint_image_test.dart
View file @
45e02daf
...
@@ -108,6 +108,26 @@ void main() {
...
@@ -108,6 +108,26 @@ void main() {
FlutterError
.
onError
=
oldFlutterError
;
FlutterError
.
onError
=
oldFlutterError
;
});
});
test
(
'centerSlice with scale ≠ 1'
,
()
async
{
final
TestCanvas
canvas
=
TestCanvas
();
paintImage
(
canvas:
canvas
,
rect:
const
Rect
.
fromLTRB
(
10
,
20
,
430
,
420
),
image:
image300x300
,
scale:
2.0
,
centerSlice:
const
Rect
.
fromLTRB
(
50
,
40
,
250
,
260
),
);
final
Invocation
command
=
canvas
.
invocations
.
firstWhere
((
Invocation
invocation
)
{
return
invocation
.
memberName
==
#drawImageNine
;
});
expect
(
command
,
isNotNull
);
expect
(
command
.
positionalArguments
[
0
],
equals
(
image300x300
));
expect
(
command
.
positionalArguments
[
1
],
equals
(
const
Rect
.
fromLTRB
(
100.0
,
80.0
,
500.0
,
520.0
)));
expect
(
command
.
positionalArguments
[
2
],
equals
(
const
Rect
.
fromLTRB
(
20.0
,
40.0
,
860.0
,
840.0
)));
});
testWidgets
(
'Reports Image painting'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Reports Image painting'
,
(
WidgetTester
tester
)
async
{
late
ImageSizeInfo
imageSizeInfo
;
late
ImageSizeInfo
imageSizeInfo
;
int
count
=
0
;
int
count
=
0
;
...
...
Write
Preview
Markdown
is supported
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