Metodo IXpsOMGeometryFigure::GetSegmentData (xpsobjectmodel.h)
Ottiene i punti dati del segmento per la figura geometry.
Sintassi
HRESULT GetSegmentData(
[in, out] UINT32 *dataCount,
[in, out] FLOAT *segmentData
);
Parametri
[in, out] dataCount
Dimensioni della matrice a cui fa riferimento il parametro segmentData .
Se il metodo restituisce correttamente, dataCount conterrà il numero di elementi restituiti nella matrice a cui fa riferimento segmentData.
Se segmentData è impostato su NULL quando viene chiamato il metodo, dataCount deve essere impostato su zero.
Se viene restituito un puntatore NULL in segmentData, dataCount conterrà le dimensioni del buffer necessarie come numero di elementi.
[in, out] segmentData
Indirizzo di una matrice con lo stesso numero di elementi specificati in dataCount. Questo valore può essere impostato su NULL se il chiamante richiede che il metodo restituisca solo le dimensioni del buffer necessarie in dataCount.
Se la matrice è abbastanza grande, questo metodo copia i punti dati del segmento nella matrice e restituisce, in dataCount, il numero di punti dati copiati. Se segmentData è impostato su NULL o fa riferimento a un buffer che non è abbastanza grande, verrà restituito un puntatore NULL , non verranno copiati dati e dataCount conterrà le dimensioni del buffer necessarie specificate come numero di elementi.
Valore restituito
Il metodo restituisce un HRESULT. I valori possibili includono, ma non sono limitati a quelli della tabella che segue. Per informazioni sui valori restituiti dall'API documento XPS non elencati in questa tabella, vedere Errori del documento XPS.
Codice restituito | Descrizione |
---|---|
|
Il metodo è riuscito. |
|
dataCount è NULL. |
|
segmentData è NULL o fa riferimento a un buffer che non è abbastanza grande per ricevere i dati del segmento. dataCount contiene il numero necessario di elementi. |
Commenti
Per determinare le dimensioni necessarie della matrice di dati del segmento prima di chiamare questo metodo, chiamare GetSegmentDataCount.
Un segmento geometry è descritto dal punto iniziale, dal tipo di segmento e da parametri aggiuntivi i cui valori sono determinati dal tipo di segmento. Le coordinate per il punto iniziale del primo segmento sono una proprietà della figura geometry e vengono impostate chiamando SetStartPoint. Il punto iniziale di ogni segmento successivo è il punto finale del segmento precedente.
I valori della matrice restituiti nel parametro segmentData corrispondono ai valori XPS_SEGMENT_TYPE della matrice restituiti dal metodo GetSegmentTypes nel parametro segmentTypes . Per leggere correttamente i valori dei dati del segmento, è necessario conoscere il tipo di ogni segmento nella figura geometry. Ad esempio, se il primo segmento di riga ha un valore di tipo segmento di XPS_SEGMENT_TYPE_LINE, i primi due valori di dati nella matrice segmentData saranno le coordinate x e y del punto finale del segmento; se il segmento successivo ha un valore di tipo segmento di XPS_SEGMENT_TYPE_BEZIER, i sei valori successivi nella matrice segmentData descrivono le caratteristiche di tale segmento; e così via per ogni segmento di riga nella figura geometry.
La tabella seguente descrive il set specifico di valori di dati restituiti per ogni tipo di segmento. Per un esempio di come accedere a questi dati in un programma, vedere l'esempio di codice seguente.
Tipo di segmento | Valori di dati obbligatori |
---|---|
XPS_SEGMENT_TYPE_LINE |
Due valori di dati:
|
XPS_SEGMENT_TYPE_ARC_LARGE_CLOCKWISE |
Cinque valori di dati:
|
XPS_SEGMENT_TYPE_ARC_SMALL_CLOCKWISE |
Cinque valori di dati:
|
XPS_SEGMENT_TYPE_ARC_LARGE_COUNTERCLOCKWISE |
Cinque valori di dati:
|
XPS_SEGMENT_TYPE_ARC_SMALL_COUNTERCLOCKWISE |
Cinque valori di dati:
|
XPS_SEGMENT_TYPE_BEZIER |
Sei valori di dati:
|
XPS_SEGMENT_TYPE_QUADRATIC_BEZIER |
Quattro valori di dati:
|
Nell'esempio di codice seguente vengono accessibili i diversi punti dati di ogni tipo di segmento in una figura geometry.
// currentFigure is the pointer to an IXpsOMGeometryFigure
// that contains the segment data to examine
HRESULT hr = S_OK;
UINT32 numSegments = 0;
UINT32 numSegmentDataPoints = 0;
XPS_SEGMENT_TYPE *segmentTypes = NULL;
FLOAT *segmentDataPoints = NULL;
BOOL *segmentStrokes = NULL;
// get number of segments in this figure
hr = currentFigure->GetSegmentCount (&numSegments);
if (SUCCEEDED(hr))
{
// allocate array for segment data types
segmentTypes = new (std::nothrow) XPS_SEGMENT_TYPE[numSegments];
if (segmentTypes == NULL) { hr = E_OUTOFMEMORY; }
}
if (SUCCEEDED(hr))
{
// allocate array for segment strokes
segmentStrokes = new (std::nothrow) BOOL[numSegments];
if (segmentStrokes == NULL) { hr = E_OUTOFMEMORY; }
}
if (SUCCEEDED(hr))
{
// get array of segment data types
hr = currentFigure->GetSegmentTypes (&numSegments, segmentTypes);
}
if (SUCCEEDED(hr))
{
// get size of segment data array
hr = currentFigure->GetSegmentDataCount (&numSegmentDataPoints);
}
if (SUCCEEDED(hr))
{
// get array to hold segment data points
segmentDataPoints = new (std::nothrow) FLOAT[numSegmentDataPoints];
if (segmentDataPoints == NULL) { hr = E_OUTOFMEMORY; }
}
if (SUCCEEDED(hr))
{
// get segment data points
hr = currentFigure->GetSegmentData (
&numSegmentDataPoints, segmentDataPoints);
}
if (SUCCEEDED(hr))
{
// process segment data
UINT32 thisSegment = 0;
XPS_SEGMENT_TYPE *thisSegmentType = segmentTypes;
XPS_SEGMENT_TYPE *lastSegmentType = NULL;
FLOAT *thisSegmentDataPoint = segmentDataPoints;
FLOAT *lastSegmentsDataPoint = NULL;
// points to element just after valid array
// valid pointers are < this value and >= &segmentTypes[0]
lastSegmentType = &segmentTypes[numSegments];
// points to element just after valid array
// valid pointers are < this value and >= &segmentDataPoints[0]
lastSegmentsDataPoint = &segmentDataPoints[numSegmentDataPoints];
// look at each segment that was returned
while (thisSegment < numSegments)
{
if ((thisSegmentType >= lastSegmentType) ||
(thisSegmentDataPoint >= lastSegmentsDataPoint))
{
// the array data is not correct.
hr = E_UNEXPECTED;
break; // out of loop
}
else
{
// process the data based on the segment type
switch (*thisSegmentType)
{
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:
{
// 5 data points
FLOAT arcEndPoint_x = *thisSegmentDataPoint++;
FLOAT arcEndPoint_y = *thisSegmentDataPoint++;
FLOAT radius_x = *thisSegmentDataPoint++;
FLOAT radius_y = *thisSegmentDataPoint++;
FLOAT angle = *thisSegmentDataPoint++;
// do something with these points
}
break;
case XPS_SEGMENT_TYPE_BEZIER:
{
// 6 data points
FLOAT controlPoint1_x = *thisSegmentDataPoint++;
FLOAT controlPoint1_y = *thisSegmentDataPoint++;
FLOAT controlPoint2_x = *thisSegmentDataPoint++;
FLOAT controlPoint2_y = *thisSegmentDataPoint++;
FLOAT endPoint_x = *thisSegmentDataPoint++;
FLOAT endPoint_y = *thisSegmentDataPoint++;
// do something with these points
}
break;
case XPS_SEGMENT_TYPE_LINE:
{
// 2 data points
FLOAT endPoint_x = *thisSegmentDataPoint++;
FLOAT endPoint_y = *thisSegmentDataPoint++;
// do something with these points
}
break;
case XPS_SEGMENT_TYPE_QUADRATIC_BEZIER:
{
// 4 data points
FLOAT controlPoint_x = *thisSegmentDataPoint++;
FLOAT controlPoint_y = *thisSegmentDataPoint++;
FLOAT endPoint_x = *thisSegmentDataPoint++;
FLOAT endPoint_y = *thisSegmentDataPoint++;
// do something with these points
}
break;
default:
// unrecognized segment type
break;
}
//
thisSegment++;
thisSegmentType++;
}
}
}
delete[] segmentTypes; segmentTypes = NULL;
delete[] segmentStrokes; segmentStrokes = NULL;
delete[] segmentDataPoints; segmentDataPoints = NULL;
Requisiti
Client minimo supportato | Windows 7, Windows Vista con SP2 e Aggiornamento della piattaforma per Windows Vista [app desktop | App UWP] |
Server minimo supportato | Windows Server 2008 R2, Windows Server 2008 con SP2 e Platform Update per Windows Server 2008 [app desktop | App UWP] |
Piattaforma di destinazione | Windows |
Intestazione | xpsobjectmodel.h |