Exemplo n.º 1
0
        private void EditPairForm_Shown(object sender, EventArgs e)
        {
            TextPair = ParallelTextControl[PairIndex];

            if (ParallelTextControl.Reversed)
            {
                textBox1.Text = TextPair.SB2 == null ? TextPair.Text2 : TextPair.SB2.ToString();
                textBox2.Text = TextPair.SB1 == null ? TextPair.Text1 : TextPair.SB1.ToString();
                start1.Checked = TextPair.StartParagraph2;
                start2.Checked = TextPair.StartParagraph1;
            }
            else
            {
                textBox1.Text = TextPair.SB1 == null ? TextPair.Text1 : TextPair.SB1.ToString();
                textBox2.Text = TextPair.SB2 == null ? TextPair.Text2 : TextPair.SB2.ToString();
                start1.Checked = TextPair.StartParagraph1;
                start2.Checked = TextPair.StartParagraph2;
            }

            switch (TextPair.StructureLevel)
            {
                case 0:
                    level0.Checked = true;
                    break;
                case 1:
                    level1.Checked = true;
                    break;
                case 2:
                    level2.Checked = true;
                    break;
                case 3:
                    level3.Checked = true;
                    break;
            }

            Result = false;
        }
Exemplo n.º 2
0
        private void InsertPair(bool insertAfter)
        {
            if (!pTC.EditMode)
                return;

            int newIndex;

            if (pTC.Number == 0)
                newIndex = 0;
            else if (insertAfter)
                newIndex = pTC.HighlightedPair + 1;
            else
                newIndex = pTC.HighlightedPair;

            TextPair newTp = new TextPair("", "", true, true);

            pTC.PText.TextPairs.Insert(newIndex, newTp);

            if (pTC.EditPair(newIndex, true))
            {
                GotoPair(newIndex, false, false, 2);
            }
            else
                pTC.PText.DeletePair(newIndex);
        }
Exemplo n.º 3
0
        public static void SetFramesByPair(TextPair textPair, DoubleFrame df)
        {
            if (df == null)
                return;

            if (textPair == null)
            {
                df.F1.Visible = false;
                df.F2.Visible = false;
            }
            else
            {
                df.F1.FillByRenderInfo(textPair.RenderedInfo1, 1);
                df.F2.FillByRenderInfo(textPair.RenderedInfo2, 2);
            }
        }
Exemplo n.º 4
0
        void ProcessTextFromPair(TextPair p, byte side, ref int occLength, Collection<CommonWordInfo> words, ref int height, ref int MaxWidth, int requiredHeight)
        {
            if ((side == 1) ? p.AllLinesComputed1 : p.AllLinesComputed2)
                return;

            int pos;
            int wordPos;

            if (height == -1)
            {
                pos = 0;
                height = 0;
                if (side == 1)
                    p.ContinueFromNewLine1 = false;
                else
                    p.ContinueFromNewLine2 = false;
            }
            else
            {
                if (side == 1)
                {
                    pos = p.CurrentPos1;
                    if (p.ContinueFromNewLine1)
                    {
                        occLength = indentLength;
                        p.ContinueFromNewLine1 = false;
                    }

                }
                else
                {
                    pos = p.CurrentPos2;
                    if (p.ContinueFromNewLine2)
                    {
                        occLength = indentLength;
                        p.ContinueFromNewLine2 = false;
                    }
                }

            }

            wordPos = -1;

            char c;

            StringBuilder word = new StringBuilder();

            int textLength = p.GetLength(side);

            while (pos < textLength)
            {
                // Must be slow
                c = p.GetChar(side, pos);

                if (c == ' ' || c == '\t' || c == '\r')
                {

                    if (word.Length == 0)
                    {
                        pos++;
                        continue;
                    }

                    ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false);

                    if (requiredHeight != -1 && requiredHeight == height)
                        goto CommonExit;

                    wordPos = -1;

                }
                else if (c == '\n')
                {
                    if (word.Length > 0)
                    {
                        ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false);
                        if (requiredHeight != -1 && requiredHeight == height)
                        {
                            wordPos = pos;
                            goto CommonExit;
                        }
                        wordPos = -1;
                    }

                    ParallelText.InsertWords(words, 0);

                    height++;
                    occLength = indentLength;

                    if (requiredHeight != -1 && requiredHeight == height)
                    {
                        //height--;
                        wordPos = ++pos;
                        if (side == 1)
                            p.ContinueFromNewLine1 = true;
                        else
                            p.ContinueFromNewLine2 = true;
                        goto CommonExit;
                    }

                }

                else if (IsEasternCharacter(c))
                {
                    if (word.Length != 0)
                    {
                        ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false);
                        if (requiredHeight != -1 && requiredHeight == height)
                            goto CommonExit;
                    }

                    word.Append(c);

                    ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref pos, true);

                    if (requiredHeight != -1 && requiredHeight == height)
                    {
                        wordPos = pos;
                        goto CommonExit;
                    }

                    wordPos = -1;

                }

                else
                {
                    if (wordPos == -1)
                        wordPos = pos;

                    word.Append(c);
                }

                pos++;

            }

            // Reached the end, process current Word (if there is any)
            if (word.Length > 0)
            {
                ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false);
                if (requiredHeight != -1 && requiredHeight == height)
                    goto CommonExit;
            }

            if (side == 1)
                p.AllLinesComputed1 = true;
            else
                p.AllLinesComputed2 = true;

            return;

            // Get here when the Height is reached
            CommonExit:

            if (side == 1)
            {
                p.CurrentPos1 = wordPos;
            }
            else
            {
                p.CurrentPos2 = wordPos;
            }
        }
Exemplo n.º 5
0
        public static string GetWord(TextPair p, byte side, int pos)
        {
            char c;

            StringBuilder word = new StringBuilder();

            int length = p.GetLength(side);

            while (pos < length)
            {
                c = p.GetChar(side, pos);
                if (c == ' ' || c == '\t')
                    if (word.Length == 0)
                    {
                        pos++;
                        continue;
                    }
                    else
                        break;

                if (c == '\n' || c == '\r')
                    break;

                if (IsEasternCharacter(c))
                    return c.ToString();

                word.Append(c);

                pos++;
            }

            return word.ToString();
        }
Exemplo n.º 6
0
        private void NipASide(TextPair source_pair, TextPair target_pair, byte side)
        {
            int final_pos;

            StringBuilder source_sb = null;

            if (side == 1)
            {
                final_pos = NaturalDividerPosition1;
                if (source_pair.SB1 == null)
                {
                    source_pair.SB1 = new StringBuilder(source_pair.Text1);
                    source_pair.Text1 = null;
                }
                source_sb = source_pair.SB1;
            }
            else
            {
                final_pos = NaturalDividerPosition2;
                if (source_pair.SB2 == null)
                {
                    source_pair.SB2 = new StringBuilder(source_pair.Text2);
                    source_pair.Text2 = null;
                }
                source_sb = source_pair.SB2;
            }

            StringBuilder sb = new StringBuilder();

            int state = 0;
            char c;

            int pos = 0;

            while (pos < final_pos)
            {
                c = source_sb[pos];

                switch (c)
                {
                    case ' ':
                    case '\r':
                    case '\t':
                        if (state == 1)
                            state = 2;
                        break;
                    case '\n':
                        if (state > 0)
                            state = 3;
                        break;
                    default:
                        if (state == 2)
                            sb.Append(' ');
                        else if (state == 3)
                        {
                            sb.Append('\r');
                            sb.Append('\n');
                        }
                        sb.Append(c);
                        state = 1;
                        break;
                }

                pos++;

            }

            if (side == 1)
                target_pair.Text1 = sb.ToString();
            else
                target_pair.Text2 = sb.ToString();

            bool startParagraph = (state == 3);
            if (side == 1)
                source_pair.StartParagraph1 = startParagraph;
            else
                source_pair.StartParagraph2 = startParagraph;

            // Cut everything before final_pos in the source text

            source_sb.Remove(0, final_pos);

            if (source_sb.Length < BigTextSize)
            {
                if (side == 1)
                {
                    source_pair.Text1 = source_sb.ToString();
                    source_pair.SB1 = null;
                }
                else
                {
                    source_pair.Text2 = source_sb.ToString();
                    source_pair.SB2 = null;
                }
            }
        }
Exemplo n.º 7
0
        private void ProcessCurrentWord(StringBuilder word, ref int occLength, Collection<CommonWordInfo> words, ref int Height, TextPair p, byte side, ref int MaxWidth, ref int wordPosition, bool eastern)
        {
            // Current Word complete, let's get its length

            int wordLength;

            wordLength = WordWidth(word.ToString(), PanelGraphics);

            int newStart = occLength + (words.Count == 0 || eastern && words.Count > 0 && words[words.Count - 1].Eastern ? 0 : SpaceLength);

            if (newStart + wordLength > MaxWidth && words.Count != 0)
            {
                // Move this Word to the Next Line.
                // Before that we need to flush words to the DB

                ParallelText.InsertWords(words, MaxWidth - occLength);

                Height++;

                newStart = 0;

                occLength = 0;

            }

            // Add this Word to the current Line
            words.Add(new CommonWordInfo(p, word.ToString(), Height, newStart, newStart + wordLength - 1, wordPosition, eastern, side));
            occLength = newStart + wordLength;

            word.Length = 0;
        }
Exemplo n.º 8
0
        bool NeedToLineBreakFirstWord(TextPair p, byte side, ref int occLength, ref int maxWidth, int sL, bool startParagraph)
        {
            if (occLength == 0) return false;
            if (startParagraph) return true;

            return (maxWidth - occLength - sL <= WordWidth(GetWord(p, side, 0), PanelGraphics));
        }
Exemplo n.º 9
0
        internal bool NipHighlightedPair()
        {
            if (NaturalDividerPosition1W == null
                    || NaturalDividerPosition2W == null)

                return false;

            TextPair np = new TextPair();

            TextPair hp = PText.TextPairs[HighlightedPair];

            np.StartParagraph1 = hp.StartParagraph1;
            np.StartParagraph2 = hp.StartParagraph2;

            NipASide(hp, np, 1);
            NipASide(hp, np, 2);

            np.AudioFileNumber = hp.AudioFileNumber;
            np.TimeBeg = hp.TimeBeg;
            np.TimeEnd = hp.TimeEnd;

            hp.AudioFileNumber = 0;
            hp.TimeBeg = 0;
            hp.TimeEnd = 0;

            PText.TextPairs.Insert(HighlightedPair, np);

            if (EditWhenNipped)
            {
                PrepareEditForm();

                editPairForm.ParallelTextControl = this;
                editPairForm.PairIndex = HighlightedPair;
                editPairForm.ShowDialog();
                EditWhenNipped = false;
            }

            PText[HighlightedPair].UpdateTotalSize();
            PText[HighlightedPair + 1].UpdateTotalSize();
            PText.UpdateAggregates(HighlightedPair);

            // Truncate all preceding pairs until true-true

            TextPair _p;
            int i = HighlightedPair;

            do
            {
                i--;
                if (i < 0)
                    break;
                _p = PText.TextPairs[i];
                _p.ClearComputedWords();
            }

            while (!_p.StartParagraph1 || !_p.StartParagraph2);

            hp.ClearComputedWords();

            // Truncate all following pairs until end or true-true

            HighlightedPair++;

            int j = HighlightedPair;

            TextPair _q;

            while (j < PText.Number() - 1)
            {
                j++;
                _q = PText[j];
                if (_q.StartParagraph1 && _q.StartParagraph2)
                    break;
                _q.ClearComputedWords();
            }

            if (!stopwatchStarted)
                ResetStopwatch(1);
            else
                if (!stopWatch.IsRunning)
                    stopWatch.Start();

            PrepareScreen();
            RenderPairs(false);

            FindFirstNaturalDividers();

            if (CurrentPair != HighlightedPair
                && PosIsOnOrAfterLastScreenWord(HighlightedPair, NaturalDividerPosition1, NaturalDividerPosition2))
            {
                CurrentPair = HighlightedPair;
                PrepareScreen();
                RenderPairs(false);
            }

            UpdateFramesOnScreen(0);
            ProcessMousePosition(true, false);
            Render();

            Side1Set = false;
            Side2Set = false;

            Modified = true;

            return true;
        }
Exemplo n.º 10
0
        public bool Load(string newFileName)
        {
            WithAudio = newFileName.EndsWith(".pbs");

            using (XmlTextReader reader = new XmlTextReader(newFileName))
            {
                try
                {
                    reader.Read();
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("File not found or unavailable: " + newFileName);
                    return false;
                }

                if (reader.NodeType != XmlNodeType.Element)
                    return false;

                if (reader.Name != "ParallelBook")
                    return false;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "lang1")
                    return false;

                Lang1 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "author1")
                    return false;

                Author1 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "title1")
                    return false;

                Title1 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "info1")
                    return false;

                Info1 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "lang2")
                    return false;

                Lang2 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "author2")
                    return false;

                Author2 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "title2")
                    return false;

                Title2 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "info2")
                    return false;

                Info2 = reader.Value;

                if (!reader.MoveToNextAttribute())
                    return false;

                if (reader.Name != "info")
                    return false;

                Info = reader.Value;

            NextPair:

                if (!reader.Read())
                    return false;

                if (reader.Name == "p" && reader.NodeType == XmlNodeType.Element)
                {
                    if (!reader.MoveToNextAttribute())
                        return false;

                    TextPair p = new TextPair();

                    if (reader.Name == "l")
                    {
                        if (reader.Value == "3")
                        {
                            p.StartParagraph1 = true;
                            p.StartParagraph2 = true;
                        }
                        else if (reader.Value == "1")
                            p.StartParagraph1 = true;
                        else if (reader.Value == "2")
                            p.StartParagraph2 = true;
                        else if (reader.Value == "4")
                            p.SetStructureLevel(1);
                        else if (reader.Value == "5")
                            p.SetStructureLevel(2);
                        else if (reader.Value == "6")
                            p.SetStructureLevel(3);

                        if (!reader.MoveToNextAttribute())
                            return false;

                    }

                    if (reader.Name != "s")
                        return false;

                    if (reader.Value.Length >= ParallelTextControl.BigTextSize)
                        p.SB1 = new StringBuilder(reader.Value);
                    else
                        p.Text1 = reader.Value;

                    p.totalTextSize = reader.Value.Length;

                    if (!reader.MoveToNextAttribute())
                        return false;

                    if (reader.Name != "t")
                        return false;

                    if (reader.Value.Length >= ParallelTextControl.BigTextSize)
                        p.SB2 = new StringBuilder(reader.Value);
                    else
                        p.Text2 = reader.Value;

                    if (WithAudio && (reader.MoveToNextAttribute()))
                    {
                        if (reader.Name != "f")
                            return false;

                        p.AudioFileNumber = uint.Parse(reader.Value);

                        if (!reader.MoveToNextAttribute())
                            return false;

                        if (reader.Name != "b")
                            return false;

                        p.TimeBeg = uint.Parse(reader.Value);

                        if (!reader.MoveToNextAttribute())
                            return false;

                        if (reader.Name != "e")
                            return false;

                        p.TimeEnd = uint.Parse(reader.Value);
                    }

                    p.totalTextSize += reader.Value.Length;

                    TextPairs.Add(p);

                    goto NextPair;

                }

                reader.Close();

                FileName = newFileName;

                if (TextPairs.Count > 0)
                    UpdateAggregates(0);

                return true;

            }
        }
Exemplo n.º 11
0
 public void AddPair(string text1, string text2, uint audioFileNum, uint timeBeg, uint timeEnd)
 {
     TextPair newPair = new TextPair(text1, text2, true, true, audioFileNum, timeBeg, timeEnd);
     TextPairs.Add(newPair);
 }
Exemplo n.º 12
0
 public CommonWordInfo(TextPair textPair, string word, int line, int wordX, int wordX2, int pos, bool eastern, byte side)
     : base(word, line, wordX, wordX2, pos, eastern)
 {
     this.TextPair = textPair;
     this.side = side;
 }