예제 #1
0
        private static bool TryGetLineBreak(TextRun textRun, out LineBreak lineBreak)
        {
            lineBreak = default;

            if (textRun.Text.IsEmpty)
            {
                return(false);
            }

            var lineBreakEnumerator = new LineBreakEnumerator(textRun.Text);

            while (lineBreakEnumerator.MoveNext())
            {
                if (!lineBreakEnumerator.Current.Required)
                {
                    continue;
                }

                lineBreak = lineBreakEnumerator.Current;

                return(lineBreak.PositionWrap >= textRun.Text.Length || true);
            }

            return(false);
        }
예제 #2
0
 private static IEnumerable <ExtendText> ExtractTextEmb(LineBreak br)
 {
     return(new[] { new ExtendText()
                    {
                        Text = "\n", StartText = br.ContentStart
                    } });
 }
예제 #3
0
        public WzXmlSerializer(int indentation, LineBreak lineBreakType)
        {
            switch (lineBreakType)
            {
            case LineBreak.None:
                lineBreak = "";
                break;

            case LineBreak.Windows:
                lineBreak = "\r\n";
                break;

            case LineBreak.Unix:
                lineBreak = "\n";
                break;
            }

            char[] indentArray = new char[indentation];

            for (int i = 0; i < indentation; i++)
            {
                indentArray[i] = (char)0x20;
            }

            indent = new string(indentArray);
        }
예제 #4
0
        void SkipBlockComment()
        {
            var startLocation = _pos;

            _pos = _pos.Increment(2);
            var end = _input.IndexOf("*/", _pos.Index, StringComparison.Ordinal);

            if (end == -1)
            {
                Raise(_pos.Increment(-2), "Unterminated comment");
            }
            _pos = new Position(_pos.Line, _pos.Column + (end - startLocation.Index), end + 2);
            var lastIndex = startLocation.Index;

            while (true)
            {
                var match = LineBreak.Match(_input, lastIndex);
                if (!match.Success || match.Index >= _pos.Index)
                {
                    break;
                }

                var lineStart = match.Index + match.Length;
                _pos      = new Position(_pos.Line + 1, _pos.Index - lineStart, _pos.Index);
                lastIndex = lineStart;
            }
            //Options.onComment?.Invoke(true, input.Substring(startLocation.Index + 2, end - (startLocation.Index + 2)), new SourceLocation(startLocation, curPosition(), SourceFile));
        }
예제 #5
0
        public static LineBreak xAppendLineBreak(this Paragraph p)
        {
            LineBreak lineBreak = new LineBreak();

            p.Inlines.Add(lineBreak);
            return(lineBreak);
        }
예제 #6
0
        public static String getDocumentUni(FlowDocument flowDoc)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Block b in flowDoc.Blocks)
            {
                Paragraph p = b as Paragraph;
                if (p != null)
                {
                    foreach (Inline i in p.Inlines)
                    {
                        Run       r  = i as Run;
                        LineBreak lb = i as LineBreak;
                        if (r != null)
                        {
                            sb.Append(r.Text);
                        }
                        else if (lb != null)
                        {
                            sb.Append(Environment.NewLine);
                        }
                    }
                }
            }
            return(sb.ToString());
        }
        /// <summary>
        /// This method creates a TextBlock with advanced format, and adds
        /// it to the StackPanel customizeFormatPlaceHolder.
        /// </summary>
        private void FormatText()
        {
            TextBlock formatTextBlock = new TextBlock();
            Run       paragraph1      = new Run()
            {
                Text = "Paragraph1"
            };

            paragraph1.FontFamily = new FontFamily("Magnetob.ttf#Magneto");
            LineBreak lineBreak  = new LineBreak();
            Run       paragraph2 = new Run()
            {
                Text = "Paragraph2"
            };
            LinearGradientBrush brush = new LinearGradientBrush();

            brush.GradientStops.Add(new GradientStop()
            {
                Color = Colors.Blue, Offset = 0d
            });
            brush.GradientStops.Add(new GradientStop()
            {
                Color = Colors.Red, Offset = 1d
            });
            paragraph2.Foreground = brush;
            formatTextBlock.Inlines.Add(paragraph1);
            formatTextBlock.Inlines.Add(lineBreak);
            formatTextBlock.Inlines.Add(paragraph2);
            this.customizeFormatPlaceHolder.Children.Add(formatTextBlock);
        }
예제 #8
0
파일: Emitter.cs 프로젝트: IngisKahn/Nyaml
        public Emitter(Stream stream, bool isCanonical = false, int indent = 2, 
            int width = 80,
            bool allowUnicode = true, LineBreak lineBreak = LineBreak.LineFeed)
        {
            this.stream = stream;

            this.state = this.ExpectStreamStart;

            this.isCanonical = isCanonical;
            this.allowUnicode = allowUnicode;

            if (indent > 1 && indent < 10)
                this.bestIndent = indent;
            if (width > this.bestIndent * 2)
                this.bestWidth = width;
            switch (lineBreak)
            {
                case LineBreak.CarriageReturn:
                    this.bestLineBreak = "\r";
                    break;
                case LineBreak.LineFeed:
                    this.bestLineBreak = "\n";
                    break;
                case LineBreak.CarriageReturnLineFeed:
                    this.bestLineBreak = "\r\n";
                    break;
            }
        }
예제 #9
0
        public bool BraceIsBlock(TokenType prevType)
        {
            if (prevType == TT["colon"])
            {
                var parent = CurrentContext;

                if (parent == TokenContext.Types["b_stat"] || parent == TokenContext.Types["b_expr"])
                {
                    return(!parent.IsExpr);
                }
            }

            if (prevType == TT["_return"])
            {
                return(LineBreak.IsMatch(Input.Slice(State.LastTokenEnd, State.Start)));
            }

            if (prevType == TT["_else"] || prevType == TT["semi"] ||
                prevType == TT["eof"] || prevType == TT["parenR"])
            {
                return(true);
            }

            if (prevType == TT["braceL"])
            {
                return(CurrentContext == TokenContext.Types["b_stat"]);
            }

            return(!State.ExprAllowed);
        }
예제 #10
0
        bool BraceIsBlock(TokenType prevType)
        {
            var parent = CurContext();

            if (parent == TokContext.FExpr || parent == TokContext.FStat)
            {
                return(true);
            }
            if (prevType == TokenType.Colon && (parent == TokContext.BStat || parent == TokContext.BExpr))
            {
                return(!parent.IsExpression);
            }

            // The check for `tt.name && exprAllowed` detects whether we are
            // after a `yield` or `of` construct. See the `updateContext` for
            // `tt.name`.
            if (prevType == TokenType.Return || prevType == TokenType.Name && _exprAllowed)
            {
                return(LineBreak.IsMatch(_input.Substring(_lastTokEnd.Index, Start.Index - _lastTokEnd.Index)));
            }
            if (prevType == TokenType.Else || prevType == TokenType.Semi || prevType == TokenType.Eof || prevType == TokenType.ParenR || prevType == TokenType.Arrow)
            {
                return(true);
            }
            if (prevType == TokenType.BraceL)
            {
                return(parent == TokContext.BStat);
            }
            if (prevType == TokenType.Var || prevType == TokenType.Name)
            {
                return(false);
            }
            return(!_exprAllowed);
        }
예제 #11
0
        private static Inline crtInline(HtmlNode xNode)
        {
            Inline converted = null;

            switch (xNode.Name)
            {
            case "hr":
#if dict_dist
                converted = new LineBreak();
#endif
                break;

            case "a":
                var hb = new Hyperlink();
                hb.Click += OnHyberlinkClick;
                hb.Inlines.Add(new Run()
                {
                    Text = xNode.InnerText
                });
                return(hb);

            case "i":
            case "#text":
                converted = new Run()
                {
                    Text = xNode.InnerText
                };
                break;

            default:
                break;
            }
            return(converted);
        }
예제 #12
0
        public static int ReadInt(int?min, int?max, string optionalText = "", LineBreak lineBreak = None, TextAlign textAlign = Center)
        {
            Cc();
            int res;

            while (true)
            {
                if (optionalText != "")
                {
                    Write(optionalText, lineBreak, textAlign);
                }

                if (textAlign == Center)
                {
                    var nbSpaces = (Console.WindowWidth - optionalText.Length) / 2;
                    Console.SetCursorPosition(nbSpaces, Console.CursorTop);
                }

                if (int.TryParse(Console.ReadLine(), out res))
                {
                    ErrorColors();
                    if ((min == null && max == null) || (min != null && max != null && res >= min && res <= max) || (min == null && res <= max) || (max == null && res >= min))
                    {
                        BaseColors();
                        break;
                    }

                    if (min != null && res < min)
                    {
                        Write();
                        Write("  Error : the input should be at least " + min + "  ", Both, textAlign);
                        BaseColors();
                        Pause("retry");
                    }
                    else if (max != null && res > max)
                    {
                        Write();
                        Write("  Error : the input should be at most " + max + "  ", Both, textAlign);
                        BaseColors();
                        Pause("retry");
                    }
                    else
                    {
                        Write();
                        Write("  Error : the input should be between " + min + " and " + max + "  ", Both, textAlign);
                        BaseColors();
                        Pause("retry");
                    }
                }
                else
                {
                    Write();
                    ErrorColors();
                    Write("  Error : the input is empty, isn't an integer or is too big  ", Both, textAlign);
                    BaseColors();
                    Pause("retry");
                }
            }
            return(res);
        }
예제 #13
0
        bool FindTextPointersI(LineBreak lb, ref RangeData rd)
        {
            if (rd.Pointer1 == null)
            {
                if (rd.Remaining1 <= 0)
                {
                    rd.Pointer1 = lb.ContentStart;
                }
                else
                {
                    rd.Remaining1 -= EolLength;
                }
            }

            if (rd.Pointer2 == null)
            {
                if (rd.Remaining2 <= 0)
                {
                    rd.Pointer2 = lb.ContentStart;
                }
                else
                {
                    rd.Remaining2 -= EolLength;
                }
            }

            return(rd.Done);
        }
예제 #14
0
        public static void Write(string text = "", LineBreak lineBreak = None, TextAlign textAlign = Center)
        {
            var length = "";

            for (var i = 0; i < text.Length; i++)
            {
                length += " ";
            }

            if (lineBreak == Before || lineBreak == Both)
            {
                AlignText(length, textAlign);
                Console.WriteLine(length);
            }

            AlignText(text, textAlign);
            Console.WriteLine(text);

            if (lineBreak != After && lineBreak != Both)
            {
                return;
            }
            AlignText(length, textAlign);
            Console.WriteLine(length);
        }
예제 #15
0
파일: Dumper.cs 프로젝트: IngisKahn/Nyaml
 public Dumper(Stream stream, bool isCanonical = false, int indent = 2, 
     int width = 80,
     bool allowUnicode = true, LineBreak lineBreak = LineBreak.LineFeed)
 {
     this.emitter = new Emitter(stream, isCanonical, indent, width,
         allowUnicode, lineBreak);
 }
예제 #16
0
        void readToken_plus_min(int code)
        {
            // '+-'
            var next = _input[_pos.Index + 1];

            if (next == code)
            {
                if (next == 45 && !_inModule && _input.Get(_pos.Index + 2) == 62 &&
                    (_lastTokEnd.Index == 0 || LineBreak.IsMatch(_input.Substring(_lastTokEnd.Index, _pos - _lastTokEnd))))
                {
                    // A `-->` line comment
                    SkipLineComment(3);
                    SkipSpace();
                    NextToken();
                    return;
                }
                FinishOp(TokenType.IncDec, 2);
            }
            else if (next == 61)
            {
                FinishOp(TokenType.Assign, 2);
            }
            else
            {
                FinishOp(TokenType.PlusMin, 1);
            }
        }
예제 #17
0
        public TextRenderHelper()
        {
            List <char> list = new List <char>();

            list.Add(',');
            list.Add('.');
            list.Add('。');
            list.Add('、');
            this.delimiters = list;
//			base..ctor(); //FIXME:???
            this.Font = UISystem.DefaultFont;
            this.horizontalAlignment = HorizontalAlignment.Center;
            this.verticalAlignment   = VerticalAlignment.Middle;
            this.horizontalOffset    = 0f;
            this.verticalOffset      = 0f;
            this.lineBreak           = LineBreak.Character;
            this.textTrimming        = TextTrimming.None;
            this.lineGap             = 0f;
            Dictionary <LineBreak, TextRenderHelper.ReflectLineBreak> dictionary = new Dictionary <LineBreak, TextRenderHelper.ReflectLineBreak>();

            dictionary.Add(LineBreak.Character, new TextRenderHelper.ReflectLineBreak(this.ReflectLineBreakCharacter));
            dictionary.Add(LineBreak.Word, new TextRenderHelper.ReflectLineBreak(this.ReflectLineBreakWord));
            dictionary.Add(LineBreak.Hyphenation, new TextRenderHelper.ReflectLineBreak(this.ReflectLineBreakHyphenation));
            dictionary.Add(LineBreak.AtCode, new TextRenderHelper.ReflectLineBreak(this.ReflectLineBreakAtCode));
            this.ReflectLineBreakFuncs = dictionary;
            Dictionary <TextTrimming, TextRenderHelper.ReflectTextTrimming> dictionary2 = new Dictionary <TextTrimming, TextRenderHelper.ReflectTextTrimming>();

            dictionary2.Add(TextTrimming.None, new TextRenderHelper.ReflectTextTrimming(this.ReflectTextTrimmingNone));
            dictionary2.Add(TextTrimming.Character, new TextRenderHelper.ReflectTextTrimming(this.ReflectTextTrimmingCharacter));
            dictionary2.Add(TextTrimming.Word, new TextRenderHelper.ReflectTextTrimming(this.ReflectTextTrimmingWord));
            dictionary2.Add(TextTrimming.EllipsisCharacter, new TextRenderHelper.ReflectTextTrimming(this.ReflectTextTrimmingEllipsisCharacter));
            dictionary2.Add(TextTrimming.EllipsisWord, new TextRenderHelper.ReflectTextTrimming(this.ReflectTextTrimmingEllipsisWord));
            this.ReflectTextTrimmingFuncs = dictionary2;
        }
예제 #18
0
파일: Yaml.cs 프로젝트: IngisKahn/Nyaml
 public static void Emit(IEnumerable<Events.Base> events, Stream stream,
     bool isCanonical = false, int indent = 2, int width = 80,
     bool allowUnicode = true, LineBreak lineBreak = LineBreak.LineFeed)
 {
     var dumper = new Dumper(stream, isCanonical, indent, width, allowUnicode,
                             lineBreak);
     Emit(events, dumper);
 }
예제 #19
0
        private void SetCurrent(int pos, byte state)
        {
            LineBreakKind kind = state >= 0xC0
                ? LineBreakKind.Hard
                : LineBreakKind.Soft;

            Current = new LineBreak(pos, kind);
        }
 private TextElement FindTextElement(TreeNode node, LineBreak lb)
 {
     if (lb.Tag == node)
     {
         return(lb);
     }
     return(null);
 }
예제 #21
0
        public void NullifyFontFamily()
        {
            LineBreak lb = new LineBreak();

            lb.FontFamily = null;
            // note: Trying to readback FontFamily, after setting it to null, will crash the plugin
            // see Run.NullifyFontFamily for a more dramatic effect ;-)
        }
예제 #22
0
        private void FixEmojis()
        {
            if (m_pending_change)
            {
                return;
            }

            /* This will prevent our operation from polluting the undo buffer, but it
             * will create an infinite undo stack... need to fix this. */
            BeginChange();

            m_pending_change = true;

            TextPointer cur = Document.ContentStart;

            while (cur.CompareTo(Document.ContentEnd) < 0)
            {
                TextPointer next = cur.GetNextInsertionPosition(LogicalDirection.Forward);
                if (next == null)
                {
                    break;
                }

                TextRange word = new TextRange(cur, next);
                if (word.Text.Length > 0)
                {
                    // Test this so as to preserve caret position
                    bool caret_was_next = (0 == next.CompareTo(CaretPosition));

                    Inline inline;
                    // FIXME: this is a hack, normally we should split into Runs and EmojiInlines
                    if (word.Text == "\n")
                    {
                        inline = new LineBreak();
                    }
                    else
                    {
                        inline = new EmojiInline()
                        {
                            Text = word.Text, FontSize = FontSize, FallbackBrush = Foreground
                        }
                    };

                    next = Replace(word, inline);
                    if (caret_was_next)
                    {
                        CaretPosition = next;
                    }
                }

                cur = next;
            }

            EndChange();

            m_pending_change = false;
        }
        public override object Build(FlowElementBuilderContext context, PrintElementLineBreak element, PrintElementMetadataMap elementMetadataMap)
        {
            var elementContent = new LineBreak();

            FlowElementBuilderHelper.ApplyBaseStyles(elementContent, element);
            FlowElementBuilderHelper.ApplyInlineStyles(elementContent, element);

            return(elementContent);
        }
예제 #24
0
        public void FindName()
        {
            LineBreak lb = new LineBreak();

            Assert.Throws <ArgumentNullException> (delegate {
                lb.FindName(null);
            }, "null");
            Assert.IsNull(lb.FindName(String.Empty), "Empty");
        }
        private Inline CloneInline(Inline inline)
        {
            Inline retVal = null;

            if (inline is LineBreak)
            {
                retVal = new LineBreak();
            }
            else if (inline is Span)
            {
                retVal = new Span();
            }
            else if (inline is Run)
            {
                retVal = new Run(((Run)inline).Text);
            }

            if (inline.ReadLocalValue(Inline.BackgroundProperty) != DependencyProperty.UnsetValue)
            {
                retVal.Background = inline.Background;
            }
            if (inline.ReadLocalValue(Inline.ForegroundProperty) != DependencyProperty.UnsetValue)
            {
                retVal.Foreground = inline.Foreground;
            }
            if (inline.ReadLocalValue(Inline.FontFamilyProperty) != DependencyProperty.UnsetValue)
            {
                retVal.FontFamily = inline.FontFamily;
            }
            if (inline.ReadLocalValue(Inline.FontSizeProperty) != DependencyProperty.UnsetValue)
            {
                retVal.FontSize = inline.FontSize;
            }
            if (inline.ReadLocalValue(Inline.FontStretchProperty) != DependencyProperty.UnsetValue)
            {
                retVal.FontStretch = inline.FontStretch;
            }
            if (inline.ReadLocalValue(Inline.FontStyleProperty) != DependencyProperty.UnsetValue)
            {
                retVal.FontStyle = inline.FontStyle;
            }
            if (inline.ReadLocalValue(Inline.FontWeightProperty) != DependencyProperty.UnsetValue)
            {
                retVal.FontWeight = inline.FontWeight;
            }
            if (inline.ReadLocalValue(Inline.TextEffectsProperty) != DependencyProperty.UnsetValue)
            {
                retVal.TextEffects = inline.TextEffects;
            }
            if (inline.ReadLocalValue(Inline.TextDecorationsProperty) != DependencyProperty.UnsetValue)
            {
                retVal.TextDecorations = inline.TextDecorations;
            }

            return(retVal);
        }
예제 #26
0
 public YAMLWriter(TextWriter tw, int initialdepth, int horizontalthresh, IDictionary <Type, bool> bbd)
 {
     Depth            = new string(' ', initialdepth);
     HorizontalThresh = horizontalthresh;
     Lw                  = new LineWriter(tw, 0);
     BBD                 = bbd;
     VertWriter          = new LeafWriter(this, VertNeedsQuotes, s => LineBreak.IsMatch(s));
     HorizontalArrWriter = new LeafWriter(this, HArrNeedsQuotes, s => false);
     HorizontalDicWriter = new LeafWriter(this, HDicNeedsQuotes, s => false);
 }
예제 #27
0
        private void AddLineBreak()
        {
            _PriorLineBreaks++;

            // Create the LineBreak and buffer it
            LineBreak     lineBreak = new LineBreak();
            DocumentState state     = _DocumentStates.Peek();

            DecorateRun(lineBreak, state);
            _CurrentParagraph.Inlines.Add(lineBreak);
        }
예제 #28
0
        bool FindStartIndexI(LineBreak lb, TextElement el, ref int index)
        {
            if (object.ReferenceEquals(lb, el))
            {
                return(true);
            }

            index += EolLength;

            return(false);
        }
예제 #29
0
        TextPointer FindTextPointerI(LineBreak lb, ref int remainingIndex)
        {
            if (remainingIndex <= 0)
            {
                return(lb.ElementStart);
            }

            remainingIndex -= EolLength;

            return(null);
        }
예제 #30
0
        public void ExtractTextLineBreak_Test()
        {
            //Arrange
            var a = new LineBreak();

            //Act
            var b = Parser.ExtractText(a);

            //Assert
            Assert.IsTrue(b.Any(x => x.Text == "\n"));
        }
예제 #31
0
        private static void NameUpdateContext(Tokenizer tok, TokenType prevType)
        {
            tok.State.ExprAllowed = false;

            if (prevType == Types["_let"] || prevType == Types["_const"] || prevType == Types["_var"])
            {
                if (LineBreak.IsMatch(tok.Input.Slice(tok.State.End)))
                {
                    tok.State.ExprAllowed = true;
                }
            }
        }
예제 #32
0
파일: Yaml.cs 프로젝트: IngisKahn/Nyaml
 public static string Emit(IEnumerable<Events.Base> events,
     bool isCanonical = false, int indent = 2, int width = 80,
     bool allowUnicode = true, LineBreak lineBreak = LineBreak.LineFeed)
 {
     using (var stream = new MemoryStream(1024))
     {
         Emit(events, stream, isCanonical, indent, width, allowUnicode, lineBreak);
         stream.Seek(0, SeekOrigin.Begin);
         using (var reader = new StreamReader(stream))
             return reader.ReadToEnd();
     }
 }
예제 #33
0
        AstThrow ParseThrowStatement(Position nodeStart)
        {
            Next();
            if (LineBreak.IsMatch(_input.Substring(_lastTokEnd.Index, Start.Index - _lastTokEnd.Index)))
            {
                Raise(_lastTokEnd, "Illegal newline after throw");
            }
            var argument = ParseExpression();

            Semicolon();
            return(new AstThrow(this, nodeStart, _lastTokEnd, argument));
        }
예제 #34
0
        private void btnBreakText_Click(object sender, EventArgs e)
        {
            string strInput = txtInput.Text;

            if (string.IsNullOrEmpty(strInput))
            {
                return;
            }

            txtOutput.Clear();

            LineBreak linebreak = new LineBreak();

            LineBreakElement[] lbElements = linebreak.FindLineBreaks(strInput);

            StringBuilder sb = new StringBuilder();

            int lineWidth    = 0;
            int maxLineWidth = (int)nudLineWidth.Value;
            int ich          = 0;

            foreach (char ch in strInput)
            {
                LineBreakCondition lbCondition = lbElements[ich].Condition;
                ich++;
                string strElem = ch.ToString();
                if (lbCondition == LineBreakCondition.Allowed)
                {
                    if (lineWidth >= maxLineWidth)
                    {
                        sb.AppendLine(string.Empty);
                        lineWidth = 0;
                    }

                    sb.Append(strElem);
                }
                else if (lbCondition == LineBreakCondition.Mandatory)
                {
                    sb.AppendLine(string.Empty);
                    lineWidth = 0;
                    //sb.Append(strElem);
                    // sb.AppendLine(strElem);
                }
                else
                {
                    sb.Append(strElem);
                }

                lineWidth++;
            }

            txtOutput.Text = sb.ToString();
        }
예제 #35
0
 public WzXmlSerializer(int indentation, LineBreak lineBreakType)
 {
     switch (lineBreakType)
     {
         case LineBreak.None:
             lineBreak = "";
             break;
         case LineBreak.Windows:
             lineBreak = "\r\n";
             break;
         case LineBreak.Unix:
             lineBreak = "\n";
             break;
     }
     char[] indentArray = new char[indentation];
     for (int i = 0; i < indentation; i++)
         indentArray[i] = (char)0x20;
     indent = new string(indentArray);
 }
 public WzClassicXmlSerializer(int indentation, LineBreak lineBreakType, bool exportbase64)
     : base(indentation, lineBreakType)
 {
     ExportBase64Data = exportbase64;
 }
예제 #37
0
        private Inline UpdateElement(HtmlTag aTag)
        {
            Inline retVal = null;

            switch (aTag.Name)
            {
                case "binding":
                case "text":
                    if (aTag.Name == "binding")
                    {
                        retVal = new Bold(new Run("{Binding}"));
                        if (aTag.Contains("path") && (textBlock.DataContext != null))
                        {
                            object obj = textBlock.DataContext;
                            PropertyInfo pi = obj.GetType().GetProperty(aTag["path"]);
                            if (pi != null && pi.CanRead)
                                retVal = new Run(pi.GetValue(obj, null).ToString());
                        }
                    }
                    else
                        retVal = new Run(aTag["value"]);

                    if (currentState.SubScript) retVal.SetValue(Typography.VariantsProperty, FontVariants.Subscript);
                    if (currentState.SuperScript) retVal.SetValue(Typography.VariantsProperty, FontVariants.Superscript);
                    if (currentState.Bold) retVal = new Bold(retVal);
                    if (currentState.Italic) retVal = new Italic(retVal);
                    if (currentState.Underline) retVal = new Underline(retVal);

                    if (currentState.Foreground.HasValue)
                        retVal.Foreground = new SolidColorBrush(currentState.Foreground.Value);

                    if (currentState.Font != null)
                        try { retVal.FontFamily = new FontFamily(currentState.Font); }
                        catch { } //Font name not found...

                    if (currentState.FontSize.HasValue)
                        retVal.FontSize = currentState.FontSize.Value;

                    break;
                case "br":
                    retVal = new LineBreak();
                    break;
                default:
                    Debug.WriteLine("UpdateElement - " + aTag.Name + " not handled.");
                    retVal = new Run();
                    break;
            }

            if (currentState.HyperLink != null && currentState.HyperLink != "")
            {
                Hyperlink link = new Hyperlink(retVal);
                try
                {
                    link.NavigateUri = new Uri(currentState.HyperLink);
                }
                catch
                {
                    link.NavigateUri = null;
                }
                retVal = link;
            }

            return retVal;
        }
예제 #38
0
파일: UILabel.cs 프로젝트: xorkrus/vk_wm
        LineBreak FitString(string text, int startIndex, int width, Graphics gMeatsure)
        {
            LineBreak lineBreak = new LineBreak();
            int currentIndex = FindWhitespace(text, startIndex);
            if (currentIndex == -1)
                currentIndex = text.Length;
            int lastIndex = startIndex;
            SizeF dims = new SizeF(0, 0);

            lineBreak.Size = new SizeF(0, 0);
            while (currentIndex != -1 && (dims = gMeatsure.MeasureString(text.Substring(startIndex, currentIndex - startIndex), FontFromGdi)).Width <= width)
            {
                // record the width/height while succesfully fit
                lineBreak.Width = dims.Width;
                lineBreak.Height = dims.Height;

                // done
                if (currentIndex == text.Length)
                {
                    lastIndex = currentIndex;
                    currentIndex = -1;
                }
                else if (text[currentIndex] == '\n')
                {
                    lastIndex = currentIndex + 1;
                    currentIndex = -1;
                }
                else
                {
                    // get next word
                    lastIndex = currentIndex + 1;
                    currentIndex = FindWhitespace(text, lastIndex);
                    // end of string
                    if (currentIndex == -1)
                        currentIndex = text.Length;
                }
            }

            if (lastIndex == startIndex)
            {
                // the string was either too long or we are at the end of the string
                if (currentIndex == -1)
                {
                    throw new Exception("Somehow executing unreachable code while drawing text.");
                }

                currentIndex = lastIndex + 1;
                while ((dims = gMeatsure.MeasureString(text.Substring(startIndex, currentIndex - startIndex), FontFromGdi)).Width <= width)
                {
                    lineBreak.Size = new SizeF(dims.Width, dims.Height);
                    currentIndex++;
                }
                lineBreak.Size = new SizeF(dims.Width, dims.Height);
                lineBreak.Width = Math.Min(lineBreak.Width, width);
                lineBreak.Text = text.Substring(startIndex, currentIndex - startIndex);
                lineBreak.Index = currentIndex;
                return lineBreak;
            }
            else
            {
                // return the index we're painting to
                lineBreak.Text = text.Substring(startIndex, lastIndex - startIndex);
                lineBreak.Index = lastIndex;
                return lineBreak;
            }
        }
예제 #39
0
파일: GlyphRun.cs 프로젝트: koush/Xaml
        LineBreak FitString(string text, int startIndex, int width)
        {
            LineBreak lineBreak = new LineBreak();
            lineBreak.Width = 0;
            int dims = 0;

            int currentIndex = FindWhitespace(text, startIndex);
            if (currentIndex == -1)
                currentIndex = text.Length;
            int lastIndex = startIndex;

            while (currentIndex != -1 && (dims = MeasureString(text.Substring(startIndex, currentIndex - startIndex))) <= width)
            {
                // record the width while succesfully fit
                lineBreak.Width = dims;

                // done
                if (currentIndex == text.Length)
                {
                    lastIndex = currentIndex;
                    currentIndex = -1;
                }
                else if (text[currentIndex] == '\n')
                {
                    lastIndex = currentIndex + 1;
                    currentIndex = -1;
                }
                else
                {
                    // get next word
                    lastIndex = currentIndex + 1;
                    currentIndex = FindWhitespace(text, lastIndex);
                    // end of string
                    if (currentIndex == -1)
                        currentIndex = text.Length;
                }
            }

            if (lastIndex == startIndex)
            {
                // the string was either too long or we are at the end of the string
                if (currentIndex == -1)
                    throw new Exception("Somehow executing unreachable code while drawing text.");

                currentIndex = lastIndex + 1;
                while ((dims = MeasureString(text.Substring(startIndex, currentIndex - startIndex))) <= width)
                {
                    lineBreak.Width = dims;
                    currentIndex++;
                }
                lineBreak.Width = Math.Min(dims, width);
                lineBreak.Text = text.Substring(startIndex, currentIndex - startIndex);
                lineBreak.Index = currentIndex;
                return lineBreak;
            }
            else
            {
                // return the index we're painting to
                lineBreak.Text = text.Substring(startIndex, lastIndex - startIndex);
                lineBreak.Index = lastIndex;
                return lineBreak;
            }
        }
 public WzNewXmlSerializer(int indentation, LineBreak lineBreakType)
     : base(indentation, lineBreakType)
 {
 }