Created
July 8, 2015 14:37
-
-
Save jeremyroman/255e8b820c7d64479af1 to your computer and use it in GitHub Desktop.
SimpleShaperTest excerpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestFontSelector : public FontSelector { | |
public: | |
static PassRefPtr<TestFontSelector> create(const String& path) | |
{ | |
WebUnitTestSupport* unitTestSupport = Platform::current()->unitTestSupport(); | |
String filePath = unitTestSupport->webKitRootDir() + path; | |
RefPtr<SharedBuffer> fontBuffer = static_cast<PassRefPtr<SharedBuffer>>(unitTestSupport->readFromFile(filePath)); | |
return adoptRef(new TestFontSelector(FontCustomPlatformData::create(fontBuffer.get()))); | |
} | |
~TestFontSelector() override { } | |
// FontSelector methods | |
PassRefPtr<FontData> getFontData(const FontDescription& fontDescription, const AtomicString& familyName) override | |
{ | |
return SimpleFontData::create( | |
m_customPlatformData->fontPlatformData(fontDescription.effectiveFontSize(), | |
fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic(), | |
fontDescription.orientation()), CustomFontData::create()); | |
} | |
void willUseFontData(const FontDescription&, const AtomicString& familyName, UChar32) override { } | |
unsigned version() const override { return 0; } | |
// FontCacheClient methods | |
void fontCacheInvalidated() override { } | |
private: | |
TestFontSelector(PassOwnPtr<FontCustomPlatformData> customPlatformData) | |
: m_customPlatformData(customPlatformData) | |
{ | |
} | |
OwnPtr<FontCustomPlatformData> m_customPlatformData; | |
}; | |
Font createTestFont(const AtomicString& familyName, const String& fontPath, float size) | |
{ | |
FontFamily family; | |
family.setFamily(familyName); | |
FontDescription fontDescription; | |
fontDescription.setFamily(family); | |
fontDescription.setSpecifiedSize(size); | |
fontDescription.setComputedSize(size); | |
Font ahemFont(fontDescription); | |
ahemFont.update(TestFontSelector::create(fontPath)); | |
return ahemFont; | |
} | |
class SimpleShaperTest : public ::testing::Test { | |
protected: | |
SimpleShaperTest() | |
: m_ahemFont(createTestFont("Ahem", "/LayoutTests/resources/Ahem.woff", 20)) | |
{ | |
} | |
const Font& ahemFont() const { return m_ahemFont; } | |
private: | |
Font m_ahemFont; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment