Review Request 116065: Implement FontLoader type.

Nikita Skovoroda chalkerx at gmail.com
Fri Mar 7 12:50:49 UTC 2014



> On March 5, 2014, 10:08 a.m., Anton Kreuzkamp wrote:
> > src/qtcore.js, line 2108
> > <https://git.reviewboard.kde.org/r/116065/diff/2/?file=246157#file246157line2108>
> >
> >     Why not just use FontLoader !== undefined? Has it a specific reason to use typeof? (with typeof you have to do an expensive string-comparison, after all)
> 
> Nikita Skovoroda wrote:
>     «FontLoader !== undefined» produces a ReferenceError in javascript when FontLoader is not declared =).
>     
>     «a.foo !== undefined» is fine when «a» is declared and «a.foo» is not defined, «var a; a !== undefined» is fine, but not declaring «a» and comparing it to something (even to «undefined») gives an error. 
>     
>     
>     Test this in d8:
>     d8>  try { someUndeclaredVar !== undefined; } catch (e) { print('Error: ' + e + '!' ); }

Or in any browser javascript console:
try { someUndeclaredVar !== undefined; } catch (e) { alert('Error: ' + e + '!' ); }

So when you don't know if a variable has beed declared in some external code, you have to use «typeof variable_name !== 'undefined'» check.

If you declared a variable yourself or when are checking if some property of a (defined) object is defined, you can use both ways:
«typeof object_name.variable_name !== 'undefined'» or «object_name.variable_name !== undefined» and both are valid.

One extra thing to mention is that in ECMAScript ? 5 (current version is 5.1) «undefined» is writable and one can overwrite it, breaking all «!== undefined» logic, but I don't think that that issue should be taken into account nowdays.


- Nikita


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/116065/#review50989
-----------------------------------------------------------


On Feb. 25, 2014, 11:20 p.m., Nikita Skovoroda wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/116065/
> -----------------------------------------------------------
> 
> (Updated Feb. 25, 2014, 11:20 p.m.)
> 
> 
> Review request for QML Web and Anton Kreuzkamp.
> 
> 
> Repository: qmlweb
> 
> 
> Description
> -------
> 
> Implement FontLoader type.
> 
> See http://qt-project.org/doc/qt-5/qml-qtquick-fontloader.html and http://qt-project.org/doc/qt-4.7/qml-fontloader.html
> 
> This currently depends on smnh's MIT-licensed FontLoader.js library
> to get notifications when a font is loaded and trigger all events in time.
> 
> Elements that are using that font through 'font.family: fontId.name' get their dimensions recalculated correctly when the font loads.
> 
> If FontLoader.js is not provided the font is still loaded, but 'status' property is set to Error and dimensions recalculation is triggered after a fixed timeout (3 seconds).
> In this case the user gets a notice in console.log.
> 
> 
> Timeout (3 seconds) is the maximum time for a font to load. If font isn't loaded in this time, status is set to Error.
> Without FontLoader.js dimensions recalculations for elements are triggered after that time.
> 
> For both cases (with and without FontLoader.js) if the font takes more than this time to load, dimensions recalculations for elements that are using this font will not be triggered or will have no effect.
> 
> On the other hand, if the font could not be loaded (with FontLoader.js enabled), the Error status will be set only when this timeout expires.
> 
> 
> Diffs
> -----
> 
>   src/qtcore.js c219e2e 
> 
> Diff: https://git.reviewboard.kde.org/r/116065/diff/
> 
> 
> Testing
> -------
> 
> Works as expected (as described above) with or without FontLoader.js.
> Tested cases when the font should load and when it should fail to load.
> 
> Tested «Text {font.family: fontId.name}» dimensions recalculations.
> 
> Works well for me.
> 
> 
> Thanks,
> 
> Nikita Skovoroda
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/qmlweb/attachments/20140307/45938b3a/attachment.html>


More information about the QmlWeb mailing list