Condividi tramite


Colorizer.ColorizeLine Method

Obtains color and font attribute information for each character in the specified line of text.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)

Syntax

'Dichiarazione
Public Overridable Function ColorizeLine ( _
    line As Integer, _
    length As Integer, _
    ptr As IntPtr, _
    state As Integer, _
    attrs As UInteger() _
) As Integer
'Utilizzo
Dim instance As Colorizer
Dim line As Integer
Dim length As Integer
Dim ptr As IntPtr
Dim state As Integer
Dim attrs As UInteger()
Dim returnValue As Integer

returnValue = instance.ColorizeLine(line, _
    length, ptr, state, attrs)
public virtual int ColorizeLine(
    int line,
    int length,
    IntPtr ptr,
    int state,
    uint[] attrs
)
public:
virtual int ColorizeLine(
    int line, 
    int length, 
    IntPtr ptr, 
    int state, 
    array<unsigned int>^ attrs
)
abstract ColorizeLine : 
        line:int * 
        length:int * 
        ptr:IntPtr * 
        state:int * 
        attrs:uint32[] -> int 
override ColorizeLine : 
        line:int * 
        length:int * 
        ptr:IntPtr * 
        state:int * 
        attrs:uint32[] -> int 
public function ColorizeLine(
    line : int, 
    length : int, 
    ptr : IntPtr, 
    state : int, 
    attrs : uint[]
) : int

Parameters

  • line
    Type: System.Int32
    [in] The line number from which the line of text came from.
  • length
    Type: System.Int32
    [in] The number of characters in the given text.
  • ptr
    Type: System.IntPtr
    [in] An unmarshaled pointer to a line of text.
  • state
    Type: System.Int32
    [in] The current state as maintained by the parser.

Return Value

Type: System.Int32
Returns the updated state value.

Implements

IVsColorizer.ColorizeLine(Int32, Int32, IntPtr, Int32, array<UInt32[])

Remarks

This method parses the line and supplies for each character an index into the ColorableItem list as provided by the language service (through GetColorableItem). Typically, this method calls the IScanner object to parse the line into tokens and return a colorable item index for each token.

This method is an implementation of ColorizeLine.

The base method processes the entire line one token at a time by calling the scanner's ScanTokenAndProvideInfoAboutIt method until the line is exhausted and fills in the attrs array for each token using the returned TokenInfo structure for the color information.

Examples

The following is how the managed package framework version of the Colorizer class implements this method. Note the process of marshaling the text to a string.

namespace Microsoft.VisualStudio.Package
{
    public class Colorizer : IVsColorizer
{
        IScanner scanner;

        public virtual int ColorizeLine(int line,
                                        int length,
                                        IntPtr ptr,
                                        int state,
                                        uint[] attrs)
        {
            int linepos = 0;
            if (this.scanner != null) {
                try
                {
                    string text = Marshal.PtrToStringUni(ptr, length);

                    this.scanner.SetSource(text, 0);

                    TokenInfo tokenInfo = new TokenInfo();

                    tokenInfo.EndIndex = -1;

                    while (this.scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
                    {
                        if (attrs != null)
                        {
                            for (; linepos < tokenInfo.StartIndex; linepos++)
                                attrs[linepos] = (uint)TokenColor.Text;

                            for (; linepos <= tokenInfo.EndIndex; linepos++)
                                attrs[linepos] = (uint)tokenInfo.Color;
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignore exceptions
                }
            }
            if (attrs != null)
            {
                // Must initialize the colors in all cases, otherwise you get 
                // random color junk on the screen.
                for (; linepos < length; linepos++)
                    attrs[linepos] = (uint)TokenColor.Text;
            }
            return state;
        }
    }
}

.NET Framework Security

See Also

Reference

Colorizer Class

Colorizer Members

Microsoft.VisualStudio.Package Namespace