Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp

Issue 2032943002: Avoid one temporary copy on web fonts decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Computer, Inc. 2 * Copyright (C) 2007 Apple Computer, Inc.
3 * Copyright (c) 2007, 2008, 2009, Google Inc. All rights reserved. 3 * Copyright (c) 2007, 2008, 2009, Google Inc. All rights reserved.
4 * Copyright (C) 2010 Company 100, Inc. 4 * Copyright (C) 2010 Company 100, Inc.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 18 matching lines...) Expand all
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "platform/fonts/FontCustomPlatformData.h" 33 #include "platform/fonts/FontCustomPlatformData.h"
34 34
35 #include "platform/LayoutTestSupport.h" 35 #include "platform/LayoutTestSupport.h"
36 #include "platform/SharedBuffer.h" 36 #include "platform/SharedBuffer.h"
37 #include "platform/fonts/FontCache.h" 37 #include "platform/fonts/FontCache.h"
38 #include "platform/fonts/FontPlatformData.h" 38 #include "platform/fonts/FontPlatformData.h"
39 #include "platform/fonts/opentype/OpenTypeSanitizer.h" 39 #include "platform/fonts/WebFontDecoder.h"
40 #include "third_party/skia/include/core/SkStream.h" 40 #include "third_party/skia/include/core/SkStream.h"
41 #include "third_party/skia/include/core/SkTypeface.h" 41 #include "third_party/skia/include/core/SkTypeface.h"
42 #include "wtf/PassOwnPtr.h" 42 #include "wtf/PassOwnPtr.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 FontCustomPlatformData::FontCustomPlatformData(PassRefPtr<SkTypeface> typeface) 46 FontCustomPlatformData::FontCustomPlatformData(PassRefPtr<SkTypeface> typeface)
47 : m_typeface(typeface) { } 47 : m_typeface(typeface) { }
48 48
49 FontCustomPlatformData::~FontCustomPlatformData() 49 FontCustomPlatformData::~FontCustomPlatformData()
50 { 50 {
51 } 51 }
52 52
53 FontPlatformData FontCustomPlatformData::fontPlatformData(float size, bool bold, bool italic, FontOrientation orientation) 53 FontPlatformData FontCustomPlatformData::fontPlatformData(float size, bool bold, bool italic, FontOrientation orientation)
54 { 54 {
55 ASSERT(m_typeface); 55 ASSERT(m_typeface);
56 return FontPlatformData(m_typeface.get(), "", size, bold && !m_typeface->isB old(), italic && !m_typeface->isItalic(), orientation); 56 return FontPlatformData(m_typeface.get(), "", size, bold && !m_typeface->isB old(), italic && !m_typeface->isItalic(), orientation);
57 } 57 }
58 58
59 PassOwnPtr<FontCustomPlatformData> FontCustomPlatformData::create(SharedBuffer* buffer, String& otsParseMessage) 59 PassOwnPtr<FontCustomPlatformData> FontCustomPlatformData::create(SharedBuffer* buffer, String& otsParseMessage)
60 { 60 {
61 DCHECK(buffer); 61 DCHECK(buffer);
62 62 WebFontDecoder decoder;
63 OpenTypeSanitizer sanitizer(buffer); 63 RefPtr<SkTypeface> typeface = decoder.decode(buffer);
64 RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize(); 64 if (!typeface) {
65 65 otsParseMessage = decoder.getErrorString();
66 if (!transcodeBuffer) { 66 return nullptr;
67 otsParseMessage = sanitizer.getErrorString();
68 return nullptr; // validation failed.
69 } 67 }
70 buffer = transcodeBuffer.get();
71
72 SkMemoryStream* stream = new SkMemoryStream(buffer->getAsSkData().get());
73 #if OS(WIN)
74 RefPtr<SkTypeface> typeface = adoptRef(FontCache::fontCache()->fontManager() ->createFromStream(stream));
75 #else
76 RefPtr<SkTypeface> typeface = adoptRef(SkTypeface::CreateFromStream(stream)) ;
77 #endif
78 if (!typeface)
79 return nullptr;
80
81 return adoptPtr(new FontCustomPlatformData(typeface.release())); 68 return adoptPtr(new FontCustomPlatformData(typeface.release()));
82 } 69 }
83 70
84 bool FontCustomPlatformData::supportsFormat(const String& format) 71 bool FontCustomPlatformData::supportsFormat(const String& format)
85 { 72 {
86 return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "o pentype") || OpenTypeSanitizer::supportsFormat(format); 73 return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "o pentype") || WebFontDecoder::supportsFormat(format);
87 } 74 }
88 75
89 } // namespace blink 76 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698