Implement `color` on spans
This commit is contained in:
parent
9bcc7ef0cc
commit
e3f59ac00f
|
@ -264,32 +264,12 @@ impl<'gc> EditText<'gc> {
|
||||||
self.relayout(context);
|
self.relayout(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a base text transform for this `EditText`, to be used for
|
/// Construct a base text transform for a particular `EditText` span.
|
||||||
/// evaluating fonts.
|
|
||||||
///
|
///
|
||||||
/// The `text_transform` constitutes the base transform that all text is
|
/// This `text_transform` is separate from and relative to the base
|
||||||
/// written into.
|
|
||||||
///
|
|
||||||
/// The `text_transform` is separate from and relative to the base
|
|
||||||
/// transform that this `EditText` automatically gets by virtue of being a
|
/// transform that this `EditText` automatically gets by virtue of being a
|
||||||
/// `DisplayObject`.
|
/// `DisplayObject`.
|
||||||
pub fn text_transform(self) -> Transform {
|
pub fn text_transform(self, color: swf::Color) -> Transform {
|
||||||
let edit_text = self.0.read();
|
|
||||||
let static_data = &edit_text.static_data;
|
|
||||||
|
|
||||||
// TODO: Many of these properties should change be instance members instead
|
|
||||||
// of static data, because they can be altered via ActionScript.
|
|
||||||
let color = static_data
|
|
||||||
.text
|
|
||||||
.color
|
|
||||||
.as_ref()
|
|
||||||
.unwrap_or_else(|| &swf::Color {
|
|
||||||
r: 0,
|
|
||||||
g: 0,
|
|
||||||
b: 0,
|
|
||||||
a: 255,
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut transform: Transform = Default::default();
|
let mut transform: Transform = Default::default();
|
||||||
transform.color_transform.r_mult = f32::from(color.r) / 255.0;
|
transform.color_transform.r_mult = f32::from(color.r) / 255.0;
|
||||||
transform.color_transform.g_mult = f32::from(color.g) / 255.0;
|
transform.color_transform.g_mult = f32::from(color.g) / 255.0;
|
||||||
|
@ -373,11 +353,11 @@ impl<'gc> EditText<'gc> {
|
||||||
// We're cheating a bit and not actually rendering text using the OS/web.
|
// We're cheating a bit and not actually rendering text using the OS/web.
|
||||||
// Instead, we embed an SWF version of Noto Sans to use as the "device font", and render
|
// Instead, we embed an SWF version of Noto Sans to use as the "device font", and render
|
||||||
// it the same as any other SWF outline text.
|
// it the same as any other SWF outline text.
|
||||||
if let Some((start, end, _tf, font, font_size)) = lbox.read().text_node() {
|
if let Some((start, end, _tf, font, font_size, color)) = lbox.read().text_node() {
|
||||||
if let Some(chunk) = edit_text.text_spans.text().get(start..end) {
|
if let Some(chunk) = edit_text.text_spans.text().get(start..end) {
|
||||||
font.evaluate(
|
font.evaluate(
|
||||||
&chunk,
|
&chunk,
|
||||||
self.text_transform(),
|
self.text_transform(color),
|
||||||
font_size,
|
font_size,
|
||||||
|transform, glyph: &Glyph| {
|
|transform, glyph: &Glyph| {
|
||||||
// Render glyph.
|
// Render glyph.
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub struct LayoutBox<'gc> {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Collect)]
|
#[derive(Clone, Debug, Collect)]
|
||||||
#[collect(require_static)]
|
#[collect(require_static)]
|
||||||
pub struct CollecTwips(Twips);
|
pub struct Collec<T>(T);
|
||||||
|
|
||||||
/// Represents different content modes of a given layout box.
|
/// Represents different content modes of a given layout box.
|
||||||
#[derive(Clone, Debug, Collect)]
|
#[derive(Clone, Debug, Collect)]
|
||||||
|
@ -138,7 +138,8 @@ pub enum LayoutContent<'gc> {
|
||||||
end: usize,
|
end: usize,
|
||||||
text_format: TextFormat,
|
text_format: TextFormat,
|
||||||
font: Font<'gc>,
|
font: Font<'gc>,
|
||||||
font_size: CollecTwips,
|
font_size: Collec<Twips>,
|
||||||
|
color: Collec<swf::Color>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +152,7 @@ impl<'gc> LayoutBox<'gc> {
|
||||||
text_format: TextFormat,
|
text_format: TextFormat,
|
||||||
font: Font<'gc>,
|
font: Font<'gc>,
|
||||||
font_size: Twips,
|
font_size: Twips,
|
||||||
|
color: swf::Color,
|
||||||
) -> GcCell<'gc, Self> {
|
) -> GcCell<'gc, Self> {
|
||||||
GcCell::allocate(
|
GcCell::allocate(
|
||||||
mc,
|
mc,
|
||||||
|
@ -162,7 +164,8 @@ impl<'gc> LayoutBox<'gc> {
|
||||||
end,
|
end,
|
||||||
text_format,
|
text_format,
|
||||||
font,
|
font,
|
||||||
font_size: CollecTwips(font_size),
|
font_size: Collec(font_size),
|
||||||
|
color: Collec(color),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -192,6 +195,7 @@ impl<'gc> LayoutBox<'gc> {
|
||||||
span.get_text_format(),
|
span.get_text_format(),
|
||||||
lc.font().unwrap(),
|
lc.font().unwrap(),
|
||||||
font_size,
|
font_size,
|
||||||
|
span.color.clone(),
|
||||||
);
|
);
|
||||||
let mut write = new_text.write(mc);
|
let mut write = new_text.write(mc);
|
||||||
|
|
||||||
|
@ -254,7 +258,7 @@ impl<'gc> LayoutBox<'gc> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to the text this box contains.
|
/// Returns a reference to the text this box contains.
|
||||||
pub fn text_node(&self) -> Option<(usize, usize, &TextFormat, Font<'gc>, Twips)> {
|
pub fn text_node(&self) -> Option<(usize, usize, &TextFormat, Font<'gc>, Twips, swf::Color)> {
|
||||||
match &self.content {
|
match &self.content {
|
||||||
LayoutContent::Text {
|
LayoutContent::Text {
|
||||||
start,
|
start,
|
||||||
|
@ -262,7 +266,15 @@ impl<'gc> LayoutBox<'gc> {
|
||||||
text_format,
|
text_format,
|
||||||
font,
|
font,
|
||||||
font_size,
|
font_size,
|
||||||
} => Some((*start, *end, &text_format, *font, font_size.0)),
|
color,
|
||||||
|
} => Some((
|
||||||
|
*start,
|
||||||
|
*end,
|
||||||
|
&text_format,
|
||||||
|
*font,
|
||||||
|
font_size.0,
|
||||||
|
color.0.clone(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue