mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Introduce a dedicated data structure for text queries
Add an IndexableText structure for text queries. Instead of linear search for a node this now uses a HashMap. Remove the now irrelevant fields from TextDisplayItem.
This commit is contained in:
parent
a5115139ba
commit
2d74bcfea5
6 changed files with 70 additions and 49 deletions
|
@ -20,15 +20,11 @@ use gfx_traits::{self, StackingContextId};
|
|||
use gfx_traits::print_tree::PrintTree;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::image::base::{Image, PixelFormat};
|
||||
use range::Range;
|
||||
use servo_geometry::MaxRect;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::f32;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use text::TextRun;
|
||||
use text::glyph::ByteIndex;
|
||||
use webrender_api::{BorderRadius, BorderWidths, BoxShadowClipMode, ClipMode, ColorF};
|
||||
use webrender_api::{ComplexClipRegion, ExtendMode, ExternalScrollId, FilterOp, FontInstanceKey};
|
||||
use webrender_api::{GlyphInstance, GradientStop, ImageBorder, ImageKey, ImageRendering};
|
||||
|
@ -103,25 +99,6 @@ impl DisplayList {
|
|||
}
|
||||
}
|
||||
|
||||
// Returns the text index within a node for the point of interest.
|
||||
pub fn text_index(&self, node: OpaqueNode, point_in_item: LayoutPoint) -> Option<usize> {
|
||||
for item in &self.list {
|
||||
match item {
|
||||
&DisplayItem::Text(ref text) => {
|
||||
let base = item.base();
|
||||
if base.metadata.node == node {
|
||||
let point = point_in_item + item.base().bounds.origin.to_vector();
|
||||
let offset = point - text.baseline_origin;
|
||||
return Some(text.text_run.range_index_of_advance(&text.range, offset.x));
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn print(&self) {
|
||||
let mut print_tree = PrintTree::new("Display List".to_owned());
|
||||
self.print_with_tree(&mut print_tree);
|
||||
|
@ -650,16 +627,6 @@ pub struct SolidColorDisplayItem {
|
|||
pub struct TextDisplayItem {
|
||||
/// Fields common to all display items.
|
||||
pub base: BaseDisplayItem,
|
||||
|
||||
/// The text run.
|
||||
#[ignore_malloc_size_of = "Because it is non-owning"]
|
||||
pub text_run: Arc<TextRun>,
|
||||
|
||||
/// The range of text within the text run.
|
||||
pub range: Range<ByteIndex>,
|
||||
|
||||
/// The position of the start of the baseline of this text.
|
||||
pub baseline_origin: LayoutPoint,
|
||||
/// A collection of (non-whitespace) glyphs to be displayed.
|
||||
pub glyphs: Vec<GlyphInstance>,
|
||||
/// Reference to the font to be used.
|
||||
|
|
|
@ -333,10 +333,10 @@ impl<'a> TextRun {
|
|||
}
|
||||
|
||||
/// Returns the index in the range of the first glyph advancing over given advance
|
||||
pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: f32) -> usize {
|
||||
pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: Au) -> usize {
|
||||
// TODO(Issue #199): alter advance direction for RTL
|
||||
// TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
|
||||
let mut remaining = Au::from_f32_px(advance);
|
||||
let mut remaining = advance;
|
||||
self.natural_word_slices_in_range(range)
|
||||
.map(|slice| {
|
||||
let (slice_index, slice_advance) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue