GetFirstRun() private method

private GetFirstRun ( ) : CssRun
return CssRun
Esempio n. 1
0
        internal void CopyText(StringBuilder stbuilder)
        {
            //copy selected text to stbuilder
            //this version just copy a plain text
            int j = _selectedLines.Count;

            for (int i = 0; i < j; ++i)
            {
                CssLineBox       selLine = _selectedLines[i];
                SelectionSegment selSeg  = selLine.SelectionSegment;
                switch (selSeg.Kind)
                {
                case SelectionSegmentKind.Partial:
                {
                    CssRun startRun     = selSeg.StartHitRun;
                    CssRun endHitRun    = selSeg.EndHitRun;
                    bool   autoFirstRun = false;
                    bool   autoLastRun  = false;
                    if (startRun == null)
                    {
                        startRun     = selLine.GetFirstRun();
                        autoFirstRun = true;
                    }
                    if (endHitRun == null)
                    {
                        endHitRun   = selLine.GetLastRun();
                        autoLastRun = true;
                    }

                    if (startRun == endHitRun)
                    {
                        if (startRun != null && _startHitRunCharIndex >= 0)
                        {
                            startRun.WriteContent(stbuilder, _startHitRunCharIndex, _endHitRunCharIndex - _startHitRunCharIndex);

                            //string alltext = rr.Text;
                            //string sub1 = alltext.Substring(_startHitRunCharIndex, _endHitRunCharIndex - _startHitRunCharIndex);
                            //stbuilder.Append(sub1);
                        }
                    }
                    else
                    {
                        int  runCount      = selLine.RunCount;
                        bool foundStartRun = false;
                        for (int n = 0; n < runCount; ++n)
                        {
                            //temp fix here!
                            //TODO: review this for other cssrun type

                            CssRun run = selLine.GetRun(n);

                            if (run == startRun)
                            {
                                foundStartRun = true;
                                if (autoFirstRun)
                                {
                                    run.WriteContent(stbuilder);
                                }
                                else
                                {
                                    if (_startHitRunCharIndex >= 0)
                                    {
                                        run.WriteContent(stbuilder, _startHitRunCharIndex);
                                    }
                                }
                            }
                            else if (run == endHitRun)
                            {
                                if (autoLastRun)
                                {
                                    run.WriteContent(stbuilder);
                                    //stbuilder.Append(alltext);
                                }
                                else
                                {
                                    if (_endHitRunCharIndex >= 0)
                                    {
                                        run.WriteContent(stbuilder, 0, _endHitRunCharIndex);
                                        //string sub1 = alltext.Substring(0, _endHitRunCharIndex);
                                        //stbuilder.Append(sub1);
                                    }
                                }
                                //stop
                                break;
                            }
                            else
                            {
                                if (foundStartRun)
                                {
                                    run.WriteContent(stbuilder);
                                    //stbuilder.Append(rr.Text);
                                }
                            }
                        }
                    }
                }
                break;

                default:
                {
                    int runCount = selLine.RunCount;
                    for (int n = 0; n < runCount; ++n)
                    {
                        CssRun run = selLine.GetRun(n);
                        run.WriteContent(stbuilder);
                        //CssTextRun r = run as CssTextRun;
                        //if (r != null)
                        //{
                        //    stbuilder.Append(r.Text);
                        //}
                        //else
                        //{

                        //}
                    }
                }
                break;
                }

                if (i < j - 1)
                {
                    //if not lastline
                    stbuilder.AppendLine();
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Applies right to left direction to words
 /// </summary>
 /// <param name="blockBox"></param>
 /// <param name="lineBox"></param>
 static void ApplyRightToLeft(CssLineBox lineBox)
 {
     if (lineBox.RunCount > 0)
     {
         float left = lineBox.GetFirstRun().Left;
         float right = lineBox.GetLastRun().Right;
         foreach (CssRun run in lineBox.GetRunIter())
         {
             float diff = run.Left - left;
             float w_right = right - diff;
             run.Left = w_right - run.Width;
         }
     }
 }