Ejemplo n.º 1
0
static SkPDFIndirectReference make_alpha_function_shader(SkPDFDocument* doc,
                                                         const SkPDFGradientShader::Key& state) {
    SkASSERT(state.fType != SkShader::kNone_GradientType);
    SkPDFGradientShader::Key opaqueState = clone_key(state);
    for (int i = 0; i < opaqueState.fInfo.fColorCount; i++) {
        opaqueState.fInfo.fColors[i] = SkColorSetA(opaqueState.fInfo.fColors[i], SK_AlphaOPAQUE);
    }
    opaqueState.fHash = hash(opaqueState);

    SkASSERT(!gradient_has_alpha(opaqueState));
    SkRect bbox = SkRect::Make(state.fBBox);
    SkPDFIndirectReference colorShader = find_pdf_shader(doc, std::move(opaqueState), false);
    if (!colorShader) {
        return SkPDFIndirectReference();
    }
    // Create resource dict with alpha graphics state as G0 and
    // pattern shader as P0, then write content stream.
    SkPDFIndirectReference alphaGsRef = create_smask_graphic_state(doc, state);

    std::unique_ptr<SkPDFDict> resourceDict = get_gradient_resource_dict(colorShader, alphaGsRef);

    std::unique_ptr<SkStreamAsset> colorStream =
            create_pattern_fill_content(alphaGsRef.fValue, colorShader.fValue, bbox);
    std::unique_ptr<SkPDFDict> alphaFunctionShader = SkPDFMakeDict();
    SkPDFUtils::PopulateTilingPatternDict(alphaFunctionShader.get(), bbox,
                                 std::move(resourceDict), SkMatrix::I());
    return SkPDFStreamOut(std::move(alphaFunctionShader), std::move(colorStream), doc);
}
Ejemplo n.º 2
0
SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
        SkPDFCanon* canon,
        SkScalar dpi,
        SkAutoTDelete<SkPDFShader::State>* autoState) {
    const SkPDFShader::State& state = **autoState;
    SkRect bbox;
    bbox.set(state.fBBox);

    SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState());

    SkAutoTUnref<SkPDFObject> colorShader(
            get_pdf_shader_by_state(canon, dpi, &opaqueState));
    if (!colorShader) {
        return NULL;
    }

    // Create resource dict with alpha graphics state as G0 and
    // pattern shader as P0, then write content stream.
    SkAutoTUnref<SkPDFObject> alphaGs(
            create_smask_graphic_state(canon, dpi, state));

    SkPDFAlphaFunctionShader* alphaFunctionShader =
            SkNEW_ARGS(SkPDFAlphaFunctionShader, (autoState->detach()));

    SkAutoTUnref<SkPDFDict> resourceDict(
            get_gradient_resource_dict(colorShader.get(), alphaGs.get()));

    SkAutoTDelete<SkStream> colorStream(
            create_pattern_fill_content(0, bbox));
    alphaFunctionShader->setData(colorStream.get());

    populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(),
                                 SkMatrix::I());
    canon->addAlphaShader(alphaFunctionShader);
    return alphaFunctionShader;
}