blob: b880d4a26a4b99781a15095bc20e3dc7488978a1 [file] [log] [blame]
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "SkPDFCatalog.h"
18#include "SkPDFStream.h"
19#include "SkStream.h"
20
21SkPDFStream::SkPDFStream(SkStream* stream) : fData(stream) {
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000022 SkRefPtr<SkPDFInt> lenValue = new SkPDFInt(fData->read(NULL, 0));
23 lenValue->unref(); // SkRefPtr and new both took a reference.
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000024 fDict.insert("Length", lenValue.get());
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000025}
26
27SkPDFStream::~SkPDFStream() {
28}
29
30void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
31 bool indirect) {
32 if (indirect)
33 return emitIndirectObject(stream, catalog);
34
35 fDict.emitObject(stream, catalog, false);
36 stream->writeText(" stream\n");
37 stream->write(fData->getMemoryBase(), fData->read(NULL, 0));
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000038 stream->writeText("endstream");
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000039}
40
41size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
42 if (indirect)
43 return getIndirectOutputSize(catalog);
44
45 return fDict.getOutputSize(catalog, false) +
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000046 strlen(" stream\nendstream") + fData->read(NULL, 0);
vandebo@chromium.org8459d4e2010-09-24 22:25:30 +000047}
48
49void SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
50 fDict.insert(key, value);
51}
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000052
53void SkPDFStream::insert(const char key[], SkPDFObject* value) {
54 fDict.insert(key, value);
55}