blob: 08d9812d2f1cae6a515c0bf92c9baf35c0053b98 [file] [log] [blame]
edisonn@google.comcf2cfa12013-08-21 16:31:37 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkPdfUtils_DEFINED
9#define SkPdfUtils_DEFINED
edisonn@google.comb857a0c2013-06-25 20:45:40 +000010
edisonn@google.com3aa35552013-08-14 18:26:20 +000011#include "SkMatrix.h"
12#include "SkRect.h"
edisonn@google.com33f11b62013-08-14 21:35:27 +000013#include "SkPdfConfig.h"
edisonn@google.com063d7072013-08-16 15:05:08 +000014#include "SkString.h"
edisonn@google.comb857a0c2013-06-25 20:45:40 +000015
edisonn@google.comb857a0c2013-06-25 20:45:40 +000016class SkPdfArray;
edisonn@google.com3aa35552013-08-14 18:26:20 +000017class SkPdfContext;
18class SkCanvas;
19class SkPdfNativeObject;
20
21// TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered.
22enum SkPdfResult {
23 kOK_SkPdfResult,
24 kPartial_SkPdfResult,
25 kNYI_SkPdfResult,
26 kIgnoreError_SkPdfResult,
27 kError_SkPdfResult,
28 kUnsupported_SkPdfResult,
29
30 kCount_SkPdfResult
31};
32
33struct NotOwnedString {
34 const unsigned char* fBuffer;
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000035 // TODO(edisonn): clean up, the last two bytes are used to signal if compression is used
edisonn@google.com3aa35552013-08-14 18:26:20 +000036 size_t fBytes;
37
38 static void init(NotOwnedString* str) {
39 str->fBuffer = NULL;
40 str->fBytes = 0;
41 }
42
43 static void init(NotOwnedString* str, const char* sz) {
44 str->fBuffer = (const unsigned char*)sz;
45 str->fBytes = strlen(sz);
46 }
47
48 bool equals(const char* sz) {
49 return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz);
50
51 }
52};
edisonn@google.comb857a0c2013-06-25 20:45:40 +000053
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000054SkMatrix SkMatrixFromPdfMatrix(double array[6]);
55
edisonn@google.com063d7072013-08-16 15:05:08 +000056// TODO(edisonn): hack to make code generation simpler. Alternatively we can update the
57// generate_code.py not to rely on != operator
58bool operator !=(const SkString& first, const char* second);
59
edisonn@google.comb857a0c2013-06-25 20:45:40 +000060SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);
61
edisonn@google.com3aa35552013-08-14 18:26:20 +000062SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize);
63
64////////////////////////////////////////////////////////////////////////////////////////////////////
65//
66// TRACE functions
67//
68#ifdef PDF_TRACE
69void SkTraceMatrix(const SkMatrix& matrix, const char* sz);
70void SkTraceRect(const SkRect& rect, const char* sz);
71#else
72#define SkTraceMatrix(a,b)
73#define SkTraceRect(a,b)
74#endif
edisonn@google.comb857a0c2013-06-25 20:45:40 +000075
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000076#ifdef PDF_TRACE_TOKENIZER
77
78static void TRACE_COMMENT(char ch) {
79 printf("%c", ch);
80}
81
82static void TRACE_TK(char ch) {
83 printf("%c", ch);
84}
85
86static void TRACE_NAME(const unsigned char* start, const unsigned char* end) {
87 while (start < end) {
88 printf("%c", *start);
89 start++;
90 }
91 printf("\n");
92}
93
94static void TRACE_STRING(const unsigned char* start, const unsigned char* end) {
95 while (start < end) {
96 printf("%c", *start);
97 start++;
98 }
99 printf("\n");
100}
101
102static void TRACE_HEXSTRING(const unsigned char* start, const unsigned char* end) {
103 while (start < end) {
104 printf("%c", *start);
105 start++;
106 }
107 printf("\n");
108}
109
110#else
111#define TRACE_COMMENT(ch)
112#define TRACE_TK(ch)
113#define TRACE_NAME(start,end)
114#define TRACE_STRING(start,end)
115#define TRACE_HEXSTRING(start,end)
116#endif
117
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000118#endif // SkPdfUtils_DEFINED