-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
🤖 and 🪵 are rendered incorrectly it would seem #26
Comments
Hmm, weird, i tried running your code and there was no image generated.. (image.data was just empty) |
That is indeed quite odd; I'm running with the following Cargo.toml
I'm also running on Windows (as you can see by the font path), maybe that makes a difference? I just re-ran the code hoping it was potentially a version issue, but I'm getting a clean |
Digging in a bit, it's starting to look like some of the scaling code is incorrectly calculating the size of the image for colored outlines. Lines 914 to 921 in d3f8bbf
I don't think it's correct to take the very first @dfrg My current changes look like this; they still don't fully calculate the bounds correctly for either the 🪵 or the 🤖 emoji's but it's overall quite a bit better then before; I would love your input on this since I suspect some of the bounds calculations / offset calculations aren't fully correct yet. Source::ColorOutline(palette_index) => {
if !scaler.has_color_outlines() {
continue;
}
scaler.state.outline.clear();
if scaler.scale_color_outline_impl(glyph_id) {
let font = &scaler.font;
let proxy = &scaler.proxy;
let state = &mut scaler.state;
let scratch = &mut state.scratch0;
let rcx = &mut state.rcx;
let outline = &mut state.outline;
// Cool effect, but probably not generally desirable.
// Maybe expose a separate option?
// if self.embolden != 0. {
// outline.embolden(self.embolden, self.embolden);
// }
if let Some(transform) = &self.transform {
outline.transform(transform);
}
let palette = proxy.color.palette(font, *palette_index);
let mut base_x = i32::MAX;
let mut base_y = 0i32;
let mut base_w = 0u32;
let mut base_h = 0u32;
let mut ok = true;
for i in 0..outline.len() {
let layer = match outline.get(i) {
Some(layer) => layer,
_ => {
ok = false;
break;
}
};
scratch.clear();
let placement = Mask::with_scratch(layer.path(), rcx)
.origin(Origin::BottomLeft)
.style(self.style)
.render_offset(self.offset)
.inspect(|fmt, w, h| {
scratch.resize(fmt.buffer_size(w, h), 0);
})
.render_into(&mut scratch[..], None); // todo: don't need to rasterize twice just to get the placement, zeno has a helper function
base_x = base_x.min(placement.left);
base_y = base_y.max(placement.top);
base_w = base_w.max(placement.width);
base_h = base_h.max(placement.height);
image.data.resize((base_w * base_h * 4) as usize, 0);
}
for i in 0..outline.len() {
let layer = match outline.get(i) {
Some(layer) => layer,
_ => {
ok = false;
break;
}
};
scratch.clear();
let placement = Mask::with_scratch(layer.path(), rcx)
.origin(Origin::BottomLeft)
.style(self.style)
.render_offset(self.offset)
.inspect(|fmt, w, h| {
scratch.resize(fmt.buffer_size(w, h), 0);
})
.render_into(&mut scratch[..], None);
//base_x = placement.left;
//base_y = placement.top;
//if i == 0 {
// base_w = placement.width;
// base_h = placement.height;
image.data.resize((base_w * base_h * 4) as usize, 0);
image.placement = placement;
image.placement.width = base_w;
image.placement.height = base_h;
//}
dbg!(placement);
let color = layer
.color_index()
.map(|i| palette.map(|p| p.get(i)))
.flatten()
.unwrap_or(self.foreground);
bitmap::blit(
&scratch[..],
placement.width,
placement.height,
placement.left.wrapping_sub(base_x),
base_y.wrapping_sub(placement.top),
color,
&mut image.data,
base_w,
base_h,
);
}
if ok {
image.source = Source::ColorOutline(*palette_index);
image.content = Content::Color;
return true;
}
}
} |
Checking it a bit further, it seems like either implementation is out of spec for ignoring the clipbox; https://learn.microsoft.com/en-us/typography/opentype/spec/colr#metrics-and-boundedness-of-color-glyphs-using-version-1-formats |
Hi Jasper! I’ll take a look at this soon. One note is that ClipBox is specifically for COLRv1 which swash does not currently support. When this was written, I believe the base layer was supposed to determine image boundaries for the full glyph. In any case, I’ll dig into those particular glyphs and see if I can find out what’s going on. In the worst case, we take the union of the bounding box of all layers and that should give us appropriate dimensions. |
The PR that I filed does this already (I hope correctly). Thanks for taking a look |
Fixed by #30 |
Repro case
It looks like both of these render partially (I haven't tried many more, however 🔥 from the documentation seems to render correctly). The robot-man seems to have his mouth cut off, and the log seems to have the top cut off.
Since this is my very first time diving into this library, I may well be doing something wrong. I've attached the repro of what I'm trying to do.
I've also attached the rendered image below;
The text was updated successfully, but these errors were encountered: