コード例 #1
0
        private void CreateLine(TextToken token)
        {
            CreateEmptyLine(token);

            string text = token.Text;
            _block.UpdateHeight(GetTextHeight(text));
            _textWidth = GetTextWidth(text, false, _lastOpenTag.TextProperties);
            _block.AddText(
                text, 
                _lastOpenTag.TextProperties, 
                _fontSize, 
                GetTextSize(text, _lastOpenTag.TextProperties), 
                token.Part, 
                token.ID);
        }
コード例 #2
0
        private void AppendToLine(TextToken token, double textWidth)
        {
            string text = token.Text;
            if (string.IsNullOrEmpty(text))
                return;

            _block = _block ?? new TextTokenBlock
                                   {
                                       TextAlign = _lastOpenTag.TextProperties.TextAlign,
                                       MarginLeft = _marginLeft,
                                       MarginRight = _marginRight,
                                       FirstTokenID = _firstTokenID,
                                       TextIndent = _textIndent
                                   };
            
            _block.LastTokenID = token.ID;
            _block.UpdateHeight(GetTextHeight(text));
            if (_separator)
            {
                TextVisualProperties properties = _lastOpenTag.TextProperties.Clone();
                var inlineItem = _block.Inlines.OfType<TextElement>().LastOrDefault();
                if (inlineItem != null && string.IsNullOrEmpty(inlineItem.LinkID))
                    properties.LinkID = string.Empty;
                _block.AddText(" ", properties, _fontSize, GetTextSize("_", properties));
            }
            _block.AddText(text, _lastOpenTag.TextProperties, _fontSize, GetTextSize(text, _lastOpenTag.TextProperties), token.Part, token.ID);
            _textWidth += textWidth;
        }
コード例 #3
0
        private void AppendToLine(TextToken token)
        {
            if (_separator && (_block == null || _block.Inlines.All(t => !(t is TextElement))))
                _separator = false;
            double width = GetTextWidth(token.Text, _separator, _lastOpenTag.TextProperties);
            if (CanAddText(width))
            {
                AppendToLine(token, width);
            }
            else
            {
                string[] partsOfWord = _hypher.GetPartsOfWord(token.Text, _hyphenation);
                if (partsOfWord.Length > 1)
                {
                    double textWidth = 0.0;
                    string str = string.Empty;
                    foreach (string part in partsOfWord)
                    {
                        string partWithSeparator = part;
                        if (!partWithSeparator.EndsWith("-"))
                            partWithSeparator = partWithSeparator + "-";

                        if (CanAddText(textWidth + GetTextWidth(partWithSeparator, _separator, _lastOpenTag.TextProperties)))
                        {
                            str = str + part;
                            textWidth += GetTextWidth(part, _separator, _lastOpenTag.TextProperties);
                        }
                        else
                            break;
                    }

                    if (!string.IsNullOrEmpty(str))
                    {
                        string partWithSeparator = str;
                        if (!partWithSeparator.EndsWith("-"))
                            partWithSeparator = partWithSeparator + "-";
                        AppendToLine(new TextToken(token.ID, partWithSeparator)
                                         {
                                             Part = str
                                         }, textWidth);

                        string rightPart = token.Text.Remove(0, str.Length);
                        if (rightPart.StartsWith("-"))
                            rightPart = rightPart.Remove(0, 1);
                        token = new TextToken(token.ID, rightPart);
                        CreateEmptyLine(token);
                        AppendToLine(token);
                        return;
                    }
                }
                CreateLine(token);
            }
            _separator = false;
        }
コード例 #4
0
 private bool AppendTextToken(TextToken textToken, string lastText, int stopTokenID, string stopText, ref bool firstText)
 {
     bool flag = false;
     if (textToken.ID == stopTokenID && !string.IsNullOrEmpty(stopText))
     {
         textToken = new TextToken(stopTokenID, stopText + "-") {Part = stopText};
         flag = true;
     }
     if (firstText && !string.IsNullOrEmpty(lastText) && textToken.Text.StartsWith(lastText))
     {
         string text = textToken.Text.Remove(0, lastText.Length);
         if (text.StartsWith("-"))
             text = text.Remove(0, 1);
         textToken = new TextToken(textToken.ID, text);
     }
     AppendToLine(textToken);
     firstText = false;
     return flag;
 }
コード例 #5
0
ファイル: BookSearch.cs プロジェクト: Korshunoved/Win10reader
        private bool CheckLastWord(BookTokenIterator bookTokenIterator, string query, out TextToken result)
        {
            result = null;
            while (bookTokenIterator.MoveNext())
            {
                var textToken = bookTokenIterator.Current as TextToken;
                if (textToken == null)
                    continue;

                if (textToken.Text.StartsWith(query))
                {
                    result = textToken;
                    return true;
                }
                return false;
            }
            return false;
        }