mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
layout: Perform text decoration propagation per CSS 2.1 § 16.3.1 without
going to the DOM.
This commit is contained in:
parent
7b3c3542a3
commit
a2e91d242b
13 changed files with 215 additions and 63 deletions
|
@ -92,12 +92,38 @@ pub struct SolidColorDisplayItem<E> {
|
|||
|
||||
/// Renders text.
|
||||
pub struct TextDisplayItem<E> {
|
||||
/// Fields common to all display items.
|
||||
base: BaseDisplayItem<E>,
|
||||
|
||||
/// The text run.
|
||||
text_run: Arc<~TextRun>,
|
||||
|
||||
/// The range of text within the text run.
|
||||
range: Range,
|
||||
|
||||
/// The color of the text.
|
||||
color: Color,
|
||||
|
||||
/// A bitfield of flags for text display items.
|
||||
flags: TextDisplayItemFlags,
|
||||
}
|
||||
|
||||
/// Flags for text display items.
|
||||
pub struct TextDisplayItemFlags(u8);
|
||||
|
||||
impl TextDisplayItemFlags {
|
||||
pub fn new() -> TextDisplayItemFlags {
|
||||
TextDisplayItemFlags(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Whether underlining is forced on.
|
||||
bitfield!(TextDisplayItemFlags, override_underline, set_override_underline, 0x01)
|
||||
// Whether overlining is forced on.
|
||||
bitfield!(TextDisplayItemFlags, override_overline, set_override_overline, 0x02)
|
||||
// Whether line-through is forced on.
|
||||
bitfield!(TextDisplayItemFlags, override_line_through, set_override_line_through, 0x04)
|
||||
|
||||
/// Renders an image.
|
||||
pub struct ImageDisplayItem<E> {
|
||||
base: BaseDisplayItem<E>,
|
||||
|
@ -184,18 +210,18 @@ impl<E> DisplayItem<E> {
|
|||
let strikeout_size = font_metrics.strikeout_size;
|
||||
let strikeout_offset = font_metrics.strikeout_offset;
|
||||
|
||||
if text_run.decoration.underline {
|
||||
if text_run.decoration.underline || text.flags.override_underline() {
|
||||
let underline_y = baseline_origin.y - underline_offset;
|
||||
let underline_bounds = Rect(Point2D(baseline_origin.x, underline_y),
|
||||
Size2D(width, underline_size));
|
||||
render_context.draw_solid_color(&underline_bounds, text.color);
|
||||
}
|
||||
if text_run.decoration.overline {
|
||||
if text_run.decoration.overline || text.flags.override_overline() {
|
||||
let overline_bounds = Rect(Point2D(baseline_origin.x, origin.y),
|
||||
Size2D(width, underline_size));
|
||||
render_context.draw_solid_color(&overline_bounds, text.color);
|
||||
}
|
||||
if text_run.decoration.line_through {
|
||||
if text_run.decoration.line_through || text.flags.override_line_through() {
|
||||
let strikeout_y = baseline_origin.y - strikeout_offset;
|
||||
let strikeout_bounds = Rect(Point2D(baseline_origin.x, strikeout_y),
|
||||
Size2D(width, strikeout_size));
|
||||
|
|
|
@ -40,6 +40,10 @@ pub use gfx_font_list = font_list;
|
|||
pub use servo_gfx_font = font;
|
||||
pub use servo_gfx_font_list = font_list;
|
||||
|
||||
// Macros
|
||||
mod macros;
|
||||
|
||||
// Private rendering modules
|
||||
mod render_context;
|
||||
|
||||
// Rendering
|
||||
|
|
22
src/components/gfx/macros.rs
Normal file
22
src/components/gfx/macros.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[macro_escape];
|
||||
|
||||
macro_rules! bitfield(
|
||||
($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
|
||||
impl $bitfieldname {
|
||||
#[inline]
|
||||
pub fn $getter(self) -> bool {
|
||||
(*self & $value) != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn $setter(&mut self, value: bool) {
|
||||
*self = $bitfieldname((**self & !$value) | (if value { $value } else { 0 }))
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue