-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable line join styles and miter limit. #3777
Conversation
Bring my fork up-to-date.
Updating from flutter/engine
FYI, The associated flutter/flutter PR is flutter/flutter#10742 |
lib/ui/painting.dart
Outdated
@@ -271,6 +271,7 @@ enum FilterQuality { | |||
|
|||
/// Styles to use for line endings. | |||
/// | |||
/// Must be in the same order as the SkPaint::Cap enum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a dartdoc, it won't make sense to our users. It should be a regular comment (and indeed there already is such a comment two lines later).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh. :-P
lib/ui/painting.dart
Outdated
@@ -286,6 +287,26 @@ enum StrokeCap { | |||
square, | |||
} | |||
|
|||
/// Styles to use for line joins. | |||
/// | |||
/// Note that this only affects line joins for polygons drawn by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-comments-dartdocs
In particular, avoid "Note that".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, noted. :-) Sorry, I did read that, I just forgot.
lib/ui/painting.dart
Outdated
/// [Canvas.drawPath] and rectangles, not points drawn as lines with | ||
/// [Canvas.drawPoints]. | ||
/// | ||
/// Must be in the same order as the SkPaint::Join enum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a regular comment, matching the style of the other enums here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/// line segments to give a beveled appearance. | ||
bevel, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these docs are great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
lib/ui/painting.dart
Outdated
/// The limit for miters to be drawn on segments when the join is set to | ||
/// [StrokeJoin.miter] and the [style] is set to [PaintingStyle.stroke]. If | ||
/// this limit is exceeded, then a [StrokeJoin.bevel] join will be drawn | ||
/// instead. Note that this may cause some 'popping' of the corners of a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: single space after period, not double
avoid "Note that" (in this case you can probably replace ". Note that
" with just a semicolon).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/ui/painting.dart
Outdated
/// | ||
/// Defaults to zero, which means that a reasonable value will be picked | ||
/// instead of using zero as the limit, which would draw a bevel all the | ||
/// time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some discussion about what the "reasonable value" is based on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's actually always 4. But I didn't want to give a specific value, since it's defined in Skia, and might change. Well, probably not, but still, it could theoretically change.
https://github.com/google/skia/blob/master/src/core/SkPaintDefaults.h#L32
In thinking about this, though, if zero is specified for the miter limit, then we don't set the value in Flutter, and Skia substitutes 4.0 sort of magically and unpredictably.
So I changed it: Flutter now has its own default value (4.0, duh. :-)) and then I check the passed value against 4.0 in C++ to decide whether or not we actually set it. I assume it's not OK to include SkPaintDefaults.h directly, since it's not a public header (because then I'd compare it against SkPaintDefaults_MiterLimit directly).
This makes the whole thing more "normal" in my mind: it has a valid, documentable default that's 4.0, and you actually can set a miter limit of zero which you couldn't before (which basically means do bevel all the time), and the C++ code is using the actual Skia default to decide if it should actually set it on the SkPaint, so it's still efficient.
I also updated the two other "magic" defaults in there (color and blend mode) to use constants so they could be better documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @abarth who may have opinions here.
Maybe Skia should expose these constants? It seems like a valid use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Skia should probably document the default.
lib/ui/painting.dart
Outdated
if (strokeJoin != StrokeJoin.miter) | ||
result.write(' $strokeJoin'); | ||
if (strokeMiterLimit != 0.0) | ||
result.write(' $strokeMiterLimit'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just the number on its own will be weird. I would recommend:
if (strokeJoin == StrokeJoin.miter) {
if (strokeMiterLimit != 0.0)
result.write(' $strokeJoin up to $strokeMiterLimit');
} else {
result.write(' $strokeJoin');
}
...or some such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Ian, please take another look at the defaults changes, and then commit if you like it. Thanks for the review! |
lib/ui/painting.dart
Outdated
@@ -552,20 +615,26 @@ class Paint { | |||
result.write(' hairline'); | |||
if (strokeCap != StrokeCap.butt) | |||
result.write(' $strokeCap'); | |||
if (strokeJoin == StrokeJoin.miter) { | |||
if (strokeMiterLimit != _kStrokeMiterLimitDefault) | |||
result.write('$strokeJoin up to $strokeMiterLimit'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here (and sorry to make you change this oven and over), can we actually make a slight tweak to this?
Printing doubles ends up with ugly strings of digits. What we normally do is print them to 1dp.
This would mean changing the strokeWidth case above to:
result.write(' ${strokeWidth.toStringAsFixed(1)}');
...and this case to:
result.write(' $strokeJoin up to ${strokeMiterLimit.toStringAsFixed(1)}');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I just noticed you're missing a space before $strokeJoin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, and good catch on the space. Done. Also, no problem about changing it until it's right.
lib/ui/painting.dart
Outdated
@@ -375,6 +398,7 @@ class Paint { | |||
_data.setInt32(_kIsAntiAliasOffset, encoded, _kFakeHostEndian); | |||
} | |||
|
|||
// Must be kept in sync with the default in paint.cc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitty nit nit: You don't have a period here at the end of the comment, but you do in the C++ comment. I'd add a period here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
lib/ui/painting.dart
Outdated
@@ -399,6 +423,7 @@ class Paint { | |||
_data.setInt32(_kColorOffset, encoded, _kFakeHostEndian); | |||
} | |||
|
|||
// Must be kept in sync with the default in paint.cc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i feel like i'm just yanking your chain now but you put the period on the comment above and didn't here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. I also found another one, just to spare you the task of commenting on each and every one. [Sorry, I should have done a search the first time.]
Thanks :-) Will land on green. |
This fixes flutter/flutter#7199 and also enables setting of the miter limit.
A separate pull request for the flutter/flutter repo will enable it there once this is committed.
This adds StrokeJoin as a type, and the Paint.strokeJoin property, so that the caller can set the join type for paths and rectangles. Canvas.drawPoints is unaffected by this property (unfortunately, in my opinion) when drawing points as lines.