IXpsOMObjectFactory::CreateGradientStop method

Creates an IXpsOMGradientStop interface to represent a single color and location definition within a gradient.

Syntax


HRESULT CreateGradientStop(
  [in]          const XPS_COLOR                  *color,
  [in]                IXpsOMColorProfileResource *colorProfile,
  [in]                FLOAT                      offset,
  [out, retval]       IXpsOMGradientStop         **gradientStop
);

Parameters

color [in]

The color value.

colorProfile [in]

A pointer to the IXpsOMColorProfileResource interface that contains the color profile to be used. If the color type is not XPS_COLOR_TYPE_CONTEXT, this parameter must be NULL.

offset [in]

The offset value.

Valid range: 0.0–1.0

gradientStop [out, retval]

A pointer to the new IXpsOMGradientStop interface.

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the table that follows. For information about XPS document API return values that are not listed in this table, see XPS Document Errors.

Return codeDescription
S_OK

The method succeeded.

E_INVALIDARG

The value in offset is not valid.

E_POINTER

color or gradientStop is NULL.

XPS_E_MISSING_COLORPROFILE

colorProfile is NULL but a color profile is expected. A color profile is required when the color type is XPS_COLOR_TYPE_CONTEXT.

XPS_E_NO_CUSTOM_OBJECTS

colorProfile does not point to a recognized interface implementation. Custom implementation of XPS Document API interfaces is not supported.

XPS_E_UNEXPECTED_COLORPROFILE

colorProfile contains a color profile but one is not expected. A color profile is only allowed when the color type is XPS_COLOR_TYPE_CONTEXT.

 

Remarks

Gradient stops are used to define the color at a specific location; the color is interpolated between the gradient stops. The offset, which is specified by offset, is a relative position between the start and end points of the gradient. The offset at the start point of a linear gradient or the origin of a radial gradient is 0.0. The offset of the end point of a linear gradient or the bounding ellipse of a radial gradient is 1.0. Gradient stops can be specified for any offset between those points, including the start and end points. The following illustration shows the gradient path and gradient stops of a linear gradient.

A figure that shows the terms used in a linear gradient

The following illustration shows the gradient stops of a radial gradient. In this example, the radial gradient region is the area enclosed by the outer ellipse and the XPS_SPREAD_METHOD_REFLECT spread method is used to fill the space outside of the gradient region.

A figure that shows the terms used in a radial gradient

The IXpsOMGradientStop interface specifies one and only one stop in a gradient.

The calculations used to render a gradient are described in the XML Paper Specification.

The code example that follows illustrates how this method is used to create a new interface.



IXpsOMGradientStop    *newInterface;
// The following values are defined outside of 
// this example.
//  XPS_COLOR                    color;
//  IXpsOMColorProfileResource    *colorProfile;
//  FLOAT                        offset;

// Note the implicit requirement that CoInitializeEx 
//  has previously been called from this thread.

hr = CoCreateInstance(
    __uuidof(XpsOMObjectFactory),
    NULL,
    CLSCTX_INPROC_SERVER,
    _uuidof(IXpsOMObjectFactory),
    reinterpret_cast<LPVOID*>(&xpsFactory)
    );

if (SUCCEEDED(hr))
{
    hr = xpsFactory->CreateGradientStop (
        &color,
        colorProfile,
        offset,
        &newInterface);

    if (SUCCEEDED(hr))
    {
        // use newInterface

        newInterface->Release();
    }
    xpsFactory->Release();
}
else
{
    // evaluate HRESULT error returned in hr
}


Requirements

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Header

Xpsobjectmodel.h

IDL

XpsObjectModel.idl

See also

IXpsOMObjectFactory
IXpsOMColorProfileResource
IXpsOMGradientStop
XPS_COLOR
XPS Document Errors
XML Paper Specification

 

 

Show: