Example #1
0
        private void AddMapRunsForClientRun(IClientRun input, List <MapRun> runs, ref int ichLog, ref int ichRen)
        {
            TextClientRun textRun = input as TextClientRun;

            if (textRun == null)
            {
                // inserting a box!
                runs.Add(new MapRun(ichLog, input, ichRen, 0, 1));
                ichLog++;
                ichRen++;
                return;
            }
            if (textRun.Length == 0 && textRun.Substitute != null)
            {
                runs.Add(new SubstituteMapRun(ichLog, textRun, ichRen, textRun.Substitute, textRun.SubstituteStyle));
                ichRen += textRun.Substitute.Length;
                return;
            }
            int cRuns = textRun.UniformRunCount;

            Debug.Assert(cRuns > 0, "we can't replace a client run reliably if it has no uniform runs");
            for (int irun = 0; irun < cRuns; irun++)
            {
                AddRunsForUniformRun(textRun, runs, ref ichLog, ref ichRen, irun);
            }
        }
Example #2
0
 public SubstituteMapRun(int logical, IClientRun clientRun, int render, string substitute, AssembledStyles substituteStyle) :
     base(logical, clientRun, render, 0, substitute.Length)
 {
     Debug.Assert(clientRun.Length == 0);
     m_substitute      = substitute;
     m_substituteStyle = substituteStyle;
 }
        public InsertionPoint NextIp(int distance)
        {
            InsertionPoint newIp;
            IClientRun     run = ContainingRun;
            ParaBox        box = run.Hookup.ParaBox;

            if (StringPosition + distance > run.Text.Length)
            {
                distance -= run.Text.Length - StringPosition;
                if (box.Source.ClientRuns[run.Hookup.ClientRunIndex] != box.Source.ClientRuns.Last())
                {
                    run = box.Source.ClientRuns[run.Hookup.ClientRunIndex + 1];
                }
                else
                {
                    box = box.NextParaBox;
                    if (box == null)
                    {
                        return(null);
                    }
                    run = box.Source.ClientRuns[0];
                }
                newIp = run.SelectAtStart(box);
                newIp = newIp.NextIp(distance);
            }
            else
            {
                newIp = new InsertionPoint(Hookup, StringPosition + distance, AssociatePrevious);
            }
            return(newIp);
        }
Example #4
0
		public MapRun(int logical, IClientRun clientRun, int render, int offset, int clientUniformRunIndex, int renderLength)
		{
			LogStart = logical;
			ClientRun = clientRun;
			RenderStart = render;
			Offset = offset;
			ClientUniformRunIndex = clientUniformRunIndex;
			RenderLength = renderLength;
		}
Example #5
0
 public MapRun(int logical, IClientRun clientRun, int render, int offset, int clientUniformRunIndex, int renderLength)
 {
     LogStart              = logical;
     ClientRun             = clientRun;
     RenderStart           = render;
     Offset                = offset;
     ClientUniformRunIndex = clientUniformRunIndex;
     RenderLength          = renderLength;
 }
Example #6
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");
 }
Example #7
0
 public ClientRunChangedMethod(TextSource source, int index, IClientRun newRun)
 {
     m_clientRunIndex = index;
     m_newRun         = newRun;
     m_source         = source;
     m_oldRun         = m_source.ClientRuns[m_clientRunIndex];
     m_newRuns        = new List <MapRun>(m_source.Runs.Length);
     m_newSource      = new TextSource();
     m_result         = new SourceChangeDetails(m_newSource);
 }
Example #8
0
        internal AssembledStyles StylesFromUniformRun(IClientRun run, int irun)
        {
            var textRun = run as TextClientRun;

            if (textRun != null)
            {
                return(textRun.UniformRunStyles(ClientUniformRunIndex));
            }
            return(((Box)run).Style);
        }
        public override void ApplyStyle(string style)
        {
            var        hookup           = Start.Hookup;
            var        start            = new InsertionPoint(hookup, Start.StringPosition, Start.AssociatePrevious);
            IClientRun run              = start.ContainingRun;
            var        box              = start.Para;
            int        lastIndex        = End.Para.Source.ClientRuns.IndexOf(End.ContainingRun);
            int        numBoxes         = 0;
            IStyle     styleToBeApplied = box.Style.Stylesheet.Style(style);

            if (styleToBeApplied == null)
            {
                return;
            }
            var isParagraphStyle = styleToBeApplied.IsParagraphStyle;

            for (int i = start.Para.Source.ClientRuns.IndexOf(run) + 1; hookup != End.Hookup; i++)
            {
                if (isParagraphStyle)
                {
                    numBoxes++;
                }
                else
                {
                    hookup.ApplyStyle(start, hookup.SelectAtEnd(), style);
                }
                if (i >= box.Source.ClientRuns.Count)
                {
                    box = box.NextParaBox;
                    if (box == null)
                    {
                        return;
                    }
                    hookup = box.SelectAtStart().Hookup;
                    i      = 0;
                }
                else
                {
                    hookup = box.Source.ClientRuns[i].SelectAtStart(box).Hookup;
                }
                start = hookup.SelectAtStart();
            }
            if (isParagraphStyle)
            {
                numBoxes++;
                ApplyParagraphStyle(Start, numBoxes, style);
            }
            else
            {
                hookup.ApplyStyle(start, End, style);
            }
        }
Example #10
0
        private void AddRunsForUniformRun(TextClientRun textRun, List <MapRun> runs, ref int ichLog, ref int ichRen, int irun)
        {
            int    offset     = 0;
            string contents   = textRun.UniformRunText(irun);
            int    orcIndex   = contents.IndexOf(orc);
            int    len        = textRun.UniformRunLength(irun);
            int    fullLength = len;

            while (orcIndex >= 0)
            {
                // Make a run for the (possibly empty) text before the ORC
                len = fullLength - orcIndex - 1;
                runs.Add(new MapRun(ichLog, textRun, ichRen, offset, irun, orcIndex));
                ichLog += orcIndex;
                ichRen += orcIndex;
                offset += orcIndex;

                // Make a run for the ORC itself.
                IClientRun    orcRun     = Interpreter(textRun, offset);
                TextClientRun textOrcRun = orcRun as TextClientRun;
                if (textOrcRun == null)
                {
                    // interpreted as a box! Need to put the ORC run (the box) in as the contents of
                    // the run.
                    runs.Add(new OrcMapRun(ichLog, orcRun, ichRen, offset, irun, 1, orcRun));
                    ichRen++;
                }
                else
                {
                    int renderLength = textOrcRun.UniformRunLength(0);                     // not yet supporting multi-run TextClientRuns for ORCs.
                    runs.Add(new OrcMapRun(ichLog, textRun, ichRen, offset, irun, renderLength, orcRun));
                    Debug.Assert(textOrcRun.UniformRunCount == 1);
                    ichRen += renderLength;
                }
                offset++;
                ichLog++;
                orcIndex = contents.IndexOf(orc, orcIndex + 1);
            }
            // Make a (possibly empty) run for any text left over (most commonly the whole contents)
            runs.Add(new MapRun(ichLog, textRun, ichRen, offset, irun, len));
            ichLog += len;
            ichRen += len;
            offset += len;
        }
Example #11
0
		internal AssembledStyles StylesFromUniformRun(IClientRun run, int irun)
		{
			var textRun = run as TextClientRun;
			if (textRun != null)
				return textRun.UniformRunStyles(ClientUniformRunIndex);
			return ((Box)run).Style;
		}
Example #12
0
		public SubstituteMapRun(int logical, IClientRun clientRun, int render, string substitute, AssembledStyles substituteStyle) :
			base(logical, clientRun, render, 0, substitute.Length)
		{
			Debug.Assert(clientRun.Length == 0);
			m_substitute = substitute;
			m_substituteStyle = substituteStyle;
		}
Example #13
0
 public MapRun(int logical, IClientRun clientRun, int render, int offset, int renderLength)
     : this(logical, clientRun, render, offset, 0, renderLength)
 {
 }
Example #14
0
		public MapRun(int logical, IClientRun clientRun, int render, int offset, int renderLength)
			: this(logical, clientRun, render, offset, 0, renderLength)
		{
		}
Example #15
0
 public OrcMapRun(int logical, IClientRun clientRun, int render, int offset, int clientUniformRunIndex, int renderLength, IClientRun orcExpansion)
     : base(logical, clientRun, render, offset, clientUniformRunIndex, renderLength)
 {
     OrcExpansion = orcExpansion;
 }
Example #16
0
 /// <summary>
 /// Add another run. This causes the MapRuns to be recalculated when needed, but does not redo layout
 /// or update display; it is intended for use by the ViewBuilder during box construction.
 /// </summary>
 internal void InsertRun(int index, IClientRun run)
 {
     Source.InsertRun(index, run);
 }
Example #17
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);
		}
Example #18
0
 /// <summary>
 /// This is the basic way we make edits to paragraph contents.
 /// Optimize JohnT: take advantage of existing information in the old source to avoid
 /// recomputing, especially for unchanged client runs.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="newRun"></param>
 /// <returns></returns>
 internal SourceChangeDetails ClientRunChanged(int index, IClientRun newRun)
 {
     return(new ClientRunChangedMethod(this, index, newRun).Run());
 }
Example #19
0
 /// <summary>
 /// Insert another run. This causes the MapRuns to be recalculated when needed, but does not redo layout
 /// or update display; it is intended for use by the ViewBuilder during box construction.
 /// May also be used during later edits, but then the caller is responsible to relayout.
 /// </summary>
 internal void InsertRun(int index, IClientRun run)
 {
     ClientRuns.Insert(index, run);
     AdjustClientRunIndexes(index); // Enhance: want a test that shows this is needed.
     Runs = null;                   // ensure recalculated when needed.
 }
Example #20
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");
		}
Example #21
0
		public OrcMapRun(int logical, IClientRun clientRun, int render, int offset, int clientUniformRunIndex, int renderLength, IClientRun orcExpansion)
			: base(logical, clientRun, render, offset, clientUniformRunIndex, renderLength)
		{
			OrcExpansion = orcExpansion;
		}
Example #22
0
		/// <summary>
		/// Add another run. This causes the MapRuns to be recalculated when needed, but does not redo layout
		/// or update display; it is intended for use by the ViewBuilder during box construction.
		/// </summary>
		internal void InsertRun(int index, IClientRun run)
		{
			Source.InsertRun(index, run);
		}
Example #23
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);
 }