1 // Copyright 2016 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fxge/win32/cpsoutput.h"
8
9 #include <algorithm>
10
11 #include "core/fxcrt/compiler_specific.h"
12 #include "core/fxcrt/fx_memcpy_wrappers.h"
13 #include "core/fxcrt/fx_system.h"
14 #include "core/fxcrt/span.h"
15
CPSOutput(HDC hDC,OutputMode mode)16 CPSOutput::CPSOutput(HDC hDC, OutputMode mode) : m_hDC(hDC), m_mode(mode) {}
17
18 CPSOutput::~CPSOutput() = default;
19
WriteBlock(pdfium::span<const uint8_t> input)20 bool CPSOutput::WriteBlock(pdfium::span<const uint8_t> input) {
21 while (!input.empty()) {
22 uint8_t buffer[1026];
23 size_t send_len = std::min<size_t>(input.size(), 1024);
24 *(reinterpret_cast<uint16_t*>(buffer)) = static_cast<uint16_t>(send_len);
25 UNSAFE_TODO(FXSYS_memcpy(buffer + 2, input.data(), send_len));
26 switch (m_mode) {
27 case OutputMode::kExtEscape:
28 ExtEscape(m_hDC, PASSTHROUGH, static_cast<int>(send_len + 2),
29 reinterpret_cast<const char*>(buffer), 0, nullptr);
30 break;
31 case OutputMode::kGdiComment:
32 GdiComment(m_hDC, static_cast<UINT>(send_len + 2), buffer);
33 break;
34 }
35 input = input.subspan(send_len);
36 }
37 return true;
38 }
39