If getAdvance fails, getAdvanceData should not assert, but ignored.

Review URL: https://codereview.appspot.com/7127056

git-svn-id: http://skia.googlecode.com/svn/trunk@7341 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
edisonn@google.com 2013-01-23 16:08:15 +00:00
parent 1d6cff7293
commit c13ee606d8
2 changed files with 29 additions and 1 deletions

View File

@ -174,7 +174,9 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
if (!subsetGlyphIDs ||
(subsetIndex < subsetGlyphIDsLength &&
static_cast<uint32_t>(gId) == subsetGlyphIDs[subsetIndex])) {
SkAssertResult(getAdvance(fontHandle, gId, &advance));
if (!getAdvance(fontHandle, gId, &advance)) {
advance = kDontCareAdvance;
}
++subsetIndex;
} else {
advance = kDontCareAdvance;

View File

@ -8,9 +8,11 @@
#include "Test.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkFlate.h"
#include "SkPDFCatalog.h"
#include "SkPDFDevice.h"
#include "SkPDFStream.h"
#include "SkPDFTypes.h"
#include "SkScalar.h"
@ -217,6 +219,28 @@ static void TestSubstitute(skiatest::Reporter* reporter) {
buffer.getOffset()));
}
// This test used to assert without the fix submitted for
// http://code.google.com/p/skia/issues/detail?id=1083.
// SKP files might have invalid glyph ids. This test ensures they are ignored,
// and there is no assert on input data in Debug mode.
static void test_issue1083(skiatest::Reporter* reporter) {
SkISize pageSize = SkISize::Make(100, 100);
SkPDFDevice* dev = new SkPDFDevice(pageSize, pageSize, SkMatrix::I());
SkCanvas c(dev);
SkPaint paint;
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
uint16_t glyphID = 65000;
c.drawText(&glyphID, 2, 0, 0, paint);
SkPDFDocument doc;
doc.appendPage(dev);
SkDynamicMemoryWStream stream;
doc.emitPDF(&stream);
}
static void TestPDFPrimitives(skiatest::Reporter* reporter) {
SkAutoTUnref<SkPDFInt> int42(new SkPDFInt(42));
SimpleCheckObjectOutput(reporter, int42.get(), "42");
@ -298,6 +322,8 @@ static void TestPDFPrimitives(skiatest::Reporter* reporter) {
TestObjectRef(reporter);
TestSubstitute(reporter);
test_issue1083(reporter);
}
#include "TestClassDef.h"