Comments (7)
Hmm, weird, i tried running your code and there was no image generated.. (image.data was just empty)
from swash.
That is indeed quite odd; I'm running with the following Cargo.toml
[package]
name = "swash-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
swash = "0.1.4"
zeno = "0.2"
image = "0.24"
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 stuff.png
image generated which looks identical to the image I've attached here.
from swash.
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 placement
as the final image's total size, I have some local modifications that calculate the sizes and offsets beforehand but it's not quite correct yet (and to be a bit faster would need some minor changes to zeno
to make some functions public). I'll play around with this some more to see if I can figure out the correct logic, though having a spec handy to compare to would be nice, so if anyone has a relevant link for me I'd love to take a look.
@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;
}
}
}
from swash.
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
from swash.
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.
from swash.
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
from swash.
Fixed by #30
from swash.
Related Issues (20)
- Subpixel Format Rendering? HOT 2
- Extract text analysis code into separate crate HOT 1
- Add support for COLRv1 HOT 1
- Implement a reference rasterizer for COLRv1 outlines HOT 2
- expose the panose subfield for detecting the GenericFamily in fount HOT 1
- Testing swash
- Some fonts are rasterised very small
- Cannot render `U+1FB87 : RIGHT ONE QUARTER BLOCK` HOT 1
- i is not rendered properly when using JetBrains Mono HOT 1
- Support for CFF seac / enchar
- Rust Nightly 4-1-2023 and forward breaks swash. HOT 2
- Use ttf-parser for font parsing HOT 5
- How is unicode_data.rs generated? HOT 1
- "Panic: misaligned pointer reference" in rustc 1.70.0 HOT 3
- CharMap does not include substitutions
- Expose public C/C++ API
- Documentation: what does "code units" means? HOT 1
- crate-private type `Outlines<'_>` in public interface HOT 8
- Is it possiable using [png](https://lib.rs/crates/png) for decode emoji png? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swash.