• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
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/fx_system.h"
12 #include "third_party/base/span.h"
13 
CPSOutput(HDC hDC,OutputMode mode)14 CPSOutput::CPSOutput(HDC hDC, OutputMode mode) : m_hDC(hDC), m_mode(mode) {}
15 
16 CPSOutput::~CPSOutput() = default;
17 
WriteBlock(const void * str,size_t len)18 bool CPSOutput::WriteBlock(const void* str, size_t len) {
19   pdfium::span<const uint8_t> input(static_cast<const uint8_t*>(str), len);
20   while (!input.empty()) {
21     uint8_t buffer[1026];
22     size_t send_len = std::min<size_t>(input.size(), 1024);
23     *(reinterpret_cast<uint16_t*>(buffer)) = static_cast<uint16_t>(send_len);
24     memcpy(buffer + 2, input.data(), send_len);
25 
26     switch (m_mode) {
27       case OutputMode::kExtEscape:
28         ExtEscape(m_hDC, PASSTHROUGH, send_len + 2,
29                   reinterpret_cast<const char*>(buffer), 0, nullptr);
30         break;
31       case OutputMode::kGdiComment:
32         GdiComment(m_hDC, send_len + 2, buffer);
33         break;
34     }
35     input = input.subspan(send_len);
36   }
37   return true;
38 }
39 
WriteString(ByteStringView str)40 bool CPSOutput::WriteString(ByteStringView str) {
41   return WriteBlock(str.unterminated_c_str(), str.GetLength());
42 }
43