Implement `color` on spans
This commit is contained in:
parent
9bcc7ef0cc
commit
e3f59ac00f
|
@ -264,32 +264,12 @@ impl<'gc> EditText<'gc> {
|
|||
self.relayout(context);
|
||||
}
|
||||
|
||||
/// Construct a base text transform for this `EditText`, to be used for
|
||||
/// evaluating fonts.
|
||||
/// Construct a base text transform for a particular `EditText` span.
|
||||
///
|
||||
/// The `text_transform` constitutes the base transform that all text is
|
||||
/// written into.
|
||||
///
|
||||
/// The `text_transform` is separate from and relative to the base
|
||||
/// This `text_transform` is separate from and relative to the base
|
||||
/// transform that this `EditText` automatically gets by virtue of being a
|
||||
/// `DisplayObject`.
|
||||
pub fn text_transform(self) -> 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,
|
||||
});
|
||||
|
||||
pub fn text_transform(self, color: swf::Color) -> Transform {
|
||||
let mut transform: Transform = Default::default();
|
||||
transform.color_transform.r_mult = f32::from(color.r) / 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.
|
||||
// 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.
|
||||
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) {
|
||||
font.evaluate(
|
||||
&chunk,
|
||||
self.text_transform(),
|
||||
self.text_transform(color),
|
||||
font_size,
|
||||
|transform, glyph: &Glyph| {
|
||||
// Render glyph.
|
||||
|
|
|
@ -123,7 +123,7 @@ pub struct LayoutBox<'gc> {
|
|||
|
||||
#[derive(Clone, Debug, Collect)]
|
||||
#[collect(require_static)]
|
||||
pub struct CollecTwips(Twips);
|
||||
pub struct Collec<T>(T);
|
||||
|
||||
/// Represents different content modes of a given layout box.
|
||||
#[derive(Clone, Debug, Collect)]
|
||||
|
@ -138,7 +138,8 @@ pub enum LayoutContent<'gc> {
|
|||
end: usize,
|
||||
text_format: TextFormat,
|
||||
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,
|
||||
font: Font<'gc>,
|
||||
font_size: Twips,
|
||||
color: swf::Color,
|
||||
) -> GcCell<'gc, Self> {
|
||||
GcCell::allocate(
|
||||
mc,
|
||||
|
@ -162,7 +164,8 @@ impl<'gc> LayoutBox<'gc> {
|
|||
end,
|
||||
text_format,
|
||||
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(),
|
||||
lc.font().unwrap(),
|
||||
font_size,
|
||||
span.color.clone(),
|
||||
);
|
||||
let mut write = new_text.write(mc);
|
||||
|
||||
|
@ -254,7 +258,7 @@ impl<'gc> LayoutBox<'gc> {
|
|||
}
|
||||
|
||||
/// 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 {
|
||||
LayoutContent::Text {
|
||||
start,
|
||||
|
@ -262,7 +266,15 @@ impl<'gc> LayoutBox<'gc> {
|
|||
text_format,
|
||||
font,
|
||||
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