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

canvas.measureText.width returns int sometimes #25080

Closed
andrey-zakharov opened this issue Dec 1, 2015 · 3 comments
Closed

canvas.measureText.width returns int sometimes #25080

andrey-zakharov opened this issue Dec 1, 2015 · 3 comments

Comments

@andrey-zakharov
Copy link

According to MDN: TextMetrics.width is double.
Its true for dart almost all the time. But attached test fails.
width gives 13 as integer for canvas font "13px Roboto" and text "00":

import 'package:test/test.dart';
import 'dart:html';

main() {
  test("TextMetrics.width", () {
    var canvas = document.createElement('canvas');
    var context = canvas.getContext('2d');
    context.font = '13px Roboto';
    expect( context.measureText("test").width.runtimeType, double );
    expect( context.measureText("00").width.runtimeType, double );
  });
}

textmetrics_test.dart.txt

@andrey-zakharov
Copy link
Author

It gives me

pub run test -pdartium  test/textmetrics_test.dart 
00:03 +0 -1: TextMetrics.width                                                                     
  Expected: ?:<double>
    Actual: ?:<int>

  package:test                expect
  textmetrics_test.dart 10:5  main.<fn>

00:03 +0 -1: Some tests failed.                

@zoechi
Copy link
Contributor

zoechi commented Dec 2, 2015

JavaScript has only double only Dart distinguishes between int and double.
I think this is a dup of ##24882

@kevmoo
Copy link
Member

kevmoo commented Dec 2, 2015

The type of width is num – one shouldn't assume it's either double or int, per @zoechi

https://api.dartlang.org/1.13.0/dart-html/TextMetrics-class.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants