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

Side by Side Diff: Source/platform/fonts/opentype/OpenTypeSanitizer.cpp

Issue 983973004: Provide user friendly messages for OTS parsing of fonts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Correcting Method call Created 5 years, 7 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) 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
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 // OTS parsing is not called yet, setting parsing error for OTS as false
62 setParsingError(false);
jungshik at Google 2015/06/01 23:22:19 You don't need to call an accessor. Why don't you
h.joshi 2015/06/04 15:19:16 Done.
61 if (!m_buffer) 63 if (!m_buffer)
jungshik at Google 2015/06/01 23:22:19 Set the error message to 'Empty Buffer' or somethi
h.joshi 2015/06/04 15:19:16 Done.
62 return nullptr; 64 return nullptr;
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)
67 return nullptr; 69 return nullptr;
jungshik at Google 2015/06/01 23:22:19 IMHO, you'd better set a custom error string here,
h.joshi 2015/06/04 15:19:16 Done.
68 70
69 // A transcoded font is usually smaller than an original font. 71 // A transcoded font is usually smaller than an original font.
70 // However, it can be slightly bigger than the original one due to 72 // However, it can be slightly bigger than the original one due to
71 // name table replacement and/or padding for glyf table. 73 // name table replacement and/or padding for glyf table.
72 // 74 //
73 // With WOFF fonts, however, we'll be decompressing, so the result can be 75 // With WOFF fonts, however, we'll be decompressing, so the result can be
74 // much larger than the original. 76 // much larger than the original.
75 77
76 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize); 78 ots::ExpandingMemoryStream output(m_buffer->size(), maxWebFontSize);
77 double start = currentTime(); 79 double start = currentTime();
78 BlinkOTSContext otsContext; 80 BlinkOTSContext otsContext;
79 81
80 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer-> data()), m_buffer->size())) 82 if (!otsContext.Process(&output, reinterpret_cast<const uint8_t*>(m_buffer-> data()), m_buffer->size())) {
83 setParsingError(true);
84 setErrorString(otsContext.getErrorString());
jungshik at Google 2015/06/01 23:22:19 again, you don't need accessors to set member vari
h.joshi 2015/06/04 15:19:16 Done.
81 return nullptr; 85 return nullptr;
86 }
82 87
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698