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

Fix intermittent macOS reftest failures #24347

Merged
merged 1 commit into from Oct 3, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3,19 +3,27 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use app_units::Au;
use core_foundation::array::CFArray;
use core_foundation::base::{CFType, TCFType};
use core_foundation::dictionary::CFDictionary;
use core_foundation::number::CFNumber;
use core_foundation::string::CFString;
use core_graphics::data_provider::CGDataProvider;
use core_graphics::font::CGFont;
use core_text::font::CTFont;
use core_text::font_collection;
use core_text::font_descriptor;
use serde::de::{Error, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use servo_atoms::Atom;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::collections::HashMap;
use std::fmt;
use std::fs::File;
use std::fs::{self, File};
use std::io::{Error as IoError, Read};
use std::ops::Deref;
use std::path::Path;
use std::sync::{Arc, Mutex};
use webrender_api::NativeFontHandle;

@@ -86,7 +94,40 @@ impl FontTemplateData {
Err(_) => None,
}
},
None => core_text::font::new_from_name(&*self.identifier, clamped_pt_size).ok(),
None => {

This comment has been minimized.

Copy link
@pcwalton

pcwalton Oct 2, 2019

Contributor

Add a comment linking to the issue. r=me with that.

// We can't rely on Core Text to load a font for us by postscript
// name here, due to https://github.com/servo/servo/issues/23290.
// The APIs will randomly load the wrong font, forcing us to use
// the roundabout route of creating a Core Graphics font from a
// a set of descriptors and then creating a Core Text font from
// that one.

let attributes: CFDictionary<CFString, CFType> =
CFDictionary::from_CFType_pairs(&[
(
CFString::new("NSFontNameAttribute"),
CFString::new(&*self.identifier).as_CFType(),
),
(
CFString::new("NSFontSizeAttribute"),
CFNumber::from(clamped_pt_size).as_CFType(),
),
]);

let descriptor = font_descriptor::new_from_attributes(&attributes);
let descriptors = CFArray::from_CFTypes(&[descriptor]);
let collection = font_collection::new_from_descriptors(&descriptors);
collection.get_descriptors().and_then(|descriptors| {
let descriptor = descriptors.get(0).unwrap();
let font_path = Path::new(&descriptor.font_path().unwrap()).to_owned();
fs::read(&font_path).ok().and_then(|bytes| {
let fontprov = CGDataProvider::from_buffer(Arc::new(bytes));
CGFont::from_data_provider(fontprov).ok().map(|cgfont| {
core_text::font::new_from_CGFont(&cgfont, clamped_pt_size)
})
})
})
},
};
if let Some(ctfont) = ctfont {
ctfonts.insert(pt_size_key, ctfont);
@@ -1,4 +1,3 @@
[word-break-normal-bo-000.html]
type: reftest
expected:
if os == "linux": FAIL
expected: FAIL
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.