[pdf] SkPDFGraphicStackState::Entry::fColor default Make the default value for SkPDFGraphicStackState::Entry::fColor a very invalid color instead of opaque black in order to better match the actual defaults in PDF. Currently if an SkPDFDevice is created and the first thing done with it is to draw an opaque black path then the opaque black will not be written to the PDF since it is currently assumed that the default will be opaque black. However, because no color space is currently defined for the fill and stroke colors and PDF otherwise has no default, the path will instead be filled with an indeterminate opaque color (in the case of poppler this will be cyan). Change-Id: I9f6a46c42fe8721d6a6f3dddc5ac986207a64bcd Reviewed-on: https://skia-review.googlesource.com/c/skia/+/635602 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/pdf/SkPDFGraphicStackState.cpp b/src/pdf/SkPDFGraphicStackState.cpp index f93cc24..dfd2214 100644 --- a/src/pdf/SkPDFGraphicStackState.cpp +++ b/src/pdf/SkPDFGraphicStackState.cpp
@@ -189,16 +189,13 @@ SkPDFUtils::ApplyPattern(state.fShaderIndex, fContentStream); currentEntry()->fShaderIndex = state.fShaderIndex; } - } else { - if (state.fColor != currentEntry()->fColor || - currentEntry()->fShaderIndex >= 0) { - emit_pdf_color(state.fColor, fContentStream); - fContentStream->writeText("RG "); - emit_pdf_color(state.fColor, fContentStream); - fContentStream->writeText("rg\n"); - currentEntry()->fColor = state.fColor; - currentEntry()->fShaderIndex = -1; - } + } else if (state.fColor != currentEntry()->fColor || currentEntry()->fShaderIndex >= 0) { + emit_pdf_color(state.fColor, fContentStream); + fContentStream->writeText("RG "); + emit_pdf_color(state.fColor, fContentStream); + fContentStream->writeText("rg\n"); + currentEntry()->fColor = state.fColor; + currentEntry()->fShaderIndex = -1; } if (state.fGraphicStateIndex != currentEntry()->fGraphicStateIndex) {
diff --git a/src/pdf/SkPDFGraphicStackState.h b/src/pdf/SkPDFGraphicStackState.h index 97cc969..2ea890c 100644 --- a/src/pdf/SkPDFGraphicStackState.h +++ b/src/pdf/SkPDFGraphicStackState.h
@@ -6,6 +6,7 @@ #include "include/core/SkColor.h" #include "include/core/SkMatrix.h" #include "include/core/SkScalar.h" +#include "include/private/base/SkFloatingPoint.h" #include "src/core/SkClipStack.h" class SkDynamicMemoryWStream; @@ -16,7 +17,7 @@ struct Entry { SkMatrix fMatrix = SkMatrix::I(); uint32_t fClipStackGenID = SkClipStack::kWideOpenGenID; - SkColor4f fColor = {0, 0, 0, 1}; + SkColor4f fColor = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; SkScalar fTextScaleX = 1; // Zero means we don't care what the value is. int fShaderIndex = -1; int fGraphicStateIndex = -1;