Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / fonts / TestFontSelector.h
blob044b188cc55f1298844d7b9ffba9fc4aa923d344
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef TestFontSelector_h
32 #define TestFontSelector_h
34 #include "platform/fonts/FontCustomPlatformData.h"
35 #include "platform/fonts/FontSelector.h"
36 #include "public/platform/Platform.h"
37 #include "public/platform/WebUnitTestSupport.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefPtr.h"
40 #include "wtf/text/AtomicString.h"
42 namespace blink {
44 class TestFontSelector : public FontSelector {
45 public:
46 static PassRefPtrWillBeRawPtr<TestFontSelector> create(const String& path)
48 WebUnitTestSupport* unitTestSupport = Platform::current()->
49 unitTestSupport();
50 RefPtr<SharedBuffer> fontBuffer = static_cast<PassRefPtr<SharedBuffer>>(
51 unitTestSupport->readFromFile(path));
52 String otsParseMessage;
53 return adoptRefWillBeNoop(new TestFontSelector(FontCustomPlatformData::create(
54 fontBuffer.get(), otsParseMessage)));
57 ~TestFontSelector() override { }
59 PassRefPtr<FontData> getFontData(const FontDescription& fontDescription,
60 const AtomicString& familyName) override
62 FontPlatformData platformData = m_customPlatformData->fontPlatformData(
63 fontDescription.effectiveFontSize(),
64 fontDescription.isSyntheticBold(),
65 fontDescription.isSyntheticItalic(),
66 fontDescription.orientation());
67 return SimpleFontData::create(platformData, CustomFontData::create());
70 void willUseFontData(const FontDescription&, const AtomicString& familyName,
71 UChar32) override { }
72 unsigned version() const override { return 0; }
73 void fontCacheInvalidated() override { }
75 private:
76 TestFontSelector(PassOwnPtr<FontCustomPlatformData> customPlatformData)
77 : m_customPlatformData(customPlatformData)
81 OwnPtr<FontCustomPlatformData> m_customPlatformData;
84 Font createTestFont(const AtomicString& familyName,
85 const String& fontPath, float size = 16.0f)
87 FontFamily family;
88 family.setFamily(familyName);
90 FontDescription fontDescription;
91 fontDescription.setFamily(family);
92 fontDescription.setSpecifiedSize(size);
93 fontDescription.setComputedSize(size);
95 Font font(fontDescription);
96 font.update(TestFontSelector::create(fontPath));
97 return font;
100 } // namespace blink
102 #endif // TestFontSelector_h