2013-06-25 20:45:40 +00:00
|
|
|
#ifndef __DEFINED__SkPdfBasics
|
|
|
|
#define __DEFINED__SkPdfBasics
|
|
|
|
|
2013-06-26 17:48:12 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
2013-07-02 22:42:53 +00:00
|
|
|
#include "SkPdfConfig.h"
|
2013-08-14 18:26:20 +00:00
|
|
|
#include "SkPdfUtils.h"
|
2013-06-26 17:48:12 +00:00
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
class SkPdfFont;
|
|
|
|
class SkPdfDoc;
|
2013-08-14 18:26:20 +00:00
|
|
|
class SkPdfNativeObject;
|
2013-06-26 17:48:12 +00:00
|
|
|
class SkPdfResourceDictionary;
|
2013-07-29 22:14:45 +00:00
|
|
|
class SkPdfSoftMaskDictionary;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-08-14 18:26:20 +00:00
|
|
|
class SkPdfNativeDoc;
|
2013-07-23 17:43:18 +00:00
|
|
|
class SkPdfAllocator;
|
2013-07-02 22:42:53 +00:00
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
// TODO(edisonn): better class design.
|
2013-08-02 20:24:48 +00:00
|
|
|
class SkPdfColorOperator {
|
2013-07-28 18:34:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
color space name or array The current color space in which color values are to be interpreted
|
|
|
|
(see Section 4.5, “Color Spaces”). There are two separate color space
|
|
|
|
parameters: one for stroking and one for all other painting opera-
|
|
|
|
tions. Initial value: DeviceGray.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO(edisonn): implement the array part too
|
2013-07-10 17:09:50 +00:00
|
|
|
// does not own the char*
|
2013-08-02 20:24:48 +00:00
|
|
|
// TODO(edisonn): remove this public, let fields be private
|
|
|
|
// TODO(edisonn): make color space an enum!
|
|
|
|
public:
|
2013-07-23 17:43:18 +00:00
|
|
|
NotOwnedString fColorSpace;
|
2013-08-14 18:26:20 +00:00
|
|
|
SkPdfNativeObject* fPattern;
|
2013-07-28 18:34:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
color (various) The current color to be used during painting operations (see Section
|
|
|
|
4.5, “Color Spaces”). The type and interpretation of this parameter
|
|
|
|
depend on the current color space; for most color spaces, a color
|
|
|
|
value consists of one to four numbers. There are two separate color
|
|
|
|
parameters: one for stroking and one for all other painting opera-
|
|
|
|
tions. Initial value: black.
|
|
|
|
*/
|
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
SkColor fColor;
|
|
|
|
double fOpacity; // ca or CA
|
2013-08-02 20:24:48 +00:00
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
// TODO(edisonn): add here other color space options.
|
|
|
|
|
2013-08-02 20:24:48 +00:00
|
|
|
public:
|
2013-06-25 20:45:40 +00:00
|
|
|
void setRGBColor(SkColor color) {
|
|
|
|
// TODO(edisonn): ASSERT DeviceRGB is the color space.
|
2013-08-02 20:24:48 +00:00
|
|
|
fPattern = NULL;
|
2013-06-25 20:45:40 +00:00
|
|
|
fColor = color;
|
|
|
|
}
|
|
|
|
// TODO(edisonn): double check the default values for all fields.
|
2013-08-02 20:24:48 +00:00
|
|
|
SkPdfColorOperator() : fPattern(NULL), fColor(SK_ColorBLACK), fOpacity(1) {
|
|
|
|
NotOwnedString::init(&fColorSpace, "DeviceRGB");
|
|
|
|
}
|
|
|
|
|
|
|
|
void setColorSpace(NotOwnedString* colorSpace) {
|
|
|
|
fColorSpace = *colorSpace;
|
|
|
|
fPattern = NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-14 18:26:20 +00:00
|
|
|
void setPatternColorSpace(SkPdfNativeObject* pattern) {
|
2013-08-02 20:24:48 +00:00
|
|
|
fColorSpace.fBuffer = (const unsigned char*)"Pattern";
|
|
|
|
fColorSpace.fBytes = 7; // strlen("Pattern")
|
|
|
|
fPattern = pattern;
|
2013-07-23 17:43:18 +00:00
|
|
|
}
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
void applyGraphicsState(SkPaint* paint) {
|
2013-07-28 20:04:35 +00:00
|
|
|
paint->setColor(SkColorSetA(fColor, (U8CPU)(fOpacity * 255)));
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
struct SkPdfGraphicsState {
|
2013-07-28 18:34:14 +00:00
|
|
|
// TODO(edisonn): deprecate and remove these!
|
2013-06-25 20:45:40 +00:00
|
|
|
double fCurPosX;
|
|
|
|
double fCurPosY;
|
|
|
|
|
|
|
|
double fCurFontSize;
|
|
|
|
bool fTextBlock;
|
|
|
|
SkPdfFont* fSkFont;
|
|
|
|
SkPath fPath;
|
|
|
|
bool fPathClosed;
|
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
double fTextLeading;
|
|
|
|
double fWordSpace;
|
|
|
|
double fCharSpace;
|
|
|
|
|
|
|
|
SkPdfResourceDictionary* fResources;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(edisonn): move most of these in canvas/paint?
|
|
|
|
// we could have some in canvas (matrixes?),
|
|
|
|
// some in 2 paints (stroking paint and non stroking paint)
|
|
|
|
|
|
|
|
// TABLE 4.2 Device-independent graphics state parameters
|
|
|
|
/*
|
|
|
|
* CTM array The current transformation matrix, which maps positions from user
|
|
|
|
coordinates to device coordinates (see Section 4.2, “Coordinate Sys-
|
|
|
|
tems”). This matrix is modified by each application of the coordi-
|
|
|
|
nate transformation operator, cm. Initial value: a matrix that
|
|
|
|
transforms default user coordinates to device coordinates.
|
|
|
|
*/
|
|
|
|
SkMatrix fCTM;
|
|
|
|
|
2013-08-07 11:56:16 +00:00
|
|
|
SkMatrix fContentStreamMatrix;
|
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
/*
|
|
|
|
clipping path (internal) The current clipping path, which defines the boundary against
|
|
|
|
which all output is to be cropped (see Section 4.4.3, “Clipping Path
|
|
|
|
Operators”). Initial value: the boundary of the entire imageable
|
|
|
|
portion of the output page.
|
|
|
|
*/
|
2013-06-25 20:45:40 +00:00
|
|
|
// Clip that is applied after the drawing is done!!!
|
|
|
|
bool fHasClipPathToApply;
|
|
|
|
SkPath fClipPath;
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
SkPdfColorOperator fStroking;
|
|
|
|
SkPdfColorOperator fNonStroking;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
/*
|
|
|
|
text state (various) A set of nine graphics state parameters that pertain only to the
|
|
|
|
painting of text. These include parameters that select the font, scale
|
|
|
|
the glyphs to an appropriate size, and accomplish other effects. The
|
|
|
|
text state parameters are described in Section 5.2, “Text State
|
|
|
|
Parameters and Operators.”
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TODO(edisonn): add SkPdfTextState class. remove these two existing fields
|
|
|
|
SkMatrix fMatrixTm;
|
|
|
|
SkMatrix fMatrixTlm;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
line width number The thickness, in user space units, of paths to be stroked (see “Line
|
|
|
|
Width” on page 152). Initial value: 1.0.
|
|
|
|
*/
|
2013-06-25 20:45:40 +00:00
|
|
|
double fLineWidth;
|
|
|
|
|
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
/*
|
|
|
|
line cap integer A code specifying the shape of the endpoints for any open path that
|
|
|
|
is stroked (see “Line Cap Style” on page 153). Initial value: 0, for
|
|
|
|
square butt caps.
|
|
|
|
*/
|
|
|
|
// TODO (edisonn): implement defaults - page 153
|
|
|
|
int fLineCap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
line join integer A code specifying the shape of joints between connected segments
|
|
|
|
of a stroked path (see “Line Join Style” on page 153). Initial value: 0,
|
|
|
|
for mitered joins.
|
|
|
|
*/
|
|
|
|
// TODO (edisonn): implement defaults - page 153
|
|
|
|
int fLineJoin;
|
|
|
|
|
|
|
|
/*
|
|
|
|
miter limit number The maximum length of mitered line joins for stroked paths (see
|
|
|
|
“Miter Limit” on page 153). This parameter limits the length of
|
|
|
|
“spikes” produced when line segments join at sharp angles. Initial
|
|
|
|
value: 10.0, for a miter cutoff below approximately 11.5 degrees.
|
|
|
|
*/
|
|
|
|
// TODO (edisonn): implement defaults - page 153
|
|
|
|
double fMiterLimit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
dash pattern array and A description of the dash pattern to be used when paths are
|
|
|
|
number stroked (see “Line Dash Pattern” on page 155). Initial value: a solid
|
|
|
|
line.
|
|
|
|
*/
|
|
|
|
SkScalar fDashArray[256]; // TODO(edisonn): allocate array?
|
|
|
|
int fDashArrayLength;
|
|
|
|
SkScalar fDashPhase;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
rendering intent name The rendering intent to be used when converting CIE-based colors
|
|
|
|
to device colors (see “Rendering Intents” on page 197). Default
|
|
|
|
value: RelativeColorimetric.
|
|
|
|
*/
|
|
|
|
// TODO(edisonn): seems paper only. Verify.
|
|
|
|
|
|
|
|
/*
|
|
|
|
stroke adjustment boolean (PDF 1.2) A flag specifying whether to compensate for possible ras-
|
|
|
|
terization effects when stroking a path with a line width that is
|
|
|
|
small relative to the pixel resolution of the output device (see Sec-
|
|
|
|
tion 6.5.4, “Automatic Stroke Adjustment”). Note that this is con-
|
|
|
|
sidered a device-independent parameter, even though the details of
|
|
|
|
its effects are device-dependent. Initial value: false.
|
|
|
|
*/
|
|
|
|
// TODO(edisonn): stroke adjustment low priority.
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
blend mode name or array (PDF 1.4) The current blend mode to be used in the transparent
|
|
|
|
imaging model (see Sections 7.2.4, “Blend Mode,” and 7.5.2, “Spec-
|
|
|
|
ifying Blending Color Space and Blend Mode”). This parameter is
|
|
|
|
implicitly reset to its initial value at the beginning of execution of a
|
|
|
|
transparency group XObject (see Section 7.5.5, “Transparency
|
|
|
|
Group XObjects”). Initial value: Normal.
|
|
|
|
*/
|
2013-07-29 19:10:58 +00:00
|
|
|
SkXfermode::Mode fBlendModes[256];
|
|
|
|
int fBlendModesLength;
|
2013-07-28 18:34:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
soft mask dictionary (PDF 1.4) A soft-mask dictionary (see “Soft-Mask Dictionaries” on
|
|
|
|
or name page 445) specifying the mask shape or mask opacity values to be
|
|
|
|
used in the transparent imaging model (see “Source Shape and
|
|
|
|
Opacity” on page 421 and “Mask Shape and Opacity” on page 443),
|
|
|
|
or the name None if no such mask is specified. This parameter is
|
|
|
|
implicitly reset to its initial value at the beginning of execution of a
|
|
|
|
transparency group XObject (see Section 7.5.5, “Transparency
|
|
|
|
Group XObjects”). Initial value: None.
|
|
|
|
*/
|
2013-07-29 22:14:45 +00:00
|
|
|
SkPdfSoftMaskDictionary* fSoftMaskDictionary;
|
2013-08-05 16:23:23 +00:00
|
|
|
// TODO(edisonn): make sMask private, add setter and getter, ref/unref/..., at the moment we most likely leask
|
|
|
|
SkBitmap* fSMask;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
alpha constant number (PDF 1.4) The constant shape or constant opacity value to be used
|
|
|
|
in the transparent imaging model (see “Source Shape and Opacity”
|
|
|
|
on page 421 and “Constant Shape and Opacity” on page 444).
|
|
|
|
There are two separate alpha constant parameters: one for stroking
|
|
|
|
and one for all other painting operations. This parameter is implic-
|
|
|
|
itly reset to its initial value at the beginning of execution of a trans-
|
|
|
|
parency group XObject (see Section 7.5.5, “Transparency Group
|
|
|
|
XObjects”). Initial value: 1.0.
|
|
|
|
*/
|
|
|
|
double fAphaConstant;
|
|
|
|
|
|
|
|
/*
|
|
|
|
alpha source boolean (PDF 1.4) A flag specifying whether the current soft mask and alpha
|
|
|
|
constant parameters are to be interpreted as shape values (true) or
|
|
|
|
opacity values (false). This flag also governs the interpretation of
|
|
|
|
the SMask entry, if any, in an image dictionary (see Section 4.8.4,
|
|
|
|
“Image Dictionaries”). Initial value: false.
|
|
|
|
*/
|
|
|
|
bool fAlphaSource;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(edisonn): Device-dependent seem to be required only on the actual physical printer?
|
|
|
|
// TABLE 4.3 Device-dependent graphics state parameters
|
|
|
|
/*
|
|
|
|
overprint boolean (PDF 1.2) A flag specifying (on output devices that support the
|
|
|
|
overprint control feature) whether painting in one set of colorants
|
|
|
|
should cause the corresponding areas of other colorants to be
|
|
|
|
erased (false) or left unchanged (true); see Section 4.5.6, “Over-
|
|
|
|
print Control.” In PDF 1.3, there are two separate overprint param-
|
|
|
|
eters: one for stroking and one for all other painting operations.
|
|
|
|
Initial value: false.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
overprint mode number (PDF 1.3) A code specifying whether a color component value of 0
|
|
|
|
in a DeviceCMYK color space should erase that component (0) or
|
|
|
|
leave it unchanged (1) when overprinting (see Section 4.5.6, “Over-
|
|
|
|
print Control”). Initial value: 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
black generation function (PDF 1.2) A function that calculates the level of the black color
|
|
|
|
or name component to use when converting RGB colors to CMYK (see Sec-
|
|
|
|
tion 6.2.3, “Conversion from DeviceRGB to DeviceCMYK”). Initial
|
|
|
|
value: installation-dependent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
undercolor removal function (PDF 1.2) A function that calculates the reduction in the levels of
|
|
|
|
or name the cyan, magenta, and yellow color components to compensate for
|
|
|
|
the amount of black added by black generation (see Section 6.2.3,
|
|
|
|
“Conversion from DeviceRGB to DeviceCMYK”). Initial value: in-
|
|
|
|
stallation-dependent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
transfer function, (PDF 1.2) A function that adjusts device gray or color component
|
|
|
|
array, or name levels to compensate for nonlinear response in a particular out-
|
|
|
|
put device (see Section 6.3, “Transfer Functions”). Initial value:
|
|
|
|
installation-dependent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
halftone dictionary, (PDF 1.2) A halftone screen for gray and color rendering, specified
|
|
|
|
stream, or name as a halftone dictionary or stream (see Section 6.4, “Halftones”).
|
|
|
|
Initial value: installation-dependent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
flatness number The precision with which curves are to be rendered on the output
|
|
|
|
device (see Section 6.5.1, “Flatness Tolerance”). The value of this
|
|
|
|
parameter gives the maximum error tolerance, measured in output
|
|
|
|
device pixels; smaller numbers give smoother curves at the expense
|
|
|
|
of more computation and memory use. Initial value: 1.0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
smoothness number (PDF 1.3) The precision with which color gradients are to be ren-
|
|
|
|
dered on the output device (see Section 6.5.2, “Smoothness Toler-
|
|
|
|
ance”). The value of this parameter gives the maximum error
|
|
|
|
tolerance, expressed as a fraction of the range of each color compo-
|
|
|
|
nent; smaller numbers give smoother color transitions at the
|
|
|
|
expense of more computation and memory use. Initial value:
|
|
|
|
installation-dependent.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-02 22:42:53 +00:00
|
|
|
SkPdfGraphicsState() {
|
2013-06-25 20:45:40 +00:00
|
|
|
fCurPosX = 0.0;
|
|
|
|
fCurPosY = 0.0;
|
|
|
|
fCurFontSize = 0.0;
|
|
|
|
fTextBlock = false;
|
2013-07-28 18:34:14 +00:00
|
|
|
fCTM = SkMatrix::I();
|
2013-06-25 20:45:40 +00:00
|
|
|
fMatrixTm = SkMatrix::I();
|
|
|
|
fMatrixTlm = SkMatrix::I();
|
|
|
|
fPathClosed = true;
|
|
|
|
fLineWidth = 0;
|
|
|
|
fTextLeading = 0;
|
|
|
|
fWordSpace = 0;
|
|
|
|
fCharSpace = 0;
|
|
|
|
fHasClipPathToApply = false;
|
|
|
|
fResources = NULL;
|
|
|
|
fSkFont = NULL;
|
2013-07-28 18:34:14 +00:00
|
|
|
fLineCap = 0;
|
|
|
|
fLineJoin = 0;
|
|
|
|
fMiterLimit = 10.0;
|
|
|
|
fAphaConstant = 1.0;
|
|
|
|
fAlphaSource = false;
|
|
|
|
fDashArrayLength = 0;
|
|
|
|
fDashPhase = 0;
|
2013-07-29 19:10:58 +00:00
|
|
|
fBlendModesLength = 1;
|
|
|
|
fBlendModes[0] = SkXfermode::kSrc_Mode; // PDF: Normal Blend mode
|
2013-08-05 20:45:40 +00:00
|
|
|
fSMask = NULL;
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 18:34:14 +00:00
|
|
|
// TODO(edisonn): make two functons instead, stroking and non stoking, avoid branching
|
|
|
|
void applyGraphicsState(SkPaint* paint, bool stroking);
|
2013-06-25 20:45:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO(edisonn): better class design.
|
2013-07-02 22:42:53 +00:00
|
|
|
// TODO(edisonn): rename to SkPdfContext
|
2013-08-14 18:26:20 +00:00
|
|
|
struct SkPdfContext {
|
|
|
|
std::stack<SkPdfNativeObject*> fObjectStack;
|
2013-07-02 22:42:53 +00:00
|
|
|
std::stack<SkPdfGraphicsState> fStateStack;
|
|
|
|
SkPdfGraphicsState fGraphicsState;
|
2013-08-14 18:26:20 +00:00
|
|
|
SkPdfNativeDoc* fPdfDoc;
|
2013-07-23 17:43:18 +00:00
|
|
|
// TODO(edisonn): the allocator, could be freed after the page is done drawing.
|
|
|
|
SkPdfAllocator* fTmpPageAllocator;
|
2013-06-25 20:45:40 +00:00
|
|
|
SkMatrix fOriginalMatrix;
|
|
|
|
|
2013-08-14 18:26:20 +00:00
|
|
|
SkPdfContext(SkPdfNativeDoc* doc);
|
|
|
|
~SkPdfContext();
|
2013-06-25 20:45:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __DEFINED__SkPdfBasics
|