Skip to main content
Participating Frequently
January 8, 2010
Question

line breaks and wrapping incorrect on hebrew+english text

  • January 8, 2010
  • 1 reply
  • 4106 views

i have a string of mixed text with hebrew and english, usually the english is only the last word in the string.

when trying to show on a limited space (110px more or less) the line break looks like it performs incorrectly since the string is all mixed and it shows the english word in between the hebrew words.

I'm using the following, in a *pure* as3 project in the flex ide using sdk 3.5 and last version textframework swc.

private function addText():void{

     //title is a string brought from xml.

     title = "Canazei סקי איטלקי במיטבו בעיירה";

     var titleLine:StringTextLineFactory = new StringTextLineFactory();

     titleLine.text = title;

     titleLine.paragraphFormat

     titleLine.compositionBounds = new Rectangle(0,0,120,120);

     titleLine.spanFormat = formatMe(blue, 12, "bold");

     titleLine.createTextLines(callbackTitle);

     function callbackTitle(tl:TextLine):void{

          addChild(tl);

          tl.y = 12;

          tl.x = 109 - tl.width;

     }

}

//thats the formatMe function:

public function formatMe(colour:uint, size:uint, weight:String):TextLayoutFormat{

     characterFormat = new TextLayoutFormat();

     characterFormat.fontSize = size;

     characterFormat.color = colour;

     characterFormat.direction = flashx.textLayout.formats.Direction.LTR;

     characterFormat.textAlign = flashx.textLayout.formats.TextAlign.START;

     characterFormat.fontFamily = "Arial, Helvetica, _sans";

     characterFormat.lineHeight = "100%";

     if (weight == "bold"){

          characterFormat.fontWeight = flash.text.engine.FontWeight.BOLD;

     }

     return characterFormat;

}

any help with this will be greatly appreciated, unfortunately the bidi support is not clear and sometimes the examples in the docs are not working.

This topic has been closed for replies.

1 reply

2Q26_2Author
Participating Frequently
January 8, 2010

still not solved, but i'm coming to the conclusion that somehow i need to tell var titleLine:StringTextLineFactory = new StringTextLineFactory(); that it needs to handle BIDI string/text to know to break correctly, am I on the right track? what else can be done or whats the correct way of doing a textLine with bidi string from RIGHT TO LEFT ??

Adobe Employee
January 11, 2010

I played around with your example a little, and removed the explicit line placement you added, and have this (see below). It works as expected if you consider English the dominant language. If you wanted it to assume Hebrew instead, you should set the direction to RTL instead of LTR. Please let me know if this works for you.

Thanks!

package
{
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.factory.StringTextLineFactory;
    import flashx.textLayout.formats.TextLayoutFormat;
    import flash.geom.Rectangle;
    import flash.display.Sprite;
    import flash.text.engine.TextLine;
   
    public class TCMTestFocus extends Sprite
    {
        public function TCMTestFocus():void{
           
            //title is a string brought from xml.           
                                            var    title:String = "Canazei סקי איטלקי במיטבו בעיירה";
            var titleLine:StringTextLineFactory = new StringTextLineFactory();           
            titleLine.text = title;
            titleLine.paragraphFormat
            titleLine.compositionBounds = new Rectangle(0,0,120,120);
            titleLine.spanFormat = formatMe(0x0000FF, 12, "bold");
            titleLine.createTextLines(callbackTitle);
           
            function callbackTitle(tl:TextLine):void{
               
                addChild(tl);               
        //        tl.y = 12;               
        //        tl.x = 109 - tl.width;
            }
           
           
           
        }
       
    public function formatMe(colour:uint, size:uint, weight:String):TextLayoutFormat{
           
            var characterFormat:TextLayoutFormat = new TextLayoutFormat();           
            characterFormat.fontSize = size;
            characterFormat.color = colour;
            characterFormat.direction = flashx.textLayout.formats.Direction.LTR;
            characterFormat.textAlign = flashx.textLayout.formats.TextAlign.START;
            characterFormat.fontFamily = "Arial, Helvetica, _sans";
            characterFormat.lineHeight = "100%";
           
            if (weight == "bold"){
                characterFormat.fontWeight = flash.text.engine.FontWeight.BOLD;
            }
           
            return characterFormat;
        }
    }
}

2Q26_2Author
Participating Frequently
January 11, 2010

Hi and thanks for taking the time trying solving this issue.

I tried using the fix you provided but it did not solve my problem.

I have included a screenshot of what I get and of what I need it to look like.

What I don't really get to understand, why if I set the text to be RTL it is still aligned to the LEFT, even though I'm setting Align to RIGHT as well.

What I actually need is probably a textfield element/component that already has RTL and BIDI built into it without needing to render a line by line procedure.

As a final question: is there a way to distinguish inside the string itself when the character is NOT english without comparing it to a list of unicodes?

Thnaks!