LinearShade Class - Linear Gradient Shading for Word Documents
Implements: ILinearShade, IBaseGraphicElement
Master linear gradient shading in Word documents using VDocs LinearShade API. Control the angle and scaling behaviour of linear gradients, enabling precise directional color transitions for text and objects programmatically in C#.
How to Configure Linear Gradients in Word Documents with C#
The LinearShade class defines the direction and scaling behaviour of a linear gradient. When used within a Gradient (via its LinearShade property), it determines how the gradient flows across the shape or text. The angle controls the direction, and the scaling flag determines whether the gradient stretches to fit the object.
Key LinearShade Features:
- Angle – Gradient direction in degrees (0° = left‑to‑right, 90° = top‑to‑bottom) using the
Rotationtype (normalised to 0‑360) - Scaled – If
true, the gradient is scaled to fit the shape's bounding box; iffalse, it uses absolute dimensions - Integration – Used exclusively within
Gradient.LinearShade
The LinearShade class controls the direction and scaling of a linear gradient fill.
It is a component of the Gradient class, used when you want a smooth color transition
along a straight line. The angle is specified via the Rotation type, which automatically
normalises values to the range [0, 360). The Scaled property determines whether the gradient
is adjusted to the object's dimensions or remains at a fixed size.
Constructors
LinearShade()Creates a new linear shade instance with Angle initialised to Scaled set to
Properties
| Property | Type | Description |
|---|---|---|
Angle |
Rotation? | Direction of the linear gradient, measured in degrees. 0° is left‑to‑right, 90° is top‑to‑bottom. Values are normalised to 0‑360. |
Scaled |
bool | If |
Related Type: Rotation
Namespace: Vega.DOM
Inheritance: BaseElement → Rotation
Implements: IRotation
Description: Represents a rotation angle in degrees, automatically normalised to the range [0, 360).
Key member:
double Value– The normalised angle.implicit operator Rotation(double)– Converts a double to aRotationwith normalisation.
Example: Rotation angle = 450; // becomes 90
Code Examples
Setting a Linear Shade with Angle
// Create a linear shade with a 45° angle and scaling enabled
var linearShade = new LinearShade
{
Angle = 45, // implicitly converted to Rotation (normalised)
Scaled = true
};
// Use in a gradient
var gradient = new Gradient
{
GradientStops = new List<IGradientStop>
{
new GradientStop { StopColor = Color.Red, StopPosition = 0 },
new GradientStop { StopColor = Color.Blue, StopPosition = 100 }
},
LinearShade = linearShade
};
Using Rotation Explicitly
// Create a Rotation instance for 270° (which is same as -90°)
var rotation = new Rotation { Value = 270 };
var linearShade = new LinearShade
{
Angle = rotation,
Scaled = false
};
Applying to Text via Gradient Fill
var gradient = new Gradient
{
GradientStops = new List<IGradientStop>
{
new GradientStop { StopColor = Color.Gold, StopPosition = 0 },
new GradientStop { StopColor = Color.DarkOrange, StopPosition = 100 }
},
LinearShade = new LinearShade
{
Angle = 135, // diagonal from bottom‑left to top‑right
Scaled = true
}
};
var textEffect = new TextEffect
{
GradientFill = gradient
};
var textStyle = new TextStyle
{
Font = new Font { Latin = new FontPart { FontName = "Arial", Size = 48 } },
TextEffect = textEffect
};
Best Practices
Set Angle for Desired Direction
Use 0° for left‑to‑right, 90° for top‑to‑bottom, 180° for right‑to‑left, and 270° for bottom‑to‑top. Diagonal angles like 45° create smooth corner‑to‑corner transitions.
Scaled vs Unscaled
Use Scaled = true when the gradient should always stretch to fill the object, regardless of its size. Use false when you want the gradient's proportions to remain constant (e.g., for a consistent pattern).
Leverage Rotation Normalisation
You can assign any angle (e.g., 450, -90) and it will be normalised. This is useful when calculating angles programmatically.
Common Use Cases & Search Terms
Frequently Asked Questions
What does the Angle value mean?
Angle specifies the direction of the linear gradient. 0° is from left to right, 90° from top to bottom, 180° from right to left, and 270° from bottom to top. Any angle can be used; it is normalised to 0‑360°.
What is the effect of Scaled = false?
When Scaled = false, the gradient is not stretched to the object's bounding box. Instead, it maintains its absolute proportions. If the object is larger, the gradient may repeat or be clipped depending on the implementation.
Can I use negative angles?
Yes, negative angles are accepted and will be normalised to the equivalent positive angle. For example, -90° becomes 270°.
How do I apply a linear shade to text?
Create a Gradient, set its LinearShade property, then assign the gradient to a TextEffect.GradientFill, and finally attach the TextEffect to a TextStyle.