2013-08-21 16:31:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPdfUtils_DEFINED
|
|
|
|
#define SkPdfUtils_DEFINED
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-08-14 18:26:20 +00:00
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkRect.h"
|
2013-08-14 21:35:27 +00:00
|
|
|
#include "SkPdfConfig.h"
|
2013-08-16 15:05:08 +00:00
|
|
|
#include "SkString.h"
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
class SkPdfArray;
|
2013-08-14 18:26:20 +00:00
|
|
|
class SkPdfContext;
|
|
|
|
class SkCanvas;
|
|
|
|
class SkPdfNativeObject;
|
|
|
|
|
|
|
|
// TODO(edisonn): temporary code, to report how much of the PDF we actually think we rendered.
|
|
|
|
enum SkPdfResult {
|
|
|
|
kOK_SkPdfResult,
|
|
|
|
kPartial_SkPdfResult,
|
|
|
|
kNYI_SkPdfResult,
|
|
|
|
kIgnoreError_SkPdfResult,
|
|
|
|
kError_SkPdfResult,
|
|
|
|
kUnsupported_SkPdfResult,
|
|
|
|
|
|
|
|
kCount_SkPdfResult
|
|
|
|
};
|
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// In order to operate fast, when we parse the pdf, we try not to allocate many new strings,
|
|
|
|
// and if possible we refer the string in the pdf stream.
|
2013-08-14 18:26:20 +00:00
|
|
|
struct NotOwnedString {
|
|
|
|
const unsigned char* fBuffer;
|
2013-10-09 20:23:12 +00:00
|
|
|
// TODO(edisonn): clean up, the last two bytes are used to signal if compression is used
|
2013-08-14 18:26:20 +00:00
|
|
|
size_t fBytes;
|
|
|
|
|
|
|
|
static void init(NotOwnedString* str) {
|
|
|
|
str->fBuffer = NULL;
|
|
|
|
str->fBytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init(NotOwnedString* str, const char* sz) {
|
|
|
|
str->fBuffer = (const unsigned char*)sz;
|
|
|
|
str->fBytes = strlen(sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool equals(const char* sz) {
|
|
|
|
return strncmp((const char*)fBuffer, sz, fBytes) == 0 && fBytes == strlen(sz);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-10-09 20:23:12 +00:00
|
|
|
SkMatrix SkMatrixFromPdfMatrix(double array[6]);
|
|
|
|
|
2013-08-16 15:05:08 +00:00
|
|
|
// TODO(edisonn): hack to make code generation simpler. Alternatively we can update the
|
|
|
|
// generate_code.py not to rely on != operator
|
|
|
|
bool operator !=(const SkString& first, const char* second);
|
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);
|
|
|
|
|
2013-10-10 20:58:22 +00:00
|
|
|
SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj,
|
|
|
|
SkRect bBox, SkMatrix matrix, double textSize);
|
2013-08-14 18:26:20 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TRACE functions
|
|
|
|
//
|
|
|
|
#ifdef PDF_TRACE
|
|
|
|
void SkTraceMatrix(const SkMatrix& matrix, const char* sz);
|
|
|
|
void SkTraceRect(const SkRect& rect, const char* sz);
|
|
|
|
#else
|
|
|
|
#define SkTraceMatrix(a,b)
|
|
|
|
#define SkTraceRect(a,b)
|
|
|
|
#endif
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-10-09 20:23:12 +00:00
|
|
|
#ifdef PDF_TRACE_TOKENIZER
|
|
|
|
|
|
|
|
static void TRACE_COMMENT(char ch) {
|
|
|
|
printf("%c", ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TRACE_TK(char ch) {
|
|
|
|
printf("%c", ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TRACE_NAME(const unsigned char* start, const unsigned char* end) {
|
|
|
|
while (start < end) {
|
|
|
|
printf("%c", *start);
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TRACE_STRING(const unsigned char* start, const unsigned char* end) {
|
|
|
|
while (start < end) {
|
|
|
|
printf("%c", *start);
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TRACE_HEXSTRING(const unsigned char* start, const unsigned char* end) {
|
|
|
|
while (start < end) {
|
|
|
|
printf("%c", *start);
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define TRACE_COMMENT(ch)
|
|
|
|
#define TRACE_TK(ch)
|
|
|
|
#define TRACE_NAME(start,end)
|
|
|
|
#define TRACE_STRING(start,end)
|
|
|
|
#define TRACE_HEXSTRING(start,end)
|
|
|
|
#endif
|
|
|
|
|
2013-08-21 16:31:37 +00:00
|
|
|
#endif // SkPdfUtils_DEFINED
|