共用方式為


IXpsOMGeometryFigure::SetSegments 方法 (xpsobjectmodel.h)

設定圖中區段的區段資訊和數據點。

語法

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

參數

[in] segmentCount

區段數目。

這個值也是 segmentTypes 和 segmentStrokes 所參考之陣列中的元素數目。

[in] segmentDataCount

區段數據點的數目。

這個值也是 segmentData 所參考之陣列中的元素數目。

[in] segmentTypes

XPS_SEGMENT_TYPE變數的陣列。 segmentCount 的值會指定此陣列中的項目數目。

[in] segmentData

區段數據值的陣列。 segmentDataCount 的值會指定此陣列中的元素數目。

[in] segmentStrokes

區段筆劃值的陣列。 segmentCount 的值會指定此陣列中的項目數目。

傳回值

方法會傳回 HRESULT。 可能的值包括但不限於下列數據表中的值。 如需此表格中未列出的 XPS 檔 API 傳回值的相關信息,請參閱 XPS 檔錯誤

傳回碼 描述
S_OK
此方法已成功。
E_INVALIDARG
segmentTypes 包含無法辨識類型的值。

或者, segmentData 陣列中的項目數目大於 segmentTypes 陣列中的項目數。

E_POINTER
segmentTypessegmentDatasegmentStrokesNULL
XPS_E_INVALID_FLOAT
segmentData 包含 FLOAT 值,其為無限或不是 (NAN) 的數位。
XPS_E_MISSING_SEGMENT_DATA
segmentData 中傳遞的陣列專案比在 segmentTypes 中傳遞的陣列少。
XPS_E_NEGATIVE_FLOAT
segmentData 中傳遞之陣列中的專案包含負值,但必須包含非負值。

備註

幾何區段是由起點、區段類型,以及值由區段類型決定的其他參數所描述。 第一個線段起點的座標是幾何圖的屬性,而且是藉由呼叫 SetStartPoint 來設定。 每個後續區段的起點都是前一個區段的終點。

定義線條線段的數據值數目取決於線段類型。 下表描述每個區段類型必須使用的特定必要數據值集。 在 segmentData 參數中傳遞的區段數據陣列中的值必須與 segmentTypes 參數中傳遞之數位中的XPS_SEGMENT_TYPE值相對應。 例如,如果第一條線段的線段類型值為 XPS_SEGMENT_TYPE_LINE,segmentData 陣列中的前兩個數據值將會是該線段終點的 x 和 y 座標;如果下一個區段的區段類型值為 XPS_SEGMENT_TYPE_BEZIER,segmentData 陣列中的下六個值將會描述該區段的特性;幾何圖中每一條線段的等等。

區段類型 必要的數據值
XPS_SEGMENT_TYPE_LINE 顯示XPS_SEGMENT_TYPE_LINE圖區段範例的圖表 兩個資料值:
線段終點的 X 座標。
線段終點的 Y 座標。
XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE 圖表XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE圖區段。 五個資料值:
弧線終點的 X 座標。
弧線終點的 Y 座標。
沿著 X 軸的橢圓形半徑長度。
沿著 y 軸的橢圓形半徑長度。
旋轉角度。
XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE 顯示XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE圖區段範例的圖表 五個資料值:
弧線終點的 X 座標。
弧線終點的 Y 座標。
沿著 X 軸的橢圓形半徑長度。
沿著 y 軸的橢圓形半徑長度。
旋轉角度。
XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE 圖表XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE圖區段。 五個資料值:
弧線終點的 X 座標。
弧線終點的 Y 座標。
沿著 X 軸的橢圓形半徑長度。
沿著 y 軸的橢圓形半徑長度。
旋轉角度。
XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE 顯示XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE圖區段範例的圖表 五個資料值:
弧線終點的 X 座標。
弧線終點的 Y 座標。
沿著 X 軸的橢圓形半徑長度。
沿著 y 軸的橢圓形半徑長度。
旋轉角度。
XPS_SEGMENT_TYPE_BEZIER 顯示圖表區段XPS_SEGMENT_TYPE_BEZIER範例的圖表 六個資料值:
Bezier 曲線第一個控制點的 X 座標。
Bezier 曲線第一個控制點的 Y 座標。
Bezier 曲線第二個控制點的 X 座標。
Bezier 曲線第二個控制點的 Y 座標。
Bezier 曲線終點的 X 座標。
Bezier 曲線終點的 Y 座標。
XPS_SEGMENT_TYPE_QUADRATIC_BEZIER 顯示XPS_SEGMENT_TYPE_QUADRATIC_BEZIER圖區段範例的圖表 四個資料值:
四邊形 Bezier 曲線控制點的 X 座標。
四邊形 Bezier 曲線控制點的 Y 座標。
四邊形 Bezier 曲線終點的 X 座標。
四邊形 Bezier 曲線終點的 Y 座標。
 

若要取得圖中的區段類型,請呼叫 GetSegmentTypes

下列程式代碼範例示範如何建立和填入 SetSegments 所需的緩衝區。

在第一個程式代碼範例中, AddSegmentDataToArrays 方法會採用描述單一區段的數據點,並將其儲存在 SetSegments 方法所需的三個不同的數據緩衝區中。 當做自變數傳遞至 AddSegmentDataToArrays 的數據緩衝區是由呼叫方法管理,如 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;
}

在此程式代碼範例中, UpdateSegmentData 會建立 SetSegments 方法所需的數據緩衝區,並從上述程式代碼範例呼叫 AddSegmentDataToArrays 方法,以填入區段數據。 填入緩衝區之後,會呼叫 SetSegments ,將此數據新增至幾何圖。

注意 這些程式代碼範例不會顯示實際的區段數據。

 
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;
}

規格需求

需求
最低支援的用戶端 適用於 Windows Vista 的 Windows 7、Windows Vista SP2 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 xpsobjectmodel.h

另請參閱

GetSegmentTypes

IXpsOMGeometryFigure

XML Paper Specification

XPS 檔案錯誤

XPS_SEGMENT_TYPE