Home | History | Annotate | Download | only in pdf
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkPDFShader_DEFINED
     11 #define SkPDFShader_DEFINED
     12 
     13 #include "SkPDFStream.h"
     14 #include "SkPDFTypes.h"
     15 
     16 class SkPDFCanon;
     17 class SkMatrix;
     18 class SkShader;
     19 struct SkIRect;
     20 
     21 /** \class SkPDFShader
     22 
     23     In PDF parlance, this is a pattern, used in place of a color when the
     24     pattern color space is selected.
     25 */
     26 
     27 class SkPDFShader {
     28 public:
     29     class State;
     30 
     31     /** Get the PDF shader for the passed SkShader. If the SkShader is
     32      *  invalid in some way, returns nullptr. The reference count of
     33      *  the object is incremented and it is the caller's responsibility to
     34      *  unreference it when done.  This is needed to accommodate the weak
     35      *  reference pattern used when the returned object is new and has no
     36      *  other references.
     37      *  @param shader      The SkShader to emulate.
     38      *  @param matrix      The current transform. (PDF shaders are absolutely
     39      *                     positioned, relative to where the page is drawn.)
     40      *  @param surfceBBox  The bounding box of the drawing surface (with matrix
     41      *                     already applied).
     42      *  @param rasterScale Additional scale to be applied for early
     43      *                     rasterization.
     44      */
     45     static SkPDFObject* GetPDFShader(SkPDFCanon* canon,
     46                                      SkScalar dpi,
     47                                      const SkShader& shader,
     48                                      const SkMatrix& matrix,
     49                                      const SkIRect& surfaceBBox,
     50                                      SkScalar rasterScale);
     51 };
     52 
     53 class SkPDFFunctionShader final : public SkPDFDict {
     54 
     55 
     56 public:
     57     static SkPDFFunctionShader* Create(SkPDFCanon*,
     58                                        SkAutoTDelete<SkPDFShader::State>*);
     59     virtual ~SkPDFFunctionShader();
     60     bool equals(const SkPDFShader::State&) const;
     61 
     62 private:
     63     SkAutoTDelete<const SkPDFShader::State> fShaderState;
     64     SkPDFFunctionShader(SkPDFShader::State*);
     65     typedef SkPDFDict INHERITED;
     66 };
     67 
     68 /**
     69  * A shader for PDF gradients. This encapsulates the function shader
     70  * inside a tiling pattern while providing a common pattern interface.
     71  * The encapsulation allows the use of a SMask for transparency gradients.
     72  */
     73 class SkPDFAlphaFunctionShader final : public SkPDFStream {
     74 public:
     75     static SkPDFAlphaFunctionShader* Create(SkPDFCanon*,
     76                                             SkScalar dpi,
     77                                             SkAutoTDelete<SkPDFShader::State>*);
     78     virtual ~SkPDFAlphaFunctionShader();
     79     bool equals(const SkPDFShader::State&) const;
     80 
     81 private:
     82     SkAutoTDelete<const SkPDFShader::State> fShaderState;
     83     SkPDFAlphaFunctionShader(SkPDFShader::State*);
     84     typedef SkPDFStream INHERITED;
     85 };
     86 
     87 class SkPDFImageShader final : public SkPDFStream {
     88 public:
     89     static SkPDFImageShader* Create(SkPDFCanon*,
     90                                     SkScalar dpi,
     91                                     SkAutoTDelete<SkPDFShader::State>*);
     92     virtual ~SkPDFImageShader();
     93     bool equals(const SkPDFShader::State&) const;
     94 
     95 private:
     96     SkAutoTDelete<const SkPDFShader::State> fShaderState;
     97     SkPDFImageShader(SkPDFShader::State*);
     98     typedef SkPDFStream INHERITED;
     99 };
    100 
    101 #endif
    102