ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
364 stars 75 forks source link

Text.js: Fixes, Docs #98

Closed videlais closed 11 years ago

videlais commented 11 years ago

Summary: -- Text.js no longer supports scaling.* -- Text.js now also has all of its functions documented in JSDocs format. -- Unit tests for text.js have been updated and testing has been enabled again

(Note: It will need to be added back to jaws-dynamic.js too for testing to actually work.)

*Because Sprite.js uses its internal image property to create its scaling, it can rely on the fact that the property is basically a constant in all calculations. Its internal width and height can be scaled according to a factor multiplied by the size of the image (which never changes).

Text.js doesn't have that same relationship to its width and height. It is drawn /in/ and not /from/ its dimensions. This means that, should scaling be enabled, it would constantly be in flux as each new call to cacheOffsets would increase or decrease its internal width and height without the weight of something like an image.width to keep it as a factor.

It could still be added back in the future though. For the most accurate measurements, it should probably use the context.measureText for width and context.font for height values. However, both are relative to the font family used -- and the current object uses pixels instead of points anyway for size consistency.