@@ -42,28 +42,46 @@ var Element = function() {
4242 addTo(div, e);
4343 return div;
4444 };
45+
46+ var rectangle = function(w) { return function(h) {
47+ var e = newElement('div');
48+ e.isElmLeaf = true;
49+ e.style.width = w + "px";
50+ e.style.height = h + "px";
51+ return e;
52+ };
53+ };
54+
4555 var makeText = function(w) { return function(pos) { return function(txt) {
4656 var e = newElement('div');
57+ e.isElmLeaf = true;
4758 e.isElmText = true;
4859 e.innerHTML = txt;
4960 e.style.textAlign = pos;
5061 if (w > 0) e.style.width = w + "px";
51− e.isElmLeaf = true;
52− e.style.visibility = "hidden";
53− e.style.styleFloat = "left";
54− e.style.cssFloat = "left";
55− document.body.appendChild(e);
56− var cStyle = window.getComputedStyle(e);
57− if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
58− e.style.height = cStyle.getPropertyValue("height");
59− document.body.removeChild(e);
60− e.style.visibility = "visible"
61− e.style.styleFloat = "none";
62− e.style.cssFloat = "none";
6362 return e;
6463 };
6564 };
6665 };
66+ var correctTextSize = function(e) {
67+ var w = e.style.width ? e.style.width.slice(0,-2) : 0;
68+
69+ var t = newElement('div');
70+ t.innerHTML = " " + e.innerHTML;
71+ t.style.textAlign = e.style.textAlign;
72+ if (w > 0) { t.style.width = w + "px"; }
73+
74+ t.style.visibility = "hidden";
75+ t.style.styleFloat = "left";
76+ t.style.cssFloat = "left";
77+
78+ document.body.appendChild(t);
79+ var cStyle = window.getComputedStyle(t);
80+ if (w <= 0) e.style.width = cStyle.getPropertyValue("width");
81+ e.style.height = cStyle.getPropertyValue("height");
82+ document.body.removeChild(t);
83+ };
84+
6785 var link = function (href) { return function (e) {
6886 var a = newElement('a');
6987 a.href = Text.fromString(href);
@@ -77,6 +95,7 @@ var Element = function() {
7795 return makeText(0)("left")(Data.String.toText(str)); };
7896 var justifiedText = makeText(0)('justify');
7997 var centeredText = makeText(0)('center');
98+ var rightedText = makeText(0)('right');
8099 var asText = function(v) { return makeText(0)("left")(Value.show(v)); };
81100
82101 var image = function(src) {
@@ -275,6 +294,7 @@ var Element = function() {
275294 collage : collage,
276295 flow : flow,
277296 layers : flow(2),
297+ rectangle : rectangle,
278298
279299 beside : beside,
280300 above : above,
@@ -292,6 +312,7 @@ var Element = function() {
292312 plainText : plainText,
293313 justifiedText : justifiedText,
294314 centeredText : centeredText,
315+ rightedText : rightedText,
295316
296317 // directions
297318 up : 0,
@@ -299,7 +320,9 @@ var Element = function() {
299320 inward : 2,
300321 down : 3,
301322 right : 4,
302− outward : 5
323+ outward : 5,
324+
325+ correctTextSize : correctTextSize
303326 };
304327}();
305328