diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 22:25:54 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 22:25:54 +0000 |
commit | adb072f92d93e5adf28a77fb4f6c15effca7b001 (patch) | |
tree | 11043d294f773825ecd59aa8f8ede9df549f1e30 /chrome/renderer | |
parent | d4d1b878fde9f01c21a8e247288d56df1e5382c6 (diff) | |
download | chromium_src-adb072f92d93e5adf28a77fb4f6c15effca7b001.zip chromium_src-adb072f92d93e5adf28a77fb4f6c15effca7b001.tar.gz chromium_src-adb072f92d93e5adf28a77fb4f6c15effca7b001.tar.bz2 |
Add a font API to Pepper and implement on Linux based on agl's code from http://codereview.chromium.org/2673003.
Review URL: http://codereview.chromium.org/2794004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/renderer_sandbox_support_linux.cc | 99 | ||||
-rw-r--r-- | chrome/renderer/renderer_sandbox_support_linux.h | 20 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 59 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 1 |
4 files changed, 178 insertions, 1 deletions
diff --git a/chrome/renderer/renderer_sandbox_support_linux.cc b/chrome/renderer/renderer_sandbox_support_linux.cc index f1d03e3..4b02bbce 100644 --- a/chrome/renderer/renderer_sandbox_support_linux.cc +++ b/chrome/renderer/renderer_sandbox_support_linux.cc @@ -4,8 +4,12 @@ #include "chrome/renderer/renderer_sandbox_support_linux.h" +#include <sys/stat.h> + +#include "base/eintr_wrapper.h" #include "base/global_descriptors_posix.h" #include "base/pickle.h" +#include "base/scoped_ptr.h" #include "base/unix_domain_socket_posix.h" #include "chrome/common/chrome_descriptors.h" #include "chrome/common/sandbox_methods_linux.h" @@ -18,7 +22,8 @@ static int GetSandboxFD() { namespace renderer_sandbox_support { -std::string getFontFamilyForCharacters(const uint16_t* utf16, size_t num_utf16) { +std::string getFontFamilyForCharacters(const uint16_t* utf16, + size_t num_utf16) { Pickle request; request.WriteInt(LinuxSandbox::METHOD_GET_FONT_FAMILY_FOR_CHARS); request.WriteInt(num_utf16); @@ -87,4 +92,96 @@ int MakeSharedMemorySegmentViaIPC(size_t length) { return result_fd; } +int MatchFontWithFallback(const std::string& face, bool bold, + bool italic, NPCharset charset) { + Pickle request; + request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK); + request.WriteString(face); + request.WriteBool(bold); + request.WriteBool(italic); + request.WriteUInt32(charset); + uint8_t reply_buf[64]; + int fd = -1; + base::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf), + &fd, request); + return fd; +} + +bool GetFontTable(int fd, uint32_t table, uint8_t* output, + size_t* output_length) { + if (table == 0) { + struct stat st; + if (fstat(fd, &st) < 0) + return false; + size_t length = st.st_size; + if (!output) { + *output_length = length; + return true; + } + if (*output_length < length) + return false; + *output_length = length; + ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0)); + if (n != static_cast<ssize_t>(length)) + return false; + return true; + } + + unsigned num_tables; + uint8_t num_tables_buf[2]; + + ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf), + 4 /* skip the font type */)); + if (n != sizeof(num_tables_buf)) + return false; + + num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 | + num_tables_buf[1]; + + // The size in bytes of an entry in the table directory. + static const unsigned kTableEntrySize = 16; + scoped_array<uint8_t> table_entries( + new uint8_t[num_tables * kTableEntrySize]); + n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize, + 12 /* skip the SFNT header */)); + if (n != static_cast<ssize_t>(num_tables * kTableEntrySize)) + return false; + + size_t offset; + size_t length = 0; + for (unsigned i = 0; i < num_tables; i++) { + const uint8_t* entry = table_entries.get() + i * kTableEntrySize; + if (memcmp(entry, &table, sizeof(table)) == 0) { + offset = static_cast<size_t>(entry[8]) << 24 | + static_cast<size_t>(entry[9]) << 16 | + static_cast<size_t>(entry[10]) << 8 | + static_cast<size_t>(entry[11]); + length = static_cast<size_t>(entry[12]) << 24 | + static_cast<size_t>(entry[13]) << 16 | + static_cast<size_t>(entry[14]) << 8 | + static_cast<size_t>(entry[15]); + + break; + } + } + + if (!length) + return false; + + if (!output) { + *output_length = length; + return true; + } + + if (*output_length < length) + return false; + + *output_length = length; + n = HANDLE_EINTR(pread(fd, output, length, offset)); + if (n != static_cast<ssize_t>(length)) + return false; + + return true; +} + } // namespace render_sandbox_support diff --git a/chrome/renderer/renderer_sandbox_support_linux.h b/chrome/renderer/renderer_sandbox_support_linux.h index 3fa318b..098c46e 100644 --- a/chrome/renderer/renderer_sandbox_support_linux.h +++ b/chrome/renderer/renderer_sandbox_support_linux.h @@ -9,6 +9,8 @@ #include <string> +#include "third_party/npapi/bindings/npapi_extensions.h" + namespace WebKit { struct WebFontRenderStyle; } @@ -30,6 +32,24 @@ void getRenderStyleForStrike(const char* family, int sizeAndStyle, // Returns a file descriptor for a shared memory segment. int MakeSharedMemorySegmentViaIPC(size_t length); +// Return a read-only file descriptor to the font which best matches the given +// properties or -1 on failure. +// charset: specifies the language(s) that the font must cover. See +// render_sandbox_host_linux.cc for more information. +int MatchFontWithFallback(const std::string& face, bool bold, + bool italic, NPCharset charset); + +// GetFontTable loads a specified font table from an open SFNT file. +// fd: a file descriptor to the SFNT file. The position doesn't matter. +// table: the table in *big-endian* format, or 0 for the whole font file. +// output: a buffer of size output_length that gets the data. can be 0, in +// which case output_length will be set to the required size in bytes. +// output_length: size of output, if it's not 0. +// +// returns: true on success. +bool GetFontTable(int fd, uint32_t table, uint8_t* output, + size_t* output_length); + }; // namespace render_sandbox_support #endif // CHROME_RENDERER_RENDERER_SANDBOX_SUPPORT_LINUX_H_ diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 1fd996e..69b1b0e 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -9,6 +9,10 @@ #include <string> #include <vector> +#if defined(OS_LINUX) +#include <unistd.h> +#endif + #include "base/file_util.h" #include "base/keyboard_codes.h" #if defined(OS_MACOSX) @@ -27,6 +31,9 @@ #include "chrome/common/render_messages.h" #include "chrome/renderer/pepper_widget.h" #include "chrome/renderer/render_thread.h" +#if defined(OS_LINUX) +#include "chrome/renderer/renderer_sandbox_support_linux.h" +#endif #include "chrome/renderer/webplugin_delegate_proxy.h" #include "gfx/blit.h" #if defined(OS_WIN) @@ -426,6 +433,58 @@ bool WebPluginDelegatePepper::SetCursor(NPCursorType type) { return true; } +NPError NPMatchFontWithFallback(NPP instance, + const NPFontDescription* description, + NPFontID* id) { +#if defined(OS_LINUX) + int fd = renderer_sandbox_support::MatchFontWithFallback( + description->face, description->weight >= 700, description->italic, + description->charset); + if (fd == -1) + return NPERR_GENERIC_ERROR; + *id = fd; + return NPERR_NO_ERROR; +#else + NOTIMPLEMENTED(); + return NPERR_GENERIC_ERROR; +#endif +} + +NPError GetFontTable(NPP instance, + NPFontID id, + uint32_t table, + void* output, + size_t* output_length) { +#if defined(OS_LINUX) + bool rv = renderer_sandbox_support::GetFontTable( + id, table, static_cast<uint8_t*>(output), output_length); + return rv ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR; +#else + NOTIMPLEMENTED(); + return NPERR_GENERIC_ERROR; +#endif +} + +NPError NPDestroyFont(NPP instance, NPFontID id) { +#if defined(OS_LINUX) + close(id); + return NPERR_NO_ERROR; +#else + NOTIMPLEMENTED(); + return NPERR_GENERIC_ERROR; +#endif +} + +NPFontExtensions g_font_extensions = { + NPMatchFontWithFallback, + GetFontTable, + NPDestroyFont +}; + +NPFontExtensions* WebPluginDelegatePepper::GetFontExtensions() { + return &g_font_extensions; +} + void WebPluginDelegatePepper::Zoom(int factor) { NPPExtensions* extensions = NULL; instance()->NPP_GetValue(NPPVPepperExtensions, &extensions); diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index 245a174..1d7ca2a 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -94,6 +94,7 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate, void* user_data); virtual NPWidgetExtensions* GetWidgetExtensions(); virtual bool SetCursor(NPCursorType type); + virtual NPFontExtensions* GetFontExtensions(); virtual void Zoom(int factor); virtual void Copy(); |