Lively Kernel canvas
// this script is evaluated on world load
MyConsole = WorldMorph.current().submorphs.detect(function(ea){return ea.name == "MyConsole"});
if(!MyConsole) return;
MyConsole = MyConsole.component;
MyConsole.setText("-- start --");
MyConsole.log = function(s) {
this.setText(this.formalModel.getText() + "\n" + s);
};
MyConsole.log("My Console initialized!");
MyConsole.morph.resetScrollPane = function() {
var sp = this.enclosingScrollPane();
if (sp) sp.scrollToBottom();
};
// console.consumers seems to be broken... so we go the hard waz
console.log = console.log.wrap(function(proceed, s) {
MyConsole.log(s)
proceed(s)})
console.log("wrapped console for MyConsole successfully")
FixBoldTextComposition40
10000.00009769295488818399Wikicontroltrue
10000.00001742693381014619Wikicontroltrue
FixTextCompositionLayer
10000.05233630784109585Wikicontroltrue
10007.026026383757136e-24Wikicontroltrue
andexploretheusageofContextJS'sobject-specificanddynamicscopeduringthatactivy202null
10001.5604257243680425e-7Wikicontroltrue
10000.0010984052216680296Wikicontroltrue
10001.6920724468117762e-7Wikicontroltrue
10000.00012900700856563666Wikicontroltrue
10002.2688958619902086e-29Wikicontroltrue
10003.163226531020515e-11Wikicontroltrue
10000.000012704234747596576Wikicontroltrue
10002.8036676917677188e-11Wikicontroltrue
-----falsetruefalse0
worldis1:WorldMorph([[0,0,1735,700]])falsetruefalse0
Errorevaluatinginitializer:SyntaxError:Invalidreturnstatement.falsetruefalse0
startingWikiNavigatorfalsetruefalse0
status207onPROPFINDhttp://lively-kernel.org/repository/webwerkstatt/draft/FixBoldTextComposition.xhtmlfalsetruefalse0
http://lively-kernel.org/repository/webwerkstatt/draft/../lib/anonymous_module_2loadedin35msfalsetruefalse0
http://lively-kernel.org/repository/webwerkstatt/draft/../lib/anonymous_module_1loadedin827msfalsetruefalse0
fontHelvetica40:spacewidth11from51xWidth20falsetruefalse0
fontArial20:spacewidth6from26xWidth10falsetruefalse0
fitWidthfailureonTextMorph.getCharBoundsfalsetruefalse0
fitWidthfailureonTextMorph.getCharBoundsfalsetruefalse0
fitWidthfailureonTextMorph.getCharBoundsfalsetruefalse0
fontArial20:spacewidth6from26xWidth10falsetruefalse0
ResizingSVGcanvasfalsetruefalse0
Moduleloadcheckdone.29modulesloaded.falsetruefalse0
fontCourier12:spacewidth7from21xWidth7falsetruefalse0
status:ReferenceError:Can'tfindvariable:sfalsetruefalse0
normal:11falsetruefalse0
bold:14falsetruefalse0
d.style=[objectCSSStyleDeclaration]falsetruefalse0
-------------------------------------------falsetruefalse0
invoke126262:TextMorph([[0,0,742,1950.800048828125]])falsetruefalse0
-------------------------------------------falsetruefalse0
invoke1:WorldMorph([[0,0,1735,700]])falsetruefalse0
status200onGEThttp://lively-kernel.org/repository/webwerkstatt/draft/FixBoldTextComposition.xhtml?1268745351330falsetruefalse0
extendForSerializationundefinedfalsetruefalse0
status204onPUThttp://lively-kernel.org/repository/webwerkstatt/draft/FixBoldTextComposition.xhtmlfalsetruefalse0
successpublishingworldathttp://lively-kernel.org/repository/webwerkstatt/draft/FixBoldTextComposition.xhtml,status204falsetruefalse0
-------------------------------------------falsetruefalse0
invoke126262:TextMorph([[0,0,742,1950.800048828125]])falsetruefalse0
-------------------------------------------falsetruefalse0
invoke1:WorldMorph([[0,0,1735,700]])falsetruefalse0
status200onGEThttp://lively-kernel.org/repository/webwerkstatt/draft/FixBoldTextComposition.xhtml?1268745351330falsetruefalse0
extendForSerializationundefinedfalsetruefalse097240nulltrue0falsefalsetruetruefalse
false1truefalsenull
nullfalse
nullfalse
nullfalse
nullfalsefalsetruetruefalse
truetrue100false
truefalsenull050
nullfalsetruenullfalse
Consolefalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
VeryllllllongWordBold20
sincetheBugcouldbefoundandprototypicallyfixedwithlayers.Thefixhastobeapplied/portedtothebasesystem202null
100020.812688833792798Wikicontroltrue
doc=document;body=document.body;create=functioncreate(name){//returndoc.createElement(name);returndoc.createElementNS(Namespace.XHTML,name);}family='Helvetica'size=20;d=body.appendChild(create("div"));d.style.kerning=0;d.style.fontFamily=family;d.style.fontSize="50px";//d.style.fontWeight='bold';//body.removeChild(d)string='l'code=string.charCodeAt(0)sub=d.appendChild(create("span"));sub.appendChild(doc.createTextNode(string));sub.style.fontWeight='normal';console.log("normal:"+sub.offsetWidth)d2=body.appendChild(create("div"));d2.style.kerning=0;d2.style.fontFamily=family;d2.style.fontSize="50px";sub2=d2.appendChild(create("span"));sub2.style.fontWeight='bold'sub2.appendChild(doc.createTextNode(string));sub2.offsetWidthconsole.log("bold:"+sub2.offsetWidth)//body.removeChild(d);body.removeChild(d2)newlively.Text.CharacterInfo(sub.offsetWidth,sub.offsetHeight);console.log('d.style='+d.style);10truetruefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
//(newTestRunner()).openIn(this.world())TestCase.subclass("HTMLFontCharWidthCompositionTest",{testFontComputeExtents:function(){varfont=lively.Text.Font.forFamily("Helvetica",100);varboldFont=lively.Text.Font.forFamily("Helvetica",100,'bold')varextents;varboldExtents;withLayers([FixTextCompositionDynamicLayer],function(){extents=font.computeExtents(font.family,font.size);})varcode="l".charCodeAt(0);varcharWidthOfW=extents[code]this.assertEqualState(charWidthOfW,newlively.Text.CharacterInfo(22,115),"charwidthofliswrong");withLayers([FixTextCompositionDynamicLayer],function(){boldExtents=font.computeExtents(boldFont.family,boldFont.size,boldFont.style);})varboldCharWidthOfW=boldExtents[code]this.assertEqualState(boldCharWidthOfW,newlively.Text.CharacterInfo(28,115),"charwidthofliswrong");this.assert(charWidthOfW.width<boldCharWidthOfW.width,"boldlisnotwiderthanregularl");}})24truetruefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
HTMLFontCharWidthCompositionTest(451ms)falsetruefalse0false
cop.tests.ActiveLayersTestfalsetruefalse0false
cop.tests.CopExampleTestfalsetruefalse0false
cop.tests.GetterAndSetterTestfalsetruefalse0false
cop.tests.LayerActivationRestrictionTestfalsetruefalse0false
cop.tests.LayerObjectActivationTestfalsetruefalse0false
cop.tests.LayerStateTestfalsetruefalse0false
cop.tests.LayerSubclassingTestfalsetruefalse0false
cop.tests.LayerTestfalsetruefalse0false
cop.tests.LayerTestCasefalsetruefalse0false7030nullnulltrue0falsefalsetruetruefalse
false1truefalsetruetruefalse
RunTestsfalsenullfalsefalsenull
RunAllTestsfalsenullfalsefalse
Testsrun:1--Testsfailed:0--Time:0.451sfalse
-----falsetruefalse0703-1nulltruefalsetruetruefalse
false1truefalsetruetruefalse
truefalsenull
nullfalsetruenullfalse
TestRunnerfalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
createLayer("FixTextCompositionLayer");createLayer("FixTextCompositionDynamicLayer");lively.Text.Font.fontCache={}layerObject(FixTextCompositionDynamicLayer,lively.Text.Font,{forFamily:function(proceed,familyName,size,style){varcache=this.fontCache;varstyleKey='n';if(style=='bold')styleKey='b';if(style=='italic')styleKey='i';if(style=='bold-italic')styleKey='bi';varkey=familyName+":"+size+":"+styleKey;varentry=cache[key];if(entry)returnentry;try{entry=newlively.Text.Font(familyName,size,style);}catch(er){console.log("%swhenlookingfor%s:%s",er,familyName,size);returnnull;}cache[key]=entry;returnentry;}});layerClass(FixTextCompositionDynamicLayer,lively.Text.Font,{getCharWidth:function(proceed,charString){//console.log("getCharWidth"+charString)varcode=charString.charCodeAt(0);if(!this.extents)this.extents=this.computeExtents(this.family,this.size,this.style);varw=this.extents[code]?this.extents[code].width:4;if(isNaN(w)){console.warn('getCharWidth:nowidthfor'+charString);return4;//don'tcrash}returnw*1;},computeExtents:function(proceed,family,size,style){console.log("layeredcomputeExtents");varextents=[];varbody=null;vardoc;//walkupthewindowchaintofindthe(X)HTMLcontextfor(varwin=window;win;win=win.parent){doc=win.document;varbodies=doc.documentElement.getElementsByTagName('body');if(bodies&&bodies.length>0){body=bodies[0];break;}}if(!body)return[];functioncreate(name){//returndoc.createElement(name);returndoc.createElementNS(Namespace.XHTML,name);}//body=document.bodyvard=body.appendChild(create("div"));d.style.kerning=0;d.style.fontFamily=family;d.style.fontSize=size+"px";console.log("style:"+style)if(style=='bold'){d.style.fontWeight='bold';}console.log('d.style='+d.style);varxWidth=-1;varxCode='x'.charCodeAt(0);for(vari=33;i<255;i++){varsub=d.appendChild(create("span"));sub.appendChild(doc.createTextNode(String.fromCharCode(i)));extents[i]=newlively.Text.CharacterInfo(sub.offsetWidth,sub.offsetHeight);if(i==xCode)xWidth=extents[i].width;}if(xWidth<0){thrownewError('xWidthis'+xWidth);}if(d.offsetWidth==0){console.log("timingproblems,expectmesseduptextforfont%s",this);}//handlespacesvarsub=d.appendChild(create("span"));sub.appendChild(doc.createTextNode('xx'));varspaceWidth=sub.offsetWidth-xWidth*2;console.log("font"+this+':spacewidth'+spaceWidth+'from'+sub.offsetWidth+'xWidth'+xWidth);//tjm:sanitycheckasFirefoxseemstodothiswrongwithcertainvaluesif(spaceWidth>100){extents[(''.charCodeAt(0))]=newlively.Text.CharacterInfo(2*xWidth/3,sub.offsetHeight);}else{extents[(''.charCodeAt(0))]=newlively.Text.CharacterInfo(spaceWidth,sub.offsetHeight);}//d.removeChild(span);body.removeChild(d);returnextents;}});layerClass(FixTextCompositionLayer,TextMorph,{composeLines:function(proceed){varargs=$A(arguments);args.shift();varresult;withLayers([FixTextCompositionDynamicLayer],function(){result=proceed(args)});returnresult}})createLayer("GuardConsoleLayer");enableLayer(GuardConsoleLayer);//DeactivateAlllayersduringtheloggingcode//topreventendlessrecursions...layerObject(GuardConsoleLayer,console,{log:function(proceed){varargs=$A(arguments);args.shift();varresult;withoutLayers(currentLayers(),function(){result=proceed(args)});returnresult}}) 0) {\n body = bodies[0];\n break;\n }\n }\n\t\n if (!body) return [];\n\n function create(name) {\n // return doc.createElement(name);\n return doc.createElementNS(Namespace.XHTML, name);\n }\n\t\t// body = document.body\n var d = body.appendChild(create(\"div\"));\n\t\n d.style.kerning = 0;\n d.style.fontFamily = family;\n d.style.fontSize = size + \"px\";\n\t\tconsole.log(\"style : \" + style)\n\t\tif (style == 'bold') {\r\t\t\td.style.fontWeight = 'bold';\r\t\t}\n\t\tconsole.log('d.style = ' + d.style );\n\t\n var xWidth = -1;\n var xCode = 'x'.charCodeAt(0);\n for (var i = 33; i < 255; i++) {\n var sub = d.appendChild(create(\"span\"));\n sub.appendChild(doc.createTextNode(String.fromCharCode(i)));\n extents[i] = new lively.Text.CharacterInfo(sub.offsetWidth, sub.offsetHeight);\n if (i == xCode) xWidth = extents[i].width;\n }\n\n if (xWidth < 0) { \n throw new Error('x Width is ' + xWidth);\n }\n\n if (d.offsetWidth == 0) {\n console.log(\"timing problems, expect messed up text for font %s\", this);\n }\n\t\n // handle spaces\n var sub = d.appendChild(create(\"span\"));\n sub.appendChild(doc.createTextNode('x x'));\n\n var spaceWidth = sub.offsetWidth - xWidth*2;\n console.log(\"font \" + this + ': space width ' + spaceWidth + ' from ' + sub.offsetWidth + ' xWidth ' + xWidth); \n\n // tjm: sanity check as Firefox seems to do this wrong with certain values\n if (spaceWidth > 100) { \n extents[(' '.charCodeAt(0))] = new lively.Text.CharacterInfo(2*xWidth/3, sub.offsetHeight);\n } else {\n extents[(' '.charCodeAt(0))] = new lively.Text.CharacterInfo(spaceWidth, sub.offsetHeight);\n }\n\n //d.removeChild(span);\n body.removeChild(d);\n return extents;\n }\r});\r\nlayerClass(FixTextCompositionLayer, TextMorph, {\n\tcomposeLines: function(proceed) {\n\t\tvar args = $A(arguments); args.shift(); \n\t\tvar result;\n\t\twithLayers([FixTextCompositionDynamicLayer], function() {\n\t\t\tresult = proceed(args)\n\t\t});\n\t\treturn result\n\t}\n})\n\ncreateLayer(\"GuardConsoleLayer\");\nenableLayer(GuardConsoleLayer);\n\n// Deactivate All layers during the logging code\n// to prevent endless recursions...\nlayerObject(GuardConsoleLayer, console, {\n\tlog: function(proceed) {\n\t\tvar args = $A(arguments); args.shift(); \n\t\tvar result;\n\t\twithoutLayers(currentLayers(), function() {\n\t\t\tresult = proceed(args)\n\t\t});\n\t\treturn result\n\t}\n})\n"]]>7truetruefalsefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null62