Compartilhar via


Método IXpsOMGeometryFigure::SetSegments (xpsobjectmodel.h)

Define as informações do segmento e os pontos de dados para segmentos na figura.

Sintaxe

HRESULT SetSegments(
  [in] UINT32                 segmentCount,
  [in] UINT32                 segmentDataCount,
  [in] const XPS_SEGMENT_TYPE *segmentTypes,
  [in] const FLOAT            *segmentData,
  [in] const BOOL             *segmentStrokes
);

Parâmetros

[in] segmentCount

O número de segmentos.

Esse valor também é o número de elementos nas matrizes referenciadas por segmentTypes e segmentStrokes.

[in] segmentDataCount

O número de pontos de dados do segmento.

Esse valor também é o número de elementos na matriz referenciada por segmentData.

[in] segmentTypes

Uma matriz de variáveis XPS_SEGMENT_TYPE . O valor de segmentCount especifica o número de elementos nessa matriz.

[in] segmentData

Uma matriz de valores de dados de segmento. O valor de segmentDataCount especifica o número de elementos nessa matriz.

[in] segmentStrokes

Uma matriz de valores de traço de segmento. O valor de segmentCount especifica o número de elementos nessa matriz.

Retornar valor

O método retorna um HRESULT. Os valores possíveis incluem, mas não se limitam a, aqueles na tabela a seguir. Para obter informações sobre valores retornados da API de documento XPS que não estão listados nesta tabela, consulte Erros de documento XPS.

Código de retorno Descrição
S_OK
O método foi bem-sucedido.
E_INVALIDARG
segmentTypes contém um valor de tipo não reconhecido.

Como alternativa, o número de entradas na matriz segmentData é maior que o número de entradas na matriz segmentTypes .

E_POINTER
segmentTypes, segmentData ou segmentStrokes é NULL.
XPS_E_INVALID_FLOAT
segmentData contém um valor FLOAT que é infinito ou não é um NÚMERO (NAN).
XPS_E_MISSING_SEGMENT_DATA
A matriz passada em segmentData tem menos entradas do que a matriz passada em segmentTypes.
XPS_E_NEGATIVE_FLOAT
Uma entrada na matriz que é passada em segmentData contém um valor negativo, mas deve conter um valor não negativo.

Comentários

Um segmento de geometria é descrito pelo ponto inicial, pelo tipo de segmento e por parâmetros adicionais cujos valores são determinados pelo tipo de segmento. As coordenadas para o ponto inicial do primeiro segmento são uma propriedade da figura de geometria e são definidas chamando SetStartPoint. O ponto inicial de cada segmento subsequente é o ponto final do segmento anterior.

O número de valores de dados que definem um segmento de linha depende do tipo de segmento. A tabela a seguir descreve o conjunto específico de valores de dados necessários que devem ser usados para cada tipo de segmento. Os valores na matriz de dados do segmento que é passado no parâmetro segmentData devem corresponder aos valores XPS_SEGMENT_TYPE na matriz que é passada no parâmetro segmentTypes . Por exemplo, se o primeiro segmento de linha tiver um valor de tipo de segmento de XPS_SEGMENT_TYPE_LINE, os dois primeiros valores de dados na matriz segmentData serão as coordenadas x e y do ponto final desse segmento; se o próximo segmento tiver um valor de tipo de segmento de XPS_SEGMENT_TYPE_BEZIER, os próximos seis valores na matriz segmentData descreverão as características desse segmento; e assim por diante para cada segmento de linha na figura de geometria.

Tipo de segmento Valores de dados necessários
XPS_SEGMENT_TYPE_LINE Um diagrama que mostra um exemplo de um segmento de figura XPS_SEGMENT_TYPE_LINE Dois valores de dados:
coordenada x do ponto de extremidade da linha de segmento.
coordenada y do ponto de extremidade da linha de segmento.
XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE Diagrama de um segmento de figura XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE. Cinco valores de dados:
coordenada x do ponto final do arco.
coordenada y do ponto final do arco.
Comprimento do raio da elipse ao longo do eixo x.
Comprimento do raio da elipse ao longo do eixo y.
Ângulo de rotação.
XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE Um diagrama que mostra um exemplo de um segmento de figura XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE Cinco valores de dados:
coordenada x do ponto final do arco.
coordenada y do ponto final do arco.
Comprimento do raio da elipse ao longo do eixo x.
Comprimento do raio da elipse ao longo do eixo y.
Ângulo de rotação.
XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE Diagrama de um segmento de figura XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE. Cinco valores de dados:
coordenada x do ponto final do arco.
coordenada y do ponto final do arco.
Comprimento do raio da elipse ao longo do eixo x.
Comprimento do raio da elipse ao longo do eixo y.
Ângulo de rotação.
XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE Um diagrama que mostra um exemplo de um segmento de figura XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE Cinco valores de dados:
coordenada x do ponto final do arco.
coordenada y do ponto final do arco.
Comprimento do raio da elipse ao longo do eixo x.
Comprimento do raio da elipse ao longo do eixo y.
Ângulo de rotação.
XPS_SEGMENT_TYPE_BEZIER Um diagrama que mostra um exemplo de um segmento de figura XPS_SEGMENT_TYPE_BEZIER Seis valores de dados:
coordenada x do primeiro ponto de controle da curva de Bezier.
coordenada y do primeiro ponto de controle da curva de Bezier.
coordenada x do segundo ponto de controle da curva de Bezier.
coordenada y do segundo ponto de controle da curva de Bezier.
coordenada x do ponto final da curva de Bezier.
coordenada y do ponto final da curva de Bézier.
XPS_SEGMENT_TYPE_QUADRATIC_BEZIER Um diagrama que mostra um exemplo de um segmento de figura XPS_SEGMENT_TYPE_QUADRATIC_BEZIER Quatro valores de dados:
coordenada x do ponto de controle da curva Quad Bezier.
Coordenada y do ponto de controle da curva Quad Bezier.
coordenada x do ponto final da curva Quad Bezier.
Coordenada y do ponto final da curva Quad Bezier.
 

Para obter os tipos de segmento na figura, chame GetSegmentTypes.

Os exemplos de código a seguir demonstram uma maneira de criar e preencher os buffers exigidos por SetSegments.

No primeiro exemplo de código, o método AddSegmentDataToArrays usa os pontos de dados que descrevem um único segmento e os armazena nos três buffers de dados diferentes exigidos pelo método SetSegments . Os buffers de dados que são passados como argumentos para AddSegmentDataToArrays são gerenciados pelo método de chamada, conforme mostrado no exemplo de código que segue AddSegmentDataToArrays.

HRESULT
AddSegmentDataToArrays(
    XPS_SEGMENT_TYPE        segmentType,
    BOOL                    segmentStroke,
    FLOAT                   *segmentPoints,
    UINT32                  *segmentsAvailable,
    UINT32                  *segmentPointsAvailable,
    XPS_SEGMENT_TYPE        **segmentTypeBuffer,
    BOOL                    **segmentStrokeBuffer,
    FLOAT                   **segmentPointBuffer
)
/*
Description:

Populates the buffers required by IXpsOMGeometryFigure::SetSegmentData
using data and buffers provided by the calling method.

Parameters:

segmentType
    IN: XPS_SEGMENT_TYPE value that specifies the segment type for
        the current segment.

segmentStroke
    IN: BOOL value that specifies whether the current segment 
        is stroked.

*segmentPoints
    IN: pointer to an array of FLOAT values that specify the 
        segment's data points. The number of values in the array
        depend on the value of the segmentType parameter.

*segmentsAvailable
    IN: the number of values that remain unused in the
        segmentTypeBuffer and the segmentStrokeBuffer.
        This value must be >= 1 when calling the method.
    OUT:  the number of values that remain unused in the
        segmentTypeBuffer and the segmentStrokeBuffer after
        segmentType and segmentStroke have been added. If the 
        method was successful, the returned value is one less 
        than the value passed in to the method.

*segmentPointsAvailable
    IN: the number of values that remain unused in the
        segmentPointBuffer.    This value must be greater-than or equal
        to the number of points required by the segmentType value.
    OUT:  the number of values that remain unused in the
        segmentPointBuffer after the segmentPoints have been added.
        The returned value depends on the segmentType value.

**segmentTypeBuffer
    IN: the first free element in the buffer that receives the segment
        type values.
    OUT: the first free element in the buffer that receives the segment
        type values. If the method is successful, this will be the element
        after the element pointed to by this value before the method 
        was called.

**segmentStrokeBuffer
    IN: the first free element in the buffer that receives the segment
        stroke values.
    OUT: the first free element in the buffer that receives the segment
        stroke values. If the method is successful, this will be the element
        after the element pointed to by this value before the method 
        was called.

**segmentPointBuffer
    IN: the first free element in the buffer that receives the segment
        point values.
    OUT: the first free element in the buffer that receives the segment
        point values. If the method is successful, the element referenced
        by this value will depend on the segment type.

Remarks.
1) the buffers and values passed into this method are managed by
    the calling method.

2) if the value returned in segmentsAvailable is 0, segmentTypeBuffer
    and segmentStrokeBuffer point to invalid memory.

3) if the value returned in segmentPointsAvailable is 0, segmentPointBuffer
    point to invalid memory.

*/
{
    HRESULT hr = S_OK;

    // test to see if there is sufficient space in the 
    // segmentTypeBuffer and the segmentStrokeBuffer before
    // proceeding
    if (*segmentsAvailable == 0)
    {
        hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
    }

    if (SUCCEEDED(hr))
    {
        // process the data based on the segment type
        switch (segmentType) 
        {
            case    XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE:
            case    XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE:
            case    XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE:
            case    XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE:
                if (*segmentPointsAvailable >= 5) 
                {
                    // 5 data points
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<arc end point (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<arc end point (y)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<arc radius (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<arc radius (y)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<arc angle
                    *segmentPointsAvailable -= 5;
                }
                else
                {
                    hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
                }
                break;
            case    XPS_SEGMENT_TYPE_BEZIER:
                if (*segmentPointsAvailable >= 6) 
                {
                    // 6 data points
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 1 (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 1 (y)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 2 (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 2 (y)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (y)
                    *segmentPointsAvailable -= 6;
                }
                else
                {
                    hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
                }
                break;
            case    XPS_SEGMENT_TYPE_LINE:
                if (*segmentPointsAvailable >= 2) 
                {
                    // 2 data points
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (y)
                    *segmentPointsAvailable -= 2;
                }
                else
                {
                    hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
                }
                break;
            case    XPS_SEGMENT_TYPE_QUADRATIC_BEZIER:
                if (*segmentPointsAvailable >= 4) 
                {
                    // 4 data points
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 2 (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<control point 2 (y)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (x)
                    *(*segmentPointBuffer)++ = *segmentPoints++; //<end point (y)
                    *segmentPointsAvailable -= 4;
                }
                else
                {
                    hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
                }
                break;
            default:
                // unrecognized segment type
                hr = E_UNEXPECTED;
                break;
        }

    }

    if (SUCCEEDED(hr))
    {
        // Copy segment type and segment stroke values
        // to array and decrement number of array values
        // that remain unused.
        //
        // The space available for these operations was
        // tested at the beginning of the method.
        *(*segmentTypeBuffer)++ = segmentType;
        *(*segmentStrokeBuffer)++ = segmentStroke;
        *segmentsAvailable--;
    } 

    return hr;
}

Neste exemplo de código, UpdateSegmentData cria os buffers de dados exigidos pelo método SetSegments e chama o método AddSegmentDataToArrays do exemplo de código anterior para preenchê-los com os dados do segmento. Depois que os buffers forem preenchidos, SetSegments será chamado para adicionar esses dados à figura de geometria.

Nota Os dados reais do segmento não são mostrados nesses exemplos de código.

 
HRESULT
UpdateSegmentData (
    IXpsOMGeometryFigure    *geometryFigure,
    UINT32                  segmentCount,
    UINT32                  segmentDataCount
)
/*
    Note that this method is not complete and only includes
    the code necessary to show how the SetSegments call is used.

    In this sample, the geometryFigure, segmentCount, and
    segmentDataCount values are assumed to have been initialized
    outside of this example.
*/
{
    HRESULT             hr = S_OK;
    XPS_SEGMENT_TYPE    segmentType = (XPS_SEGMENT_TYPE)0;
    BOOL                segmentStroke = FALSE;
    FLOAT               segmentPoints = 0;
    UINT32              segmentsAvailable = 0;
    UINT32              segmentPointsAvailable = 0;
    // these buffers are sized and allocated based on 
    //    the segment data to store.
    XPS_SEGMENT_TYPE    *segmentTypeBuffer = NULL;
    BOOL                *segmentStrokeBuffer = NULL;
    FLOAT               *segmentPointBuffer = NULL;

    XPS_SEGMENT_TYPE    *nextSegmentTypeValue = NULL;
    BOOL                *nextSegmentStrokeValue = NULL;
    FLOAT               *nextSegmentPointValue = NULL;

    // segment data is created outside of this example

    // allocate buffers as required using information 
    // from segment data. This can be dynamic or static
    // depending on how the segment information is managed.
    // This example assumes that the segment information 
    // does not change during this method.

    // initialize "next" pointers to point to the first
    // element in each array.
    nextSegmentTypeValue = segmentTypeBuffer;
    nextSegmentStrokeValue = segmentStrokeBuffer;
    nextSegmentPointValue = segmentPointBuffer;

    // for each segment in the figure, add the 
    // segment data to the buffers

        hr = AddSegmentDataToArrays(
                segmentType,
                segmentStroke,
                &segmentPoints,
                &segmentsAvailable,
                &segmentPointsAvailable,
                &nextSegmentTypeValue,
                &nextSegmentStrokeValue,
                &nextSegmentPointValue);
        
    if (SUCCEEDED(hr))
    {
        // set segment data
        hr = geometryFigure->SetSegments (
            segmentCount,
            segmentDataCount,
            segmentTypeBuffer,
            segmentPointBuffer,
            segmentStrokeBuffer);
    }
    // clean up buffers

    return hr;
}

Requisitos

Requisito Valor
Cliente mínimo com suporte Windows 7, Windows Vista com SP2 e Atualização de Plataforma para Windows Vista [aplicativos da área de trabalho | Aplicativos UWP]
Servidor mínimo com suporte Windows Server 2008 R2, Windows Server 2008 com SP2 e Platform Update para Windows Server 2008 [aplicativos da área de trabalho | Aplicativos UWP]
Plataforma de Destino Windows
Cabeçalho xpsobjectmodel.h

Confira também

GetSegmentTypes

IXpsOMGeometryFigure

Especificação de Papel XML

Erros de documento XPS

XPS_SEGMENT_TYPE