Skip to content
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

[web] Fixes IE11 crash due to missing canvas ellipse support and font polyfill failure #16965

Merged
merged 6 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/canvas_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class _CanvasPool extends _SaveStackTracking {
break;
case PathCommandTypes.ellipse:
final Ellipse ellipse = command;
ctx.ellipse(
DomRenderer.ellipse(ctx,
ellipse.x,
ellipse.y,
ellipse.radiusX,
Expand Down Expand Up @@ -563,14 +563,14 @@ class _CanvasPool extends _SaveStackTracking {

void drawOval(ui.Rect rect, ui.PaintingStyle style) {
context.beginPath();
context.ellipse(rect.center.dx, rect.center.dy, rect.width / 2,
DomRenderer.ellipse(context, rect.center.dx, rect.center.dy, rect.width / 2,
rect.height / 2, 0, 0, 2.0 * math.pi, false);
contextHandle.paint(style);
}

void drawCircle(ui.Offset c, double radius, ui.PaintingStyle style) {
context.beginPath();
context.ellipse(c.dx, c.dy, radius, radius, 0, 0, 2.0 * math.pi, false);
DomRenderer.ellipse(context, c.dx, c.dy, radius, radius, 0, 0, 2.0 * math.pi, false);
contextHandle.paint(style);
}

Expand Down
20 changes: 20 additions & 0 deletions lib/web_ui/lib/src/engine/dom_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,26 @@ flt-glass-pane * {
}
}

static bool _ellipseFeatureDetected;

/// Draws CanvasElement ellipse with fallback.
static void ellipse(html.CanvasRenderingContext2D context,
double centerX, double centerY, double radiusX, double radiusY,
double rotation, double startAngle, double endAngle, bool antiClockwise) {
_ellipseFeatureDetected ??= js_util.getProperty(context, 'ellipse') != null;
if (_ellipseFeatureDetected) {
context.ellipse(centerX, centerY, radiusX, radiusY,
rotation, startAngle, endAngle, antiClockwise);
} else {
context.save();
context.translate(centerX, centerY);
context.rotate(rotation);
context.scale(radiusX, radiusY);
context.arc(0, 0, 1, startAngle, endAngle, antiClockwise);
context.restore();
}
}

/// The element corresponding to the only child of the root surface.
html.Element get _rootApplicationElement {
final html.Element lastElement = rootElement.children.last;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/rrect_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class _RRectToCanvasRenderer extends _RRectRenderer {

void ellipse(double centerX, double centerY, double radiusX, double radiusY,
double rotation, double startAngle, double endAngle, bool antiClockwise) {
context.ellipse(centerX, centerY, radiusX, radiusY, rotation, startAngle,
DomRenderer.ellipse(context, centerX, centerY, radiusX, radiusY, rotation, startAngle,
endAngle, antiClockwise);
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/web_ui/lib/src/engine/text/font_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ class _PolyfillFontManager extends FontManager {
paragraph.style.position = 'absolute';
paragraph.style.visibility = 'hidden';
paragraph.style.fontSize = '72px';
paragraph.style.fontFamily = 'sans-serif';
final String fallbackFontName = browserEngine == BrowserEngine.ie11 ?
'Times New Roman' : 'sans-serif';
paragraph.style.fontFamily = fallbackFontName;
if (descriptors['style'] != null) {
paragraph.style.fontStyle = descriptors['style'];
}
Expand All @@ -257,7 +259,7 @@ class _PolyfillFontManager extends FontManager {
html.document.body.append(paragraph);
final int sansSerifWidth = paragraph.offsetWidth;

paragraph.style.fontFamily = "'$family', sans-serif";
paragraph.style.fontFamily = "'$family', $fallbackFontName";

final Completer<void> completer = Completer<void>();

Expand All @@ -269,8 +271,10 @@ class _PolyfillFontManager extends FontManager {
completer.complete();
} else {
if (DateTime.now().difference(_fontLoadStart) > _fontLoadTimeout) {
completer.completeError(
Exception('Timed out trying to load font: $family'));
// Let application waiting for fonts continue with fallback.
completer.complete();
// Throw unhandled exception for logging.
throw Exception('Timed out trying to load font: $family');
} else {
Timer(_fontLoadRetryDuration, _watchWidth);
}
Expand Down