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

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

Issue 12764009: re-land 187283 -- switch to 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 "skia/ext/skia_utils_base.h"
16 #include "third_party/skia/include/core/SkStream.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 FontConfigIPC::FontConfigIPC(int fd) 20 FontConfigIPC::FontConfigIPC(int fd)
19 : fd_(fd) { 21 : fd_(fd) {
20 } 22 }
21 23
22 FontConfigIPC::~FontConfigIPC() { 24 FontConfigIPC::~FontConfigIPC() {
23 close(fd_); 25 close(fd_);
24 } 26 }
25 27
26 bool FontConfigIPC::Match(std::string* result_family, 28 bool FontConfigIPC::matchFamilyName(const char familyName[],
27 unsigned* result_filefaceid, 29 SkTypeface::Style requestedStyle,
28 bool filefaceid_valid, unsigned filefaceid, 30 FontIdentity* outFontIdentity,
29 const std::string& family, 31 SkString* outFamilyName,
30 const void* characters, size_t characters_bytes, 32 SkTypeface::Style* outStyle) {
31 bool* is_bold, bool* is_italic) { 33 size_t familyNameLen = familyName ? strlen(familyName) : 0;
32 if (family.length() > kMaxFontFamilyLength) 34 if (familyNameLen > kMaxFontFamilyLength)
33 return false; 35 return false;
34 36
35 Pickle request; 37 Pickle request;
36 request.WriteInt(METHOD_MATCH); 38 request.WriteInt(METHOD_MATCH);
37 request.WriteBool(filefaceid_valid); 39 request.WriteData(familyName, familyNameLen);
38 if (filefaceid_valid) 40 request.WriteUInt32(requestedStyle);
39 request.WriteUInt32(filefaceid);
40 41
41 request.WriteBool(is_bold && *is_bold); 42 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, 43 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
52 sizeof(reply_buf), NULL, 44 sizeof(reply_buf), NULL,
53 request); 45 request);
54 if (r == -1) 46 if (r == -1)
55 return false; 47 return false;
56 48
57 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 49 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
58 PickleIterator iter(reply); 50 PickleIterator iter(reply);
59 bool result; 51 bool result;
60 if (!reply.ReadBool(&iter, &result)) 52 if (!reply.ReadBool(&iter, &result))
61 return false; 53 return false;
62 if (!result) 54 if (!result)
63 return false; 55 return false;
64 56
65 uint32_t reply_filefaceid; 57 SkString reply_family;
66 std::string reply_family; 58 FontIdentity reply_identity;
67 bool resulting_bold, resulting_italic; 59 uint32_t reply_style;
68 if (!reply.ReadUInt32(&iter, &reply_filefaceid) || 60 if (!skia::ReadSkString(reply, &iter, &reply_family) ||
69 !reply.ReadString(&iter, &reply_family) || 61 !skia::ReadSkFontIdentity(reply, &iter, &reply_identity) ||
70 !reply.ReadBool(&iter, &resulting_bold) || 62 !reply.ReadUInt32(&iter, &reply_style)) {
71 !reply.ReadBool(&iter, &resulting_italic)) {
72 return false; 63 return false;
73 } 64 }
74 65
75 if (result_filefaceid) 66 if (outFontIdentity)
76 *result_filefaceid = reply_filefaceid; 67 *outFontIdentity = reply_identity;
77 if (result_family) 68 if (outFamilyName)
78 *result_family = reply_family; 69 *outFamilyName = reply_family;
79 70 if (outStyle)
80 if (is_bold) 71 *outStyle = static_cast<SkTypeface::Style>(reply_style);
81 *is_bold = resulting_bold;
82 if (is_italic)
83 *is_italic = resulting_italic;
84 72
85 return true; 73 return true;
86 } 74 }
87 75
88 int FontConfigIPC::Open(unsigned filefaceid) { 76 SkStream* FontConfigIPC::openStream(const FontIdentity& identity) {
89 Pickle request; 77 Pickle request;
90 request.WriteInt(METHOD_OPEN); 78 request.WriteInt(METHOD_OPEN);
91 request.WriteUInt32(filefaceid); 79 request.WriteUInt32(identity.fID);
92 80
93 int result_fd = -1; 81 int result_fd = -1;
94 uint8_t reply_buf[256]; 82 uint8_t reply_buf[256];
95 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, 83 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf,
96 sizeof(reply_buf), 84 sizeof(reply_buf),
97 &result_fd, request); 85 &result_fd, request);
98 86
99 if (r == -1) 87 if (r == -1)
100 return -1; 88 return NULL;
101 89
102 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 90 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
103 bool result; 91 bool result;
104 PickleIterator iter(reply); 92 PickleIterator iter(reply);
105 if (!reply.ReadBool(&iter, &result) || 93 if (!reply.ReadBool(&iter, &result) ||
106 !result) { 94 !result) {
107 if (result_fd) 95 if (result_fd)
108 close(result_fd); 96 close(result_fd);
109 return -1; 97 return NULL;
110 } 98 }
111 99
112 return result_fd; 100 return new SkFDStream(result_fd, true);
113 } 101 }
114 102
115 } // namespace content 103 } // 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