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

separate generate_font_key from add_raw_font/add_native_font to allow… #912

Merged
merged 3 commits into from Feb 22, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

separate generate_font_key from add_raw_font/add_native_font to allow…

… for custom font key generation
  • Loading branch information
lsalzman committed Feb 22, 2017
commit 54ee53a6b7920efef9efa78c224306288a5981ef
@@ -194,8 +194,9 @@ fn main() {


if false { // draw text?
let font_key = api.generate_font_key();
let font_bytes = load_file("res/FreeSans.ttf");
let font_key = api.add_raw_font(font_bytes);
api.add_raw_font(font_key, font_bytes);

let text_bounds = LayoutRect::new(LayoutPoint::new(100.0, 200.0), LayoutSize::new(700.0, 300.0));

@@ -54,20 +54,19 @@ impl RenderApi {
RenderApiSender::new(self.api_sender.clone(), self.payload_sender.clone())
}

pub fn add_raw_font(&self, bytes: Vec<u8>) -> FontKey {
pub fn generate_font_key(&self) -> FontKey {
let new_id = self.next_unique_id();
let key = FontKey::new(new_id.0, new_id.1);
FontKey::new(new_id.0, new_id.1)
}

pub fn add_raw_font(&self, key: FontKey, bytes: Vec<u8>) {
let msg = ApiMsg::AddRawFont(key, bytes);
self.api_sender.send(msg).unwrap();
key
}

pub fn add_native_font(&self, native_font_handle: NativeFontHandle) -> FontKey {
let new_id = self.next_unique_id();
let key = FontKey::new(new_id.0, new_id.1);
pub fn add_native_font(&self, key: FontKey, native_font_handle: NativeFontHandle) {
let msg = ApiMsg::AddNativeFont(key, native_font_handle);
self.api_sender.send(msg).unwrap();
key
}

/// Gets the dimensions for the supplied glyph keys
@@ -235,7 +235,9 @@ impl Wrench {

#[cfg(target_os = "windows")]
pub fn font_key_from_native_handle(&mut self, descriptor: &NativeFontHandle) -> FontKey {
self.api.add_native_font(descriptor.clone())
let key = self.api.generate_font_key();
self.api.add_native_font(key, descriptor.clone());
key
}

#[cfg(target_os = "windows")]
@@ -246,8 +248,7 @@ impl Wrench {
dwrote::FontStretch::Normal,
dwrote::FontStyle::Normal);
let descriptor = font.to_descriptor();
let key = self.api.add_native_font(descriptor.clone());
(key, Some(descriptor))
(self.font_key_from_native_handle(&descriptor), Some(descriptor))
}

#[cfg(target_os = "windows")]
@@ -281,7 +282,8 @@ impl Wrench {
}

pub fn font_key_from_bytes(&mut self, bytes: Vec<u8>) -> (FontKey, Option<NativeFontHandle>) {
let key = self.api.add_raw_font(bytes);
let key = self.api.generate_font_key();
self.api.add_raw_font(key, bytes);
(key, None)
}

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