Beispiel #1
0
 // Remove empty runs adjacent to non-empty text ones.
 private void RemoveUnwantedRuns(List <MapRun> runs)
 {
     for (int irun = 0; irun < runs.Count;)
     {
         MapRun run = runs[irun];
         if (run.LogLength > 0 || run.RenderLength > 0)
         {
             irun++;
             continue;                     // target run is not empty (or displaying a substitute), don't consider removing it.
         }
         if (irun + 1 < runs.Count)
         {
             MapRun runNext = runs[irun + 1];
             if (runNext.ClientRun is TextClientRun && runNext.LogLength > 0)
             {
                 // following text run is non-empty, remove this empty run.
                 runs.RemoveAt(irun);
                 continue;
             }
         }
         if (irun > 0 && runs[irun - 1].ClientRun is TextClientRun)
         {
             // there is a preceding text run, remove this run, even if preceding one is empty; don't want two adjacent empties.
             runs.RemoveAt(irun);
             continue;
         }
         irun++;
     }
 }
Beispiel #2
0
        internal FwUnderlineType GetUnderlineInfo(int ich, out int underColor, out int ichLim)
        {
            int    runIndex = RunContaining(ich);
            MapRun run      = Runs[runIndex];

            ichLim     = run.RenderStart + run.RenderLength;
            underColor = (int)run.Chrp.clrUnder;
            return((FwUnderlineType)run.Chrp.unt);
        }
Beispiel #3
0
        public void GetCharProps(int ich, out LgCharRenderProps chrp, out int ichMin, out int ichLim)
        {
            int    runIndex = RunContaining(ich);
            MapRun run      = Runs[runIndex];

            ichMin = run.RenderStart;
            ichLim = ichMin + run.RenderLength;
            chrp   = run.Chrp;
        }
Beispiel #4
0
        // Determine the run of the character with the specified render index.
        internal int RunContaining(int ichRen)
        {
            Debug.Assert(ichRen >= 0);
            MapRun key   = new MapRun(0, null, ichRen, 0, 0);
            int    index = Array.BinarySearch(Runs, key, RenderStartComparer);

            if (index < 0)             // exact match
            {
                index = ~index;        // now the index of the first run with RenderStart > ichRen
                index--;               // so this one contains the character
            }
            return(index);
        }
Beispiel #5
0
        public int LogToRen(int ichLog)
        {
            Debug.Assert(ichLog >= 0);
            MapRun key   = new MapRun(ichLog, null, 0, 0, 0);
            int    index = Array.BinarySearch(Runs, key, LogStartComparer);

            if (index < 0)
            {
                index = ~index;
                // index is now the index of the first element with LogStart > ichLog (or Runs.Length, if it is greater than any LogStart in the array).
                index--;                 // if it doesn't match exactly we want the previous run (which contains this index)
            }
            MapRun run = Runs[index];

            return(run.RenderStart + (ichLog - run.LogStart));
        }
Beispiel #6
0
        static void BeginMap(MapRun mapRun)
        {
            Console.Clear();
            GetMapInfo();
            Console.Write("\nClick on a specific button: ");
            var keyMap = Console.ReadKey();

            Console.WriteLine();

            switch (keyMap.Key)
            {
            case ConsoleKey.B:
            {
                Console.Clear();
                mapRun.BasicDictionary();
                PressAnyKey();
            }
            break;

            case ConsoleKey.E:
            {
                Console.Clear();
                mapRun.EasyMap();
                PressAnyKey();
            }
            break;

            case ConsoleKey.D:
            {
                Console.Clear();
                mapRun.ImplementedDictionary();
                PressAnyKey();
            }
            break;

            case ConsoleKey.X:
            {
            }
            break;
            }
        }
Beispiel #7
0
        public string GetRenderText(int ichMin, int length)
        {
            if (Runs.Length == 0)
            {
                if (ichMin != 0)
                {
                    throw new ArgumentException("ichMin is beyond the length of the (empty) paragraph.");
                }
                if (length != 0)
                {
                    throw new ArgumentException("asked for characters from an empty paragraph");
                }
                return("");
            }
            int    ichLim        = ichMin + length;
            int    firstRunIndex = RunContaining(ichMin);
            int    lastRunIndex  = RunContaining(ichLim);
            MapRun firstRun      = Runs[firstRunIndex];
            MapRun lastRun       = Runs[lastRunIndex];
            int    ichMinRun     = ichMin - firstRun.RenderStart;
            int    ichLimRun     = ichLim - lastRun.RenderStart;
            string text;

            if (firstRunIndex == lastRunIndex)
            {
                text = GetRunText(firstRun, ichMinRun, ichLimRun);
            }
            else
            {
                StringBuilder builder = new StringBuilder(GetRunText(firstRun, ichMinRun, firstRun.RenderLength));
                for (int i = firstRunIndex + 1; i < lastRunIndex; i++)
                {
                    MapRun run = Runs[i];
                    builder.Append(run.RenderText);
                }
                builder.Append(GetRunText(lastRun, 0, ichLimRun));
                text = builder.ToString();
            }
            return(text);
        }
Beispiel #8
0
        public int RenToLog(int ichRen)
        {
            Debug.Assert(ichRen >= 0);
            MapRun key   = new MapRun(0, null, ichRen, 0, 0);
            int    index = Array.BinarySearch(Runs, key, RenderStartComparer);

            if (index >= 0)             // exact match
            {
                return(Runs[index].LogStart);
            }
            index = ~index;
            // index is now the index of the first element with RenderStart > ichRen (or Runs.Length, if it is greater than any RenderStart in the array).

            MapRun run = Runs[index - 1];             // run containing the indicated position.

            // If this is an ORC run, we want its start index (all the render characters for the run correspond to that one ORC)
            if (run is OrcMapRun)
            {
                return(run.LogStart);
            }
            // In ordinary runs, the logical and rendered characters correspond one for one.
            return(run.LogStart + (ichRen - run.RenderStart));
        }
Beispiel #9
0
 /// <summary>
 /// Get the text from the specified run. indexes are offsets into the run, in render characters.
 /// </summary>
 /// <param name="run"></param>
 /// <param name="ichMin"></param>
 /// <param name="ichLim"></param>
 /// <returns></returns>
 string GetRunText(MapRun run, int ichMin, int ichLim)
 {
     return(run.RenderText.Substring(ichMin, ichLim - ichMin));
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.Title = "Guids and implementation examples for most popular types of Data Structures v1.0";

            var stackRun            = new StackRun();
            var queueRun            = new QueueRun();
            var setRun              = new SetRun();
            var hashTableRun        = new HashTableRun();
            var mapRun              = new MapRun();
            var listRun             = new ListRun();
            var treeRun             = new TreeRun();
            var heapRun             = new HeapRun();
            var binarySearchTreeRun = new BinarySearchTreeRun();
            var graphRun            = new GraphRun();

            while (true)
            {
                Console.Clear();
                GetBasicInfo();

                Console.Write("\nClick on a specific button: ");
                var key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                case ConsoleKey.S:
                {
                    BeginStack(stackRun);
                }
                break;

                case ConsoleKey.Q:
                {
                    BeginQueue(queueRun);
                }
                break;

                case ConsoleKey.E:
                {
                    BeginSet(setRun);
                }
                break;

                case ConsoleKey.B:
                {
                    BeginHashTable(hashTableRun);
                }
                break;

                case ConsoleKey.M:
                {
                    BeginMap(mapRun);
                }
                break;

                case ConsoleKey.L:
                {
                    BeginList(listRun);
                }
                break;

                case ConsoleKey.T:
                {
                    BeginTree(treeRun);
                }
                break;

                case ConsoleKey.H:
                {
                    BeginHeap(heapRun);
                }
                break;

                case ConsoleKey.N:
                {
                    BeginBinarySearchTree(binarySearchTreeRun);
                }
                break;

                case ConsoleKey.G:
                {
                    BeginGraph(graphRun);
                }
                break;

                case ConsoleKey.X:
                {
                    Environment.Exit(0);
                }
                break;
                }
            }
        }
Beispiel #11
0
 void VerifyRun(int logical, IClientRun clientRun, int render, int offset, int irun, string runText, MapRun run, string label)
 {
     Assert.AreEqual(logical, run.LogStart, label + " - logical");
     Assert.AreEqual(clientRun, run.ClientRun, label + " - cllient run");
     Assert.AreEqual(render, run.RenderStart, label + " - render");
     Assert.AreEqual(offset, run.Offset, label + " - offset");
     Assert.AreEqual(irun, run.ClientUniformRunIndex, label + "- ClientUniformRunIndex");
     Assert.AreEqual(runText, run.RenderText, label + " - RenderText");
 }
Beispiel #12
0
 void VerifyRun(int logical, IClientRun clientRun, int render, int offset, string runText, MapRun run, string label)
 {
     VerifyRun(logical, clientRun, render, offset, 0, runText, run, label);
 }