OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "platform/fonts/opentype/OpenTypeSanitizer.h" | 32 #include "platform/fonts/opentype/OpenTypeSanitizer.h" |
33 | 33 |
34 #include "opentype-sanitiser.h" | |
35 #include "ots-memory-stream.h" | 34 #include "ots-memory-stream.h" |
36 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
37 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
38 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 static void recordDecodeSpeedHistogram(SharedBuffer* buffer, double decodeTime,
size_t decodedSize) | 41 static void recordDecodeSpeedHistogram(SharedBuffer* buffer, double decodeTime,
size_t decodedSize) |
43 { | 42 { |
44 if (decodeTime <= 0) | 43 if (decodeTime <= 0) |
(...skipping 15 matching lines...) Expand all Loading... |
60 PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() | 59 PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() |
61 { | 60 { |
62 if (!m_buffer) | 61 if (!m_buffer) |
63 return nullptr; | 62 return nullptr; |
64 | 63 |
65 // This is the largest web font size which we'll try to transcode. | 64 // This is the largest web font size which we'll try to transcode. |
66 static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB | 65 static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB |
67 if (m_buffer->size() > maxWebFontSize) | 66 if (m_buffer->size() > maxWebFontSize) |
68 return nullptr; | 67 return nullptr; |
69 | 68 |
70 ots::EnableWOFF2(); | |
71 | |
72 // A transcoded font is usually smaller than an original font. | 69 // A transcoded font is usually smaller than an original font. |
73 // However, it can be slightly bigger than the original one due to | 70 // However, it can be slightly bigger than the original one due to |
74 // name table replacement and/or padding for glyf table. | 71 // name table replacement and/or padding for glyf table. |
75 // | 72 // |
76 // With WOFF fonts, however, we'll be decompressing, so the result can be | 73 // With WOFF fonts, however, we'll be decompressing, so the result can be |
77 // much larger than the original. | 74 // much larger than the original. |
78 | 75 |
79 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); | 76 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); |
80 double start = currentTime(); | 77 double start = currentTime(); |
81 ots::OTSContext otsContext; | 78 BlinkOTSContext otsContext; |
| 79 |
82 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->
data()), m_buffer->size())) | 80 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->
data()), m_buffer->size())) |
83 return nullptr; | 81 return nullptr; |
84 | 82 |
85 const size_t transcodeLen = output.Tell(); | 83 const size_t transcodeLen = output.Tell(); |
86 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); | 84 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); |
87 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); | 85 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); |
88 } | 86 } |
89 | 87 |
90 bool OpenTypeSanitizer::supportsFormat(const String& format) | 88 bool OpenTypeSanitizer::supportsFormat(const String& format) |
91 { | 89 { |
92 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); | 90 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); |
93 } | 91 } |
94 | 92 |
95 } // namespace blink | 93 } // namespace blink |
OLD | NEW |