Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/common/font_config_ipc_linux.cc

Issue 12391070: Call Skia's version of SkFontHost_fontconfig (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/font_config_ipc_linux.h ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/skia/include/core/SkStream.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 FontConfigIPC::FontConfigIPC(int fd) 19 FontConfigIPC::FontConfigIPC(int fd)
19 : fd_(fd) { 20 : fd_(fd) {
20 } 21 }
21 22
22 FontConfigIPC::~FontConfigIPC() { 23 FontConfigIPC::~FontConfigIPC() {
23 close(fd_); 24 close(fd_);
24 } 25 }
25 26
26 bool FontConfigIPC::Match(std::string* result_family, 27 bool FontConfigIPC::matchFamilyName(const char familyName[],
27 unsigned* result_filefaceid, 28 SkTypeface::Style requestedStyle,
28 bool filefaceid_valid, unsigned filefaceid, 29 FontIdentity* outFontIdentifier,
29 const std::string& family, 30 SkString* outFamilyName,
30 const void* characters, size_t characters_bytes, 31 SkTypeface::Style* outStyle) {
31 bool* is_bold, bool* is_italic) { 32 std::string family(familyName);
32 if (family.length() > kMaxFontFamilyLength) 33 if (family.length() > kMaxFontFamilyLength)
33 return false; 34 return false;
34 35
35 Pickle request; 36 Pickle request;
36 request.WriteInt(METHOD_MATCH); 37 request.WriteInt(METHOD_MATCH);
37 request.WriteBool(filefaceid_valid); 38 request.WriteString(family);
38 if (filefaceid_valid) 39 request.WriteUInt32(requestedStyle);
39 request.WriteUInt32(filefaceid);
40 40
41 request.WriteBool(is_bold && *is_bold); 41 uint8_t reply_buf[2048];
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];
51 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, 42 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
52 sizeof(reply_buf), NULL, 43 sizeof(reply_buf), NULL,
53 request); 44 request);
54 if (r == -1) 45 if (r == -1)
55 return false; 46 return false;
56 47
57 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 48 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
58 PickleIterator iter(reply); 49 PickleIterator iter(reply);
59 bool result; 50 bool result;
60 if (!reply.ReadBool(&iter, &result)) 51 if (!reply.ReadBool(&iter, &result))
61 return false; 52 return false;
62 if (!result) 53 if (!result)
63 return false; 54 return false;
64 55
65 uint32_t reply_filefaceid;
66 std::string reply_family; 56 std::string reply_family;
67 bool resulting_bold, resulting_italic; 57 std::string reply_path;
68 if (!reply.ReadUInt32(&iter, &reply_filefaceid) || 58 uint32_t reply_ttcIndex;
69 !reply.ReadString(&iter, &reply_family) || 59 uint32_t reply_style;
70 !reply.ReadBool(&iter, &resulting_bold) || 60 if (!reply.ReadString(&iter, &reply_family) ||
71 !reply.ReadBool(&iter, &resulting_italic)) { 61 !reply.ReadString(&iter, &reply_path) ||
62 !reply.ReadUInt32(&iter, &reply_ttcIndex) ||
63 !reply.ReadUInt32(&iter, &reply_style)) {
72 return false; 64 return false;
73 } 65 }
74 66
75 if (result_filefaceid) 67 if (outFontIdentifier) {
76 *result_filefaceid = reply_filefaceid; 68 outFontIdentifier->fIntPtr = reply_ttcIndex;
77 if (result_family) 69 outFontIdentifier->fString.set(reply_path.c_str());
78 *result_family = reply_family; 70 }
79 71 if (outFamilyName)
80 if (is_bold) 72 outFamilyName->set(reply_family.c_str());
81 *is_bold = resulting_bold; 73 if (outStyle)
82 if (is_italic) 74 *outStyle = (SkTypeface::Style)reply_style;
83 *is_italic = resulting_italic;
84 75
85 return true; 76 return true;
86 } 77 }
87 78
88 int FontConfigIPC::Open(unsigned filefaceid) { 79 SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
80 std::string path(identity.fString.c_str());
81
89 Pickle request; 82 Pickle request;
90 request.WriteInt(METHOD_OPEN); 83 request.WriteInt(METHOD_OPEN);
91 request.WriteUInt32(filefaceid); 84 request.WriteString(path);
92 85
93 int result_fd = -1; 86 int result_fd = -1;
94 uint8_t reply_buf[256]; 87 uint8_t reply_buf[256];
95 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, 88 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
96 sizeof(reply_buf), 89 sizeof(reply_buf),
97 &result_fd, request); 90 &result_fd, request);
98 91
99 if (r == -1) 92 if (r == -1)
100 return -1; 93 return NULL;
101 94
102 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 95 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
103 bool result; 96 bool result;
104 PickleIterator iter(reply); 97 PickleIterator iter(reply);
105 if (!reply.ReadBool(&iter, &result) || 98 if (!reply.ReadBool(&iter, &result) ||
106 !result) { 99 !result) {
107 if (result_fd) 100 if (result_fd)
108 close(result_fd); 101 close(result_fd);
109 return -1; 102 return NULL;
110 } 103 }
111 104
112 return result_fd; 105 return new SkFDStream(result_fd, true);
113 } 106 }
114 107
115 } // namespace content 108 } // namespace content
OLDNEW
« no previous file with comments | « content/common/font_config_ipc_linux.h ('k') | content/zygote/zygote_main_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698