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
aaa9d180
Commit
aaa9d180
authored
Sep 01, 2017
by
Andrew Wilson
Committed by
GitHub
Sep 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle negative and zero sizes. (#11827)
parent
4faa0367
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
5 deletions
+62
-5
box_fit.dart
packages/flutter/lib/src/painting/box_fit.dart
+3
-0
box_painter.dart
packages/flutter/lib/src/painting/box_painter.dart
+3
-1
flutter_logo.dart
packages/flutter/lib/src/painting/flutter_logo.dart
+2
-0
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+8
-2
box_fit_test.dart
packages/flutter/test/painting/box_fit_test.dart
+44
-0
decoration_test.dart
packages/flutter/test/painting/decoration_test.dart
+2
-2
No files found.
packages/flutter/lib/src/painting/box_fit.dart
View file @
aaa9d180
...
...
@@ -125,6 +125,9 @@ class FittedSizes {
/// * [DecoratedBox], [BoxDecoration], and [DecorationImage], which together
/// provide access to [paintImage] at the widgets layer.
FittedSizes
applyBoxFit
(
BoxFit
fit
,
Size
inputSize
,
Size
outputSize
)
{
if
(
inputSize
.
height
<=
0.0
||
inputSize
.
width
<=
0.0
||
outputSize
.
height
<=
0.0
||
outputSize
.
width
<=
0.0
)
return
const
FittedSizes
(
Size
.
zero
,
Size
.
zero
);
Size
sourceSize
,
destinationSize
;
switch
(
fit
)
{
case
BoxFit
.
fill
:
...
...
packages/flutter/lib/src/painting/box_painter.dart
View file @
aaa9d180
...
...
@@ -1212,7 +1212,7 @@ Iterable<Rect> _generateImageTileRects(Rect outputRect, Rect fundamentalRect, Im
/// * `canvas`: The canvas onto which the image will be painted.
/// * `rect`: The region of the canvas into which the image will be painted.
/// The image might not fill the entire rectangle (e.g., depending on the
/// `fit`).
/// `fit`).
If `rect` is empty, nothing is painted.
/// * `image`: The image to paint onto the canvas.
/// * `colorFilter`: If non-null, the color filter to apply when painting the
/// image.
...
...
@@ -1251,6 +1251,8 @@ void paintImage({
})
{
assert
(
canvas
!=
null
);
assert
(
image
!=
null
);
if
(
rect
.
isEmpty
)
return
;
Size
outputSize
=
rect
.
size
;
Size
inputSize
=
new
Size
(
image
.
width
.
toDouble
(),
image
.
height
.
toDouble
());
Offset
sliceBorder
;
...
...
packages/flutter/lib/src/painting/flutter_logo.dart
View file @
aaa9d180
...
...
@@ -375,6 +375,8 @@ class _FlutterLogoPainter extends BoxPainter {
void
paint
(
Canvas
canvas
,
Offset
offset
,
ImageConfiguration
configuration
)
{
offset
+=
_config
.
margin
.
topLeft
;
final
Size
canvasSize
=
_config
.
margin
.
deflateSize
(
configuration
.
size
);
if
(
canvasSize
.
isEmpty
)
return
;
Size
logoSize
;
if
(
_config
.
_position
>
0.0
)
{
// horizontal style
...
...
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
aaa9d180
...
...
@@ -1860,6 +1860,8 @@ class RenderFittedBox extends RenderProxyBox {
@override
bool
hitTest
(
HitTestResult
result
,
{
Offset
position
})
{
if
(
size
.
isEmpty
)
return
false
;
_updatePaintData
();
Matrix4
inverse
;
try
{
...
...
@@ -1875,8 +1877,12 @@ class RenderFittedBox extends RenderProxyBox {
@override
void
applyPaintTransform
(
RenderBox
child
,
Matrix4
transform
)
{
_updatePaintData
();
transform
.
multiply
(
_transform
);
if
(
size
.
isEmpty
)
{
transform
.
setZero
();
}
else
{
_updatePaintData
();
transform
.
multiply
(
_transform
);
}
}
@override
...
...
packages/flutter/test/painting/box_fit_test.dart
View file @
aaa9d180
...
...
@@ -25,5 +25,49 @@ void main() {
result
=
applyBoxFit
(
BoxFit
.
fitHeight
,
const
Size
(
400.0
,
2000.0
),
const
Size
(
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
const
Size
(
200.0
,
2000.0
)));
expect
(
result
.
destination
,
equals
(
const
Size
(
100.0
,
1000.0
)));
_testZeroAndNegativeSizes
(
BoxFit
.
fill
);
_testZeroAndNegativeSizes
(
BoxFit
.
contain
);
_testZeroAndNegativeSizes
(
BoxFit
.
cover
);
_testZeroAndNegativeSizes
(
BoxFit
.
fitWidth
);
_testZeroAndNegativeSizes
(
BoxFit
.
fitHeight
);
_testZeroAndNegativeSizes
(
BoxFit
.
none
);
_testZeroAndNegativeSizes
(
BoxFit
.
scaleDown
);
});
}
void
_testZeroAndNegativeSizes
(
BoxFit
fit
)
{
FittedSizes
result
;
result
=
applyBoxFit
(
fit
,
const
Size
(-
400.0
,
2000.0
),
const
Size
(
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
-
2000.0
),
const
Size
(
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
2000.0
),
const
Size
(-
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
2000.0
),
const
Size
(
100.0
,
-
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
0.0
,
2000.0
),
const
Size
(
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
0.0
),
const
Size
(
100.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
2000.0
),
const
Size
(
0.0
,
1000.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
result
=
applyBoxFit
(
fit
,
const
Size
(
400.0
,
2000.0
),
const
Size
(
100.0
,
0.0
));
expect
(
result
.
source
,
equals
(
Size
.
zero
));
expect
(
result
.
destination
,
equals
(
Size
.
zero
));
}
packages/flutter/test/painting/decoration_test.dart
View file @
aaa9d180
...
...
@@ -213,14 +213,14 @@ void main() {
final
BoxDecoration
boxDecoration
=
new
BoxDecoration
(
image:
backgroundImage
);
final
BoxPainter
boxPainter
=
boxDecoration
.
createBoxPainter
(()
{
assert
(
false
);
});
final
TestCanvas
canvas
=
new
TestCanvas
(<
Invocation
>[]);
boxPainter
.
paint
(
canvas
,
Offset
.
zero
,
const
ImageConfiguration
(
size:
const
Size
(
10
.0
,
1
0.0
)));
boxPainter
.
paint
(
canvas
,
Offset
.
zero
,
const
ImageConfiguration
(
size:
const
Size
(
10
0.0
,
10
0.0
)));
final
Invocation
call
=
canvas
.
invocations
.
singleWhere
((
Invocation
call
)
=>
call
.
memberName
==
#drawImageNine
);
expect
(
call
.
isMethod
,
isTrue
);
expect
(
call
.
positionalArguments
,
hasLength
(
4
));
expect
(
call
.
positionalArguments
[
0
],
const
isInstanceOf
<
TestImage
>());
expect
(
call
.
positionalArguments
[
1
],
new
Rect
.
fromLTRB
(
10.0
,
20.0
,
40.0
,
60.0
));
expect
(
call
.
positionalArguments
[
2
],
new
Rect
.
fromLTRB
(
0.0
,
0.0
,
32.5
,
1
0.0
));
expect
(
call
.
positionalArguments
[
2
],
new
Rect
.
fromLTRB
(
0.0
,
0.0
,
100.0
,
10
0.0
));
expect
(
call
.
positionalArguments
[
3
],
const
isInstanceOf
<
Paint
>());
expect
(
call
.
positionalArguments
[
3
].
isAntiAlias
,
false
);
expect
(
call
.
positionalArguments
[
3
].
colorFilter
,
colorFilter
);
...
...
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