예제 #1
0
        private void cmdBidiTest_Click(object sender, EventArgs e)
        {
            //string text = "hello مرحبا a123";
            //string text = "مرحبا "; //hello
            //string text = "حب"; //love
            string text = "شمس";//sun

            //string text = "یہ ایک (car) ہے۔"; //this is a car

            char[] buffer = text.ToCharArray();
            Line   line1  = new Line(text);

            RunAdapter runAdapter = new RunAdapter();
            RunAgent   agent      = runAdapter.Agent;

            runAdapter.LoadLine(line1);

            while (runAdapter.MoveNext())
            {
                int  offset = agent.Offset;
                byte level  = agent.Level;
                int  len    = agent.Length;
                bool rtl    = agent.IsRightToLeft;
                //iter each run-span

                string tt = new string(buffer, offset, len);
                System.Diagnostics.Debug.WriteLine(tt);
            }

            //static RunAdapter runAdapter = new RunAdapter();
            //static MirrorLocator mirrorLocator = new MirrorLocator();

            //static void Main(string[] args)
            //{
            //    string text = "یہ ایک (car) ہے۔";
            //    Paragraph paragraph = new Paragraph(text, BaseDirection.AutoLeftToRight);
            //    Line line = new Line(paragraph, 0, text.Length);

            //    runAdapter.LoadLine(line);
            //    foreach (RunAgent agent in runAdapter)
            //    {
            //        Console.WriteLine("Run Level: " + agent.Level);
            //        Console.WriteLine("Run Offset: " + agent.Offset);
            //        Console.WriteLine("Run Length: " + agent.Length);
            //        Console.WriteLine("Run Direction: " + (agent.IsRightToLeft ? "RTL" : "LTR"));
            //        Console.WriteLine();
            //    }

            //    mirrorLocator.LoadLine(line);
            //    foreach (MirrorAgent agent in mirrorLocator)
            //    {
            //        Console.WriteLine("Mirror Location: " + agent.Index);
            //        Console.WriteLine("Mirror Unicode: " + agent.Mirror);
            //        Console.WriteLine();
            //    }
            //}
        }
예제 #2
0
        internal override void BreakWord(WordVisitor visitor, char[] charBuff, int startAt, int len)
        {
            //use custom parsing

            visitor.State = VisitorState.Parsing;
            RunAgent agent = _runAdapter.Agent;

            //collect arabic char and break

            int arabic_len = 0;
            int lim        = startAt + len;


            for (int i = startAt; i < lim; ++i)
            {
                char c = charBuff[i];
                if (IsArabicChar(c))
                {
                    arabic_len++;
                }
                else
                {
                    break;
                }
            }
            //
            if (arabic_len == 0)
            {
                visitor.State = VisitorState.OutOfRangeChar;
                return;
            }


            visitor.SpanBreakInfo = _breakInfo;

            //only collect char
            Line line1 = new Line(new string(charBuff, startAt, arabic_len));

            _runAdapter.LoadLine(line1);

            while (_runAdapter.MoveNext())
            {
                int  offset = agent.Offset;
                byte level  = agent.Level;
                int  sp_len = agent.Length;
                bool rtl    = agent.IsRightToLeft;

                if (rtl)
                {
                    //temp fix
                    visitor.AddWordBreak_AndSetCurrentIndex(startAt + sp_len, WordKind.Text);
                }
                else
                {
                    //use other engine
                    break;
                }
                //iter each run-span
                //string tt = new string(buffer, offset, len);
                //System.Diagnostics.Debug.WriteLine(tt);
            }

            if (visitor.CurrentIndex == startAt + len)
            {
                visitor.State = VisitorState.End;
            }
            else
            {
                //continue to other parser
                visitor.State = VisitorState.OutOfRangeChar;
            }
        }