//////////////////////////////////////////////////////////////////////////////// // // 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.TestSuiteExtended; import UnitTest.ExtendedClasses.VellumTestCase; import UnitTest.Fixtures.TestConfig; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.IBitmapDrawable; import flash.events.*; import flash.geom.Matrix; import flash.geom.Rectangle; import flash.text.engine.TabAlignment; import flash.text.engine.TextLine; import flash.utils.ByteArray; import flashx.textLayout.compose.TextFlowLine; import flashx.textLayout.elements.*; import flashx.textLayout.formats.*; import flashx.textLayout.property.NumberPropertyHandler; import flashx.textLayout.property.Property; import flashx.textLayout.tlf_internal; use namespace tlf_internal; public class ParagraphTest extends VellumTestCase { public function ParagraphTest(methodName:String, testID:String, testConfig:TestConfig, testCaseXML:XML=null) { super(methodName, testID, testConfig, testCaseXML); // Note: These must correspond to a Watson product area (case-sensitive) metaData.productArea = "Text Container"; } public static function suiteFromXML(testListXML:XML, testConfig:TestConfig, ts:TestSuiteExtended):void { var testCaseClass:Class = ParagraphTest; VellumTestCase.suiteFromXML(testCaseClass, testListXML, testConfig, ts); } /* Unused private functions private function getParaCount():uint // return the number of paragraphs KJT { SelManager.selectAll(); var startOfPara:int = SelManager.anchorPosition; var endOfPara:int = SelManager.activePosition; var curCount:uint = 0; var i:int; for (i = startOfPara; i <= endOfPara; i++) { var para:Object = SelManager.textFlow.findAbsoluteParagraph(i); if(i == ParagraphElement(para).parentRelativeStart){ curCount++; } } return curCount; } private function getAparaGraph(index:uint):ParagraphElement // return a p by index KJT { SelManager.selectAll(); var arrayOfP:Array = new Array(); var startOfPara:int = SelManager.anchorPosition; var endOfPara:int = SelManager.activePosition; var curCount:uint = 0; var i:int; for (i = startOfPara; i <= endOfPara; i++) { var para:ParagraphElement = SelManager.textFlow.findAbsoluteParagraph(i); if(i == para.parentRelativeStart){ arrayOfP.push(para); curCount++; } } return ParagraphElement(arrayOfP[index]); } */ /* ************************************************************** */ /* Alignment Tests */ /* ************************************************************** */ /** * Get a short selection and set the alignment to left align and * check that it is set correctly. */ public function alignLeftTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.LEFT); // Confirm the alignment was set. assertTrue("alignment is not left - it's " + getAlignment(), getAlignment() == TextAlign.LEFT); } /** * Get a short selection and set the alignment to right align and * check that it is set correctly. */ public function alignRightTest():void { // Set the selection. var startIndx:int = 20; var endIndx:int = 40; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.RIGHT); // Confirm the alignment was set. assertTrue("alignment is not right - it's " + getAlignment(), getAlignment() == TextAlign.RIGHT); } /** * Set the alignment to right align for all of the text and * check that it is set correctly. */ public function alignAllRightTest():void { // Set the selection / var startIndx:int = 0; var endIndx:int = SelManager.textFlow.textLength - 1; SelManager.selectRange(startIndx,endIndx); // select across paragraphs KJT // Set the alignment. setAlignment(TextAlign.RIGHT); // Confirm the alignment was set. assertTrue("alignment is not right - it's " + getAlignment(), getAlignment() == TextAlign.RIGHT); } /** * Set the alignment to START align for all of the text and * check that it is set correctly. */ public function alignStartTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.START); // Confirm the alignment was set. assertTrue("alignment should be " + TextAlign.START + " but, actually is " + getAlignment(), getAlignment() == TextAlign.START); } /** * Set the alignment to END align for all of the text and * check that it is set correctly. */ public function alignEndTest():void { // Set the selection. var startIndx:int = 20; var endIndx:int = 40; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.END); // Confirm the alignment was set. assertTrue("alignment should be " + TextAlign.END + " but, actually is " + getAlignment(), getAlignment() == TextAlign.END); } /** * Get a short selection and set the alignment to center align and * check that it is set correctly. */ public function alignCenterTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.CENTER); // Confirm the alignment was set. assertTrue("alignment is not center - it's " + getAlignment(), getAlignment() == TextAlign.CENTER); } /** * Get a short selection and set the alignment to justify "all including last" and * check that it is set correctly. */ public function alignJustifyAllTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.JUSTIFY); // Confirm the alignment was set. assertTrue("alignment is not justify - it's " + getAlignment() + " and " + getAlignmentLast(), getAlignment() == TextAlign.JUSTIFY && getAlignmentLast() == TextAlign.JUSTIFY); } /** * Get a short selection and set the alignment to justify "all but last" and * check that it is set correctly. */ public function alignJustifyAllButLastTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.JUSTIFY); // Confirm the alignment was set. assertTrue("alignment is not justify - it's " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); } /** * Get a short selection and set the alignment to justify with last line start, end, left, center, right and * check that it is set correctly. */ public function justifyWithLastLineStart():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.START); // Confirm the alignment was set. assertTrue("alignment should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); assertTrue("last line alignment should be " + TextAlign.START + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.START); } public function justifyWithLastlineEnd():void { var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx, endIndx); setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.END); assertTrue("alignment should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); assertTrue("last line alignment should be " + TextAlign.END + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.END); } public function justifyWithLastlineLeft():void { var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx, endIndx); setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.LEFT); assertTrue("alignmnet should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); assertTrue("last line alignment should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.LEFT); } public function justifyWithLastlineCenter():void { var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx, endIndx); setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.CENTER); assertTrue("alignmnet should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); assertTrue("last line alignment should be " + TextAlign.CENTER + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.CENTER); } public function justifyWithLastlineRight():void { var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx, endIndx); setAlignment(TextAlign.JUSTIFY); setAlignmentLast(TextAlign.RIGHT); assertTrue("alignment should be " + TextAlign.JUSTIFY + " but, actually is " + getAlignment(), getAlignment() == TextAlign.JUSTIFY); assertTrue("last lie alignmnet shold be " + TextAlign.RIGHT + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.RIGHT); } public function OnlyLastlineSet():void { var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx, endIndx); setAlignmentLast(TextAlign.RIGHT); assertTrue("alignment should be " + TextAlign.START + " (default) but, actually is " + getAlignment(), getAlignment() == TextAlign.START); assertTrue("last lie alignmnet shold be " + TextAlign.RIGHT + " but, actually is " + getAlignmentLast(), getAlignmentLast() == TextAlign.RIGHT); } /** * Get a short selection and set the textJustify to INTER_WORD and * check that it is set correctly. */ public function justifyInterWordTest():void { // Set the selection. var startIndx:int = 10; var endIndx:int = 20; SelManager.selectRange(startIndx,endIndx); // Set the alignment. setTextJustify(TextJustify.INTER_WORD); // Confirm the alignment was set. assertTrue("textJustify is not interWord - it's " + getTextJustify(), getTextJustify() == TextJustify.INTER_WORD); } /** * Set textJustify to INTER_WORD and DISTRIBUTE and verify * that the spacing between glyphs is different on first line. * * Test with both last line set to JUSTIFY and to LEFT. */ public function justifyLetterSpacingFirstLine():void { justifyInterWordVsDistributeCore(false, false); justifyInterWordVsDistributeCore(false, true); } /** * Set textJustify to INTER_WORD and DISTRIBUTE and verify * that the spacing between glyphs is different on last line * with last line set to JUSTIFY */ public function justifyLetterSpacingLastLineJustify():void { justifyInterWordVsDistributeCore(true, true); } /** * Set textJustify to INTER_WORD and DISTRIBUTE and verify * that the spacing between glyphs is not different on last line * with last line justification set to LEFT */ public function justifyLetterSpacingLastLineNoJustify():void { justifyInterWordVsDistributeCore(true, false); } private function justifyInterWordVsDistributeCore(lastLine:Boolean, justifyLastLine:Boolean):void { var longWordText:String = "Longlonglonglonglonglong \ Longlonglonglonglonglong Longlonglonglonglonglong Longlonglonglonglonglong \ Longlonglonglonglonglong Longlonglonglonglonglong Longlonglonglonglonglong \ Longlonglonglonglonglong Longlonglonglonglonglong Longlonglonglonglonglong \ LonglonglonglonglonglongLong longlonglonglonglong Longlonglonglonglonglong."; var longWordTextLastPosition:int = longWordText.length - 1; SelManager.selectAll(); SelManager.insertText(longWordText); SelManager.selectRange(1,1); setAlignment(TextAlign.JUSTIFY); setAlignmentLast(justifyLastLine ? TextAlign.JUSTIFY : TextAlign.LEFT); // capture block progression so we know whether glyph spacing will happen // along x or y axis. var bp:String = SelManager.textFlow.computedFormat.blockProgression; var line:TextLine; setTextJustify(TextJustify.INTER_WORD); if(lastLine) { line = SelManager.textFlow.flowComposer.findLineAtPosition(longWordTextLastPosition).getTextLine(true); } else { line = SelManager.textFlow.flowComposer.getLineAt(0).getTextLine(true); } var xPosInterWord:Array = new Array(); // Collect the x coordinates for each glyph for ( var i:int = 0; i < line.atomCount; i++) { var r:Rectangle = line.getAtomBounds(i); xPosInterWord.push(Number(bp == BlockProgression.TB ? r.x : r.y)); } setTextJustify(TextJustify.DISTRIBUTE); if(lastLine) { line = SelManager.textFlow.flowComposer.findLineAtPosition(longWordTextLastPosition).getTextLine(true); } else { line = SelManager.textFlow.flowComposer.getLineAt(0).getTextLine(true); } var xPosDistribute:Array = new Array(); // Collect the x coordinates for each glyph for ( i = 0; i < line.atomCount; i++) { r = line.getAtomBounds(i); xPosDistribute.push(Number(bp == BlockProgression.TB ? r.x : r.y)); } var foundDifferentSpacing:Boolean = false; for( i=0; i 0) { if (diffPixels.readByte() > 0) { diffCount ++; } } var diff:Number = diffCount/pixelCount*100; assertTrue("Background color has been changed after appending text to paragraph 1." + " The diff is "+ diff + " And the diffTolerance is " + diffTolerance, diff < diffTolerance); } /* this is for testing the bug 2371905. Final Empty Paragraph Shows No Selection When Block Selected */ public function FinalEmptyParaTest():void { var insertPoint:int = 14; var tlf:TextLayoutFormat = new TextLayoutFormat(); SelManager.selectRange(0,0); SelManager.insertText("This is a test" + " "); SelManager.selectRange(insertPoint, insertPoint); SelManager.splitParagraph(); var tf:TextFlow = SelManager.textFlow; var p1:ParagraphElement = tf.getChildAt(0) as ParagraphElement; var p2:ParagraphElement = tf.getChildAt(1) as ParagraphElement; var p1start:int = p1.getAbsoluteStart(); var p1end:int = p1.textLength - 1; var p2start:int = p2.getAbsoluteStart(); var p2end:int = p2start + p2.textLength - 1; SelManager.selectAll(); var absoluteEnd:int = SelManager.absoluteEnd; assertTrue("Final Empty paragragh has not been selected" + " final empty paragraph end at index " + p2end + " and the real absolute End index is: " + absoluteEnd, p2end == absoluteEnd); } } }