Método Graphics::MeasureCharacterRanges (gdiplusgraphics.h)

O método Graphics::MeasureCharacterRanges obtém um conjunto de regiões cada uma das quais vincula um intervalo de posições de caractere dentro de uma cadeia de caracteres.

Sintaxe

Status MeasureCharacterRanges(
  [in]      const WCHAR        *string,
  [in]      INT                length,
  [in]      const Font         *font,
  [in, ref] const RectF &      layoutRect,
  [in]      const StringFormat *stringFormat,
  [in]      INT                regionCount,
  [out]     Region             *regions
);

Parâmetros

[in] string

Tipo: const WCHAR*

Ponteiro para uma cadeia de caracteres largos.

Importante Para idiomas bidirecionais, como árabe, o comprimento da cadeia de caracteres não deve exceder 2046 caracteres.
 

[in] length

Tipo: INT

Inteiro que especifica o número de caracteres na matriz de cadeia de caracteres . Se o parâmetro de cadeia de caracteres apontar para uma cadeia de caracteres terminada em NULL, esse parâmetro poderá ser definido como –1.

[in] font

Tipo: const Font*

Ponteiro para um objeto Font que especifica as características da fonte (o nome da família, o tamanho e o estilo da fonte) a serem aplicadas à cadeia de caracteres.

[in, ref] layoutRect

Tipo: const Rectf

Referência a um retângulo que vincula a cadeia de caracteres.

[in] stringFormat

Tipo: const StringFormat*

Ponteiro para um objeto StringFormat que especifica os intervalos de caracteres e informações de layout, como alinhamento, corte, paradas de tabulação e assim por diante.

[in] regionCount

Tipo: INT

Inteiro que especifica o número de regiões que devem ser recebidas na matriz de regiões . Esse número deve ser igual ao número de intervalos de caracteres atualmente no objeto StringFormat .

[out] regions

Tipo: Região*

Ponteiro para uma matriz de objetos Region que recebe as regiões, cada uma delas vincula um intervalo de texto.

Valor retornado

Tipo: Status

Se o método for bem-sucedido, ele retornará Ok, que é um elemento da enumeração Status .

Se o método falhar, ele retornará um dos outros elementos da enumeração Status .

Comentários

Um intervalo de caracteres é um intervalo de posições de caractere dentro de uma cadeia de caracteres de texto. A área da exibição ocupada por um grupo de caracteres especificados pelo intervalo de caracteres é a região delimitador. Um intervalo de caracteres é definido por SetMeasurableCharacterRanges. O número de intervalos definidos no momento pode ser determinado chamando GetMeasurableCharacterRangeCount. Esse número também é o número de regiões que devem ser obtidas pelo método MeasureCharacterRanges .

Exemplos

O exemplo a seguir define três intervalos de posições de caractere dentro de uma cadeia de caracteres e define esses intervalos em um objeto StringFormat . Em seguida, o método MeasureCharacterRanges é usado para obter as três regiões da exibição ocupadas pelos caracteres especificados pelos intervalos. Isso é feito para três retângulos de layout diferentes para mostrar como as regiões mudam de acordo com o layout da cadeia de caracteres. Além disso, na terceira repetição disso, os sinalizadores de formato de cadeia de caracteres são alterados para que as regiões medidas incluam espaços à direita.

VOID MeasureCharRanges(HDC hdc)
{
   Graphics graphics(hdc);

   // Brushes and pens used for drawing and painting
   SolidBrush blueBrush(Color(255, 0, 0, 255));
   SolidBrush redBrush(Color(100, 255, 0, 0));
   Pen        blackPen(Color(255, 0, 0, 0));

   // Layout rectangles used for drawing strings
   RectF   layoutRect_A(20.0f, 20.0f, 130.0f, 130.0f);
   RectF   layoutRect_B(160.0f, 20.0f, 165.0f, 130.0f);
   RectF   layoutRect_C(335.0f, 20.0f, 165.0f, 130.0f);

   // Three different ranges of character positions within the string
   CharacterRange charRanges[3] = { CharacterRange(3, 5),
                                    CharacterRange(15, 2),
                                    CharacterRange(30, 15), };

   // Font and string format to apply to string when drawing
   Font         myFont(L"Times New Roman", 16.0f);
   StringFormat strFormat;

    // Other variables
   Region* pCharRangeRegions; // pointer to CharacterRange regions
   short   i;                 // loop counter
   INT     count;             // number of character ranges set
   WCHAR   string[] = L"The quick, brown fox easily jumps over the lazy dog.";


   // Set three ranges of character positions.
   strFormat.SetMeasurableCharacterRanges(3, charRanges);

   // Get the number of ranges that have been set, and allocate memory to 
   // store the regions that correspond to the ranges.
   count = strFormat.GetMeasurableCharacterRangeCount();
   pCharRangeRegions = new Region[count];

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle A is used. Then draw the string, and show the regions.
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_A, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_A, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_A);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle B is used. Then draw the string, and show the regions.
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_B, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_B, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_B);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }

   // Get the regions that correspond to the ranges within the string when
   // layout rectangle C is used. Set trailing spaces to be included in the
   // regions. Then draw the string, and show the regions.
   strFormat.SetFormatFlags(StringFormatFlagsMeasureTrailingSpaces);
   graphics.MeasureCharacterRanges(string, -1,
      &myFont, layoutRect_C, &strFormat, count, pCharRangeRegions);
   graphics.DrawString(string, -1,
      &myFont, layoutRect_C, &strFormat, &blueBrush);
   graphics.DrawRectangle(&blackPen, layoutRect_C);
   for ( i = 0; i < count; i++)
   {
      graphics.FillRegion(&redBrush, pCharRangeRegions + i);
   }
   // Delete memory for the range regions.
   delete [] pCharRangeRegions;
}

Requisitos

   
Cliente mínimo com suporte Windows XP, Windows 2000 Professional [somente aplicativos da área de trabalho]
Servidor mínimo com suporte Windows 2000 Server [somente aplicativos da área de trabalho]
Plataforma de Destino Windows
Cabeçalho gdiplusgraphics.h (inclua Gdiplus.h)
Biblioteca Gdiplus.lib
DLL Gdiplus.dll

Confira também

Characterrange

GetMeasurableCharacterRangeCount

Elementos gráficos

SetMeasurableCharacterRanges