blob: 87ed4597dc591da82167a3ffd7dea90189e8e379 [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
edisonn@google.comd03c2c72013-10-11 18:26:45 +000033// In order to operate fast, when we parse the pdf, we try not to allocate many new strings,
34// and if possible we refer the string in the pdf stream.
edisonn@google.com3aa35552013-08-14 18:26:20 +000035struct NotOwnedString {
36 const unsigned char* fBuffer;
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000037 // TODO(edisonn): clean up, the last two bytes are used to signal if compression is used
edisonn@google.com3aa35552013-08-14 18:26:20 +000038 size_t fBytes;
39
40 static void init(NotOwnedString* str) {
41 str->fBuffer = NULL;
42 str->fBytes = 0;
43 }
44
45 static void init(NotOwnedString* str, const char* sz) {
46 str->fBuffer = (const unsigned char*)sz;
47 str->fBytes = strlen(sz);
48 }
49
50 bool equals(const char* sz) {
51 return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz);
52
53 }
54};
edisonn@google.comb857a0c2013-06-25 20:45:40 +000055
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000056SkMatrix SkMatrixFromPdfMatrix(double array[6]);
57
edisonn@google.com063d7072013-08-16 15:05:08 +000058// TODO(edisonn): hack to make code generation simpler. Alternatively we can update the
59// generate_code.py not to rely on != operator
60bool operator !=(const SkString& first, const char* second);
61
edisonn@google.comb857a0c2013-06-25 20:45:40 +000062SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);
63
edisonn@google.come50d9a12013-10-10 20:58:22 +000064SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj,
65 SkRect bBox, SkMatrix matrix, double textSize);
edisonn@google.com3aa35552013-08-14 18:26:20 +000066
67////////////////////////////////////////////////////////////////////////////////////////////////////
68//
69// TRACE functions
70//
71#ifdef PDF_TRACE
72void SkTraceMatrix(const SkMatrix& matrix, const char* sz);
73void SkTraceRect(const SkRect& rect, const char* sz);
74#else
75#define SkTraceMatrix(a,b)
76#define SkTraceRect(a,b)
77#endif
edisonn@google.comb857a0c2013-06-25 20:45:40 +000078
edisonn@google.comc8fda9d2013-10-09 20:23:12 +000079#ifdef PDF_TRACE_TOKENIZER
80
81static void TRACE_COMMENT(char ch) {
82 printf("%c", ch);
83}
84
85static void TRACE_TK(char ch) {
86 printf("%c", ch);
87}
88
89static void TRACE_NAME(const unsigned char* start, const unsigned char* end) {
90 while (start < end) {
91 printf("%c", *start);
92 start++;
93 }
94 printf("\n");
95}
96
97static void TRACE_STRING(const unsigned char* start, const unsigned char* end) {
98 while (start < end) {
99 printf("%c", *start);
100 start++;
101 }
102 printf("\n");
103}
104
105static void TRACE_HEXSTRING(const unsigned char* start, const unsigned char* end) {
106 while (start < end) {
107 printf("%c", *start);
108 start++;
109 }
110 printf("\n");
111}
112
113#else
114#define TRACE_COMMENT(ch)
115#define TRACE_TK(ch)
116#define TRACE_NAME(start,end)
117#define TRACE_STRING(start,end)
118#define TRACE_HEXSTRING(start,end)
119#endif
120
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000121#endif // SkPdfUtils_DEFINED