Skip to content

Commit

Permalink
ART.Text now vertically aligns to the top instead of the middle of th…
Browse files Browse the repository at this point in the history
…e first row, if no path is supplied

- Better consistency with the rest of the API and the HTML/CSS box model.
- Paths are still vertically aligned middle. Neither bottom nor top alignment is useful for paths.
- Alphabetic baseline would be optimal but there is no proper way to support it in VML.
  • Loading branch information
sebmarkbage committed Jul 22, 2010
1 parent 92c8291 commit 940b775
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Source/ART.SVG.js
Expand Up @@ -333,7 +333,6 @@ ART.SVG.Text = new Class({

initialize: function(text, font, alignment, path){
this.parent('text');
this.element.setAttribute('dominant-baseline', 'middle'); // Only middle baseline is supported in VML
this.draw.apply(this, arguments);
},

Expand Down Expand Up @@ -374,8 +373,13 @@ ART.SVG.Text = new Class({

// Note: Gecko will (incorrectly) align gradients for each row, while others applies one for the entire element

var lines = String(text).split(/\r?\n/), l = lines.length;
var lines = String(text).split(/\r?\n/), l = lines.length,
baseline = paths ? 'middle' : 'text-before-edge';

if (paths && l > paths.length) l = paths.length;

element.setAttribute('dominant-baseline', baseline);

for (var i = 0; i < l; i++){
var line = lines[i], row;
if (paths){
Expand All @@ -387,7 +391,7 @@ ART.SVG.Text = new Class({
row.setAttribute('x', 0);
row.setAttribute('dy', i == 0 ? '0' : '1em');
}
row.setAttribute('dominant-baseline', 'middle');
row.setAttribute('dominant-baseline', baseline);
row.appendChild(document.createTextNode(line));
element.appendChild(row);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/ART.VML.js
Expand Up @@ -533,7 +533,7 @@ ART.VML.Text = new Class({
this.currentPath = path = new ART.Path(path);
this.element.path = path.toVML(precision);
} else if (!this.currentPath){
var i = -1, offsetRows = '';
var i = -1, offsetRows = '\n';
while ((i = text.indexOf('\n', i + 1)) > -1) offsetRows += '\n';
textPath.string = offsetRows + textPath.string;
this.element.path = 'm0,0l1,0';
Expand Down

0 comments on commit 940b775

Please sign in to comment.