//////////////////////////////////////////////////////////////////////////////// // // 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. // //////////////////////////////////////////////////////////////////////////////// package UnitTest.Tests { import UnitTest.ExtendedClasses.TestDescriptor; import UnitTest.ExtendedClasses.TestSuiteExtended; import UnitTest.ExtendedClasses.VellumTestCase; import UnitTest.Fixtures.TestConfig; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.display.IBitmapDrawable; import flash.geom.Point; import flash.text.engine.TextBaseline; import flash.text.engine.TextBlock; import flash.text.engine.TextLine; import flash.text.engine.TextLineCreationResult; import flash.utils.ByteArray; import flashx.textLayout.compose.IFlowComposer; import flashx.textLayout.compose.TextFlowLine; import flashx.textLayout.container.ContainerController; import flashx.textLayout.conversion.ConversionType; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.formats.BaselineOffset; import flashx.textLayout.formats.BlockProgression; import flashx.textLayout.formats.JustificationRule; import flashx.textLayout.formats.LeadingModel; import flashx.textLayout.formats.TextLayoutFormat; import flashx.textLayout.tlf_internal; import mx.core.UIComponent; import mx.utils.LoaderUtil; use namespace tlf_internal; public class LeadingTest extends VellumTestCase { public static var diffTolerance:Number = 0.001; public function LeadingTest(methodName:String, testID:String, testConfig:TestConfig, testXML:XML = null) { super(methodName, testID, testConfig); // Note: These must correspond to a Watson product area (case-sensitive) metaData.productArea = "Text Composition"; } public static function suite(testConfig:TestConfig, ts:TestSuiteExtended):void { ts.addTestDescriptor (new TestDescriptor (LeadingTest, "verifyRomanDefaultsTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "verifyAsianDefaultsTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "textFieldStyleLeadingTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "ascentFromRomanTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "descentFromRomanTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "ideoTopFromIdeoCenterTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "ideoBottomFromIdeoCenterTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "eastAFirstBaselineOffsetTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "spaceFirstBaselineOffsetTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "topFBOColumnTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "bottomFBOColumnTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "ascentFBOColumnTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "romanFBOColumnTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "descentFBOColumnTest", testConfig ) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "checkUpDownParagraphBoundryTest", testConfig) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "checkDownUpParagraphBoundryTest", testConfig) ); ts.addTestDescriptor (new TestDescriptor (LeadingTest, "inlineGraphicWithFBOTest", testConfig) ); } public function verifyRomanDefaultsTest():void { var cf:TextLayoutFormat = new TextLayoutFormat(SelManager.getCommonCharacterFormat()); cf.fontFamily = "Times New Roman"; var pf:TextLayoutFormat = new TextLayoutFormat(SelManager.getCommonParagraphFormat()); pf.locale = "en"; pf.leadingModel = LeadingModel.AUTO; SelManager.selectAll(); SelManager.applyLeafFormat(cf); SelManager.applyParagraphFormat(pf); SelManager.flushPendingOperations(); var data1:BitmapData = getData(); pf = new TextLayoutFormat(SelManager.getCommonParagraphFormat()); pf.locale = "en"; pf.leadingModel = LeadingModel.ROMAN_UP; SelManager.applyParagraphFormat(pf); SelManager.flushPendingOperations(); var data2:BitmapData = getData(); assertTrue("Changing to explicit default values changed image.", compareData(data1,data2) ); } public function verifyAsianDefaultsTest():void { var cf:TextLayoutFormat = new TextLayoutFormat(SelManager.getCommonCharacterFormat()); cf.fontFamily = "Times New Roman"; var pf:TextLayoutFormat = new TextLayoutFormat(SelManager.getCommonParagraphFormat()); pf.locale = "ja"; pf.leadingModel = LeadingModel.AUTO; SelManager.selectAll(); SelManager.applyLeafFormat(cf); SelManager.applyParagraphFormat(pf); SelManager.flushPendingOperations(); var data1:BitmapData = getData(); pf = new TextLayoutFormat(SelManager.getCommonParagraphFormat()); pf.locale = "ja"; pf.leadingModel = LeadingModel.IDEOGRAPHIC_TOP_DOWN; SelManager.applyParagraphFormat(pf); SelManager.flushPendingOperations(); var data2:BitmapData = getData(); assertTrue("Changing to explicit default values changed image.", compareData(data1,data2) ); } public function textFieldStyleLeadingTest():void { var textFlow:TextFlow = SelManager.textFlow; textFlow.paddingTop = 0; textFlow.paddingBottom = 0; textFlow.paddingLeft = 0; textFlow.paddingRight = 0; var cf:TextLayoutFormat = new TextLayoutFormat(); cf.paddingTop = cf.paddingBottom = cf.paddingLeft = cf.paddingRight = 0; cf.columnCount = 1; var pf:TextLayoutFormat = new TextLayoutFormat(SelManager.getCommonParagraphFormat()); pf.leadingModel = LeadingModel.ASCENT_DESCENT_UP; pf.paragraphSpaceBefore = pf.paragraphSpaceAfter = 0; pf.paragraphStartIndent = 0; pf.paragraphEndIndent = 0; var lf:TextLayoutFormat = new TextLayoutFormat(); lf.lineHeight = 0; SelManager.selectAll(); SelManager.applyFormat(lf, pf, cf); SelManager.flushPendingOperations(); var composer:IFlowComposer = SelManager.textFlow.flowComposer; composer.composeToPosition(); // ensure everything is composed regardless of what's visible var cumulativeTextHeight:Number = 0; for (var i:int=0; i = data1.getVector(data1.rect); var vect2:Vector. = data2.getVector(data2.rect); var one:uint = 0; var two:uint = 0; var count:int = 0; var marked:Boolean = false; for(var i:int = 0; i < vect1.length; i++){ one = vect1.pop(); two = vect2.pop(); /* TODO: Change this back to not include block progression.*/ if( one != two && SelManager.textFlow.computedFormat.blockProgression != BlockProgression.RL) { count++; } } return (((count/(vect1.length/4))*100) < diffTolerance); } } }