aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer/SkPdfUtils.h
blob: b18c727a311db609891d4ade0f0b9b8788a78e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * 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

#include "SkMatrix.h"
#include "SkRect.h"
#include "SkPdfConfig.h"
#include "SkString.h"

class SkPdfArray;
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
};

struct NotOwnedString {
    const unsigned char* fBuffer;
    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);

    }
};

// 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);

SkMatrix SkMatrixFromPdfArray(SkPdfArray* pdfArray);

SkPdfResult doType3Char(SkPdfContext* pdfContext, SkCanvas* canvas, const SkPdfNativeObject* skobj, SkRect bBox, SkMatrix matrix, double textSize);

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 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

#endif   // SkPdfUtils_DEFINED