avm1: Implement `TextField.antiAliasType`, `.gridFitType`, `.sharpness`, and `.thickness`.
Notably this required removing a few parameter checks from core that turned out to be AS3-only.
This commit is contained in:
parent
7155f88601
commit
10ad603566
|
@ -83,6 +83,10 @@ const PROTO_DECLS: &[Declaration] = declare_properties! {
|
||||||
"type" => property(tf_getter!(get_type), tf_setter!(set_type));
|
"type" => property(tf_getter!(get_type), tf_setter!(set_type));
|
||||||
"variable" => property(tf_getter!(variable), tf_setter!(set_variable));
|
"variable" => property(tf_getter!(variable), tf_setter!(set_variable));
|
||||||
"wordWrap" => property(tf_getter!(word_wrap), tf_setter!(set_word_wrap));
|
"wordWrap" => property(tf_getter!(word_wrap), tf_setter!(set_word_wrap));
|
||||||
|
"antiAliasType" => property(tf_getter!(anti_alias_type), tf_setter!(set_anti_alias_type));
|
||||||
|
"gridFitType" => property(tf_getter!(grid_fit_type), tf_setter!(set_grid_fit_type));
|
||||||
|
"sharpness" => property(tf_getter!(sharpness), tf_setter!(set_sharpness));
|
||||||
|
"thickness" => property(tf_getter!(thickness), tf_setter!(set_thickness));
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Implements `TextField`
|
/// Implements `TextField`
|
||||||
|
@ -676,3 +680,122 @@ pub fn bottom_scroll<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
Ok(this.bottom_scroll().into())
|
Ok(this.bottom_scroll().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn anti_alias_type<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
if this.render_settings().is_advanced() {
|
||||||
|
Ok("advanced".into())
|
||||||
|
} else {
|
||||||
|
Ok("normal".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_anti_alias_type<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
value: Value<'gc>,
|
||||||
|
) -> Result<(), Error<'gc>> {
|
||||||
|
let old_settings = this.render_settings();
|
||||||
|
let new_type = value.coerce_to_string(activation)?;
|
||||||
|
|
||||||
|
if &new_type == b"advanced" {
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_advanced_rendering(),
|
||||||
|
);
|
||||||
|
} else if &new_type == b"normal" {
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_normal_rendering(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn grid_fit_type<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
match this.render_settings().grid_fit() {
|
||||||
|
swf::TextGridFit::None => Ok("none".into()),
|
||||||
|
swf::TextGridFit::Pixel => Ok("pixel".into()),
|
||||||
|
swf::TextGridFit::SubPixel => Ok("subpixel".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_grid_fit_type<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
value: Value<'gc>,
|
||||||
|
) -> Result<(), Error<'gc>> {
|
||||||
|
let old_settings = this.render_settings();
|
||||||
|
let new_type = value.coerce_to_string(activation)?;
|
||||||
|
|
||||||
|
if &new_type == b"pixel" {
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_grid_fit(swf::TextGridFit::Pixel),
|
||||||
|
);
|
||||||
|
} else if &new_type == b"subpixel" {
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_grid_fit(swf::TextGridFit::SubPixel),
|
||||||
|
);
|
||||||
|
} else if &new_type == b"none" {
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_grid_fit(swf::TextGridFit::None),
|
||||||
|
);
|
||||||
|
} // NOTE: In AS2 invalid values do nothing.
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn thickness<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
Ok(this.render_settings().thickness().into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_thickness<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
value: Value<'gc>,
|
||||||
|
) -> Result<(), Error<'gc>> {
|
||||||
|
let old_settings = this.render_settings();
|
||||||
|
let new_thickness = value.coerce_to_f64(activation)?;
|
||||||
|
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_thickness(new_thickness as f32),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sharpness<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
_activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
Ok(this.render_settings().sharpness().into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_sharpness<'gc>(
|
||||||
|
this: EditText<'gc>,
|
||||||
|
activation: &mut Activation<'_, 'gc, '_>,
|
||||||
|
value: Value<'gc>,
|
||||||
|
) -> Result<(), Error<'gc>> {
|
||||||
|
let old_settings = this.render_settings();
|
||||||
|
let new_sharpness = value.coerce_to_f64(activation)?;
|
||||||
|
|
||||||
|
this.set_render_settings(
|
||||||
|
activation.context.gc_context,
|
||||||
|
old_settings.with_sharpness(new_sharpness as f32),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -972,6 +972,7 @@ pub fn set_grid_fit_type<'gc>(
|
||||||
old_settings.with_grid_fit(swf::TextGridFit::SubPixel),
|
old_settings.with_grid_fit(swf::TextGridFit::SubPixel),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
//NOTE: In AS3 invalid values are treated as None.
|
||||||
this.set_render_settings(
|
this.set_render_settings(
|
||||||
activation.context.gc_context,
|
activation.context.gc_context,
|
||||||
old_settings.with_grid_fit(swf::TextGridFit::None),
|
old_settings.with_grid_fit(swf::TextGridFit::None),
|
||||||
|
@ -1006,12 +1007,21 @@ pub fn set_thickness<'gc>(
|
||||||
.and_then(|this| this.as_edit_text())
|
.and_then(|this| this.as_edit_text())
|
||||||
{
|
{
|
||||||
let old_settings = this.render_settings();
|
let old_settings = this.render_settings();
|
||||||
let new_thickness = args
|
let mut new_thickness = args
|
||||||
.get(0)
|
.get(0)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(Value::Undefined)
|
.unwrap_or(Value::Undefined)
|
||||||
.coerce_to_number(activation)?;
|
.coerce_to_number(activation)?;
|
||||||
|
|
||||||
|
// NOTE: The thickness clamp is ONLY enforced on AS3.
|
||||||
|
new_thickness = if new_thickness > 200.0 {
|
||||||
|
200.0
|
||||||
|
} else if new_thickness < -200.0 {
|
||||||
|
-200.0
|
||||||
|
} else {
|
||||||
|
new_thickness
|
||||||
|
};
|
||||||
|
|
||||||
this.set_render_settings(
|
this.set_render_settings(
|
||||||
activation.context.gc_context,
|
activation.context.gc_context,
|
||||||
old_settings.with_thickness(new_thickness as f32),
|
old_settings.with_thickness(new_thickness as f32),
|
||||||
|
@ -1046,12 +1056,21 @@ pub fn set_sharpness<'gc>(
|
||||||
.and_then(|this| this.as_edit_text())
|
.and_then(|this| this.as_edit_text())
|
||||||
{
|
{
|
||||||
let old_settings = this.render_settings();
|
let old_settings = this.render_settings();
|
||||||
let new_sharpness = args
|
let mut new_sharpness = args
|
||||||
.get(0)
|
.get(0)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(Value::Undefined)
|
.unwrap_or(Value::Undefined)
|
||||||
.coerce_to_number(activation)?;
|
.coerce_to_number(activation)?;
|
||||||
|
|
||||||
|
// NOTE: The sharpness clamp is only enforced on AS3.
|
||||||
|
new_sharpness = if new_sharpness > 400.0 {
|
||||||
|
400.0
|
||||||
|
} else if new_sharpness < -400.0 {
|
||||||
|
-400.0
|
||||||
|
} else {
|
||||||
|
new_sharpness
|
||||||
|
};
|
||||||
|
|
||||||
this.set_render_settings(
|
this.set_render_settings(
|
||||||
activation.context.gc_context,
|
activation.context.gc_context,
|
||||||
old_settings.with_sharpness(new_sharpness as f32),
|
old_settings.with_sharpness(new_sharpness as f32),
|
||||||
|
|
|
@ -565,15 +565,7 @@ impl TextRenderSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_sharpness(self, mut sharpness: f32) -> Self {
|
pub fn with_sharpness(self, sharpness: f32) -> Self {
|
||||||
sharpness = if sharpness > 400.0 {
|
|
||||||
400.0
|
|
||||||
} else if sharpness < -400.0 {
|
|
||||||
-400.0
|
|
||||||
} else {
|
|
||||||
sharpness
|
|
||||||
};
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
TextRenderSettings::Normal {
|
TextRenderSettings::Normal {
|
||||||
grid_fit,
|
grid_fit,
|
||||||
|
@ -603,15 +595,7 @@ impl TextRenderSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_thickness(self, mut thickness: f32) -> Self {
|
pub fn with_thickness(self, thickness: f32) -> Self {
|
||||||
thickness = if thickness > 200.0 {
|
|
||||||
200.0
|
|
||||||
} else if thickness < -200.0 {
|
|
||||||
-200.0
|
|
||||||
} else {
|
|
||||||
thickness
|
|
||||||
};
|
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
TextRenderSettings::Normal {
|
TextRenderSettings::Normal {
|
||||||
grid_fit,
|
grid_fit,
|
||||||
|
|
Loading…
Reference in New Issue