Use byte indices instead of char indices for text runs

Replace character indices with UTF-8 byte offsets throughout the code dealing
with text shaping and breaking.  This eliminates a lot of complexity when
converting from one to the other, and interoperates better with the rest of
the Rust ecosystem.
This commit is contained in:
Matt Brubeck 2016-04-27 11:22:02 -07:00
parent dba878dfb2
commit 659305fe0a
15 changed files with 259 additions and 437 deletions

View file

@ -33,7 +33,7 @@ use std::default::Default;
use std::{f32, mem, ptr};
use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode};
use text::TextRun;
use text::glyph::CharIndex;
use text::glyph::ByteIndex;
use util::geometry::{self, MAX_RECT, PagePx, ScreenPx};
use util::opts;
@ -1768,7 +1768,7 @@ trait ScaledFontExtensionMethods {
fn draw_text(&self,
draw_target: &DrawTarget,
run: &TextRun,
range: &Range<CharIndex>,
range: &Range<ByteIndex>,
baseline_origin: Point2D<Au>,
color: Color,
antialias: bool);
@ -1779,7 +1779,7 @@ impl ScaledFontExtensionMethods for ScaledFont {
fn draw_text(&self,
draw_target: &DrawTarget,
run: &TextRun,
range: &Range<CharIndex>,
range: &Range<ByteIndex>,
baseline_origin: Point2D<Au>,
color: Color,
antialias: bool) {
@ -1795,11 +1795,10 @@ impl ScaledFontExtensionMethods for ScaledFont {
};
let mut origin = baseline_origin.clone();
let mut azglyphs = vec!();
azglyphs.reserve(range.length().to_usize());
let mut azglyphs = Vec::with_capacity(range.length().to_usize());
for slice in run.natural_word_slices_in_visual_order(range) {
for glyph in slice.glyphs.iter_glyphs_for_char_range(&slice.range) {
for glyph in slice.glyphs.iter_glyphs_for_byte_range(&slice.range) {
let glyph_advance = glyph.advance();
let glyph_offset = glyph.offset().unwrap_or(Point2D::zero());
let azglyph = struct__AzGlyph {