mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #13414 - flacerdk:master, r=mbrubeck
Implement `word-break: keep-all` (#9673) <!-- Please describe your changes on the following line: --> Implement the `keep-all` value for the `word-break` property, as specified in [CSS](https://drafts.csswg.org/css-text-3/#word-break-property). The relevant CSSWG tests (in `tests/wpt/css-tests/css-text-3_dev/html/word-break-keep-all-*.htm`) do not currently pass. As far as I can tell, this is because the tests use some JavaScript code that is not working properly. (But then, it seems that most tests in this directory are failing at the moment. I'm not sure what can be done here for now.) --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #9673. <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13414) <!-- Reviewable:end -->
This commit is contained in:
commit
c9442346d3
15 changed files with 282 additions and 13 deletions
|
@ -148,6 +148,8 @@ bitflags! {
|
|||
const DISABLE_KERNING_SHAPING_FLAG = 0x04,
|
||||
#[doc = "Text direction is right-to-left."]
|
||||
const RTL_FLAG = 0x08,
|
||||
#[doc = "Set if word-break is set to keep-all."]
|
||||
const KEEP_ALL_FLAG = 0x10,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use app_units::Au;
|
||||
use font::{Font, FontHandleMethods, FontMetrics, IS_WHITESPACE_SHAPING_FLAG, RunMetrics};
|
||||
use font::ShapingOptions;
|
||||
use font::{Font, FontHandleMethods, FontMetrics, IS_WHITESPACE_SHAPING_FLAG, KEEP_ALL_FLAG};
|
||||
use font::{RunMetrics, ShapingOptions};
|
||||
use platform::font_template::FontTemplateData;
|
||||
use range::Range;
|
||||
use std::cell::Cell;
|
||||
|
@ -206,11 +206,14 @@ impl<'a> TextRun {
|
|||
// Split off any trailing whitespace into a separate glyph run.
|
||||
let mut whitespace = slice.end..slice.end;
|
||||
if let Some((i, _)) = word.char_indices().rev()
|
||||
.take_while(|&(_, c)| char_is_whitespace(c)).last() {
|
||||
whitespace.start = slice.start + i;
|
||||
slice.end = whitespace.start;
|
||||
}
|
||||
|
||||
.take_while(|&(_, c)| char_is_whitespace(c)).last() {
|
||||
whitespace.start = slice.start + i;
|
||||
slice.end = whitespace.start;
|
||||
} else if idx != text.len() && options.flags.contains(KEEP_ALL_FLAG) {
|
||||
// If there's no whitespace and word-break is set to
|
||||
// keep-all, try increasing the slice.
|
||||
continue;
|
||||
}
|
||||
if slice.len() > 0 {
|
||||
glyphs.push(GlyphRun {
|
||||
glyph_store: font.shape_text(&text[slice.clone()], options),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue