blob: a7fbc62521de0294166f0628c14ddff9e7004840 [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) {
22 SkRefPtr<SkPDFName> lenKey = new SkPDFName("Length");
23 lenKey->unref(); // SkRefPtr and new both took a reference.
24 SkRefPtr<SkPDFInt> lenValue = new SkPDFInt(fData->read(NULL, 0));
25 lenValue->unref(); // SkRefPtr and new both took a reference.
26 fDict.insert(lenKey.get(), lenValue.get());
27}
28
29SkPDFStream::~SkPDFStream() {
30}
31
32void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog,
33 bool indirect) {
34 if (indirect)
35 return emitIndirectObject(stream, catalog);
36
37 fDict.emitObject(stream, catalog, false);
38 stream->writeText(" stream\n");
39 stream->write(fData->getMemoryBase(), fData->read(NULL, 0));
40 stream->writeText("endstream\n");
41}
42
43size_t SkPDFStream::getOutputSize(SkPDFCatalog* catalog, bool indirect) {
44 if (indirect)
45 return getIndirectOutputSize(catalog);
46
47 return fDict.getOutputSize(catalog, false) +
48 strlen(" stream\nendstream\n") + fData->read(NULL, 0);
49}
50
51void SkPDFStream::insert(SkPDFName* key, SkPDFObject* value) {
52 fDict.insert(key, value);
53}