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
CPSOutput(HDC hDC)13 CPSOutput::CPSOutput(HDC hDC) : m_hDC(hDC) {}
14
~CPSOutput()15 CPSOutput::~CPSOutput() {}
16
WriteBlock(const void * str,size_t len)17 bool CPSOutput::WriteBlock(const void* str, size_t len) {
18 int sent_len = 0;
19 while (len > 0) {
20 char buffer[1026];
21 size_t send_len = std::min(len, static_cast<size_t>(1024));
22 *(reinterpret_cast<uint16_t*>(buffer)) = send_len;
23 memcpy(buffer + 2, static_cast<const char*>(str) + sent_len, send_len);
24
25 // TODO(thestig/rbpotter): Do PASSTHROUGH for non-Chromium usage.
26 // ExtEscape(m_hDC, PASSTHROUGH, send_len + 2, buffer, 0, nullptr);
27 ::GdiComment(m_hDC, send_len + 2, reinterpret_cast<const BYTE*>(buffer));
28 sent_len += send_len;
29 len -= send_len;
30 }
31 return true;
32 }
33
WriteString(const ByteStringView & str)34 bool CPSOutput::WriteString(const ByteStringView& str) {
35 return WriteBlock(str.unterminated_c_str(), str.GetLength());
36 }
37