summaryrefslogtreecommitdiff
path: root/xfa_test/pdf/pdfium/pdfium_mem_buffer_file_read.cc
blob: b2371b42ff7854fb9a28dd9228d6b3b0fbaf5bf7 (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
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "pdf/pdfium/pdfium_mem_buffer_file_read.h"

#include <string.h>

namespace chrome_pdf {

PDFiumMemBufferFileRead::PDFiumMemBufferFileRead(const void* data,
                                                 size_t size) {
  m_FileLen = size;
  m_Param = this;
  m_GetBlock = &GetBlock;
  data_ = reinterpret_cast<const unsigned char*>(data);
}

PDFiumMemBufferFileRead::~PDFiumMemBufferFileRead() {
}

int PDFiumMemBufferFileRead::GetBlock(void* param,
                                      unsigned long position,
                                      unsigned char* buf,
                                      unsigned long size) {
  const PDFiumMemBufferFileRead* data =
      reinterpret_cast<const PDFiumMemBufferFileRead*>(param);
  if (!data || position + size > data->m_FileLen)
    return 0;
  memcpy(buf, data->data_ + position, size);
  return 1;
}

}  // namespace chrome_pdf