Permalink
Browse files

- ART.Font contains define / lookup font again.

 - The ART.Font class no longer generates a custom object, as it was kinda useless
 - There is no ART.Font:meaasure anymore. ART:text now returns the measurement. This also means you can no longer chain to ART:text.
  • Loading branch information...
1 parent 377e61c commit 8f3521ea002b791455c02898730b78dbb2b41fd9 @kamicane committed Jan 20, 2010
Showing with 21 additions and 26 deletions.
  1. +1 −1 README.md
  2. +18 −25 Source/ART.Font.js
  3. +2 −0 Source/ART.Shape.js
View
@@ -1,3 +1,3 @@
# MooTools A.R.T.
-Vector-based drawing for widgets, icons, and all that stuff. Pre-alpha.
+Vector-based drawing for widgets, icons, and all that stuff. Alpha.
View
@@ -14,37 +14,29 @@ requires: [ART.Canvas, ART.VML]
...
*/
-ART.Font = new Class({
-
- initialize: function(font){
- this.ascent = font.face.ascent;
- this.descent = font.face.descent;
- this.units = font.face['units-per-em'];
- this.glyphs = font.glyphs;
- this.width = font.w;
- },
-
- measure: function(size, text){
- var width = 0, height = size;
- size = size / this.units;
- for (var i = 0, l = text.length; i < l; ++i){
- var glyph = this.glyphs[text.charAt(i)] || this.glyphs[' '];
- width += size * (glyph.w || this.width);
- }
- return {x: width, y: size * (this.ascent - this.descent)};
- }
+// stub
-});
+ART.Font = function(font){
+ return font;
+};
(function(){
var fonts = {};
+ART.defineFont = function(name, font){
+ fonts[name] = new ART.Font(font);
+};
+
+ART.lookupFont = function(name){
+ return fonts[name];
+};
+
ART.registerFont = function(font){
var face = font.face, name = face['font-family'].toLowerCase().split(' ');
if (face['font-weight'] > 400) name.push('bold');
if (face['font-stretch'] == 'oblique') name.push('italic');
- fonts[name.join('-')] = new ART.Font(font);
+ ART.defineFont(name.join('-'), font);
};
var path = function(path, s, self){
@@ -69,18 +61,19 @@ ART.implement({'text': function(font, size, text){
if (!font) return new Error('The specified font has not been found.');
this.save();
- size = size / font.units;
+ size = size / font.face['units-per-em'];
// Temporary "relative" fix shifting the whole layer by the pointer, since the pointer is lost with path. Should not matter since it's later restored.
- this.shift({x: this.pointer.x, y: this.pointer.y + Math.round(size * font.ascent)});
+ this.shift({x: this.pointer.x, y: this.pointer.y + Math.round(size * font.face.ascent)});
var width = 0;
for (var i = 0, l = text.length; i < l; ++i){
var glyph = font.glyphs[text.charAt(i)] || font.glyphs[' '];
if (glyph.d) path('m' + glyph.d + 'x', size, this);
- var w = size * (glyph.w || font.width);
+ var w = size * (glyph.w || font.w);
this.shift({x: w, y: 0});
width += w;
}
- return this.restore();
+ this.restore();
+ return {x: width, y: size * (font.face.ascent - font.face.descent)};
}});
})();
View
@@ -14,6 +14,8 @@ requires: [ART.Canvas, ART.VML]
...
*/
+// stub
+
ART.Shape = function(shape){
return shape;
};

0 comments on commit 8f3521e

Please sign in to comment.