Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support glyph transforms for writing modes #2288

Merged
merged 2 commits into from Jan 15, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

add reftest for vertical writing modes

  • Loading branch information
lsalzman committed Jan 12, 2018
commit 61036d0487adede0d7b0582cd95f0615b76ca54e
@@ -117,7 +117,6 @@ fn get_glyph_metrics(

if let Some(transform) = transform {
bounds = bounds.apply_transform(transform);
advance = advance.apply_transform(transform);
}

// First round out to pixel boundaries
@@ -49,3 +49,4 @@ platform(linux) == subpixel-skew.yaml subpixel-skew.png
platform(linux) == embedded-bitmaps.yaml embedded-bitmaps.png
platform(linux) == clipped-transform.yaml clipped-transform.png
platform(mac) == color-bitmap-shadow.yaml color-bitmap-shadow-ref.yaml
platform(linux) == writing-modes.yaml writing-modes-ref.yaml
@@ -0,0 +1,19 @@
root:
items:
- type: stacking-context
bounds: [0, 0, 300, 60]
transform: rotate(90) translate(-120, 160)
items:
- text: "This is sideways-left"
origin: 0 40
size: 20
font: "FreeSans.ttf"
- type: stacking-context
bounds: [0, 0, 300, 60]
transform: rotate(-90) translate(-90, 120)
items:
- text: "This is sideways-right"
origin: 0 40
size: 20
font: "FreeSans.ttf"

@@ -0,0 +1,15 @@
root:
items:
- text: "This is sideways-left"
origin: 20 40
size: 20
transpose: true
flip-x: true
font: "FreeSans.ttf"
- text: "This is sideways-right"
origin: 70 300
size: 20
transpose: true
flip-y: true
font: "FreeSans.ttf"

@@ -260,6 +260,7 @@ impl Wrench {
text: &str,
size: Au,
origin: LayerPoint,
flags: FontInstanceFlags,
) -> (Vec<u32>, Vec<LayerPoint>, LayoutRect) {
// Map the string codepoints to glyph indices in this font.
// Just drop any glyph that isn't present in this font.
@@ -287,26 +288,36 @@ impl Wrench {
let mut bounding_rect = LayoutRect::zero();
let mut positions = Vec::new();

let mut x = origin.x;
let y = origin.y;
let mut cursor = origin;
let direction = if flags.contains(FontInstanceFlags::TRANSPOSE) {
LayerVector2D::new(
0.0,
if flags.contains(FontInstanceFlags::FLIP_Y) { -1.0 } else { 1.0 },
)
} else {
LayerVector2D::new(
if flags.contains(FontInstanceFlags::FLIP_X) { -1.0 } else { 1.0 },
0.0,
)
};
for metric in metrics {
positions.push(LayerPoint::new(x, y));
positions.push(cursor);

match metric {
Some(metric) => {
let glyph_rect = LayoutRect::new(
LayoutPoint::new(x + metric.left as f32, y - metric.top as f32),
LayoutPoint::new(cursor.x + metric.left as f32, cursor.y - metric.top as f32),
LayoutSize::new(metric.width as f32, metric.height as f32)
);
bounding_rect = bounding_rect.union(&glyph_rect);
x += metric.advance;
cursor += direction * metric.advance;
}
None => {
// Extract the advances from the metrics. The get_glyph_dimensions API
// has a limitation that it can't currently get dimensions for non-renderable
// glyphs (e.g. spaces), so just use a rough estimate in that case.
let space_advance = size.to_f32_px() / 3.0;
x += space_advance;
cursor += direction * space_advance;
}
}
}
@@ -195,7 +195,7 @@ pub struct YamlFrameReader {
image_map: HashMap<(PathBuf, Option<i64>), (ImageKey, LayoutSize)>,

fonts: HashMap<FontDescriptor, FontKey>,
font_instances: HashMap<(FontKey, Au), FontInstanceKey>,
font_instances: HashMap<(FontKey, Au, FontInstanceFlags), FontInstanceKey>,
font_render_mode: Option<FontRenderMode>,
}

@@ -461,7 +461,7 @@ impl YamlFrameReader {
let font_render_mode = self.font_render_mode;

*self.font_instances
.entry((font_key, size))
.entry((font_key, size, flags))
.or_insert_with(|| {
wrench.add_font_instance(
font_key,
@@ -1023,6 +1023,15 @@ impl YamlFrameReader {
if item["embedded-bitmaps"].as_bool().unwrap_or(false) {
flags |= FontInstanceFlags::EMBEDDED_BITMAPS;
}
if item["transpose"].as_bool().unwrap_or(false) {
flags |= FontInstanceFlags::TRANSPOSE;
}
if item["flip-x"].as_bool().unwrap_or(false) {
flags |= FontInstanceFlags::FLIP_X;
}
if item["flip-y"].as_bool().unwrap_or(false) {
flags |= FontInstanceFlags::FLIP_Y;
}

assert!(
item["blur-radius"].is_badvalue(),
@@ -1082,6 +1091,7 @@ impl YamlFrameReader {
text,
size,
origin,
flags,
);

let glyphs = glyph_indices
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.