OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007 Apple Computer, Inc. | |
3 * Copyright (c) 2007, 2008, 2009, Google Inc. All rights reserved. | |
4 * Copyright (C) 2010 Company 100, Inc. | |
5 * | |
6 * Redistribution and use in source and binary forms, with or without | |
7 * modification, are permitted provided that the following conditions are | |
8 * met: | |
9 * | |
10 * * Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * * Redistributions in binary form must reproduce the above | |
13 * copyright notice, this list of conditions and the following disclaimer | |
14 * in the documentation and/or other materials provided with the | |
15 * distribution. | |
16 * * Neither the name of Google Inc. nor the names of its | |
17 * contributors may be used to endorse or promote products derived from | |
18 * this software without specific prior written permission. | |
19 * | |
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 */ | |
32 | |
33 #include "config.h" | |
34 #include "platform/fonts/FontCustomPlatformData.h" | |
35 | |
36 #include "platform/LayoutTestSupport.h" | |
37 #include "platform/SharedBuffer.h" | |
38 #include "platform/fonts/FontCache.h" | |
39 #include "platform/fonts/FontPlatformData.h" | |
40 #include "platform/fonts/opentype/OpenTypeSanitizer.h" | |
41 #include "third_party/skia/include/core/SkStream.h" | |
42 #include "third_party/skia/include/core/SkTypeface.h" | |
43 #include "wtf/PassOwnPtr.h" | |
44 | |
45 namespace blink { | |
46 | |
47 FontCustomPlatformData::FontCustomPlatformData(PassRefPtr<SkTypeface> typeface) | |
48 : m_typeface(typeface) { }; | |
49 | |
50 FontCustomPlatformData::~FontCustomPlatformData() | |
51 { | |
52 } | |
53 | |
54 FontPlatformData FontCustomPlatformData::fontPlatformData(float size, bool bold,
bool italic, FontOrientation orientation) | |
55 { | |
56 ASSERT(m_typeface); | |
57 #if OS(WIN) | |
58 if (!FontCache::useDirectWrite()) { | |
59 // FIXME: Skia currently renders synthetic bold and italics with | |
60 // hinting and without linear metrics on the windows GDI backend | |
61 // while the DirectWrite backend does the right thing. Using | |
62 // CreateFromName and specifying the bold/italics style allows | |
63 // for proper rendering of synthetic style. Once Skia has been | |
64 // updated this workaround will no longer be needed. | |
65 // http://crbug.com/332958 | |
66 bool syntheticBold = bold && !m_typeface->isBold(); | |
67 bool syntheticItalic = italic && !m_typeface->isItalic(); | |
68 if (syntheticBold || syntheticItalic) { | |
69 SkString name; | |
70 m_typeface->getFamilyName(&name); | |
71 | |
72 int style = SkTypeface::kNormal; | |
73 if (syntheticBold) | |
74 style |= SkTypeface::kBold; | |
75 if (syntheticItalic) | |
76 style |= SkTypeface::kItalic; | |
77 | |
78 RefPtr<SkTypeface> typeface = adoptRef(FontCache::fontCache()->fontM
anager()->legacyCreateTypeface(name.c_str(), static_cast<SkTypeface::Style>(styl
e))); | |
79 syntheticBold = false; | |
80 syntheticItalic = false; | |
81 return FontPlatformData(typeface.release(), "", size, syntheticBold,
syntheticItalic, orientation); | |
82 } | |
83 } | |
84 #endif | |
85 return FontPlatformData(m_typeface.get(), "", size, bold && !m_typeface->isB
old(), italic && !m_typeface->isItalic(), orientation); | |
86 } | |
87 | |
88 PassOwnPtr<FontCustomPlatformData> FontCustomPlatformData::create(SharedBuffer*
buffer) | |
89 { | |
90 ASSERT_ARG(buffer, buffer); | |
91 | |
92 OpenTypeSanitizer sanitizer(buffer); | |
93 RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize(); | |
94 if (!transcodeBuffer) | |
95 return nullptr; // validation failed. | |
96 buffer = transcodeBuffer.get(); | |
97 | |
98 SkMemoryStream* stream = new SkMemoryStream(buffer->getAsSkData().get()); | |
99 #if OS(WIN) | |
100 RefPtr<SkTypeface> typeface = adoptRef(FontCache::fontCache()->fontManager()
->createFromStream(stream)); | |
101 #else | |
102 RefPtr<SkTypeface> typeface = adoptRef(SkTypeface::CreateFromStream(stream))
; | |
103 #endif | |
104 if (!typeface) | |
105 return nullptr; | |
106 | |
107 return adoptPtr(new FontCustomPlatformData(typeface.release())); | |
108 } | |
109 | |
110 bool FontCustomPlatformData::supportsFormat(const String& format) | |
111 { | |
112 return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "o
pentype") || OpenTypeSanitizer::supportsFormat(format); | |
113 } | |
114 | |
115 } // namespace blink | |
OLD | NEW |