Skip to content

Commit 2b5c668

Browse files
authored
Auto merge of rust-windowing#427 - pcwalton:content-docs, r=pcwalton
Document the rest of `pathfinder_content`
2 parents bad735e + 4060baa commit 2b5c668

9 files changed

+211
-23
lines changed

content/src/effects.rs

+46
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum Filter {
5555
uv_origin: Vector2F,
5656
},
5757

58+
/// One of the `PatternFilter` filters.
5859
PatternFilter(PatternFilter),
5960
}
6061

@@ -80,7 +81,9 @@ pub enum PatternFilter {
8081
/// To produce a full Gaussian blur, perform two successive blur operations, one in each
8182
/// direction.
8283
Blur {
84+
/// The axis of the blur: horizontal or vertical.
8385
direction: BlurDirection,
86+
/// Half the blur radius.
8487
sigma: f32,
8588
},
8689

@@ -95,43 +98,86 @@ pub enum PatternFilter {
9598
#[derive(Clone, Copy, PartialEq, Debug)]
9699
pub enum BlendMode {
97100
// Porter-Duff, supported by GPU blender
101+
/// No regions are enabled.
98102
Clear,
103+
/// Only the source will be present.
99104
Copy,
105+
/// The source that overlaps the destination, replaces the destination.
100106
SrcIn,
107+
/// Source is placed, where it falls outside of the destination.
101108
SrcOut,
109+
/// Source is placed over the destination.
102110
SrcOver,
111+
/// Source which overlaps the destination, replaces the destination. Destination is placed
112+
/// elsewhere.
103113
SrcAtop,
114+
/// Destination which overlaps the source, replaces the source.
104115
DestIn,
116+
/// Destination is placed, where it falls outside of the source.
105117
DestOut,
118+
/// Destination is placed over the source.
106119
DestOver,
120+
/// Destination which overlaps the source replaces the source. Source is placed elsewhere.
107121
DestAtop,
122+
/// The non-overlapping regions of source and destination are combined.
108123
Xor,
124+
/// Display the sum of the source image and destination image. It is defined in the Porter-Duff
125+
/// paper as the plus operator.
109126
Lighter,
110127

111128
// Others, unsupported by GPU blender
129+
/// Selects the darker of the backdrop and source colors.
112130
Darken,
131+
/// Selects the lighter of the backdrop and source colors.
113132
Lighten,
133+
/// The source color is multiplied by the destination color and replaces the destination.
114134
Multiply,
135+
/// Multiplies the complements of the backdrop and source color values, then complements the
136+
/// result.
115137
Screen,
138+
/// Multiplies or screens the colors, depending on the source color value. The effect is
139+
/// similar to shining a harsh spotlight on the backdrop.
116140
HardLight,
141+
/// Multiplies or screens the colors, depending on the backdrop color value.
117142
Overlay,
143+
/// Brightens the backdrop color to reflect the source color.
118144
ColorDodge,
145+
/// Darkens the backdrop color to reflect the source color.
119146
ColorBurn,
147+
/// Darkens or lightens the colors, depending on the source color value. The effect is similar
148+
/// to shining a diffused spotlight on the backdrop.
120149
SoftLight,
150+
/// Subtracts the darker of the two constituent colors from the lighter color.
121151
Difference,
152+
/// Produces an effect similar to that of the Difference mode but lower in contrast.
122153
Exclusion,
154+
/// Creates a color with the hue of the source color and the saturation and luminosity of the
155+
/// backdrop color.
123156
Hue,
157+
/// Creates a color with the saturation of the source color and the hue and luminosity of the
158+
/// backdrop color.
124159
Saturation,
160+
/// Creates a color with the hue and saturation of the source color and the luminosity of the
161+
/// backdrop color.
125162
Color,
163+
/// Creates a color with the luminosity of the source color and the hue and saturation of the
164+
/// backdrop color. This produces an inverse effect to that of the Color mode.
126165
Luminosity,
127166
}
128167

168+
/// The convolution kernel that will be applied horizontally to reduce color fringes when
169+
/// performing subpixel antialiasing. This kernel is automatically mirrored horizontally. The
170+
/// fourth element of this kernel is applied to the center of the pixel, the third element is
171+
/// applied one pixel to the left, and so on.
129172
#[derive(Clone, Copy, PartialEq, Debug)]
130173
pub struct DefringingKernel(pub [f32; 4]);
131174

175+
/// The axis a Gaussian blur is applied to.
132176
#[derive(Clone, Copy, PartialEq, Debug)]
133177
pub enum BlurDirection {
178+
/// The horizontal axis.
134179
X,
180+
/// The vertical axis.
135181
Y,
136182
}
137183

content/src/gradient.rs

+54-4
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,45 @@ use std::convert;
2222
use std::hash::{Hash, Hasher};
2323
use std::mem;
2424

25+
/// A gradient, either linear or radial.
2526
#[derive(Clone, PartialEq, Debug)]
2627
pub struct Gradient {
28+
/// Information specific to the type of gradient (linear or radial).
2729
pub geometry: GradientGeometry,
2830
stops: Vec<ColorStop>,
31+
/// What should be rendered upon reaching the end of the color stops.
2932
pub wrap: GradientWrap,
3033
}
3134

35+
/// A color in a gradient. Points in a gradient between two stops interpolate linearly between the
36+
/// stops.
3237
#[derive(Clone, Copy, PartialEq, Debug)]
3338
pub struct ColorStop {
39+
/// The offset of the color stop, between 0.0 and 1.0 inclusive. The value 0.0 represents the
40+
/// start of the gradient, and 1.0 represents the end.
3441
pub offset: f32,
42+
/// The color of the gradient stop.
3543
pub color: ColorU,
3644
}
3745

46+
/// The type of gradient: linear or radial.
3847
#[derive(Clone, PartialEq, Debug)]
3948
pub enum GradientGeometry {
49+
/// A linear gradient that follows a line.
50+
///
51+
/// The line is in scene coordinates, not relative to the bounding box of the path.
4052
Linear(LineSegment2F),
53+
/// A radial gradient that radiates outward from a line connecting two circles (or from one
54+
/// circle).
4155
Radial {
42-
/// The line that connects the two circles. It may have zero length for simple radial
43-
/// gradients.
56+
/// The line that connects the centers of the two circles. For single-circle radial
57+
/// gradients (the common case), this line has zero length, with start point and endpoint
58+
/// both at the circle's center point.
59+
///
60+
/// This is in scene coordinates, not relative to the bounding box of the path.
4461
line: LineSegment2F,
45-
/// The radii of the two circles. The first value may be zero.
62+
/// The radii of the two circles. The first value may be zero to start the gradient at the
63+
/// center of the circle.
4664
radii: F32x2,
4765
/// Transform from radial gradient space into screen space.
4866
///
@@ -52,9 +70,13 @@ pub enum GradientGeometry {
5270
}
5371
}
5472

73+
/// What should be rendered outside the color stops.
5574
#[derive(Clone, Copy, PartialEq, Debug)]
5675
pub enum GradientWrap {
76+
/// The area before the gradient is filled with the color of the first stop, and the area after
77+
/// the gradient is filled with the color of the last stop.
5778
Clamp,
79+
/// The gradient repeats indefinitely.
5880
Repeat,
5981
}
6082

@@ -97,6 +119,9 @@ impl Hash for ColorStop {
97119
}
98120

99121
impl Gradient {
122+
/// Creates a new linear gradient with the given line.
123+
///
124+
/// The line is in scene coordinates, not relative to the bounding box of the current path.
100125
#[inline]
101126
pub fn linear(line: LineSegment2F) -> Gradient {
102127
Gradient {
@@ -106,11 +131,19 @@ impl Gradient {
106131
}
107132
}
108133

134+
/// A convenience method equivalent to `Gradient::linear(LineSegment2F::new(from, to))`.
109135
#[inline]
110136
pub fn linear_from_points(from: Vector2F, to: Vector2F) -> Gradient {
111137
Gradient::linear(LineSegment2F::new(from, to))
112138
}
113139

140+
/// Creates a new radial gradient from a line connecting the centers of two circles with the
141+
/// given radii, or a point at the center of one circle.
142+
///
143+
/// To create a radial gradient with a single circle (the common case), pass a `Vector2F`
144+
/// representing the center of the circle for `line`; otherwise, to create a radial gradient
145+
/// with two circles, pass a `LineSegment2F`. To start the gradient at the center of the
146+
/// circle, pass zero for the first radius.
114147
#[inline]
115148
pub fn radial<L>(line: L, radii: F32x2) -> Gradient where L: RadialGradientLine {
116149
let transform = Transform2F::default();
@@ -121,6 +154,7 @@ impl Gradient {
121154
}
122155
}
123156

157+
/// Adds a new color stop to the radial gradient.
124158
#[inline]
125159
pub fn add(&mut self, stop: ColorStop) {
126160
let index = self.stops.binary_search_by(|other| {
@@ -129,22 +163,28 @@ impl Gradient {
129163
self.stops.insert(index, stop);
130164
}
131165

132-
/// A convenience method to add a color stop.
166+
/// A convenience method equivalent to
167+
/// `gradient.add_color_stop(ColorStop::new(color, offset))`.
133168
#[inline]
134169
pub fn add_color_stop(&mut self, color: ColorU, offset: f32) {
135170
self.add(ColorStop::new(color, offset))
136171
}
137172

173+
/// Returns the list of color stops in this gradient.
138174
#[inline]
139175
pub fn stops(&self) -> &[ColorStop] {
140176
&self.stops
141177
}
142178

179+
/// Returns a mutable version of the list of color stops in this gradient.
143180
#[inline]
144181
pub fn stops_mut(&mut self) -> &mut [ColorStop] {
145182
&mut self.stops
146183
}
147184

185+
/// Returns the value of the gradient at offset `t`, which will be clamped between 0.0 and 1.0.
186+
///
187+
/// FIXME(pcwalton): This should probably take `wrap` into account…
148188
pub fn sample(&self, mut t: f32) -> ColorU {
149189
if self.stops.is_empty() {
150190
return ColorU::transparent_black();
@@ -170,16 +210,23 @@ impl Gradient {
170210
lower_stop.color.to_f32().lerp(upper_stop.color.to_f32(), ratio).to_u8()
171211
}
172212

213+
/// Returns true if all colors of all stops in this gradient are opaque (alpha is 1.0).
173214
#[inline]
174215
pub fn is_opaque(&self) -> bool {
175216
self.stops.iter().all(|stop| stop.color.is_opaque())
176217
}
177218

219+
/// Returns true if all colors of all stops in this gradient are fully transparent (alpha is
220+
/// 0.0).
178221
#[inline]
179222
pub fn is_fully_transparent(&self) -> bool {
180223
self.stops.iter().all(|stop| stop.color.is_fully_transparent())
181224
}
182225

226+
/// Applies the given affine transform to this gradient.
227+
///
228+
/// FIXME(pcwalton): This isn't correct for radial gradients, as transforms can transform the
229+
/// circles into ellipses…
183230
pub fn apply_transform(&mut self, new_transform: Transform2F) {
184231
if new_transform.is_identity() {
185232
return;
@@ -195,13 +242,16 @@ impl Gradient {
195242
}
196243

197244
impl ColorStop {
245+
/// Creates a new color stop from a color and offset between 0.0 and 1.0 inclusive.
198246
#[inline]
199247
pub fn new(color: ColorU, offset: f32) -> ColorStop {
200248
ColorStop { color, offset }
201249
}
202250
}
203251

252+
/// Allows `Gradient::radial` to be called with either a `LineSegment2F` or a `Vector2F`.
204253
pub trait RadialGradientLine {
254+
/// Represents this value as a line.
205255
fn to_line(self) -> LineSegment2F;
206256
}
207257

content/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Components of a vector scene, and various path utilities.
1212
13+
#![warn(missing_docs)]
14+
1315
#[macro_use]
1416
extern crate bitflags;
1517
#[macro_use]

content/src/orientation.rs

+7
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Determining whether an outline is wound clockwise or counterclockwise.
12+
1113
use crate::outline::Outline;
1214

15+
/// Winding order: counterclockwise or clockwise, with Y down.
1316
#[derive(Clone, Copy, Debug, PartialEq)]
1417
pub enum Orientation {
18+
/// Counterclockwise, with Y down.
1519
Ccw = -1,
20+
/// Clockwise, with Y down.
1621
Cw = 1,
1722
}
1823

1924
impl Orientation {
25+
/// Determines whether the outermost winding of an outline is counterclockwise or clockwise.
26+
///
2027
/// This follows the FreeType algorithm.
2128
pub fn from_outline(outline: &Outline) -> Orientation {
2229
let mut area = 0.0;

content/src/pattern.rs

+6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ pub struct Pattern {
3636
/// Where a raster image pattern comes from.
3737
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
3838
pub enum PatternSource {
39+
/// A image whose pixels are stored in CPU memory.
3940
Image(Image),
41+
/// Previously-rendered vector content.
42+
///
43+
/// This value allows you to render content and then later use that content as a pattern.
4044
RenderTarget {
45+
/// The ID of the render target, including the ID of the scene it came from.
4146
id: RenderTargetId,
47+
/// The device pixel size of the render target.
4248
size: Vector2I,
4349
}
4450
}

content/src/render_target.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Render targets.
11+
//! Raster images that vector graphics can be rendered to and later used as a pattern.
1212
13+
/// Identifies a drawing surface for vector graphics that can be later used as a pattern.
1314
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1415
pub struct RenderTargetId {
16+
/// The ID of the scene that this render target ID belongs to.
1517
pub scene: u32,
18+
/// The ID of the render target within this scene.
1619
pub render_target: u32,
1720
}

0 commit comments

Comments
 (0)