blob: d5e5cf3fa9326d929a17095ff31482f5c01ac512 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mx:Canvas
creationComplete="handleCreationComplete()"
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.core.ByteArrayAsset;
import flash.text.engine.FontDescription;
import flashx.textLayout.elements.Configuration;
import flashx.textLayout.TextLayoutVersion;
import flash.text.engine.ElementFormat;
import flash.text.engine.TextElement;
import flash.utils.getQualifiedClassName;
import mx.core.ByteArrayAsset;
import mx.controls.Text;
import mx.collections.ArrayCollection;
import flash.display.BlendMode;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.container.ScrollPolicy;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.factory.TextFlowTextLineFactory;
import flashx.textLayout.conversion.TextConverter;
import flash.text.engine.TextBlock;
import flash.text.engine.TextLine;
import flash.text.engine.TextLineValidity;
import flash.text.engine.LineJustification;
import flash.text.engine.SpaceJustifier;
import flashx.textLayout.formats.BlockProgression;
import flashx.textLayout.debug.Debugging;
import flashx.textLayout.debug.assert;
import flashx.textLayout.tlf_internal;
use namespace tlf_internal;
private static var factory:TextFlowTextLineFactory = new TextFlowTextLineFactory();
private var resultText:Text;
// embed alice - this simplifies things - don't need to trust the swf and pass the xml around with it
[Embed(source="../../../test/testFiles/markup/tlf/alice.xml",mimeType="application/octet-stream")]
private var AliceClass : Class;
private var checkMemoryIntervalID:uint = setInterval(checkMemoryUsage,1000);
[Bindable]
public var reportString:String = "";
public function checkMemoryUsage():void
{
reportString = currIteration.toString() + " " + Math.round(System.totalMemory/1000000).toString();
}
private function setDebugFlag():void
{
var e:Error = new Error();
var s:String = e.getStackTrace();
// trace(s);
var i:int = s.indexOf("setDebugFlag");
if (s.charAt(i + 14) == '[')
debugMode = true;
}
public var debugMode:Boolean = false;
public function handleCreationComplete(): void
{
setDebugFlag();
}
// last parse time
private var parseTime:Number;
private function parseStringIntoFlow(source:String, format:String):TextFlow
{
var beginParseTime:Number = getTimer();
var tf:TextFlow = TextConverter.importToFlow(source, format);
parseTime = getTimer() - beginParseTime;
//trace("PARSE TIME:",parseTime.toString());
return tf;
}
// data for the current run
private var textFlow:TextFlow;
private var container:Sprite;
private var controller:ContainerController;
private var numberOfIterations:int = 0;
private var deltaLines:Number;
private var widthVal:Number;
private var currIteration:int = -1;
private var beginThisRender:int;
private var timingRendering:Boolean = false;
// timers
private var beginTestTime:int;
public var totalScrollTime:int;
public var totalRenderTime:int;
public function runTheTest():void
{
// number of iterations to run
// numberOfIterations = int(iterationsInput.text);
widthVal = Number(widthInput.text);
deltaLines = Number(deltaLinesInput.text);
// clear the previous run
if (resultText)
{
lineHolder.removeChild(resultText);
resultText = null;
}
if (container)
{
lineHolder.rawChildren.removeChild(container);
container = null;
}
if (textFlow == null)
{
var alice:ByteArrayAsset = new AliceClass();
var aliceData:String = alice.readMultiByte(alice.length,"utf-8");
textFlow = parseStringIntoFlow(aliceData, TextConverter.TEXT_LAYOUT_FORMAT);
}
textFlow.flowComposer.removeAllControllers();
controller = null;
// the new run
container = new Sprite();
container.x = 100;
container.y = 100;
lineHolder.rawChildren.addChild(container);
controller = new ContainerController(container,widthVal,this.height-controlBox.height);
textFlow.flowComposer.addController(controller);
textFlow.flowComposer.updateAllControllers();
addEventListener(Event.ENTER_FRAME,handleEnterFrame);
runButton.enabled = false;
currIteration = 0;
testCount++;
totalScrollTime = 0;
totalRenderTime = 0;
beginTestTime = getTimer();
}
// count of number of tests run this session
private var testCount:int = 0;
/** generate a report at the next enter frame */
public function handleEnterFrame(event:Event): void
{
if (timingRendering)
{
totalRenderTime += getTimer()-beginThisRender;
timingRendering = false;
}
var delta:Number = controller.getScrollDelta(deltaLines);
// report results
if (delta == 0)
{
var totalTestTime:int = getTimer()-this.beginTestTime;
flash.system.System.gc(); //mark
flash.system.System.gc(); //sweep
var memoryAllocated:Number = flash.system.System.totalMemory/1024;
trace("VellumAliceScroll scroll time (msecs)",totalScrollTime.toString(), "render time (msec)", totalRenderTime.toString(), "total time (msecs)",totalTestTime.toString(), " mem (K)", memoryAllocated);
var testDescription:String = testCount.toString() + ") iters: " + numberOfIterations.toString();
var playerType:String = this.debugMode ? "DEBUGGING PLAYER (not suitable for measuring performance)" : "RELEASE PLAYER "+Capabilities.version;
var vellumType:String = "Vellum build: " + flashx.textLayout.TextLayoutVersion.BUILD_NUMBER + "\n" + (Configuration.tlf_internal::debugCodeEnabled ? "DEBUG vellum engine (not suitable for measuring performance)" : "RELEASE vellum engine");
resultText = new Text();
resultText.text = "VellumAliceScroll\n" + testDescription + "\nParseTime (msec): " + parseTime.toString() + "\nScrollTime (msecs): " + totalScrollTime.toString() + "\nRenderTime (msec): " + totalRenderTime.toString() + "\nTotalTestTime (msec): " + totalTestTime.toString()
+ " \nmem (K): " + memoryAllocated.toString() + "\n" + playerType + "\n" + vellumType;
resultText.x = 80;
resultText.y = 100;
resultText.width = 400;
resultText.setStyle("fontFamily", "Minion Pro");
resultText.setStyle("fontSize", 16);
resultText.opaqueBackground = 0xFFFFFFFF;
lineHolder.addChild(resultText);
this.dispatchEvent(new Event(Event.COMPLETE));
runButton.enabled = true; // start another test?
removeEventListener(Event.ENTER_FRAME,handleEnterFrame);
}
else
{
var beginThisScroll:int = getTimer();
controller.verticalScrollPosition += delta;
totalScrollTime += getTimer()-beginThisScroll;
// prepare for the next iteration
currIteration++;
// begin timing rendering
timingRendering = true;
beginThisRender = getTimer();
}
}
]]>
</mx:Script>
<mx:VBox>
<mx:HBox id="controlBox" paddingLeft="4" paddingTop="4">
<mx:Label text="VellumAliceScroll" fontWeight="bold"/>
<!-- <mx:Label text="Iterations:" fontWeight="bold"/>
<mx:TextInput id="iterationsInput" text="1" width="40"/> -->
<mx:Label text="Width:" fontWeight="bold"/>
<mx:TextInput id="widthInput" text="500" width="60"/>
<mx:Label text="DeltaLines:" fontWeight="bold"/>
<mx:TextInput id="deltaLinesInput" text="1" width="60"/>
<mx:Button id="runButton" label="Run" click="runTheTest()"/>
<mx:Text text="{reportString}" height="20"/>
</mx:HBox>
<mx:Canvas id="lineHolder"/>
</mx:VBox>
</mx:Canvas>