Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions float-pigment-consistent-bincode/src/de/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ impl<'storage> BincodeRead<'storage> for SliceReader<'storage> {

#[inline(always)]
fn forward_to_barrier(&mut self) -> io::Result<()> {
let (_, remaining) = self.slice.split_at(self.barrier_offset);
self.slice = remaining;
self.slice = self
.slice
.get(self.barrier_offset..)
.ok_or_else(|| io::Error::new(io::ErrorKind::UnexpectedEof))?;
self.barrier_offset = 0;
Ok(())
}
Expand Down
24 changes: 24 additions & 0 deletions float-pigment-consistent-bincode/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};

const LEN_SIZE: u64 = 8;

#[test]
fn truncated_unknown_fields_return_errors() {
#[derive(Serialize)]
enum Newer {
None,
V1((u8, Vec<u8>)),
}
#[derive(Debug, PartialEq, Deserialize)]
enum Older {
None,
V1(u8),
}

let encoded = serialize(&Newer::V1((7, vec![1; 32]))).unwrap();
assert_eq!(deserialize::<Older>(&encoded).unwrap(), Older::V1(7));
for length in 0..encoded.len() {
assert!(deserialize::<Older>(&encoded[..length]).is_err());
}
assert_eq!(
deserialize::<Older>(&serialize(&Newer::None).unwrap()).unwrap(),
Older::None
);
}

fn the_same_impl<V, O>(element: V, options: &mut O)
where
V: serde::Serialize + serde::de::DeserializeOwned + PartialEq + Debug + 'static,
Expand Down
7 changes: 6 additions & 1 deletion float-pigment-css/cbindgen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ fn update_cbindgen_bindings(crate_dir: &Path) -> Result<(), BuildError> {
a.push(extra_struct.clone());
}
_ => {
a.push(line.replace(">>", "> >"));
a.push(
line.replace(">>", "> >")
.replace("Not_Body not;", "Not_Body not_;")
.replace("And_Body and;", "And_Body and_;")
.replace("Or_Body or;", "Or_Body or_;"),
);
}
}
}
Expand Down
390 changes: 390 additions & 0 deletions float-pigment-css/docs/media-query-and-rule-tree-zh_CN.md

Large diffs are not rendered by default.

162 changes: 162 additions & 0 deletions float-pigment-css/float_pigment_css.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ enum class MaskModeItem {
Luminance,
};

enum class MediaComparison {
Equal,
Less,
LessEqual,
Greater,
GreaterEqual,
};

enum class MediaType {
None,
All,
Expand All @@ -173,6 +181,16 @@ enum class PseudoElementsType {
Selection,
};

/// The sizing media features, i.e. `width` / `height` and their `min-` / `max-` variants.
enum class SizedFeature {
Width,
MinWidth,
MaxWidth,
Height,
MinHeight,
MaxHeight,
};

/// A helper type for `transition-timing-function`.
enum class StepPosition {
End,
Expand Down Expand Up @@ -977,6 +995,12 @@ struct CalcExpr {
Mul,
/// `/` expression.
Div,
/// `min(...)` expression; comma-separated calc-sums.
Min,
/// `max(...)` expression; comma-separated calc-sums.
Max,
/// `clamp(MIN, VAL, MAX)` expression.
Clamp,
};

struct Length_Body {
Expand Down Expand Up @@ -1011,6 +1035,20 @@ struct CalcExpr {
Box<CalcExpr> _1;
};

struct Min_Body {
Array<CalcExpr> _0;
};

struct Max_Body {
Array<CalcExpr> _0;
};

struct Clamp_Body {
Box<CalcExpr> _0;
Box<CalcExpr> _1;
Box<CalcExpr> _2;
};

Tag tag;
union {
Length_Body length;
Expand All @@ -1020,6 +1058,9 @@ struct CalcExpr {
Sub_Body sub;
Mul_Body mul;
Div_Body div;
Min_Body min;
Max_Body max;
Clamp_Body clamp;
};
};

Expand Down Expand Up @@ -9653,6 +9694,26 @@ struct MediaExpression {
MinHeight,
MaxHeight,
Theme,
Resolution,
MinResolution,
MaxResolution,
/// A sizing feature with a length value, e.g. `(width: 50em)`.
Sized,
/// A media feature that is not recognized, or whose value is invalid.
UnknownFeature,
/// A sizing feature in boolean context: `(width)` or `(height)`.
/// Matches when the corresponding dimension is nonzero.
Boolean,
/// A known discrete feature in boolean context, e.g. `(orientation)`.
AlwaysTrue,
Not,
And,
Or,
/// A length-valued feature in a range context, e.g. `(width > 50em)`.
Range,
/// A resolution comparison in range context, with its value normalized to dppx.
ResolutionRange,
InfiniteResolution,
};

struct MediaType_Body {
Expand Down Expand Up @@ -9691,6 +9752,54 @@ struct MediaExpression {
Theme _0;
};

struct Resolution_Body {
float _0;
};

struct MinResolution_Body {
float _0;
};

struct MaxResolution_Body {
float _0;
};

struct Sized_Body {
SizedFeature _0;
Length _1;
};

struct Boolean_Body {
SizedFeature _0;
};

struct Not_Body {
Box<MediaExpression> _0;
};

struct And_Body {
Array<MediaExpression> _0;
};

struct Or_Body {
Array<MediaExpression> _0;
};

struct Range_Body {
SizedFeature _0;
MediaComparison _1;
Length _2;
};

struct ResolutionRange_Body {
MediaComparison _0;
float _1;
};

struct InfiniteResolution_Body {
MediaComparison _0;
};

Tag tag;
union {
MediaType_Body media_type;
Expand All @@ -9702,6 +9811,17 @@ struct MediaExpression {
MinHeight_Body min_height;
MaxHeight_Body max_height;
Theme_Body theme;
Resolution_Body resolution;
MinResolution_Body min_resolution;
MaxResolution_Body max_resolution;
Sized_Body sized;
Boolean_Body boolean;
Not_Body not_;
And_Body and_;
Or_Body or_;
Range_Body range;
ResolutionRange_Body resolution_range;
InfiniteResolution_Body infinite_resolution;
};
};

Expand Down Expand Up @@ -9787,6 +9907,46 @@ struct KeyFrames {
Array<KeyFrameRule> keyframes;
};

struct RuleTreeNode {
enum class Tag {
Style,
Media,
KeyFrames,
FontFace,
Import,
};

struct Style_Body {
size_t _0;
};

struct Media_Body {
size_t media_index;
Array<RuleTreeNode> children;
};

struct KeyFrames_Body {
size_t _0;
};

struct FontFace_Body {
size_t _0;
};

struct Import_Body {
size_t _0;
};

Tag tag;
union {
Style_Body style;
Media_Body media;
KeyFrames_Body key_frames;
FontFace_Body font_face;
Import_Body import;
};
};

struct StyleSheetV1 {
StrBuffer buf;
Array<StrRef> imports;
Expand All @@ -9796,6 +9956,8 @@ struct StyleSheetV1 {
Box<StrRef> version;
Array<FontFace> font_face;
Array<KeyFrames> keyframes;
/// Grouped rules in source order; absent in legacy bincode data.
Nullable<Array<RuleTreeNode> > rule_tree;
};

struct StyleSheet {
Expand Down
6 changes: 3 additions & 3 deletions float-pigment-css/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub unsafe extern "C" fn style_sheet_resource_add_bincode(
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null());
let res = raw_ptr_as_mut_ref!(this, group::StyleSheetResource);
let bincode: *mut [u8] = core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len);
let path = CStr::from_ptr(path).to_string_lossy();
let path = CStr::from_ptr(path).to_string_lossy().into_owned();
let w = res.add_bincode_zero_copy(&path, bincode, move || {
if let Some(drop_fn) = drop_fn {
drop_fn(drop_args);
Expand Down Expand Up @@ -593,7 +593,7 @@ pub unsafe extern "C" fn style_sheet_import_index_add_bincode(
check_null!(this, FfiErrorCode::ThisNullPointer, null_mut());
check_null!(path, FfiErrorCode::PathNullPointer, null_mut());
check_null!(buffer_ptr, FfiErrorCode::BufferNullPointer, null_mut());
let path = CStr::from_ptr(path).to_string_lossy();
let path = CStr::from_ptr(path).to_string_lossy().into_owned();
let sheet = de_static_ref_zero_copy_env(
core::ptr::slice_from_raw_parts_mut(buffer_ptr, buffer_len),
|s| {
Expand Down Expand Up @@ -1109,7 +1109,7 @@ pub unsafe extern "C" fn style_sheet_bincode_version(
move || {},
);
let version = match sheet {
StyleSheet::V1(v1) => v1.version,
StyleSheet::V1(v1) => Box::new(StrRef::from(v1.version.to_string())),
_ => Box::new("unknown version".into()),
};
FfiResult::ok(Box::into_raw(version))
Expand Down
10 changes: 10 additions & 0 deletions float-pigment-css/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ impl StyleSheetGroup {
.map(|sheet| sheet.get_font_face())
}

/// Get font-face definitions matching the current media environment.
pub fn get_font_face_with_media<L: LengthNum>(
&self,
sheet_index: u16,
media_query_status: &MediaQueryStatus<L>,
) -> Option<Vec<Rc<FontFace>>> {
self.style_sheet(sheet_index)
.map(|sheet| sheet.get_font_face_with_media(media_query_status))
}

/// Get a rule by index.
///
/// If sheet index is `TEMP_SHEET_INDEX` then the temporary style sheet will be used.
Expand Down
Loading
Loading