OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/font_config_ipc_linux.h" | 5 #include "content/common/font_config_ipc_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <sys/uio.h> | 10 #include <sys/uio.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include "base/pickle.h" | 13 #include "base/pickle.h" |
14 #include "base/posix/unix_domain_socket_linux.h" | 14 #include "base/posix/unix_domain_socket_linux.h" |
15 #include "skia/ext/skia_utils_base.h" | |
16 #include "third_party/skia/include/core/SkStream.h" | |
17 | 15 |
18 namespace content { | 16 namespace content { |
19 | 17 |
20 FontConfigIPC::FontConfigIPC(int fd) | 18 FontConfigIPC::FontConfigIPC(int fd) |
21 : fd_(fd) { | 19 : fd_(fd) { |
22 } | 20 } |
23 | 21 |
24 FontConfigIPC::~FontConfigIPC() { | 22 FontConfigIPC::~FontConfigIPC() { |
25 close(fd_); | 23 close(fd_); |
26 } | 24 } |
27 | 25 |
28 bool FontConfigIPC::matchFamilyName(const char familyName[], | 26 bool FontConfigIPC::Match(std::string* result_family, |
29 SkTypeface::Style requestedStyle, | 27 unsigned* result_filefaceid, |
30 FontIdentity* outFontIdentity, | 28 bool filefaceid_valid, unsigned filefaceid, |
31 SkString* outFamilyName, | 29 const std::string& family, |
32 SkTypeface::Style* outStyle) { | 30 const void* characters, size_t characters_bytes, |
33 size_t familyNameLen = familyName ? strlen(familyName) : 0; | 31 bool* is_bold, bool* is_italic) { |
34 if (familyNameLen > kMaxFontFamilyLength) | 32 if (family.length() > kMaxFontFamilyLength) |
35 return false; | 33 return false; |
36 | 34 |
37 Pickle request; | 35 Pickle request; |
38 request.WriteInt(METHOD_MATCH); | 36 request.WriteInt(METHOD_MATCH); |
39 request.WriteData(familyName, familyNameLen); | 37 request.WriteBool(filefaceid_valid); |
40 request.WriteUInt32(requestedStyle); | 38 if (filefaceid_valid) |
| 39 request.WriteUInt32(filefaceid); |
41 | 40 |
42 uint8_t reply_buf[2048]; | 41 request.WriteBool(is_bold && *is_bold); |
| 42 request.WriteBool(is_bold && *is_italic); |
| 43 |
| 44 request.WriteUInt32(characters_bytes); |
| 45 if (characters_bytes) |
| 46 request.WriteBytes(characters, characters_bytes); |
| 47 |
| 48 request.WriteString(family); |
| 49 |
| 50 uint8_t reply_buf[512]; |
43 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, | 51 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, |
44 sizeof(reply_buf), NULL, | 52 sizeof(reply_buf), NULL, |
45 request); | 53 request); |
46 if (r == -1) | 54 if (r == -1) |
47 return false; | 55 return false; |
48 | 56 |
49 Pickle reply(reinterpret_cast<char*>(reply_buf), r); | 57 Pickle reply(reinterpret_cast<char*>(reply_buf), r); |
50 PickleIterator iter(reply); | 58 PickleIterator iter(reply); |
51 bool result; | 59 bool result; |
52 if (!reply.ReadBool(&iter, &result)) | 60 if (!reply.ReadBool(&iter, &result)) |
53 return false; | 61 return false; |
54 if (!result) | 62 if (!result) |
55 return false; | 63 return false; |
56 | 64 |
57 SkString reply_family; | 65 uint32_t reply_filefaceid; |
58 FontIdentity reply_identity; | 66 std::string reply_family; |
59 uint32_t reply_style; | 67 bool resulting_bold, resulting_italic; |
60 if (!skia::ReadSkString(reply, &iter, &reply_family) || | 68 if (!reply.ReadUInt32(&iter, &reply_filefaceid) || |
61 !skia::ReadSkFontIdentity(reply, &iter, &reply_identity) || | 69 !reply.ReadString(&iter, &reply_family) || |
62 !reply.ReadUInt32(&iter, &reply_style)) { | 70 !reply.ReadBool(&iter, &resulting_bold) || |
| 71 !reply.ReadBool(&iter, &resulting_italic)) { |
63 return false; | 72 return false; |
64 } | 73 } |
65 | 74 |
66 if (outFontIdentity) | 75 if (result_filefaceid) |
67 *outFontIdentity = reply_identity; | 76 *result_filefaceid = reply_filefaceid; |
68 if (outFamilyName) | 77 if (result_family) |
69 *outFamilyName = reply_family; | 78 *result_family = reply_family; |
70 if (outStyle) | 79 |
71 *outStyle = static_cast<SkTypeface::Style>(reply_style); | 80 if (is_bold) |
| 81 *is_bold = resulting_bold; |
| 82 if (is_italic) |
| 83 *is_italic = resulting_italic; |
72 | 84 |
73 return true; | 85 return true; |
74 } | 86 } |
75 | 87 |
76 SkStream* FontConfigIPC::openStream(const FontIdentity& identity) { | 88 int FontConfigIPC::Open(unsigned filefaceid) { |
77 Pickle request; | 89 Pickle request; |
78 request.WriteInt(METHOD_OPEN); | 90 request.WriteInt(METHOD_OPEN); |
79 request.WriteUInt32(identity.fID); | 91 request.WriteUInt32(filefaceid); |
80 | 92 |
81 int result_fd = -1; | 93 int result_fd = -1; |
82 uint8_t reply_buf[256]; | 94 uint8_t reply_buf[256]; |
83 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, | 95 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, |
84 sizeof(reply_buf), | 96 sizeof(reply_buf), |
85 &result_fd, request); | 97 &result_fd, request); |
86 | 98 |
87 if (r == -1) | 99 if (r == -1) |
88 return NULL; | 100 return -1; |
89 | 101 |
90 Pickle reply(reinterpret_cast<char*>(reply_buf), r); | 102 Pickle reply(reinterpret_cast<char*>(reply_buf), r); |
91 bool result; | 103 bool result; |
92 PickleIterator iter(reply); | 104 PickleIterator iter(reply); |
93 if (!reply.ReadBool(&iter, &result) || | 105 if (!reply.ReadBool(&iter, &result) || |
94 !result) { | 106 !result) { |
95 if (result_fd) | 107 if (result_fd) |
96 close(result_fd); | 108 close(result_fd); |
97 return NULL; | 109 return -1; |
98 } | 110 } |
99 | 111 |
100 return new SkFDStream(result_fd, true); | 112 return result_fd; |
101 } | 113 } |
102 | 114 |
103 } // namespace content | 115 } // namespace content |
OLD | NEW |