-
Notifications
You must be signed in to change notification settings - Fork 67
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
Making some internal fields public and allow serialisation of the OwnedFace type. #103
Comments
|
@RazrFalcon thank you so much for the answers! As all of your questions are connected, let me reply not in points, starting with a short description of the use case I have here. Use caseFrom legal reasons, we cannot ship the whole font representation in our app. So what I want to do is to parse the font, generate SDF representation of chosen glyphs, remove the glyph info from the font binary data, and serialise to disk the changed binary font data and the SDF glyph atlas (this will be our custom "font file" that we will be shipping with the app). This way, we will have a binary data containing helper info (such as the kerning table) + glyph atlases but without exact glyph shapes (with zeroed values in the OwnedFace issue (not really important here)Right now, I'm converting the This library issuesRegarding pub fn remove_glyph_data(&mut self) {
mem::take(&mut self.msdf_font);
let data_slice = &self.data[..]; // This is original `Vec<u8>`.
if let Ok(font_face) = ttf::RawFace::from_slice(data_slice, FONT_FACE_NUMBER) {
if let Some(glyph_table) = font_face.table(ttf::Tag::from_bytes(b"glyf")) {
let glyph_table_ptr = glyph_table.as_ptr();
let data_ptr = data_slice.as_ptr();
// Safety: This is safe, as both pointers refer to the same slice.
let start_index = unsafe { glyph_table_ptr.offset_from(data_ptr) };
for offset in 0..glyph_table.len() {
self.data[start_index as usize + offset] = 0;
}
}
}
if let Ok(font_face) = ttf::OwnedFace::from_vec(self.data.clone(), FONT_FACE_NUMBER) {
self.font_face = font_face;
}
} What I don't like in the code above is the operation duplication. I already have |
Ok, I understand the idea.
|
@RazrFalcon thanks so much for super fast answer!
|
You can also try ttf-explorer. This would help understanding the font format layout better. |
@RazrFalcon Again, thanks for fast reply!
Thank you once again for all replies and your help! |
Glad to hear. Ok, I will think about exposing |
I would be really thankful for doing it!! ❤️ |
You can access this data using: if let Some(record) = face.raw_face().table_records.into_iter().find(|r| r.tag == Tag::from_bytes(b"glyf")) {
println!("{:?}", record); // TableRecord { tag: Tag(glyf), check_sum: 3391114546, offset: 28780, length: 105582 }
} |
Hi! I'm using the
OwnedFace
type and I have several needs that sound like something more people could use:I'd like to access the information on where the
glyf::Table
data starts and where it ends. Would it be possible to either add an accessor to get reference to theglyf::Table::data
or make it public?I'm using the
OwnedFace
and I want to generate SDF representation of glyphs based on the binary data contained in it. I don't want to duplicate it, but unfortunately theSelfRefVecFace::data
is private. Can we add accessor for this field, please?Would it be possible to have
serde::Serialize
andserde::Deserialize
derives forOwnedFace
? Of course, this could be put behind a compilation flag. If we have an owned type, it seems that serialising / deserialising it may be a popular use case.The text was updated successfully, but these errors were encountered: