Skip to content
Merged
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
30 changes: 8 additions & 22 deletions core/src/avm2/globals/flash/display/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,10 @@

let bitmap_data = args.try_get_object(0).and_then(|o| o.as_bitmap_data());

let pixel_snapping = args.get_string(activation, 1);

let pixel_snapping = if &pixel_snapping == b"always" {
PixelSnapping::Always
} else if &pixel_snapping == b"auto" {
PixelSnapping::Auto
} else if &pixel_snapping == b"never" {
PixelSnapping::Never
} else {
return Err(make_error_2008(activation, "pixelSnapping"));
};
let pixel_snapping = args
.get_string(activation, 1)
.parse()
.map_err(|_| make_error_2008(activation, "pixelSnapping"))?;

let smoothing = args.get_bool(2);

Expand Down Expand Up @@ -185,17 +178,10 @@
let this = this.as_object().unwrap();

if let Some(bitmap) = this.as_display_object().and_then(|dobj| dobj.as_bitmap()) {
let value = args.get_string(activation, 0);

let pixel_snapping = if &value == b"always" {
PixelSnapping::Always
} else if &value == b"auto" {
PixelSnapping::Auto
} else if &value == b"never" {
PixelSnapping::Never
} else {
return Err(make_error_2008(activation, "pixelSnapping"));
};
let pixel_snapping = args
.get_string(activation, 0)
.parse()
.map_err(|_| make_error_2008(activation, "pixelSnapping"))?;

Check warning on line 184 in core/src/avm2/globals/flash/display/bitmap.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered lines (181–184)

bitmap.set_pixel_snapping(pixel_snapping);
}
Expand Down
27 changes: 8 additions & 19 deletions core/src/avm2/globals/flash/display/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,15 +1012,10 @@ pub fn draw_path<'gc>(
let mut drawing = this.as_drawing().unwrap();
let commands = args.get_object(activation, 0, "commands")?;
let data = args.get_object(activation, 1, "data")?;
let winding = args.get_string(activation, 2);

let fill_rule = if winding == WStr::from_units(b"nonZero") {
FillRule::NonZero
} else if winding == WStr::from_units(b"evenOdd") {
FillRule::EvenOdd
} else {
return Err(make_error_2008(activation, "winding"));
};
let fill_rule = args
.get_string(activation, 2)
.parse()
.map_err(|_| make_error_2008(activation, "winding"))?;

// FIXME - implement fill behavior described in the Flash docs
// (which is different from just running each command sequentially on `Graphics`)
Expand Down Expand Up @@ -1490,17 +1485,11 @@ fn handle_igraphics_data<'gc>(

let data = obj.get_slot(graphics_path_slots::DATA).as_object();

let winding = obj
let fill_rule = obj
.get_slot(graphics_path_slots::_WINDING)
.coerce_to_string(activation)?;

let fill_rule = if winding == WStr::from_units(b"nonZero") {
FillRule::NonZero
} else if winding == WStr::from_units(b"evenOdd") {
FillRule::EvenOdd
} else {
unreachable!("AS3 setter guarantees value of winding");
};
.coerce_to_string(activation)?
.parse()
.expect("AS3 setter guarantees value of winding");

if let (Some(commands), Some(data)) = (commands, data) {
process_commands(
Expand Down
17 changes: 17 additions & 0 deletions render/src/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use h263_rs_yuv::bt601::yuv420_to_rgba;
use ruffle_wstr::{FromWStr, WStr};
use std::any::Any;
use std::borrow::Cow;
use std::fmt::Debug;
Expand Down Expand Up @@ -66,6 +67,22 @@
Never,
}

impl FromWStr for PixelSnapping {
type Err = ();

fn from_wstr(s: &WStr) -> Result<Self, Self::Err> {
if s == b"always" {
Ok(PixelSnapping::Always)

Check warning on line 75 in render/src/bitmap.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (75)
} else if s == b"auto" {
Ok(PixelSnapping::Auto)
} else if s == b"never" {
Ok(PixelSnapping::Never)

Check warning on line 79 in render/src/bitmap.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered lines (78–79)
} else {
Err(())

Check warning on line 81 in render/src/bitmap.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (81)
}
}
}

impl PixelSnapping {
pub fn apply(&self, matrix: &mut Matrix) {
match self {
Expand Down
15 changes: 15 additions & 0 deletions render/src/shape_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::matrix::Matrix;
use enum_map::Enum;
use ruffle_wstr::{FromWStr, WStr};
use smallvec::SmallVec;
use swf::{CharacterId, FillStyle, LineStyle, Rectangle, Shape, ShapeRecord, Twips};

Expand All @@ -19,6 +20,20 @@ pub enum GradientType {
Focal,
}

impl FromWStr for FillRule {
type Err = ();

fn from_wstr(s: &WStr) -> Result<Self, Self::Err> {
if s == b"evenOdd" {
Ok(FillRule::EvenOdd)
} else if s == b"nonZero" {
Ok(FillRule::NonZero)
} else {
Err(())
}
}
}

#[cfg(feature = "tessellator")]
impl From<FillRule> for lyon::path::FillRule {
fn from(rule: FillRule) -> lyon::path::FillRule {
Expand Down
Loading