1 // Copyright (c) 2012 The Chromium 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.
5 #include "content/common/font_config_ipc_linux.h"
9 #include <sys/socket.h>
13 #include "base/pickle.h"
14 #include "base/posix/unix_domain_socket_linux.h"
18 FontConfigIPC::FontConfigIPC(int fd
)
22 FontConfigIPC::~FontConfigIPC() {
26 bool FontConfigIPC::Match(std::string
* result_family
,
27 unsigned* result_filefaceid
,
28 bool filefaceid_valid
, unsigned filefaceid
,
29 const std::string
& family
,
30 const void* characters
, size_t characters_bytes
,
31 bool* is_bold
, bool* is_italic
) {
32 if (family
.length() > kMaxFontFamilyLength
)
36 request
.WriteInt(METHOD_MATCH
);
37 request
.WriteBool(filefaceid_valid
);
39 request
.WriteUInt32(filefaceid
);
41 request
.WriteBool(is_bold
&& *is_bold
);
42 request
.WriteBool(is_bold
&& *is_italic
);
44 request
.WriteUInt32(characters_bytes
);
46 request
.WriteBytes(characters
, characters_bytes
);
48 request
.WriteString(family
);
50 uint8_t reply_buf
[512];
51 const ssize_t r
= UnixDomainSocket::SendRecvMsg(fd_
, reply_buf
,
52 sizeof(reply_buf
), NULL
,
57 Pickle
reply(reinterpret_cast<char*>(reply_buf
), r
);
58 PickleIterator
iter(reply
);
60 if (!reply
.ReadBool(&iter
, &result
))
65 uint32_t reply_filefaceid
;
66 std::string reply_family
;
67 bool resulting_bold
, resulting_italic
;
68 if (!reply
.ReadUInt32(&iter
, &reply_filefaceid
) ||
69 !reply
.ReadString(&iter
, &reply_family
) ||
70 !reply
.ReadBool(&iter
, &resulting_bold
) ||
71 !reply
.ReadBool(&iter
, &resulting_italic
)) {
75 if (result_filefaceid
)
76 *result_filefaceid
= reply_filefaceid
;
78 *result_family
= reply_family
;
81 *is_bold
= resulting_bold
;
83 *is_italic
= resulting_italic
;
88 int FontConfigIPC::Open(unsigned filefaceid
) {
90 request
.WriteInt(METHOD_OPEN
);
91 request
.WriteUInt32(filefaceid
);
94 uint8_t reply_buf
[256];
95 const ssize_t r
= UnixDomainSocket::SendRecvMsg(fd_
, reply_buf
,
102 Pickle
reply(reinterpret_cast<char*>(reply_buf
), r
);
104 PickleIterator
iter(reply
);
105 if (!reply
.ReadBool(&iter
, &result
) ||
115 } // namespace content