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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 else if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] =
= '2') | 51 else if (data[0] == 'w' && data[1] == 'O' && data[2] == 'F' && data[3] =
= '2') |
52 histogramName = "WebFont.DecodeSpeed.WOFF2"; | 52 histogramName = "WebFont.DecodeSpeed.WOFF2"; |
53 } | 53 } |
54 | 54 |
55 double kbPerSecond = decodedSize / (1000 * decodeTime); | 55 double kbPerSecond = decodedSize / (1000 * decodeTime); |
56 Platform::current()->histogramCustomCounts(histogramName, kbPerSecond, 1000,
300000, 50); | 56 Platform::current()->histogramCustomCounts(histogramName, kbPerSecond, 1000,
300000, 50); |
57 } | 57 } |
58 | 58 |
59 PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() | 59 PassRefPtr<SharedBuffer> OpenTypeSanitizer::sanitize() |
60 { | 60 { |
61 if (!m_buffer) | 61 if (!m_buffer) { |
| 62 setErrorString("Empty Buffer"); |
62 return nullptr; | 63 return nullptr; |
| 64 } |
63 | 65 |
64 // This is the largest web font size which we'll try to transcode. | 66 // This is the largest web font size which we'll try to transcode. |
65 static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB | 67 static const size_t maxWebFontSize = 30 * 1024 * 1024; // 30 MB |
66 if (m_buffer->size() > maxWebFontSize) | 68 if (m_buffer->size() > maxWebFontSize) { |
| 69 setErrorString("Web font size more than 30MB"); |
67 return nullptr; | 70 return nullptr; |
| 71 } |
68 | 72 |
69 // A transcoded font is usually smaller than an original font. | 73 // A transcoded font is usually smaller than an original font. |
70 // However, it can be slightly bigger than the original one due to | 74 // However, it can be slightly bigger than the original one due to |
71 // name table replacement and/or padding for glyf table. | 75 // name table replacement and/or padding for glyf table. |
72 // | 76 // |
73 // With WOFF fonts, however, we'll be decompressing, so the result can be | 77 // With WOFF fonts, however, we'll be decompressing, so the result can be |
74 // much larger than the original. | 78 // much larger than the original. |
75 | 79 |
76 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); | 80 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); |
77 double start = currentTime(); | 81 double start = currentTime(); |
78 BlinkOTSContext otsContext; | 82 BlinkOTSContext otsContext; |
79 | 83 |
80 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->
data()), m_buffer->size())) | 84 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer->
data()), m_buffer->size())) { |
| 85 setErrorString(otsContext.getErrorString()); |
81 return nullptr; | 86 return nullptr; |
| 87 } |
82 | 88 |
83 const size_t transcodeLen = output.Tell(); | 89 const size_t transcodeLen = output.Tell(); |
84 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); | 90 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); |
85 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); | 91 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); |
86 } | 92 } |
87 | 93 |
88 bool OpenTypeSanitizer::supportsFormat(const String& format) | 94 bool OpenTypeSanitizer::supportsFormat(const String& format) |
89 { | 95 { |
90 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); | 96 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); |
91 } | 97 } |
92 | 98 |
| 99 void BlinkOTSContext::Message(int level, const char *format, ...) |
| 100 { |
| 101 va_list args; |
| 102 va_start(args, format); |
| 103 |
| 104 #if COMPILER(MSVC) |
| 105 int result = _vscprintf(format, args); |
| 106 #else |
| 107 char ch; |
| 108 int result = vsnprintf(&ch, 1, format, args); |
| 109 #endif |
| 110 va_end(args); |
| 111 |
| 112 if (result <= 0) { |
| 113 m_errorString = String("OTS Error"); |
| 114 } else { |
| 115 Vector<char, 256> buffer; |
| 116 unsigned len = result; |
| 117 buffer.grow(len + 1); |
| 118 |
| 119 va_start(args, format); |
| 120 vsnprintf(buffer.data(), buffer.size(), format, args); |
| 121 va_end(args); |
| 122 m_errorString = StringImpl::create(reinterpret_cast<const LChar*>(buffer
.data()), len); |
| 123 } |
| 124 } |
| 125 |
| 126 ots::TableAction BlinkOTSContext::GetTableAction(uint32_t tag) |
| 127 { |
| 128 #define TABLE_TAG(c1, c2, c3, c4) ((uint32_t)((((uint8_t)(c1)) << 24) | (((uint8
_t)(c2)) << 16) | (((uint8_t)(c3)) << 8) | ((uint8_t)(c4)))) |
| 129 |
| 130 const uint32_t cbdtTag = TABLE_TAG('C', 'B', 'D', 'T'); |
| 131 const uint32_t cblcTag = TABLE_TAG('C', 'B', 'L', 'C'); |
| 132 const uint32_t colrTag = TABLE_TAG('C', 'O', 'L', 'R'); |
| 133 const uint32_t cpalTag = TABLE_TAG('C', 'P', 'A', 'L'); |
| 134 |
| 135 switch (tag) { |
| 136 // Google Color Emoji Tables |
| 137 case cbdtTag: |
| 138 case cblcTag: |
| 139 // Windows Color Emoji Tables |
| 140 case colrTag: |
| 141 case cpalTag: |
| 142 return ots::TABLE_ACTION_PASSTHRU; |
| 143 default: |
| 144 return ots::TABLE_ACTION_DEFAULT; |
| 145 } |
| 146 #undef TABLE_TAG |
| 147 } |
| 148 |
93 } // namespace blink | 149 } // namespace blink |
OLD | NEW |