コード例 #1
0
 internal static extern void cvFillConvexPoly(
     Arr img,
     Point[] pts,
     int npts,
     Scalar color,
     LineFlags line_type,
     int shift);
コード例 #2
0
 internal static extern void cvRectangleR(
     Arr img,
     Rect r,
     Scalar color,
     int thickness,
     LineFlags line_type,
     int shift);
コード例 #3
0
ファイル: FullTextLine.cs プロジェクト: redmcg/wpf
            internal FullTextLine(
                FormatSettings settings,
                int cpFirst,
                int lineLength,
                int paragraphWidth,
                LineFlags lineFlags
                )
                : this(settings.TextFormattingMode, settings.Pap.Justify, settings.TextSource.PixelsPerDip)
            {
                if ((lineFlags & LineFlags.KeepState) != 0 ||
                    settings.Pap.AlwaysCollapsible)
                {
                    _statusFlags |= StatusFlags.KeepState;
                }

                int finiteFormatWidth = settings.GetFiniteFormatWidth(paragraphWidth);

                FullTextState fullText = FullTextState.Create(settings, cpFirst, finiteFormatWidth);

                // formatting the line
                FormatLine(
                    fullText,
                    cpFirst,
                    lineLength,
                    fullText.FormatWidth,
                    finiteFormatWidth,
                    paragraphWidth,
                    lineFlags,
                    null    // collapsingSymbol
                    );
            }
コード例 #4
0
        internal LsErr CreateLine(
            int cpFirst,
            int lineLength,
            int maxWidth,
            LineFlags lineFlags,
            IntPtr previousLineBreakRecord,
            out IntPtr ploline,
            out LsLInfo plslineInfo,
            out int maxDepth,
            out LsLineWidths lineWidths
            )
        {
            Invariant.Assert(_ploc.Value != System.IntPtr.Zero);

            return(UnsafeNativeMethods.LoCreateLine(
                       _ploc.Value,
                       cpFirst,
                       lineLength,
                       maxWidth,
                       (uint)lineFlags, // line flags
                       previousLineBreakRecord,
                       out plslineInfo,
                       out ploline,
                       out maxDepth,
                       out lineWidths
                       ));
        }
コード例 #5
0
 internal static extern void cvInitFont(
     IntPtr font,
     FontFace font_face,
     double hscale,
     double vscale,
     double shear,
     int thickness,
     LineFlags line_type);
コード例 #6
0
 internal static extern void cvFillPoly(
     Arr img,
     IntPtr[] pts,
     int[] npts,
     int contours,
     Scalar color,
     LineFlags line_type,
     int shift);
コード例 #7
0
 internal static extern void cvCircle(
     Arr img,
     Point center,
     int radius,
     Scalar color,
     int thickness,
     LineFlags line_type,
     int shift);
コード例 #8
0
 internal static extern void cvRectangle(
     Arr img,
     Point pt1,
     Point pt2,
     Scalar color,
     int thickness,
     LineFlags line_type,
     int shift);
コード例 #9
0
 internal static extern void cvDrawContours(
     Arr img,
     Seq contour,
     Scalar external_color,
     Scalar hole_color,
     int max_level,
     int thickness,
     LineFlags line_type,
     Point offset);
コード例 #10
0
        /// <summary>
        /// Emits a new line to the output string.
        /// </summary>
        protected void NewLine()
        {
            Builder.AppendLine();
            Builder.Append(Indents.ToString());

            BracketCount  = ParenCount = 0;
            LineFlags     = NextLineFlags;
            NextLineFlags = LineFlags.None;
        }
コード例 #11
0
 internal static extern void cvPolyLine(
     Arr img,
     IntPtr[] pts,
     int[] npts,
     int contours,
     int is_closed,
     Scalar color,
     int thickness,
     LineFlags line_type,
     int shift);
コード例 #12
0
 internal void RemoveFlags(int line, LineFlags flags)
 {
     lock (dict)
     {
         if (dict.ContainsKey(line))
         {
             dict[line] &= ~flags;
         }
     }
 }
コード例 #13
0
 internal static extern void cvEllipse(
     Arr img,
     Point center,
     Size axes,
     double angle,
     double start_angle,
     double end_angle,
     Scalar color,
     int thickness,
     LineFlags line_type,
     int shift);
コード例 #14
0
 internal void SetFlags(int line, LineFlags flags)
 {
     lock (dict)
     {
         if (dict.ContainsKey(line))
         {
             dict[line] |= flags;
         }
         else
         {
             dict.Add(line, flags);
         }
     }
 }
コード例 #15
0
 public void Load(BinaryReaderBE reader)
 {
     EndpointIndexes[0] = reader.ReadInt16();
     EndpointIndexes[1] = reader.ReadInt16();
     Flags  = (LineFlags)reader.ReadUInt16();
     Length = reader.ReadInt16();
     HighestAdjacentFloor             = reader.ReadInt16();
     LowestAdjacentCeiling            = reader.ReadInt16();
     ClockwisePolygonSideIndex        = reader.ReadInt16();
     CounterclockwisePolygonSideIndex = reader.ReadInt16();
     ClockwisePolygonOwner            = reader.ReadInt16();
     CounterclockwisePolygonOwner     = reader.ReadInt16();
     reader.BaseStream.Seek(12, SeekOrigin.Current);
 }
コード例 #16
0
ファイル: LineDef.cs プロジェクト: vandermjr/managed-doom
        public LineDef(
            Vertex vertex1,
            Vertex vertex2,
            LineFlags flags,
            LineSpecial special,
            short tag,
            SideDef frontSide,
            SideDef backSide)
        {
            this.vertex1   = vertex1;
            this.vertex2   = vertex2;
            this.flags     = flags;
            this.special   = special;
            this.tag       = tag;
            this.frontSide = frontSide;
            this.backSide  = backSide;

            dx = vertex2.X - vertex1.X;
            dy = vertex2.Y - vertex1.Y;

            if (dx == Fixed.Zero)
            {
                slopeType = SlopeType.Vertical;
            }
            else if (dy == Fixed.Zero)
            {
                slopeType = SlopeType.Horizontal;
            }
            else
            {
                if (dy / dx > Fixed.Zero)
                {
                    slopeType = SlopeType.Positive;
                }
                else
                {
                    slopeType = SlopeType.Negative;
                }
            }

            boundingBox             = new Fixed[4];
            boundingBox[Box.Top]    = Fixed.Max(vertex1.Y, vertex2.Y);
            boundingBox[Box.Bottom] = Fixed.Min(vertex1.Y, vertex2.Y);
            boundingBox[Box.Left]   = Fixed.Min(vertex1.X, vertex2.X);
            boundingBox[Box.Right]  = Fixed.Max(vertex1.X, vertex2.X);

            frontSector = frontSide?.Sector;
            backSector  = backSide?.Sector;
        }
コード例 #17
0
ファイル: LineDef.cs プロジェクト: Ashbjorn/managed-doom
        public LineDef(
            Vertex vertex1,
            Vertex vertex2,
            LineFlags flags,
            LineSpecial special,
            short tag,
            SideDef side0,
            SideDef side1)
        {
            Vertex1 = vertex1;
            Vertex2 = vertex2;
            Flags   = flags;
            Special = special;
            Tag     = tag;
            Side0   = side0;
            Side1   = side1;

            Dx = vertex2.X - vertex1.X;
            Dy = vertex2.Y - vertex1.Y;

            if (Dx == Fixed.Zero)
            {
                SlopeType = SlopeType.Vertical;
            }
            else if (Dy == Fixed.Zero)
            {
                SlopeType = SlopeType.Horizontal;
            }
            else
            {
                if (Dy / Dx > Fixed.Zero)
                {
                    SlopeType = SlopeType.Positive;
                }
                else
                {
                    SlopeType = SlopeType.Negative;
                }
            }

            Box = new Fixed[4];
            Box[ManagedDoom.Box.Top]    = Fixed.Max(vertex1.Y, vertex2.Y);
            Box[ManagedDoom.Box.Bottom] = Fixed.Min(vertex1.Y, vertex2.Y);
            Box[ManagedDoom.Box.Left]   = Fixed.Min(vertex1.X, vertex2.X);
            Box[ManagedDoom.Box.Right]  = Fixed.Max(vertex1.X, vertex2.X);

            FrontSector = side0?.Sector;
            BackSector  = side1?.Sector;
        }
コード例 #18
0
        public CodeLineData(InteropCodeLineData data)
        {
            this.Text    = ConvertString(data.Text);
            this.Comment = ConvertString(data.Comment);
            this.OpSize  = data.OpSize;
            for (int i = 0; i < this.OpSize; i++)
            {
                this.ByteCode += "$" + data.ByteCode[i].ToString("X2") + " ";
            }

            this.Address          = data.Address;
            this.AbsoluteAddress  = data.AbsoluteAddress;
            this.EffectiveAddress = data.EffectiveAddress;
            this.Flags            = (LineFlags)data.Flags;
            this.Value            = data.Value;
            this.ValueSize        = data.ValueSize;
        }
コード例 #19
0
        /// <summary>
        /// Reads <see cref="LinesSubsection"/> from the stream.
        /// </summary>
        /// <param name="reader">Stream binary reader.</param>
        /// <param name="kind">Debug subsection kind.</param>
        /// <param name="dataLength">Debug subsection length.</param>
        public static LinesSubsection Read(IBinaryReader reader, DebugSubsectionKind kind, uint dataLength)
        {
            long            positionEnd     = reader.Position + dataLength;
            LinesSubsection linesSubsection = new LinesSubsection
            {
                Kind       = kind,
                CodeOffset = reader.ReadUint(),
                Segment    = reader.ReadUshort(),
                Flags      = (LinesSubsectionFlags)reader.ReadUshort(),
                Cod        = reader.ReadUint(),
            };
            bool columnsAvailable   = (linesSubsection.Flags & LinesSubsectionFlags.LinesHaveColumns) == LinesSubsectionFlags.LinesHaveColumns;
            List <SourceFile> files = new List <SourceFile>();

            while (reader.Position < positionEnd)
            {
                SourceFile file = new SourceFile
                {
                    Index = reader.ReadUint(),
                    Lines = new Line[reader.ReadUint()],
                };
                uint size = reader.ReadUint();

                for (int i = 0; i < file.Lines.Length; i++)
                {
                    file.Lines[i].Offset = reader.ReadUint();
                    LineFlags flags = (LineFlags)reader.ReadUint();
                    file.Lines[i].LineStart = (uint)(flags & LineFlags.LineNumberStart);
                    file.Lines[i].LineEnd   = file.Lines[i].LineStart + ((uint)(flags & LineFlags.LineEndDelta) >> 24);
                    file.Lines[i].Statement = (flags & LineFlags.Statement) == LineFlags.Statement;
                }
                if (columnsAvailable)
                {
                    for (int i = 0; i < file.Lines.Length; i++)
                    {
                        file.Lines[i].ColumnStart = reader.ReadUshort();
                        file.Lines[i].ColumnEnd   = reader.ReadUshort();
                    }
                }
                files.Add(file);
            }
            linesSubsection.Files = files.ToArray();
            return(linesSubsection);
        }
コード例 #20
0
            public SourceLine(string s)
            {
                src = s;
                LineFlags lf = LineFlags.None;

                if (s.Contains("VECTOR_TYPE"))
                {
                    lf |= LineFlags.HasVec;
                }
                if (s.Contains("SIMD_OP"))
                {
                    lf |= LineFlags.HasOp;
                }
                if (!string.IsNullOrWhiteSpace(s) && s[0] != '#')
                {
                    lf |= LineFlags.NeedsTabs;
                }
                flags = lf;
            }
コード例 #21
0
        internal LsErr CreateLine(
            int                 cpFirst, 
            int                 lineLength, 
            int                 maxWidth,
            LineFlags           lineFlags, 
            IntPtr              previousLineBreakRecord,
            out IntPtr          ploline,
            out LsLInfo         plslineInfo,
            out int             maxDepth, 
            out LsLineWidths    lineWidths
            ) 
        { 
            Invariant.Assert(_ploc.Value != System.IntPtr.Zero);
 
            return UnsafeNativeMethods.LoCreateLine(
                _ploc.Value,
                cpFirst,
                lineLength, 
                maxWidth,
                (uint)lineFlags,    // line flags 
                previousLineBreakRecord, 
                out plslineInfo,
                out ploline, 
                out maxDepth,
                out lineWidths
                );
        } 
コード例 #22
0
        /// <summary>
        /// Formats the given JavaScript string.
        /// </summary>
        /// <param name="javascript">JavaScript script to format.</param>
        /// <returns>The formatted string.</returns>
        public string Format(string javascript)
        {
            Tokenizer tokenizer   = new Tokenizer(javascript);
            bool      endLine     = false; // Cause new line
            bool      isLineStart = true;  // Current token is first on line
            Token     peek;

            Builder.Capacity = javascript.Length;
            Indents.Reset();
            ParenCount    = 0;
            BracketCount  = 0;
            LineFlags     = LineFlags.None;
            NextLineFlags = LineFlags.None;

            // Process each token in input string
            while (tokenizer.GetToken())
            {
                // Get current token
                Token token = tokenizer.CurrentToken;

                // Test for new line
                if (Builder.Length > 0)
                {
                    isLineStart = endLine;
                    if (endLine)
                    {
                        NewLine();
                        endLine = false;
                    }
                }

                // Process this token
                switch (token.Type)
                {
                case TokenType.OpenBrace:
                    if (!isLineStart)
                    {
                        if (FormatOptions.OpenBraceOnNewLine && Builder.Length > 0)
                        {
                            // Put open brace on new line
                            NewLine();
                        }
                        else
                        {
                            // Put open brace on same line
                            if (token.PreviousType != TokenType.OpenParen &&
                                token.PreviousType != TokenType.OpenBracket)
                            {
                                Builder.Append(' ');
                            }
                        }
                    }

                    // Write token
                    Builder.Append(token.Value);

                    // Start new indent block
                    peek = tokenizer.PeekToken();
                    if (peek.Type == TokenType.CloseBrace)
                    {
                        // Special handling for "{}"
                        tokenizer.GetToken();
                        Builder.Append(tokenizer.CurrentToken.Value);
                        peek = tokenizer.PeekToken();
                        if (peek.Type != TokenType.SemiColon &&
                            peek.Type != TokenType.Comma)
                        {
                            // Unindent if in conditional block without braces
                            while (Indents.Current.HasFlag(IndentFlags.NoBraces))
                            {
                                Indents.Unindent();
                            }
                            endLine = true;
                        }
                        else if (peek.Type == TokenType.Comma)
                        {
                            // Normally, we insert a new line after
                            // a closing brace and comma but not here
                            tokenizer.GetToken();
                            Builder.Append(tokenizer.CurrentToken.Value);
                        }
                    }
                    else
                    {
                        // Increase indentation
                        IndentFlags flags = IndentFlags.None;
                        if (LineFlags.HasFlag(LineFlags.DoKeyword))
                        {
                            flags |= IndentFlags.DoBlock;
                        }
                        else if (LineFlags.HasFlag(LineFlags.CaseKeyword))
                        {
                            flags |= IndentFlags.CaseBlock;
                        }

                        Indents.Indent(flags);
                        endLine = true;
                    }
                    break;

                case TokenType.CloseBrace:
                    // End indent block
                    if (Indents.Current.HasFlag(IndentFlags.CaseBlock))
                    {
                        // Extra unindent if in case/default block
                        Indents.Unindent();
                        if (isLineStart)
                        {
                            Indents.StripTrailingIndent(Builder);
                        }
                    }

                    // Unindent if in conditional block without braces
                    while (Indents.Current.HasFlag(IndentFlags.NoBraces))
                    {
                        Indents.Unindent();
                    }

                    // Regular unindent
                    Indents.Unindent();
                    if (isLineStart)
                    {
                        Indents.StripTrailingIndent(Builder);
                    }
                    else
                    {
                        NewLine();
                    }
                    Builder.Append(token.Value);

                    // Don't unindent without braces for catch/finally
                    peek = tokenizer.PeekToken();
                    if (peek.Value != "catch" &&
                        peek.Value != "finally" &&
                        peek.Value != ":")
                    {
                        // Unindent if in conditional block without braces
                        while (Indents.Current.HasFlag(IndentFlags.NoBraces))
                        {
                            Indents.Unindent();
                        }
                    }

                    if (Indents.LastIndent.HasFlag(IndentFlags.DoBlock))
                    {
                        LineFlags |= LineFlags.EndDoBlock;
                    }

                    // Insert new line after code block
                    if (peek.Type != TokenType.SemiColon &&
                        peek.Type != TokenType.CloseParen &&
                        peek.Type != TokenType.CloseBracket &&
                        peek.Type != TokenType.Comma &&
                        peek.Type != TokenType.OpenParen &&
                        peek.Type != TokenType.Colon &&
                        !LineFlags.HasFlag(LineFlags.EndDoBlock))
                    {
                        endLine = true;
                    }
                    break;

                case TokenType.OpenParen:
                    if (!isLineStart &&
                        token.PreviousType != TokenType.OpenParen &&
                        token.PreviousType != TokenType.UnaryPrefix &&
                        token.PreviousType != TokenType.CloseBracket &&
                        token.PreviousType != TokenType.CloseParen &&
                        token.PreviousType != TokenType.CloseBrace &&
                        (token.PreviousType != TokenType.Symbol ||
                         (LineFlags.HasFlag(LineFlags.BlockKeyword) &&
                          ParenCount == 0)))
                    {
                        Builder.Append(' ');
                    }
                    Builder.Append(token.Value);
                    ParenCount++;
                    break;

                case TokenType.CloseParen:
                    // Append closing parenthesis
                    Builder.Append(token.Value);
                    ParenCount = Math.Max(ParenCount - 1, 0);

                    // Test for indent block start without braces
                    if (ParenCount == 0 &&
                        LineFlags.HasFlag(LineFlags.BlockKeyword))
                    {
                        // Examine next token
                        peek = tokenizer.PeekToken();
                        if (peek.Type != TokenType.OpenBrace)
                        {
                            // Single line indent with no conditions or braces
                            Indents.Indent(IndentFlags.NoBraces);
                            endLine = true;
                        }
                    }
                    break;

                case TokenType.OpenBracket:
                    if (!isLineStart &&
                        token.PreviousType != TokenType.Symbol &&
                        token.PreviousType != TokenType.OpenParen &&
                        token.PreviousType != TokenType.CloseParen &&
                        token.PreviousType != TokenType.CloseBracket)
                    {
                        Builder.Append(' ');
                    }

                    // Special handling for JSON syntax?
                    peek = tokenizer.PeekToken();
                    if (LineFlags.HasFlag(LineFlags.JsonColon) &&
                        peek.Type != TokenType.CloseBracket &&
                        peek.Type == TokenType.OpenBrace &&
                        ParenCount == 0)
                    {
                        if (FormatOptions.OpenBraceOnNewLine)
                        {
                            NewLine();
                        }
                        Indents.Indent(IndentFlags.BracketBlock);
                        endLine = true;
                    }
                    Builder.Append(token.Value);
                    BracketCount++;
                    break;

                case TokenType.CloseBracket:
                    BracketCount = Math.Max(BracketCount - 1, 0);
                    if (Indents.Current.HasFlag(IndentFlags.BracketBlock))
                    {
                        Indents.Unindent();
                        if (isLineStart)
                        {
                            Indents.StripTrailingIndent(Builder);
                            Builder.Append(token.Value);
                        }
                        else
                        {
                            NewLine();
                            Builder.Append(token.Value);
                        }
                    }
                    else
                    {
                        Builder.Append(token.Value);
                    }
                    break;

                case TokenType.Symbol:

                    bool isBlockKeyword = BlockKeywords.Contains(token.Value);

                    // Special handling for function
                    if (token.Value == "function" && FormatOptions.NewLineBetweenFunctions && token.PreviousType == TokenType.CloseBrace)
                    {
                        NewLine();
                    }

                    // Special handling for else without if
                    if (token.Value == "else" && tokenizer.PeekToken().Value != "if")
                    {
                        isBlockKeyword = true;
                    }

                    // Special handling for switch..case..default
                    if (Indents.Current.HasFlag(IndentFlags.CaseBlock) && (token.Value == "case" || token.Value == "default"))
                    {
                        Indents.StripTrailingIndent(Builder);
                        Indents.Unindent();
                    }

                    if (ParenCount == 0 && isBlockKeyword)
                    {
                        // Keyword that starts an indented block
                        if (!isLineStart)
                        {
                            Builder.Append(' ');
                        }
                        // Append this symbol
                        Builder.Append(token.Value);

                        if (!LineFlags.HasFlag(LineFlags.EndDoBlock) ||
                            token.Value != "while")
                        {
                            // Test for special-case blocks
                            if (token.Value == "do")
                            {
                                LineFlags |= LineFlags.DoKeyword;
                            }
                            // Examine next token
                            peek = tokenizer.PeekToken();
                            if (peek.Type == TokenType.OpenBrace ||
                                peek.Type == TokenType.OpenParen)
                            {
                                // Handle indentation at ')' or '{'
                                LineFlags |= LineFlags.BlockKeyword;
                            }
                            else
                            {
                                // Single line indent with no conditions or braces
                                IndentFlags flags = IndentFlags.NoBraces;
                                if (LineFlags.HasFlag(LineFlags.DoKeyword))
                                {
                                    flags |= IndentFlags.DoBlock;
                                }

                                Indents.Indent(flags);
                                endLine = true;
                            }
                        }
                    }
                    else
                    {
                        // All other symbols
                        if (!isLineStart &&
                            token.PreviousType != TokenType.OpenParen &&
                            token.PreviousType != TokenType.OpenBracket &&
                            token.PreviousType != TokenType.UnaryPrefix &&
                            token.PreviousType != TokenType.Dot)
                        {
                            Builder.Append(' ');
                        }

                        // Flag line for case block
                        if (token.Value == "case" || token.Value == "default")
                        {
                            LineFlags |= LineFlags.CaseKeyword;
                        }

                        Builder.Append(token.Value);
                    }
                    break;

                case TokenType.String:
                case TokenType.Number:
                case TokenType.RegEx:
                    // Emit constant
                    if (!isLineStart &&
                        token.PreviousType != TokenType.OpenParen &&
                        token.PreviousType != TokenType.OpenBracket &&
                        token.PreviousType != TokenType.UnaryPrefix)
                    {
                        Builder.Append(' ');
                    }
                    Builder.Append(token.Value);
                    break;

                case TokenType.SemiColon:
                    Builder.Append(token.Value);
                    if (ParenCount == 0)
                    {
                        // Unindent if in conditional block without braces
                        while (Indents.Current.HasFlag(IndentFlags.NoBraces))
                        {
                            Indents.Unindent();
                        }
                        if (Indents.LastIndent.HasFlag(IndentFlags.DoBlock))
                        {
                            NextLineFlags |= LineFlags.EndDoBlock;
                        }

                        // Determine if end of single-line indent block
                        peek = tokenizer.PeekToken();
                        if (peek.Type == TokenType.LineComment ||
                            peek.Type == TokenType.InlineComment)
                        {
                            bool newLine;
                            if (peek.Type == TokenType.LineComment)
                            {
                                newLine = FormatOptions.NewLineBeforeLineComment;
                            }
                            else
                            {
                                newLine = FormatOptions.NewLineBeforeInlineComment;
                            }

                            tokenizer.GetToken();
                            if (newLine)
                            {
                                NewLine();
                            }
                            else
                            {
                                Builder.Append(' ');
                            }
                            Builder.Append(tokenizer.CurrentToken.Value);
                        }

                        endLine = true;
                    }
                    break;

                case TokenType.Comma:
                    Builder.Append(token.Value);
                    // Append newline if it looks like JSON syntax
                    if (token.PreviousType == TokenType.CloseBrace ||
                        (LineFlags.HasFlag(LineFlags.JsonColon) &&
                         ParenCount == 0 &&
                         BracketCount == 0 &&
                         Indents.Count > 0))
                    {
                        endLine = true;
                    }
                    break;

                case TokenType.Colon:
                    if (!LineFlags.HasFlag(LineFlags.CaseKeyword))
                    {
                        // Standard colon handling
                        if (!isLineStart &&
                            (LineFlags.HasFlag(LineFlags.QuestionMark) ||
                             token.PreviousType == TokenType.CloseBrace))
                        {
                            Builder.Append(' ');
                        }
                        Builder.Append(token.Value);
                        // May be JSON syntax
                        if (!LineFlags.HasFlag(LineFlags.QuestionMark))
                        {
                            LineFlags |= LineFlags.JsonColon;
                        }
                    }
                    else
                    {
                        // Special handling for case and default
                        Builder.Append(token.Value);
                        Indents.Indent(IndentFlags.CaseBlock);
                        endLine = true;
                    }
                    break;

                case TokenType.QuestionMark:
                    LineFlags |= LineFlags.QuestionMark;
                    if (!isLineStart)
                    {
                        Builder.Append(' ');
                    }
                    Builder.Append(token.Value);
                    break;

                case TokenType.BinaryOperator:
                case TokenType.UnaryPrefix:
                    if (!isLineStart &&
                        token.PreviousType != TokenType.OpenParen &&
                        token.PreviousType != TokenType.OpenBracket &&
                        token.PreviousType != TokenType.UnaryPrefix)
                    {
                        Builder.Append(' ');
                    }
                    Builder.Append(token.Value);
                    break;

                case TokenType.LineComment:
                    // Separate line comment from previous token
                    if (!isLineStart)
                    {
                        if (FormatOptions.NewLineBeforeLineComment)
                        {
                            NewLine();                  // Separate with new line
                        }
                        else
                        {
                            Builder.Append(' ');       // Separate with space
                        }
                    }
                    // Append comment
                    Builder.Append(token.Value);
                    // Line comment always followed by new line
                    endLine = true;
                    break;

                case TokenType.InlineComment:
                    // Separate line comment from previous token
                    if (!isLineStart)
                    {
                        if (FormatOptions.NewLineBeforeInlineComment)
                        {
                            NewLine();                  // Separate with new line
                        }
                        else
                        {
                            Builder.Append(' ');       // Separate with space
                        }
                    }
                    // Append comment
                    Builder.Append(token.Value);
                    // New line after comment
                    if (FormatOptions.NewLineAfterInlineComment)
                    {
                        endLine = true;
                    }
                    break;

                default:
                    Builder.Append(token.Value);
                    break;
                }
            }

            Builder.AppendLine();

            return(Builder.ToString());
        }
コード例 #23
0
            private void FormatLine(
                FullTextState           fullText,
                int                     cpFirst,
                int                     lineLength,
                int                     formatWidth,
                int                     finiteFormatWidth,
                int                     paragraphWidth,
                LineFlags               lineFlags,
                FormattedTextSymbols    collapsingSymbol
                )
            {
                _metrics._formatter = fullText.Formatter;
                Debug.Assert(_metrics._formatter != null);

                TextStore store = fullText.TextStore;
                TextStore markerStore = fullText.TextMarkerStore;
                FormatSettings settings = store.Settings;
                ParaProp pap = settings.Pap;

                _paragraphTextDecorations = pap.TextDecorations;
                if (_paragraphTextDecorations != null)
                {
                    if (_paragraphTextDecorations.Count != 0)
                    {
                        _defaultTextDecorationsBrush = pap.DefaultTextDecorationsBrush;
                    }
                    else
                    {
                        _paragraphTextDecorations = null;
                    }
                }

                // acquiring LS context
                TextFormatterContext context = _metrics._formatter.AcquireContext(fullText, IntPtr.Zero);

                LsLInfo plslineInfo = new LsLInfo();
                LsLineWidths lineWidths = new LsLineWidths();

                fullText.SetTabs(context);

                int lscpLineLength = 0; // line length in LSCP
                if (lineLength > 0)
                {
                    // line length is previously known (e.g. during optimal paragraph formatting),
                    // prefetch lsruns up to the specified line length.
                    lscpLineLength = PrefetchLSRuns(store, cpFirst, lineLength);
                }

                IntPtr ploline;
                LsErr lserr = context.CreateLine(
                    cpFirst,
                    lscpLineLength,
                    formatWidth,
                    lineFlags,
                    IntPtr.Zero,    // single-line formatting does not require break record
                    out ploline,
                    out plslineInfo,
                    out _depthQueryMax,
                    out lineWidths
                    );

                // Did we exceed the LineServices maximum line width?
                if (lserr == LsErr.TooLongParagraph)
                {
                    // Determine where to insert a fake line break. FullTextState.CpMeasured
                    // is a reasonable estimate since we know the nominal widths up to that
                    // point fit within the margin.
                    int cpLimit = fullText.CpMeasured;
                    int subtract = 1;

                    for (;;)
                    {
                        // The line must contain at least one character position.
                        if (cpLimit < 1)
                        {
                            cpLimit = 1;
                        }

                        store.InsertFakeLineBreak(cpLimit);

                        lserr = context.CreateLine(
                            cpFirst,
                            lscpLineLength,
                            formatWidth,
                            lineFlags,
                            IntPtr.Zero,    // single-line formatting does not require break record
                            out ploline,
                            out plslineInfo,
                            out _depthQueryMax,
                            out lineWidths
                            );

                        if (lserr != LsErr.TooLongParagraph || cpLimit == 1)
                        {
                            // We're done or can't chop off any more text.
                            break;
                        }
                        else
                        {
                            // Chop off more text and try again. Double the amount of
                            // text we chop off each time so we retry too many times.
                            cpLimit = fullText.CpMeasured - subtract;
                            subtract *= 2;
                        }
                    }
                }

                _ploline.Value = ploline;

                // get the exception in context before it is released
                Exception callbackException = context.CallbackException;

                // release the context
                context.Release();

                if(lserr != LsErr.None)
                {
                    GC.SuppressFinalize(this);
                    if(callbackException != null)
                    {
                        // rethrow exception thrown in callbacks
                        throw WrapException(callbackException);
                    }
                    else
                    {
                        // throw with LS error codes
                        TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.CreateLineFailure, lserr), lserr);
                    }
                }

                // keep context alive at least till here
                GC.KeepAlive(context);

                unsafe
                {
                    // construct text metrics for the line
                    _metrics.Compute(
                        fullText,
                        cpFirst,
                        paragraphWidth,
                        collapsingSymbol,
                        ref lineWidths,
                        &plslineInfo
                        );
                }

                // keep record for min width as we may be formatting min/max
                _textMinWidthAtTrailing = lineWidths.upMinStartTrailing - _metrics._textStart;

                if (collapsingSymbol != null)
                {
                    _collapsingSymbol = collapsingSymbol;
                    _textMinWidthAtTrailing += TextFormatterImp.RealToIdeal(collapsingSymbol.Width);
                }
                else
                {
                    // overflow detection for potential collapsible line
                    if (_metrics._textStart + _metrics._textWidthAtTrailing > finiteFormatWidth)
                    {
                        bool hasOverflowed = true;
                        if (_textFormattingMode == TextFormattingMode.Display)
                        {
                            // apply display-mode rounding before checking for overflow
                            double realWidth = Width;
                            double realFormatWidth = _metrics._formatter.IdealToReal(finiteFormatWidth);
                            hasOverflowed = (TextFormatterImp.CompareReal(realWidth, realFormatWidth, _textFormattingMode) > 0);
                        }

                        if (hasOverflowed)
                        {
                            // line has overflowed
                            _statusFlags |= StatusFlags.HasOverflowed;

                            // let's keep the full text state around. We'll need it later for collapsing
                            _fullText = fullText;
                        }
                    }
                }

                if (    fullText != null
                    &&  (   fullText.KeepState
                        ||  (_statusFlags & StatusFlags.KeepState) != 0
                        )
                    )
                {
                    // the state of full text is to be kept after formatting is done
                    _fullText = fullText;
                }

                // retain all line properties for interactive operations
                _ploc = context.Ploc;
                _cpFirst = cpFirst;
                _paragraphWidth = paragraphWidth;

                if (pap.RightToLeft)
                    _statusFlags |= StatusFlags.RightToLeft;

                if (plslineInfo.fForcedBreak != 0)
                    _statusFlags |= StatusFlags.IsTruncated;

                // retain the state of plsruns
                _plsrunVector = store.PlsrunVector;
                _lsrunsMainText = store.LsrunList;

                if (markerStore != null)
                    _lsrunsMarkerText = markerStore.LsrunList;

                // we store the text source in the line in case drawing code calls
                // the TextSource to find out the text effect index.
                // 
                _textSource = settings.TextSource;
            }
コード例 #24
0
            /// <summary>
            /// Constructing a FullTextLine
            /// </summary>
            /// <param name="settings">text formatting settings</param>
            /// <param name="cpFirst">Line's first cp</param>
            /// <param name="lineLength">character length of the line</param>
            /// <param name="paragraphWidth">paragraph width</param>
            /// <param name="lineFlags">line formatting control flags</param>
            internal FullTextLine(
                FormatSettings          settings,
                int                     cpFirst,
                int                     lineLength,
                int                     paragraphWidth,
                LineFlags               lineFlags
                )
                : this(settings.TextFormattingMode, settings.Pap.Justify)
            {
                if (    (lineFlags & LineFlags.KeepState) != 0
                    ||  settings.Pap.AlwaysCollapsible)
                {
                    _statusFlags |= StatusFlags.KeepState;
                }

                int finiteFormatWidth = settings.GetFiniteFormatWidth(paragraphWidth);

                FullTextState fullText = FullTextState.Create(settings, cpFirst, finiteFormatWidth);

                // formatting the line
                FormatLine(
                    fullText,
                    cpFirst,
                    lineLength,
                    fullText.FormatWidth,
                    finiteFormatWidth,
                    paragraphWidth,
                    lineFlags,
                    null    // collapsingSymbol
                    );
            }
コード例 #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Font"/> class with the specified
        /// parameters.
        /// </summary>
        /// <param name="fontFace">The font name identifier.</param>
        /// <param name="hscale">The width scale factor for the font.</param>
        /// <param name="vscale">The height scale factor for the font.</param>
        /// <param name="shear">
        /// Approximate tangent of the character slope relative to the vertical line. A value
        /// of 0 means a non-italic font, 1.0 means around 45 degrees of slope, and so on.
        /// </param>
        /// <param name="thickness">The thickness of the text strokes.</param>
        /// <param name="lineType">The algorithm used to draw the text strokes.</param>
        public Font(FontFace fontFace, double hscale, double vscale, double shear = 0, int thickness = 1, LineFlags lineType = LineFlags.Connected8)
            : base(true)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var pFont = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_CvFont)));
#pragma warning restore CS0618 // Type or member is obsolete
            NativeMethods.cvInitFont(pFont, fontFace, hscale, vscale, shear, thickness, lineType);
            SetHandle(pFont);
        }
コード例 #26
0
ファイル: Font.cs プロジェクト: highwayns/opencv.net
        /// <summary>
        /// Initializes a new instance of the <see cref="Font"/> class with the specified
        /// parameters.
        /// </summary>
        /// <param name="fontFace">The font name identifier.</param>
        /// <param name="hscale">The width scale factor for the font.</param>
        /// <param name="vscale">The height scale factor for the font.</param>
        /// <param name="shear">
        /// Approximate tangent of the character slope relative to the vertical line. A value
        /// of 0 means a non-italic font, 1.0 means around 45 degrees of slope, and so on.
        /// </param>
        /// <param name="thickness">The thickness of the text strokes.</param>
        /// <param name="lineType">The algorithm used to draw the text strokes.</param>
        public Font(FontFace fontFace, double hscale, double vscale, double shear = 0, int thickness = 1, LineFlags lineType = LineFlags.Connected8)
            : base(true)
        {
            var pFont = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_CvFont)));

            NativeMethods.cvInitFont(pFont, fontFace, hscale, vscale, shear, thickness, lineType);
            SetHandle(pFont);
        }
コード例 #27
0
ファイル: FullTextLine.cs プロジェクト: redmcg/wpf
            // For a given line length, return TextMetrics for as manu characters fit in the width
            private TextMetrics GetLineMetrics(
                FullTextState fullText,
                int cpFirst,
                int lineLength,
                int formatWidth,
                int finiteFormatWidth,
                int paragraphWidth,
                LineFlags lineFlags,
                FormattedTextSymbols collapsingSymbol
                )
            {
                TextMetrics result = new TextMetrics();

                result._formatter = fullText.Formatter;
                Debug.Assert(result._formatter != null);

                TextStore      store        = fullText.TextStore;
                FormatSettings settings     = store.Settings;
                ParaProp       pap          = settings.Pap;
                var            pixelsPerDip = settings.TextSource.PixelsPerDip;

                int pos             = cpFirst;
                int content_ascent  = 0;
                int content_descent = 0;

                while (lineLength <= 0 || cpFirst + lineLength > pos)
                {
                    TextRun textRun;
                    int     runLength;
                    CharacterBufferRange chars = settings.FetchTextRun(pos, cpFirst, out textRun, out runLength);

                    if (lineLength > 0 && pos + runLength > cpFirst + lineLength)
                    {
                        runLength = cpFirst + lineLength - pos;
                        chars     = new CharacterBufferRange(chars, 0, runLength);
                    }

                    if (textRun is TextEndOfParagraph || textRun is TextEndOfLine)
                    {
                        pos += runLength;
                        result._cchNewline = runLength;
                        break;
                    }

                    TextMetrics runMetrics = GetRunMetrics(fullText, textRun, chars);

                    if (content_ascent < runMetrics._textAscent)
                    {
                        content_ascent = runMetrics._textAscent;
                    }

                    if (content_descent < runMetrics._textHeight - runMetrics._textAscent)
                    {
                        content_descent = runMetrics._textHeight - runMetrics._textAscent;
                    }

                    result._textWidth += runMetrics._textWidth;

                    pos += runLength;
                }

                result._pixelsPerDip        = pixelsPerDip;
                result._cchLength           = pos - cpFirst;
                result._textWidthAtTrailing = result._textWidth;                 // will be set later by FormatLine

                if (pap.LineHeight > 0)
                {
                    // Host specifies line height, honor it.
                    result._height         = pap.LineHeight;
                    result._baselineOffset = (int)Math.Round(
                        result._height
                        * pap.DefaultTypeface.Baseline(pap.EmSize, Constants.DefaultIdealToReal, pixelsPerDip, _textFormattingMode)
                        / pap.DefaultTypeface.LineSpacing(pap.EmSize, Constants.DefaultIdealToReal, pixelsPerDip, _textFormattingMode)
                        );
                }

                if (content_ascent > 0)
                {
                    result._textAscent = content_ascent;
                    result._textHeight = content_ascent + content_descent;

                    // TODO: VerticalAdjust
                }
                else
                {
                    // Line is empty so text height and text baseline are based on the default typeface;
                    // it doesn't make sense even for an emtpy line to have zero text height
                    result._textAscent = (int)Math.Round(pap.DefaultTypeface.Baseline(pap.EmSize, Constants.DefaultIdealToReal, pixelsPerDip, _textFormattingMode));
                    result._textHeight = (int)Math.Round(pap.DefaultTypeface.LineSpacing(pap.EmSize, Constants.DefaultIdealToReal, pixelsPerDip, _textFormattingMode));
                }

                if (result._height <= 0)
                {
                    result._height         = result._textHeight;
                    result._baselineOffset = result._textAscent;
                }

                return(result);
            }
コード例 #28
0
ファイル: FullTextLine.cs プロジェクト: redmcg/wpf
            /// <summary>
            /// format text line using LS
            /// </summary>
            /// <param name="fullText">state of the full text backing store</param>
            /// <param name="cpFirst">first cp to format</param>
            /// <param name="lineLength">character length of the line</param>
            /// <param name="formatWidth">width used to format</param>
            /// <param name="finiteFormatWidth">width used to detect overflowing of format result</param>
            /// <param name="paragraphWidth">paragraph width</param>
            /// <param name="lineFlags">line formatting control flags</param>
            /// <param name="collapsingSymbol">line end collapsing symbol</param>
            private void FormatLine(
                FullTextState fullText,
                int cpFirst,
                int lineLength,
                int formatWidth,
                int finiteFormatWidth,
                int paragraphWidth,
                LineFlags lineFlags,
                FormattedTextSymbols collapsingSymbol
                )
            {
                _fullText       = fullText;
                _paragraphWidth = paragraphWidth;

                TextStore      store    = fullText.TextStore;
                FormatSettings settings = store.Settings;
                ParaProp       pap      = settings.Pap;

                _paragraphTextDecorations = pap.TextDecorations;
                if (_paragraphTextDecorations != null)
                {
                    if (_paragraphTextDecorations.Count != 0)
                    {
                        _defaultTextDecorationsBrush = pap.DefaultTextDecorationsBrush;
                    }
                    else
                    {
                        _paragraphTextDecorations = null;
                    }
                }

                _metrics = GetLineMetrics(fullText, cpFirst, lineLength, formatWidth, finiteFormatWidth, paragraphWidth, lineFlags, collapsingSymbol);

                lineLength = _metrics._cchLength;
                if (lineLength > _metrics._cchNewline)
                {
                    var lineBreakpoints = store.FindLineBreakpoints(cpFirst, lineLength);

                    // check for line wrap
                    if (pap.Wrap && _metrics._textStart + _metrics._textWidthAtTrailing > finiteFormatWidth)
                    {
                        for (int i = lineLength - 1; i > 0; i--)
                        {
                            if (lineBreakpoints.GetBreakConditionBefore(i + cpFirst) == DWriteBreakCondition.CanBreak)
                            {
                                var trailingWhitespace = lineBreakpoints.WhitespaceLengthBefore(i + cpFirst);
                                var trimmedMetrics     = GetLineMetrics(fullText, cpFirst, i - trailingWhitespace, formatWidth, finiteFormatWidth, paragraphWidth, lineFlags, collapsingSymbol);
                                if (trimmedMetrics._textStart + trimmedMetrics._textWidthAtTrailing <= finiteFormatWidth)
                                {
                                    _metrics = GetLineMetrics(fullText, cpFirst, i, formatWidth, finiteFormatWidth, paragraphWidth, lineFlags, collapsingSymbol);
                                    _metrics._cchTrailing         = trailingWhitespace;
                                    _metrics._textWidthAtTrailing = trimmedMetrics._textWidth;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (collapsingSymbol == null)
                {
                    // overflow detection for potential collapsible line
                    if (_metrics._textStart + _metrics._textWidthAtTrailing > finiteFormatWidth)
                    {
                        bool hasOverflowed = true;
                        if (_textFormattingMode == TextFormattingMode.Display)
                        {
                            // apply display-mode rounding before checking for overflow
                            double realWidth       = Width;
                            double realFormatWidth = _metrics._formatter.IdealToReal(finiteFormatWidth, PixelsPerDip);
                            hasOverflowed = (TextFormatterImp.CompareReal(realWidth, realFormatWidth, PixelsPerDip, _textFormattingMode) > 0);
                        }

                        if (hasOverflowed)
                        {
                            // line has overflowed
                            _statusFlags |= StatusFlags.HasOverflowed;
                        }
                    }
                }
            }