Author: ben
Date: 2007-07-01 20:03:04 -0700 (Sun, 01 Jul 2007)
New Revision: 5568
Modified:
openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs
openlaszlo/branches/legals/WEB-INF/lps/schema/lzx.rnc
openlaszlo/branches/legals/test/lztest/lztest-textstyle.lzx
openlaszlo/branches/legals/test/text/renderingcomparison.lzx
Log:
Change 20070701-ben-d by [EMAIL PROTECTED] on 2007-07-01 20:01:49 PDT
in /Users/ben/src/svn/openlaszlo/branches/legals2
for http://svn.openlaszlo.org/openlaszlo/branches/legals
Summary: [UPDATED] Improve text rendering in swf8, add api for text rendering
hints
New Features: new api on LzText to control swf8 rendering parameters
Bugs Fixed:
Technical Reviewer: max
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Added four new virtual attributes to LzText, each of which control an aspect
of advanced text rendering in swf8: sharpness, thickness, antiAliasType,
and gridFit. These attributes only have an effect in swf8; in other runtimes,
they will quietly be no-ops. We provide set/get for each of these new virtual
attributes, and give them good initial and default values.
Note that the default values are set such that <text>boring</text> will
use normal rendering, because advanced rendering causes a performance hit. To
get the advanced rendering, just set antiAliasType="advanced" on the text
object.
Added capability "advancedfonts" for these text rendering attributes; made it
true for swf, false for dhtml.
Release Notes:
To get advanced rendering in swf8, just set antiAliasType="advanced" on a text
object.
Details:
Tests:
http://localhost:8080/legals/test/lztest/lztest-textstyle.lzx?lzr=swf8&debug=true
sussurate should look good but blurry. mimsy borogroves should look not great.
"i should look bad" and "pixel gridfit" should have weird color bands around
the text
If you visit that url in Flash Player 7, all the text should look the same, and
a
bit crunchy.
"ant doc" still works
http://localhost:8080/legals/test/text/renderingcomparison.lzx?lzr=swf8
should look really cool, with each of the text objects in the top three
rows looking slightly different.
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
2007-07-02 02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzSprite.js
2007-07-02 03:03:04 UTC (rev 5568)
@@ -217,6 +217,7 @@
,audio: false
,accessibility: false
,htmlinputtext: false
+ ,advancedfonts: false
}
LzSprite.prototype.__updateQuirks = function(){
@@ -1455,15 +1456,7 @@
this.__contextmenu = cmenu;
}
-/**
- * LzView.getContextMenu
- * Return the current context menu
- */
-LzSprite.prototype.getContextMenu = function() {
- return this.__contextmenu;
-}
-
if (LzSprite.prototype.quirks.ie_leak_prevention) {
LzSprite.prototype.__sprites = {};
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
2007-07-02 02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzSprite.as
2007-07-02 03:03:04 UTC (rev 5568)
@@ -39,6 +39,7 @@
,audio: true
,accessibility: true
,htmlinputtext: true
+ ,advancedfonts: true
}
/**
@@ -1534,7 +1535,6 @@
LzSprite.prototype.setContextMenu = function ( cmenu ){
// For back compatibility, we accept either LzContextMenu or (Flash
primitive) ContextMenu
if (! (cmenu instanceof ContextMenu)) {
- this.__contextmenu = cmenu;
cmenu = cmenu.__LZcontextMenu();
} else {
if ($debug) Debug.warn("Passing a Flash ContextMenu to
LzView.setContextMenu is deprecated, use LzContextMenu instead");
@@ -1561,15 +1561,6 @@
}
/**
- * LzView.getContextMenu
- * Return the current context menu
- */
-LzSprite.prototype.getContextMenu = function() {
- return this.__contextmenu;
-}
-
-
-/**
* Register for update when the button gets the focus.
* Set the behavior of the enter key depending on whether the field is
* multiline or not.
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
2007-07-02 02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/swf/LzTextSprite.as
2007-07-02 03:03:04 UTC (rev 5568)
@@ -745,8 +745,73 @@
}
+/***
+ * Sets what type of antialiasing the text field should use. Only works in swf8
+ * and higher.
+ * @param aliasType "normal" or "advanced"
+ */
+LzTextSprite.prototype.setAntiAliasType = function( aliasType ){
+ this.__LZtextclip.antiAliasType = aliasType;
+}
/**
+ * Gets the kind of antialiasing set on this text object
+ */
+LzTextSprite.prototype.getAntiAliasType = function() {
+ return this.__LZtextclip.antiAliasType;
+}
+
+/***
+ * Sets what type of gridfitting the text field should use. Only works in swf8
+ * and higher.
+ * @param gridFit "none" "subpixel" or "pixel"
+ */
+LzTextSprite.prototype.setGridFit = function( gridFit ){
+ this.__LZtextclip.gridFit = gridFit;
+}
+
+/**
+ * Gets the kind of antialiasing set on this text object
+ */
+LzTextSprite.prototype.getGridFit = function() {
+ return this.__LZtextclip.gridFit;
+}
+
+
+
+/***
+ * Sets the sharpness for the text rendering
+ * Only works in swf8 and higher.
+ * @param sharpness -400 to 400
+ */
+LzTextSprite.prototype.setSharpness = function( sharpness ){
+ this.__LZtextclip.sharpness = sharpness;
+}
+
+/**
+* Gets the sharpness rendering property of this text object
+ */
+LzTextSprite.prototype.getSharpness = function() {
+ return this.__LZtextclip.sharpness;
+}
+
+/***
+ * Sets the thickness for the text rendering
+ * Only works in swf8 and higher.
+ * @param thickness -200 to 200
+ */
+LzTextSprite.prototype.setThickness = function( thickness ){
+ this.__LZtextclip.thickness = thickness;
+}
+
+/**
+* Gets the thickness rendering property of this text object
+ */
+LzTextSprite.prototype.getThickness = function() {
+ return this.__LZtextclip.thickness;
+}
+
+/**
* @access private
*/
LzTextSprite.prototype.__LZforceScrollAttrs = function () {
Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs 2007-07-02
02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/views/LzText.lzs 2007-07-02
03:03:04 UTC (rev 5568)
@@ -44,7 +44,10 @@
* @initarg String text
* @initarg Number maxlength: maximum number of characters allowed in this
field
* default: null
- *
+ * @initarg String antiAliasType (swf8 only)
+ * @initarg String gridFit (swf8 only)
+ * @initarg Number sharpness (swf8 only)
+ * @initarg Number thickness (swf8 only)
* @initarg String pattern: regexp describing set of characters allowed in
this field
* Restrict the characters that can be entered to a pattern
* specified by a regular expression.
@@ -246,6 +249,31 @@
this.setPattern(args.pattern);
}
+
+ if ('antiAliasType' in args && args.antiAliasType != null) {
+ this.setAntiAliasType(args.antiAliasType);
+ } else {
+ this.setAntiAliasType("normal");
+ }
+
+ if ('gridFit' in args && args.gridFit != null) {
+ this.setGridFit(args.gridFit);
+ } else {
+ this.setGridFit("subpixel");
+ }
+
+ if ('sharpness' in args && args.sharpness != null) {
+ this.setSharpness(args.sharpness);
+ } else {
+ this.setSharpness(0);
+ }
+
+ if ('thickness' in args && args.thickness != null) {
+ this.setThickness(args.thickness);
+ } else {
+ this.setThickness(0);
+ }
+
}
/**
@@ -316,6 +344,24 @@
/**
+ * @lzxtype string
+ * @modifiers virtual
+ */
+// no var decl since this is a virtual field
+setters.antiAliasType = "setAntiAliasType";
+defaultattrs.antiAliasType = "normal";
+
+setters.gridFit = "setGridFit";
+defaultattrs.gridfit = "subpixel";
+
+setters.sharpness = "setSharpness";
+defaultattrs.sharpness = 0;
+
+setters.thickness = "setThickness";
+defaultattrs.thickness = 0;
+
+
+/**
* setResize set behavior of text field width when new text is added.
* LzText only (cannot be used with LzInputText).
* @param Boolean val: if true, the textfield will recompute it's width after
setText() is called
@@ -774,9 +820,111 @@
this.sprite.setEmbedFonts(onroff);
}
+/***
+ * Sets what type of antialiasing the text field should use. Only works in swf8
+ * and higher.
+ * @param aliasType "normal" or "advanced"
+ */
+function setAntiAliasType( aliasType ){
+ if (this.sprite.capabilities.advancedfonts) {
+ if ((aliasType == "normal") || (aliasType == "advanced")) {
+ this.antiAliasType = aliasType;
+ this.sprite.setAntiAliasType(aliasType);
+ } else if ($debug) {
+ Debug.warn("antiAliasType invalid, must be 'normal' or 'advanced',
but you said '" + aliasType + "'");
+ }
+ }
+}
+/**
+ * Gets the kind of antialiasing set on this text object
+ */
+function getAntiAliasType() {
+ if (this.sprite.capabilities.advancedfonts) {
+ return this.antiAliasType;
+ }
+}
+/***
+ * Sets what type of grid fitting the text field should use.
+ * Only works in swf8 and higher.
+ * @param gridFit "none", "pixel", or "subpixel"
+ */
+function setGridFit( gridFit ){
+ if (this.sprite.capabilities.advancedfonts) {
+ if ((gridFit == "none") || (gridFit == "pixel") || (gridFit ==
"subpixel")) {
+ this.gridFit = gridFit;
+ this.sprite.setGridFit(gridFit);
+ } else if ($debug) {
+ Debug.warn("gridFit invalid, must be 'none', 'pixel', or
'subpixel' but you said '" + gridFit + "'");
+ }
+ }
+}
+
/**
+ * Gets the kind of grid fitting set on this text object
+ */
+function getGridFit() {
+ if (this.sprite.capabilities.advancedfonts) {
+ return this.gridFit;
+ }
+}
+
+
+/***
+ * Sets the sharpness for the text rendering
+ * Only works in swf8 and higher.
+ * @param sharpness -400 to 400
+ */
+function setSharpness( sharpness ){
+ if (this.sprite.capabilities.advancedfonts) {
+ if ((sharpness >= -400) && (sharpness <= 400)) {
+ this.sharpness = sharpness;
+ this.sprite.setSharpness(sharpness);
+ } else if ($debug) {
+ Debug.warn("sharpness out of range, must be -400 to 400");
+ }
+ }
+}
+
+/**
+ * Gets the sharpness rendering property of this text object
+ */
+function getSharpness() {
+ if (this.sprite.capabilities.advancedfonts) {
+ return this.sharpness;
+ }
+}
+
+
+/***
+ * Sets the thickness for the text rendering
+ * Only works in swf8 and higher.
+ * @param thickness -200 to 200
+ */
+function setThickness( thickness ){
+ if (this.sprite.capabilities.advancedfonts) {
+ if ((thickness >= -200) && (thickness <= 200)) {
+ this.thickness = thickness;
+ this.sprite.setThickness(thickness);
+ } else if ($debug) {
+ Debug.warn("thickness out of range, must be -200 to 200");
+ }
+ }
+}
+
+/**
+ * Gets the thickness rendering property of this text object
+ */
+function getThickness() {
+ if (this.sprite.capabilities.advancedfonts) {
+ return this.thickness;
+ }
+}
+
+
+
+/**
* @access private
*/
//TODO Remove this
Modified: openlaszlo/branches/legals/WEB-INF/lps/schema/lzx.rnc
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/schema/lzx.rnc 2007-07-02
02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/WEB-INF/lps/schema/lzx.rnc 2007-07-02
03:03:04 UTC (rev 5568)
@@ -389,8 +389,16 @@
[a:defaultValue="null"]
attribute maxlength {numberExpression}? &
attribute pattern {string}? &
- attribute label {string}?
-
+ attribute label {string}? &
+ [a:defaultValue="advanced"]
+ attribute antiAliasType {"normal" | "advanced"}? &
+ [a:defaultValue="subpixel"]
+ attribute gridFit {"none" | "pixel" | "subpixel"}? &
+ [a:defaultValue="0"]
+ attribute sharpness {numberExpression}? &
+ [a:defaultValue="0"]
+ attribute thickness {numberExpression}?
+
textContent =
(attribute text {xsd:string}
| text?)
Modified: openlaszlo/branches/legals/test/lztest/lztest-textstyle.lzx
===================================================================
--- openlaszlo/branches/legals/test/lztest/lztest-textstyle.lzx 2007-07-02
02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/test/lztest/lztest-textstyle.lzx 2007-07-02
03:03:04 UTC (rev 5568)
@@ -2,12 +2,18 @@
<!--
covers-tags : lztext
-->
+ <font src="helmetr.ttf" name="Helvetica" />
<include href="lztest/lztestmanager.lzx" />
<simplelayout axis="y" spacing="2" />
<text id="t1" />
<text fontstyle="bold" id="t2" fgcolor="0xffccff" />
- <text id="t3" />
+ <text id="t3" font="Helvetica" />
+ <text id="t4" font="Helvetica" fontsize="24" antiAliasType="advanced"
>susurrate</text>
+ <text id="t5" font="Helvetica" fontsize="24" antiAliasType="advanced"
>mimsy borogroves</text>
+ <text id="t6" font="Helvetica" fontsize="24" antiAliasType="normal"
sharpness="27" thickness="-8">hello</text>
+ <text id="t7" font="Helvetica" fontsize="24" antiAliasType="advanced"
sharpness="400" gridFit="none">i should look bad</text>
+ <text id="t8" font="Helvetica" fontsize="24" antiAliasType="advanced"
sharpness="400" gridFit="pixel">pixel gridfit</text>
<script><![CDATA[
@@ -19,23 +25,74 @@
LzTestManager.assertEquals( "project runway", t1.getText());
}
-textStyleSuite.testColor = function () {
-
+textStyleSuite.testColor = function () {
+
// color set at compile time
LzTestManager.assertEquals(0xffccff, t2.getAttribute("fgcolor"), "fgcolor
set at compile time");
LzTestManager.assertEquals('bold', t2.getAttribute("fontstyle"),
"fontstyle set at compile time");
- // color changed at runtime
+ // color changed at runtime
t3.setAttribute("bgcolor", 0x000088);
LzTestManager.assertEquals(0x000088, t3.getAttribute("bgcolor")), "bgcolor
set at run time";
t3.setAttribute("fgcolor", 0xFF0000)
LzTestManager.assertEquals( 0xFF0000, t3.getAttribute("fgcolor"), "fgcolor
set at runtime");
}
+
+textStyleSuite.testRenderingHints = function () {
+ if (t2.sprite.capabilities.advancedfonts) {
+ LzTestManager.assertEquals( 0, t3.getSharpness() ); // should be 0 by
default
+ LzTestManager.assertEquals( 0, t3.getThickness() ); // should be 0 by
default
+ t4.setSharpness(377);
+ LzTestManager.assertEquals( 377, t4.getSharpness() );
+ t4.setThickness(112);
+ LzTestManager.assertEquals( 112, t4.getThickness() );
+ t4.setSharpness(-212);
+ LzTestManager.assertEquals( -212, t4.getSharpness() );
+
+ LzTestManager.assertEquals( 27, t6.getSharpness() );
+ LzTestManager.assertEquals( -8, t6.getThickness() );
+
+ LzTestManager.assertEquals( "subpixel", t2.getGridFit() );
+ LzTestManager.assertEquals( "subpixel", t3.getGridFit() );
+ LzTestManager.assertEquals( "none", t7.getGridFit() );
+ LzTestManager.assertEquals( "pixel", t8.getGridFit() );
+ }
+}
+textStyleSuite.testRenderingDefaults = function () {
+ if (t2.sprite.capabilities.advancedfonts) {
+ LzTestManager.assertEquals("advanced", t4.getAntiAliasType()); //
should be "advanced" by default
+ LzTestManager.assertEquals("advanced", t5.getAntiAliasType()); //
should be "advanced" by default
+ t5.setAntiAliasType("normal");
+ LzTestManager.assertEquals("normal", t5.getAntiAliasType());
+ t5.setAntiAliasType("weirdo"); // should have no effect, not a legal
value
+ LzTestManager.assertEquals("normal", t5.getAntiAliasType());
+ }
+}
+
+textStyleSuite.testHintsLimits = function () {
+ if (t2.sprite.capabilities.advancedfonts) {
+ t4.setSharpness(-212);
+ t4.setSharpness(515); // should be out of range, shouldn't change value
+ LzTestManager.assertEquals( -212, t4.getSharpness() );
+ t4.setSharpness(-2378); // should be out of range, shouldn't change
value
+ LzTestManager.assertEquals( -212, t4.getSharpness() );
+ t4.setThickness(315); // should be out of range, shouldn't change value
+ LzTestManager.assertEquals( 112, t4.getThickness() );
+ t4.setThickness(-2378); // should be out of range, shouldn't change
value
+ LzTestManager.assertEquals( 112, t4.getThickness() );
+ }
+}
+
+
+
+
textStyleSuite.addTest(textStyleSuite.testJustText);
-textStyleSuite.addTest(textStyleSuite.testColor);
+textStyleSuite.addTest(textStyleSuite.testColor);
+textStyleSuite.addTest(textStyleSuite.testRenderingHints);
+textStyleSuite.addTest(textStyleSuite.testHintsLimits);
+textStyleSuite.addTest(textStyleSuite.testRenderingDefaults);
-
]]>
</script>
@@ -43,7 +100,7 @@
</canvas>
<!--
/* X_LZ_COPYRIGHT_BEGIN ***************************************************
-* Copyright 2006 Laszlo Systems, Inc. All Rights Reserved. *
+* Copyright 2006-2007 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* X_LZ_COPYRIGHT_END ******************************************************/
-->
Modified: openlaszlo/branches/legals/test/text/renderingcomparison.lzx
===================================================================
--- openlaszlo/branches/legals/test/text/renderingcomparison.lzx
2007-07-02 02:49:41 UTC (rev 5567)
+++ openlaszlo/branches/legals/test/text/renderingcomparison.lzx
2007-07-02 03:03:04 UTC (rev 5568)
@@ -14,14 +14,14 @@
</class>
<class name="multitextsample" width="200">
- <attribute name="antiAliasType" value="normal" />
- <attribute name="gridFit" value="none" />
- <attribute name="thickness" value="0" />
- <attribute name="sharpness" value="0" />
+ <attribute name="antiAliasType" value="advanced" type="string" />
+ <attribute name="gridFit" value="none" type="string" />
+ <attribute name="thickness" value="0" type="number"/>
+ <attribute name="sharpness" value="0" type="number" />
<simplelayout axis="y" />
<sampletext fontsize="9" text="As sands in the hourglass, such are" />
<sampletext fontsize="12" text="Carol is living proof of the
resilience" />
- <sampletext fontsize="15" text="Unfortunately, Frederic" />
+ <sampletext fontsize="15" text="Unfortunately, Oliver" />
<sampletext fontsize="24" text="Oxygen-starved!" />
</class>
@@ -86,26 +86,12 @@
/>
</view>
- <description label="gridFit = none, pixel, subpixel
(antiAliasType='normal')" />
- <view>
- <simplelayout axis="x" spacing="5" />
- <multitextsample id="tGFnormal"
- gridFit="normal"
- />
- <multitextsample id="tGFpixel"
- gridFit="pixel"
- />
- <multitextsample id="tGFsubpixel"
- gridFit="subpixel"
- />
- </view>
-
<description label="gridFit = none, pixel, subpixel
(antiAliasType='advanced')" />
<view>
<simplelayout axis="x" spacing="5" />
<multitextsample id="tGFnormalaaa"
- gridFit="normal"
- antiAliasType="advanced"
+ gridFit="none"
+ antiAliasType="advanced"
width="200"
/>
<multitextsample id="tGFpixelaaa"
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins