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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // 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 |
71 // name table replacement and/or padding for glyf table. | 71 // name table replacement and/or padding for glyf table. |
72 // | 72 // |
73 // 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 |
74 // much larger than the original. | 74 // much larger than the original. |
75 | 75 |
76 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); | 76 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); |
77 double start = currentTime(); | 77 double start = currentTime(); |
78 BlinkOTSContext otsContext; | 78 BlinkOTSContext otsContext; |
79 | 79 |
80 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())) { |
| 81 setParsingError(true); |
| 82 setErrorString(otsContext.getErrorString()); |
81 return nullptr; | 83 return nullptr; |
| 84 } |
82 | 85 |
| 86 setParsingError(false); |
| 87 setErrorString(otsContext.getErrorString()); |
83 const size_t transcodeLen = output.Tell(); | 88 const size_t transcodeLen = output.Tell(); |
84 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); | 89 recordDecodeSpeedHistogram(m_buffer, currentTime() - start, transcodeLen); |
85 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); | 90 return SharedBuffer::create(static_cast<unsigned char*>(output.get()), trans
codeLen); |
86 } | 91 } |
87 | 92 |
88 bool OpenTypeSanitizer::supportsFormat(const String& format) | 93 bool OpenTypeSanitizer::supportsFormat(const String& format) |
89 { | 94 { |
90 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); | 95 return equalIgnoringCase(format, "woff") || equalIgnoringCase(format, "woff2
"); |
91 } | 96 } |
92 | 97 |
| 98 void BlinkOTSContext::Message(int level, const char *format, ...) |
| 99 { |
| 100 va_list args; |
| 101 va_start(args, format); |
| 102 |
| 103 #if COMPILER(MSVC) |
| 104 int result = _vscprintf(format, args); |
| 105 #else |
| 106 char ch; |
| 107 int result = vsnprintf(&ch, 1, format, args); |
| 108 #endif |
| 109 va_end(args); |
| 110 |
| 111 if (result <= 0) { |
| 112 m_errorString = String("OTS Error"); |
| 113 } else { |
| 114 Vector<char, 256> buffer; |
| 115 unsigned len = result; |
| 116 buffer.grow(len + 1); |
| 117 |
| 118 va_start(args, format); |
| 119 vsnprintf(buffer.data(), buffer.size(), format, args); |
| 120 va_end(args); |
| 121 m_errorString = StringImpl::create(reinterpret_cast<const LChar*>(buffer
.data()), len); |
| 122 } |
| 123 } |
| 124 |
| 125 ots::TableAction BlinkOTSContext::GetTableAction(uint32_t tag) |
| 126 { |
| 127 #define TABLE_TAG(c1, c2, c3, c4) ((uint32_t)((((uint8_t)(c1)) << 24) | (((uint8
_t)(c2)) << 16) | (((uint8_t)(c3)) << 8) | ((uint8_t)(c4)))) |
| 128 |
| 129 const uint32_t cbdtTag = TABLE_TAG('C', 'B', 'D', 'T'); |
| 130 const uint32_t cblcTag = TABLE_TAG('C', 'B', 'L', 'C'); |
| 131 const uint32_t colrTag = TABLE_TAG('C', 'O', 'L', 'R'); |
| 132 const uint32_t cpalTag = TABLE_TAG('C', 'P', 'A', 'L'); |
| 133 |
| 134 switch (tag) { |
| 135 // Google Color Emoji Tables |
| 136 case cbdtTag: |
| 137 case cblcTag: |
| 138 // Windows Color Emoji Tables |
| 139 case colrTag: |
| 140 case cpalTag: |
| 141 return ots::TABLE_ACTION_PASSTHRU; |
| 142 default: |
| 143 return ots::TABLE_ACTION_DEFAULT; |
| 144 } |
| 145 #undef TABLE_TAG |
| 146 } |
| 147 |
93 } // namespace blink | 148 } // namespace blink |
OLD | NEW |