Skip to main content
May 1, 2009
Question

Justified word spacing condensed

  • May 1, 2009
  • 1 reply
  • 863 views

For some reason, word spacing is compressed for TextAlign.JUSTIFY.  If I set to left, center, or right justify, it does not alter the line breaking.  If I set to full justified, the word wrapping changes altering my text lines and overall height.  Is there a reason for this or a way to disable that behavior?

Here is sample code to demonstrate the problem:


public class TestTextLayoutCode extends Canvas {

    private var markup:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
            "<p fontSize='12' fontFamily='Times New Roman'><span>" +
            "This is a normal font size to show how the text functionality works with justified text." +
            "</span></p>" +
            "</TextFlow>";

    private var textFlow:TextFlow;
   
    public function TestTextLayoutCode() {
        textFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);
        textFlow.flowComposer = new StandardFlowComposer();
       
        var container:Sprite = new Sprite();
        container.x = 5;
        container.y = 5;
        var controller:ContainerController = new ContainerController(container);
        controller.verticalScrollPolicy = ScrollPolicy.OFF;
        textFlow.flowComposer.addController(controller);
        controller.setCompositionSize(200, 40);
        rawChildren.addChild(container);
        textFlow.flowComposer.updateAllControllers();
       
        textFlow.interactionManager = new EditManager();

        graphics.lineStyle(1,0x000000,1);
        graphics.drawRect(container.x-1,container.y-1,container.width+1,container.height+1);
       
        var button:Button = new Button();
        button.label = "Left";
        button.y = 50;
        addChild(button);
        button.addEventListener(MouseEvent.CLICK, onClickLeft);
       
        button = new Button();
        button.label = "Justify";
        button.x = 70;
        button.y = 50;
        addChild(button);
        button.addEventListener(MouseEvent.CLICK, onClickJustify);
    }
   
    private function onClickLeft(e:MouseEvent):void {
        var fmt:TextLayoutFormat = new TextLayoutFormat();
        fmt.textAlign = TextAlign.LEFT;
        setFormat(fmt);
    }
   
    private function onClickJustify(e:MouseEvent):void {
        var fmt:TextLayoutFormat = new TextLayoutFormat();
        fmt.textAlign = TextAlign.JUSTIFY;
        setFormat(fmt);
    }
   
    private function setFormat(fmt:TextLayoutFormat):void {
        if (textFlow && textFlow.interactionManager is IEditManager) {
            if (textFlow.textLength > 0) {
                textFlow.interactionManager.setSelection(0, textFlow.textLength);
                textFlow.interactionManager.refreshSelection();
                IEditManager(textFlow.interactionManager).applyParagraphFormat(fmt);
                textFlow.interactionManager.setSelection(-1,-1);
                textFlow.interactionManager.refreshSelection();
            }
        }
    }
   
}

This topic has been closed for replies.

1 reply

Adobe Employee
May 6, 2009

When you set a paragraph to justify, it may come out tighter or looser than previously. The Player allows the spaces to either expand or condense, and picks the value that is closest to optimal. This is in an effort to insure that the spacing is as close to optimal (as specified in the font) as possible, so the words don't come out looking spaced too far apart. You can see the same effect in InDesign, or other programs that do advanced composition, and it is especially apparent where the columns are set very narrow, because that is when there are fewer spaces it is harder to get them to optimal size.