示例#1
0
        public SimpleLine(SimpleSection section)
        {
            this.Section = section;

            this.Line = new List<SimpleChar>();
            var lineEnd = SimpleChar.LineEnd;
            lineEnd.Line = this;
            this.Line.Add(lineEnd);

            SpacingHanzi = SimpleDocument.BEST_SPACING;
            SpacingHanWestern = SimpleDocument.MIN_SPACING_LOOSE;
            SpacingWestern = 1;
        }
示例#2
0
        public void Merge(SimpleSection next)
        {
            var oldText = Lines.SelectMany(x => x.Line);
            var appendText = next.Lines.SelectMany(x => x.Line);

            List<SimpleChar> newText = oldText.Concat(appendText).Where(x => !x.IsLineEnd).ToList();

            var lines = new List<SimpleLine>();
            bool isLoose = true;
            do {
                var line = new SimpleLine(this);
                line.Fill(newText, isLoose = !isLoose);
                lines.Add(line);
            } while (newText.Count > 0);

            this.Lines = lines;
        }
示例#3
0
        public void Insert(String text)
        {
            text = text.Replace("\r\n", "\n").Replace("\r", "\n");
            var secs = ConvertChars(text);
            var currentSec = this.insertPos.Line.Section;
            int currentSecIndex = sections.IndexOf(currentSec);

            if (secs.Count > 1) {
                var newSec = currentSec.Split(this.insertPos);
                this.sections.Insert(currentSecIndex + 1, newSec);
            }
            currentSec.Insert(this.insertPos, secs[0]);
            var lastInsertChar = secs[0].Count > 0 ? secs[0].Last() : currentSec.End;
            for (int i = 1; i < secs.Count-1; i++) {
                SimpleSection sec = new SimpleSection();
                sec.Insert(sec.End, secs[i]);
                this.sections.Insert(currentSecIndex + i, sec);
                lastInsertChar = sec.End;
            }
            if (secs.Count > 1) {
                var nextSec = sections[currentSecIndex + secs.Count - 1];
                nextSec.Insert(nextSec.Home, secs[secs.Count - 1]);
                if (secs[secs.Count - 1].Count > 0) {
                    lastInsertChar = secs[secs.Count - 1].Last();
                } else {
                    lastInsertChar = null;
                    this.insertPos = nextSec.Home;
                }
            }

            if (lastInsertChar != null) {
                this.insertPos = NextChar(lastInsertChar);
            }

            DrawText();
        }
示例#4
0
        public SimpleSection Split(SimpleChar position)
        {
            var oldText = Lines.SelectMany(x => x.Line).ToList();

            int splitPos = oldText.IndexOf(position);
            var leftText = oldText.Take(splitPos).Where(x => !x.IsLineEnd).ToList();
            var rightText = oldText.Skip(splitPos).Where(x => !x.IsLineEnd).ToList();

            var lines = new List<SimpleLine>();
            bool isLoose = true;
            do {
                var line = new SimpleLine(this);
                line.Fill(leftText, isLoose = !isLoose);
                lines.Add(line);
            } while (leftText.Count > 0);

            this.Lines = lines;

            var splitOne = new SimpleSection();
            splitOne.Insert(splitOne.End, rightText);
            return splitOne;
        }